Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MultiConstraint.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 multiple other constrains that belong to each other and are all evaluate at once
12 /// @author Florian Richter (floric@u.washington.edu, march 2008)
13 
18 #include <numeric/random/random.hh>
19 
20 #include <basic/Tracer.hh>
21 
22 #include <utility/vector1.hh>
23 
24 static basic::Tracer tr("core.io.constraints");
25 
26 namespace core {
27 namespace scoring {
28 namespace constraints {
29 
30 ////////////////////////////////////////////////////////////////////////////////////////////////////
31 ///@details read definition of a multiconstraint. Since a MultiConstraint is essentially a vector of ?????? (Please someone finish this)
32 void
34  std::istream& data,
35  core::pose::Pose const& pose,
36  FuncFactory const & func_factory
37 )
38 {
39  Size ct ( 0 );
40  ConstraintCOP cst_op = ConstraintIO::get_instance()->read_individual_constraint_new( data, pose, func_factory );
41  if ( cst_op ) ct++;
42  while ( cst_op ) {
43  add_individual_constraint( cst_op );
44  cst_op = ConstraintIO::get_instance()->read_individual_constraint_new( data, pose, func_factory );
45  if ( cst_op ) ct++;
46  }
47  if ( member_constraints_.size() > 0 ) {
48  if ( tr.Debug.visible() ) {
49  show_def(tr.Debug,pose);
50  tr.Debug << std::endl;
51  }
52  } else {
53  tr.Error << "ERROR: " << type() << " read_def: no constraints defined! " << ct << " " << size() << std::endl;
54  }
55 }
56 
57 /// @detail this function only checks whether the member_constraints_
58 /// are identical. should mean by inference that the member_residues_, member_atoms_
59 /// and AtomID_to_Csts_ are also identical
60 bool
61 MultiConstraint::operator == ( Constraint const & other_cst ) const
62 {
63  if( !dynamic_cast< MultiConstraint const * > ( &other_cst ) ) return false;
64 
65  MultiConstraint const & other( static_cast< MultiConstraint const & > (other_cst) );
66 
68 
69  core::Size num_csts = member_constraints_.size();
70  if( num_csts != other.member_constraints_.size() ) return false;
71  for( core::Size i =1; i <= num_csts; ++i){
72  if( *(member_constraints_[i]) != *(other.member_constraints_[i]) ) return false;
73  }
74  if( this->score_type() != other.score_type() ) return false;
75 
76  return true;
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////////////////////////
80 void
81 MultiConstraint::score( XYZ_Func const & xyz_func, EnergyMap const & weights, EnergyMap & emap ) const
82 {
83  for( ConstraintCOPs::const_iterator member_it = member_constraints_.begin(); member_it != member_constraints_.end(); member_it++){
84  (*member_it)->score( xyz_func, weights, emap );
85  }
86 }
87 ////////////////////////////////////////////////////////////////////////////////////////////////////
88 /// @brief Constructor
90  Constraint( t ), //this is temporary, multi constraint shouldn't have a score type
91  report_this_as_effective_sequence_separation_( 0 )
92 {
93  for( ConstraintCOPs::const_iterator it = cst_in.begin(); it != cst_in.end(); it++ ) {
95  } //loop over all input csts that make up this multi constraint
96 }// constructor
97 ////////////////////////////////////////////////////////////////////////////////////////////////////
98 void
100 {
101  member_constraints_.push_back( cst_in );
102 
103  //examine this constraint with respect to whether it contains
104  //not yet seen atoms
105  for( Size i = 1; i <= cst_in->natoms(); i++){
106  AtomID cur_atomid = cst_in->atom(i);
107 
108  if ( std::find( member_residues_.begin(), member_residues_.end(), cur_atomid.rsd() ) == member_residues_.end() ) {
109  member_residues_.push_back( cur_atomid.rsd() );
110  }
111 
112  std::map< AtomID, ConstraintCOPs >::iterator map_it = AtomID_to_Csts_.find(cur_atomid);
113 
114  //if it does, add the atom id to the atom_members and the atomid/vect pair to the map
115  if( map_it == AtomID_to_Csts_.end() ) {
116  member_atoms_.push_back(cur_atomid);
117  ConstraintCOPs cst_vect;
118  cst_vect.push_back( cst_in );
119 
120  AtomID_to_Csts_.insert( std::pair< AtomID, ConstraintCOPs > (cur_atomid, cst_vect) );
121  } else{ //if it doesn't we have to add this constraint to the right list in the map
122  map_it->second.push_back( cst_in );
123  }
124  }
125 }
126 
127  //@brief translates the atom-names into numbers
128 void MultiConstraint::setup_for_scoring( XYZ_Func const & xyz, ScoreFunction const & scfxn) const {
129  for ( ConstraintCOPs::const_iterator cst_it = member_constraints_.begin(); cst_it != member_constraints_.end(); ++cst_it ) {
130  (*cst_it)->setup_for_scoring( xyz, scfxn );
131  }
132 }
133 
134 
137 {
138  ConstraintCOPs new_csts;
139  for( ConstraintCOPs::const_iterator cst_it = member_constraints_.begin(); cst_it != member_constraints_.end(); ++cst_it ){
140  ConstraintOP new_cst = (*cst_it)->remap_resid( seqmap );
141  if( new_cst ) new_csts.push_back( new_cst );
142  }
143  if( new_csts.size() > 0 ){
144  return ConstraintOP( new MultiConstraint( new_csts ) );
145  }
146  else return NULL;
147 }
148 
150  pose::Pose const& src,
151  pose::Pose const& dest,
152  id::SequenceMappingCOP map ) const
153 {
154  MultiConstraintOP new_multi = empty_clone();
155  for ( ConstraintCOPs::const_iterator it = member_constraints_.begin();
156  it != member_constraints_.end(); ++it ) {
157  new_multi->add_individual_constraint( (*it)->remapped_clone( src, dest, map ) );
158  }
159  return new_multi;
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////////////////////////
163 /// @brief function that figures out what constraints this atom is part of
164 /// and calculates the derivative for those
165 void
167  AtomID const & atom,
168  XYZ_Func const & xyz,
169  Vector & F1,
170  Vector & F2,
171  EnergyMap const & weights
172 ) const
173 {
174 
175  //std::cout << "we are in a multicst containing the following atoms (test AtomID is " << atom.rsd() << " " << atom.atomno() << ": ";
176  // for(Size i = 1; i <= member_atoms_.size(); i++){
177  //std::cout << member_atoms_[i].rsd() << " " << member_atoms_[i].atomno() << " ";
178  // }
179  //std::cout << ", the atom map has " << AtomID_to_Csts_.size() << " atoms." << std::endl;
180 
181  std::map< AtomID, ConstraintCOPs >::const_iterator map_it = AtomID_to_Csts_.find(atom);
182 
183  if ( map_it != AtomID_to_Csts_.end() ) {
184  ConstraintCOPs cur_csts = map_it->second;
185  //std::cout << "now taking deriv of atom " << map_it->first.atomno() << " , vector 1 element before is " << F1[1];
186 
187  for( ConstraintCOPs::const_iterator cst_it = cur_csts.begin(); cst_it != cur_csts.end(); cst_it++ ){
188  //std::cout << ", type of cst is " << (*cst_it)->score_type() << ", ";
189  (*cst_it)->fill_f1_f2(atom, xyz, F1, F2, weights);
190  }
191  //std::cout << " and after " << F1[1] << std::endl;
192 
193  } else return;
194 }
195 
196 void
197 MultiConstraint::show( std::ostream& out) const
198 {
199  out << "MultiConstraint containing the following " << member_constraints_.size() << " constraints: "
200  << std::endl;
201  for( ConstraintCOPs::const_iterator cst_it = member_constraints_.begin(); cst_it != member_constraints_.end(); cst_it++){
202  (*cst_it)->show(out);
203  }
204 
205  out << " ...all member constraints of this MultiConstraint shown." << std::endl;
206 }
207 
208 void MultiConstraint::show_def( std::ostream& out, pose::Pose const& pose ) const {
209  out << type() << std::endl;
210  for( ConstraintCOPs::const_iterator cst_it = member_constraints().begin(); cst_it != member_constraints().end(); cst_it++){
211  (*cst_it)->show_def( out, pose );
212  }
213  out << "End_"<< type() << std::endl;
214 }
215 
216 Size
217 MultiConstraint::show_violations( std::ostream& out, pose::Pose const& pose, Size verbose_level, Real threshold ) const
218 {
219  if( verbose_level > 80 ) out << "Violations for MultiConstraint: " << std::endl;
220 
221  core::Size biggest_violation(0);
222  for( ConstraintCOPs::const_iterator cst_it = member_constraints_.begin(); cst_it != member_constraints_.end(); cst_it++){
223  core::Size cur_viol = (*cst_it)->show_violations( out, pose, verbose_level, threshold);
224  if (cur_viol > biggest_violation ) biggest_violation = cur_viol;
225  }
226  return biggest_violation;
227 }
228 
232  numeric::random::RandomGenerator& RG
233 ) {
234  utility::vector1< core::Size > collected_seq_separations;
235  ConstraintCOPs const& cst_list( member_constraints() );
236  for ( ConstraintCOPs::const_iterator cst_it = cst_list.begin(); cst_it != cst_list.end(); ++cst_it ) {
237  Size seq_sep( 0 );
238  Constraint& cst = const_cast< Constraint& >( **cst_it );
239  seq_sep = cst.choose_effective_sequence_separation( sp, RG );
240  collected_seq_separations.push_back( seq_sep );
241  }
242  Size index = static_cast< Size >( collected_seq_separations.size()*RG.uniform() ) + 1;
243  report_this_as_effective_sequence_separation_ = collected_seq_separations[ index ];
245 }
246 
247 
248 } //constraints
249 } //scoring
250 } //core