Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AmbiguousConstraint.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file
11 /// @brief contains declarations for a type of constraint that holds a number of constraints
12 /// @brief where only the lowest one is evaluated
13 /// @author Florian Richter (floric@u.washington.edu, march 2008)
14 
15 // Unit headers
17 
18 // Package headers
21 // AUTO-REMOVED #include <core/scoring/constraints/XYZ_Func.hh>
22 
23 // AUTO-REMOVED #include <core/scoring/Energies.hh>
24 
25 // Project headers
26 // AUTO-REMOVED #include <core/pose/Pose.hh>
27 
28 #include <utility/vector1.hh>
29 
30 
31 namespace core {
32 namespace scoring {
33 namespace constraints {
34 
35 ////////////////////////////////////////////////////////////////////////////////////////////////////
36 /// @brief Constructor
39 {
40  active_constraint_ = NULL;
41 
43 
44  assert ( member_constraints().size() == 0 );
45 }
46 ////////////////////////////////////////////////////////////////////////////////////////////////////
47 /// @brief Constructor
49  MultiConstraint( cst_in )
50 {
51  active_constraint_ = NULL;
52 
54 
55  assert ( member_constraints().size() > 0 );
56 
57 }
58 ////////////////////////////////////////////////////////////////////////////////////////////////////
59 void
61 {
62  cst_score_types_.clear();
69 }
70 
71 
72 /// @detail this function only checks whether the passed in cst
73 /// is the same type and then hands off to the multi cst. probably
74 /// overkill to also demand that the active cst is identical
75 bool
77 {
78  if( !dynamic_cast< AmbiguousConstraint const * > ( &other_cst ) ) return false;
79 
80  return MultiConstraint::operator==( other_cst);
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////////////////////////
84 /// @brief ScoreFunction, scores all member constraints but only reports the lowest one
85 void
86 AmbiguousConstraint::score( XYZ_Func const & xyz_func, EnergyMap const & weights, EnergyMap & emap ) const
87 {
88 
89  Real low_total_cst_score = 0;
91 
92  core::Real cur_score = 0;
93  bool first_pass = true;
94 
95  for( ConstraintCOPs::const_iterator
96  member_it = member_constraints().begin();
97  member_it != member_constraints().end(); member_it++){
98 
100 
101  (*member_it)->score(xyz_func, weights, temp_EMap_ );
102 
103  cur_score = calculate_total_cst_score( weights, temp_EMap_ );
104 
105  if ( first_pass || (cur_score < low_total_cst_score ) ){
106  first_pass = false;
107 
108  low_total_cst_score = cur_score;
109  active_constraint_ = *member_it;
110 
117 
118  }
119 
120  }
121  //add lowest score to the actual emap
128 
129 
130 } //score
131 
132 
133 /// @brief helper function to accumulate all constraint scores into one number
136 {
137 
139 
140  return total_score;
141 }
142 
143 
146 {
147 
148  ConstraintCOPs new_csts;
149 
150  for( ConstraintCOPs::const_iterator cst_it = member_constraints_.begin(); cst_it != member_constraints_.end(); ++cst_it ){
151 
152  ConstraintOP new_cst = (*cst_it)->remap_resid( seqmap );
153 
154  if( new_cst ) new_csts.push_back( new_cst );
155 
156  }
157 
158  if( new_csts.size() > 0 ){
159  return ConstraintOP( new AmbiguousConstraint( new_csts ) );
160  }
161  else return NULL;
162 
163 }
164 
165 
166 /// @brief function to minimize lowest scoring member constraint
167 void
169  AtomID const & atom,
170  XYZ_Func const & xyz,
171  Vector & F1,
172  Vector & F2,
173  EnergyMap const & weights
174 ) const
175 {
176  assert( active_constraint_ );
177  //std::cerr << "Error: attempted minimization of an ambiguous constraint before the lowest scoring member constraint has been determined. Was the pose not scored?" << std::endl;
178  //utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
179  active_constraint_->fill_f1_f2( atom, xyz, F1, F2, weights );
180 }
181 
182 void
183 AmbiguousConstraint::show( std::ostream& out) const
184 {
185  /// APL -- you cannot show the active constraint in the absence of a Pose.
186  //out << "AmbiguousConstraint Active constraint:" << std::endl;
187  //active_constraint()->show(out);
188  out << "AmbiguousConstraint containing the following " << member_constraints().size() << " constraints: " << std::endl;
189  for( ConstraintCOPs::const_iterator cst_it = member_constraints().begin(); cst_it != member_constraints().end(); cst_it++){
190  (*cst_it)->show(out);
191  }
192 
193  out << " ...all member constraints of this AmbiguousConstraint shown." << std::endl;
194 }
195 
198 // XYZ_Func const & xyz, // these arguments would allow active-constraint determination in a purley const fashion
199 // EnergyMap const & weights
200 ) const
201 {
202  return active_constraint_;
203  /* APL Code below is for when we remove non-constness to the Ambiguous constraints
204  ConstraintCOP active;
205 
206  Real low_total_cst_score = 0;
207  EnergyMap temp_EMap;
208  core::Real cur_score = 0;
209  bool first_pass = true;
210 
211  for( ConstraintCOPs::const_iterator
212  member_it = member_constraints().begin();
213  member_it != member_constraints().end(); member_it++){
214  temp_EMap.zero(cst_score_types_ );
215  (*member_it)->score( xyz, weights, temp_EMap );
216  cur_score = calculate_total_cst_score( weights, temp_EMap );
217  if ( first_pass || (cur_score < low_total_cst_score ) ){
218  first_pass = false;
219  low_total_cst_score = cur_score;
220  active = *member_it;
221  }
222  }
223 
224  return active;*/
225 }
226 
227 Size
228 AmbiguousConstraint::show_violations( std::ostream& out, pose::Pose const& pose, Size verbose_level, Real threshold ) const
229 {
230  if ( verbose_level >= 70 ) {
231  Size total_viol( 0 );
232  if ( verbose_level >=80 ) { out << type() << " " << member_constraints().size() << " "; }
233  for( ConstraintCOPs::const_iterator
234  cst_it = member_constraints().begin();
235  cst_it != member_constraints().end(); cst_it++) {
236  if ( active_constraint_ ) {
237  if ( (*cst_it).get() == active_constraint_.get() ) {
238  // figure out if it's inter-res, residue_pair, or 3+body
239  utility::vector1< int > pos_list( (*cst_it)->residues() );
240  if ( pos_list.size() == 2 ) {
241  out << "ResiduePairConstraints ( " << pos_list[ 1 ] << " , " << pos_list[ 2 ] << " ) ";
242  if ( verbose_level>80 ) out << std::endl;
243  //out << "active ";
244  total_viol += (*cst_it)->show_violations( out, pose, verbose_level, threshold );
245  out << " of total: " << 1 << " ";
246  }
247  } else {
248  // out << " ";
249  //don't count the violations from this one
250  // (*cst_it)->show_violations( out, pose, verbose_level, threshold );
251  }
252  }
253  }
254  return total_viol;
255  } else {
256  if( active_constraint_ ) return active_constraint_->show_violations( out, pose, verbose_level );
257  else out << "WARNING: requested to show violations of an ambiguous constraint before"
258  <<" the pose was scored and thus, the active constraint selected." << std::endl;
259 
260  return 0;
261  }
262 }
263  /*if ( verbose_level >= 70 ) {
264  Size total_viol( 0 );
265  ConstraintCOP active( active_constraint( ConformationXYZ( pose.conformation()), pose.energies().weights() ) );
266  if ( verbose_level >=80 ) {
267  // out << type() << " " << member_constraints().size() << " ";
268  //for( ConstraintCOPs::const_iterator cst_it = member_constraints().begin(); cst_it != member_constraints().end(); cst_it++) {
269  //if ( active_constraint_ ) {
270  // if ( (*cst_it).get() == active_constraint_.get() ) {
271  // figure out if it's inter-res, residue_pair, or 3+body
272  utility::vector1< int > pos_list;
273  // generate list of all involved residues
274  for ( Size i=1; i<= active->natoms(); ++i ) {
275  int const seqpos( active->atom(i).rsd() );
276  // seqpos already in list?
277  if ( std::find( pos_list.begin(), pos_list.end(), seqpos )== pos_list.end() ) {
278  pos_list.push_back( seqpos );
279  }
280  }
281  if ( pos_list.size() == 2 ) {
282  out << "ResiduePairConstraints ( " << pos_list[ 1 ] << " , " << pos_list[ 2 ] << " ) ";
283  if ( verbose_level>80 ) out << std::endl;
284  //out << "active ";
285  total_viol += active->show_violations( out, pose, verbose_level, threshold );
286  out << " of total: " << 1 << " ";
287  }
288  // } else {
289  // out << " ";
290  //don't count the violations from this one
291  // (*cst_it)->show_violations( out, pose, verbose_level, threshold );
292  // }
293  //}
294  //}
295  return total_viol;
296  } else {
297  return active->show_violations( out, pose, verbose_level );
298  //else out << "WARNING: requested to show violations of an ambiguous constraint before"
299  // <<" the pose was scored and thus, the active constraint selected." << std::endl;
300  //
301  //return 0;
302  }
303  }
304  return 0;*/
305 //}
306 
307 void
309  std::istream & data,
310  core::pose::Pose const & pose,
311  FuncFactory const & func_factory
312 ) {
313  ConstraintOP constr;
314  while( ( constr = ConstraintIO::read_individual_constraint_new( data, pose, func_factory ) ) != 0) {
316  }
317 }
318 
319 } //constraints
320 } //scoring
321 } //core