IMP  2.1.1
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-2013 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>
16 #include <IMP/base/map.h>
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 per possibly moved particles. Each of
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 : public base::map<kernel::ParticleIndex, Data> {
52  ~ScoringFunctionsMap();
53  };
54  ScoringFunctionsMap scoring_functions_;
56  kernel::ParticleIndexes last_move_;
58  kernel::Restraints flattened_restraints_;
59  Floats flattened_restraints_scores_;
60  double weight_, max_;
61  base::PointerMember<ScoringFunction> non_incremental_;
62  // move the destructor out of the header
63  struct Wrapper : public base::Vector<internal::NBLScoring *> {
64  ~Wrapper();
65  };
66  Wrapper nbl_;
67  void create_flattened_restraints(const kernel::RestraintsTemp &rs);
68  void create_scoring_functions();
69  void do_non_incremental_evaluate();
70  Data create_data(kernel::ParticleIndex pi,
72  const kernel::Restraints &dummies) const;
73 
74  public:
75  /** Pass the particles that will be individuall mode, and the list of
76  restraints to evaluate on them.
77 
78  @param to_move particles to be moved, must contain at least one particle
79  @param rs restraints (can be empty in principle, in which case the score
80  is 0)
81  @param weight the weight used to scale the restraints
82  @param max maximum value for evaluate_if_good or evaluate_if_below,
83  can be ignored for most purposes
84  @param name The name template to use for the scoring function.
85 */
87  const kernel::RestraintsTemp &rs,
88  double weight = 1.0, double max = NO_MAX,
89  std::string name =
90  "IncrementalScoringFunction%1%");
91  /** Undo the last moved particles. This is similar in effect to, but perhaps
92  more efficient than, calling set_moved_particles() a second time with
93  the same list.
94  */
95  void reset_moved_particles();
96  /** Set which particles have moved since the last evaluate. */
97  void set_moved_particles(const kernel::ParticleIndexes &p);
98  /** Close pairs scores can be handled separately for efficiency, to do that,
99  add a pair score here to act on the list of particles.*/
100  void add_close_pair_score(PairScore *ps, double distance,
101  const kernel::ParticlesTemp &particles,
102  const PairPredicates &filters);
103  void add_close_pair_score(PairScore *ps, double distance,
104  const kernel::ParticlesTemp &particles);
105  void clear_close_pair_scores();
106  /** \deprecated_at{2.1} Use get_movable_indexes() instead. */
107  IMPCORE_DEPRECATED_FUNCTION_DECL(2.1)
108  kernel::ParticleIndexes get_movable_particles() const {
109  IMPCORE_DEPRECATED_FUNCTION_DEF(2.1, "Use get_movable_indexes()");
110  return get_movable_indexes();
111  }
112  kernel::ParticleIndexes get_movable_indexes() const;
114  const ScoreStatesTemp &ss) IMP_OVERRIDE;
115  virtual kernel::Restraints create_restraints() const IMP_OVERRIDE;
116  virtual kernel::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
117  virtual void handle_set_has_required_score_states(bool) IMP_OVERRIDE;
119 };
120 
121 IMPCORE_END_NAMESPACE
122 
123 #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
Import IMP/kernel/base_types.h in the namespace.
IMP::base::Vector< IMP::base::WeakPointer< kernel::ModelObject > > ModelObjectsTemp
A nullptr-initialized pointer to an IMP Object.
A smart pointer to a ref-counted Object that is a class memeber.
Definition: base/Pointer.h:147
Abstract score function.
Class for adding up scores during ScoringFunction evaluation.
IMP::base::Vector< IMP::base::WeakPointer< ScoreState > > ScoreStatesTemp
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
IMP::base::Vector< IMP::base::Pointer< PairPredicate > > PairPredicates
virtual void do_add_score_and_derivatives(ScoreAccumulator sa, const ScoreStatesTemp &ss)=0
Functions to generate vectors.
Storage of a model, its restraints, constraints and particles.
Declare an efficient stl-compatible map.