Convert gmx_ffparams_t to C++
authorBerk Hess <hess@kth.se>
Tue, 18 Sep 2018 21:23:04 +0000 (23:23 +0200)
committerBerk Hess <hess@kth.se>
Wed, 19 Sep 2018 10:34:54 +0000 (12:34 +0200)
Note that gmx_cmap_t still needs to be converted.

Change-Id: Ib695962c08b7cba539a9604077cc372d795b1647

17 files changed:
src/gromacs/domdec/domdec_topology.cpp
src/gromacs/fileio/tpxio.cpp
src/gromacs/gmxpreprocess/convparm.cpp
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/mdlib/broadcaststructs.cpp
src/gromacs/mdlib/constr.cpp
src/gromacs/mdlib/constr.h
src/gromacs/mdlib/constraintrange.cpp
src/gromacs/mdlib/perf_est.cpp
src/gromacs/mdlib/tests/settle.cpp
src/gromacs/mdlib/vsite.cpp
src/gromacs/topology/idef.cpp
src/gromacs/topology/idef.h
src/gromacs/topology/mtop_util.cpp
src/gromacs/topology/topology.cpp
src/gromacs/topology/topsort.cpp

index 8c165dfbcd581878171384992a3247155e9e350d..02d7a1a3d142094c90dc66707a964984b5a894c2 100644 (file)
@@ -2175,10 +2175,11 @@ gmx_localtop_t *dd_init_local_top(const gmx_mtop_t *top_global)
 
     snew(top, 1);
 
-    top->idef.ntypes    = top_global->ffparams.ntypes;
+    /* TODO: Get rid of the const casts below, e.g. by using a reference */
+    top->idef.ntypes    = top_global->ffparams.numTypes();
     top->idef.atnr      = top_global->ffparams.atnr;
-    top->idef.functype  = top_global->ffparams.functype;
-    top->idef.iparams   = top_global->ffparams.iparams;
+    top->idef.functype  = const_cast<t_functype *>(top_global->ffparams.functype.data());
+    top->idef.iparams   = const_cast<t_iparams *>(top_global->ffparams.iparams.data());
     top->idef.fudgeQQ   = top_global->ffparams.fudgeQQ;
     top->idef.cmap_grid = top_global->ffparams.cmap_grid;
 
@@ -2618,7 +2619,7 @@ static void get_cgcm_mol(const gmx_moltype_t *molt,
         }
 
         construct_vsites(nullptr, xs, 0.0, nullptr,
-                         ffparams->iparams, ilist,
+                         ffparams->iparams.data(), ilist,
                          epbcNONE, TRUE, nullptr, nullptr);
     }
 
index 59ea8d0ec0ba0d35d6e88ac8fef298c05d6fd26f..7bf82b10e4660a4562339e0ba9bca2488df41bfd 100644 (file)
@@ -1979,14 +1979,15 @@ static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
                         gmx_bool bRead, int file_version)
 {
     gmx_fio_do_int(fio, ffparams->atnr);
-    gmx_fio_do_int(fio, ffparams->ntypes);
+    int numTypes = ffparams->numTypes();
+    gmx_fio_do_int(fio, numTypes);
     if (bRead)
     {
-        snew(ffparams->functype, ffparams->ntypes);
-        snew(ffparams->iparams, ffparams->ntypes);
+        ffparams->functype.resize(numTypes);
+        ffparams->iparams.resize(numTypes);
     }
     /* Read/write all the function types */
-    gmx_fio_ndo_int(fio, ffparams->functype, ffparams->ntypes);
+    gmx_fio_ndo_int(fio, ffparams->functype.data(), ffparams->functype.size());
 
     if (file_version >= 66)
     {
@@ -2003,7 +2004,7 @@ static void do_ffparams(t_fileio *fio, gmx_ffparams_t *ffparams,
      * In practice the code is backwards compatible, which means that the
      * numbering may have to be altered from old numbering to new numbering
      */
-    for (int i = 0; i < ffparams->ntypes; i++)
+    for (int i = 0; i < ffparams->numTypes(); i++)
     {
         if (bRead)
         {
@@ -2455,11 +2456,10 @@ static void do_molblock(t_fileio *fio, gmx_molblock_t *molb,
 
 static void set_disres_npair(gmx_mtop_t *mtop)
 {
-    t_iparams             *ip;
-    gmx_mtop_ilistloop_t   iloop;
-    int                    nmol;
+    gmx_mtop_ilistloop_t     iloop;
+    int                      nmol;
 
-    ip = mtop->ffparams.iparams;
+    gmx::ArrayRef<t_iparams> ip = mtop->ffparams.iparams;
 
     iloop     = gmx_mtop_ilistloop_init(mtop);
     while (const InteractionLists *ilist = gmx_mtop_ilistloop_next(iloop, &nmol))
index a5f3f05ccc035a20259e08388cf4d9ebb0f19a93..91fd43c7ee732774b3c8d7985ad5e47b1b797e5b 100644 (file)
@@ -460,7 +460,7 @@ static int enter_params(gmx_ffparams_t *ffparams, t_functype ftype,
 
     if (!bAppend)
     {
-        for (type = start; (type < ffparams->ntypes); type++)
+        for (type = start; (type < ffparams->numTypes()); type++)
         {
             if (ffparams->functype[type] == ftype)
             {
@@ -473,12 +473,14 @@ static int enter_params(gmx_ffparams_t *ffparams, t_functype ftype,
     }
     else
     {
-        type = ffparams->ntypes;
+        type = ffparams->numTypes();
     }
-    memcpy(&ffparams->iparams[type], &newparam, static_cast<size_t>(sizeof(newparam)));
 
-    ffparams->ntypes++;
-    ffparams->functype[type] = ftype;
+    ffparams->iparams.push_back(newparam);
+    ffparams->functype.push_back(ftype);
+
+    GMX_ASSERT(ffparams->iparams.size() == ffparams->functype.size(),
+               "sizes should match");
 
     return type;
 }
@@ -495,22 +497,15 @@ static void append_interaction(InteractionList *ilist,
 
 static void enter_function(t_params *p, t_functype ftype, int comb, real reppow,
                            gmx_ffparams_t *ffparams, InteractionList *il,
-                           int *maxtypes,
                            bool bNB, bool bAppend)
 {
     int     k, type, nr, nral, start;
 
-    start = ffparams->ntypes;
+    start = ffparams->numTypes();
     nr    = p->nr;
 
     for (k = 0; k < nr; k++)
     {
-        if (*maxtypes <= ffparams->ntypes)
-        {
-            *maxtypes += 1000;
-            srenew(ffparams->functype, *maxtypes);
-            srenew(ffparams->iparams, *maxtypes);
-        }
         type = enter_params(ffparams, ftype, p->param[k].c, comb, reppow, start, bAppend);
         /* Type==-1 is used as a signal that this interaction is all-zero and should not be added. */
         if (!bNB && type >= 0)
@@ -527,25 +522,22 @@ void convert_params(int atnr, t_params nbtypes[],
                     int comb, double reppow, real fudgeQQ,
                     gmx_mtop_t *mtop)
 {
-    int             i, maxtypes;
+    int             i;
     unsigned long   flags;
     gmx_ffparams_t *ffp;
     gmx_moltype_t  *molt;
     t_params       *plist;
 
-    maxtypes = 0;
-
     ffp           = &mtop->ffparams;
-    ffp->ntypes   = 0;
     ffp->atnr     = atnr;
-    ffp->functype = nullptr;
-    ffp->iparams  = nullptr;
+    ffp->functype.clear();
+    ffp->iparams.clear();
     ffp->reppow   = reppow;
 
     enter_function(&(nbtypes[F_LJ]),  static_cast<t_functype>(F_LJ),    comb, reppow, ffp, nullptr,
-                   &maxtypes, TRUE, TRUE);
+                   TRUE, TRUE);
     enter_function(&(nbtypes[F_BHAM]), static_cast<t_functype>(F_BHAM),  comb, reppow, ffp, nullptr,
-                   &maxtypes, TRUE, TRUE);
+                   TRUE, TRUE);
 
     for (size_t mt = 0; mt < mtop->moltype.size(); mt++)
     {
@@ -563,7 +555,7 @@ void convert_params(int atnr, t_params nbtypes[],
             {
                 enter_function(&(plist[i]), static_cast<t_functype>(i), comb, reppow,
                                ffp, &molt->ilist[i],
-                               &maxtypes, FALSE, (i == F_POSRES  || i == F_FBPOSRES));
+                               FALSE, (i == F_POSRES  || i == F_FBPOSRES));
             }
         }
     }
@@ -604,7 +596,7 @@ void convert_params(int atnr, t_params nbtypes[],
                 {
                     enter_function(&(plist[i]), static_cast<t_functype>(i), comb, reppow,
                                    ffp, &(*mtop->intermolecular_ilist)[i],
-                                   &maxtypes, FALSE, FALSE);
+                                   FALSE, FALSE);
 
                     mtop->bIntermolecularInteractions = TRUE;
                 }
index 1088cd591b90b60aa57fa0726200ef1d457d11fa..c5028ebe15f623e18dc76cc0ad0819521bbf1e19 100644 (file)
@@ -245,14 +245,14 @@ static void check_bonds_timestep(const gmx_mtop_t *mtop, double dt, warninp_t wi
      */
     int            min_steps_warn = 5;
     int            min_steps_note = 10;
-    t_iparams     *ip;
     int            ftype;
     int            i, a1, a2, w_a1, w_a2, j;
     real           twopi2, limit2, fc, re, m1, m2, period2, w_period2;
     bool           bFound, bWater, bWarn;
     char           warn_buf[STRLEN];
 
-    ip = mtop->ffparams.iparams;
+    /* Get the interaction parameters */
+    gmx::ArrayRef<const t_iparams> ip = mtop->ffparams.iparams;
 
     twopi2 = gmx::square(2*M_PI);
 
@@ -1373,20 +1373,20 @@ static void checkForUnboundAtoms(const gmx_mtop_t     *mtop,
  * involved in a single constraint; the mass of the two atoms needs to
  * differ by more than \p massFactorThreshold.
  */
-static bool haveDecoupledModeInMol(const gmx_moltype_t *molt,
-                                   const t_iparams     *iparams,
-                                   real                 massFactorThreshold)
+static bool haveDecoupledModeInMol(const gmx_moltype_t            &molt,
+                                   gmx::ArrayRef<const t_iparams>  iparams,
+                                   real                            massFactorThreshold)
 {
-    if (molt->ilist[F_CONSTR].size() == 0 &&
-        molt->ilist[F_CONSTRNC].size() == 0)
+    if (molt.ilist[F_CONSTR].size() == 0 &&
+        molt.ilist[F_CONSTRNC].size() == 0)
     {
         return false;
     }
 
-    const t_atom * atom = molt->atoms.atom;
+    const t_atom * atom = molt.atoms.atom;
 
     t_blocka       atomToConstraints =
-        gmx::make_at2con(*molt, iparams,
+        gmx::make_at2con(molt, iparams,
                          gmx::FlexibleConstraintTreatment::Exclude);
 
     bool           haveDecoupledMode = false;
@@ -1395,7 +1395,7 @@ static bool haveDecoupledModeInMol(const gmx_moltype_t *molt,
         if (interaction_function[ftype].flags & IF_ATYPE)
         {
             const int              nral = NRAL(ftype);
-            const InteractionList &il   = molt->ilist[ftype];
+            const InteractionList &il   = molt.ilist[ftype];
             for (int i = 0; i < il.size(); i += 1 + nral)
             {
                 /* Here we check for the mass difference between the atoms
@@ -1501,7 +1501,7 @@ static void checkDecoupledModeAccuracy(const gmx_mtop_t *mtop,
     bool haveDecoupledMode = false;
     for (const gmx_moltype_t &molt : mtop->moltype)
     {
-        if (haveDecoupledModeInMol(&molt, mtop->ffparams.iparams,
+        if (haveDecoupledModeInMol(molt, mtop->ffparams.iparams,
                                    massFactorThreshold))
         {
             haveDecoupledMode = true;
index 778ffce363294b1cdcf013917d13fdc7158b2217..aff817aa61b7141e0152d9d807220ceeecb8ab20 100644 (file)
@@ -3676,27 +3676,19 @@ void do_index(const char* mdparin, const char *ndx,
 
 
 
-static void check_disre(gmx_mtop_t *mtop)
+static void check_disre(const gmx_mtop_t *mtop)
 {
-    gmx_ffparams_t *ffparams;
-    t_functype     *functype;
-    t_iparams      *ip;
-    int             i, ndouble, ftype;
-    int             label, old_label;
-
     if (gmx_mtop_ftype_count(mtop, F_DISRES) > 0)
     {
-        ffparams  = &mtop->ffparams;
-        functype  = ffparams->functype;
-        ip        = ffparams->iparams;
-        ndouble   = 0;
-        old_label = -1;
-        for (i = 0; i < ffparams->ntypes; i++)
+        const gmx_ffparams_t &ffparams  = mtop->ffparams;
+        int                   ndouble   = 0;
+        int                   old_label = -1;
+        for (int i = 0; i < ffparams.numTypes(); i++)
         {
-            ftype = functype[i];
+            int ftype = ffparams.functype[i];
             if (ftype == F_DISRES)
             {
-                label = ip[i].disres.label;
+                int label = ffparams.iparams[i].disres.label;
                 if (label == old_label)
                 {
                     fprintf(stderr, "Distance restraint index %d occurs twice\n", label);
index 460bce63f718cca1f6b5560e4522ee57e975d7d6..552cb6a7f6dc469475273ee13cae56ee8729df4e 100644 (file)
@@ -379,12 +379,11 @@ static void bc_cmap(const t_commrec *cr, gmx_cmap_t *cmap_grid)
 
 static void bc_ffparams(const t_commrec *cr, gmx_ffparams_t *ffp)
 {
-    block_bc(cr, ffp->ntypes);
+    int numTypes = ffp->numTypes();
+    block_bc(cr, numTypes);
     block_bc(cr, ffp->atnr);
-    snew_bc(cr, ffp->functype, ffp->ntypes);
-    snew_bc(cr, ffp->iparams, ffp->ntypes);
-    nblock_bc(cr, ffp->ntypes, ffp->functype);
-    nblock_bc(cr, ffp->ntypes, ffp->iparams);
+    nblock_abc(cr, numTypes, &ffp->functype);
+    nblock_abc(cr, numTypes, &ffp->iparams);
     block_bc(cr, ffp->reppow);
     block_bc(cr, ffp->fudgeQQ);
     bc_cmap(cr, &ffp->cmap_grid);
index 223aabae9b2854d1c05bcd1fa99eb17eb2d66400..ca77a6ad273fa1f70b3a6b265bbb0f24d32122ae 100644 (file)
@@ -828,11 +828,11 @@ t_blocka make_at2con(int                          numAtoms,
     return makeAtomsToConstraintsList(numAtoms, ilist, iparams, flexibleConstraintTreatment);
 }
 
-t_blocka make_at2con(const gmx_moltype_t         &moltype,
-                     const t_iparams             *iparams,
-                     FlexibleConstraintTreatment  flexibleConstraintTreatment)
+t_blocka make_at2con(const gmx_moltype_t            &moltype,
+                     gmx::ArrayRef<const t_iparams>  iparams,
+                     FlexibleConstraintTreatment     flexibleConstraintTreatment)
 {
-    return makeAtomsToConstraintsList(moltype.atoms.nr, moltype.ilist.data(), iparams, flexibleConstraintTreatment);
+    return makeAtomsToConstraintsList(moltype.atoms.nr, moltype.ilist.data(), iparams.data(), flexibleConstraintTreatment);
 }
 
 //! Return the number of flexible constraints in the \c ilist and \c iparams.
@@ -1015,7 +1015,7 @@ Constraints::Impl::Impl(const gmx_mtop_t     &mtop_p,
         {
             int count =
                 countFlexibleConstraintsTemplate(mtop.moltype[molblock.type].ilist.data(),
-                                                 mtop.ffparams.iparams);
+                                                 mtop.ffparams.iparams.data());
             nflexcon += molblock.nmol*count;
         }
 
index f2f768dc7b3747f38c744a25f100df6d363095b3..804f51bbdf24e3a9dbcaae4486356d8d44b503bc 100644 (file)
@@ -235,9 +235,9 @@ flexibleConstraintTreatment(bool haveDynamicsIntegrator);
  * \param[in]  flexibleConstraintTreatment  The flexible constraint treatment, see enum above
  * \returns a block struct with all constraints for each atom
  */
-t_blocka make_at2con(const gmx_moltype_t         &moltype,
-                     const t_iparams             *iparams,
-                     FlexibleConstraintTreatment  flexibleConstraintTreatment);
+t_blocka make_at2con(const gmx_moltype_t            &moltype,
+                     gmx::ArrayRef<const t_iparams>  iparams,
+                     FlexibleConstraintTreatment     flexibleConstraintTreatment);
 
 /*! \brief Returns a block struct to go from atoms to constraints
  *
index 7416f380e118c90b5e99bc34d88deaae3cfd6693..effc2bdae5951ab8ff5d5748e2dabfe5bdd85cd0 100644 (file)
@@ -58,7 +58,8 @@ namespace gmx
 
 //! Recursing function to help find all adjacent constraints.
 static void constr_recur(const t_blocka *at2con,
-                         const InteractionLists &ilist, const t_iparams *iparams,
+                         const InteractionLists &ilist,
+                         gmx::ArrayRef<const t_iparams> iparams,
                          gmx_bool bTopB,
                          int at, int depth, int nc, int *path,
                          real r0, real r1, real *r2max,
@@ -150,9 +151,9 @@ static void constr_recur(const t_blocka *at2con,
 }
 
 //! Find the interaction radius needed for constraints for this molecule type.
-static real constr_r_max_moltype(const gmx_moltype_t *molt,
-                                 const t_iparams     *iparams,
-                                 const t_inputrec    *ir)
+static real constr_r_max_moltype(const gmx_moltype_t            *molt,
+                                 gmx::ArrayRef<const t_iparams>  iparams,
+                                 const t_inputrec               *ir)
 {
     int      natoms, *path, at, count;
 
index 4705fca79012177e714abec4071be2abc0dca29a..5596dbc9e591f8f09dbd8dd1513a0e698ab86f91 100644 (file)
@@ -282,7 +282,6 @@ static void pp_group_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
     gmx_bool       bBHAM, bLJcut, bWater, bQ, bLJ;
     int            nw, nqlj, nq, nlj;
     double         fq, fqlj, flj, fqljw, fqw;
-    t_iparams     *iparams;
 
     bBHAM = (mtop->ffparams.functype[0] == F_BHAM);
 
@@ -302,7 +301,7 @@ static void pp_group_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
     /* Cost of 1 water with one Q atom or with 1/3 water (LJ negligible) */
     fqw   = c_group_qw;
 
-    iparams           = mtop->ffparams.iparams;
+    gmx::ArrayRef<const t_iparams> iparams = mtop->ffparams.iparams;
     atnr              = mtop->ffparams.atnr;
     nw                = 0;
     nqlj              = 0;
@@ -404,7 +403,6 @@ static void pp_verlet_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
 {
     int            atnr, a, nqlj, nq, nlj;
     gmx_bool       bQRF;
-    t_iparams     *iparams;
     real           r_eff;
     double         c_qlj, c_q, c_lj;
     double         nppa;
@@ -420,7 +418,7 @@ static void pp_verlet_load(const gmx_mtop_t *mtop, const t_inputrec *ir,
 
     bQRF = (EEL_RF(ir->coulombtype) || ir->coulombtype == eelCUT);
 
-    iparams           = mtop->ffparams.iparams;
+    gmx::ArrayRef<const t_iparams> iparams = mtop->ffparams.iparams;
     atnr              = mtop->ffparams.atnr;
     nqlj              = 0;
     nq                = 0;
index dafed2cc8df93bf826436f1083f636c93d2daa05..3f432d99e0ba8e09e92ca77b2df24d0c52dfd3cd 100644 (file)
@@ -210,12 +210,12 @@ TEST_P(SettleTest, SatisfiesConstraints)
     }
 
     // Set up the SETTLE parameters.
-    mtop.ffparams.ntypes = 1;
-    snew(mtop.ffparams.iparams, mtop.ffparams.ntypes);
-    const real                   dOH = 0.09572;
-    const real                   dHH = 0.15139;
-    mtop.ffparams.iparams[settleType].settle.doh = dOH;
-    mtop.ffparams.iparams[settleType].settle.dhh = dHH;
+    const real     dOH = 0.09572;
+    const real     dHH = 0.15139;
+    t_iparams      iparams;
+    iparams.settle.doh = dOH;
+    iparams.settle.dhh = dHH;
+    mtop.ffparams.iparams.push_back(iparams);
 
     // Set up the masses.
     t_mdatoms         mdatoms;
index 1f5f24578e0898f8cb53968c22ac88818322d7df..d5b4e0770922a69300c79a430fbe62659be78b6d 100644 (file)
@@ -779,7 +779,7 @@ void constructVsitesGlobal(const gmx_mtop_t         &mtop,
 
                 construct_vsites(nullptr, as_rvec_array(x.data()) + atomOffset,
                                  0.0, nullptr,
-                                 mtop.ffparams.iparams, ilist,
+                                 mtop.ffparams.iparams.data(), ilist,
                                  epbcNONE, TRUE, nullptr, nullptr);
                 atomOffset += molt.atoms.nr;
             }
@@ -2062,7 +2062,7 @@ initVsite(const gmx_mtop_t &mtop,
         for (size_t mt = 0; mt < mtop.moltype.size(); mt++)
         {
             const gmx_moltype_t &molt = mtop.moltype[mt];
-            vsite->vsite_pbc_molt[mt] = get_vsite_pbc(mtop.ffparams.iparams,
+            vsite->vsite_pbc_molt[mt] = get_vsite_pbc(mtop.ffparams.iparams.data(),
                                                       molt.ilist.data(),
                                                       molt.atoms.atom, nullptr,
                                                       molt.cgs);
index 5739cacef04a902c24d2bd984f6823edf3e0ad79..072cabef5324eddaa73980366ab1571731f35a69 100644 (file)
@@ -407,8 +407,8 @@ void pr_ffparams(FILE *fp, int indent, const char *title,
     pr_indent(fp, indent);
     fprintf(fp, "atnr=%d\n", ffparams->atnr);
     pr_indent(fp, indent);
-    fprintf(fp, "ntypes=%d\n", ffparams->ntypes);
-    for (i = 0; i < ffparams->ntypes; i++)
+    fprintf(fp, "ntypes=%d\n", ffparams->numTypes());
+    for (i = 0; i < ffparams->numTypes(); i++)
     {
         pr_indent(fp, indent+INDENT);
         fprintf(fp, "functype[%d]=%s, ",
index f82c54c2d719d017914da2fa0ee11797df695385..32752746600eccfb6adff8db715264bf40a9ceec 100644 (file)
@@ -45,6 +45,7 @@
 #include "gromacs/math/vectypes.h"
 #include "gromacs/topology/ifunc.h"
 #include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/gmxassert.h"
 #include "gromacs/utility/real.h"
 
 typedef union t_iparams
@@ -284,16 +285,27 @@ typedef struct gmx_cmap_t
 } gmx_cmap_t;
 
 
-typedef struct gmx_ffparams_t
+/* Struct that holds all force field parameters for the simulated system */
+struct gmx_ffparams_t
 {
-    int         ntypes;
-    int         atnr;
-    t_functype *functype;
-    t_iparams  *iparams;
-    double      reppow;    /* The repulsion power for VdW: C12*r^-reppow   */
-    real        fudgeQQ;   /* The scaling factor for Coulomb 1-4: f*q1*q2  */
-    gmx_cmap_t  cmap_grid; /* The dihedral correction maps                 */
-} gmx_ffparams_t;
+    /* Returns the number of function types, which matches the number of elements in iparams */
+    int numTypes() const
+    {
+        GMX_ASSERT(iparams.size() == functype.size(), "Parameters and function types go together");
+
+        return functype.size();
+    }
+
+    /* TODO: Consider merging functype and iparams, either by storing
+     *       the functype in t_iparams or by putting both in a single class.
+     */
+    int                     atnr;      /* The number of non-bonded atom types */
+    std::vector<t_functype> functype;  /* The function type per type */
+    std::vector<t_iparams>  iparams;   /* Force field parameters per type */
+    double                  reppow;    /* The repulsion power for VdW: C12*r^-reppow   */
+    real                    fudgeQQ;   /* The scaling factor for Coulomb 1-4: f*q1*q2  */
+    gmx_cmap_t              cmap_grid; /* The dihedral correction maps                 */
+};
 
 enum {
     ilsortUNKNOWN, ilsortNO_FE, ilsortFE_UNSORTED, ilsortFE_SORTED
index 45f8ba94d711533dfdde624550e21e6b4a868fb0..c53de35bc2d56fce5786db10eae81009ab0da816 100644 (file)
@@ -871,26 +871,26 @@ static void gen_local_top(const gmx_mtop_t *mtop,
     ffp = &mtop->ffparams;
 
     idef                          = &top->idef;
-    idef->ntypes                  = ffp->ntypes;
+    idef->ntypes                  = ffp->numTypes();
     idef->atnr                    = ffp->atnr;
     /* we can no longer copy the pointers to the mtop members,
      * because they will become invalid as soon as mtop gets free'd.
      * We also need to make sure to only operate on valid data!
      */
 
-    if (ffp->functype)
+    if (!ffp->functype.empty())
     {
-        snew(idef->functype, ffp->ntypes);
-        std::copy(ffp->functype, ffp->functype + ffp->ntypes, idef->functype);
+        snew(idef->functype, ffp->functype.size());
+        std::copy(ffp->functype.data(), ffp->functype.data() + ffp->functype.size(), idef->functype);
     }
     else
     {
         idef->functype = nullptr;
     }
-    if (ffp->iparams)
+    if (!ffp->iparams.empty())
     {
-        snew(idef->iparams, ffp->ntypes);
-        std::copy(ffp->iparams, ffp->iparams + ffp->ntypes, idef->iparams);
+        snew(idef->iparams, ffp->iparams.size());
+        std::copy(ffp->iparams.data(), ffp->iparams.data() + ffp->iparams.size(), idef->iparams);
     }
     else
     {
index 568dbee391cad1f6c2e703dfcca4fd259a1a662b..ad33c0a41b55a1ac817694367b3e2243338d9faa 100644 (file)
@@ -77,12 +77,11 @@ void init_mtop(gmx_mtop_t *mtop)
     mtop->name = nullptr;
 
     // TODO: Move to ffparams when that is converted to C++
-    mtop->ffparams.functype               = nullptr;
-    mtop->ffparams.iparams                = nullptr;
+    mtop->ffparams.functype.clear();
+    mtop->ffparams.iparams.clear();
     mtop->ffparams.cmap_grid.ngrid        = 0;
     mtop->ffparams.cmap_grid.grid_spacing = 0;
     mtop->ffparams.cmap_grid.cmapdata     = nullptr;
-    mtop->ffparams.ntypes                 = 0;
 
     mtop->moltype.clear();
     mtop->molblock.clear();
@@ -155,8 +154,6 @@ gmx_mtop_t::~gmx_mtop_t()
 {
     done_symtab(&symtab);
 
-    sfree(ffparams.functype);
-    sfree(ffparams.iparams);
     for (int i = 0; i < ffparams.cmap_grid.ngrid; i++)
     {
         sfree(ffparams.cmap_grid.cmapdata[i].cmap);
@@ -368,8 +365,8 @@ static void pr_moltype(FILE *fp, int indent, const char *title,
     for (j = 0; (j < F_NRE); j++)
     {
         pr_ilist(fp, indent, interaction_function[j].longname,
-                 ffparams->functype, molt->ilist[j],
-                 bShowNumbers, bShowParameters, ffparams->iparams);
+                 ffparams->functype.data(), molt->ilist[j],
+                 bShowNumbers, bShowParameters, ffparams->iparams.data());
     }
 }
 
@@ -415,9 +412,9 @@ void pr_mtop(FILE *fp, int indent, const char *title, const gmx_mtop_t *mtop,
             for (int j = 0; j < F_NRE; j++)
             {
                 pr_ilist(fp, indent, interaction_function[j].longname,
-                         mtop->ffparams.functype,
+                         mtop->ffparams.functype.data(),
                          (*mtop->intermolecular_ilist)[j],
-                         bShowNumbers, bShowParameters, mtop->ffparams.iparams);
+                         bShowNumbers, bShowParameters, mtop->ffparams.iparams.data());
             }
         }
         pr_ffparams(fp, indent, "ffparams", &(mtop->ffparams), bShowNumbers);
index 40b8afcf63c276792f15f363968e37db4b83859b..669586f8c92625e73970bff052a9fe2d418326a0 100644 (file)
@@ -160,7 +160,7 @@ gmx_bool gmx_mtop_bondeds_free_energy(const gmx_mtop_t *mtop)
 
     /* Loop over all the function types and compare the A/B parameters */
     gmx_bool bPert = FALSE;
-    for (int i = 0; i < ffparams->ntypes; i++)
+    for (int i = 0; i < ffparams->numTypes(); i++)
     {
         int ftype = ffparams->functype[i];
         if (interaction_function[ftype].flags & IF_BOND)
@@ -194,7 +194,6 @@ gmx_bool gmx_mtop_bondeds_free_energy(const gmx_mtop_t *mtop)
 void gmx_sort_ilist_fe(t_idef *idef, const real *qA, const real *qB)
 {
     int        ftype, nral, i, ic, ib, a;
-    t_iparams *iparams;
     t_ilist   *ilist;
     t_iatom   *iatoms;
     t_iatom   *iabuf;
@@ -208,7 +207,7 @@ void gmx_sort_ilist_fe(t_idef *idef, const real *qA, const real *qB)
     iabuf_nalloc = 0;
     iabuf        = nullptr;
 
-    iparams = idef->iparams;
+    const t_iparams *iparams = idef->iparams;
 
     for (ftype = 0; ftype < F_NRE; ftype++)
     {