Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MinimizationGraph.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/MinimizationGraph.hh
11 /// @brief Minimization graph class declaration
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_core_scoring_MinimizationGraph_hh
15 #define INCLUDED_core_scoring_MinimizationGraph_hh
16 
17 // Unit Headers
19 
20 // Package Headers
27 
28 #ifdef WIN32
31 #endif
32 
33 // Project headers
34 #include <core/graph/Graph.hh>
35 #include <core/types.hh>
37 #include <core/id/TorsionID.fwd.hh>
38 #include <core/id/DOF_ID.fwd.hh>
39 // AUTO-REMOVED #include <core/kinematics/DomainMap.fwd.hh>
42 #include <core/pose/Pose.fwd.hh>
43 
44 // Utility headers
45 #include <utility/pointer/ReferenceCount.hh>
46 
47 // C++ headers
48 #include <list>
49 
50 #include <utility/vector1.hh>
51 
52 
53 namespace core {
54 namespace scoring {
55 
56 /// Class MinimizationNode holds the ResSingleMinimizationData information for
57 /// a single residue in a Pose which is being minimized. The data held in this
58 /// node will be used in both scoring the residue one-body energies and evaluating
59 /// atom derivatives during minimization.
61 {
62 public:
66 
68  typedef OneBodyEnergies::const_iterator OneBodyEnergiesIterator;
69 
71  typedef TwoBodyEnergies::const_iterator TwoBodyEnergiesIterator;
73  typedef pose::Pose Pose;
74 
75 public:
76  MinimizationNode( graph::Graph * owner, Size index );
77  virtual ~MinimizationNode();
78  virtual void copy_from( parent const * source );
79 
80  virtual void print() const;
81  virtual Size count_static_memory() const;
82  virtual Size count_dynamic_memory() const;
83 
86 
87  bool add_onebody_enmeth( OneBodyEnergyCOP enmeth, Residue const & rsd, Pose const & pose, int domain_map_color );
88  bool add_twobody_enmeth(
89  TwoBodyEnergyCOP enmeth,
90  Residue const & rsd,
91  Pose const & pose,
92  EnergyMap const & weights,
93  int domain_map_color
94  );
95 
97  Residue const & rsd,
98  Pose const & pose,
99  ScoreFunction const & sfxn,
100  kinematics::MinimizerMapBase const & min_map
101  );
102  void setup_for_scoring( Residue const & rsd, Pose const & pose, ScoreFunction const & sfxn );
103  void setup_for_derivatives( Residue const & rsd, pose::Pose const & pose, ScoreFunction const & sfxn );
105  Residue const & rsd,
106  pose::Pose const & pose,
107  EnergyMap const & weights,
108  int domain_map_color
109  );
110 
111  Real weight() const { return weight_; }
112  void weight( Real setting ) { weight_ = setting; }
113 
114 private:
118  void add_sfs_1benmeth( OneBodyEnergyCOP enmeth );
119  void add_sfd_1benmeth( OneBodyEnergyCOP enmeth );
120 
124  void add_sfs_2benmeth( TwoBodyEnergyCOP enmeth );
125  void add_sfd_2benmeth( TwoBodyEnergyCOP enmeth );
126 
127  bool classify_onebody_enmeth( OneBodyEnergyCOP enmeth, Residue const & rsd, Pose const & pose,int domain_map_color );
129  TwoBodyEnergyCOP enmeth,
130  Residue const & rsd,
131  Pose const & pose,
132  EnergyMap const & weights,
133  int domain_map_color
134  );
135 
136 public:
149 
162 
163 private:
164 
166 
167  // The list of all acive and inactive 1body energy methods; inactive methods are not used during score evaluation,
168  // but they might become active if the residue-type changes at this position.
170  // The list of all active 1body energy methods
172  // one-body energy methods that evaluate a residue energy for this
173  // residue using the standard residue_energy() interface
175  // one-body energy methods that evaluate a residue energy for this
176  // residue using the residue_energy_ext() interface
178  // one-body energy methods that define DOF derivatives
180  // one-body energy methods that require a setup-for-scoring (sfs) opportunity
182  // one-body energy methods that require a setup-for-derivatives (sfd) opportunity
184 
185 
186  // The list of all active and inactive 2body energy methods; inactive methods are not used during score evaluation,
187  // but they might become active if the residue-type changes at this position.
189 
190  // The list of all active 2body energy methods that define an intraresidue energy
192  // two-body energy methods that define an intra-residue energy for this
193  // residue using the eval_intrares_energy() interface
195  // two-body energy methods that define an intra-residue energy for this
196  // residue using the eval_intrares_energy_ext() interface
198  // two-body energy methods that define DOF derivatives
200  // two-body energy methods that require a setup-for-scoring (sfs) opportunity
202  // two-body energy methods that require a setup-for-derivatives (sfs) opportunity
204 
206 };
207 
208 /// Class MinimizationEdge holds ResPairMinimizationData for a certain pair
209 /// of interacting residues; this data might be a neighborlist for this residue
210 /// pair, for example. The data held in this edge will be used in both scoring
211 /// the residue-pair energies and evaluating atom derivatives during minimization.
213 {
214 public:
218  typedef TwoBodyEnergies::const_iterator TwoBodyEnergiesIterator;
220  typedef pose::Pose Pose;
221 
222 public:
223  MinimizationEdge( MinimizationGraph * owner, Size n1, Size n2 );
224  MinimizationEdge( MinimizationGraph * owner, MinimizationEdge const & example_edge );
225  virtual ~MinimizationEdge();
226 
227  /// @brief Copy the data held on the example edge, source.
228  /// The source edge must be castable to class MinimizationEdge.
229  virtual void copy_from( parent const * source );
230 
233 
234  virtual Size count_static_memory() const;
235  virtual Size count_dynamic_memory() const;
236 
237  /// @brief Include a particular energy method as part of this edge. It may not show up
238  /// in the active energy methods should this energy method not define an energy for the
239  /// residues.
240  bool add_twobody_enmeth( TwoBodyEnergyCOP enmeth, Residue const & rsd1, Residue const & rsd2, Pose const & pose, bool residues_mwrt_eachother );
241 
242  /// @brief It may be possible to determine that an edge does not need to belong to the
243  /// minimization graph if there are no active two-body energy methods; this is a convenience
244  /// function that answers quickly if active_2benmths_.begin() == active_2benmeths_.end().
245  bool any_active_enmeths() const {
246  return ! active_2benmeths_.empty();
247  }
248 
250  Residue const & rsd1,
251  Residue const & rsd2,
252  pose::Pose const & pose,
253  ScoreFunction const & sfxn,
254  kinematics::MinimizerMapBase const & min_map
255  );
256 
257  /// @brief Initialize the active energy methods for score function evaluation
258  void setup_for_scoring( Residue const & rsd1, Residue const & rsd2, Pose const & pose, ScoreFunction const & sfxn );
259 
260  /// @brief Initialize the active energy methods for derivative evaluation
261  void setup_for_derivatives( Residue const & rsd1, Residue const & rsd2, Pose const & pose, ScoreFunction const & sfxn );
262 
263  /// @brief Setup the active and inactive energy methods
265  Residue const & rsd1,
266  Residue const & rsd2,
267  Pose const & pose,
268  bool res_moving_wrt_eachother
269  );
270 
271 private:
274  void add_sfs_enmeth( TwoBodyEnergyCOP enmeth );
275  void add_sfd_enmeth( TwoBodyEnergyCOP enmeth );
276 
278  TwoBodyEnergyCOP enmeth,
279  Residue const & rsd1,
280  Residue const & rsd2,
281  Pose const & pose,
282  bool res_moving_wrt_eachother
283  );
284 
285 public:
296 
297 
298  /// @brief The minimization graph will allow the storage of edge weights, should that
299  /// prove useful for any application (e.g. symmetric minimization)
300  Real weight() const { return weight_; }
301  /// @brief Set the weight for an edge
302  void weight( Real setting ) { weight_ = setting; }
303 
304 protected:
305  /// Downcasts
306 
307  inline
308  MinimizationGraph const *
309  get_minimization_owner() const;
310 
311  inline
314 
315  inline
318  return static_cast< MinimizationNode * > ( get_node( index ) );
319  }
320 
321  inline
322  MinimizationNode const *
323  get_minimization_node( Size index ) const {
324  return static_cast< MinimizationNode const * > ( get_node( index ) );
325  }
326 
327 private:
328 
330 
331  // The list of all active and inactive two-body energy methods for this position
333  // The list of all two-body energy methods that define a residue pair energy
334  // for this residue pair
336  // two-body energy methods that define a residue pair energy for this
337  // residue using the residue_pair_energy() interface
339  // two-body energy methods that define an intra-residue energy for this
340  // residue using the residue_pair_energy_ext() interface
342  // two-body energy methods that require a setup-for-scoring opportunity for
343  // this residue pair
345  // two-body energy methods that require a setup-for-derivatives opportunity for
346  // this residue pair
348 
350 
351 };
352 
353 /// @brief Class to hold all the minimization-specific data that's required
354 /// to efficiently evaluate the score function and its derivatives on a structure
355 /// of fixed sequence and chemical identity.
357 {
358 public:
361  typedef std::list< EnergyMethodCOP > Energies;
362  typedef Energies::const_iterator EnergiesIterator;
363 
364 public:
365  virtual ~MinimizationGraph();
366 
369  MinimizationGraph( MinimizationGraph const & src );
370 
371  MinimizationGraph const & operator = ( MinimizationGraph const & rhs );
372 
373  inline
374  MinimizationNode const *
376  {
377  return static_cast< MinimizationNode const * > ( get_node( index ));
378  }
379 
380  inline
383  {
384  return static_cast< MinimizationNode * > ( get_node( index ));
385  }
386 
387 
389  MinimizationEdge const * find_minimization_edge( Size n1, Size n2) const;
390 
391  virtual void delete_edge( graph::Edge * edge );
392 
396 
397  void set_fixed_energies( EnergyMap const & );
398  EnergyMap const & fixed_energies() const;
399 
400 protected:
401  virtual Size count_static_memory() const;
402  virtual Size count_dynamic_memory() const;
403 
404  virtual graph::Node * create_new_node( Size index );
405  virtual graph::Edge * create_new_edge( Size index1, Size index2 );
406  virtual graph::Edge * create_new_edge( graph::Edge const * example_edge );
407 
408 private:
412 
413 };
414 
415 
416 MinimizationGraph const *
418  return static_cast< MinimizationGraph const * > (get_owner());
419 }
420 
421 
424  return static_cast< MinimizationGraph * > (get_owner());
425 }
426 
427 //// Non member functions for score and derivative evaluation when using a minimization graph
428 
429 /*void
430 reinitialize_minedge_for_respair(
431  MinimizationEdge & min_edge,
432  conformation::Residue const & rsd1,
433  conformation::Residue const & rsd2,
434  ResSingleMinimizationData const & res1_ressingle_min_data,
435  ResSingleMinimizationData const & res2_ressingle_min_data,
436  pose::Pose & p,
437  ScoreFunction const & sfxn,
438  kinematics::MinimizerMapBase const & minmap
439 );*/
440 
441 /*void
442 setup_for_scoring_for_minnode(
443  MinimizationNode & min_node,
444  conformation::Residue const & rsd,
445  pose::Pose const & pose
446 );*/
447 
448 /*void
449 setup_for_scoring_for_minedge(
450  MinimizationEdge & min_edge,
451  conformation::Residue const & rsd1,
452  conformation::Residue const & rsd2,
453  pose::Pose const & pose,
454  ResSingleMinimizationData const & res1_ressingle_min_data,
455  ResSingleMinimizationData const & res2_ressingle_min_data
456 );*/
457 
458 /*void
459 setup_for_derivatives_for_minnode(
460  MinimizationNode & min_node,
461  conformation::Residue const & rsd,
462  pose::Pose const & pose
463 );*/
464 
465 /*void
466 setup_for_derivatives_for_minedge(
467  MinimizationEdge & min_edge,
468  conformation::Residue const & rsd1,
469  conformation::Residue const & rsd2,
470  pose::Pose const & pose,
471  ResSingleMinimizationData const & res1_min_data,
472  ResSingleMinimizationData const & res2_min_data
473 );*/
474 
475 /// @brief Evaluate the derivatives for all atoms on the input residue
476 /// for the terms that apply to this residue (which are stored on the input
477 /// minimization node).
478 void
480  MinimizationNode const & min_node,
481  conformation::Residue const & rsd,
482  pose::Pose const & pose,
483  EnergyMap const & res_weights,
485 );
486 
487 /// @brief Deprecated
488 /*void
489 eval_atom_derivative_for_minnode(
490  MinimizationNode const & min_node,
491  Size atom_index,
492  conformation::Residue const & rsd,
493  pose::Pose const & pose,
494  kinematics::DomainMap const & domain_map,
495  ScoreFunction const & sfxn,
496  EnergyMap const & res_weights,
497  Vector & F1, // accumulated into
498  Vector & F2 // accumulated into
499 );*/
500 
501 void
503  MinimizationNode const & min_node,
504  conformation::Residue const & rsd,
505  pose::Pose const & pose,
506  ScoreFunction const & sfxn,
507  EnergyMap & emap // accumulated into
508 );
509 
510 void
512  MinimizationEdge const & min_edge,
513  conformation::Residue const & res1,
514  conformation::Residue const & res2,
515  ResSingleMinimizationData const & res1_min_data,
516  ResSingleMinimizationData const & res2_min_data,
517  pose::Pose const & pose,
518  EnergyMap const & respair_weights,
519  utility::vector1< DerivVectorPair > & r1atom_derivs,
521 );
522 
523 /// @brief Deprecated
524 /*void
525 eval_atom_deriv_for_minedge(
526  MinimizationEdge const & min_edge,
527  Size atom_index,
528  conformation::Residue const & res1,
529  conformation::Residue const & res2,
530  ResSingleMinimizationData const & res1_min_data,
531  ResSingleMinimizationData const & res2_min_data,
532  pose::Pose const & pose,
533  kinematics::DomainMap const & domain_map,
534  ScoreFunction const & sfxn,
535  EnergyMap const & respair_weights,
536  Vector & F1, // accumulated into
537  Vector & F2 // accumulated into
538 );*/
539 
540 void
542  MinimizationEdge const & min_edge,
543  conformation::Residue const & res1,
544  conformation::Residue const & res2,
545  pose::Pose const & pose,
546  ScoreFunction const & sfxn,
547  EnergyMap & emap
548 );
549 
550 Real
552  MinimizationNode const & min_node,
553  conformation::Residue const & rsd,
554  pose::Pose const & pose,
555  id::DOF_ID const & dof_id,
556  id::TorsionID const & torsion_id,
557  ScoreFunction const & sfxn,
558  EnergyMap const & weights
559 );
560 
561 /*void
562 eval_weighted_atom_derivative_for_minnode(
563  MinimizationNode const & min_node,
564  Size atom_index,
565  conformation::Residue const & rsd,
566  pose::Pose const & pose,
567  kinematics::DomainMap const & domain_map,
568  ScoreFunction const & sfxn,
569  EnergyMap const & res_weights,
570  Vector & F1, // accumulated into
571  Vector & F2 // accumulated into
572 );*/
573 
574 void
576  MinimizationNode const & min_node,
577  conformation::Residue const & rsd,
578  pose::Pose const & pose,
579  ScoreFunction const & sfxn,
580  EnergyMap & emap, // accumulated into
581  EnergyMap & scratch_emap // should be zeros coming in, left zeroed at the end;
582 );
583 
584 
585 /*void
586 eval_weighted_atom_deriv_for_minedge(
587  MinimizationEdge const & min_edge,
588  Size atom_index,
589  conformation::Residue const & res1,
590  conformation::Residue const & res2,
591  ResSingleMinimizationData const & res1_min_data,
592  ResSingleMinimizationData const & res2_min_data,
593  pose::Pose const & pose,
594  kinematics::DomainMap const & domain_map,
595  ScoreFunction const & sfxn,
596  EnergyMap const & respair_weights,
597  Vector & F1, // accumulated into
598  Vector & F2 // accumulated into
599 );*/
600 
601 void
603  MinimizationEdge const & min_edge,
604  conformation::Residue const & res1,
605  conformation::Residue const & res2,
606  pose::Pose const & pose,
607  ScoreFunction const & sfxn,
608  EnergyMap & emap,
609  EnergyMap & scratch_emap // should be zeros coming in, left zeroed at the end;
610 );
611 
612 Real
614  MinimizationNode const & min_node,
615  conformation::Residue const & rsd,
616  pose::Pose const & pose,
617  id::DOF_ID const & dof_id,
618  id::TorsionID const & torsion_id,
619  ScoreFunction const & sfxn,
620  EnergyMap const & weights
621 );
622 
623 
624 } //namespace scoring
625 } //namespace core
626 
627 #endif
628