IMP logo
IMP Reference Guide  2.10.0
The Integrative Modeling Platform
ScoreState.h
Go to the documentation of this file.
1 /**
2  * \file IMP/ScoreState.h \brief Shared score state.
3  *
4  * Copyright 2007-2018 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPKERNEL_SCORE_STATE_H
9 #define IMPKERNEL_SCORE_STATE_H
10 
11 #include <IMP/kernel_config.h>
12 #include <IMP/WeakPointer.h>
13 #include "DerivativeAccumulator.h"
14 #include "utility.h"
15 #include "ModelObject.h"
16 #include "base_types.h"
17 #include <IMP/check_macros.h>
18 #include <IMP/deprecation_macros.h>
19 #include <IMP/ref_counted_macros.h>
20 #include <iostream>
21 
22 IMPKERNEL_BEGIN_NAMESPACE
23 //! ScoreStates maintain invariants in the Model.
24 /** ScoreStates allow actions to be taken before and after the restraint
25  evaluation process. Such code can be used to, for example:
26  - log the optimization process
27  - maintain constraints (see Constraint)
28 
29  ScoreStates have two methods which are called during
30  the Model::evaluate() function
31  - before_evaluate() which is allowed to change the contents of
32  containers and the value of attributes of particles and
33  - after_evaluate() which can change particle derivatives
34 
35  The Model uses information that the ScoreState reports about
36  its input and output containers and particles to determine a safe
37  order in which all the ScoreState objects registered in the model
38  can be applied. That is, the Model will ensure that a ScoreState
39  that has Particle \c A in its output list is applied before a
40  ScoreState that has \c A in its input list.
41  For ScoreState::before_evaluate(), Input and output lists are
42  returned by the respective get_input_* and get_output_* calls.
43  For ScoreState::after_evaluate() they are reversed (see note below).
44 
45  \note The input and output sets for the ScoreState::after_evaluate()
46  functions are assumed to be the reverse of the ScoreState::before_evaluate()
47  functions. As a result, the ScoreStates are applied in opposite order
48  after evaluate. If you have a ScoreState for which this is not true,
49  consider splitting it into two parts.
50 
51  \see Model::add_score_state().
52  */
53 class IMPKERNELEXPORT ScoreState : public ModelObject {
54  int update_order_;
55 
56  public:
57  ScoreState(Model *m, std::string name);
58  //! Force update of the structure.
59  void before_evaluate();
60 
61  //! Do post evaluation work if needed
62  void after_evaluate(DerivativeAccumulator *accpt);
63 
64 #ifndef IMP_DOXYGEN
65  bool get_has_update_order() const { return update_order_ != -1; }
66  unsigned int get_update_order() const { return update_order_; }
68 
69 #endif
70 
71  protected:
72  // Update the state given the current state of the model.
73  /* This is also called prior to every calculation of the model score.
74  It should be implemented by ScoreStates in order to provide functionality.
75  */
76  virtual void do_before_evaluate() = 0;
77 
78  // Do any necessary updates after the model score is calculated.
79  /* \param[in] accpt The object used to scale derivatives in the score
80  calculation, or nullptr if derivatives were not
81  requested.
82  */
83  virtual void do_after_evaluate(DerivativeAccumulator *accpt) = 0;
84 
86 };
87 
88 /** Return an appropriate (topologically sorted) order to update
89  the score states in. */
90 IMPKERNELEXPORT ScoreStatesTemp get_update_order(ScoreStatesTemp input);
91 
92 IMPKERNEL_END_NAMESPACE
93 
94 #endif /* IMPKERNEL_SCORE_STATE_H */
Control display of deprecation information.
Various general useful macros for IMP.
Basic types used by IMP.
Class for adding derivatives from restraints to the model.
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Ref counted objects should have private destructors.
A more IMP-like version of the std::vector.
Definition: Vector.h:39
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
ScoreStates maintain invariants in the Model.
Definition: ScoreState.h:53
virtual void handle_set_has_required_score_states(bool)
Definition: ModelObject.h:69
A nullptr-initialized pointer to an Object.
For backwards compatibility.
Single variable function.
Exception definitions and assertions.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.
ScoreStatesTemp get_update_order(ScoreStatesTemp input)