IMP logo
IMP Reference Guide  2.6.2
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-2016 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  /** Pass the particles that will be individually moved, and the list of
78  restraints to evaluate on them.
79 
80  @param to_move particles to be moved, must contain at least one particle
81  @param rs restraints (can be empty in principle, in which case the score
82  is 0)
83  @param weight the weight used to scale the restraints
84  @param max maximum value for evaluate_if_good or evaluate_if_below,
85  can be ignored for most purposes
86  @param name The name template to use for the scoring function.
87 */
89  const RestraintsTemp &rs,
90  double weight = 1.0, double max = NO_MAX,
91  std::string name =
92  "IncrementalScoringFunction%1%");
93  /** Undo the last moved particles. This is similar in effect to, but perhaps
94  more efficient than, calling set_moved_particles() a second time with
95  the same list.
96  */
97  void reset_moved_particles();
98  /** Set which particles have moved since the last evaluate. */
99  void set_moved_particles(const ParticleIndexes &p);
100  /** Close pairs scores can be handled separately for efficiency, to do that,
101  add a pair score here to act on the list of particles.*/
102  void add_close_pair_score(PairScore *ps, double distance,
103  const ParticlesTemp &particles,
104  const PairPredicates &filters);
105  void add_close_pair_score(PairScore *ps, double distance,
106  const ParticlesTemp &particles);
107  void clear_close_pair_scores();
108  ParticleIndexes get_movable_indexes() const;
110  const ScoreStatesTemp &ss) IMP_OVERRIDE;
111  virtual Restraints create_restraints() const IMP_OVERRIDE;
115 };
116 
117 IMPCORE_END_NAMESPACE
118 
119 #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
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.