IMP  2.0.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 "internal/SingleParticleScoringFunction.h"
14 #include <IMP/base/Pointer.h>
15 #include <IMP/base_types.h>
17 #include <IMP/base/map.h>
19 
20 IMPCORE_BEGIN_NAMESPACE
21 
22 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
23 namespace internal {
24  class NBLScoring;
25 }
26 #endif
27 
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  The ensure proper evaluation, the ScoringFunction is divided into a number
37  of sub scoring functions, one per possibly moved particles. Each of
38 */
39 class IMPCOREEXPORT IncrementalScoringFunction: public ScoringFunction {
40  typedef base::map<ParticleIndex,
41  base::
44  ScoringFunctionsMap scoring_functions_;
45  ParticleIndexes all_;
46  ParticleIndexes last_move_;
47  ParticleIndexes dirty_;
48  Restraints flattened_restraints_;
49  Floats flattened_restraints_scores_;
50  double weight_, max_;
51  base::OwnerPointer<ScoringFunction> non_incremental_;
52  // move the destructor out of the header
53  struct Wrapper: public
54  base::Vector<internal::NBLScoring*> {
55  ~Wrapper();
56  };
57  Wrapper nbl_;
58  void create_flattened_restraints(const RestraintsTemp &rs);
59  void create_scoring_functions();
60  void do_non_incremental_evaluate();
61  public:
62  /** Pass the particles that will be individuall mode, and the list of
63  restraints to evaluate on them.
64 
65  @param to_move particles to be moved, must contain at least one particle
66  @param rs restraints (can be empty in principle, in which case the score
67  is 0)
68  @param weight the weight used to scale the restraints
69  @param max maximum value for evaluate_if_good or evaluate_if_below,
70  can be ignored for most purposes
71  @param name The name template to use for the scoring function.
72 */
73  IncrementalScoringFunction(const ParticlesTemp &to_move,
74  const RestraintsTemp &rs,
75  double weight=1.0, double max= NO_MAX,
76  std::string name="IncrementalScoringFunction%1%");
77  /** Undo the last moved particles. This is similar in effect to, but perhaps
78  more efficient than, calling set_moved_particles() a second time with
79  the same list.
80  */
81  void reset_moved_particles();
82  /** Set which particles have moved since the last evaluate. */
83  void set_moved_particles(const ParticleIndexes &p);
84  /** Close pairs scores can be handled separately for efficiency, to do that,
85  add a pair score here to act on the list of particles.*/
86  void add_close_pair_score(PairScore *ps, double distance,
87  const ParticlesTemp &particles,
88  const PairPredicates &filters);
89  void add_close_pair_score(PairScore *ps, double distance,
90  const ParticlesTemp &particles);
91  void clear_close_pair_scores();
92  ParticleIndexes get_movable_particles() const;
94  const ScoreStatesTemp &ss) IMP_OVERRIDE;
95  Restraints create_restraints() const IMP_OVERRIDE;
96  ScoreStatesTemp get_required_score_states() const IMP_OVERRIDE;
98 };
99 
100 
101 IMPCORE_END_NAMESPACE
102 
103 #endif /* IMPCORE_INCREMENTAL_SCORING_FUNCTION_H */