Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TwoBodyEnergy.hh
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/methods/TwoBodyEnergy.hh
11 /// @brief Two Body Energy Method base class declaration
12 /// @author Andrew Leaver-Fay
13 
14 #ifndef INCLUDED_core_scoring_methods_TwoBodyEnergy_hh
15 #define INCLUDED_core_scoring_methods_TwoBodyEnergy_hh
16 
17 // Unit Headers
19 
20 // Package headers
24 
25 // Project headers
26 
29 #include <core/pose/Pose.fwd.hh>
30 #include <core/id/AtomID.fwd.hh>
31 #include <core/id/TorsionID.fwd.hh>
32 #include <core/id/DOF_ID.fwd.hh>
34 //#include <core/pack/rotamer_set/RotamerSet.fwd.hh>
35 
36 // ObjexxFCL Headers
37 #include <ObjexxFCL/FArray2D.fwd.hh>
38 
39 // Utility Headers
40 #include <utility/vector1.fwd.hh>
41 
43 #include <utility/vector1.hh>
44 
45 
46 /// The Two Body Energy Method specifies an interface for all two body methods: both
47 /// long and short range, both context dependent and independent. Any two body method
48 /// must implement this interface as well as the EnergyMethod interface.
49 ///
50 /// In this inheritance heirarchy, a common interface is defined for both context
51 /// dependent and context independent two body energies. Context dependent two
52 /// body energies require a Pose as context to evaluate the energy and so the interface
53 /// includes a Pose for all energy evaluation calls.
54 ///
55 /// However, context independent methods do not require a pose, and could
56 /// conceivably be evaluated in the absence of one. Is the design compromised
57 /// by demanding a common interface between context independent and context
58 /// dependent two-body methods? Yes and no. The alternatives are 1) to demand
59 /// separate, but nearly identical interfaces for ci2b and cd2b classes in which
60 /// case, the design is compromised by the presence of duplicated code, 2) to
61 /// use multiple inherritance so that the CI2B class could derive from a
62 /// two-body interface (shared with the CD2B class) as well as a contex-independent
63 /// interface (not shared with the CD2B class). The problem is that most of the
64 /// "shared" interface involves evaluating energies, and for the CD classes, this
65 /// requires a Pose. The truely shared interface between CI and CD classes would
66 /// be empty and problem 1 has resurfaced. Moreover, multiple inherritance is
67 /// difficult to work with and should be avoided.
68 ///
69 /// What is the drawback of requiring a pose for a CI2B method evaluation? It makes
70 /// it less clear to the energy-method user (not the energy-method writer) that the
71 /// Pose does not play a role in the evaluation of the ci2b energy. It also makes it
72 /// possible for the energy-method writer to define a context dependent two body method
73 /// while declaring it to be context independent: such an act would produce bizzare
74 /// (wrong) behavior as the innards of the ScoreFunction and the Energies class tried
75 /// to re-use cached scores that were no longer correct. So the warning must be made:
76 ///
77 /// DANGER! DANGER! DANGER!
78 /// If the EnergyMethod writer declares a method to be context independent, it
79 /// had better be!
80 
81 
82 namespace core {
83 namespace scoring {
84 namespace methods {
85 
87 {
88 public:
90 
91 public:
92 
93  /// @brief Constructor, requiring an EnergyMethodCreator. No default constructor provided
94  /// to force EnergyMethod writers to provide an energy-method-creator at construction time.
96 
97  virtual ~TwoBodyEnergy();
98 
99  /// @brief Evaluate the interaction between a given residue pair
100  /// accumulating the unweighted energies in an EnergyMap
101  virtual
102  void
104  conformation::Residue const & rsd1,
105  conformation::Residue const & rsd2,
106  pose::Pose const & pose,
107  ScoreFunction const & sfxn,
108  EnergyMap & emap
109  ) const = 0;
110 
111  /// @brief During minimization, energy methods are allowed to decide that they say nothing
112  /// about a particular residue pair (e.g. no non-zero energy) and as a result they will not be queried for
113  /// a derivative or an energy. The default implementation returns "true" for all residue pairs.
114  /// Context-dependent two-body energies have the option of behaving as if they are context-independent
115  /// by returning "false" for residue pairs that do no move wrt each other.
116  virtual
117  bool
119  conformation::Residue const & res1,
120  conformation::Residue const & res2,
121  bool res_moving_wrt_eachother
122  ) const;
123 
124 
125  /// @brief Rely on the extended version of the residue_pair_energy function during score-function
126  /// evaluation in minimization? The extended version (below) takes a ResPairMinimizationData in which
127  /// the derived base class has (or should have) cached a piece of data that will make residue-pair
128  /// energy evaluation faster than its absense (e.g. a neighbor list). Derived energy methods should
129  /// return 'true' from this function to use the extended interface. The default method implemented
130  /// in this class returns 'false'
131  virtual
132  bool
134 
135  /// @brief Evaluate the two-body energies for a particular residue, in the context of a
136  /// given Pose, and with the help of a piece of cached data for minimization, increment those
137  /// two body energies into the input EnergyMap. The calling function must guarantee that this
138  /// EnergyMethod has had the opportunity to update the input ResPairMinimizationData object
139  /// for the given residues in a call to setup_for_minimizing_for_residue_pair before this function is
140  /// invoked. This function should not be called unless the use_extended_residue_pair_energy_interface()
141  /// method returns "true". Default implementation provided by this base class calls
142  /// utility::exit().
143  virtual
144  void
146  conformation::Residue const & rsd1,
147  conformation::Residue const & rsd2,
148  ResPairMinimizationData const & min_data,
149  pose::Pose const & pose,
150  ScoreFunction const & sfxn,
151  EnergyMap & emap
152  ) const;
153 
154  /// @brief Called at the beginning of minimization, allowing this energy method to cache data
155  /// pertinent for a single residue in the the ResPairMinimizationData that is used for a
156  /// particular residue in the context of a particular Pose. This base class provides a noop
157  /// implementation for this function if there is nothing that the derived class needs to perform
158  /// in this setup phase.
159  virtual
160  void
162  conformation::Residue const & rsd,
163  pose::Pose const & pose,
164  ScoreFunction const & sfxn,
165  kinematics::MinimizerMapBase const & minmap,
166  ResSingleMinimizationData & res_data_cache
167  ) const;
168 
169  /// @brief Called at the beginning of minimization, allowing this energy method to cache data
170  /// pertinent for a single residue in the the ResPairMinimizationData that is used for a
171  /// particular residue in the context of a particular Pose. This base class provides a noop
172  /// implementation for this function if there is nothing that the derived class needs to perform
173  /// in this setup phase.
174  virtual
175  void
177  conformation::Residue const & rsd1,
178  conformation::Residue const & rsd2,
179  pose::Pose const & pose,
180  ScoreFunction const & sfxn,
181  kinematics::MinimizerMapBase const & minmap,
182  ResSingleMinimizationData const & res1_data_cache,
183  ResSingleMinimizationData const & res2_data_cache,
184  ResPairMinimizationData & data_cache
185  ) const;
186 
187  /// @brief Does this EnergyMethod require the opportunity to examine the residue before scoring begins? Not
188  /// all energy methods would. The ScoreFunction will not ask energy methods to examine residues that are uninterested
189  /// in doing so.
190  virtual
191  bool
193 
194  /// @brief Do any setup work should the coordinates of this residue (who is still guaranteed to be
195  /// of the same residue type as when setup_for_minimizing_for_residue was called) have changed so dramatically
196  /// as to possibly require some amount of setup work before scoring should proceed.
197  /// This function is used for both intra-residue setup and pre-inter-residue setup
198  virtual
199  void
201  conformation::Residue const & rsd,
202  pose::Pose const & pose,
203  ScoreFunction const & sfxn,
204  ResSingleMinimizationData & min_data
205  ) const;
206 
207  /// @brief Does this EnergyMethod require the opportunity to examine each residue before derivative evaluation begins? Not
208  /// all energy methods would. The ScoreFunction will not ask energy methods to examine residue pairs that are uninterested
209  /// in doing so.
210  virtual
211  bool
213 
214  /// @brief Do any setup work necessary before evaluating the derivatives for this residue
215  virtual
216  void
218  conformation::Residue const & rsd,
219  pose::Pose const & pose,
220  ScoreFunction const & sfxn,
221  ResSingleMinimizationData & min_data
222  ) const;
223 
224  /// @brief Does this EnergyMethod require the opportunity to examine each residue pair before scoring begins? Not
225  /// all energy methods would. The ScoreFunction will not ask energy methods to examine residue pairs that are uninterested
226  /// in doing so.
227  virtual
228  bool
230 
231  /// @brief Do any setup work should the coordinates of a pair of residues, who are still guaranteed to be
232  /// of the same residue type as when setup_for_minimizing_for_residue was called, have changed so dramatically
233  /// as to possibly require some amount of setup work before scoring should proceed
234  virtual
235  void
237  conformation::Residue const & rsd1,
238  conformation::Residue const & rsd2,
239  ResSingleMinimizationData const & minsingle_data1,
240  ResSingleMinimizationData const & minsingle_data2,
241  pose::Pose const & pose,
242  ScoreFunction const & sfxn,
243  ResPairMinimizationData & data_cache
244  ) const;
245 
246  /// @brief Does this EnergyMethod require the opportunity to examine each residue pair before derivative evaluation begins? Not
247  /// all energy methods would. The ScoreFunction will not ask energy methods to examine residue pairs that are uninterested
248  /// in doing so.
249  virtual
250  bool
252 
253  /// @brief Do any setup work necessary before evaluating the derivatives for this residue pair
254  virtual
255  void
257  conformation::Residue const & rsd1,
258  conformation::Residue const & rsd2,
259  ResSingleMinimizationData const & minsingle_data1,
260  ResSingleMinimizationData const & minsingle_data2,
261  pose::Pose const & pose,
262  ScoreFunction const & sfxn,
263  ResPairMinimizationData & data_cache
264  ) const;
265 
266  /// @brief Evaluate the derivative for an atom in rsd1 with respect to rsd2 in the context
267  /// of a particular pose, and increment the F1 and F2 vectors. This base class provides a
268  /// default noop implementation of this function. The calling function must guarantee that this
269  /// EnergyMethod has had the opportunity to update the input ResPairMinimizationData object for
270  /// the given residue in a call to prepare_for_minimization before this function is invoked.
271  /// DEPRECATED. Too slow. Too much overhead for each atom; slowed fast-relax runs by ~40%.
272  /*virtual
273  void
274  eval_atom_derivative_for_residue_pair(
275  Size const atom_index,
276  conformation::Residue const & rsd1,
277  conformation::Residue const & rsd2,
278  ResSingleMinimizationData const & minsingle_data1,
279  ResSingleMinimizationData const & minsingle_data2,
280  ResPairMinimizationData const & minpair_data,
281  pose::Pose const & pose, // provides context
282  kinematics::DomainMap const & domain_map,
283  ScoreFunction const & sfxn,
284  EnergyMap const & weights,
285  Vector & F1,
286  Vector & F2
287  ) const;*/
288 
289  /// @brief Evaluate the derivatives for all atoms on rsd1 and rsd2 with respect
290  /// to each other and increment the derivatives in atom-derivatives vector1s.
291  /// The calling function must guarantee that the r1_atom_derivs vector1 holds at
292  /// least as many entries as there are atoms in rsd1, and that the r2_atom_derivs
293  /// vector1 holds at least as many entries as there are atoms in rsd2.
294  virtual
295  void
297  conformation::Residue const & rsd1,
298  conformation::Residue const & rsd2,
301  ResPairMinimizationData const & min_data,
302  pose::Pose const & pose, // provides context
303  EnergyMap const & weights,
304  utility::vector1< DerivVectorPair > & r1_atom_derivs,
305  utility::vector1< DerivVectorPair > & r2_atom_derivs
306  ) const;
307 
308  ///@brief Evaluate the interaction between the backbone of rsd1 and the
309  /// backbone of rsd2 and accumulate the unweighted energies. The sum
310  /// bb_bb(r1,r2) + bb_sc(r1,r2) + bb_sc(r2,r1) + sc_sc( r1,r2) must
311  /// equal the weighted result of a call to residue_pair_energy.
312  /// By default, bb_bb & bb_sc return 0 and sc_sc returns
313  /// residue pair energy.
314  virtual
315  void
317  conformation::Residue const & rsd1,
318  conformation::Residue const & rsd2,
319  pose::Pose const & pose,
320  ScoreFunction const & sfxn,
321  EnergyMap & emap
322  ) const;
323 
324 
325  ///@brief Evaluate the interaction between the backbone of rsd1 and the
326  /// sidechain of rsd2 and accumulate the unweighted energies. The sum
327  /// bb_bb(r1,r2) + bb_sc(r1,r2) + bb_sc(r2,r1) + sc_sc( r1,r2) must
328  /// equal the unweighted result of a call to residue_pair_energy.
329  /// By default, bb_bb & bb_sc return 0 and sc_sc returns
330  /// residue pair energy.
331  virtual
332  void
334  conformation::Residue const & rsd1,
335  conformation::Residue const & rsd2,
336  pose::Pose const & pose,
337  ScoreFunction const & sfxn,
338  EnergyMap & emap
339  ) const;
340 
341  ///@brief Evaluate the interaction between the sidechain of rsd1 and the
342  /// sidechain of rsd2 and accumulate the unweighted energies. The sum
343  /// bb_bb(r1,r2) + bb_sc(r1,r2) + bb_sc(r2,r1) + sc_sc( r1,r2) must
344  /// equal the unweighted result of a call to residue_pair_energy.
345  /// By default, bb_bb & bb_sc return 0 and sc_sc returns
346  /// residue pair energy.
347  virtual
348  void
350  conformation::Residue const & rsd1,
351  conformation::Residue const & rsd2,
352  pose::Pose const & pose,
353  ScoreFunction const & sfxn,
354  EnergyMap & emap
355  ) const;
356 
357  /// @brief Two body energies are able to define intra-residue energies, and to do so
358  /// only in the presence of certain non-zero weights. The ScoreFunction will hand over its
359  /// weight set as it asks whether the energy method defines an intraresidue energy or not.
360  ///
361  /// For example, the Etable method defines intra-residue energies only when one or more
362  /// of the fa_intra_{atr,rep,sol} weights are non-zero.
363  virtual
364  bool
365  defines_intrares_energy( EnergyMap const & weights ) const = 0;
366 
367  /// @brief Evaluate the intra-residue energy for a given residue
368  virtual
369  void
371  conformation::Residue const & rsd,
372  pose::Pose const & pose,
373  ScoreFunction const & sfxn,
374  EnergyMap & emap
375  ) const = 0;
376 
377  /// @brief If a score function defines no intra-residue scores for a particular
378  /// residue, then it may opt-out of being asked during minimization to evaluate
379  /// the score for this residue.
380  virtual
381  bool
383  conformation::Residue const & res
384  ) const;
385 
386  /// @brief Derived classes wishing to invoke the alternate, extended interface for eval_intrares_energy
387  /// during minimization routines should return "true" when this function is invoked on them. This
388  /// class provides a default "return false" implementation so that classes not desiring to take advantage
389  /// of this alternate interface need to do nothing.
390  virtual
391  bool
393 
394  /// @brief Evaluate the intra-residue energy for a given residue using the data held within the
395  /// ResSingleMinimizationData object. This function should be invoked only on derived instances
396  /// of this class if they return "true" in a call to their use_extended_intrares_energy_interface
397  /// method. This base class provides a noop implementation for classes that do not implement this
398  /// interface, or that do not define intrares energies.
399  virtual
400  void
402  conformation::Residue const & rsd,
403  ResSingleMinimizationData const & data_cache,
404  pose::Pose const & pose,
405  ScoreFunction const & sfxn,
406  EnergyMap & emap
407  ) const;
408 
409 
410  /// @brief Evaluate the derivative for the intra-residue component of this energy method
411  /// for all the atoms in a residue in the context of a particular pose,
412  /// and increment the F1 and F2 vectors held in the atom_derivs vector1.
413  /// This base class provides a default noop implementation
414  /// of this function. The calling function must guarantee that this EnergyMethod has had the
415  /// opportunity to update the input ResSingleMinimizationData object for the given residue
416  /// in a call to prepare_for_minimization before this function is invoked.
417  /// The calling function must also guarantee that there are at least as many entries
418  /// in the atom_derivs vector1 as there are atoms in the input rsd.
419  virtual
420  void
422  conformation::Residue const & rsd,
423  ResSingleMinimizationData const & min_data,
424  pose::Pose const & pose,
425  EnergyMap const & weights,
427  ) const;
428 
429  /// @brief Use the dof_derivative interface for this energy method when
430  /// calculating derivatives? It is possible to define both dof_derivatives and
431  /// atom-derivatives; they are not mutually exclusive.
432  virtual
433  bool
434  defines_intrares_dof_derivatives( pose::Pose const & p ) const;
435 
436  /// @brief Evaluate the DOF derivative for a particular residue. The Pose merely serves as context,
437  /// and the input residue is not required to be a member of the Pose.
438  virtual
439  Real
441  conformation::Residue const & rsd,
442  ResSingleMinimizationData const & min_data,
443  id::DOF_ID const & dof_id,
444  id::TorsionID const & torsion_id,
445  pose::Pose const & pose,
446  ScoreFunction const & sfxn,
447  EnergyMap const & weights
448  ) const;
449 
450 
451  // @brief Low fidelity evaluation of sc/bb + sc/sc energy.
452  // Do not define in derived class if that class should not be
453  // used in the packer's bump-check phase.
454  virtual
455  void
457  conformation::Residue const &,
458  conformation::Residue const &,
459  pose::Pose const &,
460  ScoreFunction const &,
461  EnergyMap &
462  ) const;
463 
464  // @brief Low fidelity evaluation of sc/bb energy.
465  // Do not define in derived class if that class should not be
466  // used in the packer's bump-check phase.
467  virtual
468  void
470  conformation::Residue const &,
471  conformation::Residue const &,
472  pose::Pose const &,
473  ScoreFunction const &,
474  EnergyMap &
475  ) const;
476 
477  /// @brief Batch computation of rotamer intrares energies. Need not be overriden in
478  /// derived class -- by default, iterates over all rotamers,
479  /// and calls derived class's intrares _energy method.
480  virtual
481  void
483  conformation::RotamerSetBase const & set,
484  pose::Pose const & pose,
485  ScoreFunction const & sfxn,
487  ) const;
488 
489  /// @brief Batch computation of rotamer intrares energy map. Need not be overriden in
490  /// derived class -- by default, iterates over all rotamers,
491  /// and calls derived class's intrares _energy method.
492  virtual
493  void
495  conformation::RotamerSetBase const & set,
496  pose::Pose const & pose,
497  ScoreFunction const & sfxn,
499  ) const;
500 
501  /// @brief Batch computation of rotamer pair energies. Need not be overriden in
502  /// derived class -- by default, iterates over all pairs of rotamers,
503  /// and calls the derived class's residue_pair_energy method.
504  virtual
505  void
507  conformation::RotamerSetBase const & set1,
508  conformation::RotamerSetBase const & set2,
509  pose::Pose const & pose,
510  ScoreFunction const & sfxn,
511  EnergyMap const & weights,
512  ObjexxFCL::FArray2D< core::PackerEnergy > & energy_table
513  ) const;
514 
515  /// @brief Batch computation of rotamer/background energies. Need not be overriden
516  /// in derived class -- by default, iterates over all rotamers in the set, and calls
517  /// derived class's residue_pair_energy method for each one against the background rotamr
518  virtual
519  void
521  conformation::RotamerSetBase const & set,
522  conformation::Residue const & residue,
523  pose::Pose const & pose,
524  ScoreFunction const & sfxn,
525  EnergyMap const & weights,
527  ) const;
528 
529  /// @brief Batch computation of rotamer/background energies. Need not be overriden
530  /// in derived class -- by default, iterates over all rotamers in the set, and calls
531  /// derived class's residue_pair_energy method for each one against the background rotamr
532  virtual
533  void
535  conformation::RotamerSetBase const & set,
536  conformation::Residue const & residue,
537  pose::Pose const & pose,
538  ScoreFunction const & sfxn,
539  EnergyMap const & weights,
541  ) const;
542 
543  /* I don't think we have any two-body energy methods that define torsion energies, but if
544  we did, then we would want to implement the following function
545  virtual
546  Real
547  eval_residue_pair_dof_derivative(
548  conformation::Residue const & rsd1,
549  conformation::Residue const & rsd2,
550  id::DOF_ID const & dof_id,
551  id::TorsionID const & torsion_id,
552  pose::Pose const & pose,
553  ScoreFunction const & sfxn,
554  EnergyMap const & weights
555  ) const;*/
556 
557 
558 };
559 
560 }
561 }
562 }
563 
564 #endif