Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConstraintsEnergy.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 core/scoring/constraints/ConstraintsEnergy.hh
11 /// @brief Constraints Energy Method declaration
12 /// @author Andrew Leaver-Fay
13 
14 // Unit headers
17 
18 // Package headers
23 
27 
28 // Project headers
30 #include <core/pose/Pose.hh>
31 #include <core/scoring/Energies.hh>
32 //#include <core/scoring/ScoringManager.hh>
33 
34 // utility headers
35 #include <basic/Tracer.hh>
36 #include <basic/prof.hh>
37 
38 #include <utility/vector1.hh>
39 
40 
41 
42 namespace core {
43 namespace scoring {
44 namespace constraints {
45 
46 /// @details This must return a fresh instance of the ConstraintsEnergy class,
47 /// never an instance already in use
51 ) const {
52  return new ConstraintsEnergy;
53 }
54 
57  ScoreTypes sts;
58  sts.push_back( atom_pair_constraint );
59  sts.push_back( angle_constraint );
60  sts.push_back( dihedral_constraint );
61  sts.push_back( constant_constraint );
62  sts.push_back( coordinate_constraint );
63  sts.push_back( dof_constraint );
64  sts.push_back( res_type_constraint );
65  sts.push_back( res_type_linking_constraint );
66  sts.push_back( backbone_stub_constraint );
67  sts.push_back( big_bin_constraint );
68  sts.push_back( dunbrack_constraint );
69  sts.push_back( pocket_constraint );
70  sts.push_back( rna_bond_geometry );
71  sts.push_back( metalhash_constraint );
72  return sts;
73 }
74 
75 
76 static basic::Tracer tr( "core.scoring.ConstraintsEnergy");
77 
79 
81 
84 {
85  return new ConstraintsEnergy;
86 }
87 
90 
91 
92 bool
94  pose::Pose const & pose,
95  Size res1,
96  Size res2
97 ) const
98 {
99  return pose.constraint_set()->residue_pair_constraint_exists( res1, res2 );
100 }
101 
102 /// @brief Evaluate constraint residue_pair_energy. Defers entirely to cst_set.
103 void
105  conformation::Residue const & rsd1,
106  conformation::Residue const & rsd2,
107  pose::Pose const & pose,
108  ScoreFunction const & sfxn,
109  EnergyMap & emap
110 ) const
111 {
112  if ( pose.constraint_set() == 0 ) return;
113  // PROF_START( basic::CONSTRAINT_SCORE );
114  pose.constraint_set()->residue_pair_energy( rsd1, rsd2, pose, sfxn, emap );
115  // PROF_STOP( basic::CONSTRAINT_SCORE );
116 }
117 
118 bool
120 
121 bool
123 {
124  return true;
125 }
126 
127 void
129  conformation::Residue const & rsd1,
130  conformation::Residue const & rsd2,
131  ResPairMinimizationData const & min_data,
132  pose::Pose const & , //pose,
133  ScoreFunction const & sfxn,
134  EnergyMap & emap
135 ) const
136 {
137  CstMinimizationDataCOP res_cst = static_cast< CstMinimizationData const * > ( min_data.get_data( cst_respair_data )() );
138  if (!res_cst) return;
139  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
140  res_cst->constraints().residue_pair_energy( rsd1, rsd2, sfxn.weights(), emap );
141 }
142 
143 bool
145  conformation::Residue const &,
146  conformation::Residue const &,
147  bool res_moving_wrt_eachother
148 ) const
149 {
150  return res_moving_wrt_eachother;
151 }
152 
153 void
155  conformation::Residue const & rsd,
156  pose::Pose const & pose,
157  ScoreFunction const & sfxn,
158  kinematics::MinimizerMapBase const & minmap,
159  ResSingleMinimizationData & res_data_cache
160 ) const
161 {
162  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
163  pose.constraint_set()->setup_for_minimizing_for_residue( rsd, pose, sfxn, minmap, res_data_cache );
164 }
165 
166 void
168  conformation::Residue const & rsd1,
169  conformation::Residue const & rsd2,
170  pose::Pose const & pose,
171  ScoreFunction const & sfxn,
172  kinematics::MinimizerMapBase const & minmap,
173  ResSingleMinimizationData const & res1_data_cache,
174  ResSingleMinimizationData const & res2_data_cache,
175  ResPairMinimizationData & respair_data_cache
176 ) const
177 {
178  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
179  pose.constraint_set()->setup_for_minimizing_for_residue_pair(
180  rsd1, rsd2, pose, sfxn, minmap,
181  res1_data_cache, res2_data_cache, respair_data_cache );
182 }
183 
184 bool
186 {
187  return true;
188 }
189 
190 void
192  conformation::Residue const & rsd1,
193  conformation::Residue const & rsd2,
196  pose::Pose const &,
197  ScoreFunction const & sfxn,
198  ResPairMinimizationData & data_cache
199 ) const
200 {
201  CstMinimizationDataOP res_cst = static_cast< CstMinimizationData * > ( data_cache.get_data( cst_respair_data )() );
202  if (!res_cst) return;
203  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
204  res_cst->constraints().setup_for_scoring( ResiduePairXYZ( rsd1, rsd2 ), sfxn );
205 
206 }
207 
208 bool
210 {
211  return true;
212 }
213 
214 void
216  conformation::Residue const & rsd1,
217  conformation::Residue const & rsd2,
220  pose::Pose const &,
221  ScoreFunction const & sfxn,
222  ResPairMinimizationData & data_cache
223 ) const
224 {
225  CstMinimizationDataOP res_cst = static_cast< CstMinimizationData * > ( data_cache.get_data( cst_respair_data )() );
226  if (!res_cst) return;
227  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
228  res_cst->constraints().setup_for_derivatives( ResiduePairXYZ( rsd1, rsd2 ), sfxn );
229 }
230 
231 /*void
232 ConstraintsEnergy::eval_atom_derivative_for_residue_pair(
233  Size const atom_index,
234  conformation::Residue const & rsd1,
235  conformation::Residue const & rsd2,
236  ResSingleMinimizationData const &,// minsingle_data1,
237  ResSingleMinimizationData const &,// minsingle_data2,
238  ResPairMinimizationData const & minpair_data,
239  pose::Pose const & pose, // provides context
240  kinematics::DomainMap const &,// domain_map,
241  ScoreFunction const & ,//sfxn,
242  EnergyMap const & weights,
243  Vector & F1,
244  Vector & F2
245 ) const
246 {
247  CstMinimizationDataCOP res_cst = static_cast< CstMinimizationData const * > ( minpair_data.get_data( cst_respair_data )() );
248  if (!res_cst) return;
249  res_cst->constraints().eval_respair_atom_derivative(
250  id::AtomID( atom_index, rsd1.seqpos() ), rsd1, rsd2, weights, F1, F2 );
251 }*/
252 
253 void
255  conformation::Residue const & rsd1,
256  conformation::Residue const & rsd2,
259  ResPairMinimizationData const & min_data,
260  pose::Pose const &,
261  EnergyMap const & weights,
262  utility::vector1< DerivVectorPair > & r1_atom_derivs,
263  utility::vector1< DerivVectorPair > & r2_atom_derivs
264 ) const
265 {
266  CstMinimizationDataCOP res_cst = static_cast< CstMinimizationData const * > ( min_data.get_data( cst_respair_data )() );
267  if (!res_cst) return;
268  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
269  for ( Size ii = 1; ii <= rsd1.natoms(); ++ii ) {
270  res_cst->constraints().eval_respair_atom_derivative(
271  id::AtomID( ii, rsd1.seqpos() ), rsd1, rsd2, weights, r1_atom_derivs[ ii ].f1(), r1_atom_derivs[ ii ].f2() );
272  }
273  for ( Size ii = 1; ii <= rsd2.natoms(); ++ii ) {
274  res_cst->constraints().eval_respair_atom_derivative(
275  id::AtomID( ii, rsd2.seqpos() ), rsd2, rsd1, weights, r2_atom_derivs[ ii ].f1(), r2_atom_derivs[ ii ].f2() );
276  }
277 
278 }
279 
280 
281 
282 /////////////////////////////////////////////////////////////////////////////
283 // methods for ContextIndependentTwoBodyEnergies
284 /////////////////////////////////////////////////////////////////////////////
285 
286 /// @brief Intraresidue constraints can exist; the ConstraintsEnergy class
287 /// cannot tell whether or not any intraresidue constraints exist when only
288 /// given the weight set, so for safety it says "yes, I define intraresidue
289 /// energies" and guarantees they will be evaluated properly if they do exist.
290 bool
292 {
293  return true;
294 }
295 
296 /// @brief Evaluate the intra-residue constraint energy for a given residue
297 void
299  conformation::Residue const & rsd,
300  pose::Pose const & pose,
301  ScoreFunction const & sfxn,
302  EnergyMap & emap
303 ) const
304 {
305  if ( pose.constraint_set() == 0 ) return;
306  // PROF_START( basic::CONSTRAINT_SCORE );
307  pose.constraint_set()->eval_intrares_energy( rsd, pose, sfxn, emap );
308  // PROF_STOP( basic::CONSTRAINT_SCORE );
309 }
310 
311 /// @brief request of minimization routines that they use the extended intraresidue energy
312 /// interface
313 bool
315 {
316  return true;
317 }
318 
319 /// @brief Evaluate the intra-residue energies using ConstraintCOPs cached in the data_cache object
320 void
322  conformation::Residue const & rsd,
323  ResSingleMinimizationData const & data_cache,
324  pose::Pose const &,
325  ScoreFunction const & sfxn,
326  EnergyMap & emap
327 ) const
328 {
329  CstMinimizationDataCOP res_cst = static_cast< CstMinimizationData const * > ( data_cache.get_data( cst_res_data )() );
330  if (!res_cst) return;
331  res_cst->constraints().intra_residue_energy( rsd, sfxn.weights(), emap );
332 }
333 
334 bool
336 {
337  return true;
338 }
339 
340 
341 void
343  conformation::Residue const & rsd,
344  pose::Pose const &,
345  scoring::ScoreFunction const & sfxn,
346  ResSingleMinimizationData & min_data
347 ) const
348 {
349  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
350  CstMinimizationDataOP res_cst = static_cast< CstMinimizationData * > ( min_data.get_data( cst_res_data )() );
351  if (!res_cst) return;
352  res_cst->constraints().setup_for_scoring( ResidueXYZ( rsd ), sfxn );
353 }
354 
355 
356 bool
358 {
359  return true;
360 }
361 
362 
363 void
365  conformation::Residue const & rsd,
366  pose::Pose const &,
367  scoring::ScoreFunction const & sfxn,
368  ResSingleMinimizationData & min_data
369 ) const
370 {
371  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
372  CstMinimizationDataOP res_cst = static_cast< CstMinimizationData * > ( min_data.get_data( cst_res_data )() );
373  if (!res_cst) return;
374  res_cst->constraints().setup_for_derivatives( ResidueXYZ( rsd ), sfxn );
375 }
376 
377 /*void
378 ConstraintsEnergy::eval_intrares_atom_derivative(
379  Size const atom_index,
380  conformation::Residue const & rsd,
381  ResSingleMinimizationData const & min_data,
382  pose::Pose const &,
383  kinematics::DomainMap const &,
384  ScoreFunction const & ,
385  EnergyMap const & weights,
386  Vector & F1,
387  Vector & F2
388 ) const
389 {
390  CstMinimizationDataCOP res_cst = static_cast< CstMinimizationData const * > ( min_data.get_data( cst_res_data )() );
391  if (!res_cst) return;
392  res_cst->constraints().eval_intrares_atom_derivative(
393  id::AtomID( atom_index, rsd.seqpos() ), rsd, weights, F1, F2 );
394 }*/
395 
396 void
398  conformation::Residue const & rsd,
399  ResSingleMinimizationData const & min_data,
400  pose::Pose const &,
401  EnergyMap const & weights,
403 ) const
404 {
405  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
406  CstMinimizationDataCOP res_cst = static_cast< CstMinimizationData const * > ( min_data.get_data( cst_res_data )() );
407  if (!res_cst) return;
408  for ( Size ii = 1; ii <= rsd.natoms(); ++ii ) {
409  res_cst->constraints().eval_intrares_atom_derivative(
410  id::AtomID( ii, rsd.seqpos() ), rsd, weights,
411  atom_derivs[ ii ].f1(), atom_derivs[ ii ].f2() );
412  }
413 
414 }
415 
416 bool
418 {
419  // Only a handful of constraints actually define dof derivatives, but it's hard to know
420  // in advance if any of those constraints are in the ConstraintSet; maybe if dof-deriv
421  // defining constraints had to be held in a special place in the constraint set, they'd
422  // be easier to find and access?
423  return true;
424 }
425 
426 /// @brief Evaluate the DOF derivative for a particular residue. The Pose merely serves as context,
427 /// and the input residue is not required to be a member of the Pose.
428 Real
430  conformation::Residue const &,// rsd,
431  ResSingleMinimizationData const &,// min_data,
432  id::DOF_ID const &,// dof_id,
433  id::TorsionID const &,// torsion_id,
434  pose::Pose const &,// pose,
435  ScoreFunction const &,// sfxn,
436  EnergyMap const &// weights
437 ) const
438 {
439  return 0.0;
440 }
441 
442 // @brief store a constraint graph in the pose.energies object, or if one is
443 // already present, make sure that the constraint graph accurately reflects
444 // the constraint set. The constraint energy container keeps the revision id
445 // for a particular constraint set. If a pose constraint set changes, either
446 // in identity (i.e. a new object) or in composition (i.e. an addition/removal
447 // of a constraint) then thene ConstraintsEnergy object throws away the old
448 // ConstraintsEnergyContainer and creats a new one... somewhat wasteful.
449 //
450 // In the future, either the CE or the ConstraintSet will have to intelligently
451 // decide between a constraint graph or a constraint table. In the case of
452 // dense residue pair constraints (i.e. all pairs), a table would be more efficient.
453 void
455 {
456  using namespace methods;
457 
458  //do nothing if there are no constraints
459  if ( pose.constraint_set() == 0 ) return; //this will never happen: since empty constraint_set is created as soon as method constraint_set() is called
460  // however, if one jumps out here after asking !has_constraints() it breaks in ScoringFunction.cc:604 because the
461  // long_rang_container is not setup for constraints.
462  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
463  Energies & energies( pose.energies() );
464  bool create_new_cstcontainer( false );
465  if ( energies.long_range_container( constraints_lr ) == 0 ) {
466  create_new_cstcontainer = true; // pbmod
467  } else {
468  LREnergyContainerOP lrc = energies.nonconst_long_range_container( constraints_lr );
469  CstEnergyContainerOP cec( static_cast< CstEnergyContainer * > ( lrc.get() ) );
470  if ( ! cec->matches( pose.constraint_set()) ) {
471  create_new_cstcontainer = true;
472  }
473  }
474 
475  if ( create_new_cstcontainer ) {
476  CstEnergyContainerOP new_cec = new CstEnergyContainer( pose );
477  energies.set_long_range_container( constraints_lr, new_cec );
478  }
479 
480 }
481 
482 void
484 {
486  if ( pose.constraint_set() ) {
487  pose.constraint_set()->setup_for_scoring( pose, sfxn ); //fpd
488  }
489 }
490 
491 void
493  pose::Pose & pose,
494  utility::vector1< bool > const &,
496 ) const
497 {
499 }
500 
501 ///@brief Setup constraint-set specific derivatives
502 void
504 {
505  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
506  pose.constraint_set()->setup_for_derivatives( pose, sfxn ); //fpd
507 }
508 
509 bool
511 {
512  return pose.constraint_set()->has_non_residue_pair_constraints();
513 }
514 
515 
516 /// @brief called at the end of energy evaluation; allows
517 /// for the evaluation of constraints that cannot be
518 /// decomposed into residue pairs. Defers entirely to cst_set.
519 void
521  pose::Pose & pose,
522  ScoreFunction const & sfxn,
523  EnergyMap & totals
524 ) const
525 {
526  if ( pose.constraint_set() == 0 ) return;
527  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
528  pose.constraint_set()->eval_non_residue_pair_energy( pose, sfxn, totals );
529 }
530 
531 
532 /// called during gradient-based minimization inside dfunc
533 /**
534  F1 and F2 are not zeroed -- contributions from this atom are
535  just summed in
536 **/
537 void
539  id::AtomID const & id,
540  pose::Pose const & pose,
541  kinematics::DomainMap const &, // domain_map,
542  ScoreFunction const & sfxn,
543  EnergyMap const & weights,
544  Vector & F1,
545  Vector & F2
546 ) const
547 {
548  if ( !pose.constraint_set()->has_constraints() ) return;
549  // basic::ProfileThis doit( basic::CONSTRAINT_SCORE );
550  pose.constraint_set()->eval_multibody_atom_derivative( id, pose, sfxn, weights, F1, F2 );
551 }
552 
553 /// uses the dof constraints -- depricated interface
554 Real
556  id::DOF_ID const &,// id,
557  id::TorsionID const &,// tor,
558  pose::Pose const &,// pose,
559  ScoreFunction const &,// scorefxn,
560  EnergyMap const & // weights
561 ) const
562 {
563  // if ( pose.constraint_set() == 0 ) return 0.0;
564  //this -- oddly -- never happens, since the pose will make an empty set as soon as you ask.
565 
566  // instead...
567  //if ( ! pose.constraint_set()->has_constraints() ) return 0.0;
568  //PROF_START( basic::CONSTRAINT_SCORE );
569  //Real result ( pose.constraint_set()->eval_dof_derivative( id, tor, pose, scorefxn, weights ) );
570  //PROF_STOP( basic::CONSTRAINT_SCORE );
571  return 0.0;
572 }
573 
574 
575 /// @brief constraints are context independent
576 void
579 ) const
580 {}
583 {
584  return 1; // Initial versioning
585 }
586 
587 
588 
589 
590 
591 } // constraints
592 } // scoring
593 } // core