Merge branch release-2016
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 31 Mar 2017 14:29:54 +0000 (16:29 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 31 Mar 2017 14:29:54 +0000 (16:29 +0200)
Change-Id: I536af0bcfba93ecf3e2afeb847120dc8f637cc92

docs/CMakeLists.txt
docs/manual/topology.tex
docs/user-guide/index.rst
docs/user-guide/managing-simulations.rst [new file with mode: 0644]
docs/user-guide/mdp-options.rst
src/gromacs/gmxana/gmx_xpm2ps.cpp
src/gromacs/gmxpreprocess/readir.cpp

index bf033c4baf890506ca68b04996e4a78a0bbaa0c3..9fe64470444d1b40deb0ce5aeb84c8470606202b 100644 (file)
@@ -122,6 +122,7 @@ if (SPHINX_FOUND)
         user-guide/flow.rst
         user-guide/system-preparation.rst
         user-guide/cutoff-schemes.rst
+        user-guide/managing-simulations.rst
         user-guide/mdrun-features.rst
         user-guide/mdrun-performance.rst
         user-guide/mdp-options.rst
index c92e3fd7be7768626817d204baa1a4f85e3d700d..603d3e217619684b21b590c910cffca6209832bc 100644 (file)
@@ -1,7 +1,7 @@
 %
 % This file is part of the GROMACS molecular simulation package.
 %
-% Copyright (c) 2013,2014,2015,2016, by the GROMACS development team, led by
+% Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
 % Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
 % and including many others, as listed in the AUTHORS file in the
 % top-level source directory and at http://www.gromacs.org.
@@ -1310,7 +1310,7 @@ position restraint                 & {\ttss position_restraints}    & 1     & 1
 flat-bottomed position restraint   & {\ttss position_restraints}    & 1     & 2     & $g$, $r$ (nm), $k$ (\kJmolnm{-2})                     &            & \ssecref{fbpositionrestraint} \\
 %restraint potential                & {\tts bonds}                   & 2     & 10    & low, up$_1$, up$_2$ (nm); $k_{dr}$ (\kJmolnm{-2})     &            & \ssecref{} \\
 distance restraint                 & {\ttss distance_restraints}    & 2     & 1     & type; label; low, up$_1$, up$_2$ (nm); weight ()      &            & \ssecref{distancerestraint} \\
-dihedral restraint                 & {\ttss dihedral_restraints}    & 4     & 1     & $\phi_0$ (deg); $\Delta\phi$ (deg); &    all   & \ssecref{dihedralrestraint} \\
+dihedral restraint                 & {\ttss dihedral_restraints}    & 4     & 1     & $\phi_0$ (deg); $\Delta\phi$ (deg); $k_\mathrm{dihr}$ (\kJmolrad{-2}) &    all   & \ssecref{dihedralrestraint} \\
 orientation restraint              & {\ttss orientation_restraints} & 2     & 1     & exp.; label; $\alpha$; $c$ (U nm$^\alpha$); obs. (U); weight (U$^{-1}$) & & \ssecref{orientationrestraint} \\
 angle restraint                    & {\ttss angle_restraints}       & 4     & 1     & $\theta_0$ (deg); $k_c$ (\kJmol); multiplicity        & $\theta,k$ & \ssecref{anglerestraint} \\
 angle restraint (z)                & {\ttss angle_restraints_z}     & 2     & 1     & $\theta_0$ (deg); $k_c$ (\kJmol); multiplicity        & $\theta,k$ & \ssecref{anglerestraint} \\
index 625c3d53ac4ee205c36e67da25a333239d26173c..0f48df976f87bd72f7ece503d347d384c8116c2d 100644 (file)
@@ -24,6 +24,7 @@ For background on algorithms and implementations, see the
    cutoff-schemes
    mdrun-features
    mdrun-performance
+   managing-simulations
    mdp-options
    file-formats
    cmdline
diff --git a/docs/user-guide/managing-simulations.rst b/docs/user-guide/managing-simulations.rst
new file mode 100644 (file)
index 0000000..136cd4b
--- /dev/null
@@ -0,0 +1,223 @@
+Managing long simulations
+=========================
+
+Molecular simulations often extend beyond the lifetime of a single
+UNIX command-line process. It is useful to be able to stop and
+restart the simulation in a
+way that is equivalent to a single run. When :ref:`gmx mdrun` is
+halted, it writes a checkpoint file that can restart the simulation
+exactly as if there was no interruption. To do this, the checkpoint
+retains a full-precision version of the positions and velocities,
+along with state information necessary to restart algorithms e.g.
+that implement coupling to external thermal reservoirs. A restart can
+be attempted using e.g. a :ref:`gro` file with velocities, but since
+the :ref:`gro` file has significantly less precision, and none of
+the coupling algorithms will have their state carried over, such
+a restart is less continuous than a normal MD step.
+
+Such a checkpoint file is also written periodically by :ref:`gmx
+mdrun` during the run. The interval is given by the ``-cpt`` flag to
+:ref:`gmx mdrun`. When :ref:`gmx mdrun` attemps to write each
+successive checkpoint file, it first renames the old file with the
+suffix ``_prev``, so that even if something goes wrong while writing
+the new checkpoint file, only recent progress can be lost.
+
+:ref:`gmx mdrun` can be halted in several ways:
+
+* the number of simulation :mdp:`nsteps` can expire
+* the user issues a termination signal (e.g. with Ctrl-C on the terminal)
+* the job scheduler issues a termination signal when time expires
+* when :ref:`gmx mdrun` detects that the length specified with
+  ``-maxh`` has elapsed (this option is useful to help cooperate with
+  a job scheduler, but can be problematic if jobs can be suspended)
+* some kind of catastrophic failure, such as loss of power, or a
+  disk filling up, or a network failing
+
+To use the checkpoint file for a restart, use a command line such as
+
+::
+
+   gmx mdrun -cpi state
+
+which directs mdrun to use the checkpoint file (which is named
+``state.cpt`` by default). You can choose to give the output
+checkpoint file a different name with the ``-cpo`` flag, but if so
+then you must provide that name as input to ``-cpi`` when you later
+use that file. You can
+query the contents of checkpoint files with :ref:`gmx check` and
+:ref:`gmx dump`.
+
+Appending to output files
+-------------------------
+
+By default, :ref:`gmx mdrun` will append to the old output files. If
+the previous part ended in a regular way, then the performance data at
+the end of the log file will will be removed, some new information
+about the run context written, and the simulation will proceed. Otherwise,
+mdrun will truncate all the output files back to the time of the last
+written checkpoint file, and continue from there, as if the simulation
+stopped at that checkpoint in a regular way.
+
+You can choose not to append the output files by using the
+``-noappend`` flag, which forces mdrun to write each output to a
+separate file, whose name includes a ".partXXXX" string to describe
+which simulation part is contained in this file. This numbering starts
+from zero and increases monotonically as simulations are restarted,
+but does not reflect the number of simulation steps in each part. The
+:mdp:`simulation-part` option can be used to set this number manually
+in :ref:`gmx grompp`, which can be useful if data has been lost,
+e.g. through filesystem failure or user error.
+
+Appending will not work if any output files have been modified or
+removed after mdrun wrote them, because the checkpoint file maintains
+a checksum of each file that it will verify before it writes to them
+again. In such cases, you must either restore the file, name them
+as the checkpoint file expects, or continue with ``-noappend``. If
+your original run used ``-deffnm``, and you want appending, then
+your continuations must also use ``-deffnm``.
+
+Backing up your files
+---------------------
+
+You should arrange to back up your simulation files frequently. Network
+file systems on clusters can be configured in more or less conservative
+ways, and this can lead :ref:`gmx mdrun` to be told that a checkpoint
+file has been written to disk when actually it is still in memory
+somewhere and vulnerable to a power failure or disk that fills or 
+fails in the meantime. The UNIX tool rsync can be a useful way to
+periodically copy your simulation output to a remote storage location,
+which works safely even while the simulation is underway. Keeping a copy
+of the final checkpoint file from each part of a job submitted to a
+cluster can be useful if a file system is unreliable.
+
+Extending a .tpr file
+---------------------
+
+If the simulation described by :ref:`tpr` file has completed and should
+be extended, use the :ref:`gmx convert-tpr` tool to extend the run, e.g.
+
+::
+
+   gmx convert-tpr -s previous.tpr -extend timetoextendby -o next.tpr
+   gmx mdrun -s next.tpr -cpi state.cpt
+
+The time can also be extended using the ``-until`` and ``-nsteps``
+options. Note that the original :ref:`mdp` file may have generated
+velocities, but that is a one-time operation within :ref:`gmx grompp`
+that is never performed again by any other tool. 
+
+Changing mdp options for a restart
+----------------------------------
+
+If you wish to make changes to your simulations settings other than
+length, then you should do so in the :ref:`mdp` file or topology, and
+then call
+
+::
+
+   gmx grompp -f possibly-changed.mdp -p possibly-changed.top -c state.cpt -o new.tpr
+   gmx mdrun -s new.tpr -cpi state.cpt
+
+to instruct :ref:`gmx grompp` to copy the full-precision coordinates
+in the checkpoint file into the new :ref:`tpr` file. You should
+consider your choices for :mdp:`tinit`, :mdp:`init-step`,
+:mdp:`nsteps` and :mdp:`simulation-part`. You should generally not
+regenerate velocities with :mdp:`gen-vel`, and generally select
+:mdp:`continuation` so that constraints are not re-applied before
+the first integration step.
+
+Restarts without checkpoint files
+---------------------------------
+
+It is possible to perform an exact restart a simulation if you lack a
+checkpoint file but have a matching pair of frames in a :ref:`trr` and
+:ref:`edr` file written by :ref:`gmx mdrun`. To do this, use
+
+::
+
+   gmx convert-tpr -s old.tpr -e matching.edr -t matching.trr -o new.tpr
+
+Are continuations exact?
+------------------------
+
+If you had a computer with unlimited precision, or if you integrated
+the time-discretized equations of motion by hand, exact continuation
+would lead to identical results. But since practical computers have
+limited precision and MD is chaotic, trajectories will diverge very
+rapidly even if one bit is different. Such trajectories will all be
+equally valid, but eventually very different. Continuation using a
+checkpoint file, using the same code compiled with the same compiler
+and running on the same computer architecture using the same number of
+processors without GPUs (see next section) would lead to binary
+identical results. However,
+by default the actual work load will be balanced across the hardware
+according to the observed execution times. Such trajectories are
+in principle not reproducible, and in particular a run that took
+place in more than one part will not be identical with an equivalent
+run in one part - but neither of them is better in any sense.
+
+Reproducibility
+---------------
+
+The following factors affect the reproducibility of a simulation, and thus its output:
+
+* Precision (mixed / double) with double giving "better" reproducibility.
+* Number of cores, due to different order in which forces are
+  accumulated. For instance (a+b)+c is not necessarily binary
+  identical to a+(b+c) in floating-point arithmetic.
+* Type of processors. Even within the same processor family there can be slight differences.
+* Optimization level when compiling.
+* Optimizations at run time: e.g. the FFTW library that is typically
+  used for fast Fourier transforms determines at startup which version
+  of their algorithms is fastest, and uses that for the remainder of
+  the calculations. Since the speed estimate is not deterministic, the
+  results may vary from run to run.
+* Random numbers used for instance as a seed for generating velocities
+  (in GROMACS at the preprocessing stage).
+* Uninitialized variables in the code (but there shouldn't be any)
+* Dynamic linking to different versions of shared libraries (e.g. for FFTs)
+* Dynamic load balancing, since particles are redistributed to
+  processors based on elapsed wallclock time, which will lead to
+  (a+b)+c != a+(b+c) issues as above
+* Number of PME-only ranks (for parallel PME simulations)
+* MPI reductions typically do not guarantee the order of the
+  operations, and so the absence of associativity for floating-point
+  arithmetic means the result of a reduction depends on the order
+  actually chosen
+* On GPUs, the reduction of e.g. non-bonded forces has a non-deterministic
+  summation order, so any fast implementation is non-reprodudible by
+  design.
+
+The important question is whether it is a problem if simulations are
+not completely reproducible. The answer is yes and no. Reproducibility
+is a cornerstone of science in general, and hence it is important.
+The `Central Limit Theorem <https://en.wikipedia.org/wiki/Central_limit_theorem>`
+tells us that in the case of infinitely long
+simulations, all observables converge to their equilibrium
+values. Molecular simulations in GROMACS adhere to this theorem, and
+hence, for instance, the energy of your system will converge to a
+finite value, the diffusion constant of your water molecules will
+converge to a finite value, and so on. That means all the important
+observables, which are the values you would like to get out of your
+simulation, are reproducible. Each individual trajectory is not
+reproducible, however.
+
+However, there are a few cases where it would be useful if
+trajectories were reproducible, too. These include developers doing
+debugging, and searching for a rare event in a trajectory when, if
+it occurs, you want to have manually saved your checkpoint file so
+you can restart the simulation under different conditions, e.g.
+writing output much more frequently.
+
+In order to obtain this reproducible trajectory, it is important
+to look over the list above and eliminate the factors that could
+affect it. Further, using
+
+::
+
+   gmx mdrun -reprod
+
+will eliminate all sources of non-reproducibility that it can,
+i.e. same executable + same hardware + same shared libraries + same
+run input file + same command line parameters will lead to
+reproducible results.
index 54d7e19b64de663e8d8fab277b96638704f82046..e111c89668041f097d9dfd3686a810864c34c35d 100644 (file)
@@ -209,6 +209,15 @@ Run control
         the step number of the restart frame. :ref:`gmx convert-tpr`
         does this automatically.
 
+.. mdp:: simulation-part
+
+         (0)
+         A simulation can consist of multiple parts, each of which has
+         a part number. This option specifies what that number will
+         be, which helps keep track of parts that are logically the
+         same simulation. This option is generally useful to set only
+         when coping with a crashed simulation where files were lost.
+
 .. mdp:: comm-mode
 
    .. mdp-value:: Linear
@@ -1615,7 +1624,7 @@ applicable pulling coordinate.
    their periodic image which is closest to
    :mdp:`pull-group1-pbcatom`. A value of 0 means that the middle
    atom (number wise) is used. This parameter is not used with
-   :mdp:`pull-group1-geometry` cylinder. A value of -1 turns on cosine
+   :mdp:`pull-coord1-geometry` cylinder. A value of -1 turns on cosine
    weighting, which is useful for a group of molecules in a periodic
    system, *e.g.* a water slab (see Engin et al. J. Chem. Phys. B
    2010).
index cec4fe8ca105cf12b85572667673967b1a332341..90f0448fb10b20cbd37b0ada91a8fbb96de5b94b 100644 (file)
@@ -43,6 +43,7 @@
 #include <cstring>
 
 #include <algorithm>
+#include <string>
 
 #include "gromacs/commandline/pargs.h"
 #include "gromacs/commandline/viewit.h"
@@ -60,6 +61,7 @@
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/stringutil.h"
 
 #define FUDGE 1.2
 #define DDD   2
@@ -791,7 +793,7 @@ void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
             int mapoffset)
 {
     const char   *libm2p;
-    char          buf[256], *legend;
+    char         *legend;
     t_psdata      out;
     t_psrec       psrec, *psr;
     int           W, H;
@@ -932,19 +934,19 @@ void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
             /* Print title, if any */
             ps_rgb(out, BLACK);
             ps_strfont(out, psr->titfont, psr->titfontsize);
+            std::string buf;
             if (!mat2 || (std::strcmp(mat[i].title, mat2[i].title) == 0))
             {
-                std::strcpy(buf, mat[i].title);
+                buf = mat[i].title;
             }
             else
             {
-                sprintf(buf, "%s / %s", mat[i].title, mat2[i].title);
+                buf = gmx::formatString("%s / %s", mat[i].title, mat2[i].title);
             }
             ps_ctext(out, x0+w/2, y0+box_height(&(mat[i]), psr)+psr->titfontsize,
-                     buf, eXCenter);
+                     buf.c_str(), eXCenter);
         }
-        sprintf(buf, "Here starts the filling of box #%d", i);
-        ps_comment(out, buf);
+        ps_comment(out, gmx::formatString("Here starts the filling of box #%d", i).c_str());
         for (x = 0; (x < mat[i].nx); x++)
         {
             int nexty;
index c90f0dfec62723e0ea3f961dc049e2447786b3e0..a2952f296e24ba68efad0df35f5f8ea5bc9f2eb5 100644 (file)
@@ -45,6 +45,7 @@
 #include <cmath>
 
 #include <algorithm>
+#include <string>
 
 #include "gromacs/fileio/readinp.h"
 #include "gromacs/fileio/warninp.h"
@@ -2549,8 +2550,7 @@ void get_ir(const char *mdparin, const char *mdparout,
 
     if (strlen(is->deform) > 0 && ndeform != 6)
     {
-        sprintf(warn_buf, "Cannot parse exactly 6 box deformation velocities from string '%s'", is->deform);
-        warning_error(wi, warn_buf);
+        warning_error(wi, gmx::formatString("Cannot parse exactly 6 box deformation velocities from string '%s'", is->deform).c_str());
     }
     for (i = 0; i < 3; i++)
     {