IMP logo
IMP Reference Guide  2.5.0
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-2015 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/container_macros.h>
16 #include <IMP/SingletonContainer.h>
17 #include <IMP/Optimizer.h>
19 #include <IMP/internal/StaticListContainer.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 supports 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_;
55  Pointer<ConfigurationSet> rejected_;
56 
57  typedef IMP::internal::StaticListContainer<SingletonContainer>
58  Container;
59 
60  Parameters fill_in_parameters() const;
61  void randomize(const Parameters &pms, Container *sc) const;
62  Container *set_up_movers(const Parameters &pms, MonteCarlo *mc) const;
63 
64  public:
65  MCCGSampler(Model *m, std::string name = "MCCG Sampler %1%");
66 
67  //! Set the bounding box for randomizing the Cartesian coordinates
68  void set_bounding_box(const algebra::BoundingBoxD<3> &bb);
69 
70  /** \name Number of steps
71  A sampling run proceeds as 3 nested loops
72  -# number of attempts
73  -# number of Monte Carlo steps
74  -# number of CG steps
75  @{
76  */
77  //! Set the maximum number of attempts to find a solution
78  void set_number_of_attempts(unsigned int att);
79 
80  //! Set the number of MC steps to take in each optimization run
81  void set_number_of_monte_carlo_steps(unsigned int cg);
82 
83  //! Set the number of CG steps to take after each MC step
84  void set_number_of_conjugate_gradient_steps(unsigned int cg);
85  /** @} */
86 
87  //! Set the maximum size of the MC step for all attributes
88  void set_max_monte_carlo_step_size(double d);
89 
90  //! Set the maximum size of the MC step for an attribute
91  /** As was mentioned, at the moment k can be one of
92  x,y or z.
93  */
94  void set_max_monte_carlo_step_size(FloatKey k, double d);
95 
96  //! if set to true, then do not randomize the configuration before
97  //! sampling.
98  void set_is_refining(bool tf);
99 
100  //! Set a local optimizer to use instead of ConjugateGradients
101  void set_local_optimizer(Optimizer *opt);
102 
103  //! Whether or not to save rejected conformations
104  /**
105  Saving these can be useful if the sampling is not finding
106  any good conformations.
107  */
108  void set_save_rejected_configurations(bool tf);
109 
110  ConfigurationSet *get_rejected_configurations() const;
111 
112  /** \name Optimizer states
113  The optimizer states will be added to the MonteCarlo optimizer
114  used.
115  */
116  IMP_LIST(public, OptimizerState, optimizer_state, OptimizerState *,
118 
119  virtual ConfigurationSet *do_sample() const IMP_OVERRIDE;
121 };
122 
123 IMPCORE_END_NAMESPACE
124 
125 #endif /* IMPCORE_MCCG_SAMPLER_H */
A Monte Carlo optimizer.
Definition: MonteCarlo.h:45
A container for Singletons.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Base class for all samplers.
Definition: Sampler.h:31
Base class for all optimizers.
Macros to define containers of objects.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
#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.
Definition: Model.h:72
Base class for all optimizers.
Definition: Optimizer.h:46
Base class for all samplers.
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:146
A bounding box in D dimensions.
A class to store a set of configurations of a model.
A simple sampler.
Definition: MCCGSampler.h:40
Shared optimizer state that is invoked upon commitment of new coordinates.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.