Debian Codegraph @

include/BALL/MOLMEC/MDSIMULATION/molecularDynamics.h

raw symbols SCIP
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 // $Id: molecularDynamics.h,v 1.33 2005/12/23 17:01:53 amoll Exp $
5 //
6
7 // MolecularDynamics: A base class for molecular dynamics simulations
8 // Useful MD classes must be derived from this class.
9
10 #ifndef BALL_MOLMEC_MDSIMULATION_MOLECULARDYNAMICS_H
11 #define BALL_MOLMEC_MDSIMULATION_MOLECULARDYNAMICS_H
12
13 #ifndef BALL_COMMON_H
14 # include <BALL/common.h>
15 #endif
16
17 #ifndef BALL_DATATYPE_OPTIONS_H
18 # include <BALL/DATATYPE/options.h>
19 #endif
20
21 #ifndef BALL_MOLMEC_COMMON_ATOMVECTOR_H
22 # include <BALL/MOLMEC/COMMON/atomVector.h>
23 #endif
24
25 #include <vector>
26
27 namespace BALL
28 {
29 // Some forward decls
30 class SnapShotManager;
31 class ForceField;
32 class System;
33
34 /** Molecular Dynamics base class.
35 This class is the base class for classical molecular dynamics
36 simulations. Actual MD classes are derived from this class and
37 then implement the actual simulation classes for the different
38 ensembles or methods.
39
40 \ingroup MDSimulation
41 */
42 class BALL_EXPORT MolecularDynamics
43 {
44 public:
45
46 /** Local classes for option names and default option values
47 for all MD(sub)classes.
48 */
49 struct BALL_EXPORT Option
50 {
51
52 /** The maximal number of iterations to be carried out
53 */
54 static const char* MAXIMAL_NUMBER_OF_ITERATIONS;
55
56 /** The maximal simulation time in ps(equivalent to
57 MAXIMAL_NUMBER_OF_ITERATIONS
58 */
59 static const char* MAXIMAL_SIMULATION_TIME;
60
61 /** The current number of iteration
62 */
63 static const char* NUMBER_OF_ITERATION;
64
65 /** After how many iterations shall energy information be saved
66 */
67 static const char* ENERGY_OUTPUT_FREQUENCY;
68
69 /** After how many iterations shall a snapshot of the system be taken
70 */
71 static const char* SNAPSHOT_FREQUENCY;
72
73 /** The time step in picoseconds
74 */
75 static const char* TIME_STEP;
76
77 /** The reference temperature in Kelvin
78 */
79 static const char* REFERENCE_TEMPERATURE;
80
81 /** The parameter for heat bath coupling in picoseconds.
82 * It should be greater than 0.1 ps.
83 */
84 static const char* BATH_RELAXATION_TIME;
85
86 /** The current time of the simulation in picoseconds
87 */
88 static const char* CURRENT_TIME;
89 };
90
91 struct BALL_EXPORT Default
92 {
93
94 /** The maximal number of iterations to be simulated.
95 */
96 static const Size MAXIMAL_NUMBER_OF_ITERATIONS;
97
98 /** The maximal simulation time in ps(equivalent to
99 MAXIMAL_NUMBER_OF_ITERATIONS )
100 */
101 static const double MAXIMAL_SIMULATION_TIME;
102
103 /** The current number of iteration
104 */
105 static const Size NUMBER_OF_ITERATION;
106
107 /** After how many iterations shall the current energy/temperature
108 * be calculated/saved.
109 */
110 static const Size ENERGY_OUTPUT_FREQUENCY;
111
112 /** After how many iterations shall the current positions/velocities be saved.
113 */
114 static const Size SNAPSHOT_FREQUENCY;
115
116 /** The size of the time step in picoseconds. Default 0.0005 ps
117 */
118 static const double TIME_STEP;
119
120 /** The reference temperature for the simulated system.
121 */
122 static const double REFERENCE_TEMPERATURE;
123
124 /** The parameter for heat bath coupling in picoseconds. Default = 0.2 ps
125 */
126 static const double BATH_RELAXATION_TIME;
127
128 /** The current time of the simulation in picoseconds
129 * Useful when doing several successive MD runs on the system
130 */
131 static const double CURRENT_TIME;
132 };
133
134 /** @name Constructors and Destructors
135 */
136 //@{
137
138 BALL_CREATE(MolecularDynamics)
139
140 /** Default constructor.
141 */
142 MolecularDynamics();
143
144 /** Constructor. It expects the forcefield
145 */
146 MolecularDynamics(ForceField& force_field);
147
148 /** Copy constructor
149 */
150 MolecularDynamics(const MolecularDynamics& rhs);
151
152 /** Destructor.
153 */
154 virtual ~MolecularDynamics();
155
156 //@}
157 /** @name Assignments
158 */
159 //@{
160
161 /** Assignment operator
162 */
163 const MolecularDynamics& operator =(const MolecularDynamics& rhs);
164
165 /** Assign a molecular dynamics objects.
166 */
167 void set(const MolecularDynamics& rhs);
168
169 //@}
170 /** @name Debugging and Diagnostics
171 */
172 //@{
173
174 /** Has the molecular dynamics class been successfully set up?
175 */
176 bool isValid() const;
177
178 //@}
179 /** @name Setup methods
180 */
181 //@{
182
183 /** Set up the molecular dynamics
184 */
185 virtual bool setup(ForceField& force_field, SnapShotManager* snapshot_man);
186
187 /** Set up the molecular dynamics
188 */
189 virtual bool setup(ForceField& forcefield, SnapShotManager* snapshot_man, const Options& myoptions);
190
191 /** Specific setup; derived class can use this method for
192 additional preparations if necessary
193 */
194 virtual bool specificSetup();
195
196 //@}
197 /** @name Accessors
198 */
199 //@{
200
201 /** Set the number of the current iteration
202 */
203 void setNumberOfIteration(Size number);
204
205 /** Set the maximal number of iterations that will be
206 carried out. If the number of the start iteration is 0 (which is the default),
207 this method sets the total number of simulated iterations.
208 */
209 void setMaximalNumberOfIterations(Size number);
210
211 /** Set the maximal simulation time in ps that will be
212 carried out. If the start time is zero(which is the
213 default), then this method sets the total simulation time.
214 */
215 void setMaximalSimulationTime(double time);
216
217 /** Set the time step in ps.
218 Note that this will change the maximum simulation time.
219 */
220 virtual void setTimeStep(double step);
221
222 /** Set the reference temperature for the system.
223 In isothermal ensembles, this is the simulation temperature
224 set set by the thermostat.
225 */
226 void setReferenceTemperature(double temperature);
227
228 /** Set the current time of the MD run in picoseconds
229 */
230 void setCurrentTime(double time);
231
232 /** Set the energy output frequency.
233 The current energies during the simulation will
234 be printed every <b>number</b> steps.
235 */
236 void setEnergyOutputFrequency(Size number);
237
238 /** Set the snapshot frequency
239 */
240 void setSnapShotFrequency(Size number);
241
242 /** Get the energy output frequency
243 */
244 Size getEnergyOutputFrequency() const;
245
246 /** Get the current iteration of the MD simulation
247 */
248 Size getNumberOfIterations() const;
249
250 /** Get the maximal number of iterations of the MD simulation
251 */
252 Size getMaximalNumberOfIterations() const;
253
254 /** Get the maximal simulation time of the MD simulation
255 */
256 double getMaximalSimulationTime() const;
257
258 /** Get the current time step
259 */
260 double getTimeStep() const;
261
262 /** Get the snapshot frequency
263 */
264 Size getSnapShotFrequency() const;
265
266 /** Get the current temperature of the system
267 */
268 double getTemperature() const;
269
270 /** Get the current time of the MD simulation
271 */
272 double getTime() const;
273
274 /** Get the current total energy of the system
275 */
276 double getTotalEnergy() const;
277
278 /** Get the current potential energy of the system
279 */
280 double getPotentialEnergy() const;
281
282 /** Get the current kinetic energy of the system
283 */
284 double getKineticEnergy() const;
285
286 /** Get the force field the MD simulation is bound to
287 */
288 ForceField* getForceField() const;
289
290 /** Start the molecular dynamics simulation.
291 This method calls \link simulateIterations simulateIterations \endlink with the maximum
292 number of iterations.
293 @see setMaximumNumberOfIterations
294 @return false if an error occurred, e.g. the energy was too high
295 */
296 bool simulate(bool restart = false);
297
298 /** Simulate a given time interval.
299 This method determines the number of steps necessary
300 to simulate a given time interval and executes a
301 simulation for that interval by calling \link simulateIterations simulateIterations \endlink .
302 @return false if an error occurred, e.g. the energy was too high
303 */
304 bool simulateTime(double simulation_time, bool restart = false);
305
306 /** Start the molecular dynamics simulation and carry out
307 the given number of iterations.
308 This is the proper simulation method, which is implemented in
309 the derived classes only. The implementation provided
310 by \link MolecularDynamics MolecularDynamics \endlink is simply empty.
311 @return false if an error occurred, e.g. the energy was too high
312 */
313 virtual bool simulateIterations(Size number, bool restart = false);
314
315 /** Specify if the MDSimulation aborts if the Energy is greater than abort_energy_
316 */
317 void enableEnergyAbortCondition(bool state);
318
319 /// Query if the MDSimulation aborts if the Energy is greater than abort_energy_
320 bool energyAbortConditionEnabled() const;
321
322 /** Specify the energy to abort the simulation.
323 The default value is 10^8.
324 */
325 void setEnergyToAbort(float value);
326
327 /** Query the energy to abort the simulation.
328 The default value is 10^8.
329 */
330 float getEnergyToAbort() const;
331
332 //@}
333
334 /** @name Public Attributes
335 */
336 //@{
337
338 /** The options for this class
339 */
340 Options options;
341
342 protected:
343
344 //@}
345 /*_ @name Protected Methods
346 */
347 //_@{
348
349 /*_ A method for calculating the
350 current temperature in the system
351 */
352 void updateInstantaneousTemperature();
353
354 //_@}
355 /*_ @name Protected Attributes
356 */
357 //_@{
358
359 /*_ The boolean variable indicates if the setup of the
360 molecular dynamics has been successful
361 */
362 bool valid_;
363
364 /*_ The force field the MD class is bound to
365 */
366 ForceField* force_field_ptr_;
367
368 /*_ The system the MD class is bound to
369 */
370 System* system_ptr_;
371
372 /*_ The list of atoms. The simulation will be carried out for these atoms
373 */
374 AtomVector atom_vector_;
375
376 /*_ The current iteration number
377 */
378 Size number_of_iteration_;
379
380 /*_ The maximal number of iterations to be simulated when
381 calling the simulate() method.
382 */
383 Size maximal_number_of_iterations_;
384
385 /*_ The time step in picoseconds
386 */
387 double time_step_;
388
389 /*_ The reference temperature in Kelvin
390 */
391 double reference_temperature_;
392
393 /*_ The current(kinetic) temperatue in Kelvin
394 */
395 double current_temperature_;
396
397 /*_ The current kinetic energy in kJ/mol
398 */
399 double kinetic_energy_;
400
401 /*_ The current total energy in kJ/mol
402 */
403 double total_energy_;
404
405 /*_ The current time of the MD run
406 */
407 double current_time_;
408
409 /*_ Frequency of energy output(i.e. after how many iterations)
410 */
411 Size energy_output_frequency_;
412
413 /*_ Frequency of taking snapshots(i.e. after how many iterations)
414 */
415 Size snapshot_frequency_;
416
417 /*_ The Snapshot Manager that is used for taking snapshots
418 */
419 SnapShotManager* snapshot_manager_ptr_;
420
421 //_
422 bool abort_by_energy_enabled_;
423
424 //_
425 float abort_energy_;
426
427 //_@}
428
429 }; // end of class MolecularDynamics
430 } // end of namespace Ball
431
432 #endif // BALL_MOLMEC_MDSIMULATION_MOLECULARDYNAMICS_H