IMP  2.0.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-2013 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 class IMPATOMEXPORT Simulator : public Optimizer
26 {
27 public:
28  //! Create the optimizer
29  /** If sc is not null, that container will be used to find particles
30  to move, otherwise the model will be searched.*/
31  Simulator(Model *m,
32  std::string name= "Simulator %1%");
33 
34  //! Simulate until the given time in fs
35  double simulate(double time_in_fs);
36 
37  double get_temperature() const {
38  return temperature_;
39  }
40  void set_temperature(double d) {
41  temperature_=d;
42  }
43  /** \name Time steps
44  The simulator has a maximum allowed time step. It can take
45  shorter ones if needed due to stability concerns.
46 
47  As with all times in \imp, the time step is in fs.
48  @{
49  */
50  void set_maximum_time_step(double ts) {
51  max_time_step_=ts;
52  }
53  double get_maximum_time_step() const {
54  return max_time_step_;
55  }
56  double get_last_time_step() const {
57  if (last_time_step_ <0) return get_maximum_time_step();
58  else return last_time_step_;
59  }
60  /** @} */
61 #ifndef IMP_DOXYGEN
62  void set_time_step(double ts) {
63  set_maximum_time_step(ts);
64  }
65 #endif
66 
67  double get_kt() const;
68 
69  /**
70  returns the simulation time in femtoseconds that was performed
71  by this simulator since it was constructed
72  @note this time can be tweaked using set_current_time() )
73  */
74  double get_current_time() const {
75  return current_time_;
76  }
77 
78  /**
79  Sets the current simulation time in femtoseconds to ct
80  @relates get_current_time()
81  */
82  void set_current_time(double ct) {
83  current_time_=ct;
84  }
85  /** Get the set of particles used in the simulation.
86  This may be different then the stored set, eg if
87  no particles are stored, the Model is searched for
88  appropriate particles.
89  */
90  ParticlesTemp get_simulation_particles() const;
91  ParticleIndexes get_simulation_particle_indexes() const;
92  /** \name Explicitly specifying particles
93 
94  One can explicitly specify which particles should be used for
95  molecular dynamics. Each particle must be a Mass and
96  core::XYZ particle. If none are specified, the model
97  is searched for appropriate particles.
98  @{
99  */
100  IMP_LIST(public, Particle, particle, Particle*, Particles);
101  /** @} */
103 protected:
104  /** A Simulator class can perform setup operations before a series
105  of simulation steps is taken. */
106  virtual void setup(const ParticleIndexes &) {};
107 
108  /** Perform a single time step and return the amount that time
109  should be advanced. A maximum time step value is passed.
110  */
111  virtual double do_step(const ParticleIndexes &sc, double dt)=0;
112 
113  /** Return true if the passed particle is appropriate for
114  the simulation.
115  */
116  virtual bool get_is_simulation_particle(ParticleIndex p) const=0;
117  private:
118  double temperature_;
119  double max_time_step_;
120  double current_time_;
121  double last_time_step_;
122 };
123 
124 
126 
127 /**\name Energy conversions
128 
129  The native energy units in \imp are difficult to do any sort of math with.
130  One can convert the quantities into more useful ones.
131  @{
132 */
133 IMPATOMEXPORT double get_energy_in_femto_joules(double energy_in_kcal_per_mol);
134 IMPATOMEXPORT double
135 get_force_in_femto_newtons(double force_in_kcal_per_mol_per_angstrom);
136 
137 IMPATOMEXPORT double
138 get_spring_constant_in_femto_newtons_per_angstrom(double
139  k_in_kcal_per_mol_per_angstrom_square);
140 
141 /** @} */
142 
143 
144 
145 IMPATOM_END_NAMESPACE
146 
147 #endif /* IMPATOM_SIMULATOR_H */