IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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>
17#include <IMP/Optimizer.h>
19#include <IMP/internal/StaticListContainer.h>
20
21IMPCORE_BEGIN_NAMESPACE
22
23class 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*/
40class 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 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
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
85 /** @} */
86
87 //! Set the maximum size of the MC step for all attributes
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 */
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
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 */
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 override;
120 IMP_OBJECT_METHODS(MCCGSampler);
121};
122
123IMPCORE_END_NAMESPACE
124
125#endif /* IMPCORE_MCCG_SAMPLER_H */
A bounding box in D dimensions.
Base class for all optimizers.
Base class for all samplers.
A container for Singletons.
A class to store a set of configurations of a model.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Shared optimizer state that is invoked upon commitment of new coordinates.
Base class for all optimizers.
Definition Optimizer.h:48
An axis-aligned bounding box.
void set_number_of_monte_carlo_steps(unsigned int cg)
Set the number of MC steps to take in each optimization run.
void set_number_of_attempts(unsigned int att)
Set the maximum number of attempts to find a solution.
void set_is_refining(bool tf)
void set_number_of_conjugate_gradient_steps(unsigned int cg)
Set the number of CG steps to take after each MC step.
void set_max_monte_carlo_step_size(FloatKey k, double d)
Set the maximum size of the MC step for an attribute.
void set_max_monte_carlo_step_size(double d)
Set the maximum size of the MC step for all attributes.
void set_local_optimizer(Optimizer *opt)
Set a local optimizer to use instead of ConjugateGradients.
void set_save_rejected_configurations(bool tf)
Whether or not to save rejected conformations.
void set_bounding_box(const algebra::BoundingBoxD< 3 > &bb)
Set the bounding box for randomizing the Cartesian coordinates.
A Monte Carlo optimizer.
Definition MonteCarlo.h:46
Macros to define containers of objects.
#define IMP_LIST(protection, Ucname, lcname, Data, PluralData)
A macro to provide a uniform interface for storing lists of objects.
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition base_types.h:32
IMP::Vector< FloatKey > FloatKeys
Definition base_types.h:33
IMP::Vector< IMP::Pointer< OptimizerState > > OptimizerStates
Definition base_types.h:142
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
A smart pointer to a ref-counted Object that is a class member.
Definition Pointer.h:144
A smart pointer to a reference counted object.
Definition Pointer.h:88