From: Berk Hess Date: Tue, 18 Sep 2018 21:23:04 +0000 (+0200) Subject: Convert gmx_ffparams_t to C++ X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=3a8cba140385e9fa7da661cf3746f94921c74b44;p=alexxy%2Fgromacs.git Convert gmx_ffparams_t to C++ Note that gmx_cmap_t still needs to be converted. Change-Id: Ib695962c08b7cba539a9604077cc372d795b1647 --- diff --git a/src/gromacs/domdec/domdec_topology.cpp b/src/gromacs/domdec/domdec_topology.cpp index 8c165dfbcd..02d7a1a3d1 100644 --- a/src/gromacs/domdec/domdec_topology.cpp +++ b/src/gromacs/domdec/domdec_topology.cpp @@ -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(top_global->ffparams.functype.data()); + top->idef.iparams = const_cast(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); } diff --git a/src/gromacs/fileio/tpxio.cpp b/src/gromacs/fileio/tpxio.cpp index 59ea8d0ec0..7bf82b10e4 100644 --- a/src/gromacs/fileio/tpxio.cpp +++ b/src/gromacs/fileio/tpxio.cpp @@ -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 ip = mtop->ffparams.iparams; iloop = gmx_mtop_ilistloop_init(mtop); while (const InteractionLists *ilist = gmx_mtop_ilistloop_next(iloop, &nmol)) diff --git a/src/gromacs/gmxpreprocess/convparm.cpp b/src/gromacs/gmxpreprocess/convparm.cpp index a5f3f05ccc..91fd43c7ee 100644 --- a/src/gromacs/gmxpreprocess/convparm.cpp +++ b/src/gromacs/gmxpreprocess/convparm.cpp @@ -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(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(F_LJ), comb, reppow, ffp, nullptr, - &maxtypes, TRUE, TRUE); + TRUE, TRUE); enter_function(&(nbtypes[F_BHAM]), static_cast(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(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(i), comb, reppow, ffp, &(*mtop->intermolecular_ilist)[i], - &maxtypes, FALSE, FALSE); + FALSE, FALSE); mtop->bIntermolecularInteractions = TRUE; } diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index 1088cd591b..c5028ebe15 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -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 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 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; diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 778ffce363..aff817aa61 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -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); diff --git a/src/gromacs/mdlib/broadcaststructs.cpp b/src/gromacs/mdlib/broadcaststructs.cpp index 460bce63f7..552cb6a7f6 100644 --- a/src/gromacs/mdlib/broadcaststructs.cpp +++ b/src/gromacs/mdlib/broadcaststructs.cpp @@ -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); diff --git a/src/gromacs/mdlib/constr.cpp b/src/gromacs/mdlib/constr.cpp index 223aabae9b..ca77a6ad27 100644 --- a/src/gromacs/mdlib/constr.cpp +++ b/src/gromacs/mdlib/constr.cpp @@ -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 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; } diff --git a/src/gromacs/mdlib/constr.h b/src/gromacs/mdlib/constr.h index f2f768dc7b..804f51bbdf 100644 --- a/src/gromacs/mdlib/constr.h +++ b/src/gromacs/mdlib/constr.h @@ -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 iparams, + FlexibleConstraintTreatment flexibleConstraintTreatment); /*! \brief Returns a block struct to go from atoms to constraints * diff --git a/src/gromacs/mdlib/constraintrange.cpp b/src/gromacs/mdlib/constraintrange.cpp index 7416f380e1..effc2bdae5 100644 --- a/src/gromacs/mdlib/constraintrange.cpp +++ b/src/gromacs/mdlib/constraintrange.cpp @@ -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 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 iparams, + const t_inputrec *ir) { int natoms, *path, at, count; diff --git a/src/gromacs/mdlib/perf_est.cpp b/src/gromacs/mdlib/perf_est.cpp index 4705fca790..5596dbc9e5 100644 --- a/src/gromacs/mdlib/perf_est.cpp +++ b/src/gromacs/mdlib/perf_est.cpp @@ -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 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 iparams = mtop->ffparams.iparams; atnr = mtop->ffparams.atnr; nqlj = 0; nq = 0; diff --git a/src/gromacs/mdlib/tests/settle.cpp b/src/gromacs/mdlib/tests/settle.cpp index dafed2cc8d..3f432d99e0 100644 --- a/src/gromacs/mdlib/tests/settle.cpp +++ b/src/gromacs/mdlib/tests/settle.cpp @@ -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; diff --git a/src/gromacs/mdlib/vsite.cpp b/src/gromacs/mdlib/vsite.cpp index 1f5f24578e..d5b4e07709 100644 --- a/src/gromacs/mdlib/vsite.cpp +++ b/src/gromacs/mdlib/vsite.cpp @@ -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); diff --git a/src/gromacs/topology/idef.cpp b/src/gromacs/topology/idef.cpp index 5739cacef0..072cabef53 100644 --- a/src/gromacs/topology/idef.cpp +++ b/src/gromacs/topology/idef.cpp @@ -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, ", diff --git a/src/gromacs/topology/idef.h b/src/gromacs/topology/idef.h index f82c54c2d7..3275274660 100644 --- a/src/gromacs/topology/idef.h +++ b/src/gromacs/topology/idef.h @@ -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 functype; /* The function type per type */ + std::vector 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 diff --git a/src/gromacs/topology/mtop_util.cpp b/src/gromacs/topology/mtop_util.cpp index 45f8ba94d7..c53de35bc2 100644 --- a/src/gromacs/topology/mtop_util.cpp +++ b/src/gromacs/topology/mtop_util.cpp @@ -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 { diff --git a/src/gromacs/topology/topology.cpp b/src/gromacs/topology/topology.cpp index 568dbee391..ad33c0a41b 100644 --- a/src/gromacs/topology/topology.cpp +++ b/src/gromacs/topology/topology.cpp @@ -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); diff --git a/src/gromacs/topology/topsort.cpp b/src/gromacs/topology/topsort.cpp index 40b8afcf63..669586f8c9 100644 --- a/src/gromacs/topology/topsort.cpp +++ b/src/gromacs/topology/topsort.cpp @@ -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++) {