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