From: Paul Bauer Date: Wed, 20 Feb 2019 15:25:05 +0000 (+0100) Subject: Refactor t_params to InteractionTypeParameters X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=54d6977d4cac248ab7ac98f7665e04ab50451466;p=alexxy%2Fgromacs.git Refactor t_params to InteractionTypeParameters Part of preprocessing clean up. Refs #2833 Change-Id: I4514edde34c978c2756f1c17471e0adde0736896 --- diff --git a/src/gromacs/gmxpreprocess/add_par.cpp b/src/gromacs/gmxpreprocess/add_par.cpp index 8117146105..a3b8283c65 100644 --- a/src/gromacs/gmxpreprocess/add_par.cpp +++ b/src/gromacs/gmxpreprocess/add_par.cpp @@ -72,7 +72,7 @@ static void clear_force_param(int i0, real c[]) } } -void add_param(t_params *ps, int ai, int aj, const real *c, const char *s) +void add_param(InteractionTypeParameters *ps, int ai, int aj, const real *c, const char *s) { int i; @@ -99,7 +99,7 @@ void add_param(t_params *ps, int ai, int aj, const real *c, const char *s) ps->nr++; } -void add_imp_param(t_params *ps, int ai, int aj, int ak, int al, real c0, real c1, +void add_imp_param(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, real c0, real c1, const char *s) { pr_alloc(1, ps); @@ -115,7 +115,7 @@ void add_imp_param(t_params *ps, int ai, int aj, int ak, int al, real c0, real c ps->nr++; } -void add_dih_param(t_params *ps, int ai, int aj, int ak, int al, real c0, real c1, +void add_dih_param(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, real c0, real c1, real c2, const char *s) { pr_alloc(1, ps); @@ -132,7 +132,7 @@ void add_dih_param(t_params *ps, int ai, int aj, int ak, int al, real c0, real c ps->nr++; } -void add_cmap_param(t_params *ps, int ai, int aj, int ak, int al, int am, const char *s) +void add_cmap_param(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, int am, const char *s) { pr_alloc(1, ps); ps->param[ps->nr].ai() = ai; @@ -146,7 +146,7 @@ void add_cmap_param(t_params *ps, int ai, int aj, int ak, int al, int am, const ps->nr++; } -void add_vsite2_atoms(t_params *ps, int ai, int aj, int ak) +void add_vsite2_atoms(InteractionTypeParameters *ps, int ai, int aj, int ak) { pr_alloc(1, ps); ps->param[ps->nr].ai() = ai; @@ -158,7 +158,7 @@ void add_vsite2_atoms(t_params *ps, int ai, int aj, int ak) ps->nr++; } -void add_vsite2_param(t_params *ps, int ai, int aj, int ak, real c0) +void add_vsite2_param(InteractionTypeParameters *ps, int ai, int aj, int ak, real c0) { pr_alloc(1, ps); ps->param[ps->nr].ai() = ai; @@ -171,7 +171,7 @@ void add_vsite2_param(t_params *ps, int ai, int aj, int ak, real c0) ps->nr++; } -void add_vsite3_param(t_params *ps, int ai, int aj, int ak, int al, +void add_vsite3_param(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, real c0, real c1) { pr_alloc(1, ps); @@ -187,7 +187,7 @@ void add_vsite3_param(t_params *ps, int ai, int aj, int ak, int al, ps->nr++; } -void add_vsite3_atoms(t_params *ps, int ai, int aj, int ak, int al, bool bSwapParity) +void add_vsite3_atoms(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, bool bSwapParity) { pr_alloc(1, ps); ps->param[ps->nr].ai() = ai; @@ -204,7 +204,7 @@ void add_vsite3_atoms(t_params *ps, int ai, int aj, int ak, int al, bool bSwapPa ps->nr++; } -void add_vsite4_atoms(t_params *ps, int ai, int aj, int ak, int al, int am) +void add_vsite4_atoms(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, int am) { pr_alloc(1, ps); ps->param[ps->nr].ai() = ai; diff --git a/src/gromacs/gmxpreprocess/add_par.h b/src/gromacs/gmxpreprocess/add_par.h index 999e122238..de35358e4b 100644 --- a/src/gromacs/gmxpreprocess/add_par.h +++ b/src/gromacs/gmxpreprocess/add_par.h @@ -40,31 +40,31 @@ #include "gromacs/utility/real.h" -struct t_params; +struct InteractionTypeParameters; struct PreprocessResidue; -void add_param(t_params *ps, int ai, int aj, const real *c, const char *s); +void add_param(InteractionTypeParameters *ps, int ai, int aj, const real *c, const char *s); -void add_imp_param(t_params *ps, int ai, int aj, int ak, int al, +void add_imp_param(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, real c0, real c1, const char *s); -void add_dih_param(t_params *ps, int ai, int aj, int ak, int al, +void add_dih_param(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, real c0, real c1, real c2, const char *s); -void add_cmap_param(t_params *ps, int ai, int aj, int ak, int al, int am, +void add_cmap_param(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, int am, const char *s); -void add_vsite2_atoms(t_params *ps, int ai, int aj, int ak); +void add_vsite2_atoms(InteractionTypeParameters *ps, int ai, int aj, int ak); -void add_vsite3_atoms(t_params *ps, int ai, int aj, int ak, int al, +void add_vsite3_atoms(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, bool bSwapParity); -void add_vsite2_param(t_params *ps, int ai, int aj, int ak, real c0); +void add_vsite2_param(InteractionTypeParameters *ps, int ai, int aj, int ak, real c0); -void add_vsite3_param(t_params *ps, int ai, int aj, int ak, int al, +void add_vsite3_param(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, real c0, real c1); -void add_vsite4_atoms(t_params *ps, int ai, int aj, int ak, int al, +void add_vsite4_atoms(InteractionTypeParameters *ps, int ai, int aj, int ak, int al, int am); int search_jtype(const PreprocessResidue &localPpResidue, const char *name, bool bFirstRes); diff --git a/src/gromacs/gmxpreprocess/convparm.cpp b/src/gromacs/gmxpreprocess/convparm.cpp index 1ea48876c9..63f7aca8f8 100644 --- a/src/gromacs/gmxpreprocess/convparm.cpp +++ b/src/gromacs/gmxpreprocess/convparm.cpp @@ -497,7 +497,7 @@ static void append_interaction(InteractionList *ilist, } } -static void enter_function(const t_params *p, t_functype ftype, int comb, real reppow, +static void enter_function(const InteractionTypeParameters *p, t_functype ftype, int comb, real reppow, gmx_ffparams_t *ffparams, InteractionList *il, bool bNB, bool bAppend) { @@ -519,11 +519,11 @@ static void enter_function(const t_params *p, t_functype ftype, int comb, real r } } -void convert_params(int atnr, t_params nbtypes[], - gmx::ArrayRef mi, - const MoleculeInformation *intermolecular_interactions, - int comb, double reppow, real fudgeQQ, - gmx_mtop_t *mtop) +void convertInteractionTypeParameters(int atnr, gmx::ArrayRef nbtypes, + gmx::ArrayRef mi, + const MoleculeInformation *intermolecular_interactions, + int comb, double reppow, real fudgeQQ, + gmx_mtop_t *mtop) { int i; unsigned long flags; @@ -548,7 +548,7 @@ void convert_params(int atnr, t_params nbtypes[], { molt->ilist[i].iatoms.clear(); - const t_params *plist = mi[mt].plist; + gmx::ArrayRef plist = mi[mt].plist; flags = interaction_function[i].flags; if ((i != F_LJ) && (i != F_BHAM) && ((flags & IF_BOND) || @@ -572,7 +572,7 @@ void convert_params(int atnr, t_params nbtypes[], { (*mtop->intermolecular_ilist)[i].iatoms.clear(); - const t_params *plist = intermolecular_interactions->plist; + gmx::ArrayRef plist = intermolecular_interactions->plist; if (plist[i].nr > 0) { diff --git a/src/gromacs/gmxpreprocess/convparm.h b/src/gromacs/gmxpreprocess/convparm.h index 2b61d6fcfd..bcc82b83c5 100644 --- a/src/gromacs/gmxpreprocess/convparm.h +++ b/src/gromacs/gmxpreprocess/convparm.h @@ -43,12 +43,12 @@ struct gmx_mtop_t; struct MoleculeInformation; -struct t_params; +struct InteractionTypeParameters; -void convert_params(int atnr, t_params nbtypes[], - gmx::ArrayRef mi, - const MoleculeInformation *intermolecular_interactions, - int comb, double reppow, real fudgeQQ, - gmx_mtop_t *mtop); +void convertInteractionTypeParameters(int atnr, gmx::ArrayRef nbtypes, + gmx::ArrayRef mi, + const MoleculeInformation *intermolecular_interactions, + int comb, double reppow, real fudgeQQ, + gmx_mtop_t *mtop); #endif diff --git a/src/gromacs/gmxpreprocess/gen_ad.cpp b/src/gromacs/gmxpreprocess/gen_ad.cpp index 365b2e577c..9cb2eb7ffa 100644 --- a/src/gromacs/gmxpreprocess/gen_ad.cpp +++ b/src/gromacs/gmxpreprocess/gen_ad.cpp @@ -216,12 +216,11 @@ static void rm2par(t_param p[], int *np, peq eq) sfree(index); } -static void cppar(t_param p[], int np, t_params plist[], int ftype) +static void cppar(t_param p[], int np, gmx::ArrayRef plist, int ftype) { - int i, j, nral, nrfp; - t_params *ps; + int i, j, nral, nrfp; - ps = &plist[ftype]; + InteractionTypeParameters *ps = &plist[ftype]; nral = NRAL(ftype); nrfp = NRFP(ftype); @@ -726,7 +725,7 @@ void generate_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]) /* Generate pairs, angles and dihedrals from .rtp settings */ void gen_pad(t_nextnb *nnb, t_atoms *atoms, gmx::ArrayRef rtpFFDB, - t_params plist[], t_excls excls[], gmx::ArrayRef globalPatches, + gmx::ArrayRef plist, t_excls excls[], gmx::ArrayRef globalPatches, bool bAllowMissing) { t_param *ang, *dih, *pai, *improper; diff --git a/src/gromacs/gmxpreprocess/gen_ad.h b/src/gromacs/gmxpreprocess/gen_ad.h index d27f6725f3..f4b2456141 100644 --- a/src/gromacs/gmxpreprocess/gen_ad.h +++ b/src/gromacs/gmxpreprocess/gen_ad.h @@ -44,14 +44,18 @@ struct t_atoms; struct t_excls; struct MoleculePatchDatabase; struct t_nextnb; -struct t_params; +struct InteractionTypeParameters; struct PreprocessResidue; void generate_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]); void clean_excls(t_nextnb *nnb, int nrexcl, t_excls excls[]); -void gen_pad(t_nextnb *nnb, t_atoms *atoms, gmx::ArrayRef rtpFFDB, - t_params plist[], t_excls excls[], gmx::ArrayRef globalPatches, - bool bAllowMissing); +void gen_pad(t_nextnb *nnb, + t_atoms *atoms, + gmx::ArrayRef rtpFFDB, + gmx::ArrayRef plist, + t_excls excls[], + gmx::ArrayRef globalPatches, + bool bAllowMissing); #endif diff --git a/src/gromacs/gmxpreprocess/gen_vsite.cpp b/src/gromacs/gmxpreprocess/gen_vsite.cpp index 9d9fd1b1e2..c5ce5f54db 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.cpp +++ b/src/gromacs/gmxpreprocess/gen_vsite.cpp @@ -469,15 +469,15 @@ static real get_ddb_angle(gmx::ArrayRef vsitetop, } -static void count_bonds(int atom, t_params *psb, char ***atomname, +static void count_bonds(int atom, InteractionTypeParameters *psb, char ***atomname, int *nrbonds, int *nrHatoms, int Hatoms[], int *Heavy, int *nrheavies, int heavies[]) { - int i, heavy, other, nrb, nrH, nrhv; + int heavy, other, nrb, nrH, nrhv; /* find heavy atom bound to this hydrogen */ heavy = NOTSET; - for (i = 0; (i < psb->nr) && (heavy == NOTSET); i++) + for (int i = 0; (i < psb->nr) && (heavy == NOTSET); i++) { if (psb->param[i].ai() == atom) { @@ -497,7 +497,7 @@ static void count_bonds(int atom, t_params *psb, char ***atomname, nrb = 0; nrH = 0; nrhv = 0; - for (i = 0; i < psb->nr; i++) + for (int i = 0; i < psb->nr; i++) { if (psb->param[i].ai() == heavy) { @@ -606,7 +606,7 @@ static real get_amass(int atom, t_atoms *at, gmx::ArrayRef plist, int vsite_type[], int Heavy, int nrHatoms, int Hatoms[], int nrheavies, int heavies[]) { - int i, j, ftype, other, moreheavy; - bool bSwapParity; + int other, moreheavy; - for (i = 0; i < nrHatoms; i++) + for (int i = 0; i < nrHatoms; i++) { - ftype = vsite_type[Hatoms[i]]; + int ftype = vsite_type[Hatoms[i]]; /* Errors in setting the vsite_type should really be caugth earlier, * because here it's not possible to print any useful error message. * But it's still better to print a message than to segfault. @@ -633,7 +632,7 @@ static void add_vsites(t_params plist[], int vsite_type[], { gmx_incons("Undetected error in setting up virtual sites"); } - bSwapParity = (ftype < 0); + bool bSwapParity = (ftype < 0); vsite_type[Hatoms[i]] = ftype = abs(ftype); if (ftype == F_BONDS) { @@ -670,7 +669,7 @@ static void add_vsites(t_params plist[], int vsite_type[], { /* find more heavy atoms */ other = moreheavy = NOTSET; - for (j = 0; (j < plist[F_BONDS].nr) && (moreheavy == NOTSET); j++) + for (int j = 0; (j < plist[F_BONDS].nr) && (moreheavy == NOTSET); j++) { if (plist[F_BONDS].param[j].ai() == heavies[0]) { @@ -722,7 +721,7 @@ static void add_vsites(t_params plist[], int vsite_type[], /* get cos(alpha) when a, b and c are given: */ #define acosrule(a, b, c) ( (gmx::square(b)+gmx::square(c)-gmx::square(a))/(2*(b)*(c)) ) -static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[], +static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], gmx::ArrayRef plist, int nrfound, int *ats, real bond_cc, real bond_ch, real xcom, bool bDoZ) { @@ -813,7 +812,7 @@ static int gen_vsites_6ring(t_atoms *at, int *vsite_type[], t_params plist[], return nvsite; } -static int gen_vsites_phe(t_atoms *at, int *vsite_type[], t_params plist[], +static int gen_vsites_phe(t_atoms *at, int *vsite_type[], gmx::ArrayRef plist, int nrfound, int *ats, gmx::ArrayRef vsitetop) { real bond_cc, bond_ch; @@ -878,7 +877,8 @@ static int gen_vsites_trp(gpp_atomtype *atype, int *o2n[], int *newvsite_type[], int *newcgnr[], t_symtab *symtab, int *nadd, gmx::ArrayRef x, int *cgnr[], - t_atoms *at, int *vsite_type[], t_params plist[], + t_atoms *at, int *vsite_type[], + gmx::ArrayRef plist, int nrfound, int *ats, int add_shift, gmx::ArrayRef vsitetop) { @@ -1151,7 +1151,8 @@ static int gen_vsites_tyr(gpp_atomtype *atype, int *o2n[], int *newvsite_type[], int *newcgnr[], t_symtab *symtab, int *nadd, gmx::ArrayRef x, int *cgnr[], - t_atoms *at, int *vsite_type[], t_params plist[], + t_atoms *at, int *vsite_type[], + gmx::ArrayRef plist, int nrfound, int *ats, int add_shift, gmx::ArrayRef vsitetop) { @@ -1295,7 +1296,8 @@ static int gen_vsites_tyr(gpp_atomtype *atype, return nvsite; } -static int gen_vsites_his(t_atoms *at, int *vsite_type[], t_params plist[], +static int gen_vsites_his(t_atoms *at, int *vsite_type[], + gmx::ArrayRef plist, int nrfound, int *ats, gmx::ArrayRef vsitetop) { int nvsite, i; @@ -1550,27 +1552,27 @@ static char atomnamesuffix[] = "1234"; void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *atype, t_atoms *at, t_symtab *symtab, std::vector *x, - t_params plist[], int *vsite_type[], int *cgnr[], + gmx::ArrayRef plist, int *vsite_type[], int *cgnr[], real mHmult, bool bVsiteAromatics, const char *ffdir) { #define MAXATOMSPERRESIDUE 16 - 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]; - bool bWARNING, bAddVsiteParam, bFirstWater; - matrix tmpmat; - real mHtot, mtot, fact, fact2; - rvec rpar, rperp, temp; - char tpname[32], nexttpname[32]; - int *o2n, *newvsite_type, *newcgnr, ats[MAXATOMSPERRESIDUE]; - t_atom *newatom; - t_params *params; - char ***newatomname; - char *resnm = nullptr; - int cmplength; - bool isN, planarN, bFound; + int k, m, i0, ni0, whatres, resind, add_shift, nvsite, nadd; + int ai, aj, ak, al; + int nrfound = 0, needed, nrbonds, nrHatoms, Heavy, nrheavies, tpM, tpHeavy; + int Hatoms[4], heavies[4]; + bool bWARNING, bAddVsiteParam, bFirstWater; + matrix tmpmat; + real mHtot, mtot, fact, fact2; + rvec rpar, rperp, temp; + char tpname[32], nexttpname[32]; + int *o2n, *newvsite_type, *newcgnr, ats[MAXATOMSPERRESIDUE]; + t_atom *newatom; + InteractionTypeParameters *params; + char ***newatomname; + char *resnm = nullptr; + int cmplength; + bool isN, planarN, bFound; /* if bVsiteAromatics=TRUE do_vsites will specifically convert atoms in PHE, TRP, TYR and HIS to a construction of virtual sites */ @@ -1648,7 +1650,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty snew(newcgnr, at->nr); /* make index array to tell where the atoms go to when masses are inserted */ snew(o2n, at->nr); - for (i = 0; i < at->nr; i++) + for (int i = 0; i < at->nr; i++) { o2n[i] = i; } @@ -1660,7 +1662,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty /* generate vsite constructions */ /* loop over all atoms */ resind = -1; - for (i = 0; (i < at->nr); i++) + for (int i = 0; (i < at->nr); i++) { if (at->atom[i].resind != resind) { @@ -1682,7 +1684,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty bResProcessed[resind] = TRUE; /* find out if this residue needs converting */ whatres = NOTSET; - for (j = 0; j < resNR && whatres == NOTSET; j++) + for (int j = 0; j < resNR && whatres == NOTSET; j++) { cmplength = bPartial[j] ? strlen(resnm)-1 : strlen(resnm); @@ -1860,7 +1862,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty if ((nrHatoms == 2) && ((*at->atomname[Heavy])[0] == 'N')) { isN = TRUE; - j = nitrogen_is_planar(vsiteconflist, tpname); + int j = nitrogen_is_planar(vsiteconflist, tpname); if (j < 0) { gmx_fatal(FARGS, "No vsite database NH2 entry for type %s\n", tpname); @@ -1888,7 +1890,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty bAddVsiteParam = FALSE; /* we'll do this ourselves! */ /* -NH2 (umbrella), -NH3+ or -CH3 */ (*vsite_type)[Heavy] = F_VSITE3; - for (j = 0; j < nrHatoms; j++) + for (int j = 0; j < nrHatoms; j++) { (*vsite_type)[Hatoms[j]] = Hat_vsite_type[j]; } @@ -1923,7 +1925,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty fprintf(stderr, "Inserting %d dummy masses at %d\n", NMASS, o2n[i0]+1); } nadd += NMASS; - for (j = i0; j < at->nr; j++) + for (int j = i0; j < at->nr; j++) { o2n[j] = j+nadd; } @@ -1934,7 +1936,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty srenew(newvsite_type, at->nr+nadd); srenew(newcgnr, at->nr+nadd); - for (j = 0; j < NMASS; j++) + for (int j = 0; j < NMASS; j++) { newatomname[at->nr+nadd-1-j] = nullptr; } @@ -1942,7 +1944,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty /* calculate starting position for the masses */ mHtot = 0; /* get atom masses, and set Heavy and Hatoms mass to zero */ - for (j = 0; j < nrHatoms; j++) + for (int j = 0; j < nrHatoms; j++) { mHtot += get_amass(Hatoms[j], at, rtpFFDB, &rt); at->atom[Hatoms[j]].m = at->atom[Hatoms[j]].mB = 0; @@ -1959,7 +1961,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty * rpar = Heavy -> Hcom * rperp = Hcom -> H1 */ clear_rvec(rpar); - for (j = 0; j < nrHatoms; j++) + for (int j = 0; j < nrHatoms; j++) { rvec_inc(rpar, (*x)[Hatoms[j]]); } @@ -1969,7 +1971,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty rvec_dec(rperp, rpar); /* rperp = H1 - Heavy - rpar */ /* calc mass positions */ svmul(fact2, rpar, temp); - for (j = 0; (j < NMASS); j++) /* xM = xN + fact2 * rpar +/- fact * rperp */ + for (int j = 0; (j < NMASS); j++) /* xM = xN + fact2 * rpar +/- fact * rperp */ { rvec_add((*x)[Heavy], temp, newx[ni0+j]); } @@ -1977,10 +1979,11 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty rvec_inc(newx[ni0 ], temp); rvec_dec(newx[ni0+1], temp); /* set atom parameters for the masses */ - for (j = 0; (j < NMASS); j++) + for (int j = 0; (j < NMASS); j++) { /* make name: "M??#" or "M?#" (? is atomname, # is number) */ name[0] = 'M'; + int k; for (k = 0; (*at->atomname[Heavy])[k] && ( k < NMASS ); k++) { name[k+1] = (*at->atomname[Heavy])[k]; @@ -2009,7 +2012,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty add_vsite3_atoms (&plist[(*vsite_type)[Heavy]], Heavy, heavies[0], add_shift+ni0, add_shift+ni0+1, FALSE); - for (j = 0; j < nrHatoms; j++) + for (int j = 0; j < nrHatoms; j++) { add_vsite3_atoms(&plist[(*vsite_type)[Hatoms[j]]], Hatoms[j], heavies[0], add_shift+ni0, add_shift+ni0+1, @@ -2038,7 +2041,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty add_vsites(plist, (*vsite_type), Heavy, nrHatoms, Hatoms, nrheavies, heavies); /* transfer mass of virtual site to Heavy atom */ - for (j = 0; j < nrHatoms; j++) + for (int j = 0; j < nrHatoms; j++) { if (is_vsite((*vsite_type)[Hatoms[j]])) { @@ -2061,7 +2064,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty if (debug) { fprintf(debug, "Before inserting new atoms:\n"); - for (i = 0; i < at->nr; i++) + for (int i = 0; i < at->nr; i++) { fprintf(debug, "%4d %4d %4s %4d %4s %6d %-10s\n", i+1, o2n[i]+1, at->atomname[i] ? *(at->atomname[i]) : "(NULL)", @@ -2073,7 +2076,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty "NOTSET" : interaction_function[(*vsite_type)[i]].name); } fprintf(debug, "new atoms to be inserted:\n"); - for (i = 0; i < at->nr+nadd; i++) + for (int i = 0; i < at->nr+nadd; i++) { if (newatomname[i]) { @@ -2087,7 +2090,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty } /* add all original atoms to the new arrays, using o2n index array */ - for (i = 0; i < at->nr; i++) + for (int i = 0; i < at->nr; i++) { newatomname [o2n[i]] = at->atomname [i]; newatom [o2n[i]] = at->atom [i]; @@ -2116,7 +2119,7 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty if (debug) { fprintf(debug, "After inserting new atoms:\n"); - for (i = 0; i < at->nr; i++) + for (int i = 0; i < at->nr; i++) { fprintf(debug, "%4d %4s %4d %4s %6d %-10s\n", i+1, at->atomname[i] ? *(at->atomname[i]) : "(NULL)", @@ -2130,17 +2133,17 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty } /* now renumber all the interactions because of the added atoms */ - for (ftype = 0; ftype < F_NRE; ftype++) + for (int ftype = 0; ftype < F_NRE; ftype++) { - params = &(plist[ftype]); + InteractionTypeParameters *params = &(plist[ftype]); if (debug) { fprintf(debug, "Renumbering %d %s\n", params->nr, interaction_function[ftype].longname); } - for (i = 0; i < params->nr; i++) + for (int i = 0; i < params->nr; i++) { - for (j = 0; j < NRAL(ftype); j++) + for (int j = 0; j < NRAL(ftype); j++) { if (params->param[i].a[j] >= add_shift) { @@ -2169,11 +2172,11 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty } /* now check if atoms in the added constraints are in increasing order */ params = &(plist[F_CONSTRNC]); - for (i = 0; i < params->nr; i++) + for (int i = 0; i < params->nr; i++) { if (params->param[i].ai() > params->param[i].aj()) { - j = params->param[i].aj(); + int j = params->param[i].aj(); params->param[i].aj() = params->param[i].ai(); params->param[i].ai() = j; } @@ -2188,20 +2191,18 @@ void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *aty fprintf(stderr, "Added %d new constraints\n", plist[F_CONSTRNC].nr); } -void do_h_mass(t_params *psb, int vsite_type[], t_atoms *at, real mHmult, +void do_h_mass(InteractionTypeParameters *psb, int vsite_type[], t_atoms *at, real mHmult, bool bDeuterate) { - int i, j, a; - /* loop over all atoms */ - for (i = 0; i < at->nr; i++) + for (int i = 0; i < at->nr; i++) { /* adjust masses if i is hydrogen and not a virtual site */ if (!is_vsite(vsite_type[i]) && is_hydrogen(*(at->atomname[i])) ) { /* find bonded heavy atom */ - a = NOTSET; - for (j = 0; (j < psb->nr) && (a == NOTSET); j++) + int a = NOTSET; + for (int j = 0; (j < psb->nr) && (a == NOTSET); j++) { /* if other atom is not a virtual site, it is the one we want */ if ( (psb->param[j].ai() == i) && diff --git a/src/gromacs/gmxpreprocess/gen_vsite.h b/src/gromacs/gmxpreprocess/gen_vsite.h index 66246efa8c..a5d89a1f11 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.h +++ b/src/gromacs/gmxpreprocess/gen_vsite.h @@ -44,7 +44,7 @@ struct gpp_atomtype; struct t_atoms; -struct t_params; +struct InteractionTypeParameters; struct PreprocessResidue; struct t_symtab; @@ -52,11 +52,11 @@ struct t_symtab; void do_vsites(gmx::ArrayRef rtpFFDB, gpp_atomtype *atype, t_atoms *at, t_symtab *symtab, std::vector *x, - t_params plist[], int *dummy_type[], int *cgnr[], + gmx::ArrayRef plist, int *dummy_type[], int *cgnr[], real mHmult, bool bVSiteAromatics, const char *ffdir); -void do_h_mass(t_params *psb, int vsite_type[], t_atoms *at, real mHmult, +void do_h_mass(InteractionTypeParameters *psb, int vsite_type[], t_atoms *at, real mHmult, bool bDeuterate); #endif diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.cpp b/src/gromacs/gmxpreprocess/gpp_atomtype.cpp index 3fe7003ccd..c43d6bf0f9 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.cpp +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.cpp @@ -326,7 +326,7 @@ static int search_atomtypes(gpp_atomtype *ga, int *n, int typelist[], return i; } -void renum_atype(t_params plist[], gmx_mtop_t *mtop, +void renum_atype(gmx::ArrayRef plist, gmx_mtop_t *mtop, int *wall_atomtype, gpp_atomtype *ga, bool bVerbose) { diff --git a/src/gromacs/gmxpreprocess/gpp_atomtype.h b/src/gromacs/gmxpreprocess/gpp_atomtype.h index 38bc3c0824..075f7c895a 100644 --- a/src/gromacs/gmxpreprocess/gpp_atomtype.h +++ b/src/gromacs/gmxpreprocess/gpp_atomtype.h @@ -40,6 +40,7 @@ #include +#include "gromacs/utility/arrayref.h" #include "gromacs/utility/real.h" struct gmx_mtop_t; @@ -47,7 +48,7 @@ struct gpp_atomtype; struct t_atom; struct t_atomtypes; struct t_param; -struct t_params; +struct InteractionTypeParameters; struct t_symtab; int get_atomtype_type(const char *str, gpp_atomtype *at); @@ -94,7 +95,7 @@ int add_atomtype(gpp_atomtype *at, t_symtab *tab, void print_at (FILE * out, gpp_atomtype *at); /* Print an atomtype record to a text file */ -void renum_atype(t_params plist[], gmx_mtop_t *mtop, +void renum_atype(gmx::ArrayRef plist, gmx_mtop_t *mtop, int *wall_atomtype, gpp_atomtype *at, bool bVerbose); diff --git a/src/gromacs/gmxpreprocess/gpp_nextnb.cpp b/src/gromacs/gmxpreprocess/gpp_nextnb.cpp index 74c2fa3226..d793d94958 100644 --- a/src/gromacs/gmxpreprocess/gpp_nextnb.cpp +++ b/src/gromacs/gmxpreprocess/gpp_nextnb.cpp @@ -340,15 +340,12 @@ static void do_gen(int nrbonds, /* total number of bonds in s */ } -static void add_b(t_params *bonds, int *nrf, sortable *s) +static void add_b(InteractionTypeParameters *bonds, int *nrf, sortable *s) { - int i; - int ai, aj; - - for (i = 0; (i < bonds->nr); i++) + for (int i = 0; (i < bonds->nr); i++) { - ai = bonds->param[i].ai(); - aj = bonds->param[i].aj(); + int ai = bonds->param[i].ai(); + int aj = bonds->param[i].aj(); if ((ai < 0) || (aj < 0)) { gmx_fatal(FARGS, "Impossible atom numbers in bond %d: ai=%d, aj=%d", @@ -362,13 +359,13 @@ static void add_b(t_params *bonds, int *nrf, sortable *s) } } -void gen_nnb(t_nextnb *nnb, t_params plist[]) +void gen_nnb(t_nextnb *nnb, gmx::ArrayRef plist) { sortable *s; - int i, nrbonds, nrf; + int nrbonds, nrf; nrbonds = 0; - for (i = 0; (i < F_NRE); i++) + for (int i = 0; (i < F_NRE); i++) { if (IS_CHEMBOND(i)) { @@ -380,7 +377,7 @@ void gen_nnb(t_nextnb *nnb, t_params plist[]) snew(s, nrbonds); nrf = 0; - for (i = 0; (i < F_NRE); i++) + for (int i = 0; (i < F_NRE); i++) { if (IS_CHEMBOND(i)) { @@ -441,7 +438,9 @@ sort_and_purge_nnb(t_nextnb *nnb) } -void generate_excl (int nrexcl, int nratoms, t_params plist[], t_nextnb *nnb, t_blocka *excl) +void generate_excl (int nrexcl, + int nratoms, + gmx::ArrayRef plist, t_nextnb *nnb, t_blocka *excl) { if (nrexcl < 0) { diff --git a/src/gromacs/gmxpreprocess/gpp_nextnb.h b/src/gromacs/gmxpreprocess/gpp_nextnb.h index 569c079e8e..1e6f8a420a 100644 --- a/src/gromacs/gmxpreprocess/gpp_nextnb.h +++ b/src/gromacs/gmxpreprocess/gpp_nextnb.h @@ -38,8 +38,10 @@ #ifndef GMX_GMXPREPROCESS_GPP_NEXTNB_H #define GMX_GMXPREPROCESS_GPP_NEXTNB_H +#include "gromacs/utility/arrayref.h" + struct t_blocka; -struct t_params; +struct InteractionTypeParameters; struct t_nextnb { @@ -66,7 +68,7 @@ void print_nnb(t_nextnb *nnb, char *s); #define print_nnb(nnb, s) #endif -void gen_nnb(t_nextnb *nnb, t_params plist[]); +void gen_nnb(t_nextnb *nnb, gmx::ArrayRef plist); /* Generate a t_nextnb structure from bond information. * With the structure you can either generate exclusions * or generate angles and dihedrals. The structure must be @@ -74,7 +76,7 @@ void gen_nnb(t_nextnb *nnb, t_params plist[]); */ void generate_excl (int nrexcl, int nratoms, - t_params plist[], t_nextnb *nnb, t_blocka *excl); + gmx::ArrayRef plist, t_nextnb *nnb, t_blocka *excl); /* Generate an exclusion block from bonds and constraints in * plist. */ diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index c7d7ffa6eb..f669c50b44 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -509,7 +509,7 @@ new_status(const char *topfile, const char *topppfile, const char *confin, gpp_atomtype *atype, gmx_mtop_t *sys, std::vector *mi, std::unique_ptr *intermolecular_interactions, - t_params plist[], + gmx::ArrayRef plist, int *comb, double *reppow, real *fudgeQQ, gmx_bool bMorse, warninp *wi) @@ -870,8 +870,8 @@ static void read_posres(gmx_mtop_t *mtop, for (gmx_molblock_t &molb : mtop->molblock) { nat_molb = molb.nmol*mtop->moltype[molb.type].atoms.nr; - const t_params *pr = &(molinfo[molb.type].plist[F_POSRES]); - const t_params *prfb = &(molinfo[molb.type].plist[F_FBPOSRES]); + const InteractionTypeParameters *pr = &(molinfo[molb.type].plist[F_POSRES]); + const InteractionTypeParameters *prfb = &(molinfo[molb.type].plist[F_FBPOSRES]); if (pr->nr > 0 || prfb->nr > 0) { atom = mtop->moltype[molb.type].atoms.atom; @@ -1111,10 +1111,10 @@ interpolate1d( double xmin, static void -setup_cmap (int grid_spacing, - int nc, - const real * grid, - gmx_cmap_t * cmap_grid) +setup_cmap (int grid_spacing, + int nc, + gmx::ArrayRef grid, + gmx_cmap_t * cmap_grid) { int i, j, k, ii, jj, kk, idx; int offset; @@ -1213,7 +1213,7 @@ static int count_constraints(const gmx_mtop_t *mtop, for (const gmx_molblock_t &molb : mtop->molblock) { count_mol = 0; - const t_params *plist = mi[molb.type].plist; + gmx::ArrayRef plist = mi[molb.type].plist; for (i = 0; i < F_NRE; i++) { @@ -1694,7 +1694,6 @@ int gmx_grompp(int argc, char *argv[]) std::unique_ptr intermolecular_interactions; gpp_atomtype *atype; int nvsite, comb; - t_params *plist; real fudgeQQ; double reppow; const char *mdparin; @@ -1799,7 +1798,7 @@ int gmx_grompp(int argc, char *argv[]) warning_error(wi, warn_buf); } - snew(plist, F_NRE); + std::array plist; init_plist(plist); gmx_mtop_t sys; atype = init_atomtype(); @@ -1955,10 +1954,10 @@ int gmx_grompp(int argc, char *argv[]) } /* If we are using CMAP, setup the pre-interpolation grid */ - if (plist[F_CMAP].ncmap > 0) + if (plist[F_CMAP].ncmap() > 0) { - init_cmap_grid(&sys.ffparams.cmap_grid, plist[F_CMAP].nc, plist[F_CMAP].grid_spacing); - setup_cmap(plist[F_CMAP].grid_spacing, plist[F_CMAP].nc, plist[F_CMAP].cmap, &sys.ffparams.cmap_grid); + init_cmap_grid(&sys.ffparams.cmap_grid, plist[F_CMAP].cmapAngles, plist[F_CMAP].cmakeGridSpacing); + setup_cmap(plist[F_CMAP].cmakeGridSpacing, plist[F_CMAP].cmapAngles, plist[F_CMAP].cmap, &sys.ffparams.cmap_grid); } set_wall_atomtype(atype, opts, ir, wi); @@ -1987,12 +1986,12 @@ int gmx_grompp(int argc, char *argv[]) } ntype = get_atomtype_ntypes(atype); - convert_params(ntype, plist, mi, intermolecular_interactions.get(), - comb, reppow, fudgeQQ, &sys); + convertInteractionTypeParameters(ntype, plist, mi, intermolecular_interactions.get(), + comb, reppow, fudgeQQ, &sys); if (debug) { - pr_symtab(debug, 0, "After convert_params", &sys.symtab); + pr_symtab(debug, 0, "After converInteractionTypeParameters", &sys.symtab); } /* set ptype to VSite for virtual sites */ @@ -2324,7 +2323,6 @@ int gmx_grompp(int argc, char *argv[]) sfree(opts->include); sfree(opts); done_plist(plist); - sfree(plist); for (auto &mol : mi) { // Some of the contents of molinfo have been stolen, so diff --git a/src/gromacs/gmxpreprocess/grompp_impl.h b/src/gromacs/gmxpreprocess/grompp_impl.h index 8c6489a15f..e2b3c55fe6 100644 --- a/src/gromacs/gmxpreprocess/grompp_impl.h +++ b/src/gromacs/gmxpreprocess/grompp_impl.h @@ -50,42 +50,61 @@ struct t_param { - int a[MAXATOMLIST]; /* The atom list (eg. bonds: particle */ - /* i = a[0] (ai), j = a[1] (aj)) */ - real c[MAXFORCEPARAM]; /* Force parameters (eg. b0 = c[0]) */ - char s[MAXSLEN]; /* A string (instead of parameters), * - * read from the .rtp file in pdb2gmx */ - const int &ai() const { return a[0]; } - int &ai() { return a[0]; } - const int &aj() const { return a[1]; } - int &aj() { return a[1]; } - const int &ak() const { return a[2]; } - int &ak() { return a[2]; } - const int &al() const { return a[3]; } - int &al() { return a[3]; } - const int &am() const { return a[4]; } - int &am() { return a[4]; } - - real &c0() { return c[0]; } - real &c1() { return c[1]; } - real &c2() { return c[2]; } + int a[MAXATOMLIST]; /* The atom list (eg. bonds: particle */ + /* i = a[0] (ai), j = a[1] (aj)) */ + real c[MAXFORCEPARAM]; /* Force parameters (eg. b0 = c[0]) */ + char s[MAXSLEN]; /* A string (instead of parameters), * + * read from the .rtp file in pdb2gmx */ + const int &ai() const { return a[0]; } + int &ai() { return a[0]; } + const int &aj() const { return a[1]; } + int &aj() { return a[1]; } + const int &ak() const { return a[2]; } + int &ak() { return a[2]; } + const int &al() const { return a[3]; } + int &al() { return a[3]; } + const int &am() const { return a[4]; } + int &am() { return a[4]; } + + const real &c0() const { return c[0]; } + real &c0() { return c[0]; } + const real &c1() const { return c[1]; } + real &c1() { return c[1]; } + const real &c2() const { return c[2]; } + real &c2() { return c[2]; } }; -struct t_params +/*! \libinternal \brief + * The parameters for a set of interactions of a given + * (unspecified) type found in the enumeration in ifunc.h. + * + * This is used for containing the data obtained from the + * lists of interactions of a given type in a [moleculetype] + * topology file definition. + * + * \todo Remove manual memory management. + */ +struct InteractionTypeParameters { // NOLINT (clang-analyzer-optin.performance.Padding) - int nr; /* The number of bonds in this record */ - int maxnr; /* The amount of elements in the array */ - t_param *param; /* Array of parameters (dim: nr or nr*nr) */ - - /* CMAP tmp data, there are probably better places for this */ - int grid_spacing; /* Cmap grid spacing */ - int nc; /* Number of cmap angles */ - - real *cmap; /* Temporary storage of the raw cmap grid data */ - int ncmap; /* Number of allocated elements in cmap grid*/ - - int *cmap_types; /* Store the five atomtypes followed by a number that identifies the type */ - int nct; /* Number of allocated elements in cmap_types */ + //! Number of parameters. + int nr = 0; + //! Maximum number of parameters. + int maxnr = 0; + //! The parameters of the interactions + t_param *param; + //! CMAP grid spacing. + int cmakeGridSpacing = -1; + //! Number of cmap angles. + int cmapAngles = -1; + //! CMAP grid data. + std::vector cmap; + //! The five atomtypes followed by a number that identifies the type. + std::vector cmapAtomTypes; + + //! Elements in cmap grid data. + int ncmap() const { return cmap.size(); } + //! Number of elements in cmapAtomTypes. + int nct() const { return cmapAtomTypes.size(); } }; struct t_excls @@ -101,23 +120,23 @@ struct t_excls struct MoleculeInformation { //! Name of the molecule. - char **name = nullptr; + char **name = nullptr; //!Number of exclusions per atom. - int nrexcl = 0; + int nrexcl = 0; //! Have exclusions been generated?. - bool excl_set = false; + bool excl_set = false; //! Has the mol been processed. - bool bProcessed = false; + bool bProcessed = false; //! Atoms in the moelcule. - t_atoms atoms; + t_atoms atoms; //! Charge groups in the molecule - t_block cgs; + t_block cgs; //! Molecules separated in datastructure. - t_block mols; + t_block mols; //! Exclusions in the molecule. - t_blocka excls; + t_blocka excls; //! Parameters in old style. - t_params plist[F_NRE]; + std::array plist; /*! \brief * Initializer. diff --git a/src/gromacs/gmxpreprocess/nm2type.cpp b/src/gromacs/gmxpreprocess/nm2type.cpp index 3926d6137a..748e435b02 100644 --- a/src/gromacs/gmxpreprocess/nm2type.cpp +++ b/src/gromacs/gmxpreprocess/nm2type.cpp @@ -192,7 +192,7 @@ static int match_str(const char *atom, const char *template_string) } int nm2type(int nnm, t_nm2type nm2t[], t_symtab *tab, t_atoms *atoms, - gpp_atomtype *atype, int *nbonds, t_params *bonds) + gpp_atomtype *atype, int *nbonds, InteractionTypeParameters *bonds) { int cur = 0; #define prev (1-cur) diff --git a/src/gromacs/gmxpreprocess/nm2type.h b/src/gromacs/gmxpreprocess/nm2type.h index d9973d57ee..5d6fa3d0b4 100644 --- a/src/gromacs/gmxpreprocess/nm2type.h +++ b/src/gromacs/gmxpreprocess/nm2type.h @@ -41,7 +41,7 @@ struct gpp_atomtype; struct t_atoms; -struct t_params; +struct InteractionTypeParameters; struct t_symtab; struct t_nm2type @@ -62,7 +62,7 @@ void dump_nm2type(FILE *fp, int nnm, t_nm2type nm2t[]); /* Dump the database for debugging. Can be reread by the program */ int nm2type(int nnm, t_nm2type nm2t[], t_symtab *tab, t_atoms *atoms, - gpp_atomtype *atype, int *nbonds, t_params *bond); + gpp_atomtype *atype, int *nbonds, InteractionTypeParameters *bond); /* Try to determine the atomtype (force field dependent) for the atoms * with help of the bond list */ diff --git a/src/gromacs/gmxpreprocess/pdb2top.cpp b/src/gromacs/gmxpreprocess/pdb2top.cpp index aebbbe3150..ed6a9c7d4d 100644 --- a/src/gromacs/gmxpreprocess/pdb2top.cpp +++ b/src/gromacs/gmxpreprocess/pdb2top.cpp @@ -672,7 +672,7 @@ void print_top_mols(FILE *out, void write_top(FILE *out, const char *pr, const char *molname, t_atoms *at, bool bRTPresname, - int bts[], t_params plist[], t_excls excls[], + int bts[], gmx::ArrayRef plist, t_excls excls[], gpp_atomtype *atype, int *cgnr, int nrexcl) /* NOTE: nrexcl is not the size of *excl! */ { @@ -711,7 +711,7 @@ void write_top(FILE *out, const char *pr, const char *molname, -static void do_ssbonds(t_params *ps, t_atoms *atoms, +static void do_ssbonds(InteractionTypeParameters *ps, t_atoms *atoms, gmx::ArrayRef ssbonds, bool bAllowMissing) { for (const auto &bond : ssbonds) @@ -731,7 +731,7 @@ static void do_ssbonds(t_params *ps, t_atoms *atoms, } } -static void at2bonds(t_params *psb, gmx::ArrayRef globalPatches, +static void at2bonds(InteractionTypeParameters *psb, gmx::ArrayRef globalPatches, t_atoms *atoms, gmx::ArrayRef x, real long_bond_dist, real short_bond_dist) @@ -835,7 +835,7 @@ static int pcompar(const void *a, const void *b) } } -static void clean_bonds(t_params *ps) +static void clean_bonds(InteractionTypeParameters *ps) { int i, j; int a; @@ -879,7 +879,7 @@ static void clean_bonds(t_params *ps) } } -void print_sums(t_atoms *atoms, bool bSystem) +void print_sums(const t_atoms *atoms, bool bSystem) { double m, qtot; int i; @@ -1348,7 +1348,7 @@ void match_atomnames_with_rtp(gmx::ArrayRef usedPpResidue } #define NUM_CMAP_ATOMS 5 -static void gen_cmap(t_params *psb, gmx::ArrayRef usedPpResidues, t_atoms *atoms) +static void gen_cmap(InteractionTypeParameters *psb, gmx::ArrayRef usedPpResidues, t_atoms *atoms) { int residx; const char *ptr; @@ -1478,13 +1478,13 @@ void pdb2top(FILE *top_file, const char *posre_fn, const char *molname, bool bDeuterate, bool bChargeGroups, bool bCmap, bool bRenumRes, bool bRTPresname) { - t_params plist[F_NRE]; - t_excls *excls; - t_nextnb nnb; - int *cgnr; - int *vsite_type; - int i, nmissat; - int bts[ebtsNR]; + std::array plist; + t_excls *excls; + t_nextnb nnb; + int *cgnr; + int *vsite_type; + int i, nmissat; + int bts[ebtsNR]; init_plist(plist); ResidueType rt; diff --git a/src/gromacs/gmxpreprocess/pdb2top.h b/src/gromacs/gmxpreprocess/pdb2top.h index 9999178862..b9c625c3a4 100644 --- a/src/gromacs/gmxpreprocess/pdb2top.h +++ b/src/gromacs/gmxpreprocess/pdb2top.h @@ -50,7 +50,7 @@ struct t_atoms; struct t_excls; struct MoleculePatchDatabase; struct t_mols; -struct t_params; +struct InteractionTypeParameters; struct t_resinfo; struct PreprocessResidue; struct DisulfideBond; @@ -113,7 +113,7 @@ void print_top_mols(FILE *out, void write_top(FILE *out, const char *pr, const char *molname, t_atoms *at, bool bRTPresname, - int bts[], t_params plist[], t_excls excls[], + int bts[], gmx::ArrayRef plist, t_excls excls[], gpp_atomtype *atype, int *cgnr, int nrexcl); /* NOTE: nrexcl is not the size of *excl! */ @@ -134,6 +134,6 @@ void pdb2top(FILE *top_file, const char *posre_fn, const char *molname, bool bRenumRes, bool bRTPresname); /* Create a topology ! */ -void print_sums(t_atoms *atoms, bool bSystem); +void print_sums(const t_atoms *atoms, bool bSystem); #endif diff --git a/src/gromacs/gmxpreprocess/topio.cpp b/src/gromacs/gmxpreprocess/topio.cpp index 94903e99ac..ae0f82e37d 100644 --- a/src/gromacs/gmxpreprocess/topio.cpp +++ b/src/gromacs/gmxpreprocess/topio.cpp @@ -85,7 +85,7 @@ #define OPENDIR '[' /* starting sign for directive */ #define CLOSEDIR ']' /* ending sign for directive */ -static void gen_pairs(t_params *nbs, t_params *pairs, real fudge, int comb) +static void gen_pairs(InteractionTypeParameters *nbs, InteractionTypeParameters *pairs, real fudge, int comb) { int i, j, ntp, nrfp, nrfpA, nrfpB, nnn; real scaling; @@ -381,7 +381,7 @@ static char **read_topol(const char *infile, const char *outfile, int *nrmols, std::vector *molinfo, std::unique_ptr *intermolecular_interactions, - t_params plist[], + gmx::ArrayRef plist, int *combination_rule, double *reppow, t_gromppopts *opts, @@ -453,8 +453,8 @@ static char **read_topol(const char *infile, const char *outfile, *reppow = 12.0; /* Default value for repulsion power */ /* Init the number of CMAP torsion angles and grid spacing */ - plist[F_CMAP].grid_spacing = 0; - plist[F_CMAP].nc = 0; + plist[F_CMAP].cmakeGridSpacing = 0; + plist[F_CMAP].cmapAngles = 0; bWarn_copy_A_B = bFEP; @@ -737,10 +737,12 @@ static char **read_topol(const char *infile, const char *outfile, break; case Directive::d_pairs: + GMX_RELEASE_ASSERT(mi0, "Need to have a valid MoleculeInformation object to work on"); push_bond(d, plist, mi0->plist, &(mi0->atoms), atype, pline, FALSE, bGenPairs, *fudgeQQ, bZero, &bWarn_copy_A_B, wi); break; case Directive::d_pairs_nb: + GMX_RELEASE_ASSERT(mi0, "Need to have a valid MoleculeInformation object to work on"); push_bond(d, plist, mi0->plist, &(mi0->atoms), atype, pline, FALSE, FALSE, 1.0, bZero, &bWarn_copy_A_B, wi); break; @@ -762,14 +764,17 @@ static char **read_topol(const char *infile, const char *outfile, case Directive::d_polarization: case Directive::d_water_polarization: case Directive::d_thole_polarization: + GMX_RELEASE_ASSERT(mi0, "Need to have a valid MoleculeInformation object to work on"); push_bond(d, plist, mi0->plist, &(mi0->atoms), atype, pline, TRUE, bGenPairs, *fudgeQQ, bZero, &bWarn_copy_A_B, wi); break; case Directive::d_cmap: + GMX_RELEASE_ASSERT(mi0, "Need to have a valid MoleculeInformation object to work on"); push_cmap(d, plist, mi0->plist, &(mi0->atoms), atype, pline, wi); break; case Directive::d_vsitesn: + GMX_RELEASE_ASSERT(mi0, "Need to have a valid MoleculeInformation object to work on"); push_vsitesn(d, mi0->plist, &(mi0->atoms), pline, wi); break; case Directive::d_exclusions: @@ -933,24 +938,24 @@ static char **read_topol(const char *infile, const char *outfile, return title; } -char **do_top(bool bVerbose, - const char *topfile, - const char *topppfile, - t_gromppopts *opts, - bool bZero, - t_symtab *symtab, - t_params plist[], - int *combination_rule, - double *repulsion_power, - real *fudgeQQ, - gpp_atomtype *atype, - int *nrmols, - std::vector *molinfo, - std::unique_ptr *intermolecular_interactions, - const t_inputrec *ir, - std::vector *molblock, - bool *ffParametrizedWithHBondConstraints, - warninp *wi) +char **do_top(bool bVerbose, + const char *topfile, + const char *topppfile, + t_gromppopts *opts, + bool bZero, + t_symtab *symtab, + gmx::ArrayRef plist, + int *combination_rule, + double *repulsion_power, + real *fudgeQQ, + gpp_atomtype *atype, + int *nrmols, + std::vector *molinfo, + std::unique_ptr *intermolecular_interactions, + const t_inputrec *ir, + std::vector *molblock, + bool *ffParametrizedWithHBondConstraints, + warninp *wi) { /* Tmpfile might contain a long path */ const char *tmpfile; diff --git a/src/gromacs/gmxpreprocess/topio.h b/src/gromacs/gmxpreprocess/topio.h index c71d5b7a38..746aafe3a2 100644 --- a/src/gromacs/gmxpreprocess/topio.h +++ b/src/gromacs/gmxpreprocess/topio.h @@ -41,6 +41,7 @@ #include #include +#include "gromacs/utility/arrayref.h" #include "gromacs/utility/real.h" struct gmx_molblock_t; @@ -49,7 +50,7 @@ struct gpp_atomtype; struct t_gromppopts; struct t_inputrec; struct MoleculeInformation; -struct t_params; +struct InteractionTypeParameters; struct t_symtab; struct warninp; enum struct GmxQmmmMode; @@ -58,24 +59,24 @@ typedef warninp *warninp_t; double check_mol(const gmx_mtop_t *mtop, warninp_t wi); /* Check mass and charge */ -char **do_top(bool bVerbose, - const char *topfile, - const char *topppfile, - t_gromppopts *opts, - bool bZero, - t_symtab *symtab, - t_params plist[], - int *combination_rule, - double *repulsion_power, - real *fudgeQQ, - gpp_atomtype *atype, - int *nrmols, - std::vector *molinfo, - std::unique_ptr *intermolecular_interactions, - const t_inputrec *ir, - std::vector *molblock, - bool *ffParametrizedWithHBondConstraints, - warninp_t wi); +char **do_top(bool bVerbose, + const char *topfile, + const char *topppfile, + t_gromppopts *opts, + bool bZero, + t_symtab *symtab, + gmx::ArrayRef plist, + int *combination_rule, + double *repulsion_power, + real *fudgeQQ, + gpp_atomtype *atype, + int *nrmols, + std::vector *molinfo, + std::unique_ptr *intermolecular_interactions, + const t_inputrec *ir, + std::vector *molblock, + bool *ffParametrizedWithHBondConstraints, + warninp_t wi); /* This routine expects sys->molt[m].ilist to be of size F_NRE and ordered. */ void generate_qmexcl(gmx_mtop_t *sys, t_inputrec *ir, warninp_t wi, GmxQmmmMode qmmmMode); diff --git a/src/gromacs/gmxpreprocess/toppush.cpp b/src/gromacs/gmxpreprocess/toppush.cpp index d529057a6b..ca06defb24 100644 --- a/src/gromacs/gmxpreprocess/toppush.cpp +++ b/src/gromacs/gmxpreprocess/toppush.cpp @@ -66,7 +66,7 @@ #include "gromacs/utility/smalloc.h" #include "gromacs/utility/stringutil.h" -void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype *atype, +void generate_nbparams(int comb, int ftype, InteractionTypeParameters *plist, gpp_atomtype *atype, warninp *wi) { int i, j, k = -1, nf; @@ -192,7 +192,7 @@ void generate_nbparams(int comb, int ftype, t_params *plist, gpp_atomtype *atype } /*! \brief Used to temporarily store the explicit non-bonded parameter - * combinations, which will be copied to t_params. */ + * combinations, which will be copied to InteractionTypeParameters. */ struct t_nbparam { //! Has this combination been set. @@ -215,7 +215,7 @@ static void realloc_nb_params(gpp_atomtype *at, } } -int copy_nbparams(t_nbparam **param, int ftype, t_params *plist, int nr) +int copy_nbparams(t_nbparam **param, int ftype, InteractionTypeParameters *plist, int nr) { int i, j, f; int nrfp, ncopy; @@ -581,13 +581,13 @@ static bool equalEitherForwardOrBackward(gmx::ArrayRef a, gmx::ArrayRef std::equal(a.begin(), a.end(), b.rbegin())); } -static void push_bondtype(t_params * bt, - const t_param * b, - int nral, - int ftype, - bool bAllowRepeat, - const char * line, - warninp *wi) +static void push_bondtype(InteractionTypeParameters * bt, + const t_param * b, + int nral, + int ftype, + bool bAllowRepeat, + const char * line, + warninp *wi) { int nr = bt->nr; int nrfp = NRFP(ftype); @@ -715,7 +715,7 @@ static void push_bondtype(t_params * bt, } } -void push_bt(Directive d, t_params bt[], int nral, +void push_bt(Directive d, gmx::ArrayRef bt, int nral, gpp_atomtype *at, gpp_bond_atomtype *bat, char *line, warninp *wi) @@ -815,7 +815,7 @@ void push_bt(Directive d, t_params bt[], int nral, } -void push_dihedraltype(Directive d, t_params bt[], +void push_dihedraltype(Directive d, gmx::ArrayRef bt, gpp_bond_atomtype *bat, char *line, warninp *wi) { @@ -1111,7 +1111,7 @@ void push_nbt(Directive d, t_nbparam **nbt, gpp_atomtype *atype, } void -push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at, +push_cmaptype(Directive d, gmx::ArrayRef bt, int nral, gpp_atomtype *at, gpp_bond_atomtype *bat, char *line, warninp *wi) { @@ -1155,10 +1155,6 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at, nrfpB = strtol(alc[7], nullptr, 10)*strtol(alc[7], nullptr, 10); nrfp = nrfpA+nrfpB; - /* Allocate memory for the CMAP grid */ - bt[F_CMAP].ncmap += nrfp; - srenew(bt[F_CMAP].cmap, bt[F_CMAP].ncmap); - /* Read in CMAP parameters */ sl = 0; for (i = 0; i < ncmap; i++) @@ -1169,7 +1165,7 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at, } nn = sscanf(line+start+sl, " %s ", s); sl += strlen(s); - bt[F_CMAP].cmap[i+(bt[F_CMAP].ncmap)-nrfp] = strtod(s, nullptr); + bt[F_CMAP].cmap.emplace_back(strtod(s, nullptr)); if (nn == 1) { @@ -1188,7 +1184,7 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at, { for (i = 0; i < ncmap; i++) { - bt[F_CMAP].cmap[i+ncmap] = bt[F_CMAP].cmap[i]; + bt[F_CMAP].cmap.emplace_back(bt[F_CMAP].cmap[i]); } } else @@ -1211,12 +1207,9 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at, /* Set grid spacing and the number of grids (we assume these numbers to be the same for all grids * so we can safely assign them each time */ - bt[F_CMAP].grid_spacing = nxcmap; /* Or nycmap, they need to be equal */ - bt[F_CMAP].nc = bt[F_CMAP].nc + 1; /* Since we are incrementing here, we need to subtract later, see (*****) */ - nct = (nral+1) * bt[F_CMAP].nc; - - /* Allocate memory for the cmap_types information */ - srenew(bt[F_CMAP].cmap_types, nct); + bt[F_CMAP].cmakeGridSpacing = nxcmap; /* Or nycmap, they need to be equal */ + bt[F_CMAP].cmapAngles++; /* Since we are incrementing here, we need to subtract later, see (*****) */ + nct = (nral+1) * bt[F_CMAP].cmapAngles; for (i = 0; (i < nral); i++) { @@ -1232,16 +1225,16 @@ push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at, } /* Assign a grid number to each cmap_type */ - bt[F_CMAP].cmap_types[bt[F_CMAP].nct++] = get_bond_atomtype_type(alc[i], bat); + bt[F_CMAP].cmapAtomTypes.emplace_back(get_bond_atomtype_type(alc[i], bat)); } /* Assign a type number to this cmap */ - bt[F_CMAP].cmap_types[bt[F_CMAP].nct++] = bt[F_CMAP].nc-1; /* Since we inremented earlier, we need to subtrac here, to get the types right (****) */ + bt[F_CMAP].cmapAtomTypes.emplace_back(bt[F_CMAP].cmapAngles-1); /* Since we inremented earlier, we need to subtrac here, to get the types right (****) */ /* Check for the correct number of atoms (again) */ - if (bt[F_CMAP].nct != nct) + if (bt[F_CMAP].nct() != nct) { - auto message = gmx::formatString("Incorrect number of atom types (%d) in cmap type %d\n", nct, bt[F_CMAP].nc); + auto message = gmx::formatString("Incorrect number of atom types (%d) in cmap type %d\n", nct, bt[F_CMAP].cmapAngles); warning_error(wi, message); } @@ -1469,7 +1462,7 @@ void push_molt(t_symtab *symtab, mol->back().excl_set = false; } -static bool default_nb_params(int ftype, t_params bt[], t_atoms *at, +static bool default_nb_params(int ftype, gmx::ArrayRef bt, t_atoms *at, t_param *p, int c_start, bool bB, bool bGenPairs) { int i, j, ti, tj, ntype; @@ -1564,7 +1557,7 @@ static bool default_nb_params(int ftype, t_params bt[], t_atoms *at, return bFound; } -static bool default_cmap_params(t_params bondtype[], +static bool default_cmap_params(gmx::ArrayRef bondtype, t_atoms *at, gpp_atomtype *atype, t_param *p, bool bB, int *cmap_type, int *nparam_def, @@ -1578,7 +1571,7 @@ static bool default_cmap_params(t_params bondtype[], ct = 0; /* Match the current cmap angle against the list of cmap_types */ - for (i = 0; i < bondtype[F_CMAP].nct && !bFound; i += 6) + for (i = 0; i < bondtype[F_CMAP].nct() && !bFound; i += 6) { if (bB) { @@ -1587,15 +1580,15 @@ static bool default_cmap_params(t_params bondtype[], else { if ( - (get_atomtype_batype(at->atom[p->a[0]].type, atype) == bondtype[F_CMAP].cmap_types[i]) && - (get_atomtype_batype(at->atom[p->a[1]].type, atype) == bondtype[F_CMAP].cmap_types[i+1]) && - (get_atomtype_batype(at->atom[p->a[2]].type, atype) == bondtype[F_CMAP].cmap_types[i+2]) && - (get_atomtype_batype(at->atom[p->a[3]].type, atype) == bondtype[F_CMAP].cmap_types[i+3]) && - (get_atomtype_batype(at->atom[p->a[4]].type, atype) == bondtype[F_CMAP].cmap_types[i+4])) + (get_atomtype_batype(at->atom[p->a[0]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i]) && + (get_atomtype_batype(at->atom[p->a[1]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i+1]) && + (get_atomtype_batype(at->atom[p->a[2]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i+2]) && + (get_atomtype_batype(at->atom[p->a[3]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i+3]) && + (get_atomtype_batype(at->atom[p->a[4]].type, atype) == bondtype[F_CMAP].cmapAtomTypes[i+4])) { /* Found cmap torsion */ bFound = TRUE; - ct = bondtype[F_CMAP].cmap_types[i+5]; + ct = bondtype[F_CMAP].cmapAtomTypes[i+5]; nparam_found = 1; } } @@ -1639,11 +1632,11 @@ static int natom_match(t_param *pi, } } -static bool default_params(int ftype, t_params bt[], - t_atoms *at, gpp_atomtype *atype, - t_param *p, bool bB, - t_param **param_def, - int *nparam_def) +static bool defaultInteractionTypeParameters(int ftype, gmx::ArrayRef bt, + t_atoms *at, gpp_atomtype *atype, + t_param *p, bool bB, + t_param **param_def, + int *nparam_def) { int nparam_found; bool bFound, bSame; @@ -1758,7 +1751,8 @@ static bool default_params(int ftype, t_params bt[], -void push_bond(Directive d, t_params bondtype[], t_params bond[], +void push_bond(Directive d, gmx::ArrayRef bondtype, + gmx::ArrayRef bond, t_atoms *at, gpp_atomtype *atype, char *line, bool bBonded, bool bGenPairs, real fudgeQQ, bool bZero, bool *bWarn_copy_A_B, @@ -1904,7 +1898,7 @@ void push_bond(Directive d, t_params bondtype[], t_params bond[], if (bBonded) { - bFoundA = default_params(ftype, bondtype, at, atype, ¶m, FALSE, ¶m_defA, &nparam_defA); + bFoundA = defaultInteractionTypeParameters(ftype, bondtype, at, atype, ¶m, FALSE, ¶m_defA, &nparam_defA); if (bFoundA) { /* Copy the A-state and B-state default parameters. */ @@ -1914,7 +1908,7 @@ void push_bond(Directive d, t_params bondtype[], t_params bond[], param.c[j] = param_defA->c[j]; } } - bFoundB = default_params(ftype, bondtype, at, atype, ¶m, TRUE, ¶m_defB, &nparam_defB); + bFoundB = defaultInteractionTypeParameters(ftype, bondtype, at, atype, ¶m, TRUE, ¶m_defB, &nparam_defB); if (bFoundB) { /* Copy only the B-state default parameters */ @@ -2166,7 +2160,8 @@ void push_bond(Directive d, t_params bondtype[], t_params bond[], } } -void push_cmap(Directive d, t_params bondtype[], t_params bond[], +void push_cmap(Directive d, gmx::ArrayRef bondtype, + gmx::ArrayRef bond, t_atoms *at, gpp_atomtype *atype, char *line, warninp *wi) { @@ -2259,7 +2254,7 @@ void push_cmap(Directive d, t_params bondtype[], t_params bond[], -void push_vsitesn(Directive d, t_params bond[], +void push_vsitesn(Directive d, gmx::ArrayRef bond, t_atoms *at, char *line, warninp *wi) { @@ -2508,7 +2503,7 @@ int add_atomtype_decoupled(t_symtab *symtab, gpp_atomtype *at, return nr; } -static void convert_pairs_to_pairsQ(t_params *plist, +static void convert_pairs_to_pairsQ(gmx::ArrayRef plist, real fudgeQQ, t_atoms *atoms) { t_param *paramp1, *paramp2, *paramnew; @@ -2573,7 +2568,7 @@ static void convert_pairs_to_pairsQ(t_params *plist, plist[F_LJ14].param = nullptr; } -static void generate_LJCpairsNB(MoleculeInformation *mol, int nb_funct, t_params *nbp, warninp *wi) +static void generate_LJCpairsNB(MoleculeInformation *mol, int nb_funct, InteractionTypeParameters *nbp, warninp *wi) { int n, ntype, i, j, k; t_atom *atom; @@ -2695,7 +2690,7 @@ static void decouple_atoms(t_atoms *atoms, int atomtype_decouple, void convert_moltype_couple(MoleculeInformation *mol, int atomtype_decouple, real fudgeQQ, int couple_lam0, int couple_lam1, - bool bCoupleIntra, int nb_funct, t_params *nbp, + bool bCoupleIntra, int nb_funct, InteractionTypeParameters *nbp, warninp *wi) { convert_pairs_to_pairsQ(mol->plist, fudgeQQ, &mol->atoms); diff --git a/src/gromacs/gmxpreprocess/toppush.h b/src/gromacs/gmxpreprocess/toppush.h index 1bb0078a37..48d706871a 100644 --- a/src/gromacs/gmxpreprocess/toppush.h +++ b/src/gromacs/gmxpreprocess/toppush.h @@ -51,7 +51,7 @@ struct t_block; struct MoleculeInformation; struct t_nbparam; struct t_param; -struct t_params; +struct InteractionTypeParameters; struct PreprocessResidue; struct warninp; @@ -60,7 +60,7 @@ namespace gmx struct ExclusionBlock; } // namespace gmx -void generate_nbparams(int comb, int funct, t_params plist[], +void generate_nbparams(int comb, int funct, InteractionTypeParameters *plist, gpp_atomtype *atype, warninp *wi); @@ -69,15 +69,15 @@ void push_at (struct t_symtab *symtab, gpp_atomtype *at, t_nbparam ***nbparam, t_nbparam ***pair, warninp *wi); -void push_bt(Directive d, t_params bt[], int nral, +void push_bt(Directive d, gmx::ArrayRef bt, int nral, gpp_atomtype *at, gpp_bond_atomtype *bat, char *line, warninp *wi); -void push_dihedraltype(Directive d, t_params bt[], +void push_dihedraltype(Directive d, gmx::ArrayRef bt, gpp_bond_atomtype *bat, char *line, warninp *wi); -void push_cmaptype(Directive d, t_params bt[], int nral, gpp_atomtype *at, +void push_cmaptype(Directive d, gmx::ArrayRef bt, int nral, gpp_atomtype *at, gpp_bond_atomtype *bat, char *line, warninp *wi); @@ -93,17 +93,20 @@ void push_atom(struct t_symtab *symtab, int *lastcg, warninp *wi); -void push_bond(Directive d, t_params bondtype[], t_params bond[], +void push_bond(Directive d, gmx::ArrayRef bondtype, + gmx::ArrayRef bond, t_atoms *at, gpp_atomtype *atype, char *line, bool bBonded, bool bGenPairs, real fudgeQQ, bool bZero, bool *bWarn_copy_A_B, warninp *wi); -void push_cmap(Directive d, t_params bondtype[], t_params bond[], +void push_cmap(Directive d, + gmx::ArrayRef bondtype, + gmx::ArrayRef bond, t_atoms *at, gpp_atomtype *atype, char *line, warninp *wi); -void push_vsitesn(Directive d, t_params bond[], +void push_vsitesn(Directive d, gmx::ArrayRef bond, t_atoms *at, char *line, warninp *wi); @@ -116,7 +119,7 @@ void push_molt(struct t_symtab *symtab, std::vector *mol, c void push_excl(char *line, gmx::ArrayRef b2, warninp *wi); -int copy_nbparams(t_nbparam **param, int ftype, t_params *plist, int nr); +int copy_nbparams(t_nbparam **param, int ftype, InteractionTypeParameters *plist, int nr); void free_nbparam(t_nbparam **param, int nr); @@ -130,7 +133,7 @@ void convert_moltype_couple(MoleculeInformation *mol, int atomtype_decouple, real fudgeQQ, int couple_lam0, int couple_lam1, bool bCoupleIntra, - int nb_funct, t_params *nbp, + int nb_funct, InteractionTypeParameters *nbp, warninp *wi); /* Setup mol such that the B-state has no interaction with the rest * of the system, but full interaction with itself. diff --git a/src/gromacs/gmxpreprocess/topshake.cpp b/src/gromacs/gmxpreprocess/topshake.cpp index 5c54f19db7..49dea59eee 100644 --- a/src/gromacs/gmxpreprocess/topshake.cpp +++ b/src/gromacs/gmxpreprocess/topshake.cpp @@ -53,7 +53,7 @@ #include "gromacs/utility/fatalerror.h" #include "gromacs/utility/smalloc.h" -static void copy_bond (t_params *pr, int to, int from) +static void copy_bond (InteractionTypeParameters *pr, int to, int from) /* copies an entry in a bond list to another position. * does no allocing or freeing of memory */ @@ -103,15 +103,15 @@ static int count_hydrogens (char ***atomname, int nra, const int a[]) return nh; } -void make_shake (t_params plist[], t_atoms *atoms, int nshake) +void make_shake(gmx::ArrayRef plist, t_atoms *atoms, int nshake) { - char ***info = atoms->atomname; - t_params *pr; - t_params *bonds; - t_param p, *bond, *ang; - real b_ij, b_jk; - int i, j, ftype, ftype_a; - bool bFound; + char ***info = atoms->atomname; + InteractionTypeParameters *pr; + InteractionTypeParameters *bonds; + t_param p, *bond, *ang; + real b_ij, b_jk; + int i, j, ftype, ftype_a; + bool bFound; if (nshake != eshNONE) { diff --git a/src/gromacs/gmxpreprocess/topshake.h b/src/gromacs/gmxpreprocess/topshake.h index 6573aed28c..f9163f50db 100644 --- a/src/gromacs/gmxpreprocess/topshake.h +++ b/src/gromacs/gmxpreprocess/topshake.h @@ -38,9 +38,11 @@ #ifndef GMX_GMXPREPROCESS_TOPSHAKE_H #define GMX_GMXPREPROCESS_TOPSHAKE_H +#include "gromacs/utility/arrayref.h" + struct t_atoms; -struct t_params; +struct InteractionTypeParameters; -void make_shake (t_params plist[], t_atoms *atoms, int nshake); +void make_shake (gmx::ArrayRef plist, t_atoms *atoms, int nshake); #endif diff --git a/src/gromacs/gmxpreprocess/toputil.cpp b/src/gromacs/gmxpreprocess/toputil.cpp index ae1a78e340..ecde0d9fa8 100644 --- a/src/gromacs/gmxpreprocess/toputil.cpp +++ b/src/gromacs/gmxpreprocess/toputil.cpp @@ -78,7 +78,7 @@ void set_p_string(t_param *p, const char *s) } } -void pr_alloc (int extra, t_params *pr) +void pr_alloc (int extra, InteractionTypeParameters *pr) { int i, j; @@ -91,7 +91,7 @@ void pr_alloc (int extra, t_params *pr) { return; } - GMX_ASSERT(pr->nr != 0 || pr->param == nullptr, "Invalid t_params object"); + GMX_ASSERT(pr->nr != 0 || pr->param == nullptr, "Invalid InteractionTypeParameters object"); if (pr->nr+extra > pr->maxnr) { pr->maxnr = std::max(static_cast(1.2*pr->maxnr), pr->maxnr + extra); @@ -111,7 +111,7 @@ void pr_alloc (int extra, t_params *pr) } } -void init_plist(t_params plist[]) +void init_plist(gmx::ArrayRef plist) { int i; @@ -120,25 +120,14 @@ void init_plist(t_params plist[]) plist[i].nr = 0; plist[i].maxnr = 0; plist[i].param = nullptr; - - /* CMAP */ - plist[i].ncmap = 0; - plist[i].cmap = nullptr; - plist[i].grid_spacing = 0; - plist[i].nc = 0; - plist[i].nct = 0; - plist[i].cmap_types = nullptr; } } -void done_plist(t_params *plist) +void done_plist(gmx::ArrayRef plist) { for (int i = 0; i < F_NRE; i++) { - t_params *pl = &plist[i]; - sfree(pl->param); - sfree(pl->cmap); - sfree(pl->cmap_types); + sfree(plist[i].param); } } @@ -157,7 +146,7 @@ void cp_param(t_param *dest, t_param *src) strncpy(dest->s, src->s, sizeof(dest->s)); } -void add_param_to_list(t_params *list, t_param *b) +void add_param_to_list(InteractionTypeParameters *list, t_param *b) { int j; @@ -181,18 +170,17 @@ void add_param_to_list(t_params *list, t_param *b) /* PRINTING STRUCTURES */ static void print_bt(FILE *out, Directive d, gpp_atomtype *at, - int ftype, int fsubtype, t_params plist[], + int ftype, int fsubtype, gmx::ArrayRef plist, bool bFullDih) { /* This dihp is a DIRTY patch because the dih-types do not use * all four atoms to determine the type. */ - const int dihp[2][2] = { { 1, 2 }, { 0, 3 } }; - t_params *bt; - int i, j, f, nral, nrfp; - bool bDih = FALSE, bSwapParity; + const int dihp[2][2] = { { 1, 2 }, { 0, 3 } }; + int i, j, f, nral, nrfp; + bool bDih = FALSE, bSwapParity; - bt = &(plist[ftype]); + const InteractionTypeParameters *bt = &(plist[ftype]); if (!bt->nr) { @@ -501,7 +489,7 @@ void print_atoms(FILE *out, gpp_atomtype *atype, t_atoms *at, int *cgnr, } void print_bondeds(FILE *out, int natoms, Directive d, - int ftype, int fsubtype, t_params plist[]) + int ftype, int fsubtype, gmx::ArrayRef plist) { t_symtab stab; gpp_atomtype *atype; diff --git a/src/gromacs/gmxpreprocess/toputil.h b/src/gromacs/gmxpreprocess/toputil.h index 5664d606b1..068225238e 100644 --- a/src/gromacs/gmxpreprocess/toputil.h +++ b/src/gromacs/gmxpreprocess/toputil.h @@ -40,6 +40,8 @@ #include +#include "gromacs/utility/arrayref.h" + enum class Directive : int; struct gpp_atomtype; struct t_atoms; @@ -47,24 +49,24 @@ struct t_blocka; struct t_excls; struct MoleculeInformation; struct t_param; -struct t_params; +struct InteractionTypeParameters; /* UTILITIES */ int name2index(char *str, char ***typenames, int ntypes); -void pr_alloc (int extra, t_params *pr); +void pr_alloc (int extra, InteractionTypeParameters *pr); void set_p_string(t_param *p, const char *s); void cp_param(t_param *dest, t_param *src); -void add_param_to_list(t_params *list, t_param *b); +void add_param_to_list(InteractionTypeParameters *list, t_param *b); /* INITIATE */ -void init_plist(t_params plist[]); -void done_plist(t_params *plist); +void init_plist(gmx::ArrayRef plist); +void done_plist(gmx::ArrayRef plist); /* PRINTING */ @@ -76,7 +78,7 @@ void print_atoms(FILE *out, gpp_atomtype *atype, t_atoms *at, int *cgnr, bool bRTPresname); void print_bondeds(FILE *out, int natoms, Directive d, - int ftype, int fsubtype, t_params plist[]); + int ftype, int fsubtype, gmx::ArrayRef plist); void print_excl(FILE *out, int natoms, t_excls excls[]); diff --git a/src/gromacs/gmxpreprocess/vsite_parm.cpp b/src/gromacs/gmxpreprocess/vsite_parm.cpp index 02e18a2313..d047c3bb95 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.cpp +++ b/src/gromacs/gmxpreprocess/vsite_parm.cpp @@ -150,7 +150,7 @@ static void get_bondeds(int nrat, const t_iatom atoms[], } } -static at2vsitebond_t *make_at2vsitebond(int natoms, t_params plist[]) +static at2vsitebond_t *make_at2vsitebond(int natoms, gmx::ArrayRef plist) { bool *bVSI; int ftype, i, j, nrcheck, nr; @@ -218,7 +218,7 @@ static void done_at2vsitebond(int natoms, at2vsitebond_t *at2vb) sfree(at2vb); } -static at2vsitecon_t *make_at2vsitecon(int natoms, t_params plist[]) +static at2vsitecon_t *make_at2vsitecon(int natoms, gmx::ArrayRef plist) { bool *bVSI; int ftype, i, j, ai, aj, nr; @@ -768,7 +768,7 @@ calc_vsite4fdn_param(t_param *param, int set_vsites(bool bVerbose, t_atoms *atoms, gpp_atomtype *atype, - t_params plist[]) + gmx::ArrayRef plist) { int i, j, ftype; int nvsite, nrbond, nrang, nridih, nrset; @@ -934,12 +934,12 @@ typedef struct { int ftype, parnr; } t_pindex; -static void check_vsite_constraints(t_params *plist, +static void check_vsite_constraints(gmx::ArrayRef plist, int cftype, const int vsite_type[]) { - int i, k, n; - int atom; - t_params *ps; + int i, k, n; + int atom; + InteractionTypeParameters *ps; n = 0; ps = &(plist[cftype]); @@ -962,14 +962,14 @@ static void check_vsite_constraints(t_params *plist, } } -static void clean_vsite_bonds(t_params *plist, t_pindex pindex[], +static void clean_vsite_bonds(gmx::ArrayRef plist, t_pindex pindex[], int cftype, const int vsite_type[]) { - int ftype, i, j, k, m, n, nvsite, nOut, kept_i; - int nconverted, nremoved; - int atom, oatom, at1, at2; - bool bKeep, bRemove, bUsed, bPresent, bThisFD, bThisOUT, bAllFD, bFirstTwo; - t_params *ps; + int ftype, i, j, k, m, n, nvsite, nOut, kept_i; + int nconverted, nremoved; + int atom, oatom, at1, at2; + bool bKeep, bRemove, bUsed, bPresent, bThisFD, bThisOUT, bAllFD, bFirstTwo; + InteractionTypeParameters *ps; if (cftype == F_CONNBONDS) { @@ -1186,14 +1186,14 @@ static void clean_vsite_bonds(t_params *plist, t_pindex pindex[], ps->nr = kept_i; } -static void clean_vsite_angles(t_params *plist, t_pindex pindex[], +static void clean_vsite_angles(gmx::ArrayRef plist, t_pindex pindex[], int cftype, const int vsite_type[], at2vsitecon_t *at2vc) { - int i, j, k, m, n, nvsite, kept_i; - int atom, at1, at2; - bool bKeep, bUsed, bPresent, bAll3FAD, bFirstTwo; - t_params *ps; + int i, j, k, m, n, nvsite, kept_i; + int atom, at1, at2; + bool bKeep, bUsed, bPresent, bAll3FAD, bFirstTwo; + InteractionTypeParameters *ps; ps = &(plist[cftype]); kept_i = 0; @@ -1323,11 +1323,11 @@ static void clean_vsite_angles(t_params *plist, t_pindex pindex[], ps->nr = kept_i; } -static void clean_vsite_dihs(t_params *plist, t_pindex pindex[], +static void clean_vsite_dihs(gmx::ArrayRef plist, t_pindex pindex[], int cftype, const int vsite_type[]) { - int i, kept_i; - t_params *ps; + int i, kept_i; + InteractionTypeParameters *ps; ps = &(plist[cftype]); @@ -1435,7 +1435,7 @@ static void clean_vsite_dihs(t_params *plist, t_pindex pindex[], ps->nr = kept_i; } -void clean_vsite_bondeds(t_params *plist, int natoms, bool bRmVSiteBds) +void clean_vsite_bondeds(gmx::ArrayRef plist, int natoms, bool bRmVSiteBds) { int i, k, nvsite, ftype, vsite, parnr; int *vsite_type; diff --git a/src/gromacs/gmxpreprocess/vsite_parm.h b/src/gromacs/gmxpreprocess/vsite_parm.h index 986908ebaf..81005a0fe4 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.h +++ b/src/gromacs/gmxpreprocess/vsite_parm.h @@ -38,13 +38,15 @@ #ifndef GMX_GMXPREPROCESS_VSITE_PARM_H #define GMX_GMXPREPROCESS_VSITE_PARM_H +#include "gromacs/utility/arrayref.h" + struct gpp_atomtype; struct gmx_moltype_t; struct t_atoms; -struct t_params; +struct InteractionTypeParameters; int set_vsites(bool bVerbose, t_atoms *atoms, gpp_atomtype *atype, - t_params plist[]); + gmx::ArrayRef plist); /* set parameters for virtual sites, return number of virtual sites */ void set_vsites_ptype(bool bVerbose, gmx_moltype_t *molt); @@ -54,6 +56,6 @@ void set_vsites_ptype(bool bVerbose, gmx_moltype_t *molt); * * Throw away all obsolete bonds, angles and dihedrals. * Throw away all constraints. */ -void clean_vsite_bondeds(t_params *ps, int natoms, bool bRmVSiteBds); +void clean_vsite_bondeds(gmx::ArrayRef ps, int natoms, bool bRmVSiteBds); #endif diff --git a/src/gromacs/gmxpreprocess/x2top.cpp b/src/gromacs/gmxpreprocess/x2top.cpp index ada52a8a6c..a120b42925 100644 --- a/src/gromacs/gmxpreprocess/x2top.cpp +++ b/src/gromacs/gmxpreprocess/x2top.cpp @@ -94,7 +94,7 @@ static bool is_bond(int nnm, t_nm2type nmt[], char *ai, char *aj, real blen) } static void mk_bonds(int nnm, t_nm2type nmt[], - t_atoms *atoms, const rvec x[], t_params *bond, int nbond[], + t_atoms *atoms, const rvec x[], InteractionTypeParameters *bond, int nbond[], bool bPBC, matrix box) { t_param b; @@ -178,7 +178,7 @@ static int *set_cgnr(t_atoms *atoms, bool bUsePDBcharge, real *qtot, real *mtot) return cgnr; } -static gpp_atomtype *set_atom_type(t_symtab *tab, t_atoms *atoms, t_params *bonds, +static gpp_atomtype *set_atom_type(t_symtab *tab, t_atoms *atoms, InteractionTypeParameters *bonds, int *nbonds, int nnm, t_nm2type nm2t[]) { gpp_atomtype *atype; @@ -199,18 +199,17 @@ static gpp_atomtype *set_atom_type(t_symtab *tab, t_atoms *atoms, t_params *bond return atype; } -static void lo_set_force_const(t_params *plist, real c[], int nrfp, bool bRound, +static void lo_set_force_const(InteractionTypeParameters *plist, real c[], int nrfp, bool bRound, bool bDih, bool bParam) { - int i, j; double cc; char buf[32]; - for (i = 0; (i < plist->nr); i++) + for (int i = 0; (i < plist->nr); i++) { if (!bParam) { - for (j = 0; j < nrfp; j++) + for (int j = 0; j < nrfp; j++) { c[j] = NOTSET; } @@ -240,7 +239,7 @@ static void lo_set_force_const(t_params *plist, real c[], int nrfp, bool bRound, } } GMX_ASSERT(nrfp <= MAXFORCEPARAM/2, "Only 6 parameters may be used for an interaction"); - for (j = 0; (j < nrfp); j++) + for (int j = 0; (j < nrfp); j++) { plist->param[i].c[j] = c[j]; plist->param[i].c[nrfp+j] = c[j]; @@ -249,7 +248,7 @@ static void lo_set_force_const(t_params *plist, real c[], int nrfp, bool bRound, } } -static void set_force_const(t_params plist[], real kb, real kt, real kp, bool bRound, +static void set_force_const(gmx::ArrayRef plist, real kb, real kt, real kp, bool bRound, bool bParam) { real c[MAXFORCEPARAM]; @@ -264,35 +263,35 @@ static void set_force_const(t_params plist[], real kb, real kt, real kp, bool bR lo_set_force_const(&plist[F_PDIHS], c, 3, bRound, TRUE, bParam); } -static void calc_angles_dihs(t_params *ang, t_params *dih, const rvec x[], bool bPBC, +static void calc_angles_dihs(InteractionTypeParameters *ang, InteractionTypeParameters *dih, const rvec x[], bool bPBC, matrix box) { - int i, ai, aj, ak, al, t1, t2, t3; + int t1, t2, t3; rvec r_ij, r_kj, r_kl, m, n; - real th, costh, ph; + real costh; t_pbc pbc; if (bPBC) { set_pbc(&pbc, epbcXYZ, box); } - for (i = 0; (i < ang->nr); i++) + for (int i = 0; (i < ang->nr); i++) { - ai = ang->param[i].ai(); - aj = ang->param[i].aj(); - ak = ang->param[i].ak(); - th = RAD2DEG*bond_angle(x[ai], x[aj], x[ak], bPBC ? &pbc : nullptr, - r_ij, r_kj, &costh, &t1, &t2); + int ai = ang->param[i].ai(); + int aj = ang->param[i].aj(); + int ak = ang->param[i].ak(); + real th = RAD2DEG*bond_angle(x[ai], x[aj], x[ak], bPBC ? &pbc : nullptr, + r_ij, r_kj, &costh, &t1, &t2); ang->param[i].c0() = th; } - for (i = 0; (i < dih->nr); i++) + for (int i = 0; (i < dih->nr); i++) { - ai = dih->param[i].ai(); - aj = dih->param[i].aj(); - ak = dih->param[i].ak(); - al = dih->param[i].al(); - ph = RAD2DEG*dih_angle(x[ai], x[aj], x[ak], x[al], bPBC ? &pbc : nullptr, - r_ij, r_kj, r_kl, m, n, &t1, &t2, &t3); + int ai = dih->param[i].ai(); + int aj = dih->param[i].aj(); + int ak = dih->param[i].ak(); + int al = dih->param[i].al(); + real ph = RAD2DEG*dih_angle(x[ai], x[aj], x[ak], x[al], bPBC ? &pbc : nullptr, + r_ij, r_kj, r_kl, m, n, &t1, &t2, &t3); dih->param[i].c0() = ph; } } @@ -307,24 +306,22 @@ static void dump_hybridization(FILE *fp, t_atoms *atoms, int nbonds[]) } } -static void print_pl(FILE *fp, t_params plist[], int ftp, const char *name, +static void print_pl(FILE *fp, gmx::ArrayRef plist, int ftp, const char *name, char ***atomname) { - int i, j, nral, nrfp; - if (plist[ftp].nr > 0) { fprintf(fp, "\n"); fprintf(fp, "[ %s ]\n", name); - nral = interaction_function[ftp].nratoms; - nrfp = interaction_function[ftp].nrfpA; - for (i = 0; (i < plist[ftp].nr); i++) + int nral = interaction_function[ftp].nratoms; + int nrfp = interaction_function[ftp].nrfpA; + for (int i = 0; (i < plist[ftp].nr); i++) { - for (j = 0; (j < nral); j++) + for (int j = 0; (j < nral); j++) { fprintf(fp, " %5s", *atomname[plist[ftp].param[i].a[j]]); } - for (j = 0; (j < nrfp); j++) + for (int j = 0; (j < nrfp); j++) { if (plist[ftp].param[i].c[j] != NOTSET) { @@ -337,7 +334,7 @@ static void print_pl(FILE *fp, t_params plist[], int ftp, const char *name, } static void print_rtp(const char *filenm, const char *title, t_atoms *atoms, - t_params plist[], gpp_atomtype *atype, int cgnr[]) + gmx::ArrayRef plist, gpp_atomtype *atype, int cgnr[]) { FILE *fp; int i, tp; @@ -370,7 +367,7 @@ static void print_rtp(const char *filenm, const char *title, t_atoms *atoms, int gmx_x2top(int argc, char *argv[]) { - const char *desc[] = { + const char *desc[] = { "[THISMODULE] generates a primitive topology from a coordinate file.", "The program assumes all hydrogens are present when defining", "the hybridization from the atom name and the number of bonds.", @@ -391,51 +388,51 @@ int gmx_x2top(int argc, char *argv[]) "one of the short names above on the command line instead. In that", "case [THISMODULE] just looks for the corresponding file.[PAR]", }; - const char *bugs[] = { + const char *bugs[] = { "The atom type selection is primitive. Virtually no chemical knowledge is used", "Periodic boundary conditions screw up the bonding", "No improper dihedrals are generated", "The atoms to atomtype translation table is incomplete ([TT]atomname2type.n2t[tt] file in the data directory). Please extend it and send the results back to the GROMACS crew." }; - FILE *fp; - t_params plist[F_NRE]; - t_excls *excls; - gpp_atomtype *atype; - t_nextnb nnb; - t_nm2type *nm2t; - t_mols mymol; - int nnm; - char forcefield[32], ffdir[STRLEN]; - rvec *x; /* coordinates? */ - int *nbonds, *cgnr; - int bts[] = { 1, 1, 1, 2 }; - matrix box; /* box length matrix */ - int natoms; /* number of atoms in one molecule */ - int epbc; - bool bRTP, bTOP, bOPLS; - t_symtab symtab; - real qtot, mtot; - char n2t[STRLEN]; - gmx_output_env_t *oenv; - - t_filenm fnm[] = { + FILE *fp; + std::array plist; + t_excls *excls; + gpp_atomtype *atype; + t_nextnb nnb; + t_nm2type *nm2t; + t_mols mymol; + int nnm; + char forcefield[32], ffdir[STRLEN]; + rvec *x; /* coordinates? */ + int *nbonds, *cgnr; + int bts[] = { 1, 1, 1, 2 }; + matrix box; /* box length matrix */ + int natoms; /* number of atoms in one molecule */ + int epbc; + bool bRTP, bTOP, bOPLS; + t_symtab symtab; + real qtot, mtot; + char n2t[STRLEN]; + gmx_output_env_t *oenv; + + t_filenm fnm[] = { { efSTX, "-f", "conf", ffREAD }, { efTOP, "-o", "out", ffOPTWR }, { efRTP, "-r", "out", ffOPTWR } }; #define NFILE asize(fnm) - real kb = 4e5, kt = 400, kp = 5; - PreprocessResidue rtp_header_settings; - bool bRemoveDihedralIfWithImproper = FALSE; - bool bGenerateHH14Interactions = TRUE; - bool bKeepAllGeneratedDihedrals = FALSE; - int nrexcl = 3; - bool bParam = TRUE, bRound = TRUE; - bool bPairs = TRUE, bPBC = TRUE; - bool bUsePDBcharge = FALSE, bVerbose = FALSE; - const char *molnm = "ICE"; - const char *ff = "oplsaa"; - t_pargs pa[] = { + real kb = 4e5, kt = 400, kp = 5; + PreprocessResidue rtp_header_settings; + bool bRemoveDihedralIfWithImproper = FALSE; + bool bGenerateHH14Interactions = TRUE; + bool bKeepAllGeneratedDihedrals = FALSE; + int nrexcl = 3; + bool bParam = TRUE, bRound = TRUE; + bool bPairs = TRUE, bPBC = TRUE; + bool bUsePDBcharge = FALSE, bVerbose = FALSE; + const char *molnm = "ICE"; + const char *ff = "oplsaa"; + t_pargs pa[] = { { "-ff", FALSE, etSTR, {&ff}, "Force field for your simulation. Type \"select\" for interactive selection." }, { "-v", FALSE, etBOOL, {&bVerbose}, @@ -498,9 +495,6 @@ int gmx_x2top(int argc, char *argv[]) mymol.name = gmx_strdup(molnm); mymol.nr = 1; - /* Init parameter lists */ - init_plist(plist); - /* Read coordinates */ t_topology *top; snew(top, 1);