IMP  2.1.1
The Integrative Modeling Platform
MCCGSampler.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/MCCGSampler.h
3  * \brief A Monte Carlo/Conjugate Gradients based sampler.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPCORE_MCCG_SAMPLER_H
10 #define IMPCORE_MCCG_SAMPLER_H
11 
12 #include <IMP/core/core_config.h>
13 
14 #include <IMP/Sampler.h>
15 #include <IMP/sampler_macros.h>
16 #include <IMP/container_macros.h>
17 #include <IMP/Optimizer.h>
19 #include <IMP/kernel/internal/InternalListSingletonContainer.h>
20 
21 IMPCORE_BEGIN_NAMESPACE
22 
23 class MonteCarlo;
24 
25 //! A simple sampler.
26 /** This sampler randomizes the conformation and then uses Monte Carlo
27  and conjugate gradient steps to search for good solutions. Each
28  Monte Carlo move is followed by the specified number of
29  conjugate gradient steps before it is decided whether to accept
30  or reject the move. When the sampler encounters a solution that
31  passes all of the restraint score cutoffs, it will accept the solution
32  and move on to generating another one.
33 
34  At the moment it only support optimization of Cartesian coordinates,
35  but this will be fixed when people ask for it
36  (and they already have :-). We are also open to supporting a wider
37  variety of optimization protocols (eg only do conjugate gradient
38  steps occasionally).
39 */
40 class IMPCOREEXPORT MCCGSampler : public Sampler {
41  struct Parameters {
42  unsigned int cg_steps_;
43  int mc_steps_;
44  typedef std::map<FloatKey, double> BallSizes;
45  BallSizes ball_sizes_;
46  typedef std::map<FloatKey, std::pair<Float, Float> > Bounds;
47  Bounds bounds_;
48  unsigned int attempts_;
49  FloatKeys opt_keys_;
51  Parameters();
52  };
53  Parameters default_parameters_;
54  bool is_refining_;
56 
57  Parameters fill_in_parameters() const;
58  void randomize(const Parameters &pms,
59  IMP::internal::InternalListSingletonContainer *sc) const;
60  IMP::internal::InternalListSingletonContainer *set_up_movers(
61  const Parameters &pms, MonteCarlo *mc) const;
62 
63  public:
64  MCCGSampler(kernel::Model *m, std::string name = "MCCG Sampler %1%");
65 
66  //! Set the bounding box for randomizing the Cartesian coordinates
67  void set_bounding_box(const algebra::BoundingBoxD<3> &bb);
68 
69  /** \name Number of steps
70  A sampling run proceeds as 3 nested loops
71  -# number of attempts
72  -# number of Monte Carlo steps
73  -# number of CG steps
74  @{
75  */
76  //! Set the maximum number of attempts to find a solution
77  void set_number_of_attempts(unsigned int att);
78 
79  //! Set the number of MC steps to take in each optimization run
80  void set_number_of_monte_carlo_steps(unsigned int cg);
81 
82  //! Set the number of CG steps to take after each MC step
83  void set_number_of_conjugate_gradient_steps(unsigned int cg);
84  /** @} */
85 
86  //! Set the maximum size of the MC step for all attributes
87  void set_max_monte_carlo_step_size(double d);
88 
89  //! Set the maximum size of the MC step for an attribute
90  /** As was mentioned, at the moment k can be one of
91  x,y or z.
92  */
93  void set_max_monte_carlo_step_size(FloatKey k, double d);
94 
95  //! if set to true, then do not randomize the configuration before
96  //! sampling.
97  void set_is_refining(bool tf);
98 
99  //! Set a local optimizer to use instead of ConjugateGradients
100  void set_local_optimizer(Optimizer *opt);
101 
102  //! Whether or not to save rejected conformations
103  /**
104  Saving these can be useful if the sampling is not finding
105  any good conformations.
106  */
107  void set_save_rejected_configurations(bool tf);
108 
109  ConfigurationSet *get_rejected_configurations() const;
110 
111  /** \name Optimizer states
112  The optimizer states will be added to the MonteCarlo optimizer
113  used.
114  */
115  IMP_LIST(public, OptimizerState, optimizer_state, OptimizerState *,
117 
118  virtual ConfigurationSet *do_sample() const IMP_OVERRIDE;
120 };
121 
122 IMPCORE_END_NAMESPACE
123 
124 #endif /* IMPCORE_MCCG_SAMPLER_H */
A class to store a set of configurations of a model.
A Monte Carlo optimizer.
Definition: MonteCarlo.h:47
Import IMP/kernel/sampler_macros.h in the namespace.
A smart pointer to a ref-counted Object that is a class memeber.
Definition: base/Pointer.h:147
Shared optimizer state that is invoked upon commitment of new coordinates.
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
Import IMP/kernel/Optimizer.h in the namespace.
Import IMP/kernel/container_macros.h in the namespace.
Import IMP/kernel/Sampler.h in the namespace.
A bounding box in D dimensions.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Base class for all optimizers.
A simple sampler.
Definition: MCCGSampler.h:40
IMP::base::Vector< IMP::base::Pointer< OptimizerState > > OptimizerStates
Base class for all samplers.
#define IMP_LIST(protection, Ucname, lcname, Data, PluralData)
A macro to provide a uniform interface for storing lists of objects.
Class for storing model, its restraints, constraints, and particles.