IMP logo
IMP Reference Guide  2.14.0
The Integrative Modeling Platform
IncrementalScoringFunction.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/IncrementalScoringFunction.h
3  * \brief Score model efficiently when a small number of particles are changed.
4  *
5  * Copyright 2007-2020 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPCORE_INCREMENTAL_SCORING_FUNCTION_H
10 #define IMPCORE_INCREMENTAL_SCORING_FUNCTION_H
11 
12 #include <IMP/core/core_config.h>
13 #include <IMP/Pointer.h>
14 #include <IMP/base_types.h>
17 #include <boost/unordered_map.hpp>
18 
19 IMPCORE_BEGIN_NAMESPACE
20 
21 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
22 namespace internal {
23 class NBLScoring;
24 }
25 #endif
26 
27 //! Score the model efficiently when a small number of particles are changed.
28 /** This is a scoring function that computes the score efficiently when a small
29  number of particles are changed.
30  \note At the moment moves of one particle at a time are handled most
31  efficiently.
32  \note Only full evaluation is supported and information about restraint
33  sets and such are lost (and so one can't count on information about
34  whether the score is good).
35 
36  To ensure proper evaluation, the ScoringFunction is divided into a number
37  of sub scoring functions, one for each possibly moved particle.
38 */
39 class IMPCOREEXPORT IncrementalScoringFunction : public ScoringFunction {
40  struct Data {
42  Ints indexes;
43  };
44  /* have to make sure that when the dependencies are reset on destruction,
45  the map is in a well defined state (and not in the middle of its
46  destructor).
47  Otherwise, ~IncrementalScoringFunction -> map destructor
48  -> Model::set_has_dependencies()
49  -> IncrementalScoringFunction::do_set_has_dependencies()
50  -> map destructor -> boom
51  */
52  struct ScoringFunctionsMap
53  : public boost::unordered_map<ParticleIndex, Data> {
54  ~ScoringFunctionsMap();
55  };
56  ScoringFunctionsMap scoring_functions_;
57  ParticleIndexes all_;
58  ParticleIndexes last_move_;
59  ParticleIndexes dirty_;
60  Restraints flattened_restraints_;
61  Floats flattened_restraints_scores_;
62  double weight_, max_;
63  PointerMember<ScoringFunction> non_incremental_;
64  // move the destructor out of the header
65  struct Wrapper : public Vector<internal::NBLScoring *> {
66  ~Wrapper();
67  };
68  Wrapper nbl_;
69  void create_flattened_restraints(const RestraintsTemp &rs);
70  void create_scoring_functions();
71  void do_non_incremental_evaluate();
72  Data create_data(ParticleIndex pi, RestraintsTemp cr,
73  const boost::unordered_map<Restraint *, int> &all,
74  const Restraints &dummies) const;
75 
76  public:
77  //! Constructor.
78  /** Pass the particles that will be individually moved, and the list of
79  restraints to evaluate on them.
80 
81  @param m Model object containing all particles to be moved
82  @param to_move particles to be moved; must contain at least one particle
83  @param rs restraints (can be empty in principle, in which case the score
84  is 0)
85  @param weight the weight used to scale the restraints
86  @param max maximum value for evaluate_if_good or evaluate_if_below;
87  can be ignored for most purposes
88  @param name The name template to use for the scoring function.
89 */
91  const ParticleIndexes &to_move,
92  const RestraintsTemp &rs,
93  double weight = 1.0, double max = NO_MAX,
94  std::string name =
95  "IncrementalScoringFunction%1%");
96 
97  //! Undo the last moved particles.
98  /** This is similar in effect to, but perhaps
99  more efficient than, calling set_moved_particles() a second time with
100  the same list.
101  */
102  void reset_moved_particles();
103 
104  //! Set which particles have moved since the last evaluate.
105  void set_moved_particles(const ParticleIndexes &p);
106 
107  /** Close pairs scores can be handled separately for efficiency, to do that,
108  add a pair score here to act on the list of particles.*/
109  void add_close_pair_score(PairScore *ps, double distance,
110  const ParticlesTemp &particles,
111  const PairPredicates &filters);
112  void add_close_pair_score(PairScore *ps, double distance,
113  const ParticlesTemp &particles);
114  void clear_close_pair_scores();
115  ParticleIndexes get_movable_indexes() const;
117  const ScoreStatesTemp &ss) IMP_OVERRIDE;
118  virtual Restraints create_restraints() const IMP_OVERRIDE;
122 };
123 
124 IMPCORE_END_NAMESPACE
125 
126 #endif /* IMPCORE_INCREMENTAL_SCORING_FUNCTION_H */
virtual void do_add_score_and_derivatives(ScoreAccumulator sa, const ScoreStatesTemp &ss)=0
Abstract class for scoring object(s) of type ParticleIndexPair.
Definition: PairScore.h:37
const double NO_MAX
Use this value when you want to turn off maximum for restraint evaluation.
Basic types used by IMP.
virtual Restraints create_restraints() const =0
Return a set of restraints equivalent to this scoring function.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:146
Class for adding up scores during ScoringFunction evaluation.
virtual void handle_set_has_required_score_states(bool)
Definition: ModelObject.h:69
A nullptr-initialized pointer to an IMP Object.
Represents a scoring function on the model.
Functions to search over vectors.
Score the model efficiently when a small number of particles are changed.
Storage of a model, its restraints, constraints and particles.
virtual ModelObjectsTemp do_get_inputs() const =0
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.