Disable fastmath with OpenCL on Intel devices
[alexxy/gromacs.git] / docs / user-guide / terminology.rst
1 Terminology
2 ===========
3
4 .. _gmx-pressure:
5
6 Pressure
7 --------
8
9 The pressure in molecular dynamics can be computed from the kinetic energy and
10 the virial. 
11
12 Fluctuation
13 ^^^^^^^^^^^
14
15 Whether or not pressure coupling is used within a simulation, the pressure
16 value for the simulation box will oscillate significantly. Instantaneous
17 pressure is meaningless, and not well-defined. Over a picosecond time scale it
18 usually will not be a good indicator of the true pressure. This variation is
19 entirely normal due to the fact that pressure is a macroscopic property and can
20 only be measured properly as time average, while it is being measured and/or
21 adjusted with pressure coupling on the microscopic scale. How much it varies
22 and the speed at which it does depends on the number of atoms in the system,
23 the type of pressure coupling used and the value of the coupling constants.
24 Fluctuations of the order of hundreds of bar are typical. For a box of 216
25 waters, fluctuations of 500-600 bar are standard. Since the fluctuations go
26 down with the square root of the number of particles, a system of 21600 water
27 molecules (100 times larger) will still have pressure fluctuations of 50-60 bar.
28
29 .. _gmx-pbc:
30
31 Periodic boundary conditions
32 ----------------------------
33
34 Periodic boundary conditions (PBC) are used in molecular dynamics simulations
35 to avoid problems with boundary effects caused by finite size, and make the
36 system more like an infinite one, at the cost of possible periodicity effects.
37
38 Beginners visualizing a trajectory sometimes think they are observing a problem
39 when
40
41 * the molecule(s) does not stay in the centre of the box, or
42 * it appears that (parts of) the molecule(s) diffuse out of the box, or
43 * holes are created, or
44 * broken molecules appear, or
45 * their unit cell was a rhombic dodecahedron or cubic octahedron but it looks
46   like a slanted cube after the simulation, or
47 * crazy bonds all across the simulation cell appear.
48
49 This is not a problem or error that is occuring, it is what you should expect.
50
51 The existence of PBC means that any atom that leaves a simulation box by, say,
52 the right-hand face, then enters the simulation box by the left-hand face. In
53 the example of a large protein, if you look at the face of the simulation box
54 that is opposite to the one from which the protein is protruding, then a hole
55 in the solvent will be visible. The reason that the molecule(s) move from where
56 they were initially located within the box is (for the vast majority of
57 simulations) they are free to diffuse around. And so they do. They are not held
58 in a magic location of the box. The box is not centered around anything while
59 performing the simulation. Molecules are not made whole as a matter of course.
60 Moreover, any periodic cell shape can be expressed as a parallelepiped (a.k.a.
61 triclinic cell), and |Gromacs| does so internally regardless of the initial
62 shape of the box.
63
64 These visual issues can be fixed after the conclusion of the simulation by
65 judicious use of the optional inputs to :ref:`gmx trjconv` to process the
66 trajectory files. Similarly, analyses such as RMSD of atomic positions can be
67 flawed when a reference structure is compared with a structure that needs
68 adjusting for periodicity effects, and the solution with :ref:`gmx trjconv`
69 follows the same lines. Some complex cases needing more than one operation will
70 require more than one invocation of :ref:`gmx trjconv` in order to work.
71
72 For further information, see the corresponding section in the :ref:`Reference Manual <pbc>`.
73
74 Suggested workflow
75 ^^^^^^^^^^^^^^^^^^
76
77 Fixing periodicity effects with :ref:`gmx trjconv` to suit visualization or
78 analysis can be tricky. Multiple invocations can be necessary. You may need to
79 create custom index groups (e.g. to keep your ligand with your protein)
80 Following the steps below in order (omitting those not required) should help
81 get a pleasant result. You will need to consult ``gmx trjconv -h`` to find out
82 the details for each step. That's deliberate -- there is no magic "do what I
83 want" recipe. You have to decide what you want, first. :-)
84
85 #. First make your molecules whole if you want them whole.
86 #. Cluster your molecules/particles if you want them clustered.
87 #. If you want jumps removed, extract the first frame from the trajectory to
88    use as the reference, and then use ``-pbc nojump`` with that first
89    frame as reference.
90 #. Center your system using some criterion. Doing so shifts the system, so
91    don't use ``-pbc nojump`` after this step.
92 #. Perhaps put everything in some box with the other ``-pbc`` or ``-ur``
93    options.
94 #. Fit the resulting trajectory to some (other) reference structure (if
95    desired), and don't use any PBC related option afterwards.
96
97 With point three, the issue is that :ref:`gmx trjconv` removes the jumps from
98 the first frame using the reference structure provided with -s. If the reference
99 structure (run input file) is not clustered/whole, using ``-pbc nojump``
100 will undo steps 1 and 2.
101
102 .. _gmx-thermostats:
103
104 Thermostats
105 -----------
106
107 Thermostats are designed to help a simulation sample from the correct ensemble
108 (i.e. NVT or NPT) by modulating the temperature of the system in some fashion.
109 First, we need to establish what we mean by temperature. In simulations, the
110 "instantaneous (kinetic) temperature" is usually computed from the kinetic
111 energy of the system using the equipartition theorem. In other words, the
112 temperature is computed from the system's total kinetic energy.
113
114 So, what's the goal of a thermostat? Actually, it turns out the goal is not to
115 keep the temperature constant, as that would mean fixing the total kinetic
116 energy, which would be silly and not the aim of NVT or NPT. Rather, it's to
117 ensure that the average temperature of a system be correct.
118
119 To see why this is the case, imagine a glass of water sitting in a room.
120 Suppose you can look very closely at a few molecules in some small region of
121 the glass, and measure their kinetic energies. You would not expect the kinetic
122 energy of this small number of particles to remain precisely constant; rather,
123 you'd expect fluctuations in the kinetic energy due to the small number of
124 particles. As you average over larger and larger numbers of particles, the
125 fluctuations in the average get smaller and smaller, so finally by the time you
126 look at the whole glass, you say it has "constant temperature".
127
128 Molecular dynamics simulations are often fairly small compared to a glass of
129 water, so we have bigger fluctuations. So it's really more appropriate here to
130 think of the role of a thermostat as ensuring that we have
131
132 (a) the correct average temperature, and
133 (b) the fluctuations of the correct size.
134
135 See the relevant section in the :ref:`Reference Manual <temp-coupling>`
136 for details on how temperature coupling is applied and
137 the types currently available.
138
139 .. _gmx-thermostats-do:
140
141 What to do
142 ^^^^^^^^^^
143
144 Some hints on practices that generally are a good idea:
145
146 * Preferably, use a thermostat that samples the correct distribution of
147   temperatures (for examples, see the corresponding manual section), in addition
148   to giving you the correct average temperature.
149 * At least: use a thermostat that gives you the correct average temperature,
150   and apply it to components of your system for which they are justified (see
151   the first bullet in `What not to do`_). In some cases, using
152   ``tc-grps = System`` may lead to the "hot solvent/cold solute" problem
153   described in the 3rd reference in `Further reading`_.
154
155 .. _gmx-thermostats-dont:
156
157 What not to do
158 ^^^^^^^^^^^^^^
159
160 Some hints on practices that generally not a good idea to use:
161
162 * Do not use separate thermostats for every component of your system. Some
163   molecular dynamics thermostats only work well in the thermodynamic limit. A
164   group must be of sufficient size to justify its own thermostat. If you use one
165   thermostat for, say, a small molecule, another for protein, and another for
166   water, you are likely introducing errors and artifacts that are hard to
167   predict. In particular, do not couple ions in aqueous solvent in a separate
168   group from that solvent. For a protein simulation, using ``tc-grps = Protein
169   Non-Protein`` is usually best.
170 * Do not use thermostats that work well only in the limit of a large number of
171   degrees of freedom for systems with few degrees of freedom. For example, do
172   not use Nosé-Hoover or Berendsen thermostats for types of free energy
173   calculations where you will have a component of the system with very few
174   degrees of freedom in an end state (i.e. a noninteracting small molecule).
175
176 Further reading
177 ^^^^^^^^^^^^^^^
178
179 #. `Cheng, A. & Merz, K. M. Application of the nosé- hoover chain algorithm to
180    the study of protein dynamics. *J. Phys. Chem.* **100** (5), 1927–1937
181    (1996). <http://pubs.acs.org/doi/abs/10.1021/jp951968y>`__
182 #. `Mor, A., Ziv, G. & Levy, Y. Simulations of proteins with inhomogeneous
183    degrees of freedom: the effect of thermostats. *J. Comput. Chem.* **29**
184    (12), 1992–1998 (2008). <http://dx.doi.org/10.1002/jcc.20951>`__
185 #. `Lingenheil, M., Denschlag, R., Reichold, R. & Tavan, P. The
186    "hot-solvent/cold-solute" problem revisited. *J. Chem. Theory Comput.* **4**
187    (8), 1293–1306 (2008). <http://pubs.acs.org/doi/abs/10.1021/ct8000365>`__
188
189 Energy conservation
190 -------------------
191
192 In principle, a molecular dynamics simulation should conserve the total energy,
193 the total momentum and (in a non-periodic system) the total angular momentum. A
194 number of algorithmic and numerical issues make that this is not always the
195 case:
196
197 * Cut-off treatment and/or long-range electrostatics treatment (see Van Der
198   Spoel, D. & van Maaren, P. J. The origin of layer structure artifacts in
199   simulations of liquid water. *J. Chem. Theor. Comp.* **2**, 1–11 (2006).)
200 * Treatment of pair lists,
201 * Constraint algorithms (see e.g. Hess, B. P-LINCS: A parallel linear constraint
202   solver for molecular simulation. *J. Chem. Theor. Comp.* **4**, 116–122
203   (`2008 <http://dx.doi.org/10.1021/ct700116n>`_).).
204 * The integration timestep.
205 * :ref:`Temperature coupling <gmx-thermostats>` and :ref:`pressure coupling <gmx-pressure>`.
206 * Round-off error (in particular in single precision), for example subtracting
207   large numbers (Lippert, R. A. et al. A common, avoidable source of error in
208   molecular dynamics integrators. *J. Chem. Phys.* **126**, 046101 (`2007 <http://dx.doi.org/10.1063/1.2431176>`_).).
209 * The choice of the integration algorithm (in |Gromacs| this is normally
210   leap-frog).
211 * Removal of center of mass motion: when doing this in more than one group the
212   conservation of energy will be violated.
213
214 Average structure
215 -----------------
216
217 Various |Gromacs| utilities can compute average structures. Presumably the idea
218 for this comes from something like an ensemble-average NMR structure. In some
219 cases, it makes sense to calculate an average structure (as a step on the way
220 to calculating root-mean-squared fluctuations (RMSF), for example, one needs
221 the average position of all of the atoms).
222
223 However, it's important to remember that an average structure isn't necessarily
224 meaningful. By way of analogy, suppose I alternate holding a ball in my left
225 hand, then in my right hand. What's the average position of the ball? Halfway
226 in between -- even though I always have it either in my left hand or my right
227 hand. Similarly, for structures, averages will tend to be meaningless anytime
228 there are separate metastable conformational states. This can happen on a
229 sidechain level, or for some regions of backbone, or even whole helices or
230 components of the secondary structure.
231
232 Thus, if you derive an average structure from a molecular dynamics simulation,
233 and find artifacts like unphysical bond lengths, weird structures, etc., this
234 doesn't necessarily mean something is wrong. It just shows the above: an
235 average structure from a simulation is not necessarily a physically meaningful
236 structure.
237
238 .. _blowing-up:
239
240 Blowing up
241 ----------
242
243 *Blowing up* is a highly technical term used to describe a common sort of
244 simulation failure. In brief, it describes a failure typically due to an
245 unacceptably large force that ends up resulting in a failure of the integrator.
246
247 To give a bit more background, it's important to remember that molecular
248 dynamics numerically integrates Newton's equations of motion by taking small,
249 discrete timesteps, and using these timesteps to determine new velocities and
250 positions from velocities, positions, and forces at the previous timestep. If
251 forces become too large at one timestep, this can result in extremely large
252 changes in velocity/position when going to the next timestep. Typically, this
253 will result in a cascade of errors: one atom experiences a very large force one
254 timestep, and thus goes shooting across the system in an uncontrolled way in
255 the next timestep, overshooting its preferred location or landing on top of
256 another atom or something similar. This then results in even larger forces the
257 next timestep, more uncontrolled motions, and so on. Ultimately, this will
258 cause the simulation package to crash in some way, since it can't cope with
259 such situations. In simulations with constraints, the first symptom of this
260 will usually be some LINCS or SHAKE warning or error -- not because the
261 constraints are the source of the problem, but just because they're the first
262 thing to crash. Similarly, in simulations with domain decomposition, you may
263 see messages about particles being more than a cell length out of the domain
264 decomposition cell of their charge group, which are symptomatic of your
265 underlying problem, and not the domain decomposition algorithm itself. Likewise
266 for warnings about tabulated or 1-4 interactions being outside the distance
267 supported by the table. This can happen on one computer system while another
268 resulted in a stable simulation because of the impossibility of numerical
269 reproducibility of these calculations on different computer systems.
270
271 Possible causes include:
272
273 * you didn't minimize well enough,
274 * you have a bad starting structure, perhaps with steric clashes,
275 * you are using too large a timestep (particularly given your choice of
276   constraints),
277 * you are doing particle insertion in free energy calculations without using
278   soft core,
279 * you are using inappropriate pressure coupling (e.g. when you are not in
280   equilibrium, Berendsen can be best while relaxing the volume, but you will
281   need to switch to a more accurate pressure-coupling algorithm later),
282 * you are using inappropriate temperature coupling, perhaps on inappropriate
283   groups, or
284 * your position restraints are to coordinates too different from those present
285   in the system, or
286 * you have a single water molecule somewhere within the system that is
287   isolated from the other water molecules, or
288 * you are experiencing a bug in :ref:`gmx mdrun`.
289
290 Because blowing up is due, typically, to forces that are too large for a
291 particular timestep size, there are a couple of basic solutions:
292
293 * make sure the forces don't get that large, or
294 * use a smaller timestep.
295
296 Better system preparation is a way to make sure that forces don't get large, if
297 the problems are occurring near the beginning of a simulation.
298
299 .. _system-diagnosis:
300
301 Diagnosing an unstable system
302 -----------------------------
303
304 Troubleshooting a system that is blowing up can be challenging, especially for
305 an inexperienced user. Here are a few general tips that one may find useful
306 when addressing such a scenario:
307
308 #. If the crash is happening relatively early (within a few steps), set
309    ``nstxout`` (or ``nstxout-compressed``) to 1, capturing all possible frames.
310    Watch the resulting trajectory to see which atoms/residues/molecules become
311    unstable first.
312 #. Simplify the problem to try to establish a cause:
313
314    * If you have a new box of solvent, try minimizing and simulating a single
315      molecule to see if the instability is due to some inherent problem with
316      the molecule's topology or if instead there are clashes in your starting
317      configuration.
318    * If you have a protein-ligand system, try simulating the protein alone in
319      the desired solvent. If it is stable, simulate the ligand in vacuo to see
320      if its topology gives stable configurations, energies, etc.
321    * Remove the use of fancy algorithms, particularly if you haven't
322      equilibrated thoroughly first
323
324 #. Monitor various components of the system's energy using :ref:`gmx energy`.
325    If an intramolecular term is spiking, that may indicate improper bonded
326    parameters, for example.
327 #. Make sure you haven't been ignoring error messages (missing atoms when
328    running :ref:`gmx pdb2gmx`, mismatching names when running :ref:`gmx grompp`,
329    etc.) or using work-arounds (like using ``gmx grompp -maxwarn`` when you
330    shouldn't be) to make sure your topology is intact and being interpreted
331    correctly.
332 #. Make sure you are using appropriate settings in your :ref:`mdp` file for the
333    force field you have chosen and the type of system you have. Particularly
334    important settings are treatment of cutoffs, proper neighbor searching
335    interval (``nstlist``), and temperature coupling. Improper settings can lead
336    to a breakdown in the model physics, even if the starting configuration of
337    the system is reasonable.
338
339 When using no explict solvent, starting your equilibration with a smaller time
340 step than your production run can help energy equipartition more stably.
341
342 There are several common situations in which instability frequently arises,
343 usually in the introduction of new species (ligands or other molecules) into
344 the system. To determine the source of the problem, simplify the system (e.g.
345 the case of a protein-ligand complex) in the following way.
346
347 #. Does the protein (in water) minimize adequately by itself? This is a test of
348    the integrity of the coordinates and system preparation. If this fails,
349    something probably went wrong when running :ref:`gmx pdb2gmx` (see below), or
350    maybe :ref:`gmx genion` placed an ion very close to the protein (it is
351    random, after all).
352 #. Does the ligand minimize in vacuo? This is a test of the topology. If it
353    does not, check your parameterization of the ligand and any implementation of
354    new parameters in force field files.
355 #. (If previous item is successful) Does the ligand minimize in water, and/or
356    does a short simulation of the ligand in water succeed?
357
358 Other sources of possible problems are in the biomolecule topology itself.
359
360 #. Did you use ``-missing`` when running :ref:`gmx pdb2gmx`? If so, don't.
361    Reconstruct missing coordinates rather than ignoring them.
362 #. Did you override long/short bond warnings by changing the lengths? If so,
363    don't. You probably have missing atoms or some terrible input geometry.
364
365 .. _gmx-md:
366
367 Molecular dynamics
368 ------------------
369
370 Molecular dynamics (MD) is computer simulation with atoms and/or molecules
371 interacting using some basic laws of physics.
372 The |Gromacs| :ref:`Reference Manual <md>` provides a good general introduction to this area,
373 as well as specific material for use with |Gromacs|. The first few chapters are mandatory reading
374 for anybody wishing to use |Gromacs| and not waste time.
375
376 * Introduction to molecular modeling (`slides`_, `video`_)] - theoretical framework, modeling levels,
377   limitations and possibilities, systems and methods (Erik Lindahl).
378
379 Books
380 ^^^^^
381
382 There a several text books around.
383
384 Good introductory books are:
385 * A. Leach (2001) Molecular Modeling: Principles and Applications.
386 * T. Schlick (2002) Molecular Modeling and Simulation
387
388 With programming background:
389 * D. Rapaport (1996) The Art of Molecular Dynamics Simulation
390 * D. Frenkel, B. Smith (2001) Understanding Molecular Simulation
391
392 More from the physicist's view:
393 * M. Allen, D. Tildesley (1989) Computer simulation of liquids
394 * H.J.C. Berendsen (2007) Simulating the Physical World: Hierarchical Modeling from Quantum Mechanics to Fluid Dynamics
395
396 Types / Ensembles
397 ^^^^^^^^^^^^^^^^^
398 * NVE - number of particles (N), system volume (V) and energy (E) are constant / conserved.
399 * NVT - number of particles (N), system volume (V) and temperature (T) are
400   constant / conserved. (See :ref:`thermostats <gmx-thermostats>` for more on *constant* temperature).
401 * NPT - number of particles (N), system pressure (P) and temperature (T) are constant / conserved.
402   (See :ref:`pressure coupling <gmx-pressure>` for more on *constant* pressure).
403
404 .. _slides: https://extras.csc.fi/chem/courses/gmx2007/Erik_Talks/preworkshop_tutorial_introduction.pdf
405 .. _video:  http://tv.funet.fi/medar/showRecordingInfo.do?id=/metadata/fi/csc/courses/gromacs_workshop_2007/IntroductiontoMolecularSimulationandGromacs.xml
406
407 .. _gmx-force-field:
408
409 Force field
410 -----------
411
412 Force fields are sets of potential functions and parametrized interactions that can be used to study
413 physical systems. A general introduction to their history, function and use is beyond the scope of this
414 guide, and the user is asked to consult either the relevant literature or 
415 try to start at the relevant `Wikipedia page`_.
416
417 .. _Wikipedia page: https://en.wikipedia.org/wiki/Force_field_(chemistry)