IMP logo
IMP Reference Guide  2.8.0
The Integrative Modeling Platform
Simulator.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/Simulator.h
3  * \brief Simple molecular dynamics optimizer.
4  *
5  * Copyright 2007-2017 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPATOM_SIMULATOR_H
10 #define IMPATOM_SIMULATOR_H
11 
12 #include <IMP/atom/atom_config.h>
13 
14 #include <IMP/Particle.h>
15 #include <IMP/Optimizer.h>
16 #include <IMP/internal/units.h>
17 #include <IMP/algebra/Vector3D.h>
18 
19 IMPATOM_BEGIN_NAMESPACE
20 
21 // for swig
22 class SimulationParameters;
23 
24 //! The base class for simulators.
25 /**
26  A simulator is an optimizer with dynamic tracking of time,
27  such that each frame is associated with a (possibly variable size)
28  time step.
29 
30  The simulation can be invoked directly by calling simulate(fs) for
31  a given time in femtoseconds, or by calling Optimizer::optimize(nf)
32  for a given number of frames.
33  */
34 class IMPATOMEXPORT Simulator : public Optimizer {
35  public:
36  /**
37  @param m model associated with simulator
38  @param name simulator name where %1% is a joker
39  @param wave_factor if >=1.001, use wave time step size with larger maximal
40  time step, using simulate_wave() when calling optimize()
41 
42  @note wave_factor is an advanced feature - if you're not sure, just use its
43  default, see also simulate_wave()
44  @note wave_factor is experimental and liable to change at any time.
45 
46  \see simulate()
47  */
48  Simulator(Model *m, std::string name = "Simulator %1%",
49  double wave_factor = 1.0);
50 
51  //! Simulate for a given time in fs
52  /**
53  simulate for at least the passed time, by calling do_simulate()
54  with optimizing states turned on
55 
56  @param time_in_fs time in femtoseconds
57  */
58  double simulate(double time_in_fs);
59 
60  //! Simulate for a given time in fs using a wave step function
61  //! with maximal time step increased by up to max_time_step_factor
62  /**
63  simulate for at least the passed time, by calling do_simulate_wave()
64  with optimizing states turned on
65 
66  @param time_in_fs time_in_fs in femtoseconds
67  @param max_time_step_factor the maximal factor by which the
68  maximum time step is exceeded
69  @param base base by which time step increases or decreases
70  during the wave
71 
72  @note This function is experimental and liable to change at any
73  time.
74  */
75  double simulate_wave(double time_in_fs, double max_time_step_factor = 10.0,
76  double base = 1.5);
77 
78  //! Return the simulator temeprature in kelvin
79  double get_temperature() const { return temperature_; }
80 
81  //! Set the temperature of the simulator to d in kelvin units
82  void set_temperature(double d) { temperature_ = d; }
83 
84  /** \name Time steps
85  The simulator has a maximum allowed time step. It can take
86  shorter ones if needed due to stability concerns.
87 
88  As with all times in \imp, the time step is in fs.
89  @{
90  */
91  void set_maximum_time_step(double ts) { max_time_step_ = ts; }
92 
93  //! Get the maximum allowed time step in fs
94  double get_maximum_time_step() const { return max_time_step_; }
95 
96  //! Get the time of the last simulated time step (or the maximal time step
97  //! if the simulation has not started), in units of fs
98  double get_last_time_step() const {
99  if (last_time_step_ < 0)
100  return get_maximum_time_step();
101  else
102  return last_time_step_;
103  }
104 /** @} */
105 #ifndef IMP_DOXYGEN
106  void set_time_step(double ts) { set_maximum_time_step(ts); }
107 #endif
108 
109  // returns kt in units of kCal/mol for temperature get_temeprature() [K]
110  double get_kt() const;
111 
112  /**
113  returns the simulation time in femtoseconds that was performed
114  by this simulator since it was constructed
115  @note this time can be tweaked using set_current_time() )
116  */
117  double get_current_time() const { return current_time_; }
118 
119  //! Sets the current simulation time in femtoseconds to ct.
120  void set_current_time(double ct) { current_time_ = ct; }
121 
122  //! Returns the set of particles used in the simulation.
123  /** If a non-empty
124  set of particles was provided explicitly by earlier calls to the
125  particles list accessor methods, eg, add_particles(), this set
126  it returned. Otherwise, the associated Model object is
127  searched for appropriate particles that have a mass and XYZ
128  decorators.
129 
130  \see add_particle()
131  \see add_particles()
132  \see remove_particle()
133  \see clear_particles()
134  \see set_particles()
135  \see set_particles_order()
136  */
137  ParticlesTemp get_simulation_particles() const;
138 
139  /**
140  Same as get_simulation_particles(), but returns particle
141  model indexes.
142 
143  \see get_simulation_particles()
144  */
145  ParticleIndexes get_simulation_particle_indexes() const;
146 
147  /** \name Explicitly accessing the particles list
148 
149  One can explicitly specify which particles should be used for
150  the simulation, or retrieve information about the list of particles.
151  Each particle must be a Mass and core::XYZ particle. If none are
152  specified, the model is searched for appropriate particles, based
153  on the get_simulation_particles() method, which can be overridden
154  by child classes.
155  @{
156  */
157  IMP_LIST(public, Particle, particle, Particle *, Particles);
158 
159  protected:
160  /** @} */
161  virtual Float do_optimize(unsigned int max_steps) IMP_OVERRIDE IMP_FINAL;
162 
163  /** Perform any setup operations needed before running a series
164  of simulation steps
165 
166  @note Called by do_simulate() or do_simulate_wave() before iterative
167  calls to do_step()
168 */
169  virtual void setup(const ParticleIndexes &) {};
170 
171  //! Perform a single time step
172  /** \param[in] sc the particles that should be moved
173  \param[in] dt maximum time step value
174  \return the amount that time should be advanced.
175  */
176  virtual double do_step(const ParticleIndexes &sc, double dt) = 0;
177 
178  //! Return true if the passed particle is appropriate for the simulation.
179  virtual bool get_is_simulation_particle(ParticleIndex p) const = 0;
180 
181  /** called by simulate() -
182  calls setup() and then calls do_step() iteratively
183  till given simulation time is completed
184 
185  @param time time to simulate
186 
187  @return score at end of simulation period
188  */
189  virtual double do_simulate(double time);
190 
191  /** Calls the protected method setup() and then calls
192  method do_step() iteratively, and using a self adjusting time
193  step that can grow up to max_time_step_factor times than
194  the default time step returned by get_maximum_time_step()
195 
196  \see simulate_wave()
197  */
198  virtual double do_simulate_wave(double time_in_fs, double max_time_step_factor = 10.0,
199  double base = 1.5);
200 
201  private:
202  double temperature_;
203  double max_time_step_;
204  double current_time_;
205  double last_time_step_;
206  double wave_factor_; // if >1.0, use simulate_wave() from do_optimize()
207 };
208 
210 
211 
212 IMPATOM_END_NAMESPACE
213 
214 #endif /* IMPATOM_SIMULATOR_H */
double get_kt(double T)
Return kT for a given temperature in units of [kcal/mol].
The base class for simulators.
Definition: Simulator.h:34
double get_current_time() const
Definition: Simulator.h:117
void set_temperature(double d)
Set the temperature of the simulator to d in kelvin units.
Definition: Simulator.h:82
#define IMP_FINAL
Have the compiler report an error if anything overrides this method.
double get_maximum_time_step() const
Get the maximum allowed time step in fs.
Definition: Simulator.h:94
Base class for all optimizers.
#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
virtual void setup(const ParticleIndexes &)
Definition: Simulator.h:169
virtual double do_optimize(unsigned int ns)=0
override this function to do actual optimization
void set_current_time(double ct)
Sets the current simulation time in femtoseconds to ct.
Definition: Simulator.h:120
Base class for all optimizers.
Definition: Optimizer.h:46
double get_last_time_step() const
Definition: Simulator.h:98
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
double get_temperature() const
Return the simulator temeprature in kelvin.
Definition: Simulator.h:79
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Simple 3D vector class.
Class to handle individual particles of a Model object.
Definition: Particle.h:41
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.