IMP logo
IMP Reference Guide  2.19.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-2022 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  \deprecated_at{2.17} Use IMP::ScoringFunction::evaluate_moved instead.
40 */
41 class IMPCOREEXPORT IncrementalScoringFunction : public ScoringFunction {
42  struct Data {
44  Ints indexes;
45  };
46  /* have to make sure that when the dependencies are reset on destruction,
47  the map is in a well defined state (and not in the middle of its
48  destructor).
49  Otherwise, ~IncrementalScoringFunction -> map destructor
50  -> Model::set_has_dependencies()
51  -> IncrementalScoringFunction::do_set_has_dependencies()
52  -> map destructor -> boom
53  */
54  struct ScoringFunctionsMap
55  : public boost::unordered_map<ParticleIndex, Data> {
56  ~ScoringFunctionsMap();
57  };
58  ScoringFunctionsMap scoring_functions_;
59  ParticleIndexes all_;
60  ParticleIndexes last_move_;
61  ParticleIndexes dirty_;
62  Restraints flattened_restraints_;
63  Floats flattened_restraints_scores_;
64  double weight_, max_;
65  PointerMember<ScoringFunction> non_incremental_;
66  // move the destructor out of the header
67  struct Wrapper : public Vector<internal::NBLScoring *> {
68  ~Wrapper();
69  };
70  Wrapper nbl_;
71  void create_flattened_restraints(const RestraintsTemp &rs);
72  void create_scoring_functions();
73  void do_non_incremental_evaluate();
74  Data create_data(ParticleIndex pi, RestraintsTemp cr,
75  const boost::unordered_map<Restraint *, int> &all,
76  const Restraints &dummies) const;
77 
78  public:
79  //! Constructor.
80  /** Pass the particles that will be individually moved, and the list of
81  restraints to evaluate on them.
82 
83  @param m Model object containing all particles to be moved
84  @param to_move particles to be moved; must contain at least one particle
85  @param rs restraints (can be empty in principle, in which case the score
86  is 0)
87  @param weight the weight used to scale the restraints
88  @param max maximum value for evaluate_if_good or evaluate_if_below;
89  can be ignored for most purposes
90  @param name The name template to use for the scoring function.
91 */
92  IMPCORE_DEPRECATED_OBJECT_DECL(2.17)
94  const ParticleIndexes &to_move,
95  const RestraintsTemp &rs,
96  double weight = 1.0, double max = NO_MAX,
97  std::string name =
98  "IncrementalScoringFunction%1%");
99 
100  //! Undo the last moved particles.
101  /** This is similar in effect to, but perhaps
102  more efficient than, calling set_moved_particles() a second time with
103  the same list.
104  */
105  void reset_moved_particles();
106 
107  //! Set which particles have moved since the last evaluate.
108  void set_moved_particles(const ParticleIndexes &p);
109 
110  /** Close pairs scores can be handled separately for efficiency, to do that,
111  add a pair score here to act on the list of particles.*/
112  void add_close_pair_score(PairScore *ps, double distance,
113  const ParticlesTemp &particles,
114  const PairPredicates &filters);
115  void add_close_pair_score(PairScore *ps, double distance,
116  const ParticlesTemp &particles);
117  void clear_close_pair_scores();
118  ParticleIndexes get_movable_indexes() const;
120  const ScoreStatesTemp &ss) override;
121  virtual Restraints create_restraints() const override;
122  virtual ModelObjectsTemp do_get_inputs() const override;
123  virtual void handle_set_has_required_score_states(bool) override;
125 };
126 
127 IMPCORE_END_NAMESPACE
128 
129 #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:44
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:86
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:143
Class for adding up scores during ScoringFunction evaluation.
virtual void handle_set_has_required_score_states(bool)
Definition: ModelObject.h:93
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.
A scoring function on a list of restraints.
virtual ModelObjectsTemp do_get_inputs() const =0