Add membrane embedding docs
[alexxy/gromacs.git] / src / programs / mdrun / mdrun.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 /*! \defgroup module_mdrun Implementation of mdrun
38  * \ingroup group_mdrun
39  *
40  * \brief This module contains code that implements mdrun.
41  */
42 /*! \internal \file
43  *
44  * \brief This file implements mdrun
45  *
46  * \author Berk Hess <hess@kth.se>
47  * \author David van der Spoel <david.vanderspoel@icm.uu.se>
48  * \author Erik Lindahl <erik@kth.se>
49  * \author Mark Abraham <mark.j.abraham@gmail.com>
50  *
51  * \ingroup module_mdrun
52  */
53 #include "gmxpre.h"
54
55 #include "config.h"
56
57 #include <stdio.h>
58 #include <string.h>
59
60 #include "gromacs/commandline/pargs.h"
61 #include "gromacs/fileio/filenm.h"
62 #include "gromacs/legacyheaders/macros.h"
63 #include "gromacs/legacyheaders/main.h"
64 #include "gromacs/legacyheaders/mdrun.h"
65 #include "gromacs/legacyheaders/network.h"
66 #include "gromacs/legacyheaders/readinp.h"
67 #include "gromacs/legacyheaders/typedefs.h"
68 #include "gromacs/legacyheaders/types/commrec.h"
69 #include "gromacs/mdrunutility/handlerestart.h"
70 #include "gromacs/utility/fatalerror.h"
71
72 #include "mdrun_main.h"
73
74 /*! \brief Return whether either of the command-line parameters that
75  *  will trigger a multi-simulation is set */
76 static bool is_multisim_option_set(int argc, const char *const argv[])
77 {
78     for (int i = 0; i < argc; ++i)
79     {
80         if (strcmp(argv[i], "-multi") == 0 || strcmp(argv[i], "-multidir") == 0)
81         {
82             return true;
83         }
84     }
85     return false;
86 }
87
88 //! Implements C-style main function for mdrun
89 int gmx_mdrun(int argc, char *argv[])
90 {
91     const char   *desc[] = {
92         "[THISMODULE] is the main computational chemistry engine",
93         "within GROMACS. Obviously, it performs Molecular Dynamics simulations,",
94         "but it can also perform Stochastic Dynamics, Energy Minimization,",
95         "test particle insertion or (re)calculation of energies.",
96         "Normal mode analysis is another option. In this case [TT]mdrun[tt]",
97         "builds a Hessian matrix from single conformation.",
98         "For usual Normal Modes-like calculations, make sure that",
99         "the structure provided is properly energy-minimized.",
100         "The generated matrix can be diagonalized by [gmx-nmeig].[PAR]",
101         "The [TT]mdrun[tt] program reads the run input file ([TT]-s[tt])",
102         "and distributes the topology over ranks if needed.",
103         "[TT]mdrun[tt] produces at least four output files.",
104         "A single log file ([TT]-g[tt]) is written.",
105         "The trajectory file ([TT]-o[tt]), contains coordinates, velocities and",
106         "optionally forces.",
107         "The structure file ([TT]-c[tt]) contains the coordinates and",
108         "velocities of the last step.",
109         "The energy file ([TT]-e[tt]) contains energies, the temperature,",
110         "pressure, etc, a lot of these things are also printed in the log file.",
111         "Optionally coordinates can be written to a compressed trajectory file",
112         "([TT]-x[tt]).[PAR]",
113         "The option [TT]-dhdl[tt] is only used when free energy calculation is",
114         "turned on.[PAR]",
115         "Running mdrun efficiently in parallel is a complex topic topic,",
116         "many aspects of which are covered in the online User Guide. You",
117         "should look there for practical advice on using many of the options",
118         "available in mdrun.[PAR]",
119         "ED (essential dynamics) sampling and/or additional flooding potentials",
120         "are switched on by using the [TT]-ei[tt] flag followed by an [REF].edi[ref]",
121         "file. The [REF].edi[ref] file can be produced with the [TT]make_edi[tt] tool",
122         "or by using options in the essdyn menu of the WHAT IF program.",
123         "[TT]mdrun[tt] produces a [REF].xvg[ref] output file that",
124         "contains projections of positions, velocities and forces onto selected",
125         "eigenvectors.[PAR]",
126         "When user-defined potential functions have been selected in the",
127         "[REF].mdp[ref] file the [TT]-table[tt] option is used to pass [TT]mdrun[tt]",
128         "a formatted table with potential functions. The file is read from",
129         "either the current directory or from the [TT]GMXLIB[tt] directory.",
130         "A number of pre-formatted tables are presented in the [TT]GMXLIB[tt] dir,",
131         "for 6-8, 6-9, 6-10, 6-11, 6-12 Lennard-Jones potentials with",
132         "normal Coulomb.",
133         "When pair interactions are present, a separate table for pair interaction",
134         "functions is read using the [TT]-tablep[tt] option.[PAR]",
135         "When tabulated bonded functions are present in the topology,",
136         "interaction functions are read using the [TT]-tableb[tt] option.",
137         "For each different tabulated interaction type the table file name is",
138         "modified in a different way: before the file extension an underscore is",
139         "appended, then a 'b' for bonds, an 'a' for angles or a 'd' for dihedrals",
140         "and finally the table number of the interaction type.[PAR]",
141         "The options [TT]-px[tt] and [TT]-pf[tt] are used for writing pull COM",
142         "coordinates and forces when pulling is selected",
143         "in the [REF].mdp[ref] file.[PAR]",
144         "Finally some experimental algorithms can be tested when the",
145         "appropriate options have been given. Currently under",
146         "investigation are: polarizability.",
147         "[PAR]",
148         "The option [TT]-membed[tt] does what used to be g_membed, i.e. embed",
149         "a protein into a membrane. This module requires a number of settings",
150         "that are provided in a data file that is the argument of this option.",
151         "For more details in membrane embedding, see the documentation in the",
152         "user guide. The options [TT]-mn[tt] and [TT]-mp[tt] are used to provide",
153         "the index and topology files used for the embedding.",
154         "[PAR]",
155         "The option [TT]-pforce[tt] is useful when you suspect a simulation",
156         "crashes due to too large forces. With this option coordinates and",
157         "forces of atoms with a force larger than a certain value will",
158         "be printed to stderr.",
159         "[PAR]",
160         "Checkpoints containing the complete state of the system are written",
161         "at regular intervals (option [TT]-cpt[tt]) to the file [TT]-cpo[tt],",
162         "unless option [TT]-cpt[tt] is set to -1.",
163         "The previous checkpoint is backed up to [TT]state_prev.cpt[tt] to",
164         "make sure that a recent state of the system is always available,",
165         "even when the simulation is terminated while writing a checkpoint.",
166         "With [TT]-cpnum[tt] all checkpoint files are kept and appended",
167         "with the step number.",
168         "A simulation can be continued by reading the full state from file",
169         "with option [TT]-cpi[tt]. This option is intelligent in the way that",
170         "if no checkpoint file is found, GROMACS just assumes a normal run and",
171         "starts from the first step of the [REF].tpr[ref] file. By default the output",
172         "will be appending to the existing output files. The checkpoint file",
173         "contains checksums of all output files, such that you will never",
174         "loose data when some output files are modified, corrupt or removed.",
175         "There are three scenarios with [TT]-cpi[tt]:[PAR]",
176         "[TT]*[tt] no files with matching names are present: new output files are written[PAR]",
177         "[TT]*[tt] all files are present with names and checksums matching those stored",
178         "in the checkpoint file: files are appended[PAR]",
179         "[TT]*[tt] otherwise no files are modified and a fatal error is generated[PAR]",
180         "With [TT]-noappend[tt] new output files are opened and the simulation",
181         "part number is added to all output file names.",
182         "Note that in all cases the checkpoint file itself is not renamed",
183         "and will be overwritten, unless its name does not match",
184         "the [TT]-cpo[tt] option.",
185         "[PAR]",
186         "With checkpointing the output is appended to previously written",
187         "output files, unless [TT]-noappend[tt] is used or none of the previous",
188         "output files are present (except for the checkpoint file).",
189         "The integrity of the files to be appended is verified using checksums",
190         "which are stored in the checkpoint file. This ensures that output can",
191         "not be mixed up or corrupted due to file appending. When only some",
192         "of the previous output files are present, a fatal error is generated",
193         "and no old output files are modified and no new output files are opened.",
194         "The result with appending will be the same as from a single run.",
195         "The contents will be binary identical, unless you use a different number",
196         "of ranks or dynamic load balancing or the FFT library uses optimizations",
197         "through timing.",
198         "[PAR]",
199         "With option [TT]-maxh[tt] a simulation is terminated and a checkpoint",
200         "file is written at the first neighbor search step where the run time",
201         "exceeds [TT]-maxh[tt]\\*0.99 hours. This option is particularly useful in",
202         "combination with setting [TT]nsteps[tt] to -1 either in the mdp or using the",
203         "similarly named command line option. This results in an infinite run,",
204         "terminated only when the time limit set by [TT]-maxh[tt] is reached (if any)"
205         "or upon receiving a signal."
206         "[PAR]",
207         "When [TT]mdrun[tt] receives a TERM signal, it will set nsteps to the current",
208         "step plus one. When [TT]mdrun[tt] receives an INT signal (e.g. when ctrl+C is",
209         "pressed), it will stop after the next neighbor search step ",
210         "(with nstlist=0 at the next step).",
211         "In both cases all the usual output will be written to file.",
212         "When running with MPI, a signal to one of the [TT]mdrun[tt] ranks",
213         "is sufficient, this signal should not be sent to mpirun or",
214         "the [TT]mdrun[tt] process that is the parent of the others.",
215         "[PAR]",
216         "Interactive molecular dynamics (IMD) can be activated by using at least one",
217         "of the three IMD switches: The [TT]-imdterm[tt] switch allows to terminate the",
218         "simulation from the molecular viewer (e.g. VMD). With [TT]-imdwait[tt],",
219         "[TT]mdrun[tt] pauses whenever no IMD client is connected. Pulling from the",
220         "IMD remote can be turned on by [TT]-imdpull[tt].",
221         "The port [TT]mdrun[tt] listens to can be altered by [TT]-imdport[tt].The",
222         "file pointed to by [TT]-if[tt] contains atom indices and forces if IMD",
223         "pulling is used."
224         "[PAR]",
225         "When [TT]mdrun[tt] is started with MPI, it does not run niced by default."
226     };
227     t_commrec    *cr;
228     t_filenm      fnm[] = {
229         { efTPR, NULL,      NULL,       ffREAD },
230         { efTRN, "-o",      NULL,       ffWRITE },
231         { efCOMPRESSED, "-x", NULL,     ffOPTWR },
232         { efCPT, "-cpi",    NULL,       ffOPTRD | ffALLOW_MISSING },
233         { efCPT, "-cpo",    NULL,       ffOPTWR },
234         { efSTO, "-c",      "confout",  ffWRITE },
235         { efEDR, "-e",      "ener",     ffWRITE },
236         { efLOG, "-g",      "md",       ffWRITE },
237         { efXVG, "-dhdl",   "dhdl",     ffOPTWR },
238         { efXVG, "-field",  "field",    ffOPTWR },
239         { efXVG, "-table",  "table",    ffOPTRD },
240         { efXVG, "-tabletf", "tabletf",    ffOPTRD },
241         { efXVG, "-tablep", "tablep",   ffOPTRD },
242         { efXVG, "-tableb", "table",    ffOPTRD },
243         { efTRX, "-rerun",  "rerun",    ffOPTRD },
244         { efXVG, "-tpi",    "tpi",      ffOPTWR },
245         { efXVG, "-tpid",   "tpidist",  ffOPTWR },
246         { efEDI, "-ei",     "sam",      ffOPTRD },
247         { efXVG, "-eo",     "edsam",    ffOPTWR },
248         { efXVG, "-devout", "deviatie", ffOPTWR },
249         { efXVG, "-runav",  "runaver",  ffOPTWR },
250         { efXVG, "-px",     "pullx",    ffOPTWR },
251         { efXVG, "-pf",     "pullf",    ffOPTWR },
252         { efXVG, "-ro",     "rotation", ffOPTWR },
253         { efLOG, "-ra",     "rotangles", ffOPTWR },
254         { efLOG, "-rs",     "rotslabs", ffOPTWR },
255         { efLOG, "-rt",     "rottorque", ffOPTWR },
256         { efMTX, "-mtx",    "nm",       ffOPTWR },
257         { efNDX, "-dn",     "dipole",   ffOPTWR },
258         { efRND, "-multidir", NULL,      ffOPTRDMULT},
259         { efDAT, "-membed", "membed",   ffOPTRD },
260         { efTOP, "-mp",     "membed",   ffOPTRD },
261         { efNDX, "-mn",     "membed",   ffOPTRD },
262         { efXVG, "-if",     "imdforces", ffOPTWR },
263         { efXVG, "-swap",   "swapions", ffOPTWR }
264     };
265     const int     NFILE = asize(fnm);
266
267     /* Command line options ! */
268     gmx_bool        bDDBondCheck  = TRUE;
269     gmx_bool        bDDBondComm   = TRUE;
270     gmx_bool        bTunePME      = TRUE;
271     gmx_bool        bVerbose      = FALSE;
272     gmx_bool        bCompact      = TRUE;
273     gmx_bool        bRerunVSite   = FALSE;
274     gmx_bool        bConfout      = TRUE;
275     gmx_bool        bReproducible = FALSE;
276     gmx_bool        bIMDwait      = FALSE;
277     gmx_bool        bIMDterm      = FALSE;
278     gmx_bool        bIMDpull      = FALSE;
279
280     int             npme          = -1;
281     int             nstlist       = 0;
282     int             nmultisim     = 0;
283     int             nstglobalcomm = -1;
284     int             repl_ex_nst   = 0;
285     int             repl_ex_seed  = -1;
286     int             repl_ex_nex   = 0;
287     int             nstepout      = 100;
288     int             resetstep     = -1;
289     gmx_int64_t     nsteps        = -2;   /* the value -2 means that the mdp option will be used */
290     int             imdport       = 8888; /* can be almost anything, 8888 is easy to remember */
291
292     rvec            realddxyz          = {0, 0, 0};
293     const char     *ddno_opt[ddnoNR+1] =
294     { NULL, "interleave", "pp_pme", "cartesian", NULL };
295     const char     *dddlb_opt[] =
296     { NULL, "auto", "no", "yes", NULL };
297     const char     *thread_aff_opt[threadaffNR+1] =
298     { NULL, "auto", "on", "off", NULL };
299     const char     *nbpu_opt[] =
300     { NULL, "auto", "cpu", "gpu", "gpu_cpu", NULL };
301     real            rdd                   = 0.0, rconstr = 0.0, dlb_scale = 0.8, pforce = -1;
302     char           *ddcsx                 = NULL, *ddcsy = NULL, *ddcsz = NULL;
303     real            cpt_period            = 15.0, max_hours = -1;
304     gmx_bool        bTryToAppendFiles     = TRUE;
305     gmx_bool        bKeepAndNumCPT        = FALSE;
306     gmx_bool        bResetCountersHalfWay = FALSE;
307     output_env_t    oenv                  = NULL;
308
309     /* Non transparent initialization of a complex gmx_hw_opt_t struct.
310      * But unfortunately we are not allowed to call a function here,
311      * since declarations follow below.
312      */
313     gmx_hw_opt_t    hw_opt = {
314         0, 0, 0, 0, threadaffSEL, 0, 0,
315         { NULL, FALSE, 0, NULL }
316     };
317
318     t_pargs         pa[] = {
319
320         { "-dd",      FALSE, etRVEC, {&realddxyz},
321           "Domain decomposition grid, 0 is optimize" },
322         { "-ddorder", FALSE, etENUM, {ddno_opt},
323           "DD rank order" },
324         { "-npme",    FALSE, etINT, {&npme},
325           "Number of separate ranks to be used for PME, -1 is guess" },
326         { "-nt",      FALSE, etINT, {&hw_opt.nthreads_tot},
327           "Total number of threads to start (0 is guess)" },
328         { "-ntmpi",   FALSE, etINT, {&hw_opt.nthreads_tmpi},
329           "Number of thread-MPI threads to start (0 is guess)" },
330         { "-ntomp",   FALSE, etINT, {&hw_opt.nthreads_omp},
331           "Number of OpenMP threads per MPI rank to start (0 is guess)" },
332         { "-ntomp_pme", FALSE, etINT, {&hw_opt.nthreads_omp_pme},
333           "Number of OpenMP threads per MPI rank to start (0 is -ntomp)" },
334         { "-pin",     FALSE, etENUM, {thread_aff_opt},
335           "Whether mdrun should try to set thread affinities" },
336         { "-pinoffset", FALSE, etINT, {&hw_opt.core_pinning_offset},
337           "The lowest logical core number to which mdrun should pin the first thread" },
338         { "-pinstride", FALSE, etINT, {&hw_opt.core_pinning_stride},
339           "Pinning distance in logical cores for threads, use 0 to minimize the number of threads per physical core" },
340         { "-gpu_id",  FALSE, etSTR, {&hw_opt.gpu_opt.gpu_id},
341           "List of GPU device id-s to use, specifies the per-node PP rank to GPU mapping" },
342         { "-ddcheck", FALSE, etBOOL, {&bDDBondCheck},
343           "Check for all bonded interactions with DD" },
344         { "-ddbondcomm", FALSE, etBOOL, {&bDDBondComm},
345           "HIDDENUse special bonded atom communication when [TT]-rdd[tt] > cut-off" },
346         { "-rdd",     FALSE, etREAL, {&rdd},
347           "The maximum distance for bonded interactions with DD (nm), 0 is determine from initial coordinates" },
348         { "-rcon",    FALSE, etREAL, {&rconstr},
349           "Maximum distance for P-LINCS (nm), 0 is estimate" },
350         { "-dlb",     FALSE, etENUM, {dddlb_opt},
351           "Dynamic load balancing (with DD)" },
352         { "-dds",     FALSE, etREAL, {&dlb_scale},
353           "Fraction in (0,1) by whose reciprocal the initial DD cell size will be increased in order to "
354           "provide a margin in which dynamic load balancing can act while preserving the minimum cell size." },
355         { "-ddcsx",   FALSE, etSTR, {&ddcsx},
356           "HIDDENA string containing a vector of the relative sizes in the x "
357           "direction of the corresponding DD cells. Only effective with static "
358           "load balancing." },
359         { "-ddcsy",   FALSE, etSTR, {&ddcsy},
360           "HIDDENA string containing a vector of the relative sizes in the y "
361           "direction of the corresponding DD cells. Only effective with static "
362           "load balancing." },
363         { "-ddcsz",   FALSE, etSTR, {&ddcsz},
364           "HIDDENA string containing a vector of the relative sizes in the z "
365           "direction of the corresponding DD cells. Only effective with static "
366           "load balancing." },
367         { "-gcom",    FALSE, etINT, {&nstglobalcomm},
368           "Global communication frequency" },
369         { "-nb",      FALSE, etENUM, {&nbpu_opt},
370           "Calculate non-bonded interactions on" },
371         { "-nstlist", FALSE, etINT, {&nstlist},
372           "Set nstlist when using a Verlet buffer tolerance (0 is guess)" },
373         { "-tunepme", FALSE, etBOOL, {&bTunePME},
374           "Optimize PME load between PP/PME ranks or GPU/CPU" },
375         { "-v",       FALSE, etBOOL, {&bVerbose},
376           "Be loud and noisy" },
377         { "-compact", FALSE, etBOOL, {&bCompact},
378           "Write a compact log file" },
379         { "-pforce",  FALSE, etREAL, {&pforce},
380           "Print all forces larger than this (kJ/mol nm)" },
381         { "-reprod",  FALSE, etBOOL, {&bReproducible},
382           "Try to avoid optimizations that affect binary reproducibility" },
383         { "-cpt",     FALSE, etREAL, {&cpt_period},
384           "Checkpoint interval (minutes)" },
385         { "-cpnum",   FALSE, etBOOL, {&bKeepAndNumCPT},
386           "Keep and number checkpoint files" },
387         { "-append",  FALSE, etBOOL, {&bTryToAppendFiles},
388           "Append to previous output files when continuing from checkpoint instead of adding the simulation part number to all file names" },
389         { "-nsteps",  FALSE, etINT64, {&nsteps},
390           "Run this number of steps, overrides .mdp file option (-1 means infinite, -2 means use mdp option, smaller is invalid)" },
391         { "-maxh",   FALSE, etREAL, {&max_hours},
392           "Terminate after 0.99 times this time (hours)" },
393         { "-multi",   FALSE, etINT, {&nmultisim},
394           "Do multiple simulations in parallel" },
395         { "-replex",  FALSE, etINT, {&repl_ex_nst},
396           "Attempt replica exchange periodically with this period (steps)" },
397         { "-nex",  FALSE, etINT, {&repl_ex_nex},
398           "Number of random exchanges to carry out each exchange interval (N^3 is one suggestion).  -nex zero or not specified gives neighbor replica exchange." },
399         { "-reseed",  FALSE, etINT, {&repl_ex_seed},
400           "Seed for replica exchange, -1 is generate a seed" },
401         { "-imdport",    FALSE, etINT, {&imdport},
402           "HIDDENIMD listening port" },
403         { "-imdwait",  FALSE, etBOOL, {&bIMDwait},
404           "HIDDENPause the simulation while no IMD client is connected" },
405         { "-imdterm",  FALSE, etBOOL, {&bIMDterm},
406           "HIDDENAllow termination of the simulation from IMD client" },
407         { "-imdpull",  FALSE, etBOOL, {&bIMDpull},
408           "HIDDENAllow pulling in the simulation from IMD client" },
409         { "-rerunvsite", FALSE, etBOOL, {&bRerunVSite},
410           "HIDDENRecalculate virtual site coordinates with [TT]-rerun[tt]" },
411         { "-confout", FALSE, etBOOL, {&bConfout},
412           "HIDDENWrite the last configuration with [TT]-c[tt] and force checkpointing at the last step" },
413         { "-stepout", FALSE, etINT, {&nstepout},
414           "HIDDENFrequency of writing the remaining wall clock time for the run" },
415         { "-resetstep", FALSE, etINT, {&resetstep},
416           "HIDDENReset cycle counters after these many time steps" },
417         { "-resethway", FALSE, etBOOL, {&bResetCountersHalfWay},
418           "HIDDENReset the cycle counters after half the number of steps or halfway [TT]-maxh[tt]" }
419     };
420     unsigned long   Flags;
421     ivec            ddxyz;
422     int             dd_node_order;
423     gmx_bool        bDoAppendFiles, bStartFromCpt;
424     FILE           *fplog;
425     int             rc;
426     char          **multidir = NULL;
427
428     cr = init_commrec();
429
430     unsigned long PCA_Flags = PCA_CAN_SET_DEFFNM;
431     // With -multi or -multidir, the file names are going to get processed
432     // further (or the working directory changed), so we can't check for their
433     // existence during parsing.  It isn't useful to do any completion based on
434     // file system contents, either.
435     if (is_multisim_option_set(argc, argv))
436     {
437         PCA_Flags |= PCA_DISABLE_INPUT_FILE_CHECKING;
438     }
439
440     /* Comment this in to do fexist calls only on master
441      * works not with rerun or tables at the moment
442      * also comment out the version of init_forcerec in md.c
443      * with NULL instead of opt2fn
444      */
445     /*
446        if (!MASTER(cr))
447        {
448        PCA_Flags |= PCA_NOT_READ_NODE;
449        }
450      */
451
452     if (!parse_common_args(&argc, argv, PCA_Flags, NFILE, fnm, asize(pa), pa,
453                            asize(desc), desc, 0, NULL, &oenv))
454     {
455         return 0;
456     }
457
458
459     /* we set these early because they might be used in init_multisystem()
460        Note that there is the potential for npme>nnodes until the number of
461        threads is set later on, if there's thread parallelization. That shouldn't
462        lead to problems. */
463     dd_node_order = nenum(ddno_opt);
464     cr->npmenodes = npme;
465
466     hw_opt.thread_affinity = nenum(thread_aff_opt);
467
468     /* now check the -multi and -multidir option */
469     if (opt2bSet("-multidir", NFILE, fnm))
470     {
471         if (nmultisim > 0)
472         {
473             gmx_fatal(FARGS, "mdrun -multi and -multidir options are mutually exclusive.");
474         }
475         nmultisim = opt2fns(&multidir, "-multidir", NFILE, fnm);
476     }
477
478
479     if (repl_ex_nst != 0 && nmultisim < 2)
480     {
481         gmx_fatal(FARGS, "Need at least two replicas for replica exchange (option -multi)");
482     }
483
484     if (repl_ex_nex < 0)
485     {
486         gmx_fatal(FARGS, "Replica exchange number of exchanges needs to be positive");
487     }
488
489     if (nmultisim > 1)
490     {
491 #ifndef GMX_THREAD_MPI
492         gmx_bool bParFn = (multidir == NULL);
493         init_multisystem(cr, nmultisim, multidir, NFILE, fnm, bParFn);
494 #else
495         gmx_fatal(FARGS, "mdrun -multi is not supported with the thread library. "
496                   "Please compile GROMACS with MPI support");
497 #endif
498     }
499
500     handleRestart(cr, bTryToAppendFiles, NFILE, fnm,
501                   &bDoAppendFiles, &bStartFromCpt);
502
503     Flags = opt2bSet("-rerun", NFILE, fnm) ? MD_RERUN : 0;
504     Flags = Flags | (bDDBondCheck  ? MD_DDBONDCHECK  : 0);
505     Flags = Flags | (bDDBondComm   ? MD_DDBONDCOMM   : 0);
506     Flags = Flags | (bTunePME      ? MD_TUNEPME      : 0);
507     Flags = Flags | (bConfout      ? MD_CONFOUT      : 0);
508     Flags = Flags | (bRerunVSite   ? MD_RERUN_VSITE  : 0);
509     Flags = Flags | (bReproducible ? MD_REPRODUCIBLE : 0);
510     Flags = Flags | (bDoAppendFiles ? MD_APPENDFILES  : 0);
511     Flags = Flags | (opt2parg_bSet("-append", asize(pa), pa) ? MD_APPENDFILESSET : 0);
512     Flags = Flags | (bKeepAndNumCPT ? MD_KEEPANDNUMCPT : 0);
513     Flags = Flags | (bStartFromCpt ? MD_STARTFROMCPT : 0);
514     Flags = Flags | (bResetCountersHalfWay ? MD_RESETCOUNTERSHALFWAY : 0);
515     Flags = Flags | (bIMDwait      ? MD_IMDWAIT      : 0);
516     Flags = Flags | (bIMDterm      ? MD_IMDTERM      : 0);
517     Flags = Flags | (bIMDpull      ? MD_IMDPULL      : 0);
518
519     /* We postpone opening the log file if we are appending, so we can
520        first truncate the old log file and append to the correct position
521        there instead.  */
522     if (MASTER(cr) && !bDoAppendFiles)
523     {
524         gmx_log_open(ftp2fn(efLOG, NFILE, fnm), cr,
525                      Flags & MD_APPENDFILES, &fplog);
526     }
527     else
528     {
529         fplog = NULL;
530     }
531
532     ddxyz[XX] = (int)(realddxyz[XX] + 0.5);
533     ddxyz[YY] = (int)(realddxyz[YY] + 0.5);
534     ddxyz[ZZ] = (int)(realddxyz[ZZ] + 0.5);
535
536     rc = mdrunner(&hw_opt, fplog, cr, NFILE, fnm, oenv, bVerbose, bCompact,
537                   nstglobalcomm, ddxyz, dd_node_order, rdd, rconstr,
538                   dddlb_opt[0], dlb_scale, ddcsx, ddcsy, ddcsz,
539                   nbpu_opt[0], nstlist,
540                   nsteps, nstepout, resetstep,
541                   nmultisim, repl_ex_nst, repl_ex_nex, repl_ex_seed,
542                   pforce, cpt_period, max_hours, imdport, Flags);
543
544     /* Log file has to be closed in mdrunner if we are appending to it
545        (fplog not set here) */
546     if (MASTER(cr) && !bDoAppendFiles)
547     {
548         gmx_log_close(fplog);
549     }
550
551     return rc;
552 }