IMP  2.3.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-2014 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/kernel/Particle.h>
15 #include <IMP/Optimizer.h>
16 #include <IMP/kernel/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 give 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(kernel::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 a given time, by calling the protected
54  method do_step() iteratively.
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 a given time, by calling the protected
64  method do_step() iteratively, and using a self adjusting time
65  step that can grow up to max_time_step_factor times than
66  the default time step returned by get_maximum_time_step()
67 
68  @param time_in_fs time_in_fs in femtoseconds
69  @param max_time_step_factor the maximal factor by which the
70  maximum time step is exceeded
71  @param base base by which time step increases or decreases
72  during the wave
73 
74  @note This function is experimental and liable to change at any
75  time.
76  */
77  double simulate_wave(double time_in_fs, double max_time_step_factor = 10.0,
78  double base = 1.5);
79 
80  double get_temperature() const { return temperature_; }
81  void set_temperature(double d) { temperature_ = d; }
82  /** \name Time steps
83  The simulator has a maximum allowed time step. It can take
84  shorter ones if needed due to stability concerns.
85 
86  As with all times in \imp, the time step is in fs.
87  @{
88  */
89  void set_maximum_time_step(double ts) { max_time_step_ = ts; }
90  double get_maximum_time_step() const { return max_time_step_; }
91  double get_last_time_step() const {
92  if (last_time_step_ < 0)
93  return get_maximum_time_step();
94  else
95  return last_time_step_;
96  }
97 /** @} */
98 #ifndef IMP_DOXYGEN
99  void set_time_step(double ts) { set_maximum_time_step(ts); }
100 #endif
101 
102  double get_kt() const;
103 
104  /**
105  returns the simulation time in femtoseconds that was performed
106  by this simulator since it was constructed
107  @note this time can be tweaked using set_current_time() )
108  */
109  double get_current_time() const { return current_time_; }
110 
111  //! Sets the current simulation time in femtoseconds to ct.
112  void set_current_time(double ct) { current_time_ = ct; }
113 
114  //! Returns the set of particles used in the simulation.
115  /** If a non-empty
116  set of particles was provided explicitly by earlier calls to the
117  particles list accessor methods, eg, add_particles(), this set
118  it returned. Otherwise, the associated kernel::Model object is
119  searched for appropriate particles that have a mass and XYZ
120  decorators.
121 
122  \see add_particle()
123  \see add_particles()
124  \see remove_particle()
125  \see clear_particles()
126  \see set_particles()
127  \see set_particles_order()
128  */
129  kernel::ParticlesTemp get_simulation_particles() const;
130 
131  /**
132  Same as get_simulation_particles(), but returns particle
133  model indexes.
134 
135  \see get_simulation_particles()
136  */
137  kernel::ParticleIndexes get_simulation_particle_indexes() const;
138 
139  /** \name Explicitly accessing the particles list
140 
141  One can explicitly specify which particles should be used for
142  the simulation, or retrieve information about the list of particles.
143  Each particle must be a Mass and core::XYZ particle. If none are
144  specified, the model is searched for appropriate particles, based
145  on the get_simulation_particles() method, which can be overridden
146  by child classes.
147  @{
148  */
149  IMP_LIST(public, Particle, particle, kernel::Particle *, kernel::Particles);
150 
151  protected:
152  /** @} */
153  virtual Float do_optimize(unsigned int max_steps) IMP_OVERRIDE IMP_FINAL;
154 
155  /** A Simulator class can perform setup operations before a series
156  of simulation steps is taken. */
157  virtual void setup(const kernel::ParticleIndexes &) {};
158 
159  //! Perform a single time step
160  /** \param[in] dt maximum time step value
161  \return the amount that time should be advanced.
162  */
163  virtual double do_step(const kernel::ParticleIndexes &sc, double dt) = 0;
164 
165  //! Return true if the passed particle is appropriate for the simulation.
166  virtual bool get_is_simulation_particle(kernel::ParticleIndex p) const = 0;
167 
168  private:
169  // see simulate() documentation
170  double do_simulate(double time);
171  // see simulate_wave() documentation
172  double do_simulate_wave(double time_in_fs, double max_time_step_factor = 10.0,
173  double base = 1.5);
174  double temperature_;
175  double max_time_step_;
176  double current_time_;
177  double last_time_step_;
178  double wave_factor_; // if >1.0, use simulate_wave() from do_optimize()
179 };
180 
182 
183 /**\name Energy conversions
184 
185  The native energy units in \imp are difficult to do any sort of math with.
186  One can convert the quantities into more useful ones.
187  @{
188 */
189 IMPATOMEXPORT double get_energy_in_femto_joules(double energy_in_kcal_per_mol);
190 IMPATOMEXPORT double get_force_in_femto_newtons(
191  double force_in_kcal_per_mol_per_angstrom);
192 
193 IMPATOMEXPORT double get_spring_constant_in_femto_newtons_per_angstrom(
194  double k_in_kcal_per_mol_per_angstrom_square);
195 
196 /** @} */
197 
198 IMPATOM_END_NAMESPACE
199 
200 #endif /* IMPATOM_SIMULATOR_H */
double get_kt(double T)
Return kT for a given temperature.
The base class for simulators.
Definition: Simulator.h:34
double get_current_time() const
Definition: Simulator.h:109
#define IMP_FINAL
Have the compiler report an error if anything overrides this method.
Import IMP/kernel/Optimizer.h in the namespace.
void set_current_time(double ct)
Sets the current simulation time in femtoseconds to ct.
Definition: Simulator.h:112
Class to handle individual model particles.
Base class for all optimizers.
Classes to handle individual model particles. (Note that implementation of inline functions in in int...
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Definition: object_macros.h:52
virtual void setup(const kernel::ParticleIndexes &)
Definition: Simulator.h:157
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Simple 3D vector class.
#define IMP_LIST(protection, Ucname, lcname, Data, PluralData)
A macro to provide a uniform interface for storing lists of objects.
virtual double do_optimize(unsigned int ns)=0
override this function to do actual optimization
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73