Updated exponential fitting to make it robust.
[alexxy/gromacs.git] / docs / manual / analyse.tex
1 %
2 % This file is part of the GROMACS molecular simulation package.
3 %
4 % Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
5 % Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 % and including many others, as listed in the AUTHORS file in the
7 % top-level source directory and at http://www.gromacs.org.
8 %
9 % GROMACS is free software; you can redistribute it and/or
10 % modify it under the terms of the GNU Lesser General Public License
11 % as published by the Free Software Foundation; either version 2.1
12 % of the License, or (at your option) any later version.
13 %
14 % GROMACS is distributed in the hope that it will be useful,
15 % but WITHOUT ANY WARRANTY; without even the implied warranty of
16 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 % Lesser General Public License for more details.
18 %
19 % You should have received a copy of the GNU Lesser General Public
20 % License along with GROMACS; if not, see
21 % http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 % Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 %
24 % If you want to redistribute modifications to GROMACS, please
25 % consider that scientific software is very special. Version
26 % control is crucial - bugs must be traceable. We will be happy to
27 % consider code for inclusion in the official distribution, but
28 % derived work must not be called official GROMACS. Details are found
29 % in the README & COPYING files - if they are missing, get the
30 % official version at http://www.gromacs.org.
31 %
32 % To help us fund GROMACS development, we humbly ask that you cite
33 % the research papers on the package. Check out http://www.gromacs.org.
34
35 \chapter{Analysis}
36 \label{ch:analysis}
37 In this chapter different ways of analyzing your trajectory are described. 
38 The names of the corresponding analysis programs are given. 
39 Specific information on the in- and output of these programs can be found 
40 in the online manual at {\wwwpage}.
41 The output files are often produced as finished Grace/Xmgr graphs.
42
43 First, in \secref{usinggroups}, the group concept in analysis is explained. 
44 \ssecref{selections} explains a newer concept of dynamic selections,
45 which is currently supported by a few tools.
46 Then, the different analysis tools are presented.
47
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Groups in Analysis
49
50 \section{Using Groups}
51 \label{sec:usinggroups}\index{groups}
52 {\tt gmx make_ndx, gmx mk_angndx, gmx select}\\
53 In \chref{algorithms}, it was explained how {\em groups of
54 atoms} can be used in {\tt mdrun} (see~\secref{groupconcept}).
55 In most analysis programs, groups
56 of atoms must also be chosen. Most programs can generate several default
57 index groups, but groups can always be read from an index file. Let's
58 consider the example of a simulation of a binary mixture of components A and B. When
59 we want to calculate the radial distribution function (RDF)
60 $g_{AB}(r)$ of A with respect to B, we have to calculate:
61 \beq
62 4\pi r^2 g_{AB}(r)      ~=~     V~\sum_{i \in A}^{N_A} \sum_{j \in B}^{N_B} P(r)
63 \eeq
64 where $V$ is the volume and $P(r)$ is the probability of finding a B atom
65 at distance $r$ from an A atom.
66
67 By having the user define the {\em atom numbers} for groups A and B in
68 a simple file, we can calculate this $g_{AB}$ in the most general way, without
69 having to make any assumptions in the RDF program about the type of 
70 particles. 
71
72 Groups can therefore consist of a series of {\em atom numbers}, but in
73 some cases also of {\em molecule numbers}.  It is also possible to
74 specify a series of angles by {\em triples} of {\em atom numbers},
75 dihedrals by {\em quadruples} of {\em atom numbers} and bonds or
76 vectors (in a molecule) by {\em pairs} of {\em atom numbers}. When
77 appropriate the type of index file will be specified for the following
78 analysis programs.  To help creating such \swapindex{index}{file}s ({\tt
79 index.ndx}), there are a couple of programs to generate them, using
80 either your input configuration or the topology.  To generate an
81 index file consisting of a series of {\em atom numbers} (as in the
82 example of $g_{AB}$), use {\tt \normindex{gmx make_ndx}} or
83 {\tt \normindex{gmx select}}.  To generate an index file
84 with angles or dihedrals, use {\tt \normindex{gmx mk_angndx}}.
85 Of course you can also
86 make them by hand. The general format is presented here:
87
88 \begin{verbatim}
89 [ Oxygen ]
90    1       4       7
91
92 [ Hydrogen ]
93    2       3       5       6
94    8       9
95 \end{verbatim}
96
97 First, the group name is written between square brackets. The following
98 atom numbers may be spread out over as many lines as you like. The
99 atom numbering starts at 1.
100
101 \swapindexquiet{choosing}{groups}%
102 Each tool that can use groups will offer the available alternatives
103 for the user to choose. That choice can be made with the number of the
104 group, or its name. In fact, the first few letters of the group
105 name will suffice if that will distinguish the group from all others.
106 There are ways to use Unix shell features to choose group names
107 on the command line, rather than interactively. Consult {\wwwpage}
108 for suggestions.
109
110 \subsection{Default Groups}
111 \label{subsec:defaultgroups}
112 When no index file is supplied to analysis tools or {\tt grompp},
113 a number of \swapindex{default}{groups} are generated to choose from:
114 \begin{description}
115 \item[{\tt System}]\mbox{}\\
116         all atoms in the system
117 \item[{\tt Protein}]\mbox{}\\
118         all protein atoms
119 \item[{\tt Protein-H}]\mbox{}\\
120         protein atoms excluding hydrogens
121 \item[{\tt C-alpha}]\mbox{}\\
122         C$_{\alpha}$ atoms
123 \item[{\tt Backbone}]\mbox{}\\
124         protein backbone atoms; N, C$_{\alpha}$ and C
125 \item[{\tt MainChain}]\mbox{}\\
126         protein main chain atoms: N, C$_{\alpha}$, C and O, including
127         oxygens in C-terminus
128 \item[{\tt MainChain+Cb}]\mbox{}\\
129         protein main chain atoms including C$_{\beta}$
130 \item[{\tt MainChain+H}]\mbox{}\\
131         protein main chain atoms including backbone amide hydrogens and
132         hydrogens on the N-terminus
133 \item[{\tt SideChain}]\mbox{}\\
134         protein side chain atoms; that is all atoms except N,
135         C$_{\alpha}$, C, O, backbone amide hydrogens, oxygens in
136         C-terminus and hydrogens on the N-terminus
137 \item[{\tt SideChain-H}]\mbox{}\\
138         protein side chain atoms excluding all hydrogens
139 %\ifthenelse{\equal{\gmxlite}{1}}{}{
140 \item[{\tt Prot-Masses}]\mbox{}\\
141         protein atoms excluding dummy masses (as used in virtual site
142         constructions of NH$_3$ groups and tryptophan side-chains),
143         see also \secref{vsitetop}; this group is only included when
144         it differs from the ``{\tt Protein}'' group
145 %} % Brace matches ifthenelse test for gmxlite
146 \item[{\tt Non-Protein}]\mbox{}\\
147         all non-protein atoms
148 \item[{\tt DNA}]\mbox{}\\
149         all DNA atoms
150 \item[{\tt RNA}]\mbox{}\\
151         all RNA atoms
152 \item[{\tt Water}]\mbox{}\\
153         water molecules (names like {\tt SOL}, {\tt WAT}, {\tt HOH}, etc.)  See
154         {\tt \normindex{residuetypes.dat}} for a full listing
155 \item[{\tt non-Water}]\mbox{}\\
156         anything not covered by the {\tt Water} group
157 \item[{\tt Ion}]\mbox{}\\
158         any name matching an Ion entry in {\tt \normindex{residuetypes.dat}}
159 \item[{\tt Water_and_Ions}]\mbox{}\\
160         combination of the {\tt Water} and {\tt Ions} groups 
161 \item[{\tt molecule_name}]\mbox{}\\
162         for all residues/molecules which are not recognized as protein,
163         DNA, or RNA; one group per residue/molecule name is generated
164 \item[{\tt Other}]\mbox{}\\
165         all atoms which are neither protein, DNA, nor RNA.
166 \end{description}
167 Empty groups will not be generated.
168 Most of the groups only contain protein atoms.
169 An atom is considered a protein atom if its residue name is listed
170 in the {\tt \normindex{residuetypes.dat}} file and is listed as a
171 ``Protein'' entry.  The process for determinding DNA, RNA, etc. is
172 analogous. If you need to modify these classifications, then you
173 can copy the file from the library directory into your working
174 directory and edit the local copy.
175
176 \subsection{Selections}
177 \label{subsec:selections}
178 {\tt \normindex{gmx select}}\\
179 Currently, a few analysis tools support an extended concept of {\em
180 (dynamic) \normindex{selections}}.  There are three main differences to
181 traditional index groups:
182 \begin{itemize}
183   \item The selections are specified as text instead of reading fixed
184     atom indices from a file, using a syntax similar to VMD.  The text
185     can be entered interactively, provided on the command line, or from
186     a file.
187   \item The selections are not restricted to atoms, but can also specify
188     that the analysis is to be performed on, e.g., center-of-mass
189     positions of a group of atoms.
190     Some tools may not support selections that do not evaluate to single
191     atoms, e.g., if they require information that is available only for
192     single atoms, like atom names or types.
193   \item The selections can be dynamic, i.e., evaluate to different atoms
194     for different trajectory frames.  This allows analyzing only a
195     subset of the system that satisfies some geometric criteria.
196 \end{itemize}
197 As an example of a simple selection,
198 {\tt resname ABC and within 2 of resname DEF}
199 selects all atoms in residues named ABC that are within 2\,nm of any
200 atom in a residue named DEF.
201
202 Tools that accept selections can also use traditional index files
203 similarly to older tools: it is possible to give an {\tt .ndx} file to
204 the tool, and directly select a group from the index file as a
205 selection, either by group number or by group name.  The index groups
206 can also be used as a part of a more complicated selection.
207
208 To get started, you can run {\tt gmx select} with a single structure,
209 and use the interactive prompt to try out different selections.
210 The tool provides, among others, output options {\tt -on} and
211 {\tt -ofpdb} to write out the selected atoms to an index file and to a
212 {\tt .pdb} file, respectively.  This does not allow testing selections
213 that evaluate to center-of-mass positions, but other selections can be
214 tested and the result examined.
215
216 The detailed syntax and the individual keywords that can be used in
217 selections can be accessed by typing {\tt help} in the interactive
218 prompt of any selection-enabled tool, as well as with
219 {\tt gmx help selections}.  The help is divided into subtopics that can
220 be accessed with, e.g., {\tt help syntax} / {\tt gmx help selections
221 syntax}.  Some individual selection keywords have extended help as well,
222 which can be accessed with, e.g., {\tt help keywords within}.
223
224 The interactive prompt does not currently provide much editing
225 capabilities.  If you need them, you can run the program under
226 {\tt rlwrap}.
227
228 For tools that do not yet support the selection syntax, you can use
229 {\tt gmx select -on} to generate static index groups to pass to the
230 tool.  However, this only allows for a small subset (only the first
231 bullet from the above list) of the flexibility that fully
232 selection-aware tools offer.
233
234 It is also possible to write your own analysis
235 tools to take advantage of the flexibility of these selections: see the
236 {\tt template.cpp} file in the {\tt share/gromacs/template} directory of
237 your installation for an example.
238
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Looking at your trajectory
240
241 \section{Looking at your trajectory}
242 \label{sec:lookwhostalking}
243 \begin{figure}
244 \centerline{
245 {\includegraphics[width=8cm,angle=90]{plots/ngmxdump}}}
246 \caption{The window of {\tt gmx view} showing a box of water.}
247 \label{fig:ngmxdump}
248 \end{figure}
249 {\tt gmx view}\\
250 Before analyzing your trajectory it is often informative to look at
251 your trajectory first. {\gromacs} comes with a simple trajectory
252 viewer {\tt \normindex{gmx view}}; the advantage with this one is that it does not
253 require OpenGL, which usually isn't present on {\eg} supercomputers.
254 It is also possible to generate a
255 hard-copy in Encapsulated Postscript format (see
256 \figref{ngmxdump}). If you want a faster and more fancy viewer
257  there are several programs
258 that can read the {\gromacs} trajectory formats -- have a look at our
259 homepage ({\wwwpage}) for updated links. 
260
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% General properties
262
263 \section{General properties}
264 \label{sec:genprop}
265 {\tt gmx energy, gmx traj}\\
266 To analyze some or all {\em energies} and other properties, such as
267 {\em total pressure}, {\em pressure tensor}, {\em density}, {\em
268 box-volume} and {\em box-sizes}, use the program {\tt \normindex{gmx energy}}.  A
269 choice can be made from a list a set of energies, like potential,
270 kinetic or total energy, or individual contributions, like
271 Lennard-Jones or dihedral energies.
272
273 The {\em center-of-mass velocity}, defined as
274 \beq
275 {\bf v}_{com} = {1 \over M} \sum_{i=1}^N m_i {\bf v}_i
276 \eeq
277 with $M = \sum_{i=1}^N m_i$ the total mass of the system, can be
278 monitored in time by the program {\tt \normindex{gmx traj} -com -ov}. It is however
279 recommended to remove the center-of-mass velocity every step (see
280 \chref{algorithms})!
281
282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Radial distribution functions 
283
284 \section{Radial distribution functions}
285 \label{sec:rdf}
286 {\tt gmx rdf}\\
287 The {\em radial distribution function} (RDF) or pair correlation
288 function $g_{AB}(r)$ between particles of type $A$ and $B$ is defined
289 in the following way:
290 \newcommand{\dfrac}[2]{\displaystyle \frac{#1}{#2}}
291 \beq
292 \begin{array}{rcl}
293 g_{AB}(r)&=&    \dfrac{\langle \rho_B(r) \rangle}{\langle\rho_B\rangle_{local}}         \\
294          &=&    \dfrac{1}{\langle\rho_B\rangle_{local}}\dfrac{1}{N_A}
295                 \sum_{i \in A}^{N_A} \sum_{j \in B}^{N_B} 
296                 \dfrac{\delta( r_{ij} - r )}{4 \pi r^2}         \\
297 \end{array}
298 \eeq
299 with $\langle\rho_B(r)\rangle$ the particle density of type $B$ at a distance $r$
300 around particles $A$, and $\langle\rho_B\rangle_{local}$ the particle density of
301 type $B$ averaged over all spheres around particles $A$ with radius
302 $r_{max}$ (see \figref{rdfex}C).
303
304 \begin{figure}
305 \centerline{
306 {\includegraphics[width=7cm,angle=270]{plots/rdf}}}
307 \caption[Definition of slices in {\tt gmx rdf}.]{Definition of slices
308 in {\tt gmx rdf}: A. $g_{AB}(r)$. B. $g_{AB}(r,\theta)$. The slices are
309 colored gray. C. Normalization $\langle\rho_B\rangle_{local}$. D. Normalization
310 $\langle\rho_B\rangle_{local,\:\theta }$. Normalization volumes are colored gray.}
311 \label{fig:rdfex}
312 \end{figure}
313
314 Usually the value of $r_{max}$ is half of the box length.  The
315 averaging is also performed in time.  In practice the analysis program
316 {\tt \normindex{gmx rdf}} divides the system into spherical slices (from $r$ to
317 $r+dr$, see \figref{rdfex}A) and makes a histogram in stead of
318 the $\delta$-function. An example of the RDF of oxygen-oxygen in
319 SPC water~\cite{Berendsen81} is given in \figref{rdf}.
320
321 \begin{figure}
322 \centerline{
323 {\includegraphics[width=8cm]{plots/rdfO-O}}}
324 \caption{$g_{OO}(r)$ for Oxygen-Oxygen of SPC-water.}
325 \label{fig:rdf}
326 \end{figure}
327
328 % TODO: This functionality isn't there...
329 With {\tt gmx rdf} it is also possible to calculate an angle dependent rdf
330 $g_{AB}(r,\theta)$, where the angle $\theta$ is defined with respect to a 
331 certain laboratory axis ${\bf e}$, see \figref{rdfex}B.
332 \bea 
333 g_{AB}(r,\theta) &=& {1 \over \langle\rho_B\rangle_{local,\:\theta }} {1 \over N_A} \sum_{i \in A}^{N_A} \sum_{j \in B}^{N_B} {\delta( r_{ij} - r ) \delta(\theta_{ij} -\theta) \over 2 \pi r^2 sin(\theta)}\\
334 cos(\theta_{ij}) &=& {{\bf r}_{ij} \cdot {\bf e} \over \|r_{ij}\| \;\| e\| }
335 \eea
336 This $g_{AB}(r,\theta)$ is useful for analyzing anisotropic systems. 
337 {\bf Note} that in this case the normalization $\langle\rho_B\rangle_{local,\:\theta}$ is 
338 the average density in all angle slices from $\theta$ to $\theta + d\theta$ 
339 up to $r_{max}$, so angle dependent, see \figref{rdfex}D.
340
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Correlation functions 
342 %\ifthenelse{\equal{\gmxlite}{1}}{}{
343
344 \section{Correlation functions}
345 \label{sec:corr}
346
347 \subsection{Theory of correlation functions}
348 The theory of correlation functions is well established~\cite{Allen87}.
349 We describe here the implementation of the various 
350 \normindex{correlation} function flavors in the {\gromacs} code.
351 The definition of the \index{autocorrelation function} (ACF)
352 $C_f(t)$ for a property $f(t)$ is:
353 \beq
354 C_f(t)  ~=~     \left\langle f(\xi) f(\xi+t)\right\rangle_{\xi}
355 \label{eqn:corr}
356 \eeq
357 where the notation on the right hand side indicates averaging over $\xi$, {\ie} over
358 time origins.
359 It is also possible to compute cross-correlation function from two properties
360 $f(t)$ and $g(t)$:
361 \beq
362 C_{fg}(t) ~=~   \left\langle f(\xi) g(\xi+t)\right\rangle_{\xi}
363 \eeq
364 however, in {\gromacs} there is no standard mechanism to do this
365 ({\bf note:} you can use the {\tt \normindex{xmgr}} program to compute cross correlations).
366 The integral of the correlation function over time is the 
367 correlation time $\tau_f$:
368 \beq
369 \tau_f  ~=~     \int_0^{\infty} C_f(t) {\rm d} t
370 \label{eqn:corrtime}
371 \eeq
372
373 In practice, correlation functions are calculated based on data points with
374 discrete time intervals {$\Delta$t}, so that the ACF from an MD simulation is:
375 \beq
376 C_f(j\Delta t)  ~=~     \frac{1}{N-j}\sum_{i=0}^{N-1-j} f(i\Delta t) f((i+j)\Delta t)
377 \label{eqn:corrmd}
378 \eeq
379 where $N$ is the number of available time frames for the calculation.
380 The resulting ACF is
381 obviously only available at time points with the same interval {$\Delta$t}.
382 Since, for many applications, it is necessary to know the short time behavior
383 of the ACF ({\eg} the first 10 ps) this often means that we have to save the
384 data with intervals much shorter than the time scale of interest.
385 Another implication of \eqnref{corrmd} is that in principle we can not compute
386 all points of the ACF with the same accuracy, since we have $N-1$ data points
387 for $C_f(\Delta t)$ but only 1 for $C_f((N-1)\Delta t)$. However, if we decide to
388 compute only an ACF of length $M\Delta t$, where $M \leq N/2$ we can compute 
389 all points with the same statistical accuracy:
390 \beq
391 C_f(j\Delta t)  ~=~ \frac{1}{M}\sum_{i=0}^{N-1-M} f(i\Delta t)f((i+j)\Delta t)
392 \eeq
393 Here of course $j < M$.
394 $M$ is sometimes referred to as the \normindex{time lag} of the correlation function. 
395 When we decide to do this, we intentionally do not use all the available points
396 for very short time intervals ($j << M$), but it makes it easier to interpret
397 the results.
398 Another aspect that may not be neglected when computing
399 ACFs from simulation is that usually the time origins $\xi$ (\eqnref{corr})
400 are not statistically independent, which may introduce a bias in the results.
401 This can be tested using a block-averaging procedure, where only time origins
402 with a spacing at least the length of the time lag are included, {\eg} using 
403 $k$ time origins with spacing of $M\Delta t$ (where $kM \leq N$):
404 \beq
405 C_f(j\Delta t)  ~=~ \frac{1}{k}\sum_{i=0}^{k-1} f(iM\Delta t)f((iM+j)\Delta t)
406 \eeq
407 However, one
408 needs very long simulations to get good accuracy this way, because there are 
409 many fewer points that contribute to the ACF.
410
411 \subsection{Using FFT for computation of the ACF}
412 The computational cost for calculating an ACF according to \eqnref{corrmd}
413 is proportional to $N^2$, which is considerable. However, this can be improved
414 by using fast Fourier transforms to do the convolution~\cite{Allen87}.
415
416 \subsection{Special forms of the ACF}
417 There are some important varieties on the ACF, {\eg} the ACF of a vector \ve{p}:
418 \beq
419 C_{\ve{p}}(t) ~=~       \int_0^{\infty} P_n(\cos\angle\left(\ve{p}(\xi),\ve{p}(\xi+t)\right) {\rm d} \xi
420 \label{eqn:corrleg}
421 \eeq
422 where $P_n(x)$ is the $n^{th}$ order Legendre polynomial
423 \footnote{$P_0(x) = 1$, $P_1(x) = x$, $P_2(x) = (3x^2-1)/2$}.
424 Such correlation times 
425 can actually be obtained experimentally using {\eg} NMR or other relaxation 
426 experiments. {\gromacs} can compute correlations using 
427 the 1$^{st}$ and 2$^{nd}$ order Legendre polynomial (\eqnref{corrleg}).
428 This can also be used for rotational autocorrelation
429 ({\tt \normindex{gmx rotacf}})
430 and dipole autocorrelation ({\tt \normindex{gmx dipoles}}).
431
432 In order to study torsion angle dynamics, we define a dihedral 
433 autocorrelation function as~\cite{Spoel97a}:
434 \beq
435 C(t)    ~=~     \left\langle \cos(\theta(\tau)-\theta(\tau+t))\right\rangle_{\tau}
436 \label{eqn:coenk}
437 \eeq
438 {\bf Note} that this is not a  product of two functions 
439 as is generally used for correlation
440 functions, but it may be rewritten as the sum of two products:
441 \beq
442 C(t)    ~=~     \left\langle\cos(\theta(\tau))\cos(\theta(\tau+t))\,+\,\sin(\theta(\tau))\sin(\theta(\tau+t))\right\rangle_{\tau}
443 \label{eqn:cot}
444 \eeq
445
446 \subsection{Some Applications}
447 The program {\tt \normindex{gmx velacc}} calculates the {\em velocity autocorrelation 
448 function}.
449 \beq
450 C_{\ve{v}} (\tau) ~=~ \langle {\ve{v}}_i(\tau) \cdot {\ve{v}}_i(0) \rangle_{i \in A}
451 \eeq
452 The self diffusion coefficient can be calculated using the Green-Kubo 
453 relation~\cite{Allen87}:
454 \beq
455 D_A ~=~ {1\over 3} \int_0^{\infty} \langle {\bf v}_i(t) \cdot {\bf v}_i(0) \rangle_{i \in A} \; dt
456 \eeq
457 which is just the integral of the velocity autocorrelation function.
458 There is a widely-held belief that the velocity ACF converges faster than the mean
459 square displacement (\secref{msd}), which can also be used for the computation of 
460 diffusion constants. However, Allen \& Tildesley~\cite{Allen87} 
461 warn us that the long-time 
462 contribution to the velocity ACF can not be ignored, so care must be taken.
463
464 Another important quantity is the dipole correlation time. The {\em dipole 
465 correlation function} for particles of type $A$ is calculated as follows by 
466 {\tt \normindex{gmx dipoles}}:
467 \beq
468 C_{\mu} (\tau) ~=~
469 \langle {\bf \mu}_i(\tau) \cdot {\bf \mu}_i(0) \rangle_{i \in A}
470 \eeq
471 with ${\bf \mu}_i = \sum_{j \in i} {\bf r}_j q_j$. The dipole correlation time 
472 can be computed using \eqnref{corrtime}.
473 For some applications see~\cite{Spoel98a}.
474
475 The \normindex{viscosity} of a liquid can be related to the correlation 
476 time of the Pressure tensor $\ve{P}$~\cite{PSmith93c,Balasubramanian96}.
477 {\tt \normindex{gmx energy}} can compute the viscosity,
478 but this is not very accurate~\cite{Hess2002a}, and 
479 actually the values do not converge.
480 %} % Brace matches ifthenelse test for gmxlite
481
482 \section{Curve fitting in \gromacs}
483 \subsection{Sum of exponential functions}
484 Sometimes it is useful to fit a curve to an analytical function, for
485 example in the case of autocorrelation functions with noisy
486 tails. {\gromacs} is not a general purpose curve-fitting tool however
487 and therefore {\gromacs} only supports a limited number of
488 functions. 
489 Table~\ref{tab:fitfn} lists the available options with the
490 corresponding command-line options. The underlying routines for
491 fitting use the Levenberg-Marquardt algorithm as implemented in the
492 {\tt lmfit} package~\cite{lmfit} (a bare-bones version of which is
493 included in {\gromacs} in which an option for error-weighted fitting
494 was implemented). 
495 \begin{table}[ht]
496 \centering
497 \caption{Overview of fitting functions supported in (most) analysis tools
498   that compute autocorrelation functions. The ``Note'' column describes
499   properties of the output parameters.}
500 \label{tab:fitfn}
501 \begin{tabular}{lcc}
502 \hline
503 Command & Functional form $f(t)$& Note\\
504 line option         &           & \\
505 \hline
506 exp        & $e^{-t/{a_0}}$ &\\
507 aexp      & $a_1e^{-t/{a_0}}$ &\\
508 exp_exp & $a_1e^{-t/{a_0}}+(1-a_1)e^{-t/{a_2}}$ & $a_2\ge a_0\ge 0$\\
509 exp5      & $a_1e^{-t/{a_0}}+a_3e^{-t/{a_2}}+a_4$ &$a_2\ge a_0\ge 0$\\
510 exp7     &
511 $a_1e^{-t/{a_0}}+a_3e^{-t/{a_2}}+a_5e^{-t/{a_4}}+a_6$&$a_4\ge a_2\ge
512 a_0 \ge0$\\
513 exp9    &
514 $a_1e^{-t/{a_0}}+a_3e^{-t/{a_2}}+a_5e^{-t/{a_4}}+a_7e^{-t/{a_6}}+a_8$&$a_6\ge
515 a_4\ge a_2\ge a_0\ge 0$\\
516 \hline
517 \end{tabular}
518 \end{table}
519
520 \subsection{Error estimation}
521 Under the hood {\gromacs} implements some more fitting functions,
522 namely a function to estimate the error in time-correlated data due to Hess~\cite{Hess2002a}:
523 \beq
524 \varepsilon^2(t) =
525 \alpha\tau_1\left(1+\frac{\tau_1}{t}\left(e^{-t/\tau_1}-1\right)\right)
526       + (1-\alpha)\tau_2\left(1+\frac{\tau_2}{t}\left(e^{-t/\tau_2}-1\right)\right)
527 \eeq
528 where $\tau_1$ and
529 $\tau_2$ are time constants (with $\tau_2 \ge \tau_1$) and $\alpha$
530 usually is close to 1 (in the fitting procedure it is enforced that
531 $0\leq\alpha\leq 1$). This is used in {\tt gmx analyze} for error
532 estimation using
533 \beq
534 \lim_{t\rightarrow\infty}\varepsilon(t) = \sigma\sqrt{\frac{2(\alpha\tau_1+(1-\alpha)\tau_2)}{T}}
535 \eeq
536 where $\sigma$ is the standard deviation of the data set and $T$ is
537 the total simulation time~\cite{Hess2002a}.
538
539 \subsection{Interphase boundary demarcation}
540 In order to determine the position and width of an interface,
541 Steen-S{\ae}thre {\em et al.} fitted a density profile to the
542 following function
543 \beq
544 f(x) ~=~ \frac{a_0+a_1}{2} - \frac{a_0-a_1}{2}{\rm
545   erf}\left(\frac{x-a_2}{a_3^2}\right)
546 \eeq
547 where $a_0$ and $a_1$ are densities of different phases, $x$ is the
548 coordinate normal to the interface, $a_2$ is the position of the
549 interface and $a_3$ is the width of the
550 interface~\cite{Steen-Saethre2014a}.
551 This is implemented in {\tt gmx densorder}.
552
553 \subsection{Transverse current autocorrelation function}
554 In order to establish the transverse current autocorrelation function
555 (useful for computing viscosity~\cite{Palmer1994a})
556 the following function is fitted:
557 \beq
558 f(x) ~=~ e^{-\nu}\left({\rm cosh}(\omega\nu)+\frac{{\rm
559     sinh}(\omega\nu)}{\omega}\right)
560 \eeq
561 with $\nu = x/(2a_0)$ and $\omega = \sqrt{1-a_1}$.
562 This is implemented in {\tt gmx tcaf}.
563
564 \subsection{Viscosity estimation from pressure autocorrelation
565   function}
566 The viscosity is a notoriously difficult property to extract from
567 simulations~\cite{Hess2002a,Wensink2003a}. It is {\em in principle}
568 possible to determine it by integrating the pressure autocorrelation
569 function~\cite{PSmith93c}, however this is often hampered by the noisy
570 tail of the ACF. A workaround to this is fitting the ACF to the
571 following function~\cite{Guo2002b}:
572 \beq
573 f(t)/f(0) = (1-C) {\rm cos}(\omega t) e^{-(t/\tau_f)^{\beta_f}} + C
574 e^{-(t/\tau_s)^{\beta_s}}
575 \eeq
576 where $\omega$ is the frequency of rapid pressure oscillations (mainly
577 due to bonded forces in molecular simulations), $\tau_f$ and $\beta_f$
578 are the time constant and exponent of fast relaxation in a
579 stretched-exponential approximation, $\tau_s$ and $\beta_s$ are constants
580 for slow relaxation and $C$ is the pre-factor that determines the
581 weight between fast and slow relaxation. After a fit, the integral of
582 the function $f(t)$ is used to compute the viscosity:
583 \beq
584 \eta = \frac{V}{k_B T}\int_0^{\infty} f(t) dt
585 \eeq
586 This equation has been
587 applied to computing the bulk and shear viscosity using different
588 elements from the pressure tensor~\cite{Fanourgakis2012a}.
589 This is implemented in {\tt gmx viscosity}.
590
591 \section{Mean Square Displacement}
592 \label{sec:msd}
593 {\tt gmx msd}\\
594 To determine the self \index{diffusion coefficient} $D_A$ of
595 particles of type $A$, one can use the \normindex{Einstein
596 relation}~\cite{Allen87}:
597 \beq 
598 \lim_{t \rightarrow \infty} \langle
599 \|{\bf r}_i(t) - {\bf r}_i(0)\|^2 \rangle_{i \in A} ~=~ 6 D_A t 
600 \eeq
601 This {\em mean square displacement} and $D_A$ are calculated by the
602 program {\tt \normindex{gmx msd}}. Normally an index file containing
603 atom numbers is used and the MSD is averaged over these atoms.  For
604 molecules consisting of more than one atom, ${\bf r}_i$ can be taken
605 as the center of mass positions of the molecules. In that case, you
606 should use an index file with molecule numbers. The results will be
607 nearly identical to averaging over atoms, however. The {\tt gmx msd}
608 program can
609 also be used for calculating diffusion in one or two dimensions. This
610 is useful for studying lateral diffusion on interfaces.
611
612 An example of the mean square displacement of SPC water is given in
613 \figref{msdwater}.
614
615 \begin{figure}
616 \centerline{
617 {\includegraphics[width=8cm]{plots/msdwater}}}
618 \caption{Mean Square Displacement of SPC-water.}
619 \label{fig:msdwater}
620 \end{figure}
621
622 %\ifthenelse{\equal{\gmxlite}{1}}{}{
623
624 %%%%%%%%%%%%%%%%%%%%% Bonds, angles and dihedral %%%%%%%%%%%%%%%%%%%
625
626 \section{Bonds/distances, angles and dihedrals}
627 \label{sec:bad}
628 {\tt gmx distance, gmx angle, gmx gangle}\\
629 To monitor specific {\em bonds} in your modules, or more generally
630 distances between points, the program
631 {\tt \normindex{gmx distance}} can calculate distances as a function of
632 time, as well as the distribution of the distance.
633 With a traditional index file, the groups should consist of pairs of
634 atom numbers, for example:
635 \begin{verbatim}
636 [ bonds_1 ]
637  1     2
638  3     4
639  9    10
640
641 [ bonds_2 ]
642 12    13
643 \end{verbatim}
644 Selections are also supported, with first two positions defining the
645 first distance, second pair of positions defining the second distance
646 and so on.  You can calculate the distances between CA and CB atoms in
647 all your residues (assuming that every residue either has both atoms, or
648 neither) using a selection such as:
649 \begin{verbatim}
650 name CA CB
651 \end{verbatim}
652 The selections also allow more generic distances to be computed.
653 For example, to compute the distances between centers of mass of two
654 residues, you can use:
655 \begin{verbatim}
656 com of resname AAA plus com of resname BBB
657 \end{verbatim}
658
659 The program {\tt \normindex{gmx angle}} calculates the distribution of {\em angles} and
660 {\em dihedrals} in time. It also gives the average angle or dihedral. 
661 The index file consists of triplets or quadruples of atom numbers:
662
663 \begin{verbatim}
664 [ angles ]
665  1     2     3
666  2     3     4
667  3     4     5
668
669 [ dihedrals ]
670  1     2     3     4
671  2     3     5     5
672 \end{verbatim}
673
674 For the dihedral angles you can use either the ``biochemical convention'' 
675 ($\phi = 0 \equiv cis$) or ``polymer convention'' ($\phi = 0 \equiv trans$), 
676 see \figref{dih_def}.
677
678 \begin{figure}
679 \centerline{
680 {\includegraphics[width=3.5cm,angle=270]{plots/dih-def}}}
681 \caption[Dihedral conventions.]{Dihedral conventions: A. ``Biochemical
682 convention''. B. ``Polymer convention''.}
683 \label{fig:dih_def}
684 \end{figure}
685
686 The program {\tt \normindex{gmx gangle}} provides a selection-enabled
687 version to compute angles.  This tool can also compute angles and
688 dihedrals, but does not support all the options of {\tt gmx angle}, such
689 as autocorrelation or other time series analyses.
690 In addition, it supports angles between two vectors, a vector and a
691 plane, two planes (defined by 2 or 3 points, respectively), a
692 vector/plane and the $z$ axis, or a vector/plane and the normal of a
693 sphere (determined by a single position).
694 Also the angle between a vector/plane compared to its position in the
695 first frame is supported.
696 For planes, {\tt \normindex{gmx gangle}} uses the normal vector
697 perpendicular to the plane.
698 See \figref{sgangle}A, B, C) for the definitions.
699
700 \begin{figure}
701 \centerline{
702 {\includegraphics{plots/sgangle}}}
703 \caption[Angle options of {\tt gmx gangle}.]{Angle options of {\tt gmx gangle}:
704 A. Angle between two vectors.
705 B. Angle between two planes.
706 C. Angle between a vector and the $z$ axis.
707 D. Angle between a vector and the normal of a sphere.
708 Also other combinations are supported: planes and vectors can be used
709 interchangeably.}
710 \label{fig:sgangle}
711 \end{figure}
712 %} % Brace matches ifthenelse test for gmxlite
713
714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Radius of gyration and distances
715
716 \section{Radius of gyration and distances}
717 \label{sec:rg}
718 {\tt gmx gyrate, gmx distance, gmx mindist, gmx mdmat, gmx pairdist, gmx xpm2ps}\\
719 To have a rough measure for the compactness of a structure, you can calculate 
720 the {\em radius of gyration} with the program {\tt \normindex{gmx gyrate}} as follows:
721 \beq
722 R_g ~=~ \left({\frac{\sum_i \|{\bf r}_i\|^2 m_i}{\sum_i m_i}}\right)^{\half}
723 \label{eqn:rg}
724 \eeq
725 where $m_i$ is the mass of atom $i$ and ${\bf r}_i$ the position of 
726 atom $i$ with respect to the center of mass of the molecule. It is especially 
727 useful to characterize polymer solutions and proteins.
728
729 Sometimes it is interesting to plot the {\em distance} between two atoms,
730 or the {\em minimum} distance between two groups of atoms
731 ({\eg}: protein side-chains in a salt bridge). 
732 To calculate these distances between certain groups there are several 
733 possibilities:
734 \begin{description}
735 \item[$\bullet$] 
736 The {\em distance between the geometrical centers} of two groups can be 
737 calculated with the program
738 %\ifthenelse{\equal{\gmxlite}{1}}{
739 {{\tt \normindex{gmx distance}}, as explained in \secref{bad}.}
740 \item[$\bullet$]
741 The {\em minimum distance} between two groups of atoms during time 
742 can be calculated with the program {\tt \normindex{gmx mindist}}. It also calculates the 
743 {\em number of contacts} between these groups 
744 within a certain radius $r_{max}$.
745 \item[$\bullet$]
746 {\tt \normindex{gmx pairdist}} is a selection-enabled version of
747 {\tt gmx mindist}.
748 \item[$\bullet$]
749 To monitor the {\em minimum distances between amino acid residues} 
750 within a (protein) molecule, you can use 
751 the program {\tt \normindex{gmx mdmat}}. This minimum distance between two residues
752 A$_i$ and A$_j$ is defined as the smallest distance between any pair of 
753 atoms (i $\in$ A$_i$, j $\in$ A$_j$).
754 The output is a symmetrical matrix of smallest distances 
755 between all residues.
756 To visualize this matrix, you can use a program such as {\tt xv}.
757 If you want to view the axes and legend or if you want to print
758 the matrix, you can convert it with 
759 {\tt xpm2ps} into a Postscript picture, see \figref{mdmat}.
760 \begin{figure}
761 \centerline{
762 \includegraphics[width=6.5cm]{plots/distm}}
763 \caption{A minimum distance matrix for a peptide~\protect\cite{Spoel96b}.}
764 \label{fig:mdmat}
765 \end{figure}
766
767 Plotting these matrices for different time-frames, one can analyze changes 
768 in the structure, and {\eg} forming of salt bridges.
769 \end{description}
770
771 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Root mean square deviations 
772
773 \section{Root mean square deviations in structure}
774 \label{sec:rmsd}
775 {\tt gmx rms, gmx rmsdist}\\
776 The {\em root mean square deviation} ($RMSD$) of certain atoms in a molecule
777 with respect to a reference structure can be calculated with the program 
778 {\tt \normindex{gmx rms}} by least-square fitting the structure to the reference structure
779 ($t_2 = 0$) and subsequently calculating the $RMSD$ (\eqnref{rmsd}).
780 \beq
781 RMSD(t_1,t_2) ~=~ \left[\frac{1}{M} \sum_{i=1}^N m_i \|{\bf r}_i(t_1)-{\bf r}_i(t_2)\|^2 \right]^{\frac{1}{2}}
782 \label{eqn:rmsd}
783 \eeq
784 where $M = \sum_{i=1}^N m_i$ and ${\bf r}_i(t)$ is the position of atom $i$ at time $t$.
785 {\bf Note} that fitting does not have to use the same atoms as the calculation
786 of the $RMSD$; {\eg} a protein is usually fitted on the backbone atoms
787 (N,C$_{\alpha}$,C), but the $RMSD$ can be computed of the backbone
788 or of the whole protein.
789
790 Instead of comparing the structures to the initial structure at time $t=0$ 
791 (so for example a crystal structure), one can also calculate \eqnref{rmsd} 
792 with a structure at time $t_2=t_1-\tau$.
793 This gives some insight in the mobility as a function of $\tau$.
794 A matrix can also be made with the $RMSD$ as a function of $t_1$ and $t_2$,
795 which gives a nice graphical interpretation of a trajectory.
796 If there are transitions in a trajectory, they will clearly show up in
797 such a matrix.
798
799 Alternatively the $RMSD$ can be computed using a fit-free method with the 
800 program {\tt \normindex{gmx rmsdist}}:
801 \beq
802 RMSD(t) ~=~     \left[\frac{1}{N^2}\sum_{i=1}^N \sum_{j=1}^N    \|{\bf r}_{ij}(t)-{\bf r}_{ij}(0)\|^2\right]^{\frac{1}{2}}
803 \label{eqn:rmsdff}
804 \eeq
805 where the {\em distance} {\bf r}$_{ij}$ between atoms at time $t$ 
806 is compared with the distance between the same atoms at time $0$.
807
808 %\ifthenelse{\equal{\gmxlite}{1}}{}{
809 \section{Covariance analysis\index{covariance analysis}}
810 \label{sec:covanal}
811 Covariance analysis, also called
812 \seeindex{principal component analysis}{covariance analysis}
813 or \seeindex{essential dynamics}{covariance analysis}
814 \cite{Amadei93}{,} can find correlated motions.
815 It uses the covariance matrix $C$ of the atomic coordinates:
816 \beq
817 C_{ij} = \left \langle 
818 M_{ii}^{\frac{1}{2}} (x_i - \langle x_i \rangle)
819 M_{jj}^{\frac{1}{2}}  (x_j - \langle x_j \rangle)
820 \right \rangle
821 \eeq
822 where $M$ is a diagonal matrix containing the masses of the atoms
823 (mass-weighted analysis) or the unit matrix (non-mass weighted analysis).
824 $C$ is a symmetric $3N \times 3N$ matrix, which can be diagonalized with
825 an orthonormal transformation matrix $R$:
826 \beq
827 R^T C R = \mbox{diag}(\lambda_1,\lambda_2,\ldots,\lambda_{3N})
828 ~~~~\mbox{where}~~\lambda_1 \geq \lambda_2 \geq \ldots \geq \lambda_{3N}
829 \eeq
830 The columns of $R$ are the eigenvectors, also called principal or
831 essential modes.
832 $R$ defines a transformation to a new coordinate system. The trajectory
833 can be projected on the principal modes to give the principal components
834 $p_i(t)$:
835 \beq
836 {\bf p}(t) = R^T M^{\frac{1}{2}} ({\bf x}(t) - \langle {\bf x} \rangle)
837 \eeq
838 The eigenvalue $\lambda_i$ is the mean square fluctuation of principal
839 component $i$. The first few principal modes often describe 
840 collective, global motions in the system.
841 The trajectory can be filtered along one (or more) principal modes.
842 For one principal mode $i$ this goes as follows:
843 \beq
844 {\bf x}^f(t) =
845 \langle {\bf x} \rangle + M^{-\frac{1}{2}} R_{*i} \, p_i(t)
846 \eeq
847
848 When the analysis is performed on a macromolecule, one often wants to
849 remove the overall rotation and translation to look at the internal motion
850 only. This can be achieved by least square fitting to a reference structure.
851 Care has to be taken that the reference structure is representative for the
852 ensemble, since the choice of reference structure influences the covariance
853 matrix.
854
855 One should always check if the principal modes are well defined.
856 If the first principal component resembles a half cosine and
857 the second resembles a full cosine, you might be filtering noise (see below).
858 A good way to check the relevance of the first few principal
859 modes is to calculate the overlap of the sampling between
860 the first and second half of the simulation.
861 {\bf Note} that this can only be done when the same reference structure is
862 used for the two halves.
863
864 A good measure for the overlap has been defined in~\cite{Hess2002b}.
865 The elements of the covariance matrix are proportional to the square
866 of the displacement, so we need to take the square root of the matrix
867 to examine the extent of sampling. The square root can be
868 calculated from the eigenvalues $\lambda_i$ and the eigenvectors,
869 which are the columns of the rotation matrix $R$.
870 For a symmetric and diagonally-dominant matrix $A$ of size $3N \times 3N$
871 the square root can be calculated as:
872 \beq
873 A^\frac{1}{2} = 
874 R \, \mbox{diag}(\lambda_1^\frac{1}{2},\lambda_2^\frac{1}{2},\ldots,\lambda_{3N}^\frac{1}{2}) \, R^T
875 \eeq
876 It can be verified easily that the product of this matrix with itself gives
877 $A$.
878 Now we can define a difference $d$ between covariance matrices $A$ and $B$
879 as follows:
880 \begin{eqnarray}
881 d(A,B) & = & \sqrt{\mbox{tr}\left(\left(A^\frac{1}{2} - B^\frac{1}{2}\right)^2\right)
882 }
883 \\ & = &
884 \sqrt{\mbox{tr}\left(A + B - 2 A^\frac{1}{2} B^\frac{1}{2}\right)}
885 \\ & = &
886 \left( \sum_{i=1}^N \left( \lambda_i^A + \lambda_i^B \right)
887 - 2 \sum_{i=1}^N \sum_{j=1}^N \sqrt{\lambda_i^A \lambda_j^B}
888 \left(R_i^A \cdot R_j^B\right)^2 \right)^\frac{1}{2}
889 \end{eqnarray}
890 where tr is the trace of a matrix.
891 We can now define the overlap $s$ as:
892 \beq
893 s(A,B) = 1 - \frac{d(A,B)}{\sqrt{\mbox{tr}A + \mbox{tr} B}}
894 \eeq
895 The overlap is 1 if and only if matrices $A$ and $B$ are identical.
896 It is 0 when the sampled subspaces are completely orthogonal.
897
898 A commonly-used measure is the subspace overlap of the first few
899 eigenvectors of covariance matrices.
900 The overlap of the subspace spanned by $m$ orthonormal vectors 
901 ${\bf w}_1,\ldots,{\bf w}_m$ with a reference subspace spanned by 
902 $n$ orthonormal vectors ${\bf v}_1,\ldots,{\bf v}_n$
903 can be quantified as follows:
904 \beq
905 \mbox{overlap}({\bf v},{\bf w}) =
906 \frac{1}{n} \sum_{i=1}^n \sum_{j=1}^m ({\bf v}_i \cdot {\bf w}_j)^2
907 \eeq
908 The overlap will increase with increasing $m$ and will be 1 when
909 set ${\bf v}$ is a subspace of set ${\bf w}$.
910 The disadvantage of this method is that it does not take the eigenvalues
911 into account. All eigenvectors are weighted equally, and when
912 degenerate subspaces are present (equal eigenvalues), the calculated overlap
913 will be too low.
914
915 Another useful check is the cosine content. It has been proven that the
916 the principal components of random diffusion are cosines with the number of
917 periods equal to half the principal component index~\cite{Hess2000,Hess2002b}.
918 The eigenvalues are proportional to the index to the power $-2$.
919 The cosine content is defined as:
920 \beq
921 \frac{2}{T}
922 \left( \int_0^T \cos\left(\frac{i \pi t}{T}\right) \, p_i(t) \mbox{d} t \right)^2
923 \left( \int_0^T p_i^2(t) \mbox{d} t \right)^{-1}
924 \eeq
925 When the cosine content of the first few principal components
926 is close to 1, the largest fluctuations are not connected with
927 the potential, but with random diffusion.
928
929 The covariance matrix is built and diagonalized by
930 {\tt \normindex{gmx covar}}.
931 The principal components and overlap (and many more things)
932 can be plotted and analyzed with {\tt \normindex{gmx anaeig}}.
933 The cosine content can be calculated with {\tt \normindex{gmx analyze}}.
934 %} % Brace matches ifthenelse test for gmxlite
935
936 %\ifthenelse{\equal{\gmxlite}{1}}{}{
937 \section{Dihedral principal component analysis}
938 {\tt gmx angle, gmx covar, gmx anaeig}\\
939 Principal component analysis can be performed in dihedral
940 space~\cite{Mu2005a} using {\gromacs}. You start by defining the
941 dihedral angles of interest in an index file, either using {\tt
942  gmx mk_angndx} or otherwise. Then you use the {\tt gmx angle} program
943 with the {\tt -or} flag to produce a new {\tt .trr} file containing the cosine and
944 sine of each dihedral angle in two coordinates, respectively. That is,
945 in the {\tt .trr} file you will have a series of numbers corresponding to:
946 cos($\phi_1$), sin($\phi_1$), cos($\phi_2$), sin($\phi_2$), ...,
947 cos($\phi_n$), sin($\phi_n$), and the array is padded with zeros, if
948 necessary.  Then you can use this {\tt .trr} file as input for the {\tt
949  gmx covar} program and perform principal component analysis as usual.
950 For this to work you will need to generate a reference file ({\tt .tpr}, 
951 {\tt .gro}, {\tt .pdb} etc.) containing the same number of ``atoms'' 
952 as the new {\tt .trr} file, that is for $n$ dihedrals you need 2$n$/3 atoms 
953 (rounded up if not an integer number). 
954 You should use the {\tt -nofit} option for {\tt
955 gmx covar} since the coordinates in the dummy reference file do not
956 correspond in any way to the information in the {\tt .trr} file. Analysis of
957 the results is done using {\tt gmx anaeig}.
958 %} % Brace matches ifthenelse test for gmxlite
959  
960 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Hydrogen bonds
961
962 \section{Hydrogen bonds}
963 {\tt gmx hbond}\\
964 The program {\tt \normindex{gmx hbond}} analyzes the {\em hydrogen bonds} (H-bonds)
965 between all possible donors D and acceptors A. To determine if an
966 H-bond exists, a geometrical criterion is used, see also
967 \figref{hbond}:
968 \beq
969 \begin{array}{rclcl}
970 r       & \leq  & r_{HB}        & = & 0.35~\mbox{nm}    \\
971 \alpha  & \leq  & \alpha_{HB}   & = & 30^o              \\
972 \end{array}
973 \eeq
974
975 \begin{figure}
976 \centerline{\includegraphics[width=2.5cm,angle=270]{plots/hbond}}
977 \caption{Geometrical Hydrogen bond criterion.}
978 \label{fig:hbond}
979 \end{figure}
980
981 The value of $r_{HB} = 0.35$~nm corresponds to the first minimum of the RDF of 
982 SPC water (see also \figref{rdf}).
983
984 The program {\tt gmx hbond} analyzes all hydrogen bonds existing
985 between two groups of atoms (which must be either identical or
986 non-overlapping) or in specified donor-hydrogen-acceptor triplets, in
987 the following ways:
988
989 \begin{figure}
990 \centerline{
991 {\includegraphics[width=5cm,angle=270]{plots/hbond-insert}}}
992 \caption[Insertion of water into an H-bond.]{Insertion of water into
993 an H-bond. (1) Normal H-bond between two residues. (2) H-bonding
994 bridge via a water molecule.}
995 \label{fig:insert}
996 \end{figure}
997
998 \begin{itemize}
999 \item
1000 Donor-Acceptor distance ($r$) distribution of all H-bonds
1001 \item
1002 Hydrogen-Donor-Acceptor angle ($\alpha$) distribution of all H-bonds 
1003 \item
1004 The total number of H-bonds in each time frame
1005 \item
1006 \newcommand{\nn}[1]{$n$-$n$+$#1$}
1007 The number of H-bonds in time between residues, divided into groups
1008 \nn{i} where $n$ and $n$+$i$ stand for residue numbers and $i$ goes
1009 from 0 to 6. The group for $i=6$ also includes all H-bonds for
1010 $i>6$. These groups include the \nn{3}, \nn{4} and \nn{5} H-bonds,
1011 which provide a measure for the formation of $\alpha$-helices or
1012 $\beta$-turns or strands.
1013 \item
1014 The lifetime of the H-bonds is calculated from the average over all
1015 autocorrelation functions of the existence functions (either 0 or 1)
1016 of all H-bonds:
1017 \beq
1018 C(\tau) ~=~ \langle s_i(t)~s_i (t + \tau) \rangle
1019 \label{eqn:hbcorr}
1020 \eeq
1021 with $s_i(t) = \{0,1\}$ for H-bond $i$ at time $t$. The integral of
1022 $C(\tau)$ gives a rough estimate of the average H-bond lifetime
1023 $\tau_{HB}$:
1024 \beq
1025 \tau_{HB} ~=~ \int_{0}^{\infty} C(\tau) d\tau
1026 \label{eqn:hblife}
1027 \eeq
1028 Both the integral and the complete autocorrelation function $C(\tau)$
1029 will be output, so that more sophisticated analysis ({\eg}\@ using
1030 multi-exponential fits) can be used to get better estimates for
1031 $\tau_{HB}$. A more complete analysis is given in ref.~\cite{Spoel2006b};
1032 one of the more fancy option is the Luzar and Chandler analysis
1033 of hydrogen bond kinetics~\cite{Luzar96b,Luzar2000a}. 
1034 \item
1035 An H-bond existence map can be generated of dimensions {\em
1036 \#~H-bonds}$\times${\em \#~frames}. The ordering is identical to the index 
1037 file (see below), but reversed, meaning that the last triplet in the index
1038 file corresponds to the first row of the existence map.
1039 \item
1040 Index groups are output containing the analyzed groups, all
1041 donor-hydrogen atom pairs and acceptor atoms in these groups,
1042 donor-hydrogen-acceptor triplets involved in hydrogen bonds between
1043 the analyzed groups and all solvent atoms involved in insertion.
1044
1045 \end{itemize}
1046
1047 %\ifthenelse{\equal{\gmxlite}{1}}{}{
1048 %
1049 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Protein related items 
1050
1051 \section{Protein-related items}
1052 {\tt gmx do_dssp, gmx rama, gmx wheel}\\
1053 To analyze structural changes of a protein, you can calculate the radius of 
1054 gyration or the minimum residue distances over time 
1055 (see \secref{rg}), or calculate the RMSD (\secref{rmsd}).
1056
1057 You can also look at the changing of {\em secondary structure elements} 
1058 during your run. For this, you can use the program {\tt \normindex{gmx do_dssp}}, which is 
1059 an interface for the commercial program {\tt DSSP}~\cite{Kabsch83}. For 
1060 further information, see the {\tt DSSP} manual. A typical output plot of 
1061 {\tt gmx do_dssp} is given in \figref{dssp}.
1062
1063 \begin{figure}
1064 \centerline{
1065 \includegraphics[width=12cm]{plots/dssp}}
1066 \caption{Analysis of the secondary structure elements of a peptide in time.}
1067 \label{fig:dssp}
1068 \end{figure}
1069
1070 One other important analysis of proteins is the so-called 
1071 {\em Ramachandran plot}. 
1072 This is the projection of the structure on the two dihedral angles $\phi$ and 
1073 $\psi$ of the protein backbone, see \figref{phipsi}.
1074
1075 \begin{figure}
1076 \centerline{
1077 \includegraphics[width=5cm]{plots/phipsi}}
1078 \caption{Definition of the dihedral angles $\phi$ and $\psi$ of the protein backbone.}
1079 \label{fig:phipsi}
1080 \end{figure}
1081
1082 To evaluate this Ramachandran plot you can use the program {\tt
1083 \normindex{gmx rama}}.
1084 A typical output is given in \figref{rama}.
1085
1086 \begin{figure}
1087 \centerline{
1088 {\includegraphics[width=8cm]{plots/rama}}}
1089 \caption{Ramachandran plot of a small protein.}
1090 \label{fig:rama}
1091 \end{figure}
1092
1093 When studying $\alpha$-helices 
1094 it is useful to have a {\em helical wheel} projection
1095 of your peptide, to see whether a peptide is amphipathic. This can be done
1096 using the {\tt \normindex{gmx wheel}} program. Two examples are
1097 plotted in \figref{wheel}.
1098
1099 \begin{figure}
1100 \centerline{\includegraphics[width=\htw]{plots/hpr-wheel}}
1101 \caption{Helical wheel projection of the N-terminal helix of HPr.}
1102 \label{fig:wheel}
1103 \end{figure}
1104
1105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Membrane Related Items
1106
1107 \section{Interface-related items}
1108 {\tt gmx order, gmx density, gmx potential, gmx traj}\\
1109 When simulating molecules with long carbon tails, it can be
1110 interesting to calculate their average orientation. There are several
1111 flavors of order parameters, most of which are related. The program
1112 {\tt \normindex{gmx order}} can calculate order parameters using the equation:
1113
1114 \begin{equation}
1115 S_{z} = \frac{3}{2}\langle {\cos^2{\theta_z}} \rangle - \frac{1}{2}
1116 \label{eqn:Sgr}
1117 \end{equation}
1118 where $\theta_z$ is the angle between the $z$-axis of the simulation
1119 box and the molecular axis under consideration. The latter is defined as the
1120 vector from C$_{n-1}$ to C$_{n+1}$. The parameters $S_x$
1121 and $S_y$ are defined in the same way. The brackets imply averaging over time
1122 and molecules. Order parameters can vary between 1 (full order along
1123 the interface normal) and $-1/2$ (full order perpendicular to the
1124 normal), with a value of zero in the case of isotropic orientation.
1125
1126 The program can do two things for you. It can calculate the order
1127 parameter for each CH$_2$ segment separately, for any of three axes,
1128 or it can divide the box in slices and calculate the average value of
1129 the order parameter per segment in one slice. The first method gives
1130 an idea of the ordering of a molecule from head to tail, the second
1131 method gives an idea of the ordering as function of the box length.
1132
1133 The electrostatic potential ($\psi$) across the interface can be
1134 computed from a trajectory by evaluating the double integral of the
1135 charge density ($\rho(z)$):
1136 \beq
1137 \psi(z) - \psi(-\infty) = - \int_{-\infty}^z dz' \int_{-\infty}^{z'} \rho(z'')dz''/ \epsilon_0 
1138 \label{eqn:elpotgr}
1139 \eeq
1140 where the position $z=-\infty$ is far enough in the bulk phase such that
1141 the field is zero.  With this method, it is possible to ``split'' the
1142 total potential into separate contributions from lipid and water
1143 molecules. The program {\tt \normindex{gmx potential}} divides the box in slices and
1144 sums all charges of the atoms in each slice. It then integrates this
1145 charge density to give the electric field, which is in turn integrated to
1146 give the potential. Charge density, electric field, and potential are written
1147 to {\tt xvgr} input files.
1148
1149 The program {\tt \normindex{gmx traj}} is a very simple analysis program. All it
1150 does is print the coordinates, velocities, or forces of selected atoms.
1151 It can also calculate the center of mass of one or more
1152 molecules and print the coordinates of the center of mass to three
1153 files. By itself, this is probably not a very useful analysis, but
1154 having the coordinates of selected molecules or atoms can be very
1155 handy for further analysis, not only in interfacial systems.
1156
1157 The program {\tt \normindex{gmx density}} calculates the mass density of
1158 groups and gives a plot of the density against a box
1159 axis. This is useful for looking at the distribution of groups or
1160 atoms across the interface.
1161
1162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Chemical shifts
1163
1164 % \section{Chemical shifts}
1165 % {\tt total, do_shift}\\
1166 % You can compute the NMR chemical shifts of protons with the program
1167 % {\tt \normindex{do_shift}}. This is just an {\gromacs} interface to
1168 % the public domain program {\tt total}~\cite{Williamson93a}. For
1169 % further information, read the article. Although there is limited
1170 % support for this in {\gromacs}, users are encouraged to use the
1171 % software provided by David Case's group at Scripps because it seems
1172 % to be more up-to-date.
1173
1174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1175 %} % Brace matches ifthenelse test for gmxlite
1176
1177 % LocalWords:  Xmgr ndx mk angndx rdf dihedrals grompp hydrogens MainChain Prot
1178 % LocalWords:  oxygens SideChain tryptophan vsitetop aminoacids dat ngmx dr SPC
1179 % LocalWords:  OO ACF fg xmgr corrmd ACFs kM iM FFT th NMR nd corrleg rotacf dt
1180 % LocalWords:  velacc Kubo msd Tildesley corrtime msdwater sgangle cis dih xpm
1181 % LocalWords:  mindist mdmat rms rmsdist rmsd jj diag eigenvectors covar anaeig
1182 % LocalWords:  macromolecule trr tpr gro pdb nofit hbond rclcl HB multi Luzar
1183 % LocalWords:  dssp rama xrama rg Ramachandran phipsi amphipathic HPr xvgr pvd
1184 % LocalWords:  Scripps RDF online usinggroups mdrun groupconcept HOH
1185 % LocalWords:  residuetypes determinding OpenGL traj ov rcl ij ps nm
1186 % LocalWords:  autocorrelation interfacial pairdist