From: Mark Abraham Date: Fri, 10 Jul 2015 11:31:10 +0000 (+0200) Subject: Converted gmxpreprocess to compile as C++ X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?p=alexxy%2Fgromacs.git;a=commitdiff_plain;h=af07072599f486eecab10a103964b58dc4d5e260 Converted gmxpreprocess to compile as C++ Used std:: math function and header, eliminated unused code, vars and params, used some size_t variables when handling strings. Added assertions for sqrt operations intended to work on integers that are perfect squares. Converted existing assert calls to GMX_ASSERT Removed include guards from headers Refactored some ter_db code to be clearer about how generic vs specific termini are handled. Made string parameter to _mod into const char *. Noted TODOs for clean up required for pdb2gmx -merge Change-Id: Ibe8b8c4b208a39325e6fe450a41d8521daa5d8f0 --- diff --git a/src/gromacs/gmxpreprocess/CMakeLists.txt b/src/gromacs/gmxpreprocess/CMakeLists.txt index 63a81b53fc..8dd9c8aad8 100644 --- a/src/gromacs/gmxpreprocess/CMakeLists.txt +++ b/src/gromacs/gmxpreprocess/CMakeLists.txt @@ -1,7 +1,7 @@ # # This file is part of the GROMACS molecular simulation package. # -# Copyright (c) 2011,2013,2014, by the GROMACS development team, led by +# Copyright (c) 2011,2013,2014,2015, 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. @@ -32,7 +32,7 @@ # To help us fund GROMACS development, we humbly ask that you cite # the research papers on the package. Check out http://www.gromacs.org. -file(GLOB GMXPREPROCESS_SOURCES *.c *.cpp) +file(GLOB GMXPREPROCESS_SOURCES *.cpp) set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${GMXPREPROCESS_SOURCES} PARENT_SCOPE) diff --git a/src/gromacs/gmxpreprocess/add_par.c b/src/gromacs/gmxpreprocess/add_par.cpp similarity index 96% rename from src/gromacs/gmxpreprocess/add_par.c rename to src/gromacs/gmxpreprocess/add_par.cpp index cf471c4641..9a916d05b8 100644 --- a/src/gromacs/gmxpreprocess/add_par.c +++ b/src/gromacs/gmxpreprocess/add_par.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015, 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. @@ -39,6 +39,8 @@ #include +#include + #include "gromacs/gmxpreprocess/grompp-impl.h" #include "gromacs/gmxpreprocess/hackblock.h" #include "gromacs/gmxpreprocess/toputil.h" @@ -216,8 +218,9 @@ void add_vsite4_atoms(t_params *ps, int ai, int aj, int ak, int al, int am) int search_jtype(t_restp *rtp, char *name, gmx_bool bNterm) { - int niter, iter, j, k, kmax, jmax, minstrlen; - char *rtpname, searchname[12]; + int niter, iter, j, jmax; + size_t k, kmax, minstrlen; + char *rtpname, searchname[12]; strcpy(searchname, name); @@ -253,7 +256,7 @@ int search_jtype(t_restp *rtp, char *name, gmx_bool bNterm) } if (iter == niter - 1) { - minstrlen = min(strlen(searchname), strlen(rtpname)); + minstrlen = std::min(strlen(searchname), strlen(rtpname)); for (k = 0; k < minstrlen; k++) { if (searchname[k] != rtpname[k]) diff --git a/src/gromacs/gmxpreprocess/add_par.h b/src/gromacs/gmxpreprocess/add_par.h index 92a0d8be4d..0ed13041fd 100644 --- a/src/gromacs/gmxpreprocess/add_par.h +++ b/src/gromacs/gmxpreprocess/add_par.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -41,11 +41,6 @@ #include "gromacs/gmxpreprocess/pdb2top.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" -{ -#endif - void add_param(t_params *ps, int ai, int aj, real *c, char *s); void add_imp_param(t_params *ps, int ai, int aj, int ak, int al, @@ -72,8 +67,4 @@ void add_vsite4_atoms(t_params *ps, int ai, int aj, int ak, int al, int search_jtype(t_restp *rp, char *name, gmx_bool bFirstRes); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/calch.c b/src/gromacs/gmxpreprocess/calch.cpp similarity index 96% rename from src/gromacs/gmxpreprocess/calch.c rename to src/gromacs/gmxpreprocess/calch.cpp index d171bbd34b..3011953d87 100644 --- a/src/gromacs/gmxpreprocess/calch.c +++ b/src/gromacs/gmxpreprocess/calch.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2010,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2014,2015, 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. @@ -38,6 +38,8 @@ #include "calch.h" +#include + #include "gromacs/legacyheaders/macros.h" #include "gromacs/math/units.h" #include "gromacs/math/utilities.h" @@ -81,7 +83,6 @@ static void gen_waterhydrogen(int nh, rvec xa[], rvec xh[], int *l) #undef BB #undef CC int m; - rvec kkk; /* This was copied from Gromos */ for (m = 0; (m < DIM); m++) @@ -119,7 +120,7 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l) real s6, rij, ra, rb, xd; int d; - s6 = 0.5*sqrt(3.e0); + s6 = 0.5*std::sqrt(3.e0); /* common work for constructing one, two or three dihedral hydrogens */ switch (nht) @@ -137,7 +138,7 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l) sb[d] = xd-xAK[d]; rij += sqr(sij[d]); } - rij = sqrt(rij); + rij = std::sqrt(rij); sa[XX] = sij[YY]*sb[ZZ]-sij[ZZ]*sb[YY]; sa[YY] = sij[ZZ]*sb[XX]-sij[XX]*sb[ZZ]; sa[ZZ] = sij[XX]*sb[YY]-sij[YY]*sb[XX]; @@ -147,7 +148,7 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l) sij[d] = sij[d]/rij; ra += sqr(sa[d]); } - ra = sqrt(ra); + ra = std::sqrt(ra); for (d = 0; (d < DIM); d++) { sa[d] = sa[d]/ra; @@ -171,15 +172,15 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l) rij += sqr(sij[d]); rb += sqr(sb[d]); } - rij = sqrt(rij); - rb = sqrt(rb); + rij = std::sqrt(rij); + rb = std::sqrt(rb); ra = 0.e0; for (d = 0; (d < DIM); d++) { sa[d] = sij[d]/rij+sb[d]/rb; ra += sqr(sa[d]); } - ra = sqrt(ra); + ra = std::sqrt(ra); for (d = 0; (d < DIM); d++) { xH1[d] = xAI[d]+distH*sa[d]/ra; diff --git a/src/gromacs/gmxpreprocess/calch.h b/src/gromacs/gmxpreprocess/calch.h index ea6211f4dc..31cdeecd6e 100644 --- a/src/gromacs/gmxpreprocess/calch.h +++ b/src/gromacs/gmxpreprocess/calch.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2010,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2014,2015, 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. @@ -39,10 +39,6 @@ #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l); /* * w.f. van gunsteren, groningen, july 1981 @@ -64,8 +60,4 @@ void calc_h_pos(int nht, rvec xa[], rvec xh[], int *l); * l : dynamically changed index */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/convparm.c b/src/gromacs/gmxpreprocess/convparm.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/convparm.c rename to src/gromacs/gmxpreprocess/convparm.cpp index 93f1603c8e..84fda24234 100644 --- a/src/gromacs/gmxpreprocess/convparm.c +++ b/src/gromacs/gmxpreprocess/convparm.cpp @@ -39,9 +39,10 @@ #include "convparm.h" -#include #include +#include + #include "gromacs/gmxpreprocess/gpp_atomtype.h" #include "gromacs/gmxpreprocess/topio.h" #include "gromacs/gmxpreprocess/toputil.h" @@ -81,21 +82,21 @@ static int round_check(real r, int limit, int ftype, const char *name) return i; } -static void set_ljparams(int comb, double reppow, real v, real w, +static void set_ljparams(int comb, double reppow, double v, double w, real *c6, real *c12) { if (comb == eCOMB_ARITHMETIC || comb == eCOMB_GEOM_SIG_EPS) { if (v >= 0) { - *c6 = 4*w*pow(v, 6.0); - *c12 = 4*w*pow(v, reppow); + *c6 = 4*w*std::pow(v, 6.0); + *c12 = 4*w*std::pow(v, reppow); } else { /* Interpret negative sigma as c6=0 and c12 with -sigma */ *c6 = 0; - *c12 = 4*w*pow(-v, reppow); + *c12 = 4*w*std::pow(-v, reppow); } } else @@ -113,7 +114,6 @@ assign_param(t_functype ftype, t_iparams *newparam, real old[MAXFORCEPARAM], int comb, double reppow) { int i, j; - real tmp; gmx_bool all_param_zero = TRUE; /* Set to zero */ @@ -259,7 +259,7 @@ assign_param(t_functype ftype, t_iparams *newparam, newparam->thole.alpha2 = old[2]; if ((old[1] > 0) && (old[2] > 0)) { - newparam->thole.rfac = old[0]*pow(old[1]*old[2], -1.0/6.0); + newparam->thole.rfac = old[0]*std::pow(old[1]*old[2], static_cast(-1.0/6.0)); } else { @@ -436,8 +436,8 @@ assign_param(t_functype ftype, t_iparams *newparam, newparam->vsiten.a = old[1]; break; case F_CMAP: - newparam->cmap.cmapA = old[0]; - newparam->cmap.cmapB = old[1]; + newparam->cmap.cmapA = static_cast(old[0]); + newparam->cmap.cmapB = static_cast(old[1]); break; case F_GB12: case F_GB13: @@ -571,7 +571,7 @@ void convert_params(int atnr, t_params nbtypes[], int comb, double reppow, real fudgeQQ, gmx_mtop_t *mtop) { - int i, j, maxtypes, mt; + int i, maxtypes, mt; unsigned long flags; gmx_ffparams_t *ffp; gmx_moltype_t *molt; diff --git a/src/gromacs/gmxpreprocess/convparm.h b/src/gromacs/gmxpreprocess/convparm.h index 0505967510..23f233cdba 100644 --- a/src/gromacs/gmxpreprocess/convparm.h +++ b/src/gromacs/gmxpreprocess/convparm.h @@ -41,18 +41,10 @@ #include "gromacs/gmxpreprocess/grompp-impl.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - void convert_params(int atnr, t_params nbtypes[], t_molinfo *mi, t_molinfo *intermolecular_interactions, int comb, double reppow, real fudgeQQ, gmx_mtop_t *mtop); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/fflibutil.h b/src/gromacs/gmxpreprocess/fflibutil.h index 572235eee9..1c0d6597c0 100644 --- a/src/gromacs/gmxpreprocess/fflibutil.h +++ b/src/gromacs/gmxpreprocess/fflibutil.h @@ -38,11 +38,9 @@ #include -#include "gromacs/utility/basedefinitions.h" - -#ifdef __cplusplus #include +#include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/datafilefinder.h" /*! \brief @@ -50,9 +48,6 @@ */ std::vector fflib_enumerate_forcefields(); -extern "C" { -#endif - const char *fflib_forcefield_dir_ext(); /* Returns the name of the force field directory extension */ @@ -86,8 +81,4 @@ FILE *fflib_open(const char *file); * either absolute or relative to the current dir. */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/gen_ad.c b/src/gromacs/gmxpreprocess/gen_ad.cpp similarity index 97% rename from src/gromacs/gmxpreprocess/gen_ad.c rename to src/gromacs/gmxpreprocess/gen_ad.cpp index 1b7a0b9c5e..201c17e1b0 100644 --- a/src/gromacs/gmxpreprocess/gen_ad.c +++ b/src/gromacs/gmxpreprocess/gen_ad.cpp @@ -40,10 +40,13 @@ #include "gen_ad.h" #include -#include #include #include +#include + +#include + #include "gromacs/fileio/confio.h" #include "gromacs/gmxpreprocess/gpp_nextnb.h" #include "gromacs/gmxpreprocess/pgutil.h" @@ -510,10 +513,8 @@ static void clean_dih(t_param *dih, int *ndih, t_param improper[], int nimproper static int get_impropers(t_atoms *atoms, t_hackblock hb[], t_param **improper, gmx_bool bAllowMissing) { - char *a0; t_rbondeds *impropers; - t_rbonded *hbimproper; - int nimproper, i, j, k, r, start, ninc, nalloc; + int nimproper, i, j, k, start, ninc, nalloc; atom_id ai[MAXATOMLIST]; gmx_bool bStop; @@ -686,7 +687,7 @@ static void remove_excl(t_excls *excls, int remove) void clean_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]) { - int i, j, j1, k, k1, l, l1, m, n, e; + int i, j, j1, k, k1, l, l1, e; t_excls *excl; if (nrexcl >= 1) @@ -750,10 +751,10 @@ void clean_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]) void generate_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]) { - int i, j, j1, k, k1, l, l1, m, n, e, N; + int i, j, n, N; t_excls *excl; - for (N = 1; (N < min(nrexcl, nnb->nrex)); N++) + for (N = 1; (N < std::min(nrexcl, nnb->nrex)); N++) { /* extract all i-j-k-l neighbours from nnb struct */ for (i = 0; (i < nnb->nr); i++) @@ -861,8 +862,8 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[], maxres = minres; for (m = 1; m < 3; m++) { - minres = min(minres, atoms->atom[ang[nang].a[m]].resind); - maxres = max(maxres, atoms->atom[ang[nang].a[m]].resind); + minres = std::min(minres, atoms->atom[ang[nang].a[m]].resind); + maxres = std::max(maxres, atoms->atom[ang[nang].a[m]].resind); } res = 2*minres-maxres; do @@ -925,8 +926,8 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[], maxres = minres; for (m = 1; m < 4; m++) { - minres = min(minres, atoms->atom[dih[ndih].a[m]].resind); - maxres = max(maxres, atoms->atom[dih[ndih].a[m]].resind); + minres = std::min(minres, atoms->atom[dih[ndih].a[m]].resind); + maxres = std::max(maxres, atoms->atom[dih[ndih].a[m]].resind); } res = 2*minres-maxres; do @@ -1004,8 +1005,8 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[], } if (nbd == 3) { - i1 = min(i, l1); - i2 = max(i, l1); + i1 = std::min(i, l1); + i2 = std::max(i, l1); bExcl = FALSE; for (m = 0; m < excls[i1].nr; m++) { diff --git a/src/gromacs/gmxpreprocess/gen_ad.h b/src/gromacs/gmxpreprocess/gen_ad.h index e8814a5cab..af4c037288 100644 --- a/src/gromacs/gmxpreprocess/gen_ad.h +++ b/src/gromacs/gmxpreprocess/gen_ad.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2012,2014, by the GROMACS development team, led by + * Copyright (c) 2012,2014,2015, 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,10 +43,6 @@ #include "gromacs/gmxpreprocess/toputil.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - void generate_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]); void clean_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]); @@ -54,8 +50,4 @@ void gen_pad(t_nextnb *nnb, t_atoms *atoms, t_restp rtp[], t_params plist[], t_excls excls[], t_hackblock hb[], gmx_bool bAllowMissing); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.c b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp similarity index 96% rename from src/gromacs/gmxpreprocess/gen_maxwell_velocities.c rename to src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp index 02522be85f..3ba751f6b2 100644 --- a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.c +++ b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -38,7 +38,7 @@ #include "gen_maxwell_velocities.h" -#include +#include #include "gromacs/legacyheaders/typedefs.h" #include "gromacs/math/units.h" @@ -65,7 +65,7 @@ static void low_mspeed(real tempi, mass = atom->m; if (mass > 0) { - sd = sqrt(boltz/mass); + sd = std::sqrt(boltz/mass); for (m = 0; (m < DIM); m++) { v[i][m] = sd*gmx_rng_gaussian_real(rng); @@ -77,7 +77,7 @@ static void low_mspeed(real tempi, temp = (2.0*ekin)/(nrdf*BOLTZ); if (temp > 0) { - scal = sqrt(tempi/temp); + scal = std::sqrt(tempi/temp); for (i = 0; (i < mtop->natoms); i++) { for (m = 0; (m < DIM); m++) @@ -99,8 +99,6 @@ static void low_mspeed(real tempi, void maxwell_speed(real tempi, unsigned int seed, gmx_mtop_t *mtop, rvec v[]) { - atom_id *dummy; - int i; gmx_rng_t rng; if (seed == 0) diff --git a/src/gromacs/gmxpreprocess/gen_maxwell_velocities.h b/src/gromacs/gmxpreprocess/gen_maxwell_velocities.h index 2679948ced..b4f65cd3c3 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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -40,10 +40,6 @@ #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - /*! \brief * Generate Maxwellian velocities. * @@ -66,8 +62,4 @@ void maxwell_speed(real tempi, unsigned int seed, */ void stop_cm(FILE *log, int natoms, real mass[], rvec x[], rvec v[]); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/gen_vsite.c b/src/gromacs/gmxpreprocess/gen_vsite.cpp similarity index 97% rename from src/gromacs/gmxpreprocess/gen_vsite.c rename to src/gromacs/gmxpreprocess/gen_vsite.cpp index 4d0e990044..5e21b9032c 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.c +++ b/src/gromacs/gmxpreprocess/gen_vsite.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -38,11 +38,12 @@ #include "gen_vsite.h" -#include #include #include #include +#include + #include "gromacs/gmxpreprocess/add_par.h" #include "gromacs/gmxpreprocess/fflibutil.h" #include "gromacs/gmxpreprocess/gpp_atomtype.h" @@ -158,7 +159,7 @@ static void read_vsite_database(const char *ddbname, FILE *ddb; char dirstr[STRLEN]; char pline[STRLEN]; - int i, j, n, k, nvsite, ntop, curdir, prevdir; + int i, n, k, nvsite, ntop, curdir; t_vsiteconf *vsiteconflist; t_vsitetop *vsitetoplist; char *ch; @@ -582,7 +583,7 @@ static void add_vsites(t_params plist[], int vsite_type[], int Heavy, int nrHatoms, int Hatoms[], int nrheavies, int heavies[]) { - int i, j, ftype, other, moreheavy, bb; + int i, j, ftype, other, moreheavy; gmx_bool bSwapParity; for (i = 0; i < nrHatoms; i++) @@ -697,7 +698,7 @@ static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[], int i, nvsite; real a, b, dCGCE, tmp1, tmp2, mtot, mG, mrest; - real xCG, yCG, xCE1, yCE1, xCE2, yCE2; + real xCG; /* CG, CE1 and CE2 stay and each get a part of the total mass, * so the c-o-m stays the same. */ @@ -711,7 +712,7 @@ static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[], } /* constraints between CG, CE1 and CE2: */ - dCGCE = sqrt( cosrule(bond_cc, bond_cc, ANGLE_6RING) ); + dCGCE = std::sqrt( cosrule(bond_cc, bond_cc, ANGLE_6RING) ); my_add_param(&(plist[F_CONSTRNC]), ats[atCG], ats[atCE1], dCGCE); my_add_param(&(plist[F_CONSTRNC]), ats[atCG], ats[atCE2], dCGCE); my_add_param(&(plist[F_CONSTRNC]), ats[atCE1], ats[atCE2], dCGCE); @@ -734,11 +735,6 @@ static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[], * the CE1-CE2 bond and y=0 at the line from CG to the middle of CE1-CE2 bond. */ xCG = -bond_cc+bond_cc*cos(ANGLE_6RING); - yCG = 0; - xCE1 = 0; - yCE1 = bond_cc*sin(0.5*ANGLE_6RING); - xCE2 = 0; - yCE2 = -bond_cc*sin(0.5*ANGLE_6RING); mG = at->atom[ats[atCG]].m = at->atom[ats[atCG]].mB = xcom*mtot/xCG; mrest = mtot-mG; @@ -792,7 +788,7 @@ static int gen_vsites_phe(t_atoms *at, int *vsite_type[], t_params plist[], atCG, atCD1, atHD1, atCD2, atHD2, atCE1, atHE1, atCE2, atHE2, atCZ, atHZ, atNR }; - real x[atNR], y[atNR]; + real x[atNR]; /* Aromatic rings have 6-fold symmetry, so we only need one bond length. * (angle is always 120 degrees). */ @@ -800,27 +796,16 @@ static int gen_vsites_phe(t_atoms *at, int *vsite_type[], t_params plist[], bond_ch = get_ddb_bond(vsitetop, nvsitetop, "PHE", "CD1", "HD1"); x[atCG] = -bond_cc+bond_cc*cos(ANGLE_6RING); - y[atCG] = 0; x[atCD1] = -bond_cc; - y[atCD1] = bond_cc*sin(0.5*ANGLE_6RING); x[atHD1] = x[atCD1]+bond_ch*cos(ANGLE_6RING); - y[atHD1] = y[atCD1]+bond_ch*sin(ANGLE_6RING); x[atCE1] = 0; - y[atCE1] = y[atCD1]; x[atHE1] = x[atCE1]-bond_ch*cos(ANGLE_6RING); - y[atHE1] = y[atCE1]+bond_ch*sin(ANGLE_6RING); x[atCD2] = x[atCD1]; - y[atCD2] = -y[atCD1]; x[atHD2] = x[atHD1]; - y[atHD2] = -y[atHD1]; x[atCE2] = x[atCE1]; - y[atCE2] = -y[atCE1]; x[atHE2] = x[atHE1]; - y[atHE2] = -y[atHE1]; x[atCZ] = bond_cc*cos(0.5*ANGLE_6RING); - y[atCZ] = 0; x[atHZ] = x[atCZ]+bond_ch; - y[atHZ] = 0; xcom = mtot = 0; for (i = 0; i < atNR; i++) @@ -840,14 +825,11 @@ static void calc_vsite3_param(real xd, real yd, real xi, real yi, real xj, real * virtual site coordinates here. */ real dx_ij, dx_ik, dy_ij, dy_ik; - real b_ij, b_ik; dx_ij = xj-xi; dy_ij = yj-yi; dx_ik = xk-xi; dy_ik = yk-yi; - b_ij = sqrt(dx_ij*dx_ij+dy_ij*dy_ij); - b_ik = sqrt(dx_ik*dx_ik+dy_ik*dy_ik); *a = ( (xd-xi)*dy_ik - dx_ik*(yd-yi) ) / (dx_ij*dy_ik - dx_ik*dy_ij); *b = ( yd - yi - (*a)*dy_ij ) / dy_ik; @@ -877,20 +859,18 @@ static int gen_vsites_trp(gpp_atomtype_t atype, rvec *newx[], }; real xi[atNR], yi[atNR]; - real xcom[NMASS], ycom[NMASS], I, alpha; - real lineA, lineB, dist; + real xcom[NMASS], ycom[NMASS], alpha; real b_CD2_CE2, b_NE1_CE2, b_CG_CD2, b_CH2_HH2, b_CE2_CZ2; real b_NE1_HE1, b_CD2_CE3, b_CE3_CZ3, b_CB_CG; real b_CZ2_CH2, b_CZ2_HZ2, b_CD1_HD1, b_CE3_HE3; real b_CG_CD1, b_CZ3_HZ3; real a_NE1_CE2_CD2, a_CE2_CD2_CG, a_CB_CG_CD2, a_CE2_CD2_CE3; - real a_CB_CG_CD1, a_CD2_CG_CD1, a_CE2_CZ2_HZ2, a_CZ2_CH2_HH2; + real a_CD2_CG_CD1, a_CE2_CZ2_HZ2, a_CZ2_CH2_HH2; real a_CD2_CE2_CZ2, a_CD2_CE3_CZ3, a_CE3_CZ3_HZ3, a_CG_CD1_HD1; real a_CE2_CZ2_CH2, a_HE1_NE1_CE2, a_CD2_CE3_HE3; - real xM[NMASS]; int atM[NMASS], tpM, i, i0, j, nvsite; - real mwtot, mtot, mM[NMASS], dCBM1, dCBM2, dM1M2; - real a, b, c[MAXFORCEPARAM]; + real mM[NMASS], dCBM1, dCBM2, dM1M2; + real a, b; rvec r_ij, r_ik, t1, t2; char name[10]; @@ -920,7 +900,7 @@ static int gen_vsites_trp(gpp_atomtype_t atype, rvec *newx[], a_CE2_CD2_CG = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CE2", "CD2", "CG"); a_CB_CG_CD2 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CB", "CG", "CD2"); a_CD2_CG_CD1 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CD2", "CG", "CD1"); - a_CB_CG_CD1 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CB", "CG", "CD1"); + /*a_CB_CG_CD1 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CB", "CG", "CD1"); unused */ a_CE2_CD2_CE3 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CE2", "CD2", "CE3"); a_CD2_CE2_CZ2 = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TRP", "CD2", "CE2", "CZ2"); @@ -997,10 +977,6 @@ static int gen_vsites_trp(gpp_atomtype_t atype, rvec *newx[], xi[atHH2] = xi[atCH2]+b_CH2_HH2*sin(alpha); yi[atHH2] = yi[atCH2]-b_CH2_HH2*cos(alpha); - /* Determine coeff. for the line CB-CG */ - lineA = (yi[atCB]-yi[atCG])/(xi[atCB]-xi[atCG]); - lineB = yi[atCG]-lineA*xi[atCG]; - /* Calculate masses for each ring and put it on the dummy masses */ for (j = 0; j < NMASS; j++) { @@ -1097,9 +1073,9 @@ static int gen_vsites_trp(gpp_atomtype_t atype, rvec *newx[], /* constraints between CB, M1 and M2 */ /* 'add_shift' says which atoms won't be renumbered afterwards */ - dCBM1 = sqrt( sqr(xcom[0]-xi[atCB]) + sqr(ycom[0]-yi[atCB]) ); - dM1M2 = sqrt( sqr(xcom[0]-xcom[1]) + sqr(ycom[0]-ycom[1]) ); - dCBM2 = sqrt( sqr(xcom[1]-xi[atCB]) + sqr(ycom[1]-yi[atCB]) ); + dCBM1 = std::sqrt( sqr(xcom[0]-xi[atCB]) + sqr(ycom[0]-yi[atCB]) ); + dM1M2 = std::sqrt( sqr(xcom[0]-xcom[1]) + sqr(ycom[0]-ycom[1]) ); + dCBM2 = std::sqrt( sqr(xcom[1]-xi[atCB]) + sqr(ycom[1]-yi[atCB]) ); my_add_param(&(plist[F_CONSTRNC]), ats[atCB], add_shift+atM[0], dCBM1); my_add_param(&(plist[F_CONSTRNC]), ats[atCB], add_shift+atM[1], dCBM2); my_add_param(&(plist[F_CONSTRNC]), add_shift+atM[0], add_shift+atM[1], dM1M2); @@ -1144,7 +1120,7 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[], real dCGCE, dCEOH, dCGM, tmp1, a, b; real bond_cc, bond_ch, bond_co, bond_oh, angle_coh; real xcom, mtot; - real vmass, vdist, mM; + real vdist, mM; rvec r1; char name[10]; @@ -1153,7 +1129,7 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[], atCG, atCD1, atHD1, atCD2, atHD2, atCE1, atHE1, atCE2, atHE2, atCZ, atOH, atHH, atNR }; - real xi[atNR], yi[atNR]; + real xi[atNR]; /* CG, CE1, CE2 (as in general 6-ring) and OH and HH stay, rest gets virtualized. Now we have two linked triangles with one improper keeping them flat */ @@ -1172,27 +1148,16 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[], angle_coh = DEG2RAD*get_ddb_angle(vsitetop, nvsitetop, "TYR", "CZ", "OH", "HH"); xi[atCG] = -bond_cc+bond_cc*cos(ANGLE_6RING); - yi[atCG] = 0; xi[atCD1] = -bond_cc; - yi[atCD1] = bond_cc*sin(0.5*ANGLE_6RING); xi[atHD1] = xi[atCD1]+bond_ch*cos(ANGLE_6RING); - yi[atHD1] = yi[atCD1]+bond_ch*sin(ANGLE_6RING); xi[atCE1] = 0; - yi[atCE1] = yi[atCD1]; xi[atHE1] = xi[atCE1]-bond_ch*cos(ANGLE_6RING); - yi[atHE1] = yi[atCE1]+bond_ch*sin(ANGLE_6RING); xi[atCD2] = xi[atCD1]; - yi[atCD2] = -yi[atCD1]; xi[atHD2] = xi[atHD1]; - yi[atHD2] = -yi[atHD1]; xi[atCE2] = xi[atCE1]; - yi[atCE2] = -yi[atCE1]; xi[atHE2] = xi[atHE1]; - yi[atHE2] = -yi[atHE1]; xi[atCZ] = bond_cc*cos(0.5*ANGLE_6RING); - yi[atCZ] = 0; xi[atOH] = xi[atCZ]+bond_co; - yi[atOH] = 0; xcom = mtot = 0; for (i = 0; i < atOH; i++) @@ -1214,8 +1179,8 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[], at->atom[ats[atCZ]].m = at->atom[ats[atCZ]].mB = 0; /* constraints between CE1, CE2 and OH */ - dCGCE = sqrt( cosrule(bond_cc, bond_cc, ANGLE_6RING) ); - dCEOH = sqrt( cosrule(bond_cc, bond_co, ANGLE_6RING) ); + dCGCE = std::sqrt( cosrule(bond_cc, bond_cc, ANGLE_6RING) ); + dCEOH = std::sqrt( cosrule(bond_cc, bond_co, ANGLE_6RING) ); my_add_param(&(plist[F_CONSTRNC]), ats[atCE1], ats[atOH], dCEOH); my_add_param(&(plist[F_CONSTRNC]), ats[atCE2], ats[atOH], dCEOH); @@ -1282,7 +1247,7 @@ static int gen_vsites_tyr(gpp_atomtype_t atype, rvec *newx[], nvsite++; /* assume we also want the COH angle constrained: */ tmp1 = bond_cc*cos(0.5*ANGLE_6RING) + dCGCE*sin(ANGLE_6RING*0.5) + bond_co; - dCGM = sqrt( cosrule(tmp1, vdist, angle_coh) ); + dCGM = std::sqrt( cosrule(tmp1, vdist, angle_coh) ); my_add_param(&(plist[F_CONSTRNC]), ats[atCG], add_shift+atM, dCGM); my_add_param(&(plist[F_CONSTRNC]), ats[atOH], add_shift+atM, vdist); @@ -1375,8 +1340,8 @@ static int gen_vsites_his(t_atoms *at, int *vsite_type[], t_params plist[], } /* constraints between CG, CE1 and NE1 */ - dCGCE1 = sqrt( cosrule(b_CG_ND1, b_ND1_CE1, a_CG_ND1_CE1) ); - dCGNE2 = sqrt( cosrule(b_CG_CD2, b_CD2_NE2, a_CG_CD2_NE2) ); + dCGCE1 = std::sqrt( cosrule(b_CG_ND1, b_ND1_CE1, a_CG_ND1_CE1) ); + dCGNE2 = std::sqrt( cosrule(b_CG_CD2, b_CD2_NE2, a_CG_CD2_NE2) ); my_add_param(&(plist[F_CONSTRNC]), ats[atCG], ats[atCE1], dCGCE1); my_add_param(&(plist[F_CONSTRNC]), ats[atCG], ats[atNE2], dCGNE2); @@ -1394,7 +1359,7 @@ static int gen_vsites_his(t_atoms *at, int *vsite_type[], t_params plist[], y[atCE1] = cosalpha*dCGCE1; x[atNE2] = 0; y[atNE2] = y[atCE1]-b_CE1_NE2; - sinalpha = sqrt(1-cosalpha*cosalpha); + sinalpha = std::sqrt(1-cosalpha*cosalpha); x[atCG] = -sinalpha*dCGCE1; y[atCG] = 0; x[atHE1] = x[atHE2] = x[atHD1] = x[atHD2] = 0; @@ -1553,7 +1518,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype, int i, j, k, m, i0, ni0, whatres, resind, add_shift, ftype, nvsite, nadd; int ai, aj, ak, al; int nrfound = 0, needed, nrbonds, nrHatoms, Heavy, nrheavies, tpM, tpHeavy; - int Hatoms[4], heavies[4], bb; + int Hatoms[4], heavies[4]; gmx_bool bWARNING, bAddVsiteParam, bFirstWater; matrix tmpmat; gmx_bool *bResProcessed; @@ -1959,7 +1924,7 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype, mHtot *= mHmult; } fact2 = mHtot/mtot; - fact = sqrt(fact2); + fact = std::sqrt(fact2); /* generate vectors parallel and perpendicular to rotational axis: * rpar = Heavy -> Hcom * rperp = Hcom -> H1 */ diff --git a/src/gromacs/gmxpreprocess/gen_vsite.h b/src/gromacs/gmxpreprocess/gen_vsite.h index 6a350ef709..4ece47f91e 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.h +++ b/src/gromacs/gmxpreprocess/gen_vsite.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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,11 +43,6 @@ #include "gromacs/gmxpreprocess/hackblock.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" -{ -#endif - /* stuff for pdb2gmx */ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype, @@ -59,8 +54,4 @@ void do_vsites(int nrtp, t_restp rtp[], gpp_atomtype_t atype, void do_h_mass(t_params *psb, int vsite_type[], t_atoms *at, real mHmult, gmx_bool bDeuterate); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/genconf.c b/src/gromacs/gmxpreprocess/genconf.cpp similarity index 100% rename from src/gromacs/gmxpreprocess/genconf.c rename to src/gromacs/gmxpreprocess/genconf.cpp diff --git a/src/gromacs/gmxpreprocess/genconf.h b/src/gromacs/gmxpreprocess/genconf.h index fa067de2d7..e10b6139a8 100644 --- a/src/gromacs/gmxpreprocess/genconf.h +++ b/src/gromacs/gmxpreprocess/genconf.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014, by the GROMACS development team, led by + * Copyright (c) 2014,2015, 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. @@ -35,14 +35,6 @@ #ifndef GMX_GMXPREPROCESS_GENCONF_H #define GMX_GMXPREPROCESS_GENCONF_H -#ifdef __cplusplus -extern "C" { -#endif - int gmx_genconf(int argc, char *argv[]); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/genhydro.c b/src/gromacs/gmxpreprocess/genhydro.cpp similarity index 99% rename from src/gromacs/gmxpreprocess/genhydro.c rename to src/gromacs/gmxpreprocess/genhydro.cpp index 3a85fa1209..5708d3ec56 100644 --- a/src/gromacs/gmxpreprocess/genhydro.c +++ b/src/gromacs/gmxpreprocess/genhydro.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -177,7 +177,7 @@ static t_hackblock *get_hackblocks(t_atoms *pdba, int nah, t_hackblock ah[], static void expand_hackblocks_one(t_hackblock *hbr, char *atomname, int *nabi, t_hack **abi, gmx_bool bN, gmx_bool bC) { - int j, k, l, d; + int j, k, l; gmx_bool bIgnore; /* we'll recursively add atoms to atoms */ @@ -320,7 +320,7 @@ static void expand_hackblocks(t_atoms *pdba, t_hackblock hb[], static int check_atoms_present(t_atoms *pdba, int nab[], t_hack *ab[]) { - int i, j, k, d, rnr, nadd; + int i, j, k, rnr, nadd; nadd = 0; for (i = 0; i < pdba->nr; i++) @@ -468,7 +468,7 @@ static int add_h_low(t_atoms **pdbaptr, rvec *xptr[], { t_atoms *newpdba = NULL, *pdba = NULL; int nadd; - int i, newi, j, d, natoms, nalreadypresent; + int i, newi, j, natoms, nalreadypresent; int *nab = NULL; t_hack **ab = NULL; t_hackblock *hb; @@ -726,10 +726,6 @@ static int add_h_low(t_atoms **pdbaptr, rvec *xptr[], } *pdbaptr = newpdba; } - else - { - nadd = newi-natoms; - } sfree(*xptr); *xptr = xn; diff --git a/src/gromacs/gmxpreprocess/genhydro.h b/src/gromacs/gmxpreprocess/genhydro.h index 9161a33324..1fd797cff1 100644 --- a/src/gromacs/gmxpreprocess/genhydro.h +++ b/src/gromacs/gmxpreprocess/genhydro.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -41,10 +41,6 @@ #include "gromacs/fileio/pdbio.h" #include "gromacs/gmxpreprocess/hackblock.h" -#ifdef __cplusplus -extern "C" { -#endif - int add_h(t_atoms **pdbaptr, rvec *xptr[], int nah, t_hackblock ah[], int nterpairs, @@ -76,8 +72,4 @@ void deprotonate(t_atoms *atoms, rvec *x); * removed */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/gmxcpp.c b/src/gromacs/gmxpreprocess/gmxcpp.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/gmxcpp.c rename to src/gromacs/gmxpreprocess/gmxcpp.cpp index 90ad4aabcf..f538a72225 100644 --- a/src/gromacs/gmxpreprocess/gmxcpp.c +++ b/src/gromacs/gmxpreprocess/gmxcpp.cpp @@ -41,11 +41,14 @@ #include #include #include -#include #include #include #include +#include + +#include + #include #include "gromacs/legacyheaders/macros.h" @@ -240,10 +243,9 @@ static void done_defines() int cpp_open_file(const char *filenm, gmx_cpp_t *handle, char **cppopts) { gmx_cpp_t cpp; - char *buf, *pdum; + char *buf; char *ptr, *ptr2; int i; - unsigned int i1; /* First process options, they might be necessary for opening files (especially include statements). */ @@ -509,7 +511,6 @@ process_directive(gmx_cpp_t *handlep, const char *dname, const char *dval) /* Make a linked list of open files and move on to the include file */ handle->child->parent = handle; *handlep = handle->child; - handle = *handlep; return eCPP_OK; } @@ -670,7 +671,9 @@ int cpp_read_line(gmx_cpp_t *handlep, int n, char buf[]) } if (nn > 0) { - len = strlen(buf) + nn*max(4, 4+strlen(defs[i].def)-strlen(defs[i].name)); + size_t four = 4; + + len = strlen(buf) + nn*std::max(four, four+strlen(defs[i].def)-strlen(defs[i].name)); snew(name, len); ptr = buf; while ((ptr2 = strstrw(ptr, defs[i].name)) != NULL) @@ -702,7 +705,6 @@ int cpp_cur_linenr(const gmx_cpp_t *handlep) /* Close the file! Return integer status. */ int cpp_close_file(gmx_cpp_t *handlep) { - int i; gmx_cpp_t handle = (gmx_cpp_t)*handlep; if (!handle) diff --git a/src/gromacs/gmxpreprocess/gmxcpp.h b/src/gromacs/gmxpreprocess/gmxcpp.h index 035fdc56e9..d0446f9753 100644 --- a/src/gromacs/gmxpreprocess/gmxcpp.h +++ b/src/gromacs/gmxpreprocess/gmxcpp.h @@ -38,10 +38,6 @@ #ifndef GMX_GMXPREPROCESS_GMXCPP_H #define GMX_GMXPREPROCESS_GMXCPP_H -#ifdef __cplusplus -extern "C" { -#endif - typedef struct gmx_cpp *gmx_cpp_t; /* The possible return codes for these functions */ @@ -99,8 +95,4 @@ void cpp_done(); */ char *cpp_error(gmx_cpp_t *handlep, int status); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.c b/src/gromacs/gmxpreprocess/gpp_atomtype.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/gpp_atomtype.c rename to src/gromacs/gmxpreprocess/gpp_atomtype.cpp index 4a9c932b0f..1387e21914 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.c +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015, 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. @@ -38,9 +38,10 @@ #include "gpp_atomtype.h" -#include #include +#include + #include "gromacs/gmxpreprocess/topdirs.h" #include "gromacs/gmxpreprocess/toputil.h" #include "gromacs/legacyheaders/txtdump.h" @@ -295,7 +296,7 @@ int set_atomtype(int nt, gpp_atomtype_t ga, t_symtab *tab, int add_atomtype(gpp_atomtype_t ga, t_symtab *tab, t_atom *a, const char *name, t_param *nb, int bondatomtype, - real radius, real vol, real surftens, real atomnumber, + real radius, real vol, real surftens, int atomnumber, real gb_radius, real S_hct) { int i; diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.h b/src/gromacs/gmxpreprocess/gpp_atomtype.h index 9dd46548b3..19d345c650 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.h +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015, 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,10 +43,6 @@ #include "gromacs/gmxpreprocess/grompp-impl.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct gpp_atomtype *gpp_atomtype_t; int get_atomtype_type(const char *str, gpp_atomtype_t at); @@ -99,7 +95,7 @@ set_atomtype_gbparam(gpp_atomtype_t at, int i, int add_atomtype(gpp_atomtype_t at, struct t_symtab *tab, t_atom *a, const char *name, t_param *nb, int bondatomtype, - real radius, real vol, real surftens, real atomnumber, + real radius, real vol, real surftens, int atomnumber, real gb_radius, real S_hct); /* Add a complete new atom type to an existing atomtype structure. Returns the number of the atom type. */ @@ -114,8 +110,4 @@ void renum_atype(t_params plist[], gmx_mtop_t *mtop, void copy_atomtype_atomtypes(gpp_atomtype_t atype, t_atomtypes *atypes); /* Copy from one structure to another */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.c b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp similarity index 100% rename from src/gromacs/gmxpreprocess/gpp_bond_atomtype.c rename to src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp diff --git a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.h b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.h index c901d9b1f0..6fc4635bab 100644 --- a/src/gromacs/gmxpreprocess/gpp_bond_atomtype.h +++ b/src/gromacs/gmxpreprocess/gpp_bond_atomtype.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015, 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. @@ -42,10 +42,6 @@ #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct gpp_bondatomtype *t_bond_atomtype; int get_bond_atomtype_type(char *str, t_bond_atomtype at); @@ -65,8 +61,4 @@ void add_bond_atomtype(t_bond_atomtype at, struct t_symtab *tab, char *name); /* Add a complete new atom type to an existing atomtype structure */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/gpp_nextnb.c b/src/gromacs/gmxpreprocess/gpp_nextnb.cpp similarity index 99% rename from src/gromacs/gmxpreprocess/gpp_nextnb.c rename to src/gromacs/gmxpreprocess/gpp_nextnb.cpp index ac779b14bd..a7425263b6 100644 --- a/src/gromacs/gmxpreprocess/gpp_nextnb.c +++ b/src/gromacs/gmxpreprocess/gpp_nextnb.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015, 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. @@ -406,8 +406,6 @@ sort_and_purge_nnb(t_nextnb *nnb) void generate_excl (int nrexcl, int nratoms, t_params plist[], t_nextnb *nnb, t_blocka *excl) { - int i, j, k; - if (nrexcl < 0) { gmx_fatal(FARGS, "Can't have %d exclusions...", nrexcl); diff --git a/src/gromacs/gmxpreprocess/gpp_nextnb.h b/src/gromacs/gmxpreprocess/gpp_nextnb.h index c5dde3865e..93f35d634a 100644 --- a/src/gromacs/gmxpreprocess/gpp_nextnb.h +++ b/src/gromacs/gmxpreprocess/gpp_nextnb.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2010,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2014,2015, 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. @@ -40,10 +40,6 @@ #include "gromacs/gmxpreprocess/grompp-impl.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { int nr; /* nr atoms (0 <= i < nr) (atoms->nr) */ int nrex; /* with nrex lists of neighbours */ @@ -81,8 +77,4 @@ void generate_excl (int nrexcl, int nratoms, * plist. */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/grompp-impl.h b/src/gromacs/gmxpreprocess/grompp-impl.h index 20cafb0cd7..8e268457c7 100644 --- a/src/gromacs/gmxpreprocess/grompp-impl.h +++ b/src/gromacs/gmxpreprocess/grompp-impl.h @@ -40,10 +40,6 @@ #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - #define MAXSLEN 32 typedef struct { @@ -54,7 +50,6 @@ typedef struct { * non-bonded parameter combinations, which will be copied to t_params. */ -#ifndef __cplusplus /* * With the macros below you don't * have to use an index if you don't wan't to. You can eg. use @@ -74,7 +69,6 @@ typedef struct { #define C0 c[0] #define C1 c[1] #define C2 c[2] -#endif typedef struct { atom_id a[MAXATOMLIST]; /* The atom list (eg. bonds: particle */ @@ -171,8 +165,4 @@ typedef enum { d_none } directive; -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/grompp.c b/src/gromacs/gmxpreprocess/grompp.cpp similarity index 97% rename from src/gromacs/gmxpreprocess/grompp.c rename to src/gromacs/gmxpreprocess/grompp.cpp index 6be2102a68..304e68c20b 100644 --- a/src/gromacs/gmxpreprocess/grompp.c +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -38,12 +38,14 @@ #include "grompp.h" -#include #include #include -#include #include +#include + +#include + #include #include "gromacs/commandline/pargs.h" @@ -83,6 +85,7 @@ #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/futil.h" +#include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" #include "gromacs/utility/snprintf.h" @@ -187,7 +190,7 @@ static void check_cg_sizes(const char *topfn, t_block *cgs, warninp_t wi) maxsize = 0; for (cg = 0; cg < cgs->nr; cg++) { - maxsize = max(maxsize, cgs->index[cg+1]-cgs->index[cg]); + maxsize = std::max(maxsize, cgs->index[cg+1]-cgs->index[cg]); } if (maxsize > MAX_CHARGEGROUP_SIZE) @@ -289,7 +292,7 @@ static void check_bonds_timestep(gmx_mtop_t *mtop, double dt, warninp_t wi) if (debug) { fprintf(debug, "fc %g m1 %g m2 %g period %g\n", - fc, m1, m2, sqrt(period2)); + fc, m1, m2, std::sqrt(period2)); } if (period2 < limit2) { @@ -334,7 +337,7 @@ static void check_bonds_timestep(gmx_mtop_t *mtop, double dt, warninp_t wi) *w_moltype->name, w_a1+1, *w_moltype->atoms.atomname[w_a1], w_a2+1, *w_moltype->atoms.atomname[w_a2], - sqrt(w_period2), bWarn ? min_steps_warn : min_steps_note, dt, + std::sqrt(w_period2), bWarn ? min_steps_warn : min_steps_note, dt, bWater ? "Maybe you asked for fexible water." : "Maybe you forgot to change the constraints mdp option."); @@ -810,7 +813,7 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB, rvec com, warninp_t wi) { - gmx_bool bFirst = TRUE, *hadAtom; + gmx_bool *hadAtom; rvec *x, *v, *xp; dvec sum; double totmass; @@ -826,7 +829,7 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB, get_stx_coordnum(fn, &natoms); if (natoms != mtop->natoms) { - sprintf(warn_buf, "The number of atoms in %s (%d) does not match the number of atoms in the topology (%d). Will assume that the first %d atoms in the topology and %s match.", fn, natoms, mtop->natoms, min(mtop->natoms, natoms), fn); + sprintf(warn_buf, "The number of atoms in %s (%d) does not match the number of atoms in the topology (%d). Will assume that the first %d atoms in the topology and %s match.", fn, natoms, mtop->natoms, std::min(mtop->natoms, natoms), fn); warning(wi, warn_buf); } snew(x, natoms); @@ -935,7 +938,7 @@ static void read_posres(gmx_mtop_t *mtop, t_molinfo *molinfo, gmx_bool bTopB, if (rc_scaling != erscNO) { - assert(npbcdim <= DIM); + GMX_ASSERT(npbcdim <= DIM, "Only DIM dimensions can have PBC"); for (mb = 0; mb < mtop->nmolblock; mb++) { @@ -993,8 +996,6 @@ static void gen_posres(gmx_mtop_t *mtop, t_molinfo *mi, rvec com, rvec comB, warninp_t wi) { - int i, j; - read_posres (mtop, mi, FALSE, fnA, rc_scaling, ePBC, com, wi); /* It is safer to simply read the b-state posres rather than trying * to be smart and copy the positions. @@ -1091,7 +1092,7 @@ interpolate1d( double xmin, int ix; double a, b; - ix = (x-xmin)/dx; + ix = static_cast((x-xmin)/dx); a = (xmin+(ix+1)*dx-x)/dx; b = (x-xmin-ix*dx)/dx; @@ -1181,7 +1182,7 @@ setup_cmap (int grid_spacing, void init_cmap_grid(gmx_cmap_t *cmap_grid, int ngrid, int grid_spacing) { - int i, k, nelem; + int i, nelem; cmap_grid->ngrid = ngrid; cmap_grid->grid_spacing = grid_spacing; @@ -1308,22 +1309,19 @@ static real calc_temp(const gmx_mtop_t *mtop, const t_inputrec *ir, rvec *v) { - double sum_mv2; gmx_mtop_atomloop_all_t aloop; t_atom *atom; int a; - int nrdf, g; - - sum_mv2 = 0; + double sum_mv2 = 0; aloop = gmx_mtop_atomloop_all_init(mtop); while (gmx_mtop_atomloop_all_next(aloop, &a, &atom)) { sum_mv2 += atom->m*norm2(v[a]); } - nrdf = 0; - for (g = 0; g < ir->opts.ngtc; g++) + double nrdf = 0; + for (int g = 0; g < ir->opts.ngtc; g++) { nrdf += ir->opts.nrdf[g]; } @@ -1348,7 +1346,7 @@ static real get_max_reference_temp(const t_inputrec *ir, } else { - ref_t = max(ref_t, ir->opts.ref_t[i]); + ref_t = std::max(ref_t, ir->opts.ref_t[i]); } } @@ -1370,7 +1368,6 @@ static void set_verlet_buffer(const gmx_mtop_t *mtop, matrix box, warninp_t wi) { - int i; verletbuf_list_setup_t ls; real rlist_1x1; int n_nonlin_vsite; @@ -1396,18 +1393,18 @@ static void set_verlet_buffer(const gmx_mtop_t *mtop, } printf("Calculated rlist for %dx%d atom pair-list as %.3f nm, buffer size %.3f nm\n", - 1, 1, rlist_1x1, rlist_1x1-max(ir->rvdw, ir->rcoulomb)); + 1, 1, rlist_1x1, rlist_1x1-std::max(ir->rvdw, ir->rcoulomb)); ir->rlistlong = ir->rlist; printf("Set rlist, assuming %dx%d atom pair-list, to %.3f nm, buffer size %.3f nm\n", ls.cluster_size_i, ls.cluster_size_j, - ir->rlist, ir->rlist-max(ir->rvdw, ir->rcoulomb)); + ir->rlist, ir->rlist-std::max(ir->rvdw, ir->rcoulomb)); printf("Note that mdrun will redetermine rlist based on the actual pair-list setup\n"); if (sqr(ir->rlistlong) >= max_cutoff2(ir->ePBC, box)) { - gmx_fatal(FARGS, "The pair-list cut-off (%g nm) is longer than half the shortest box vector or longer than the smallest box diagonal element (%g nm). Increase the box size or decrease nstlist or increase verlet-buffer-tolerance.", ir->rlistlong, sqrt(max_cutoff2(ir->ePBC, box))); + gmx_fatal(FARGS, "The pair-list cut-off (%g nm) is longer than half the shortest box vector or longer than the smallest box diagonal element (%g nm). Increase the box size or decrease nstlist or increase verlet-buffer-tolerance.", ir->rlistlong, std::sqrt(max_cutoff2(ir->ePBC, box))); } } @@ -1516,26 +1513,21 @@ int gmx_grompp(int argc, char *argv[]) t_molinfo *mi, *intermolecular_interactions; gpp_atomtype_t atype; t_inputrec *ir; - int natoms, nvsite, comb, mt; + int nvsite, comb, mt; t_params *plist; t_state *state; matrix box; - real max_spacing, fudgeQQ; + real fudgeQQ; double reppow; char fn[STRLEN], fnB[STRLEN]; const char *mdparin; int ntype; gmx_bool bNeedVel, bGenVel; gmx_bool have_atomnumber; - int n12, n13, n14; - t_params *gb_plist = NULL; - gmx_genborn_t *born = NULL; output_env_t oenv; gmx_bool bVerbose = FALSE; warninp_t wi; char warn_buf[STRLEN]; - unsigned int useed; - t_atoms IMDatoms; /* Atoms to be operated on interactively (IMD) */ t_filenm fnm[] = { { efMDP, NULL, NULL, ffREAD }, @@ -1603,7 +1595,7 @@ int gmx_grompp(int argc, char *argv[]) if (ir->ld_seed == -1) { ir->ld_seed = (gmx_int64_t)gmx_rng_make_seed(); - fprintf(stderr, "Setting the LD random seed to %"GMX_PRId64 "\n", ir->ld_seed); + fprintf(stderr, "Setting the LD random seed to %" GMX_PRId64 "\n", ir->ld_seed); } if (ir->expandedvals->lmc_seed == -1) @@ -1782,7 +1774,7 @@ int gmx_grompp(int argc, char *argv[]) if (bRenum) { renum_atype(plist, sys, ir->wall_atomtype, atype, bVerbose); - ntype = get_atomtype_ntypes(atype); + get_atomtype_ntypes(atype); } if (ir->implicit_solvent != eisNO) @@ -1862,7 +1854,6 @@ int gmx_grompp(int argc, char *argv[]) } do_index(mdparin, ftp2fn_null(efNDX, NFILE, fnm), sys, bVerbose, ir, - bGenVel ? state->v : NULL, wi); if (ir->cutoff_scheme == ecutsVERLET && ir->verletbuf_tol > 0 && @@ -2009,8 +2000,8 @@ int gmx_grompp(int argc, char *argv[]) set_warning_line(wi, mdparin, -1); warning_error(wi, "Some of the Fourier grid sizes are set, but all of them need to be set."); } - max_spacing = calc_grid(stdout, box, ir->fourier_spacing, - &(ir->nkx), &(ir->nky), &(ir->nkz)); + calc_grid(stdout, box, ir->fourier_spacing, + &(ir->nkx), &(ir->nky), &(ir->nkz)); } /* MRS: eventually figure out better logic for initializing the fep diff --git a/src/gromacs/gmxpreprocess/grompp.h b/src/gromacs/gmxpreprocess/grompp.h index 9dc5254a80..9e6bcba686 100644 --- a/src/gromacs/gmxpreprocess/grompp.h +++ b/src/gromacs/gmxpreprocess/grompp.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014, by the GROMACS development team, led by + * Copyright (c) 2014,2015, 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. @@ -35,17 +35,6 @@ #ifndef GMX_GMXPREPROCESS_GROMPP_H #define GMX_GMXPREPROCESS_GROMPP_H -#ifdef __cplusplus -extern "C" { -#endif -#if 0 -} -#endif - int gmx_grompp(int argc, char *argv[]); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/h_db.c b/src/gromacs/gmxpreprocess/h_db.cpp similarity index 97% rename from src/gromacs/gmxpreprocess/h_db.c rename to src/gromacs/gmxpreprocess/h_db.cpp index b63fdde27a..7504972d5d 100644 --- a/src/gromacs/gmxpreprocess/h_db.c +++ b/src/gromacs/gmxpreprocess/h_db.cpp @@ -191,8 +191,11 @@ static void read_h_db_file(const char *hfn, int *nahptr, t_hackblock **ah) } gmx_ffclose(in); - /* Sort the list (necessary to be able to use bsearch */ - qsort(aah, nah, (size_t)sizeof(**ah), compaddh); + if (nah > 0) + { + /* Sort the list (necessary to be able to use bsearch */ + qsort(aah, nah, (size_t)sizeof(**ah), compaddh); + } /* if (debug) @@ -208,7 +211,6 @@ int read_h_db(const char *ffdir, t_hackblock **ah) int nhdbf, f; char **hdbf; int nah; - FILE *fp; /* Read the hydrogen database file(s). * Do not generate an error when no files are found. diff --git a/src/gromacs/gmxpreprocess/h_db.h b/src/gromacs/gmxpreprocess/h_db.h index 24f873b6c2..c8e2df6f04 100644 --- a/src/gromacs/gmxpreprocess/h_db.h +++ b/src/gromacs/gmxpreprocess/h_db.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015, 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. @@ -42,10 +42,6 @@ #include "gromacs/gmxpreprocess/hackblock.h" -#ifdef __cplusplus -extern "C" { -#endif - /* functions for the h-database */ void read_ab(char *line, const char *fn, t_hack *ab); @@ -65,8 +61,4 @@ int compaddh(const void *a, const void *b); t_hackblock *search_h_db(int nh, t_hackblock ah[], char *key); /* Search for an entry in the database */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/hackblock.c b/src/gromacs/gmxpreprocess/hackblock.cpp similarity index 100% rename from src/gromacs/gmxpreprocess/hackblock.c rename to src/gromacs/gmxpreprocess/hackblock.cpp diff --git a/src/gromacs/gmxpreprocess/hackblock.h b/src/gromacs/gmxpreprocess/hackblock.h index 294dcec86c..bdeff0af49 100644 --- a/src/gromacs/gmxpreprocess/hackblock.h +++ b/src/gromacs/gmxpreprocess/hackblock.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -44,10 +44,6 @@ #include "gromacs/legacyheaders/typedefs.h" #include "gromacs/topology/symtab.h" -#ifdef __cplusplus -extern "C" { -#endif - /* Used for reading .rtp/.tdb */ /* ebtsBONDS must be the first, new types can be added to the end */ /* these *MUST* correspond to the arrays in hackblock.c */ @@ -195,8 +191,4 @@ void dump_hb(FILE *out, int nres, t_hackblock hb[]); void init_t_protonate(t_protonate *protonate); /* initialize t_protein struct */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/hizzie.c b/src/gromacs/gmxpreprocess/hizzie.cpp similarity index 97% rename from src/gromacs/gmxpreprocess/hizzie.c rename to src/gromacs/gmxpreprocess/hizzie.cpp index 0aff84f7a4..b2575850b3 100644 --- a/src/gromacs/gmxpreprocess/hizzie.c +++ b/src/gromacs/gmxpreprocess/hizzie.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -40,6 +40,8 @@ #include #include +#include + #include "gromacs/fileio/pdbio.h" #include "gromacs/gmxpreprocess/pdb2top.h" #include "gromacs/gmxpreprocess/toputil.h" @@ -176,7 +178,7 @@ static gmx_bool chk_hbonds(int i, t_atoms *pdba, rvec x[], pdba->resinfo[pdba->atom[i].resind].nr, *pdba->atomname[i], *pdba->resinfo[pdba->atom[aj].resind].name, pdba->resinfo[pdba->atom[aj].resind].nr, *pdba->atomname[aj], - sqrt(d2), a); + std::sqrt(d2), a); } hbond[i] = TRUE; bHB = TRUE; @@ -213,14 +215,13 @@ void set_histp(t_atoms *pdba, rvec *x, real angle, real dist) #define NPD asize(prot_don) gmx_bool *donor, *acceptor; - gmx_bool *hbond, bHaveH = FALSE; + gmx_bool *hbond; gmx_bool bHDd, bHEd; rvec xh1, xh2; int natom; - int i, j, nd, na, aj, hisind, his0, type = -1; + int i, j, nd, na, hisind, type = -1; int nd1, ne2, cg, cd2, ce1; t_blocka *hb; - real d; char *atomnm; natom = pdba->nr; diff --git a/src/gromacs/gmxpreprocess/hizzie.h b/src/gromacs/gmxpreprocess/hizzie.h index 92c44f43b5..5bdcb8801c 100644 --- a/src/gromacs/gmxpreprocess/hizzie.h +++ b/src/gromacs/gmxpreprocess/hizzie.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -38,15 +38,7 @@ #ifndef GMX_GMXPREPROCESS_HIZZIE_H #define GMX_GMXPREPROCESS_HIZZIE_H -#ifdef __cplusplus -extern "C" { -#endif - void set_histp(t_atoms *pdba, rvec *x, real angle, real distance); /* calculate HIStidine protonation state */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/nm2type.c b/src/gromacs/gmxpreprocess/nm2type.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/nm2type.c rename to src/gromacs/gmxpreprocess/nm2type.cpp index 9f02a585bd..dba4da9f9c 100644 --- a/src/gromacs/gmxpreprocess/nm2type.c +++ b/src/gromacs/gmxpreprocess/nm2type.cpp @@ -41,6 +41,8 @@ #include +#include + #include "gromacs/fileio/confio.h" #include "gromacs/gmxpreprocess/fflibutil.h" #include "gromacs/gmxpreprocess/gpp_atomtype.h" @@ -66,7 +68,7 @@ static void rd_nm2type_file(const char *fn, int *nnm, t_nm2type **nmp) char format[128], f1[128]; char buf[1024], elem[16], type[16], nbbuf[16], **newbuf; int i, nb, nnnm, line = 1; - double qq, mm, *blen; + double qq, mm; t_nm2type *nm2t = NULL; fp = fflib_open(fn); @@ -201,7 +203,7 @@ int nm2type(int nnm, t_nm2type nm2t[], struct t_symtab *tab, t_atoms *atoms, int cur = 0; #define prev (1-cur) int i, j, k, m, n, nresolved, nb, maxbond, ai, aj, best, im, nqual[2][ematchNR]; - int *bbb, *n_mask, *m_mask, **match, **quality; + int *bbb, *n_mask, *m_mask, **match; char *aname_i, *aname_m, *aname_n, *type; double qq, mm; t_param *param; @@ -210,7 +212,7 @@ int nm2type(int nnm, t_nm2type nm2t[], struct t_symtab *tab, t_atoms *atoms, maxbond = 0; for (i = 0; (i < atoms->nr); i++) { - maxbond = max(maxbond, nbonds[i]); + maxbond = std::max(maxbond, nbonds[i]); } if (debug) { diff --git a/src/gromacs/gmxpreprocess/nm2type.h b/src/gromacs/gmxpreprocess/nm2type.h index 4f8505ed04..e86af8228d 100644 --- a/src/gromacs/gmxpreprocess/nm2type.h +++ b/src/gromacs/gmxpreprocess/nm2type.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2008, The GROMACS development team. - * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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,10 +43,6 @@ #include "gromacs/gmxpreprocess/grompp-impl.h" #include "gromacs/topology/atoms.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { char *elem, *type; double q, m; @@ -69,8 +65,4 @@ int nm2type(int nnm, t_nm2type nm2t[], struct t_symtab *tab, t_atoms *atoms, * with help of the bond list */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/pdb2gmx.c b/src/gromacs/gmxpreprocess/pdb2gmx.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/pdb2gmx.c rename to src/gromacs/gmxpreprocess/pdb2gmx.cpp index 242aaf65e0..f025990f80 100644 --- a/src/gromacs/gmxpreprocess/pdb2gmx.c +++ b/src/gromacs/gmxpreprocess/pdb2gmx.cpp @@ -73,6 +73,7 @@ #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/dir_separator.h" #include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" #define RTP_MAXCHAR 5 @@ -322,7 +323,7 @@ static void rename_resrtp(t_atoms *pdba, int nterpairs, int *r_start, int *r_end int nrr, rtprename_t *rr, t_symtab *symtab, gmx_bool bVerbose) { - int r, i, j; + int r, j; gmx_bool bStart, bEnd; char *nn; gmx_bool bFFRTPTERRNM; @@ -703,7 +704,6 @@ static void sort_pdbatoms(t_restp restp[], rvec **xnew; int i, j; t_restp *rptr; - t_hackblock *hbr; t_pdbindex *pdbi; atom_id *a; char *atomnm; @@ -834,7 +834,10 @@ static int remove_duplicate_atoms(t_atoms *pdba, rvec x[], gmx_bool bVerbose) { pdba->atom[j] = pdba->atom[j+1]; pdba->atomname[j] = pdba->atomname[j+1]; - pdba->pdbinfo[j] = pdba->pdbinfo[j+1]; + if (pdba->pdbinfo) + { + pdba->pdbinfo[j] = pdba->pdbinfo[j+1]; + } copy_rvec(x[j+1], x[j]); } srenew(pdba->atom, pdba->nr); @@ -921,42 +924,18 @@ void find_nc_ter(t_atoms *pdba, int r0, int r1, int *r_start, int *r_end, } -static void -modify_chain_numbers(t_atoms * pdba, - const char * chainsep) +enum SplittingType { - int i; - char old_prev_chainid; - char old_this_chainid; - int old_prev_chainnum; - int old_this_chainnum; - t_resinfo *ri; - char select[STRLEN]; - int new_chainnum; - int this_atomnum; - int prev_atomnum; - const char * prev_atomname; - const char * this_atomname; - const char * prev_resname; - const char * this_resname; - int prev_resnum; - int this_resnum; - char prev_chainid; - char this_chainid; - int prev_chainnumber; - int this_chainnumber; - - enum - { - SPLIT_ID_OR_TER, - SPLIT_ID_AND_TER, - SPLIT_ID_ONLY, - SPLIT_TER_ONLY, - SPLIT_INTERACTIVE - } - splitting; - - splitting = SPLIT_TER_ONLY; /* keep compiler happy */ + SPLIT_ID_OR_TER, + SPLIT_ID_AND_TER, + SPLIT_ID_ONLY, + SPLIT_TER_ONLY, + SPLIT_INTERACTIVE +}; + +static SplittingType getSplittingType(const char *chainsep) +{ + SplittingType splitting = SPLIT_TER_ONLY; /* keep compiler happy */ /* Be a bit flexible to catch typos */ if (!strncmp(chainsep, "id_o", 4)) @@ -990,6 +969,33 @@ modify_chain_numbers(t_atoms * pdba, { gmx_fatal(FARGS, "Unidentified setting for chain separation: %s\n", chainsep); } + return splitting; +} + +static void +modify_chain_numbers(t_atoms * pdba, + const char * chainsep) +{ + int i; + char old_prev_chainid; + char old_this_chainid; + int old_prev_chainnum; + int old_this_chainnum; + t_resinfo *ri; + char select[STRLEN]; + int new_chainnum; + int this_atomnum; + int prev_atomnum; + const char * prev_atomname; + const char * this_atomname; + const char * prev_resname; + const char * this_resname; + int prev_resnum; + int this_resnum; + char prev_chainid; + char this_chainid; + + SplittingType splitting = getSplittingType(chainsep); /* The default chain enumeration is based on TER records only, which is reflected in chainnum below */ @@ -1002,7 +1008,6 @@ modify_chain_numbers(t_atoms * pdba, this_resname = NULL; this_resnum = -1; this_chainid = '?'; - this_chainnumber = -1; for (i = 0; i < pdba->nres; i++) { @@ -1015,14 +1020,12 @@ modify_chain_numbers(t_atoms * pdba, prev_resname = this_resname; prev_resnum = this_resnum; prev_chainid = this_chainid; - prev_chainnumber = this_chainnumber; this_atomname = *(pdba->atomname[i]); this_atomnum = (pdba->pdbinfo != NULL) ? pdba->pdbinfo[i].atomnr : i+1; this_resname = *ri->name; this_resnum = ri->nr; this_chainid = ri->chainid; - this_chainnumber = ri->chainnum; switch (splitting) { @@ -1257,17 +1260,16 @@ int gmx_pdb2gmx(int argc, char *argv[]) const char *watres; int nrtpf; char **rtpf; - char rtp[STRLEN]; int nrrn; char **rrn; - int nrtprename, naa; + int nrtprename; rtprename_t *rtprename = NULL; int nah, nNtdb, nCtdb, ntdblist; t_hackblock *ntdb, *ctdb, **tdblist; int nssbonds; t_ssbond *ssbonds; rvec *pdbx, *x; - gmx_bool bVsites = FALSE, bWat, bPrevWat = FALSE, bITP, bVsiteAromatics = FALSE, bCheckMerge; + gmx_bool bVsites = FALSE, bWat, bPrevWat = FALSE, bITP, bVsiteAromatics = FALSE; real mHmult = 0; t_hackblock *hb_chain; t_restp *restp_chain; @@ -1441,6 +1443,9 @@ int gmx_pdb2gmx(int argc, char *argv[]) mHmult = 1.0; } + /* parse_common_args ensures vsitestr has been selected, but + clang-static-analyzer needs clues to know that */ + GMX_ASSERT(vsitestr[0], "-vsite default wasn't processed correctly"); switch (vsitestr[0][0]) { case 'n': /* none */ @@ -1481,7 +1486,6 @@ int gmx_pdb2gmx(int argc, char *argv[]) sfree(rrn); /* Add all alternative names from the residue renaming database to the list of recognized amino/nucleic acids. */ - naa = 0; for (i = 0; i < nrtprename; i++) { rc = gmx_residuetype_get_type(rt, rtprename[i].gmx, &p_restype); @@ -1523,8 +1527,6 @@ int gmx_pdb2gmx(int argc, char *argv[]) } printf("Analyzing pdb file\n"); - nch = 0; - maxch = 0; nwaterchain = 0; modify_chain_numbers(&pdba_all, chainsep[0]); @@ -1541,13 +1543,17 @@ int gmx_pdb2gmx(int argc, char *argv[]) /* Keep the compiler happy */ prev_chainstart = 0; - pdb_ch = NULL; + nch = 0; + maxch = 16; + snew(pdb_ch, maxch); bMerged = FALSE; for (i = 0; (i < natom); i++) { ri = &pdba_all.resinfo[pdba_all.atom[i].resind]; + /* TODO this should live in a helper object, and consolidate + that with code in modify_chain_numbers */ prev_atomname = this_atomname; prev_atomnum = this_atomnum; prev_resname = this_resname; @@ -1623,6 +1629,7 @@ int gmx_pdb2gmx(int argc, char *argv[]) ri->chainid); } } + // TODO This is too convoluted. Use a std::vector if (nch == maxch) { maxch += 16; @@ -1781,7 +1788,6 @@ int gmx_pdb2gmx(int argc, char *argv[]) nmol = 0; incls = NULL; mols = NULL; - nres = 0; for (chain = 0; (chain < nch); chain++) { cc = &(chains[chain]); @@ -1954,7 +1960,7 @@ int gmx_pdb2gmx(int argc, char *argv[]) block = new_blocka(); snew(gnames, 1); sort_pdbatoms(restp_chain, natom, &pdba, &x, block, &gnames); - natom = remove_duplicate_atoms(pdba, x, bVerbose); + remove_duplicate_atoms(pdba, x, bVerbose); if (ftp2bSet(efNDX, NFILE, fnm)) { if (bRemoveH) diff --git a/src/gromacs/gmxpreprocess/pdb2gmx.h b/src/gromacs/gmxpreprocess/pdb2gmx.h index d85c5bbae8..b8da74c90b 100644 --- a/src/gromacs/gmxpreprocess/pdb2gmx.h +++ b/src/gromacs/gmxpreprocess/pdb2gmx.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014, by the GROMACS development team, led by + * Copyright (c) 2014,2015, 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. @@ -35,17 +35,6 @@ #ifndef GMX_GMXPREPROCESS_PDB2GMX_H #define GMX_GMXPREPROCESS_PDB2GMX_H -#ifdef __cplusplus -extern "C" { -#endif -#if 0 -} -#endif - int gmx_pdb2gmx(int argc, char *argv[]); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/pdb2top.cpp b/src/gromacs/gmxpreprocess/pdb2top.cpp index 49b7316358..00529571be 100644 --- a/src/gromacs/gmxpreprocess/pdb2top.cpp +++ b/src/gromacs/gmxpreprocess/pdb2top.cpp @@ -39,10 +39,11 @@ #include "pdb2top.h" #include -#include #include #include +#include + #include #include #include @@ -800,12 +801,12 @@ static void at2bonds(t_params *psb, t_hackblock *hb, { fprintf(stderr, "Warning: Long Bond (%d-%d = %g nm)\n", - ai+1, aj+1, sqrt(dist2)); + ai+1, aj+1, std::sqrt(dist2)); } else if (dist2 < short_bond_dist2) { fprintf(stderr, "Warning: Short Bond (%d-%d = %g nm)\n", - ai+1, aj+1, sqrt(dist2)); + ai+1, aj+1, std::sqrt(dist2)); } add_param(psb, ai, aj, NULL, hb[resind].rb[ebtsBONDS].b[j].s); } diff --git a/src/gromacs/gmxpreprocess/pdb2top.h b/src/gromacs/gmxpreprocess/pdb2top.h index cfbc800c87..a5e468106c 100644 --- a/src/gromacs/gmxpreprocess/pdb2top.h +++ b/src/gromacs/gmxpreprocess/pdb2top.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -44,11 +44,6 @@ #include "gromacs/gmxpreprocess/toputil.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" -{ -#endif - /* this *MUST* correspond to array in pdb2top.c */ enum { ehisA, ehisB, ehisH, ehis1, ehisNR @@ -127,8 +122,4 @@ void pdb2top(FILE *top_file, char *posre_fn, char *molname, void print_sums(t_atoms *atoms, gmx_bool bSystem); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/pgutil.c b/src/gromacs/gmxpreprocess/pgutil.cpp similarity index 100% rename from src/gromacs/gmxpreprocess/pgutil.c rename to src/gromacs/gmxpreprocess/pgutil.cpp diff --git a/src/gromacs/gmxpreprocess/pgutil.h b/src/gromacs/gmxpreprocess/pgutil.h index b9ebce727a..1c5b46d2ca 100644 --- a/src/gromacs/gmxpreprocess/pgutil.h +++ b/src/gromacs/gmxpreprocess/pgutil.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -40,11 +40,6 @@ #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" -{ -#endif - /* Search an atom in array of pointers to strings, starting from start * if type starts with '-' then searches backwards from start. * bondtype is only used for printing the error/warning string, @@ -67,8 +62,4 @@ search_res_atom(const char *type, int resind, void set_at(t_atom *at, real m, real q, int type, int resind); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/read-conformation.h b/src/gromacs/gmxpreprocess/read-conformation.h index 5ced52b98b..7c9f6a27fd 100644 --- a/src/gromacs/gmxpreprocess/read-conformation.h +++ b/src/gromacs/gmxpreprocess/read-conformation.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014, by the GROMACS development team, led by + * Copyright (c) 2014,2015, 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. @@ -37,10 +37,6 @@ #include "gromacs/legacyheaders/types/simple.h" -#ifdef __cplusplus -extern "C" { -#endif - struct gmx_atomprop; struct t_atoms; @@ -61,8 +57,4 @@ real *makeExclusionDistances(const struct t_atoms *a, struct gmx_atomprop *aps, char *readConformation(const char *confin, struct t_atoms *atoms, rvec **x, rvec **v, int *ePBC, matrix box, const char *statusTitle); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/readadress.c b/src/gromacs/gmxpreprocess/readadress.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/readadress.c rename to src/gromacs/gmxpreprocess/readadress.cpp index a95374cda8..16f75891ec 100644 --- a/src/gromacs/gmxpreprocess/readadress.c +++ b/src/gromacs/gmxpreprocess/readadress.cpp @@ -2,7 +2,7 @@ * This file is part of the GROMACS molecular simulation package. * * Copyright (c) 2009 Christoph Junghans, Brad Lambeth. - * Copyright (c) 2012,2014, by the GROMACS development team, led by + * Copyright (c) 2012,2014,2015, 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. diff --git a/src/gromacs/gmxpreprocess/readir.c b/src/gromacs/gmxpreprocess/readir.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/readir.c rename to src/gromacs/gmxpreprocess/readir.cpp index 52f408f21d..2bbed056dd 100644 --- a/src/gromacs/gmxpreprocess/readir.c +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -42,6 +42,10 @@ #include #include +#include + +#include + #include "gromacs/gmxpreprocess/toputil.h" #include "gromacs/legacyheaders/chargegroup.h" #include "gromacs/legacyheaders/inputrec.h" @@ -155,7 +159,7 @@ static void GetSimTemps(int ntemps, t_simtemp *simtemp, double *temperature_lamb } else if (simtemp->eSimTempScale == esimtempGEOMETRIC) /* should give roughly equal acceptance for constant heat capacity . . . */ { - simtemp->temperatures[i] = simtemp->simtemp_low * pow(simtemp->simtemp_high/simtemp->simtemp_low, (1.0*i)/(ntemps-1)); + simtemp->temperatures[i] = simtemp->simtemp_low * std::pow(simtemp->simtemp_high/simtemp->simtemp_low, static_cast((1.0*i)/(ntemps-1))); } else if (simtemp->eSimTempScale == esimtempEXPONENTIAL) { @@ -172,7 +176,7 @@ static void GetSimTemps(int ntemps, t_simtemp *simtemp, double *temperature_lamb -static void _low_check(gmx_bool b, char *s, warninp_t wi) +static void _low_check(gmx_bool b, const char *s, warninp_t wi) { if (b) { @@ -246,10 +250,7 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts, #define CHECK(b) _low_check(b, err_buf, wi) char err_buf[256], warn_buf[STRLEN]; int i, j; - int ns_type = 0; - real dt_coupl = 0; real dt_pcoupl; - int nstcmin; t_lambda *fep = ir->fepvals; t_expanded *expand = ir->expandedvals; @@ -386,7 +387,7 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts, warning_note(wi, "With Verlet lists the optimal nstlist is >= 10, with GPUs >= 20. Note that with the Verlet scheme, nstlist has no effect on the accuracy of your simulation."); } - rc_max = max(ir->rvdw, ir->rcoulomb); + rc_max = std::max(ir->rvdw, ir->rcoulomb); if (ir->verletbuf_tol <= 0) { @@ -739,7 +740,7 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts, sigma = 0.34; /* Maximum estimate for A and B charges equal with lambda power 1 */ lambda = 0.5; - r_sc = pow(lambda*fep->sc_alpha*pow(sigma/ir->rcoulomb, fep->sc_r_power) + 1.0, 1.0/fep->sc_r_power); + r_sc = std::pow(lambda*fep->sc_alpha*std::pow(sigma/ir->rcoulomb, fep->sc_r_power) + 1.0, 1.0/fep->sc_r_power); sprintf(warn_buf, "With PME there is a minor soft core effect present at the cut-off, proportional to (LJsigma/rcoulomb)^%g. This could have a minor effect on energy conservation, but usually other effects dominate. With a common sigma value of %g nm the fraction of the particle-particle potential at the cut-off at lambda=%g is around %.1e, while ewald-rtol is %.1e.", fep->sc_r_power, sigma, lambda, r_sc - 1.0, ir->ewald_rtol); @@ -775,7 +776,6 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts, if ((ir->bSimTemp) || (ir->efep == efepEXPANDED)) { fep = ir->fepvals; - expand = ir->expandedvals; /* checking equilibration of weights inputs for validity */ @@ -848,9 +848,11 @@ void check_ir(const char *mdparin, t_inputrec *ir, t_gromppopts *opts, sprintf(err_buf, "If there is no temperature control, and lmc-mcmove!= 'no',mc_temperature must be set to a positive number"); if (expand->nstTij > 0) { + sprintf(err_buf, "nstlog must be non-zero"); + CHECK(ir->nstlog != 0); sprintf(err_buf, "nst-transition-matrix (%d) must be an integer multiple of nstlog (%d)", expand->nstTij, ir->nstlog); - CHECK((mod(expand->nstTij, ir->nstlog) != 0)); + CHECK((expand->nstTij % ir->nstlog) != 0); } } @@ -1651,7 +1653,6 @@ static void do_fep_params(t_inputrec *ir, char fep_lambda[][STRLEN], char weight } } - expand = ir->expandedvals; /* now read in the weights */ parse_n_real(weights, &nweights, &(expand->init_lambda_weights)); if (nweights == 0) @@ -1758,7 +1759,7 @@ static void add_wall_energrps(gmx_groups_t *groups, int nwall, t_symtab *symtab) void read_expandedparams(int *ninp_p, t_inpfile **inp_p, t_expanded *expand, warninp_t wi) { - int ninp, nerror = 0; + int ninp; t_inpfile *inp; ninp = *ninp_p; @@ -2485,9 +2486,9 @@ void get_ir(const char *mdparin, const char *mdparout, { dumdub[0][i] = 0; } - m = sscanf(is->deform, "%lf %lf %lf %lf %lf %lf", - &(dumdub[0][0]), &(dumdub[0][1]), &(dumdub[0][2]), - &(dumdub[0][3]), &(dumdub[0][4]), &(dumdub[0][5])); + sscanf(is->deform, "%lf %lf %lf %lf %lf %lf", + &(dumdub[0][0]), &(dumdub[0][1]), &(dumdub[0][2]), + &(dumdub[0][3]), &(dumdub[0][4]), &(dumdub[0][5])); for (i = 0; i < 3; i++) { ir->deform[i][i] = dumdub[0][i]; @@ -2843,8 +2844,8 @@ static void calc_nrdf(gmx_mtop_t *mtop, t_inputrec *ir, char **gnames) { imin = 2; } - imin = min(imin, nrdf2[ai]); - jmin = min(jmin, nrdf2[aj]); + imin = std::min(imin, nrdf2[ai]); + jmin = std::min(jmin, nrdf2[aj]); nrdf2[ai] -= imin; nrdf2[aj] -= jmin; nrdf_tc [ggrpnr(groups, egcTC, ai)] -= 0.5*imin; @@ -2863,7 +2864,7 @@ static void calc_nrdf(gmx_mtop_t *mtop, t_inputrec *ir, char **gnames) for (j = 0; j < 3; j++) { ai = as + ia[1+j]; - imin = min(2, nrdf2[ai]); + imin = std::min(2, nrdf2[ai]); nrdf2[ai] -= imin; nrdf_tc [ggrpnr(groups, egcTC, ai)] -= 0.5*imin; nrdf_vcm[ggrpnr(groups, egcVCM, ai)] -= 0.5*imin; @@ -2935,7 +2936,6 @@ static void calc_nrdf(gmx_mtop_t *mtop, t_inputrec *ir, char **gnames) n_sub = 6; break; default: - n_sub = 0; gmx_incons("Checking comm_mode"); } @@ -3208,7 +3208,7 @@ void make_IMD_group(t_IMD *IMDgroup, char *IMDgname, t_blocka *grps, char **gnam void do_index(const char* mdparin, const char *ndx, gmx_mtop_t *mtop, gmx_bool bVerbose, - t_inputrec *ir, rvec *v, + t_inputrec *ir, warninp_t wi) { t_blocka *grps; @@ -3223,10 +3223,8 @@ void do_index(const char* mdparin, const char *ndx, int nacg, nfreeze, nfrdim, nenergy, nvcm, nuser; char *ptr1[MAXPTR], *ptr2[MAXPTR], *ptr3[MAXPTR]; int i, j, k, restnm; - real SAtime; gmx_bool bExcl, bTable, bSetTCpar, bAnneal, bRest; - int nQMmethod, nQMbasis, nQMcharge, nQMmult, nbSH, nCASorb, nCASelec, - nSAon, nSAoff, nSAsteps, nQMg, nbOPT, nbTS; + int nQMmethod, nQMbasis, nQMg; char warn_buf[STRLEN]; if (bVerbose) @@ -3312,7 +3310,7 @@ void do_index(const char* mdparin, const char *ndx, if (ir->opts.tau_t[i] >= 0) { - tau_min = min(tau_min, ir->opts.tau_t[i]); + tau_min = std::min(tau_min, ir->opts.tau_t[i]); } } if (ir->etc != etcNO && ir->nsttcouple == -1) @@ -3330,7 +3328,7 @@ void do_index(const char* mdparin, const char *ndx, { if (ir->nstpcouple != ir->nsttcouple) { - int mincouple = min(ir->nstpcouple, ir->nsttcouple); + int mincouple = std::min(ir->nstpcouple, ir->nsttcouple); ir->nstpcouple = ir->nsttcouple = mincouple; sprintf(warn_buf, "for current Trotter decomposition methods with vv, nsttcouple and nstpcouple must be equal. Both have been reset to min(nsttcouple,nstpcouple) = %d", mincouple); warning_note(wi, warn_buf); @@ -3623,30 +3621,6 @@ void do_index(const char* mdparin, const char *ndx, /* Now we have filled the freeze struct, so we can calculate NRDF */ calc_nrdf(mtop, ir, gnames); - if (v && NULL) - { - real fac, ntot = 0; - - /* Must check per group! */ - for (i = 0; (i < ir->opts.ngtc); i++) - { - ntot += ir->opts.nrdf[i]; - } - if (ntot != (DIM*natoms)) - { - fac = sqrt(ntot/(DIM*natoms)); - if (bVerbose) - { - fprintf(stderr, "Scaling velocities by a factor of %.3f to account for constraints\n" - "and removal of center of mass motion\n", fac); - } - for (i = 0; (i < natoms); i++) - { - svmul(fac, v[i], v[i]); - } - } - } - nuser = str_nelem(is->user1, MAXPTR, ptr1); do_numbering(natoms, groups, nuser, ptr1, grps, gnames, egcUser1, restnm, egrptpALL_GENREST, bVerbose, wi); @@ -3687,9 +3661,9 @@ void do_index(const char* mdparin, const char *ndx, eQMbasis_names); } - nQMmult = str_nelem(is->QMmult, MAXPTR, ptr1); - nQMcharge = str_nelem(is->QMcharge, MAXPTR, ptr2); - nbSH = str_nelem(is->bSH, MAXPTR, ptr3); + str_nelem(is->QMmult, MAXPTR, ptr1); + str_nelem(is->QMcharge, MAXPTR, ptr2); + str_nelem(is->bSH, MAXPTR, ptr3); snew(ir->opts.QMmult, nr); snew(ir->opts.QMcharge, nr); snew(ir->opts.bSH, nr); @@ -3701,8 +3675,8 @@ void do_index(const char* mdparin, const char *ndx, ir->opts.bSH[i] = (gmx_strncasecmp(ptr3[i], "Y", 1) == 0); } - nCASelec = str_nelem(is->CASelectrons, MAXPTR, ptr1); - nCASorb = str_nelem(is->CASorbitals, MAXPTR, ptr2); + str_nelem(is->CASelectrons, MAXPTR, ptr1); + str_nelem(is->CASorbitals, MAXPTR, ptr2); snew(ir->opts.CASelectrons, nr); snew(ir->opts.CASorbitals, nr); for (i = 0; i < nr; i++) @@ -3712,8 +3686,8 @@ void do_index(const char* mdparin, const char *ndx, } /* special optimization options */ - nbOPT = str_nelem(is->bOPT, MAXPTR, ptr1); - nbTS = str_nelem(is->bTS, MAXPTR, ptr2); + str_nelem(is->bOPT, MAXPTR, ptr1); + str_nelem(is->bTS, MAXPTR, ptr2); snew(ir->opts.bOPT, nr); snew(ir->opts.bTS, nr); for (i = 0; i < nr; i++) @@ -3721,9 +3695,9 @@ void do_index(const char* mdparin, const char *ndx, ir->opts.bOPT[i] = (gmx_strncasecmp(ptr1[i], "Y", 1) == 0); ir->opts.bTS[i] = (gmx_strncasecmp(ptr2[i], "Y", 1) == 0); } - nSAon = str_nelem(is->SAon, MAXPTR, ptr1); - nSAoff = str_nelem(is->SAoff, MAXPTR, ptr2); - nSAsteps = str_nelem(is->SAsteps, MAXPTR, ptr3); + str_nelem(is->SAon, MAXPTR, ptr1); + str_nelem(is->SAoff, MAXPTR, ptr2); + str_nelem(is->SAsteps, MAXPTR, ptr3); snew(ir->opts.SAon, nr); snew(ir->opts.SAoff, nr); snew(ir->opts.SAsteps, nr); @@ -3929,10 +3903,9 @@ check_combination_rule_differences(const gmx_mtop_t *mtop, int state, gmx_bool *bC6ParametersWorkWithLBRules, gmx_bool *bLBRulesPossible) { - int ntypes, tpi, tpj, thisLBdiff, thisgeomdiff; + int ntypes, tpi, tpj; int *typecount; real tol; - double geometricdiff, LBdiff; double c6i, c6j, c12i, c12j; double c6, c6_geometric, c6_LB; double sigmai, sigmaj, epsi, epsj; @@ -3955,11 +3928,9 @@ check_combination_rule_differences(const gmx_mtop_t *mtop, int state, *bC6ParametersWorkWithLBRules = TRUE; *bC6ParametersWorkWithGeometricRules = TRUE; bCanDoLBRules = TRUE; - bCanDoGeometricRules = TRUE; ntypes = mtop->ffparams.atnr; snew(typecount, ntypes); gmx_mtop_count_atomtypes(mtop, state, typecount); - geometricdiff = LBdiff = 0.0; *bLBRulesPossible = TRUE; for (tpi = 0; tpi < ntypes; ++tpi) { @@ -3970,16 +3941,16 @@ check_combination_rule_differences(const gmx_mtop_t *mtop, int state, c6j = mtop->ffparams.iparams[(ntypes + 1) * tpj].lj.c6; c12j = mtop->ffparams.iparams[(ntypes + 1) * tpj].lj.c12; c6 = mtop->ffparams.iparams[ntypes * tpi + tpj].lj.c6; - c6_geometric = sqrt(c6i * c6j); + c6_geometric = std::sqrt(c6i * c6j); if (!gmx_numzero(c6_geometric)) { if (!gmx_numzero(c12i) && !gmx_numzero(c12j)) { - sigmai = pow(c12i / c6i, 1.0/6.0); - sigmaj = pow(c12j / c6j, 1.0/6.0); + sigmai = std::pow(c12i / c6i, 1.0/6.0); + sigmaj = std::pow(c12j / c6j, 1.0/6.0); epsi = c6i * c6i /(4.0 * c12i); epsj = c6j * c6j /(4.0 * c12j); - c6_LB = 4.0 * pow(epsi * epsj, 1.0/2.0) * pow(0.5 * (sigmai + sigmaj), 6); + c6_LB = 4.0 * std::pow(epsi * epsj, 1.0/2.0) * std::pow(0.5 * (sigmai + sigmaj), 6); } else { @@ -4009,7 +3980,6 @@ static void check_combination_rules(const t_inputrec *ir, const gmx_mtop_t *mtop, warninp_t wi) { - char err_buf[256]; gmx_bool bLBRulesPossible, bC6ParametersWorkWithGeometricRules, bC6ParametersWorkWithLBRules; check_combination_rule_differences(mtop, 0, @@ -4055,9 +4025,9 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys, warninp_t wi) { char err_buf[STRLEN]; - int i, m, c, nmol, npct; + int i, m, c, nmol; gmx_bool bCharge, bAcc; - real gdt_max, *mgrp, mt; + real *mgrp, mt; rvec acc; gmx_mtop_atomloop_block_t aloopb; gmx_mtop_atomloop_all_t aloop; @@ -4088,8 +4058,8 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys, tau = 0; for (i = 0; i < ir->opts.ngtc; i++) { - T = max(T, ir->opts.ref_t[i]); - tau = max(tau, ir->opts.tau_t[i]); + T = std::max(T, ir->opts.ref_t[i]); + tau = std::max(tau, ir->opts.tau_t[i]); } if (T > 0) { @@ -4411,7 +4381,7 @@ void double_check(t_inputrec *ir, matrix box, } else { - min_size = min(box[XX][XX], min(box[YY][YY], box[ZZ][ZZ])); + min_size = std::min(box[XX][XX], std::min(box[YY][YY], box[ZZ][ZZ])); if (2*ir->rlistlong >= min_size) { sprintf(warn_buf, "ERROR: One of the box lengths is smaller than twice the cut-off length. Increase the box size or decrease rlist."); @@ -4453,7 +4423,7 @@ void check_chargegroup_radii(const gmx_mtop_t *mtop, const t_inputrec *ir, sprintf(warn_buf, "The sum of the two largest charge group radii (%f) " "is larger than rlist (%f)\n", - max(rvdw1+rvdw2, rcoul1+rcoul2), ir->rlist); + std::max(rvdw1+rvdw2, rcoul1+rcoul2), ir->rlist); warning(wi, warn_buf); } else diff --git a/src/gromacs/gmxpreprocess/readir.h b/src/gromacs/gmxpreprocess/readir.h index ea76d63004..924681e895 100644 --- a/src/gromacs/gmxpreprocess/readir.h +++ b/src/gromacs/gmxpreprocess/readir.h @@ -42,10 +42,6 @@ #include "gromacs/legacyheaders/readinp.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - enum { eshNONE, eshHBONDS, eshALLBONDS, eshHANGLES, eshALLANGLES, eshNR }; @@ -117,11 +113,8 @@ void do_index(const char* mdparin, gmx_mtop_t *mtop, gmx_bool bVerbose, t_inputrec *ir, - rvec *v, warninp_t wi); /* Read the index file and assign grp numbers to atoms. - * If v is not NULL, the velocities will be scaled to the correct number - * of degrees of freedom. */ /* Routines In readpull.c */ @@ -164,8 +157,4 @@ void make_rotation_groups(t_rot *rot, char **rotgnames, void set_reference_positions(t_rot *rot, rvec *x, matrix box, const char *fn, gmx_bool bSet, warninp_t wi); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/readpull.c b/src/gromacs/gmxpreprocess/readpull.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/readpull.c rename to src/gromacs/gmxpreprocess/readpull.cpp index f2fb2d2203..665c93586b 100644 --- a/src/gromacs/gmxpreprocess/readpull.c +++ b/src/gromacs/gmxpreprocess/readpull.cpp @@ -68,7 +68,7 @@ static void init_pull_group(t_pull_group *pg, const char *wbuf) { double d; - int n, m; + int n; pg->nweight = 0; while (sscanf(wbuf, "%lf %n", &d, &n) == 1) @@ -84,9 +84,8 @@ static void init_pull_group(t_pull_group *pg, static void process_pull_dim(char *dim_buf, ivec dim) { - int ndim, d, nchar, c; + int ndim, d, nchar; char *ptr, pulldim1[STRLEN]; - t_pull_coord *pcrd; ptr = dim_buf; ndim = 0; @@ -189,13 +188,11 @@ char **read_pullparams(int *ninp_p, t_inpfile **inp_p, pull_params_t *pull, warninp_t wi) { - int ninp, i, nchar, nscan, m, idum; + int ninp, i, nscan, idum; t_inpfile *inp; const char *tmp; char **grpbuf; - char dummy[STRLEN], buf[STRLEN], groups[STRLEN], dim_buf[STRLEN]; - char init[STRLEN]; - const char *init_def1 = "0.0", *init_def3 = "0.0 0.0 0.0"; + char buf[STRLEN], groups[STRLEN], dim_buf[STRLEN]; char wbuf[STRLEN], origin_buf[STRLEN], vec_buf[STRLEN]; t_pull_group *pgrp; diff --git a/src/gromacs/gmxpreprocess/readrot.c b/src/gromacs/gmxpreprocess/readrot.cpp similarity index 99% rename from src/gromacs/gmxpreprocess/readrot.c rename to src/gromacs/gmxpreprocess/readrot.cpp index bd10df6e19..6968670a27 100644 --- a/src/gromacs/gmxpreprocess/readrot.c +++ b/src/gromacs/gmxpreprocess/readrot.cpp @@ -46,7 +46,7 @@ #include "gromacs/utility/futil.h" #include "gromacs/utility/smalloc.h" -static char *RotStr = {"Enforced rotation:"}; +static const char *RotStr = "Enforced rotation:"; static char s_vec[STRLEN]; diff --git a/src/gromacs/gmxpreprocess/resall.c b/src/gromacs/gmxpreprocess/resall.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/resall.c rename to src/gromacs/gmxpreprocess/resall.cpp index fe75e0cc65..208faddf99 100644 --- a/src/gromacs/gmxpreprocess/resall.c +++ b/src/gromacs/gmxpreprocess/resall.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -42,6 +42,8 @@ #include #include +#include + #include "gromacs/fileio/strdb.h" #include "gromacs/gmxpreprocess/fflibutil.h" #include "gromacs/gmxpreprocess/pgutil.h" @@ -88,7 +90,7 @@ gpp_atomtype_t read_atype(const char *ffdir, t_symtab *tab) if (sscanf(buf, "%s%lf", name, &m) == 2) { a->m = m; - add_atomtype(at, tab, a, name, nb, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ); + add_atomtype(at, tab, a, name, nb, 0, 0.0, 0.0, 0.0, 0, 0.0, 0.0 ); fprintf(stderr, "\rAtomtype %d", ++nratt); } else @@ -332,7 +334,7 @@ void read_resall(char *rrdb, int *nrtpptr, t_restp **rtp, gmx_bool bAllowOverrideRTP) { FILE *in; - char filebase[STRLEN], *ptr, line[STRLEN], header[STRLEN]; + char filebase[STRLEN], line[STRLEN], header[STRLEN]; int i, nrtp, maxrtp, bt, nparam; int dum1, dum2, dum3; t_restp *rrtp, *header_settings; @@ -574,7 +576,7 @@ static int neq_str_sign(const char *a1, const char *a2) l1 = (int)strlen(a1); l2 = (int)strlen(a2); - lm = min(l1, l2); + lm = std::min(l1, l2); if (lm >= 1 && ((l1 == l2+1 && is_sign(a1[l1-1])) || diff --git a/src/gromacs/gmxpreprocess/resall.h b/src/gromacs/gmxpreprocess/resall.h index 487ed643e2..463f982ef7 100644 --- a/src/gromacs/gmxpreprocess/resall.h +++ b/src/gromacs/gmxpreprocess/resall.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2010,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2014,2015, 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,10 +43,6 @@ #include "gromacs/gmxpreprocess/hackblock.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - char *search_rtp(const char *key, int nrtp, t_restp rtp[]); /* Search for an entry in the rtp database, returns the rtp residue name. * A mismatch of one character is allowed, if there is only one nearly @@ -69,8 +65,5 @@ void read_resall(char *resdb, int *nrtp, t_restp **rtp, void print_resall(FILE *out, int nrtp, t_restp rtp[], gpp_atomtype_t atype); /* write rtp database */ -#ifdef __cplusplus -} -#endif #endif diff --git a/src/gromacs/gmxpreprocess/solvate.h b/src/gromacs/gmxpreprocess/solvate.h index 29552919ba..d7b17f6fbc 100644 --- a/src/gromacs/gmxpreprocess/solvate.h +++ b/src/gromacs/gmxpreprocess/solvate.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014, by the GROMACS development team, led by + * Copyright (c) 2014,2015, 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. @@ -35,17 +35,6 @@ #ifndef GMX_GMXPREPROCESS_SOLVATE_H #define GMX_GMXPREPROCESS_SOLVATE_H -#ifdef __cplusplus -extern "C" { -#endif -#if 0 -} -#endif - int gmx_solvate(int argc, char *argv[]); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/sortwater.c b/src/gromacs/gmxpreprocess/sortwater.cpp similarity index 99% rename from src/gromacs/gmxpreprocess/sortwater.c rename to src/gromacs/gmxpreprocess/sortwater.cpp index 73c8b5472d..1248f8d46a 100644 --- a/src/gromacs/gmxpreprocess/sortwater.c +++ b/src/gromacs/gmxpreprocess/sortwater.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2010,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2014,2015, 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. diff --git a/src/gromacs/gmxpreprocess/sortwater.h b/src/gromacs/gmxpreprocess/sortwater.h index fc9e704712..ebef2dfa37 100644 --- a/src/gromacs/gmxpreprocess/sortwater.h +++ b/src/gromacs/gmxpreprocess/sortwater.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2010,2014, by the GROMACS development team, led by + * Copyright (c) 2010,2014,2015, 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. @@ -41,10 +41,6 @@ #include "gromacs/legacyheaders/typedefs.h" #include "gromacs/random/random.h" -#ifdef __cplusplus -extern "C" { -#endif - void randwater(int astart, int nwater, int nwatom, rvec x[], rvec v[], gmx_rng_t rng); /* Randomize the order of nwater molecules of length nwatom, the @@ -65,8 +61,4 @@ void mkcompact(int astart, int nwater, int nwatom, rvec x[], rvec v[], /* Make compact subboxes * IS NOT THREAD SAFE */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/specbond.c b/src/gromacs/gmxpreprocess/specbond.cpp similarity index 97% rename from src/gromacs/gmxpreprocess/specbond.c rename to src/gromacs/gmxpreprocess/specbond.cpp index 2d1bfcf261..700e216d42 100644 --- a/src/gromacs/gmxpreprocess/specbond.c +++ b/src/gromacs/gmxpreprocess/specbond.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -39,9 +39,12 @@ #include "specbond.h" #include -#include #include +#include + +#include + #include "gromacs/fileio/pdbio.h" #include "gromacs/fileio/strdb.h" #include "gromacs/gmxpreprocess/pdb2top.h" @@ -274,7 +277,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive, for (j = 0; (j < nspec); j++) { aj = sgp[j]; - d[i][j] = sqrt(distance2(x[ai], x[aj])); + d[i][j] = std::sqrt(distance2(x[ai], x[aj])); } } if (nspec > 1) @@ -285,7 +288,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive, { /* print resname/number column headings */ fprintf(stderr, "%8s%8s", "", ""); - e = min(b+MAXCOL, nspec-1); + e = std::min(b+MAXCOL, nspec-1); for (i = b; (i < e); i++) { sprintf(buf, "%s%d", *pdba->resinfo[pdba->atom[sgp[i]].resind].name, @@ -295,7 +298,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive, fprintf(stderr, "\n"); /* print atomname/number column headings */ fprintf(stderr, "%8s%8s", "", ""); - e = min(b+MAXCOL, nspec-1); + e = std::min(b+MAXCOL, nspec-1); for (i = b; (i < e); i++) { sprintf(buf, "%s%d", *pdba->atomname[sgp[i]], sgp[i]+1); @@ -303,7 +306,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive, } fprintf(stderr, "\n"); /* print matrix */ - e = min(b+MAXCOL, nspec); + e = std::min(b+MAXCOL, nspec); for (i = b+1; (i < nspec); i++) { sprintf(buf, "%s%d", *pdba->resinfo[pdba->atom[sgp[i]].resind].name, @@ -311,7 +314,7 @@ int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive, fprintf(stderr, "%8s", buf); sprintf(buf, "%s%d", *pdba->atomname[sgp[i]], sgp[i]+1); fprintf(stderr, "%8s", buf); - e2 = min(i, e); + e2 = std::min(i, e); for (j = b; (j < e2); j++) { fprintf(stderr, " %7.3f", d[i][j]); diff --git a/src/gromacs/gmxpreprocess/specbond.h b/src/gromacs/gmxpreprocess/specbond.h index 4c8eedc307..bcdd7bd9aa 100644 --- a/src/gromacs/gmxpreprocess/specbond.h +++ b/src/gromacs/gmxpreprocess/specbond.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -40,17 +40,9 @@ #include "gromacs/gmxpreprocess/pdb2top.h" -#ifdef __cplusplus -extern "C" { -#endif - int mk_specbonds(t_atoms *pdba, rvec x[], gmx_bool bInteractive, t_ssbond **specbonds, gmx_bool bVerbose); gmx_bool yesno(void); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/ter_db.c b/src/gromacs/gmxpreprocess/ter_db.cpp similarity index 91% rename from src/gromacs/gmxpreprocess/ter_db.c rename to src/gromacs/gmxpreprocess/ter_db.cpp index df0722c368..eca3a323f0 100644 --- a/src/gromacs/gmxpreprocess/ter_db.c +++ b/src/gromacs/gmxpreprocess/ter_db.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -90,7 +90,7 @@ static void read_atom(char *line, gmx_bool bAdd, char **nname, t_atom *a, gpp_atomtype_t atype, int *cgnr) { int nr, i; - char buf[5][30], type[12]; + char buf[5][30]; double m, q; /* This code is messy, because of support for different formats: @@ -151,7 +151,7 @@ static void print_ter_db(const char *ff, char C, int nb, t_hackblock tb[], { FILE *out; int i, j, k, bt, nrepl, nadd, ndel; - char buf[STRLEN], nname[STRLEN]; + char buf[STRLEN]; sprintf(buf, "%s-%c.tdb", ff, C); out = gmx_fio_fopen(buf, "w"); @@ -440,6 +440,7 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[], const char *rtpname, int *nret) { + // TODO Four years later, no force fields have ever used this, so decide status of this feature /* Since some force fields (e.g. OPLS) needs different * atomtypes for different residues there could be a lot * of entries in the databases for specific residues @@ -462,9 +463,9 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[], */ t_restp * restp; - int i, j, n, len, none_idx; + int i, j, n, none_idx; gmx_bool found; - char *rtpname_match, *s, *s2, *c; + char *rtpname_match, *s; t_hackblock **list; rtpname_match = search_rtp(rtpname, nrtp, rtp); @@ -505,8 +506,8 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[], while (!found && s != NULL); } - /* All residue-specific termini have been added. See if there - * are some generic ones by searching for the occurence of + /* All residue-specific termini have been added. We might have to fall + * back on generic termini, which are characterized by not having * '-' in the name prior to the last position (which indicates charge). * The [ None ] alternative is special since we don't want that * to be the default, so we put it last in the list we return. @@ -528,8 +529,22 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[], } else { - c = strchr(s, '-'); - if (c == NULL || ((c-s+1) == strlen(s))) + /* Time to see if there's a generic terminus that matches. + Is there a hyphen? */ + char *c = strchr(s, '-'); + + /* A conjunction hyphen normally indicates a residue-specific + terminus, which is named like "GLY-COOH". A generic terminus + won't have a hyphen. */ + bool bFoundAnyHyphen = (c != NULL); + /* '-' as the last character indicates charge, so if that's + the only one found e.g. "COO-", then it was not a conjunction + hyphen, so this is a generic terminus */ + bool bOnlyFoundChargeHyphen = (bFoundAnyHyphen && + *(c+1) == '\0'); + /* Thus, "GLY-COO-" is not recognized as a generic terminus. */ + bool bFoundGenericTerminus = !bFoundAnyHyphen || bOnlyFoundChargeHyphen; + if (bFoundGenericTerminus) { /* Check that we haven't already added a residue-specific version * of this terminus. @@ -567,12 +582,9 @@ t_hackblock *choose_ter(int nb, t_hackblock **tb, const char *title) printf("%s\n", title); for (i = 0; (i < nb); i++) { - char *advice_string = ""; - if (0 == gmx_wcmatch("*ZWITTERION*", (*tb[i]).name)) - { - advice_string = " (only use with zwitterions containing exactly one residue)"; - } - printf("%2d: %s%s\n", i, (*tb[i]).name, advice_string); + bool bIsZwitterion = (0 == gmx_wcmatch("*ZWITTERION*", (*tb[i]).name)); + printf("%2d: %s%s\n", i, (*tb[i]).name, + bIsZwitterion ? " (only use with zwitterions containing exactly one residue)" : ""); } do { diff --git a/src/gromacs/gmxpreprocess/ter_db.h b/src/gromacs/gmxpreprocess/ter_db.h index 45477d6207..b861e42d58 100644 --- a/src/gromacs/gmxpreprocess/ter_db.h +++ b/src/gromacs/gmxpreprocess/ter_db.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011,2014, by the GROMACS development team, led by + * Copyright (c) 2011,2014,2015, 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. @@ -41,9 +41,6 @@ #include "gromacs/gmxpreprocess/grompp-impl.h" #include "gromacs/gmxpreprocess/hackblock.h" -#ifdef __cplusplus -extern "C" { -#endif int read_ter_db(const char *ffdir, char ter, t_hackblock **tbptr, gpp_atomtype_t atype); @@ -59,8 +56,4 @@ t_hackblock **filter_ter(int nrtp, t_restp rtp[], t_hackblock *choose_ter(int nb, t_hackblock **tb, const char *title); /* Interactively select one.. */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/tomorse.c b/src/gromacs/gmxpreprocess/tomorse.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/tomorse.c rename to src/gromacs/gmxpreprocess/tomorse.cpp index cd9b793b5f..668c652cd8 100644 --- a/src/gromacs/gmxpreprocess/tomorse.c +++ b/src/gromacs/gmxpreprocess/tomorse.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -40,10 +40,11 @@ #include "tomorse.h" #include -#include #include #include +#include + #include "gromacs/gmxpreprocess/gpp_atomtype.h" #include "gromacs/gmxpreprocess/grompp-impl.h" #include "gromacs/gmxpreprocess/toputil.h" @@ -250,7 +251,7 @@ void convert_harmonics(int nrmols, t_molinfo mols[], gpp_atomtype_t atype) bRemoveHarm[j] = TRUE; b0 = mols[i].plist[bb].param[j].c[0]; kb = mols[i].plist[bb].param[j].c[1]; - beta = sqrt(kb/(2*edis)); + beta = std::sqrt(kb/(2*edis)); mols[i].plist[F_MORSE].param[nrmorse].a[0] = ni; mols[i].plist[F_MORSE].param[nrmorse].a[1] = nj; mols[i].plist[F_MORSE].param[nrmorse].c[0] = b0; diff --git a/src/gromacs/gmxpreprocess/tomorse.h b/src/gromacs/gmxpreprocess/tomorse.h index 6a39ea6fd8..cb098869de 100644 --- a/src/gromacs/gmxpreprocess/tomorse.h +++ b/src/gromacs/gmxpreprocess/tomorse.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2012,2013,2014, by the GROMACS development team, led by + * Copyright (c) 2012,2013,2014,2015, 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. @@ -44,14 +44,6 @@ #include "gromacs/gmxpreprocess/grompp-impl.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - void convert_harmonics(int nrmols, t_molinfo mols[], gpp_atomtype_t atype); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/topdirs.c b/src/gromacs/gmxpreprocess/topdirs.cpp similarity index 100% rename from src/gromacs/gmxpreprocess/topdirs.c rename to src/gromacs/gmxpreprocess/topdirs.cpp diff --git a/src/gromacs/gmxpreprocess/topdirs.h b/src/gromacs/gmxpreprocess/topdirs.h index fa62531eeb..38a664a2d0 100644 --- a/src/gromacs/gmxpreprocess/topdirs.h +++ b/src/gromacs/gmxpreprocess/topdirs.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -40,10 +40,6 @@ #include "gromacs/gmxpreprocess/grompp-impl.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct tagDirStack { directive d; struct tagDirStack *prev; @@ -65,8 +61,4 @@ int DS_Search (DirStack *DS, directive d); int DS_Check_Order (DirStack *DS, directive d); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/topio.c b/src/gromacs/gmxpreprocess/topio.cpp similarity index 99% rename from src/gromacs/gmxpreprocess/topio.c rename to src/gromacs/gmxpreprocess/topio.cpp index 3478619757..906823befc 100644 --- a/src/gromacs/gmxpreprocess/topio.c +++ b/src/gromacs/gmxpreprocess/topio.cpp @@ -38,14 +38,14 @@ #include "topio.h" -#include #include #include -#include #include #include #include +#include + #include #include "gromacs/fileio/gmxfio.h" @@ -72,6 +72,7 @@ #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/futil.h" +#include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" #define OPENDIR '[' /* starting sign for directive */ @@ -120,7 +121,8 @@ static void gen_pairs(t_params *nbs, t_params *pairs, real fudge, int comb) int i, j, ntp, nrfp, nrfpA, nrfpB, nnn; real scaling; ntp = nbs->nr; - nnn = sqrt(ntp); + nnn = static_cast(std::sqrt(static_cast(ntp))); + GMX_ASSERT(nnn * nnn == ntp, "Number of pairs of generated non-bonded parameters should be a perfect square"); nrfp = NRFP(F_LJ); nrfpA = interaction_function[F_LJ14].nrfpA; nrfpB = interaction_function[F_LJ14].nrfpB; @@ -415,7 +417,7 @@ find_gb_anglelength(t_params *plist, int ai, int ak, real *length) if (status1 == 0 && status2 == 0) { /* cosine theorem to get r13 */ - *length = sqrt(r12*r12+r23*r23-(2*r12*r23*cos(a123/RAD2DEG))); + *length = std::sqrt(r12*r12+r23*r23-(2*r12*r23*cos(a123/RAD2DEG))); found = 1; } } @@ -430,8 +432,7 @@ find_gb_anglelength(t_params *plist, int ai, int ak, real *length) int generate_gb_exclusion_interactions(t_molinfo *mi, gpp_atomtype_t atype, t_nextnb *nnb) { - int i, j, k, n, ai, aj, ti, tj; - int n12, n13, n14; + int j, n, ai, aj, ti, tj; int ftype; t_param param; t_params * plist; @@ -575,7 +576,7 @@ static char **read_topol(const char *infile, const char *outfile, warninp_t wi) { FILE *out; - int i, sl, nb_funct, comb; + int i, sl, nb_funct; char *pline = NULL, **title = NULL; char line[STRLEN], errbuf[256], comb_str[256], nb_str[256]; char genpairs[32]; @@ -583,12 +584,10 @@ static char **read_topol(const char *infile, const char *outfile, int nrcopies, nmol, nmolb = 0, nscan, ncombs, ncopy; double fLJ, fQQ, fPOW; gmx_molblock_t *molb = NULL; - t_topology *block = NULL; t_molinfo *mi0 = NULL; DirStack *DS; directive d, newd; t_nbparam **nbparam, **pair; - gmx_bool bIntermolecularInteractions; t_block2 *block2; real fudgeLJ = -1; /* Multiplication factor to generate 1-4 from LJ */ gmx_bool bReadDefaults, bReadMolType, bGenPairs, bWarn_copy_A_B; @@ -965,7 +964,7 @@ static char **read_topol(const char *infile, const char *outfile, push_vsitesn(d, mi0->plist, &(mi0->atoms), pline, wi); break; case d_exclusions: - assert(block2); + GMX_ASSERT(block2, "block2 must always be allocated so exclusions can be processed"); if (!block2[nmol-1].nr) { init_block2(&(block2[nmol-1]), mi0->atoms.nr); @@ -1260,7 +1259,6 @@ static void generate_qmexcl_moltype(gmx_moltype_t *molt, unsigned char *grpnr, j = 0; while (j < molt->ilist[i].nr) { - bexcl = FALSE; switch (nratoms) { case 2: @@ -1299,6 +1297,7 @@ static void generate_qmexcl_moltype(gmx_moltype_t *molt, unsigned char *grpnr, break; default: gmx_fatal(FARGS, "no such bonded interactions with %d atoms\n", nratoms); + bexcl = FALSE; } if (bexcl) { diff --git a/src/gromacs/gmxpreprocess/topio.h b/src/gromacs/gmxpreprocess/topio.h index 744f31202a..124503492f 100644 --- a/src/gromacs/gmxpreprocess/topio.h +++ b/src/gromacs/gmxpreprocess/topio.h @@ -43,10 +43,6 @@ #include "gromacs/gmxpreprocess/readir.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - double check_mol(gmx_mtop_t *mtop, warninp_t wi); /* Check mass and charge */ @@ -73,8 +69,4 @@ char **do_top(gmx_bool bVerbose, /* 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); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/toppush.c b/src/gromacs/gmxpreprocess/toppush.cpp similarity index 97% rename from src/gromacs/gmxpreprocess/toppush.c rename to src/gromacs/gmxpreprocess/toppush.cpp index 832a2a1203..6fb5e3577c 100644 --- a/src/gromacs/gmxpreprocess/toppush.c +++ b/src/gromacs/gmxpreprocess/toppush.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -38,11 +38,13 @@ #include "toppush.h" -#include #include -#include #include +#include + +#include + #include "gromacs/gmxpreprocess/gpp_atomtype.h" #include "gromacs/gmxpreprocess/gpp_bond_atomtype.h" #include "gromacs/gmxpreprocess/readir.h" @@ -54,6 +56,7 @@ #include "gromacs/topology/symtab.h" #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atype, @@ -86,7 +89,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp { ci = get_atomtype_nbparam(i, nf, atype); cj = get_atomtype_nbparam(j, nf, atype); - c = sqrt(ci * cj); + c = std::sqrt(ci * cj); plist->param[k].c[nf] = c; } } @@ -111,7 +114,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp { plist->param[k].c[0] *= -1; } - plist->param[k].c[1] = sqrt(ci1*cj1); + plist->param[k].c[1] = std::sqrt(ci1*cj1); } } @@ -126,7 +129,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp cj0 = get_atomtype_nbparam(j, 0, atype); ci1 = get_atomtype_nbparam(i, 1, atype); cj1 = get_atomtype_nbparam(j, 1, atype); - plist->param[k].c[0] = sqrt(fabs(ci0*cj0)); + plist->param[k].c[0] = std::sqrt(fabs(ci0*cj0)); /* Negative sigma signals that c6 should be set to zero later, * so we need to propagate that through the combination rules. */ @@ -134,7 +137,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp { plist->param[k].c[0] *= -1; } - plist->param[k].c[1] = sqrt(ci1*cj1); + plist->param[k].c[1] = std::sqrt(ci1*cj1); } } @@ -160,7 +163,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp cj2 = get_atomtype_nbparam(j, 2, atype); bi = get_atomtype_nbparam(i, 1, atype); bj = get_atomtype_nbparam(j, 1, atype); - plist->param[k].c[0] = sqrt(ci0 * cj0); + plist->param[k].c[0] = std::sqrt(ci0 * cj0); if ((bi == 0) || (bj == 0)) { plist->param[k].c[1] = 0; @@ -169,7 +172,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype_t atyp { plist->param[k].c[1] = 2.0/(1/bi+1/bj); } - plist->param[k].c[2] = sqrt(ci2 * cj2); + plist->param[k].c[2] = std::sqrt(ci2 * cj2); } } @@ -516,9 +519,9 @@ void push_at (t_symtab *symtab, gpp_atomtype_t at, t_bond_atomtype bat, gmx_fatal(FARGS, "Replacing atomtype %s failed", type); } } - else if ((nr = add_atomtype(at, symtab, atom, type, param, - batype_nr, radius, vol, - surftens, atomnr, gb_radius, S_hct)) == NOTSET) + else if ((add_atomtype(at, symtab, atom, type, param, + batype_nr, radius, vol, + surftens, atomnr, gb_radius, S_hct)) == NOTSET) { gmx_fatal(FARGS, "Adding atomtype %s failed", type); } @@ -674,7 +677,7 @@ void push_bt(directive d, t_params bt[], int nral, "%*s%*s%*s%*s%*s%*s%*s" }; const char *formlf = "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf"; - int i, ft, ftype, nn, nrfp, nrfpA, nrfpB; + int i, ft, ftype, nn, nrfp, nrfpA; char f1[STRLEN]; char alc[MAXATOMLIST+1][20]; /* One force parameter more, so we can check if we read too many */ @@ -700,7 +703,6 @@ void push_bt(directive d, t_params bt[], int nral, ftype = ifunc_index(d, ft); nrfp = NRFP(ftype); nrfpA = interaction_function[ftype].nrfpA; - nrfpB = interaction_function[ftype].nrfpB; strcpy(f1, formnl[nral]); strcat(f1, formlf); if ((nn = sscanf(line, f1, &c[0], &c[1], &c[2], &c[3], &c[4], &c[5], &c[6], &c[7], &c[8], &c[9], &c[10], &c[11], &c[12])) @@ -786,7 +788,7 @@ void push_dihedraltype(directive d, t_params bt[], "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", }; - int i, ft, ftype, nn, nrfp, nrfpA, nrfpB, nral; + int i, ft, ftype, nn, nrfp, nrfpA, nral; char f1[STRLEN]; char alc[MAXATOMLIST+1][20]; double c[MAXFORCEPARAM]; @@ -860,7 +862,6 @@ void push_dihedraltype(directive d, t_params bt[], ftype = ifunc_index(d, ft); nrfp = NRFP(ftype); nrfpA = interaction_function[ftype].nrfpA; - nrfpB = interaction_function[ftype].nrfpB; strcpy(f1, formnl[nral]); strcat(f1, formlf[nrfp-1]); @@ -925,14 +926,13 @@ void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype, warninp_t wi) { /* swap the atoms */ - const char *form2 = "%*s%*s%*s%lf%lf"; const char *form3 = "%*s%*s%*s%lf%lf%lf"; const char *form4 = "%*s%*s%*s%lf%lf%lf%lf"; const char *form5 = "%*s%*s%*s%lf%lf%lf%lf%lf"; char a0[80], a1[80]; - int i, f, n, ftype, atnr, nrfp; + int i, f, n, ftype, nrfp; double c[4], dum; - real cr[4], sig6; + real cr[4]; atom_id ai, aj; t_nbparam *nbp; gmx_bool bId; @@ -968,7 +968,7 @@ void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype, /* When the B topology parameters are not set, * copy them from topology A */ - assert(nrfp <= 4); + GMX_ASSERT(nrfp <= 4, "LJ-14 cannot have more than 4 parameters"); for (i = n; i < nrfp; i++) { c[i] = c[i-2]; @@ -1018,7 +1018,7 @@ void push_nbt(directive d, t_nbparam **nbt, gpp_atomtype_t atype, { gmx_fatal(FARGS, "Atomtype %s not found", a1); } - nbp = &(nbt[max(ai, aj)][min(ai, aj)]); + nbp = &(nbt[std::max(ai, aj)][std::min(ai, aj)]); if (nbp->bSet) { @@ -1050,13 +1050,12 @@ void push_gb_params (gpp_atomtype_t at, char *line, warninp_t wi) { - int nfield; int atype; double radius, vol, surftens, gb_radius, S_hct; char atypename[STRLEN]; char errbuf[STRLEN]; - if ( (nfield = sscanf(line, "%s%lf%lf%lf%lf%lf", atypename, &radius, &vol, &surftens, &gb_radius, &S_hct)) != 6) + if ( (sscanf(line, "%s%lf%lf%lf%lf%lf", atypename, &radius, &vol, &surftens, &gb_radius, &S_hct)) != 6) { sprintf(errbuf, "Too few gb parameters for type %s\n", atypename); warning(wi, errbuf); @@ -1081,12 +1080,11 @@ push_cmaptype(directive d, t_params bt[], int nral, gpp_atomtype_t at, { const char *formal = "%s%s%s%s%s%s%s%s"; - int i, j, ft, ftype, nn, nrfp, nrfpA, nrfpB; + int i, ft, ftype, nn, nrfp, nrfpA, nrfpB; int start; int nxcmap, nycmap, ncmap, read_cmap, sl, nct; char s[20], alc[MAXATOMLIST+2][20]; t_param p; - gmx_bool bAllowRepeat; char errbuf[256]; /* Keep the compiler happy */ @@ -1464,7 +1462,8 @@ static gmx_bool default_nb_params(int ftype, t_params bt[], t_atoms *at, /* First test the generated-pair position to save * time when we have 1000*1000 entries for e.g. OPLS... */ - ntype = sqrt(nr); + ntype = static_cast(std::sqrt(static_cast(nr))); + GMX_ASSERT(ntype * ntype == nr, "Number of pairs of generated non-bonded parameters should be a perfect square"); if (bB) { ti = at->atom[p->a[0]].typeB; @@ -1541,7 +1540,7 @@ static gmx_bool default_cmap_params(t_params bondtype[], t_param *p, gmx_bool bB, int *cmap_type, int *nparam_def) { - int i, j, nparam_found; + int i, nparam_found; int ct; gmx_bool bFound = FALSE; @@ -1731,7 +1730,7 @@ void push_bond(directive d, t_params bondtype[], t_params bond[], /* One force parameter more, so we can check if we read too many */ double cc[MAXFORCEPARAM+1]; int aa[MAXATOMLIST+1]; - t_param param, paramB, *param_defA, *param_defB; + t_param param, *param_defA, *param_defB; gmx_bool bFoundA = FALSE, bFoundB = FALSE, bDef, bPert, bSwapParity = FALSE; int nparam_defA, nparam_defB; char errbuf[256]; @@ -1841,7 +1840,7 @@ void push_bond(directive d, t_params bondtype[], t_params bond[], if (bFoundA) { /* Copy the A-state and B-state default parameters. */ - assert(NRFPA(ftype)+NRFPB(ftype) <= MAXFORCEPARAM); + GMX_ASSERT(NRFPA(ftype)+NRFPB(ftype) <= MAXFORCEPARAM, "Bonded interactions may have at most 12 parameters"); for (j = 0; (j < NRFPA(ftype)+NRFPB(ftype)); j++) { param.c[j] = param_defA->c[j]; @@ -2113,16 +2112,15 @@ void push_cmap(directive d, t_params bondtype[], t_params bond[], "%d%d%d%d%d%d%d" }; - int i, j, nr, ftype, nral, nread, ncmap_params; + int i, j, ftype, nral, nread, ncmap_params; int cmap_type; int aa[MAXATOMLIST+1]; char errbuf[256]; gmx_bool bFound; - t_param param, paramB, *param_defA, *param_defB; + t_param param; ftype = ifunc_index(d, 1); nral = NRAL(ftype); - nr = bondtype[ftype].nr; ncmap_params = 0; nread = sscanf(line, aaformat[nral-1], @@ -2225,7 +2223,7 @@ void push_vsitesn(directive d, t_params bond[], param.a[0] = a - 1; - ret = sscanf(ptr, "%d%n", &type, &n); + sscanf(ptr, "%d%n", &type, &n); ptr += n; ftype = ifunc_index(d, type); @@ -2606,7 +2604,8 @@ static void generate_LJCpairsNB(t_molinfo *mol, int nb_funct, t_params *nbp) n = mol->atoms.nr; atom = mol->atoms.atom; - ntype = sqrt(nbp->nr); + ntype = static_cast(std::sqrt(static_cast(nbp->nr))); + GMX_ASSERT(ntype * ntype == nbp->nr, "Number of pairs of generated non-bonded parameters should be a perfect square"); for (i = 0; i < MAXATOMLIST; i++) { diff --git a/src/gromacs/gmxpreprocess/toppush.h b/src/gromacs/gmxpreprocess/toppush.h index 1e14c57bc7..8ee48618df 100644 --- a/src/gromacs/gmxpreprocess/toppush.h +++ b/src/gromacs/gmxpreprocess/toppush.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -44,10 +44,6 @@ #include "gromacs/legacyheaders/typedefs.h" #include "gromacs/legacyheaders/warninp.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { int nr; /* The number of entries in the list */ int nra2; /* The total number of entries in a */ @@ -142,8 +138,4 @@ void convert_moltype_couple(t_molinfo *mol, int atomtype_decouple, * of the system, but full interaction with itself. */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/topshake.c b/src/gromacs/gmxpreprocess/topshake.cpp similarity index 96% rename from src/gromacs/gmxpreprocess/topshake.c rename to src/gromacs/gmxpreprocess/topshake.cpp index bd2662df2a..466bcc843d 100644 --- a/src/gromacs/gmxpreprocess/topshake.c +++ 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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -40,7 +40,8 @@ #include "topshake.h" #include -#include + +#include #include "gromacs/gmxpreprocess/readir.h" #include "gromacs/gmxpreprocess/topdirs.h" @@ -108,7 +109,7 @@ void make_shake (t_params plist[], t_atoms *atoms, int nshake) t_params *bonds; t_param p, *bond, *ang; real b_ij, b_jk; - int nb, b, i, j, ftype, ftype_a; + int i, j, ftype, ftype_a; gmx_bool bFound; if (nshake != eshNONE) @@ -193,8 +194,8 @@ void make_shake (t_params plist[], t_atoms *atoms, int nshake) if (bFound) { /* apply law of cosines */ - p.C0 = sqrt( b_ij*b_ij + b_jk*b_jk - - 2.0*b_ij*b_jk*cos(DEG2RAD*ang->C0) ); + p.C0 = std::sqrt( b_ij*b_ij + b_jk*b_jk - + 2.0*b_ij*b_jk*cos(DEG2RAD*ang->C0) ); p.C1 = p.C0; #ifdef DEBUG printf("p: %d, q: %d, dist: %12.5e\n", p.AI, p.AJ, p.C0); diff --git a/src/gromacs/gmxpreprocess/topshake.h b/src/gromacs/gmxpreprocess/topshake.h index 15e09da662..f232d56206 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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -40,14 +40,6 @@ #include "gromacs/gmxpreprocess/topio.h" -#ifdef __cplusplus -extern "C" { -#endif - void make_shake (t_params plist[], t_atoms *atoms, int nshake); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/toputil.c b/src/gromacs/gmxpreprocess/toputil.cpp similarity index 96% rename from src/gromacs/gmxpreprocess/toputil.c rename to src/gromacs/gmxpreprocess/toputil.cpp index 4cbcc05525..133773bea0 100644 --- a/src/gromacs/gmxpreprocess/toputil.c +++ b/src/gromacs/gmxpreprocess/toputil.cpp @@ -38,16 +38,19 @@ #include "toputil.h" -#include -#include #include +#include + +#include + #include "gromacs/gmxpreprocess/gpp_atomtype.h" #include "gromacs/gmxpreprocess/topdirs.h" #include "gromacs/legacyheaders/macros.h" #include "gromacs/topology/block.h" #include "gromacs/topology/symtab.h" #include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" /* UTILITIES */ @@ -86,10 +89,10 @@ void pr_alloc (int extra, t_params *pr) { return; } - assert(!((pr->nr == 0) && (pr->param != NULL))); + GMX_ASSERT(pr->nr != 0 || pr->param == NULL, "Invalid t_params object"); if (pr->nr+extra > pr->maxnr) { - pr->maxnr = max(1.2*pr->maxnr, pr->maxnr + extra); + pr->maxnr = std::max(static_cast(1.2*pr->maxnr), pr->maxnr + extra); srenew(pr->param, pr->maxnr); for (i = pr->nr; (i < pr->maxnr); i++) { @@ -477,6 +480,8 @@ void print_atoms(FILE *out, gpp_atomtype_t atype, t_atoms *at, int *cgnr, gmx_fatal(FARGS, "tpA = %d, i= %d in print_atoms", tpA, i); } + /* This is true by construction, but static analysers don't know */ + GMX_ASSERT(!bRTPresname || at->resinfo[at->atom[i].resind].rtp, "-rtpres did not have residue name available"); fprintf(out, "%6d %10s %6d%c %5s %6s %6d %10g %10g", i+1, tpnmA, at->resinfo[ri].nr, diff --git a/src/gromacs/gmxpreprocess/toputil.h b/src/gromacs/gmxpreprocess/toputil.h index d7d040effe..f25b3f4bf0 100644 --- a/src/gromacs/gmxpreprocess/toputil.h +++ b/src/gromacs/gmxpreprocess/toputil.h @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2012,2014, by the GROMACS development team, led by + * Copyright (c) 2012,2014,2015, 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. @@ -41,10 +41,6 @@ #include "gromacs/gmxpreprocess/gpp_atomtype.h" #include "gromacs/gmxpreprocess/grompp-impl.h" -#ifdef __cplusplus -extern "C" { -#endif - /* UTILITIES */ int name2index(char *str, char ***typenames, int ntypes); @@ -79,8 +75,4 @@ void print_bondeds(FILE *out, int natoms, directive d, void print_excl(FILE *out, int natoms, t_excls excls[]); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/vsite_parm.c b/src/gromacs/gmxpreprocess/vsite_parm.cpp similarity index 96% rename from src/gromacs/gmxpreprocess/vsite_parm.c rename to src/gromacs/gmxpreprocess/vsite_parm.cpp index 12357de2b4..34bbded82f 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.c +++ b/src/gromacs/gmxpreprocess/vsite_parm.cpp @@ -38,11 +38,13 @@ #include "vsite_parm.h" -#include -#include #include #include +#include + +#include + #include "gromacs/gmxpreprocess/add_par.h" #include "gromacs/gmxpreprocess/resall.h" #include "gromacs/gmxpreprocess/toputil.h" @@ -52,6 +54,7 @@ #include "gromacs/math/vec.h" #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" typedef struct { @@ -448,7 +451,7 @@ static gmx_bool calc_vsite3_param(gpp_atomtype_t atype, bError = bError || (bjk != bjl); /* the X atom (C or N) in the XH2/XH3 group is the first after the masses: */ - aN = max(param->AK, param->AL)+1; + aN = std::max(param->AK, param->AL)+1; /* get common bonds */ bMM = get_bond_length(nrbond, bonds, param->AK, param->AL); @@ -458,7 +461,7 @@ static gmx_bool calc_vsite3_param(gpp_atomtype_t atype, /* calculate common things */ rM = 0.5*bMM; - dM = sqrt( sqr(bCM) - sqr(rM) ); + dM = std::sqrt( sqr(bCM) - sqr(rM) ); /* are we dealing with the X atom? */ if (param->AI == aN) @@ -617,7 +620,7 @@ static gmx_bool calc_vsite3out_param(gpp_atomtype_t atype, bError = bError || (bjk != bjl); /* the X atom (C or N) in the XH3 group is the first after the masses: */ - aN = max(param->AK, param->AL)+1; + aN = std::max(param->AK, param->AL)+1; /* get all bondlengths and angles: */ bMM = get_bond_length(nrbond, bonds, param->AK, param->AL); @@ -635,7 +638,7 @@ static gmx_bool calc_vsite3out_param(gpp_atomtype_t atype, rHx = rH*cos(DEG2RAD*30); rHy = rH*sin(DEG2RAD*30); rM = 0.5*bMM; - dM = sqrt( sqr(bCM) - sqr(rM) ); + dM = std::sqrt( sqr(bCM) - sqr(rM) ); a = 0.5*( (dH/dM) - (rHy/rM) ); b = 0.5*( (dH/dM) + (rHy/rM) ); c = rHx / (2*dM*rM); @@ -656,9 +659,9 @@ static gmx_bool calc_vsite3out_param(gpp_atomtype_t atype, pijl = cos(aijl)*bij; a = ( pijk + (pijk*cos(akjl)-pijl) * cos(akjl) / sqr(sin(akjl)) ) / bjk; b = ( pijl + (pijl*cos(akjl)-pijk) * cos(akjl) / sqr(sin(akjl)) ) / bjl; - c = -sqrt( sqr(bij) - - ( sqr(pijk) - 2*pijk*pijl*cos(akjl) + sqr(pijl) ) - / sqr(sin(akjl)) ) + c = -std::sqrt( sqr(bij) - + ( sqr(pijk) - 2*pijk*pijl*cos(akjl) + sqr(pijl) ) + / sqr(sin(akjl)) ) / ( bjk*bjl*sin(akjl) ); } @@ -720,8 +723,8 @@ static gmx_bool calc_vsite4fd_param(t_param *param, gmx_fatal(FARGS, "invalid construction in calc_vsite4fd for atom %d: " "cosakl=%f, cosakm=%f\n", param->AI+1, cosakl, cosakm); } - sinakl = sqrt(1-sqr(cosakl)); - sinakm = sqrt(1-sqr(cosakm)); + sinakl = std::sqrt(1-sqr(cosakl)); + sinakm = std::sqrt(1-sqr(cosakm)); /* note: there is a '+' because of the way the sines are calculated */ cl = -pk / ( pl*cosakl - pk + pl*sinakl*(pm*cosakm-pk)/(pm*sinakm) ); @@ -817,7 +820,6 @@ int set_vsites(gmx_bool bVerbose, t_atoms *atoms, gpp_atomtype_t atype, t_mybonded *idihs; bFirst = TRUE; - bERROR = TRUE; nvsite = 0; if (debug) { @@ -915,6 +917,7 @@ int set_vsites(gmx_bool bVerbose, t_atoms *atoms, gpp_atomtype_t atype, "for %s atom %d", interaction_function[ftype].longname, plist[ftype].param[i].AI+1); + bERROR = TRUE; } /* switch */ if (bERROR) { @@ -1020,7 +1023,7 @@ static void check_vsite_constraints(t_params *plist, static void clean_vsite_bonds(t_params *plist, t_pindex pindex[], int cftype, int vsite_type[]) { - int ftype, i, j, parnr, k, l, m, n, nvsite, nOut, kept_i, vsitetype; + int ftype, i, j, k, m, n, nvsite, nOut, kept_i; int nconverted, nremoved; atom_id atom, oatom, at1, at2; gmx_bool bKeep, bRemove, bUsed, bPresent, bThisFD, bThisOUT, bAllFD, bFirstTwo; @@ -1104,8 +1107,8 @@ static void clean_vsite_bonds(t_params *plist, t_pindex pindex[], } else { - assert(vsnral != 0); - assert(first_atoms != NULL); + GMX_ASSERT(vsnral != 0, "nvsite > 1 must have vsnral != 0"); + GMX_ASSERT(first_atoms != NULL, "nvsite > 1 must have first_atoms != NULL"); /* if it is not the first then check if this vsite is constructed from the same atoms */ if (vsnral == NRAL(pindex[atom].ftype)-1) @@ -1175,7 +1178,7 @@ static void clean_vsite_bonds(t_params *plist, t_pindex pindex[], bUsed = FALSE; for (m = 0; (m < vsnral) && !bUsed; m++) { - assert(first_atoms != NULL); + GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was"); if (atom == first_atoms[m]) { @@ -1286,7 +1289,7 @@ static void clean_vsite_angles(t_params *plist, t_pindex pindex[], int cftype, int vsite_type[], at2vsitecon_t *at2vc) { - int i, j, parnr, k, l, m, n, nvsite, kept_i, vsitetype; + int i, j, k, m, n, nvsite, kept_i; atom_id atom, at1, at2; gmx_bool bKeep, bUsed, bPresent, bAll3FAD, bFirstTwo; t_params *ps; @@ -1317,8 +1320,8 @@ static void clean_vsite_angles(t_params *plist, t_pindex pindex[], } else { - assert(vsnral != 0); - assert(first_atoms != NULL); + GMX_ASSERT(vsnral != 0, "If we've seen a vsite before, we know how many constructing atoms it had"); + GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was"); /* check if this vsite is constructed from the same atoms */ if (vsnral == NRAL(pindex[atom].ftype)-1) { @@ -1366,7 +1369,7 @@ static void clean_vsite_angles(t_params *plist, t_pindex pindex[], bUsed = FALSE; for (m = 0; (m < vsnral) && !bUsed; m++) { - assert(first_atoms != NULL); + GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was"); if (atom == first_atoms[m]) { @@ -1430,7 +1433,7 @@ static void clean_vsite_dihs(t_params *plist, t_pindex pindex[], kept_i = 0; for (i = 0; (i < ps->nr); i++) /* for all dihedrals in the plist */ { - int ftype, parnr, k, l, m, n, nvsite; + int k, m, n, nvsite; int vsnral = 0; const atom_id *first_atoms = NULL; atom_id atom; @@ -1461,9 +1464,8 @@ static void clean_vsite_dihs(t_params *plist, t_pindex pindex[], } else { - assert(vsnral != 0); - assert(first_atoms != NULL); - + GMX_ASSERT(vsnral != 0, "If we've seen a vsite before, we know how many constructing atoms it had"); + GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was"); /* check if this vsite is constructed from the same atoms */ if (vsnral == NRAL(pindex[atom].ftype)-1) { @@ -1504,9 +1506,8 @@ static void clean_vsite_dihs(t_params *plist, t_pindex pindex[], construction of virtual sites. If so, keep it, if not throw away: */ for (k = 0; (k < 4) && !bKeep; k++) /* for all atoms in the dihedral */ { - assert(vsnral != 0); - assert(first_atoms != NULL); - + GMX_ASSERT(vsnral != 0, "If we've seen a vsite before, we know how many constructing atoms it had"); + GMX_ASSERT(first_atoms != NULL, "If we've seen a vsite before, we know what its first atom index was"); atom = ps->param[i].a[k]; if (vsite_type[atom] == NOTSET && vsite_type[atom] != F_VSITEN) { diff --git a/src/gromacs/gmxpreprocess/vsite_parm.h b/src/gromacs/gmxpreprocess/vsite_parm.h index 178ab9c0a4..2f87ef71af 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.h +++ b/src/gromacs/gmxpreprocess/vsite_parm.h @@ -42,10 +42,6 @@ #include "gromacs/gmxpreprocess/grompp-impl.h" #include "gromacs/legacyheaders/typedefs.h" -#ifdef __cplusplus -extern "C" { -#endif - int set_vsites(gmx_bool bVerbose, t_atoms *atoms, gpp_atomtype_t atype, t_params plist[]); /* set parameters for virtual sites, return number of virtual sites */ @@ -59,8 +55,4 @@ void set_vsites_ptype(gmx_bool bVerbose, gmx_moltype_t *molt); * Throw away all constraints. */ void clean_vsite_bondeds(t_params *ps, int natoms, gmx_bool bRmVSiteBds); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/x2top.c b/src/gromacs/gmxpreprocess/x2top.cpp similarity index 98% rename from src/gromacs/gmxpreprocess/x2top.c rename to src/gromacs/gmxpreprocess/x2top.cpp index 1c4e0bdce9..48f090e60f 100644 --- a/src/gromacs/gmxpreprocess/x2top.c +++ b/src/gromacs/gmxpreprocess/x2top.cpp @@ -38,7 +38,7 @@ #include "x2top.h" -#include +#include #include "gromacs/commandline/pargs.h" #include "gromacs/fileio/confio.h" @@ -62,6 +62,7 @@ #include "gromacs/topology/symtab.h" #include "gromacs/utility/cstringutil.h" #include "gromacs/utility/fatalerror.h" +#include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" char atp[7] = "HCNOSX"; @@ -156,11 +157,11 @@ void mk_bonds(int nnm, t_nm2type nmt[], dx2 = iprod(dx, dx); if (is_bond(nnm, nmt, *atoms->atomname[i], *atoms->atomname[j], - sqrt(dx2))) + std::sqrt(dx2))) { b.AI = i; b.AJ = j; - b.C0 = sqrt(dx2); + b.C0 = std::sqrt(dx2); add_param_to_list (bond, &b); nbond[i]++; nbond[j]++; @@ -179,7 +180,7 @@ int *set_cgnr(t_atoms *atoms, gmx_bool bUsePDBcharge, real *qtot, real *mtot) { int i, n = 1; int *cgnr; - double qt = 0, mt = 0; + double qt = 0; *qtot = *mtot = 0; snew(cgnr, atoms->nr); @@ -263,7 +264,7 @@ void lo_set_force_const(t_params *plist, real c[], int nrfp, gmx_bool bRound, c[0] += 180; } } - assert(nrfp <= MAXFORCEPARAM/2); + GMX_ASSERT(nrfp <= MAXFORCEPARAM/2, "Only 6 parameters may be used for an interaction"); for (j = 0; (j < nrfp); j++) { plist->param[i].c[j] = c[j]; @@ -276,7 +277,6 @@ void lo_set_force_const(t_params *plist, real c[], int nrfp, gmx_bool bRound, void set_force_const(t_params plist[], real kb, real kt, real kp, gmx_bool bRound, gmx_bool bParam) { - int i; real c[MAXFORCEPARAM]; c[0] = 0; @@ -451,12 +451,10 @@ int gmx_x2top(int argc, char *argv[]) int bts[] = { 1, 1, 1, 2 }; matrix box; /* box length matrix */ int natoms; /* number of atoms in one molecule */ - int nres; /* number of molecules? */ - int i, j, k, l, m, ndih; int epbc; gmx_bool bRTP, bTOP, bOPLS; t_symtab symtab; - real cutoff, qtot, mtot; + real qtot, mtot; char n2t[STRLEN]; output_env_t oenv; @@ -466,7 +464,7 @@ int gmx_x2top(int argc, char *argv[]) { efRTP, "-r", "out", ffOPTWR } }; #define NFILE asize(fnm) - static real scale = 1.1, kb = 4e5, kt = 400, kp = 5; + static real kb = 4e5, kt = 400, kp = 5; static t_restp rtp_header_settings; static gmx_bool bRemoveDihedralIfWithImproper = FALSE; static gmx_bool bGenerateHH14Interactions = TRUE; diff --git a/src/gromacs/gmxpreprocess/x2top.h b/src/gromacs/gmxpreprocess/x2top.h index 78de61acc7..99a5911dfc 100644 --- a/src/gromacs/gmxpreprocess/x2top.h +++ b/src/gromacs/gmxpreprocess/x2top.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014, by the GROMACS development team, led by + * Copyright (c) 2014,2015, 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. @@ -35,17 +35,6 @@ #ifndef GMX_GMXPREPROCESS_X2TOP_H #define GMX_GMXPREPROCESS_X2TOP_H -#ifdef __cplusplus -extern "C" { -#endif -#if 0 -} -#endif - int gmx_x2top(int argc, char *argv[]); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/gmxpreprocess/xlate.c b/src/gromacs/gmxpreprocess/xlate.cpp similarity index 99% rename from src/gromacs/gmxpreprocess/xlate.c rename to src/gromacs/gmxpreprocess/xlate.cpp index c4d2c7cfe2..151eef2cbf 100644 --- a/src/gromacs/gmxpreprocess/xlate.c +++ b/src/gromacs/gmxpreprocess/xlate.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. diff --git a/src/gromacs/gmxpreprocess/xlate.h b/src/gromacs/gmxpreprocess/xlate.h index aa1c61006d..45c2a8fff3 100644 --- a/src/gromacs/gmxpreprocess/xlate.h +++ b/src/gromacs/gmxpreprocess/xlate.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -41,10 +41,6 @@ #include "gromacs/gmxpreprocess/hackblock.h" #include "gromacs/utility/basedefinitions.h" -#ifdef __cplusplus -extern "C" { -#endif - struct gmx_residuetype_t; struct t_atoms; struct t_symtab; @@ -57,8 +53,4 @@ void rename_atoms(const char *xlfile, const char *ffdir, gmx_bool bResname, struct gmx_residuetype_t *rt, gmx_bool bReorderNum, gmx_bool bVerbose); -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/gromacs/math/vec.h b/src/gromacs/math/vec.h index d5ee22cbe1..17ef70662e 100644 --- a/src/gromacs/math/vec.h +++ b/src/gromacs/math/vec.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, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, 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. @@ -841,7 +841,7 @@ static gmx_inline real _divide_err(real a, real b, const char *file, int line) return a/b; } -static gmx_inline int _mod(int a, int b, char *file, int line) +static gmx_inline int _mod(int a, int b, const char *file, int line) { if (b == 0) {