From: Paul Bauer Date: Thu, 27 Jun 2019 10:17:46 +0000 (+0200) Subject: Use more MDLogger in preprocessing X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=1a3955c65ca38796c1b9138f6318f85bdc26baf8;p=alexxy%2Fgromacs.git Use more MDLogger in preprocessing Refs #2999, #3005 Change-Id: I2ec9f5d9d98d7b1add0cc3e9339e7a93b6e1c9a6 --- diff --git a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp index eb28f8a142..41d53a1d3c 100644 --- a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp +++ b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp @@ -49,9 +49,10 @@ #include "gromacs/topology/mtop_util.h" #include "gromacs/topology/topology.h" #include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/logger.h" #include "gromacs/utility/smalloc.h" -static void low_mspeed(real tempi, gmx_mtop_t* mtop, rvec v[], gmx::ThreeFry2x64<>* rng) +static void low_mspeed(real tempi, gmx_mtop_t* mtop, rvec v[], gmx::ThreeFry2x64<>* rng, const gmx::MDLogger& logger) { int nrdf; real boltz; @@ -90,7 +91,9 @@ static void low_mspeed(real tempi, gmx_mtop_t* mtop, rvec v[], gmx::ThreeFry2x64 } } } - fprintf(stderr, "Velocities were taken from a Maxwell distribution at %g K\n", tempi); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Velocities were taken from a Maxwell distribution at %g K", tempi); if (debug) { fprintf(debug, @@ -100,17 +103,19 @@ static void low_mspeed(real tempi, gmx_mtop_t* mtop, rvec v[], gmx::ThreeFry2x64 } } -void maxwell_speed(real tempi, unsigned int seed, gmx_mtop_t* mtop, rvec v[]) +void maxwell_speed(real tempi, unsigned int seed, gmx_mtop_t* mtop, rvec v[], const gmx::MDLogger& logger) { if (seed == 0) { seed = static_cast(gmx::makeRandomSeed()); - fprintf(stderr, "Using random seed %u for generating velocities\n", seed); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Using random seed %u for generating velocities", seed); } gmx::ThreeFry2x64<> rng(seed, gmx::RandomDomain::MaxwellVelocities); - low_mspeed(tempi, mtop, v, &rng); + low_mspeed(tempi, mtop, v, &rng, logger); } static real calc_cm(int natoms, const real mass[], rvec x[], rvec v[], rvec xcm, rvec vcm, rvec acm, matrix L) @@ -175,14 +180,14 @@ static real calc_cm(int natoms, const real mass[], rvec x[], rvec v[], rvec xcm, return tm; } -void stop_cm(FILE gmx_unused* log, int natoms, real mass[], rvec x[], rvec v[]) +void stop_cm(const gmx::MDLogger gmx_unused& logger, int natoms, real mass[], rvec x[], rvec v[]) { rvec xcm, vcm, acm; tensor L; int i, m; #ifdef DEBUG - fprintf(log, "stopping center of mass motion...\n"); + GMX_LOG(logger.info).asParagraph().appendTextFormatted("stopping center of mass motion..."); #endif (void)calc_cm(natoms, mass, x, v, xcm, vcm, acm, L); @@ -194,8 +199,4 @@ void stop_cm(FILE gmx_unused* log, int natoms, real mass[], rvec x[], rvec v[]) v[i][m] -= vcm[m]; } } - -#ifdef DEBUG - (void)calc_cm(log, natoms, mass, x, v, xcm, vcm, acm, L); -#endif } diff --git a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.h b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.h index e339cd797d..5a31cb4fd4 100644 --- a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.h +++ b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2019, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2019,2020, 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. @@ -45,6 +45,11 @@ struct gmx_mtop_t; +namespace gmx +{ +class MDLogger; +} + /*! \brief * Generate Maxwellian velocities. * @@ -52,18 +57,19 @@ struct gmx_mtop_t; * \param[in] seed Random number generator seed * \param[in] mtop Molecular Topology * \param[out] v Velocities + * \param[in] logger Handle to logging interface. */ -void maxwell_speed(real tempi, unsigned int seed, gmx_mtop_t* mtop, rvec v[]); +void maxwell_speed(real tempi, unsigned int seed, gmx_mtop_t* mtop, rvec v[], const gmx::MDLogger& logger); /*! \brief * Remove the center of mass motion in a set of coordinates. * - * \param[out] log File for printing debug information + * \param[in] logger Handle to logging interface. * \param[in] natoms Number of atoms * \param[in] mass Atomic masses * \param[in] x Coordinates * \param[out] v Velocities */ -void stop_cm(FILE* log, int natoms, real mass[], rvec x[], rvec v[]); +void stop_cm(const gmx::MDLogger& logger, int natoms, real mass[], rvec x[], rvec v[]); #endif diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index a5a830c4d8..eb09d636e8 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -591,7 +591,7 @@ static void new_status(const char* topfile, /* TOPOLOGY processing */ sys->name = do_top(bVerbose, topfile, topppfile, opts, bZero, &(sys->symtab), interactions, comb, reppow, fudgeQQ, atypes, mi, intermolecular_interactions, ir, - &molblock, &ffParametrizedWithHBondConstraints, wi); + &molblock, &ffParametrizedWithHBondConstraints, wi, logger); sys->molblock.clear(); @@ -749,9 +749,9 @@ static void new_status(const char* topfile, GMX_LOG(logger.info).asParagraph().appendTextFormatted("Setting gen_seed to %d", opts->seed); } state->flags |= (1 << estV); - maxwell_speed(opts->tempi, opts->seed, sys, state->v.rvec_array()); + maxwell_speed(opts->tempi, opts->seed, sys, state->v.rvec_array(), logger); - stop_cm(stdout, state->natoms, mass, state->x.rvec_array(), state->v.rvec_array()); + stop_cm(logger, state->natoms, mass, state->x.rvec_array(), state->v.rvec_array()); sfree(mass); } } @@ -1919,7 +1919,7 @@ int gmx_grompp(int argc, char* argv[]) /* set parameters for virtual site construction (not for vsiten) */ for (size_t mt = 0; mt < sys.moltype.size(); mt++) { - nvsite += set_vsites(bVerbose, &sys.moltype[mt].atoms, &atypes, mi[mt].interactions); + nvsite += set_vsites(bVerbose, &sys.moltype[mt].atoms, &atypes, mi[mt].interactions, logger); } /* now throw away all obsolete bonds, angles and dihedrals: */ /* note: constraints are ALWAYS removed */ @@ -1927,7 +1927,7 @@ int gmx_grompp(int argc, char* argv[]) { for (size_t mt = 0; mt < sys.moltype.size(); mt++) { - clean_vsite_bondeds(mi[mt].interactions, sys.moltype[mt].atoms.nr, bRmVSBds); + clean_vsite_bondeds(mi[mt].interactions, sys.moltype[mt].atoms.nr, bRmVSBds, logger); } } @@ -2079,7 +2079,7 @@ int gmx_grompp(int argc, char* argv[]) /* set ptype to VSite for virtual sites */ for (gmx_moltype_t& moltype : sys.moltype) { - set_vsites_ptype(FALSE, &moltype); + set_vsites_ptype(FALSE, &moltype, logger); } if (debug) { @@ -2225,7 +2225,7 @@ int gmx_grompp(int argc, char* argv[]) /* make exclusions between QM atoms and remove charges if needed */ if (ir->bQMMM) { - generate_qmexcl(&sys, ir, wi, GmxQmmmMode::GMX_QMMM_ORIGINAL); + generate_qmexcl(&sys, ir, wi, GmxQmmmMode::GMX_QMMM_ORIGINAL, logger); if (ir->QMMMscheme != eQMMMschemeoniom) { std::vector qmmmAtoms = qmmmAtomIndices(*ir, sys); @@ -2235,7 +2235,7 @@ int gmx_grompp(int argc, char* argv[]) if (ir->eI == eiMimic) { - generate_qmexcl(&sys, ir, wi, GmxQmmmMode::GMX_QMMM_MIMIC); + generate_qmexcl(&sys, ir, wi, GmxQmmmMode::GMX_QMMM_MIMIC, logger); } if (ftp2bSet(efTRN, NFILE, fnm)) diff --git a/src/gromacs/gmxpreprocess/topio.cpp b/src/gromacs/gmxpreprocess/topio.cpp index fae59b91e4..7d33fafda6 100644 --- a/src/gromacs/gmxpreprocess/topio.cpp +++ b/src/gromacs/gmxpreprocess/topio.cpp @@ -80,6 +80,7 @@ #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/futil.h" #include "gromacs/utility/gmxassert.h" +#include "gromacs/utility/logger.h" #include "gromacs/utility/pleasecite.h" #include "gromacs/utility/smalloc.h" @@ -382,7 +383,8 @@ static char** read_topol(const char* infile, bool bFEP, bool bZero, bool usingFullRangeElectrostatics, - warninp* wi) + warninp* wi, + const gmx::MDLogger& logger) { FILE* out; int sl, nb_funct; @@ -694,19 +696,24 @@ static char** read_topol(const char* infile, generate_nbparams(*combination_rule, nb_funct, &(interactions[nb_funct]), atypes, wi); ncopy = copy_nbparams(nbparam, nb_funct, &(interactions[nb_funct]), ntype); - fprintf(stderr, - "Generated %d of the %d non-bonded parameter " - "combinations\n", - ncombs - ncopy, ncombs); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted( + "Generated %d of the %d non-bonded parameter " + "combinations", + ncombs - ncopy, ncombs); free_nbparam(nbparam, ntype); if (bGenPairs) { gen_pairs((interactions[nb_funct]), &(interactions[F_LJ14]), fudgeLJ, *combination_rule); ncopy = copy_nbparams(pair, nb_funct, &(interactions[F_LJ14]), ntype); - fprintf(stderr, - "Generated %d of the %d 1-4 parameter combinations\n", - ncombs - ncopy, ncombs); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted( + "Generated %d of the %d 1-4 parameter " + "combinations", + ncombs - ncopy, ncombs); free_nbparam(pair, ntype); } /* Copy GBSA parameters to atomtype array? */ @@ -819,14 +826,17 @@ static char** read_topol(const char* infile, { gmx_fatal(FARGS, "Molecule type '%s' contains no atoms", *mi0->name); } - fprintf(stderr, "Excluding %d bonded neighbours molecule type '%s'\n", - mi0->nrexcl, *mi0->name); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted( + "Excluding %d bonded neighbours molecule type '%s'", + mi0->nrexcl, *mi0->name); sum_q(&mi0->atoms, nrcopies, &qt, &qBt); if (!mi0->bProcessed) { generate_excl(mi0->nrexcl, mi0->atoms.nr, mi0->interactions, &(mi0->excls)); gmx::mergeExclusions(&(mi0->excls), exclusionBlocks[whichmol]); - make_shake(mi0->interactions, &mi0->atoms, opts->nshake); + make_shake(mi0->interactions, &mi0->atoms, opts->nshake, logger); if (bCouple) { @@ -840,7 +850,9 @@ static char** read_topol(const char* infile, break; } default: - fprintf(stderr, "case: %d\n", static_cast(d)); + GMX_LOG(logger.warning) + .asParagraph() + .appendTextFormatted("case: %d", static_cast(d)); gmx_incons("unknown directive"); } } @@ -905,7 +917,10 @@ static char** read_topol(const char* infile, { gmx_fatal(FARGS, "Did not find any molecules of type '%s' for coupling", opts->couple_moltype); } - fprintf(stderr, "Coupling %d copies of molecule type '%s'\n", nmol_couple, opts->couple_moltype); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Coupling %d copies of molecule type '%s'", nmol_couple, + opts->couple_moltype); } /* this is not very clean, but fixes core dump on empty system name */ @@ -961,7 +976,8 @@ char** do_top(bool bVerbose, const t_inputrec* ir, std::vector* molblock, bool* ffParametrizedWithHBondConstraints, - warninp* wi) + warninp* wi, + const gmx::MDLogger& logger) { /* Tmpfile might contain a long path */ const char* tmpfile; @@ -978,12 +994,12 @@ char** do_top(bool bVerbose, if (bVerbose) { - printf("processing topology...\n"); + GMX_LOG(logger.info).asParagraph().appendTextFormatted("processing topology..."); } title = read_topol(topfile, tmpfile, opts->define, opts->include, symtab, atypes, molinfo, intermolecular_interactions, interactions, combination_rule, repulsion_power, opts, fudgeQQ, molblock, ffParametrizedWithHBondConstraints, - ir->efep != efepNO, bZero, EEL_FULL(ir->coulombtype), wi); + ir->efep != efepNO, bZero, EEL_FULL(ir->coulombtype), wi, logger); if ((*combination_rule != eCOMB_GEOMETRIC) && (ir->vdwtype == evdwUSER)) { @@ -1004,12 +1020,17 @@ char** do_top(bool bVerbose, * CONNBOND and, when MiMiC is not used, removes bonded interactions between QM and link atoms. * Finally, in case if MiMiC QM/MM is used - charges of QM atoms are set to 0 * - * @param molt molecule type with QM atoms - * @param grpnr group informatio - * @param ir input record - * @param qmmmMode QM/MM mode switch: original/MiMiC + * \param[in,out] molt molecule type with QM atoms + * \param[in] grpnr group informatio + * \param[in,out] ir input record + * \param[in,out] qmmmMode QM/MM mode switch: original/MiMiC + * \param[in] logger Handle to logging interface. */ -static void generate_qmexcl_moltype(gmx_moltype_t* molt, const unsigned char* grpnr, t_inputrec* ir, GmxQmmmMode qmmmMode) +static void generate_qmexcl_moltype(gmx_moltype_t* molt, + const unsigned char* grpnr, + t_inputrec* ir, + GmxQmmmMode qmmmMode, + const gmx::MDLogger& logger) { /* This routine expects molt->ilist to be of size F_NRE and ordered. */ @@ -1083,7 +1104,10 @@ static void generate_qmexcl_moltype(gmx_moltype_t* molt, const unsigned char* gr int ind_connbond = 0; if (molt->ilist[F_CONNBONDS].size() != 0) { - fprintf(stderr, "nr. of CONNBONDS present already: %d\n", molt->ilist[F_CONNBONDS].size() / 3); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("nr. of CONNBONDS present already: %d", + molt->ilist[F_CONNBONDS].size() / 3); ftype_connbond = molt->ilist[F_CONNBONDS].iatoms[0]; ind_connbond = molt->ilist[F_CONNBONDS].size(); } @@ -1310,7 +1334,7 @@ static void generate_qmexcl_moltype(gmx_moltype_t* molt, const unsigned char* gr free(blink); } /* generate_qmexcl */ -void generate_qmexcl(gmx_mtop_t* sys, t_inputrec* ir, warninp* wi, GmxQmmmMode qmmmMode) +void generate_qmexcl(gmx_mtop_t* sys, t_inputrec* ir, warninp* wi, GmxQmmmMode qmmmMode, const gmx::MDLogger& logger) { /* This routine expects molt->molt[m].ilist to be of size F_NRE and ordered. */ @@ -1387,7 +1411,7 @@ void generate_qmexcl(gmx_mtop_t* sys, t_inputrec* ir, warninp* wi, GmxQmmmMode q /* Set the molecule type for the QMMM molblock */ molb->type = sys->moltype.size() - 1; } - generate_qmexcl_moltype(&sys->moltype[molb->type], grpnr, ir, qmmmMode); + generate_qmexcl_moltype(&sys->moltype[molb->type], grpnr, ir, qmmmMode, logger); } if (grpnr) { diff --git a/src/gromacs/gmxpreprocess/topio.h b/src/gromacs/gmxpreprocess/topio.h index 050b39aa12..d1177212c5 100644 --- a/src/gromacs/gmxpreprocess/topio.h +++ b/src/gromacs/gmxpreprocess/topio.h @@ -57,6 +57,11 @@ struct warninp; enum struct GmxQmmmMode; typedef warninp* warninp_t; +namespace gmx +{ +class MDLogger; +} + double check_mol(const gmx_mtop_t* mtop, warninp_t wi); /* Check mass and charge */ @@ -76,9 +81,10 @@ char** do_top(bool bVerbose, const t_inputrec* ir, std::vector* molblock, bool* ffParametrizedWithHBondConstraints, - warninp_t wi); + warninp_t wi, + const gmx::MDLogger& logger); /* This routine expects sys->molt[m].ilist to be of size F_NRE and ordered. */ -void generate_qmexcl(gmx_mtop_t* sys, t_inputrec* ir, warninp_t wi, GmxQmmmMode qmmmMode); +void generate_qmexcl(gmx_mtop_t* sys, t_inputrec* ir, warninp_t wi, GmxQmmmMode qmmmMode, const gmx::MDLogger& logger); #endif diff --git a/src/gromacs/gmxpreprocess/topshake.cpp b/src/gromacs/gmxpreprocess/topshake.cpp index 4851e85c2c..d1c8abba67 100644 --- a/src/gromacs/gmxpreprocess/topshake.cpp +++ b/src/gromacs/gmxpreprocess/topshake.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2018,2019, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2018,2019,2020, 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. @@ -51,6 +51,7 @@ #include "gromacs/math/units.h" #include "gromacs/topology/ifunc.h" #include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/logger.h" #include "gromacs/utility/smalloc.h" static int count_hydrogens(char*** atomname, int nra, gmx::ArrayRef a) @@ -74,7 +75,7 @@ static int count_hydrogens(char*** atomname, int nra, gmx::ArrayRef a return nh; } -void make_shake(gmx::ArrayRef plist, t_atoms* atoms, int nshake) +void make_shake(gmx::ArrayRef plist, t_atoms* atoms, int nshake, const gmx::MDLogger& logger) { char*** info = atoms->atomname; real b_ij, b_jk; @@ -82,10 +83,26 @@ void make_shake(gmx::ArrayRef plist, t_atoms* atoms, int nsh { switch (nshake) { - case eshHBONDS: printf("turning H bonds into constraints...\n"); break; - case eshALLBONDS: printf("turning all bonds into constraints...\n"); break; - case eshHANGLES: printf("turning all bonds and H angles into constraints...\n"); break; - case eshALLANGLES: printf("turning all bonds and angles into constraints...\n"); break; + case eshHBONDS: + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("turning H bonds into constraints..."); + break; + case eshALLBONDS: + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("turning all bonds into constraints..."); + break; + case eshHANGLES: + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("turning all bonds and H angles into constraints..."); + break; + case eshALLANGLES: + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("turning all bonds and angles into constraints..."); + break; default: gmx_fatal(FARGS, "Invalid option for make_shake (%d)", nshake); } @@ -111,7 +128,10 @@ void make_shake(gmx::ArrayRef plist, t_atoms* atoms, int nsh { const InteractionOfType* ang = &(*parm); #ifdef DEBUG - printf("Angle: %d-%d-%d\n", ang->ai(), ang->aj(), ang->ak()); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Angle: %d-%d-%d", ang->ai(), + ang->aj(), ang->ak()); #endif int numhydrogens = count_hydrogens(info, 3, ang->atoms()); if ((nshake == eshALLANGLES) || (numhydrogens > 1) @@ -155,8 +175,11 @@ void make_shake(gmx::ArrayRef plist, t_atoms* atoms, int nsh } /* apply law of cosines */ #ifdef DEBUG - printf("p: %d, q: %d, dist: %12.5e\n", atomNumbers[0], - atomNumbers[1], forceParm[0]); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("p: %d, q: %d, dist: %12.5e", + atomNumbers[0], atomNumbers[1], + forceParm[0]); #endif add_param_to_list(&(plist[F_CONSTR]), InteractionOfType(atomNumbers, forceParm)); diff --git a/src/gromacs/gmxpreprocess/topshake.h b/src/gromacs/gmxpreprocess/topshake.h index db9f9b2200..9244f71df8 100644 --- a/src/gromacs/gmxpreprocess/topshake.h +++ b/src/gromacs/gmxpreprocess/topshake.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2019, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2019,2020, 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. @@ -43,6 +43,11 @@ struct t_atoms; struct InteractionsOfType; -void make_shake(gmx::ArrayRef plist, t_atoms* atoms, int nshake); +namespace gmx +{ +class MDLogger; +} + +void make_shake(gmx::ArrayRef plist, t_atoms* atoms, int nshake, const gmx::MDLogger& logger); #endif diff --git a/src/gromacs/gmxpreprocess/vsite_parm.cpp b/src/gromacs/gmxpreprocess/vsite_parm.cpp index f637bcc120..8d4669f734 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.cpp +++ b/src/gromacs/gmxpreprocess/vsite_parm.cpp @@ -60,6 +60,7 @@ #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/gmxassert.h" +#include "gromacs/utility/logger.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/strconvert.h" @@ -639,7 +640,8 @@ static bool calc_vsite3out_param(PreprocessingAtomTypes* aty static bool calc_vsite4fd_param(InteractionOfType* vsite, gmx::ArrayRef bonds, - gmx::ArrayRef angles) + gmx::ArrayRef angles, + const gmx::MDLogger& logger) { /* i = virtual site | ,k * j = 1st bonded heavy atom | i-j-m @@ -671,8 +673,11 @@ static bool calc_vsite4fd_param(InteractionOfType* vsit cosakm = (std::cos(akjm) - std::cos(aijk) * std::cos(aijm)) / (std::sin(aijk) * std::sin(aijm)); if (cosakl < -1 || cosakl > 1 || cosakm < -1 || cosakm > 1) { - fprintf(stderr, "virtual site %d: angle ijk = %f, angle ijl = %f, angle ijm = %f\n", - vsite->ai() + 1, RAD2DEG * aijk, RAD2DEG * aijl, RAD2DEG * aijm); + GMX_LOG(logger.warning) + .asParagraph() + .appendTextFormatted( + "virtual site %d: angle ijk = %f, angle ijl = %f, angle ijm = %f", + vsite->ai() + 1, RAD2DEG * aijk, RAD2DEG * aijl, RAD2DEG * aijm); gmx_fatal(FARGS, "invalid construction in calc_vsite4fd for atom %d: " "cosakl=%f, cosakm=%f\n", @@ -696,7 +701,8 @@ static bool calc_vsite4fd_param(InteractionOfType* vsit static bool calc_vsite4fdn_param(InteractionOfType* vsite, gmx::ArrayRef bonds, - gmx::ArrayRef angles) + gmx::ArrayRef angles, + const gmx::MDLogger& logger) { /* i = virtual site | ,k * j = 1st bonded heavy atom | i-j-m @@ -732,8 +738,11 @@ static bool calc_vsite4fdn_param(InteractionOfType* vsi if (fabs(pl) < 1000 * GMX_REAL_MIN || fabs(pm) < 1000 * GMX_REAL_MIN) { - fprintf(stderr, "virtual site %d: angle ijk = %f, angle ijl = %f, angle ijm = %f\n", - vsite->ai() + 1, RAD2DEG * aijk, RAD2DEG * aijl, RAD2DEG * aijm); + GMX_LOG(logger.warning) + .asParagraph() + .appendTextFormatted( + "virtual site %d: angle ijk = %f, angle ijl = %f, angle ijm = %f", + vsite->ai() + 1, RAD2DEG * aijk, RAD2DEG * aijl, RAD2DEG * aijm); gmx_fatal(FARGS, "invalid construction in calc_vsite4fdn for atom %d: " "pl=%f, pm=%f\n", @@ -752,7 +761,11 @@ static bool calc_vsite4fdn_param(InteractionOfType* vsi } -int set_vsites(bool bVerbose, t_atoms* atoms, PreprocessingAtomTypes* atypes, gmx::ArrayRef plist) +int set_vsites(bool bVerbose, + t_atoms* atoms, + PreprocessingAtomTypes* atypes, + gmx::ArrayRef plist, + const gmx::MDLogger& logger) { int ftype; int nvsite, nrset; @@ -797,7 +810,9 @@ int set_vsites(bool bVerbose, t_atoms* atoms, PreprocessingAtomTypes* atypes, gm { if (bVerbose && bFirst) { - fprintf(stderr, "Calculating parameters for virtual sites\n"); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Calculating parameters for virtual sites"); bFirst = FALSE; } @@ -836,11 +851,11 @@ int set_vsites(bool bVerbose, t_atoms* atoms, PreprocessingAtomTypes* atypes, gm break; case F_VSITE4FD: bERROR = calc_vsite4fd_param(¶m, allVsiteBondeds.bonds, - allVsiteBondeds.angles); + allVsiteBondeds.angles, logger); break; case F_VSITE4FDN: bERROR = calc_vsite4fdn_param(¶m, allVsiteBondeds.bonds, - allVsiteBondeds.angles); + allVsiteBondeds.angles, logger); break; default: gmx_fatal(FARGS, @@ -864,13 +879,15 @@ int set_vsites(bool bVerbose, t_atoms* atoms, PreprocessingAtomTypes* atypes, gm return nvsite; } -void set_vsites_ptype(bool bVerbose, gmx_moltype_t* molt) +void set_vsites_ptype(bool bVerbose, gmx_moltype_t* molt, const gmx::MDLogger& logger) { int ftype, i; if (bVerbose) { - fprintf(stderr, "Setting particle type to V for virtual sites\n"); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Setting particle type to V for virtual sites"); } for (ftype = 0; ftype < F_NRE; ftype++) { @@ -883,8 +900,10 @@ void set_vsites_ptype(bool bVerbose, gmx_moltype_t* molt) if (debug && nrd) { - fprintf(stderr, "doing %d %s virtual sites\n", (nrd / (nra + 1)), - interaction_function[ftype].longname); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("doing %d %s virtual sites", (nrd / (nra + 1)), + interaction_function[ftype].longname); } for (i = 0; (i < nrd);) @@ -928,7 +947,10 @@ private: int interactionIndex_; }; -static void check_vsite_constraints(gmx::ArrayRef plist, int cftype, const int vsite_type[]) +static void check_vsite_constraints(gmx::ArrayRef plist, + int cftype, + const int vsite_type[], + const gmx::MDLogger& logger) { int n = 0; for (const auto& param : plist[cftype].interactionTypes) @@ -939,8 +961,11 @@ static void check_vsite_constraints(gmx::ArrayRef plist, int int atom = atoms[k]; if (vsite_type[atom] != NOTSET) { - fprintf(stderr, "ERROR: Cannot have constraint (%d-%d) with virtual site (%d)\n", - param.ai() + 1, param.aj() + 1, atom + 1); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted( + "ERROR: Cannot have constraint (%d-%d) with virtual site (%d)", + param.ai() + 1, param.aj() + 1, atom + 1); n++; } } @@ -954,7 +979,8 @@ static void check_vsite_constraints(gmx::ArrayRef plist, int static void clean_vsite_bonds(gmx::ArrayRef plist, gmx::ArrayRef pindex, int cftype, - const int vsite_type[]) + const int vsite_type[], + const gmx::MDLogger& logger) { int ftype, nOut; int nconverted, nremoved; @@ -1167,23 +1193,31 @@ static void clean_vsite_bonds(gmx::ArrayRef plist, if (nremoved) { - fprintf(stderr, "Removed %4d %15ss with virtual sites, %zu left\n", nremoved, - interaction_function[cftype].longname, ps->size()); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Removed %4d %15ss with virtual sites, %zu left", nremoved, + interaction_function[cftype].longname, ps->size()); } if (nconverted) { - fprintf(stderr, "Converted %4d %15ss with virtual sites to connections, %zu left\n", - nconverted, interaction_function[cftype].longname, ps->size()); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted( + "Converted %4d %15ss with virtual sites to connections, %zu left", + nconverted, interaction_function[cftype].longname, ps->size()); } if (nOut) { - fprintf(stderr, - "Warning: removed %d %ss with vsite with %s construction\n" - " This vsite construction does not guarantee constant " - "bond-length\n" - " If the constructions were generated by pdb2gmx ignore " - "this warning\n", - nOut, interaction_function[cftype].longname, interaction_function[F_VSITE3OUT].longname); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted( + "Warning: removed %d %ss with vsite with %s construction\n" + " This vsite construction does not guarantee constant " + "bond-length\n" + " If the constructions were generated by pdb2gmx ignore " + "this warning", + nOut, interaction_function[cftype].longname, + interaction_function[F_VSITE3OUT].longname); } } @@ -1191,7 +1225,8 @@ static void clean_vsite_angles(gmx::ArrayRef plist, gmx::ArrayRef pindex, int cftype, const int vsite_type[], - gmx::ArrayRef at2vc) + gmx::ArrayRef at2vc, + const gmx::MDLogger& logger) { int atom, at1, at2; InteractionsOfType* ps; @@ -1333,15 +1368,19 @@ static void clean_vsite_angles(gmx::ArrayRef plist, if (oldSize != gmx::ssize(*ps)) { - fprintf(stderr, "Removed %4zu %15ss with virtual sites, %zu left\n", oldSize - ps->size(), - interaction_function[cftype].longname, ps->size()); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Removed %4zu %15ss with virtual sites, %zu left", + oldSize - ps->size(), interaction_function[cftype].longname, + ps->size()); } } static void clean_vsite_dihs(gmx::ArrayRef plist, gmx::ArrayRef pindex, int cftype, - const int vsite_type[]) + const int vsite_type[], + const gmx::MDLogger& logger) { InteractionsOfType* ps; @@ -1460,13 +1499,19 @@ static void clean_vsite_dihs(gmx::ArrayRef plist, if (oldSize != gmx::ssize(*ps)) { - fprintf(stderr, "Removed %4zu %15ss with virtual sites, %zu left\n", oldSize - ps->size(), - interaction_function[cftype].longname, ps->size()); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Removed %4zu %15ss with virtual sites, %zu left", + oldSize - ps->size(), interaction_function[cftype].longname, + ps->size()); } } // TODO use gmx::compat::optional for pindex. -void clean_vsite_bondeds(gmx::ArrayRef plist, int natoms, bool bRmVSiteBds) +void clean_vsite_bondeds(gmx::ArrayRef plist, + int natoms, + bool bRmVSiteBds, + const gmx::MDLogger& logger) { int nvsite, vsite; int* vsite_type; @@ -1515,8 +1560,10 @@ void clean_vsite_bondeds(gmx::ArrayRef plist, int natoms, bo /* the rest only if we have virtual sites: */ if (nvsite) { - fprintf(stderr, "Cleaning up constraints %swith virtual sites\n", - bRmVSiteBds ? "and constant bonded interactions " : ""); + GMX_LOG(logger.info) + .asParagraph() + .appendTextFormatted("Cleaning up constraints %swith virtual sites", + bRmVSiteBds ? "and constant bonded interactions " : ""); /* Make a reverse list to avoid ninteractions^2 operations */ at2vc = make_at2vsitecon(natoms, plist); @@ -1554,15 +1601,15 @@ void clean_vsite_bondeds(gmx::ArrayRef plist, int natoms, bo { if (interaction_function[ftype].flags & (IF_BTYPE | IF_CONSTRAINT)) { - clean_vsite_bonds(plist, pindex, ftype, vsite_type); + clean_vsite_bonds(plist, pindex, ftype, vsite_type, logger); } else if (interaction_function[ftype].flags & IF_ATYPE) { - clean_vsite_angles(plist, pindex, ftype, vsite_type, at2vc); + clean_vsite_angles(plist, pindex, ftype, vsite_type, at2vc, logger); } else if ((ftype == F_PDIHS) || (ftype == F_IDIHS)) { - clean_vsite_dihs(plist, pindex, ftype, vsite_type); + clean_vsite_dihs(plist, pindex, ftype, vsite_type, logger); } } } @@ -1571,7 +1618,7 @@ void clean_vsite_bondeds(gmx::ArrayRef plist, int natoms, bo { if (interaction_function[ftype].flags & IF_CONSTRAINT) { - check_vsite_constraints(plist, ftype, vsite_type); + check_vsite_constraints(plist, ftype, vsite_type, logger); } } } diff --git a/src/gromacs/gmxpreprocess/vsite_parm.h b/src/gromacs/gmxpreprocess/vsite_parm.h index 8b597f8555..0141efe4de 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.h +++ b/src/gromacs/gmxpreprocess/vsite_parm.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014,2015,2018,2019, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2018,2019,2020, 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. @@ -45,19 +45,28 @@ struct gmx_moltype_t; struct t_atoms; struct InteractionsOfType; +namespace gmx +{ +class MDLogger; +} + int set_vsites(bool bVerbose, t_atoms* atoms, PreprocessingAtomTypes* atype, - gmx::ArrayRef plist); + gmx::ArrayRef plist, + const gmx::MDLogger& logger); /* set parameters for virtual sites, return number of virtual sites */ -void set_vsites_ptype(bool bVerbose, gmx_moltype_t* molt); +void set_vsites_ptype(bool bVerbose, gmx_moltype_t* molt, const gmx::MDLogger& logger); /* set ptype to VSite for virtual sites */ /*! \brief Clean up the bonded interactions * * Throw away all obsolete bonds, angles and dihedrals. * Throw away all constraints. */ -void clean_vsite_bondeds(gmx::ArrayRef ps, int natoms, bool bRmVSiteBds); +void clean_vsite_bondeds(gmx::ArrayRef ps, + int natoms, + bool bRmVSiteBds, + const gmx::MDLogger& logger); #endif