Converted gmxpreprocess to compile as C++
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 10 Jul 2015 11:31:10 +0000 (13:31 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 14 Jul 2015 15:42:53 +0000 (17:42 +0200)
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

77 files changed:
src/gromacs/gmxpreprocess/CMakeLists.txt
src/gromacs/gmxpreprocess/add_par.cpp [moved from src/gromacs/gmxpreprocess/add_par.c with 96% similarity]
src/gromacs/gmxpreprocess/add_par.h
src/gromacs/gmxpreprocess/calch.cpp [moved from src/gromacs/gmxpreprocess/calch.c with 96% similarity]
src/gromacs/gmxpreprocess/calch.h
src/gromacs/gmxpreprocess/convparm.cpp [moved from src/gromacs/gmxpreprocess/convparm.c with 98% similarity]
src/gromacs/gmxpreprocess/convparm.h
src/gromacs/gmxpreprocess/fflibutil.h
src/gromacs/gmxpreprocess/gen_ad.cpp [moved from src/gromacs/gmxpreprocess/gen_ad.c with 97% similarity]
src/gromacs/gmxpreprocess/gen_ad.h
src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp [moved from src/gromacs/gmxpreprocess/gen_maxwell_velocities.c with 96% similarity]
src/gromacs/gmxpreprocess/gen_maxwell_velocities.h
src/gromacs/gmxpreprocess/gen_vsite.cpp [moved from src/gromacs/gmxpreprocess/gen_vsite.c with 97% similarity]
src/gromacs/gmxpreprocess/gen_vsite.h
src/gromacs/gmxpreprocess/genconf.cpp [moved from src/gromacs/gmxpreprocess/genconf.c with 100% similarity]
src/gromacs/gmxpreprocess/genconf.h
src/gromacs/gmxpreprocess/genhydro.cpp [moved from src/gromacs/gmxpreprocess/genhydro.c with 99% similarity]
src/gromacs/gmxpreprocess/genhydro.h
src/gromacs/gmxpreprocess/gmxcpp.cpp [moved from src/gromacs/gmxpreprocess/gmxcpp.c with 98% similarity]
src/gromacs/gmxpreprocess/gmxcpp.h
src/gromacs/gmxpreprocess/gpp_atomtype.cpp [moved from src/gromacs/gmxpreprocess/gpp_atomtype.c with 98% similarity]
src/gromacs/gmxpreprocess/gpp_atomtype.h
src/gromacs/gmxpreprocess/gpp_bond_atomtype.cpp [moved from src/gromacs/gmxpreprocess/gpp_bond_atomtype.c with 100% similarity]
src/gromacs/gmxpreprocess/gpp_bond_atomtype.h
src/gromacs/gmxpreprocess/gpp_nextnb.cpp [moved from src/gromacs/gmxpreprocess/gpp_nextnb.c with 99% similarity]
src/gromacs/gmxpreprocess/gpp_nextnb.h
src/gromacs/gmxpreprocess/grompp-impl.h
src/gromacs/gmxpreprocess/grompp.cpp [moved from src/gromacs/gmxpreprocess/grompp.c with 97% similarity]
src/gromacs/gmxpreprocess/grompp.h
src/gromacs/gmxpreprocess/h_db.cpp [moved from src/gromacs/gmxpreprocess/h_db.c with 97% similarity]
src/gromacs/gmxpreprocess/h_db.h
src/gromacs/gmxpreprocess/hackblock.cpp [moved from src/gromacs/gmxpreprocess/hackblock.c with 100% similarity]
src/gromacs/gmxpreprocess/hackblock.h
src/gromacs/gmxpreprocess/hizzie.cpp [moved from src/gromacs/gmxpreprocess/hizzie.c with 97% similarity]
src/gromacs/gmxpreprocess/hizzie.h
src/gromacs/gmxpreprocess/nm2type.cpp [moved from src/gromacs/gmxpreprocess/nm2type.c with 98% similarity]
src/gromacs/gmxpreprocess/nm2type.h
src/gromacs/gmxpreprocess/pdb2gmx.cpp [moved from src/gromacs/gmxpreprocess/pdb2gmx.c with 98% similarity]
src/gromacs/gmxpreprocess/pdb2gmx.h
src/gromacs/gmxpreprocess/pdb2top.cpp
src/gromacs/gmxpreprocess/pdb2top.h
src/gromacs/gmxpreprocess/pgutil.cpp [moved from src/gromacs/gmxpreprocess/pgutil.c with 100% similarity]
src/gromacs/gmxpreprocess/pgutil.h
src/gromacs/gmxpreprocess/read-conformation.h
src/gromacs/gmxpreprocess/readadress.cpp [moved from src/gromacs/gmxpreprocess/readadress.c with 98% similarity]
src/gromacs/gmxpreprocess/readir.cpp [moved from src/gromacs/gmxpreprocess/readir.c with 98% similarity]
src/gromacs/gmxpreprocess/readir.h
src/gromacs/gmxpreprocess/readpull.cpp [moved from src/gromacs/gmxpreprocess/readpull.c with 98% similarity]
src/gromacs/gmxpreprocess/readrot.cpp [moved from src/gromacs/gmxpreprocess/readrot.c with 99% similarity]
src/gromacs/gmxpreprocess/resall.cpp [moved from src/gromacs/gmxpreprocess/resall.c with 98% similarity]
src/gromacs/gmxpreprocess/resall.h
src/gromacs/gmxpreprocess/solvate.h
src/gromacs/gmxpreprocess/sortwater.cpp [moved from src/gromacs/gmxpreprocess/sortwater.c with 99% similarity]
src/gromacs/gmxpreprocess/sortwater.h
src/gromacs/gmxpreprocess/specbond.cpp [moved from src/gromacs/gmxpreprocess/specbond.c with 97% similarity]
src/gromacs/gmxpreprocess/specbond.h
src/gromacs/gmxpreprocess/ter_db.cpp [moved from src/gromacs/gmxpreprocess/ter_db.c with 91% similarity]
src/gromacs/gmxpreprocess/ter_db.h
src/gromacs/gmxpreprocess/tomorse.cpp [moved from src/gromacs/gmxpreprocess/tomorse.c with 98% similarity]
src/gromacs/gmxpreprocess/tomorse.h
src/gromacs/gmxpreprocess/topdirs.cpp [moved from src/gromacs/gmxpreprocess/topdirs.c with 100% similarity]
src/gromacs/gmxpreprocess/topdirs.h
src/gromacs/gmxpreprocess/topio.cpp [moved from src/gromacs/gmxpreprocess/topio.c with 99% similarity]
src/gromacs/gmxpreprocess/topio.h
src/gromacs/gmxpreprocess/toppush.cpp [moved from src/gromacs/gmxpreprocess/toppush.c with 97% similarity]
src/gromacs/gmxpreprocess/toppush.h
src/gromacs/gmxpreprocess/topshake.cpp [moved from src/gromacs/gmxpreprocess/topshake.c with 96% similarity]
src/gromacs/gmxpreprocess/topshake.h
src/gromacs/gmxpreprocess/toputil.cpp [moved from src/gromacs/gmxpreprocess/toputil.c with 96% similarity]
src/gromacs/gmxpreprocess/toputil.h
src/gromacs/gmxpreprocess/vsite_parm.cpp [moved from src/gromacs/gmxpreprocess/vsite_parm.c with 96% similarity]
src/gromacs/gmxpreprocess/vsite_parm.h
src/gromacs/gmxpreprocess/x2top.cpp [moved from src/gromacs/gmxpreprocess/x2top.c with 98% similarity]
src/gromacs/gmxpreprocess/x2top.h
src/gromacs/gmxpreprocess/xlate.cpp [moved from src/gromacs/gmxpreprocess/xlate.c with 99% similarity]
src/gromacs/gmxpreprocess/xlate.h
src/gromacs/math/vec.h

index 63a81b53fc1b9b8385f98e49f3d5e73799b0d67f..8dd9c8aad8791d0b71f09189b7b7cc34451748b4 100644 (file)
@@ -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)
 
similarity index 96%
rename from src/gromacs/gmxpreprocess/add_par.c
rename to src/gromacs/gmxpreprocess/add_par.cpp
index cf471c4641e40693d73cef372453199e72c89640..9a916d05b8256f55ca900c44f82e93e00ce6bd99 100644 (file)
@@ -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 <string.h>
 
+#include <algorithm>
+
 #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])
index 92a0d8be4d432853825564648e0fa42c5977864a..0ed13041fdc35474ccc3b0ff61ae215125cae34d 100644 (file)
@@ -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.
 #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
similarity index 96%
rename from src/gromacs/gmxpreprocess/calch.c
rename to src/gromacs/gmxpreprocess/calch.cpp
index d171bbd34b85d99be060f2b883fb38626a834ca6..3011953d87deedd911d607a01b8cd13ddab81792 100644 (file)
@@ -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 <cmath>
+
 #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;
index ea6211f4dcd663a503542f2f73599544db4646c1..31cdeecd6e8833ecb34f711a07c1f998158a361f 100644 (file)
@@ -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.
 
 #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
similarity index 98%
rename from src/gromacs/gmxpreprocess/convparm.c
rename to src/gromacs/gmxpreprocess/convparm.cpp
index 93f1603c8e9ea4c9253656b953d0c6485e94eb10..84fda2423458e715ce07e9e9c426f66f08c83fce 100644 (file)
 
 #include "convparm.h"
 
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
 #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<real>(-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<int>(old[0]);
+            newparam->cmap.cmapB = static_cast<int>(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;
index 0505967510d630582b2e8104ba25c8c507d4bceb..23f233cdbac205dc4bd4f496154036ead1dc25e3 100644 (file)
 #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
index 572235eee9b412c6b2d2ac92d2c816624fba4c55..1c0d6597c0d62a22e9ccc484683f218652126078 100644 (file)
 
 #include <stdio.h>
 
-#include "gromacs/utility/basedefinitions.h"
-
-#ifdef __cplusplus
 #include <vector>
 
+#include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/datafilefinder.h"
 
 /*! \brief
@@ -50,9 +48,6 @@
  */
 std::vector<gmx::DataFileInfo> 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
similarity index 97%
rename from src/gromacs/gmxpreprocess/gen_ad.c
rename to src/gromacs/gmxpreprocess/gen_ad.cpp
index 1b7a0b9c5e3f68f57527db29decb909ac2973afd..201c17e1b0d3c307df2eac201f7d6ebfd785df09 100644 (file)
 #include "gen_ad.h"
 
 #include <ctype.h>
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #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++)
                                     {
index e8814a5cabe8491f960b7b543bafe0dfa9ad9712..af4c037288d149279d5181d4548c56f76d74bd61 100644 (file)
@@ -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.
 #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
similarity index 96%
rename from src/gromacs/gmxpreprocess/gen_maxwell_velocities.c
rename to src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp
index 02522be85facfea72c534ecfbc500d2fcfff594e..3ba751f6b29ac1e9e3b800dd05c3ca6afb092506 100644 (file)
@@ -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 <math.h>
+#include <cmath>
 
 #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)
index 2679948ceddcb28c7d200d3345baf1ea8ba87fd9..b4f65cd3c39460b4ee6572693932360accb4651c 100644 (file)
@@ -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.
 
 #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
similarity index 97%
rename from src/gromacs/gmxpreprocess/gen_vsite.c
rename to src/gromacs/gmxpreprocess/gen_vsite.cpp
index 4d0e990044c17b47b9faf3c0d269383e98ceef72..5e21b9032c0f54ed0cead89483bc50177a0b5d46 100644 (file)
@@ -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.
 
 #include "gen_vsite.h"
 
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
 #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   */
index 6a350ef7093b373f8e8eded985adee4b06f76078..4ece47f91e2bd418cb843c5eeba04cbcf29c6156 100644 (file)
@@ -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.
 #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
index fa067de2d7571b2d72d0852dafc49f00afc568f5..e10b6139a860b74799fc9b590736ae837cf4e8e7 100644 (file)
@@ -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.
 #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
similarity index 99%
rename from src/gromacs/gmxpreprocess/genhydro.c
rename to src/gromacs/gmxpreprocess/genhydro.cpp
index 3a85fa12094f8a8201a5647d3174d605c1619db1..5708d3ec5624dc451fdb581740018f4e2455d74d 100644 (file)
@@ -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;
index 9161a33324d63b8786358f7ed2b5ca285818a0d5..1fd797cff15a8934ad6f916769d856d3c0b6d053 100644 (file)
@@ -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.
 #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
similarity index 98%
rename from src/gromacs/gmxpreprocess/gmxcpp.c
rename to src/gromacs/gmxpreprocess/gmxcpp.cpp
index 90ad4aabcfbb33a3cef904e6896f8effea707880..f538a72225f1bd479271a6b99e161babd2b31b7e 100644 (file)
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include <sys/types.h>
 
 #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)
index 035fdc56e9ac943c6a86c05ee1f156090ef01207..d0446f97533c965a0c05016851a0b25e47bee8ef 100644 (file)
 #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
similarity index 98%
rename from src/gromacs/gmxpreprocess/gpp_atomtype.c
rename to src/gromacs/gmxpreprocess/gpp_atomtype.cpp
index 4a9c932b0f93c8dd01f095bbc21acf0d006e4108..1387e21914c20b4c09678db505dd1be70861c09c 100644 (file)
@@ -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.
 
 #include "gpp_atomtype.h"
 
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
 #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;
index 9dd46548b3ae6fa8eece4e85583559e92ed09e62..19d345c650d80184509373e2b4b62ce3d83840c3 100644 (file)
@@ -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.
 #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
index c901d9b1f07484ab890e755a1ff22eb92cbb157c..6fc4635babec989e2836a7eabae2bc21be393ea6 100644 (file)
@@ -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.
 
 #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
similarity index 99%
rename from src/gromacs/gmxpreprocess/gpp_nextnb.c
rename to src/gromacs/gmxpreprocess/gpp_nextnb.cpp
index ac779b14bdb2489eb34c261b3a3bc26a23597475..a7425263b6f235f8a4fdf33040e88e90aecc15d4 100644 (file)
@@ -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);
index c5dde3865e4d3451ddf8a87fd2b98297d1ed38fc..93f35d634a230d7f7feb1371403ec46cbfeb60be 100644 (file)
@@ -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.
 
 #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
index 20cafb0cd77ffc9b0113af0205484c336860c641..8e268457c7a20e064989c5179f74d3f3e8efcd2c 100644 (file)
 
 #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
similarity index 97%
rename from src/gromacs/gmxpreprocess/grompp.c
rename to src/gromacs/gmxpreprocess/grompp.cpp
index 6be2102a68672de0baea594e1bafdbca928adcd2..304e68c20b450385650962f701dcd93262957fd9 100644 (file)
 
 #include "grompp.h"
 
-#include <assert.h>
 #include <errno.h>
 #include <limits.h>
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #include <sys/types.h>
 
 #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<int>((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
index 9dc5254a80f66a4b461b96f2ffe29a3e22f3614f..9e6bcba68690f4299fb674f585d0d28041fc7cea 100644 (file)
@@ -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.
 #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
similarity index 97%
rename from src/gromacs/gmxpreprocess/h_db.c
rename to src/gromacs/gmxpreprocess/h_db.cpp
index b63fdde27aea356c25cb2d89dfbbea668c91e017..7504972d5dd2707e55fdfed77f0a601b317e8bc1 100644 (file)
@@ -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.
index 24f873b6c2e3fb913b269d925e7c479f024c92a7..c8e2df6f044bdfe21e3e2a31225b150c80dd072c 100644 (file)
@@ -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.
 
 #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
index 294dcec86c486006856beeae573b874907c00fb9..bdeff0af49485179a0a4bd080570fa2bd6e41bd8 100644 (file)
@@ -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.
 #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
similarity index 97%
rename from src/gromacs/gmxpreprocess/hizzie.c
rename to src/gromacs/gmxpreprocess/hizzie.cpp
index 0aff84f7a41b04bac8fbf85c3ebeac82ef960f50..b2575850b3912fa1ec7f2a34cf118cbc960d2918 100644 (file)
@@ -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 <stdio.h>
 #include <string.h>
 
+#include <cmath>
+
 #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;
index 92c44f43b5d7fe954a59dc67a78b3cb8c4ae92b2..5bdcb8801c037e0941aedfac80383602b07da8d4 100644 (file)
@@ -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.
 #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
similarity index 98%
rename from src/gromacs/gmxpreprocess/nm2type.c
rename to src/gromacs/gmxpreprocess/nm2type.cpp
index 9f02a585bdf7220f9e3f355d5d9f1105696b612e..dba4da9f9c9c47300b43aa86ad3a288f0956a4f6 100644 (file)
@@ -41,6 +41,8 @@
 
 #include <string.h>
 
+#include <algorithm>
+
 #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)
     {
index 4f8505ed04bf7817835db8ab72f0a51da5bc164a..e86af8228d1382ea915687baf13d1be1f40a9479 100644 (file)
@@ -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.
 #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
similarity index 98%
rename from src/gromacs/gmxpreprocess/pdb2gmx.c
rename to src/gromacs/gmxpreprocess/pdb2gmx.cpp
index 242aaf65e08ec587661d8acc684dcaaccd5348cb..f025990f80936e4d56f9c1cec60140126cfd0a16 100644 (file)
@@ -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)
index d85c5bbae83c5d7bab54d8598dd8c24975678c15..b8da74c90b5bb2c69ab7cb1b04cf6def55e24e0e 100644 (file)
@@ -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.
 #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
index 49b7316358b22428befbfc097570f5610bdb3508..00529571beae6650627eda67db453ba6a6b291bd 100644 (file)
 #include "pdb2top.h"
 
 #include <ctype.h>
-#include <math.h>
 #include <stdio.h>
 #include <string.h>
 
+#include <cmath>
+
 #include <algorithm>
 #include <string>
 #include <vector>
@@ -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);
             }
index cfbc800c879048746709698f1a4deac9228f09b8..a5e468106c0c97e3998bcf4f2c69f81343421ee9 100644 (file)
@@ -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.
 #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
index b9ebce727a120ee843584bee155085d0c1b28a07..1c5b46d2ca1e02d9b3a00eb811adeafe51a6c8f8 100644 (file)
@@ -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.
 
 #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
index 5ced52b98b35a37a60d735ca4ca578b153fff953..7c9f6a27fd1d6045deb8ec8a2c4f175ba1473d55 100644 (file)
@@ -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.
 
 #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
similarity index 98%
rename from src/gromacs/gmxpreprocess/readadress.c
rename to src/gromacs/gmxpreprocess/readadress.cpp
index a95374cda85b3e7d873a8804f18ac396778b4570..16f75891ec2e18fb3695334753555e468f0be249 100644 (file)
@@ -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.
similarity index 98%
rename from src/gromacs/gmxpreprocess/readir.c
rename to src/gromacs/gmxpreprocess/readir.cpp
index 52f408f21d1a314edfeb62accce09a99b67a26ce..2bbed056ddded6898b6b3548f391014dbf5c4eda 100644 (file)
 #include <limits.h>
 #include <stdlib.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #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<real>((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
index ea76d63004759091f6689f6d17237759bceca28f..924681e895f8c3a94959ba6bbeb857577862a430 100644 (file)
 #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
similarity index 98%
rename from src/gromacs/gmxpreprocess/readpull.c
rename to src/gromacs/gmxpreprocess/readpull.cpp
index f2fb2d220309a6e6e44b9fa8d471b588f773cf1b..665c93586b18a848f2d9f2b3a544f47ca2d25483 100644 (file)
@@ -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;
similarity index 99%
rename from src/gromacs/gmxpreprocess/readrot.c
rename to src/gromacs/gmxpreprocess/readrot.cpp
index bd10df6e198993f69472abeb9bad5ef8f0873a2f..6968670a27e557690725cb15c82ea7a3c20837f7 100644 (file)
@@ -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];
similarity index 98%
rename from src/gromacs/gmxpreprocess/resall.c
rename to src/gromacs/gmxpreprocess/resall.cpp
index fe75e0cc652e8f65294e2c8aab6a8aa960047d47..208faddf996e387e8fd089bf364f85f3e81ecd4e 100644 (file)
@@ -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 <stdlib.h>
 #include <string.h>
 
+#include <algorithm>
+
 #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])) ||
index 487ed643e2a06febc6b4c69f5c069fffd7cd657f..463f982ef7e1114782bc824f100ad213a2d8a734 100644 (file)
@@ -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.
 #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
index 29552919bad4207ed6e2b8e5545bb39893a41a37..d7b17f6fbccdbfe3d7f016b8f7871cd3910be8a7 100644 (file)
@@ -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.
 #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
similarity index 99%
rename from src/gromacs/gmxpreprocess/sortwater.c
rename to src/gromacs/gmxpreprocess/sortwater.cpp
index 73c8b5472d8f7be3eb320460be9a0e554c8d7e96..1248f8d46a914d0c012bd69c65810a5c9adbad04 100644 (file)
@@ -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.
index fc9e704712cadbd20af5733a776972c7cf48e1a2..ebef2dfa375b974168d5ed03c479d603b9cd3959 100644 (file)
@@ -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.
 #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
similarity index 97%
rename from src/gromacs/gmxpreprocess/specbond.c
rename to src/gromacs/gmxpreprocess/specbond.cpp
index 2d1bfcf261425105a6b0effc306a7b22c4201cbf..700e216d4218f2875cb1d88bf05964ec238579f0 100644 (file)
@@ -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.
 #include "specbond.h"
 
 #include <ctype.h>
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #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]);
index 4c8eedc307b62365d1fbb221b286426aad2afa02..bcdd7bd9aaf5824c77d0bb5f735a9830a6cf2c34 100644 (file)
@@ -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.
 
 #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
similarity index 91%
rename from src/gromacs/gmxpreprocess/ter_db.c
rename to src/gromacs/gmxpreprocess/ter_db.cpp
index df0722c368326e6cb534e58b01efc89cfc981dfb..eca3a323f077bbd84f61da58b2bdd6e6aa2930d5 100644 (file)
@@ -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
     {
index 45477d620705a65421430521529d7b2258db012d..b861e42d58ecdac70562055af3443be908647d7a 100644 (file)
@@ -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
similarity index 98%
rename from src/gromacs/gmxpreprocess/tomorse.c
rename to src/gromacs/gmxpreprocess/tomorse.cpp
index cd9b793b5fb3b2bc75cd9c8b049cc73668da52cd..668c652cd895924168d734a5c8006fc6520a3c99 100644 (file)
@@ -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.
 #include "tomorse.h"
 
 #include <ctype.h>
-#include <math.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
 #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;
index 6a39ea6fd84200e000bbe34358be5c9bd477dcd8..cb098869de9d5f9c3384c83c2d20d7978ab50007 100644 (file)
@@ -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.
 #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
index fa62531eeb70025e794080eab2691cc009a00f9a..38a664a2d0f24f0b71fede126ada2c3238de7e19 100644 (file)
@@ -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.
 
 #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
similarity index 99%
rename from src/gromacs/gmxpreprocess/topio.c
rename to src/gromacs/gmxpreprocess/topio.cpp
index 3478619757bd2ebad0d0fff4b24e83ec76d3c44c..906823befc2f44b4b41976dd8760ba4f1aaad2f3 100644 (file)
 
 #include "topio.h"
 
-#include <assert.h>
 #include <ctype.h>
 #include <errno.h>
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include <cmath>
+
 #include <sys/types.h>
 
 #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<int>(std::sqrt(static_cast<double>(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)
             {
index 744f31202a342f7217c2e64c4bd34f8da7c5ead1..124503492ff4abb4c78728635b02bef3ca0bb7ac 100644 (file)
 #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
similarity index 97%
rename from src/gromacs/gmxpreprocess/toppush.c
rename to src/gromacs/gmxpreprocess/toppush.cpp
index 832a2a12037fdd70864944b4f56605199393e290..6fb5e3577c60f18a60d028ccb45cd3a9552470b7 100644 (file)
@@ -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.
 
 #include "toppush.h"
 
-#include <assert.h>
 #include <ctype.h>
-#include <math.h>
 #include <stdlib.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #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<int>(std::sqrt(static_cast<double>(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<int>(std::sqrt(static_cast<double>(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++)
     {
index 1e14c57bc72a8db85f7648838bb51aa85790be03..8ee48618dfd8a7b7e2df47c59ad92ff35c179ff5 100644 (file)
@@ -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.
 #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
similarity index 96%
rename from src/gromacs/gmxpreprocess/topshake.c
rename to src/gromacs/gmxpreprocess/topshake.cpp
index bd2662df2ad09d93914160f2a698f7c199a1dec8..466bcc843dd39c80394d614c03d177115a0633b2 100644 (file)
@@ -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 <ctype.h>
-#include <math.h>
+
+#include <cmath>
 
 #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);
index 15e09da6623937ebfd8ad444961a9ac9ab27c17f..f232d5620698eb7cfc526a19be37c029e69adbe4 100644 (file)
@@ -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.
 
 #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
similarity index 96%
rename from src/gromacs/gmxpreprocess/toputil.c
rename to src/gromacs/gmxpreprocess/toputil.cpp
index 4cbcc05525a137e9b96b058295075b1861246ff2..133773bea069801a11178aff2a467ceb135d4af9 100644 (file)
 
 #include "toputil.h"
 
-#include <assert.h>
-#include <math.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #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<int>(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,
index d7d040effe46e3035391c61b73f57dfa608f48ed..f25b3f4bf0448ed0b979ed575ce045aa157cf56f 100644 (file)
@@ -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.
 #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
similarity index 96%
rename from src/gromacs/gmxpreprocess/vsite_parm.c
rename to src/gromacs/gmxpreprocess/vsite_parm.cpp
index 12357de2b44b0a2174e343c470c3063b1a250f35..34bbded82f44cbb5a9ba5e5d7f50a997bfe4815a 100644 (file)
 
 #include "vsite_parm.h"
 
-#include <assert.h>
-#include <math.h>
 #include <stdio.h>
 #include <string.h>
 
+#include <cmath>
+
+#include <algorithm>
+
 #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)
             {
index 178ab9c0a4df8dd2809e33f3b78e8263400fd06c..2f87ef71afe07336f8d2c2a0f9b9587c971dd022 100644 (file)
 #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
similarity index 98%
rename from src/gromacs/gmxpreprocess/x2top.c
rename to src/gromacs/gmxpreprocess/x2top.cpp
index 1c4e0bdce97c89a368ffa9169c44ee27f6346938..48f090e60f029a677920d1f2fd8ab88edf928df4 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "x2top.h"
 
-#include <assert.h>
+#include <cmath>
 
 #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;
index 78de61acc7d978d32ae171693a1a9c1d94cc98db..99a5911dfc96a40be9f5544df442ec453e2ce1d7 100644 (file)
@@ -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.
 #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
similarity index 99%
rename from src/gromacs/gmxpreprocess/xlate.c
rename to src/gromacs/gmxpreprocess/xlate.cpp
index c4d2c7cfe23760334ded99be85c64094a3328b61..151eef2cbf41fb5aaf5d8b33b7663a35c3c1212a 100644 (file)
@@ -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.
index aa1c61006d4f2e50d1dc426f424e37c976fecbba..45c2a8fff358c0d866cd324307990f52492a8573 100644 (file)
@@ -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.
 #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
index d5ee22cbe1b3fead8a6a22449034d044fb1d47eb..17ef70662e5eb3ee4d100686e8e40d533fcd8161 100644 (file)
@@ -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)
     {