Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Constraints.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
12 
13 // Unit headers
15 
16 // Package headers
19 
20 // AUTO-REMOVED #include <core/scoring/EnergyMap.hh>
21 #include <core/pose/Pose.fwd.hh>
22 
23 // Utility Headers
24 
25 // C++ Headers
26 #include <algorithm>
27 
28 #include <utility/vector1.hh>
29 #include <numeric/xyzVector.hh>
30 
31 
32 namespace core {
33 namespace scoring {
34 namespace constraints {
35 
36 /// @details Auto-generated virtual destructor
38 
40 {}
41 
43  ReferenceCount()
44 {
45  copy_from( other );
46 }
47 
48 
49 
52 {
53 
54  ConstraintsOP new_constraints = new Constraints();
55  new_constraints->copy_from( *this );
56  return new_constraints;
57 }
58 
59 Constraints const &
61 {
62  copy_from( rhs );
63  return *this;
64 }
65 
66 
67 void
69  for ( ConstraintCOPs::const_iterator
70  iter = other.constraints_.begin(), iter_end = other.constraints_.end();
71  iter != iter_end; ++iter ) {
72  // All Constraints are now immutable, and so do not ever need to be cloned.
73  //constraints_.push_back( (*iter)->clone() );
74  constraints_.push_back( (*iter) );
75  }
76 }
77 
78 // call the setup_for_derivatives for each constraint
79 void
80 Constraints::setup_for_scoring( XYZ_Func const & xyz, ScoreFunction const &scfxn ) const {
81  for ( ConstraintCOPs::const_iterator it= constraints_.begin(), ite=constraints_.end();
82  it != ite; ++it ) {
83  (*it)->setup_for_scoring( xyz, scfxn );
84  }
85 }
86 
87 // call the setup_for_derivatives for each constraint
88 void
90  for ( ConstraintCOPs::const_iterator it= constraints_.begin(), ite=constraints_.end();
91  it != ite; ++it ) {
92  (*it)->setup_for_derivatives( xyz, scfxn );
93  }
94 }
95 
96 
97 void
99  id::AtomID const & atom_id,
100  conformation::Residue const & residue,
101  EnergyMap const & weights,
102  Vector & F1,
103  Vector & F2
104 ) const
105 {
106  ResidueXYZ resxyz( residue );
107  for ( ConstraintCOPs::const_iterator it= constraints_.begin(), ite=constraints_.end();
108  it != ite; ++it ) {
109  Constraint const & cst( **it );
110  Vector f1(0.0), f2(0.0);
111  cst.fill_f1_f2( atom_id, resxyz, f1, f2, weights );
112  F1 += f1;
113  F2 += f2;
114  }
115 }
116 
117 void
119  id::AtomID const & atom_id,
120  conformation::Residue const & residue1,
121  conformation::Residue const & residue2,
122  EnergyMap const & weights,
123  Vector & F1,
124  Vector & F2
125 ) const
126 {
127  ResiduePairXYZ respairxyz( residue1, residue2 );
128  for ( ConstraintCOPs::const_iterator it= constraints_.begin(), ite=constraints_.end();
129  it != ite; ++it ) {
130  Constraint const & cst( **it );
131  Vector f1(0.0), f2(0.0);
132  cst.fill_f1_f2( atom_id, respairxyz, f1, f2, weights );
133  F1 += f1;
134  F2 += f2;
135  }
136 }
137 
138 void
140  id::AtomID const & atom_id,
141  conformation::Conformation const & conformation,
142  EnergyMap const & weights,
143  Vector & F1,
144  Vector & F2
145 ) const
146 {
147  ConformationXYZ confxyz( conformation );
148  for ( ConstraintCOPs::const_iterator it= constraints_.begin(), ite=constraints_.end();
149  it != ite; ++it ) {
150  Constraint const & cst( **it );
151  Vector f1(0.0), f2(0.0);
152  cst.fill_f1_f2( atom_id, confxyz, f1, f2, weights );
153  F1 += f1;
154  F2 += f2;
155  }
156 }
157 
158 
159 
160 /// private
161 /// does not zero the emap entries before accumulating
162 ///
163 void
165  XYZ_Func const & xyz_func,
166  EnergyMap const & weights,
167  EnergyMap & emap
168 ) const
169 {
170  for ( ConstraintCOPs::const_iterator it=constraints_.begin(), ite = constraints_.end(); it != ite; ++it ) {
171  Constraint const & cst( **it );
172  cst.score( xyz_func, weights, emap );
173  //cst.show( std::cout );
174  }
175 }
176 
177 /// will fail if Residues dont contain all the necessary atoms
178 void
180  Residue const & rsd1,
181  Residue const & rsd2,
182  EnergyMap const & weights,
183  EnergyMap & emap
184 ) const
185 {
186  ResiduePairXYZ const xyz_func( rsd1, rsd2 );
187  energy( xyz_func, weights, emap );
188 }
189 
190 /// will fail if Residues dont contain all the necessary atoms
191 void
193  Residue const & rsd,
194  EnergyMap const & weights,
195  EnergyMap & emap
196 ) const
197 {
198  ResidueXYZ const xyz_func( rsd );
199  energy( xyz_func, weights, emap );
200 }
201 
202 ///
203 void
205  Conformation const & conformation,
206  EnergyMap const & weights,
207  EnergyMap & emap
208 ) const
209 {
210  ConformationXYZ const xyz_func( conformation );
211  energy( xyz_func, weights, emap );
212 }
213 
214 ///
215 void
217 {
218  constraints_.push_back( cst );
219 }
220 
223 
224 
225 /// @details If this list contains the same constraint multiple times,
226 /// only one copy of it is removed.
227 /// I can't imagine *why* that scenario would ever come up, but still...
228 /// flo jan '11 added object_comparison bool that triggers removal of
229 /// constraint if the actual constraints are identical, even though
230 /// they're different objects
231 bool
233  ConstraintCOP cst,
234  bool object_comparison
235 )
236 {
237 
238  if( object_comparison ){
239  for( ConstraintCOPs::iterator cst_it = constraints_.begin(), cst_end = constraints_.end(); cst_it != cst_end; ++cst_it ){
240 
241  if( *cst == **cst_it ){
242  constraints_.erase( cst_it );
243  return true;
244  }
245  }
246  return false;
247  }
248 
249  ConstraintCOPs::iterator where = std::find( constraints_.begin(), constraints_.end(), cst );
250  if( where == constraints_.end() ) return false;
251  constraints_.erase( where );
252  return true;
253 }
254 
255 void
256 Constraints::show( std::ostream & out ) {
257  for ( ConstraintCOPs::const_iterator it=constraints_.begin(), ite = constraints_.end();
258  it != ite;
259  ++it ) {
260  Constraint const & cst( **it );
261  cst.show( out );
262  }
263 }
264 
265 void
267  std::ostream & out,
268  pose::Pose const & pose
269 ) const {
270  for ( ConstraintCOPs::const_iterator it=constraints_.begin(), ite = constraints_.end();
271  it != ite;
272  ++it ) {
273  Constraint const & cst( **it );
274  cst.show_def( out, pose );
275  }
276 }
277 
278 Size
280  std::ostream& out,
281  pose::Pose const & pose,
282  Size verbose_level,
283  Real threshold
284 ) {
285  Size total_viol( 0 );
286  Size total_cst( 0 );
287  for ( ConstraintCOPs::const_iterator it=constraints_.begin(), ite = constraints_.end();
288  it != ite;
289  ++it ) {
290  Constraint const & cst( **it );
291  total_viol+=cst.show_violations( out, pose, verbose_level, threshold );
292  total_cst++;
293  }
294  if ( verbose_level > 60 ) out << " of total: " << total_cst << " ";
295  return total_viol;
296 }
297 
298 Size
300 {
301  return constraints_.size();
302 }
303 
304 void
306 {
307  constraints_.clear();
308 }
309 
310 } // constraints
311 } // scoring
312 } // core