From bc16a24254b7072ddc476a7fa65ead4ffb007a9b Mon Sep 17 00:00:00 2001 From: Berk Hess Date: Fri, 9 Dec 2016 09:40:13 +0100 Subject: [PATCH] Make grompp -r obligatory with posres With position restraints it would often occur that users accidentally used equilibrated coordinates instead of the original coordinates for position restraint coordinates due to grompp -r defaulting to -c. Now -r always need to be supplied with position restraints, but using the same file name as with -c will reproduce the old behavior. Change-Id: Ie4d931897e155114d1162b329c9336627af39a45 --- src/gromacs/gmxpreprocess/grompp.cpp | 52 +++++++++++++++------------------ src/programs/mdrun/tests/moduletest.cpp | 1 + 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index e8724a7482..6c37eb71f1 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -829,7 +829,7 @@ static void cont_status(const char *slog, const char *ener, } static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB, - char *fn, + const char *fn, int rc_scaling, int ePBC, rvec com, warninp_t wi) @@ -1011,7 +1011,7 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB, } static void gen_posres(gmx_mtop_t *mtop, t_molinfo *mi, - char *fnA, char *fnB, + const char *fnA, const char *fnB, int rc_scaling, int ePBC, rvec com, rvec comB, warninp_t wi) @@ -1715,12 +1715,11 @@ int gmx_grompp(int argc, char *argv[]) "Specifying the [TT]-pp[tt] flag will get the pre-processed", "topology file written out so that you can verify its contents.[PAR]", - "When using position restraints a file with restraint coordinates", - "can be supplied with [TT]-r[tt], otherwise restraining will be done", - "with respect to the conformation from the [TT]-c[tt] option.", - "For free energy calculation the the coordinates for the B topology", - "can be supplied with [TT]-rb[tt], otherwise they will be equal to", - "those of the A topology.[PAR]", + "When using position restraints, a file with restraint coordinates", + "must be supplied with [TT]-r[tt] (can be the same file as supplied", + "for [TT]-c[tt]). For free energy calculations, separate reference", + "coordinates for the B topology can be supplied with [TT]-rb[tt],", + "otherwise they will be equal to those of the A topology.[PAR]", "Starting coordinates can be read from trajectory with [TT]-t[tt].", "The last frame with coordinates and velocities will be read,", @@ -1777,7 +1776,6 @@ int gmx_grompp(int argc, char *argv[]) matrix box; real fudgeQQ; double reppow; - char fn[STRLEN], fnB[STRLEN]; const char *mdparin; int ntype; gmx_bool bNeedVel, bGenVel; @@ -1791,8 +1789,8 @@ int gmx_grompp(int argc, char *argv[]) { efMDP, nullptr, nullptr, ffREAD }, { efMDP, "-po", "mdout", ffWRITE }, { efSTX, "-c", nullptr, ffREAD }, - { efSTX, "-r", nullptr, ffOPTRD }, - { efSTX, "-rb", nullptr, ffOPTRD }, + { efSTX, "-r", "restraint", ffOPTRD }, + { efSTX, "-rb", "restraint", ffOPTRD }, { efNDX, nullptr, nullptr, ffOPTRD }, { efTOP, nullptr, nullptr, ffREAD }, { efTOP, "-pp", "processed", ffOPTWR }, @@ -1889,7 +1887,7 @@ int gmx_grompp(int argc, char *argv[]) pr_symtab(debug, 0, "Just opened", &sys->symtab); } - strcpy(fn, ftp2fn(efTOP, NFILE, fnm)); + const char *fn = ftp2fn(efTOP, NFILE, fnm); if (!gmx_fexist(fn)) { gmx_fatal(FARGS, "%s does not exist", fn); @@ -1978,25 +1976,21 @@ int gmx_grompp(int argc, char *argv[]) */ check_warning_error(wi, FARGS); - if (opt2bSet("-r", NFILE, fnm)) + if (nint_ftype(sys, mi, F_POSRES) > 0 || + nint_ftype(sys, mi, F_FBPOSRES) > 0) { - sprintf(fn, "%s", opt2fn("-r", NFILE, fnm)); - } - else - { - sprintf(fn, "%s", opt2fn("-c", NFILE, fnm)); - } - if (opt2bSet("-rb", NFILE, fnm)) - { - sprintf(fnB, "%s", opt2fn("-rb", NFILE, fnm)); - } - else - { - strcpy(fnB, fn); - } + const char *fn = opt2fn("-r", NFILE, fnm); + const char *fnB; + + if (opt2bSet("-rb", NFILE, fnm)) + { + fnB = opt2fn("-rb", NFILE, fnm); + } + else + { + fnB = fn; + } - if (nint_ftype(sys, mi, F_POSRES) > 0 || nint_ftype(sys, mi, F_FBPOSRES) > 0) - { if (bVerbose) { fprintf(stderr, "Reading position restraint coords from %s", fn); diff --git a/src/programs/mdrun/tests/moduletest.cpp b/src/programs/mdrun/tests/moduletest.cpp index b0c9cef4e9..b3e46c1874 100644 --- a/src/programs/mdrun/tests/moduletest.cpp +++ b/src/programs/mdrun/tests/moduletest.cpp @@ -165,6 +165,7 @@ SimulationRunner::callGromppOnThisRank(const CommandLine &callerRef) caller.addOption("-n", ndxFileName_); caller.addOption("-p", topFileName_); caller.addOption("-c", groFileName_); + caller.addOption("-r", groFileName_); caller.addOption("-po", mdpOutputFileName_); caller.addOption("-o", tprFileName_); -- 2.11.4.GIT