Note that gmx_cmap_t still needs to be converted.
Change-Id: Ib695962c08b7cba539a9604077cc372d795b1647
snew(top, 1);
- top->idef.ntypes = top_global->ffparams.ntypes;
+ /* TODO: Get rid of the const casts below, e.g. by using a reference */
+ top->idef.ntypes = top_global->ffparams.numTypes();
top->idef.atnr = top_global->ffparams.atnr;
- top->idef.functype = top_global->ffparams.functype;
- top->idef.iparams = top_global->ffparams.iparams;
+ top->idef.functype = const_cast<t_functype *>(top_global->ffparams.functype.data());
+ top->idef.iparams = const_cast<t_iparams *>(top_global->ffparams.iparams.data());
top->idef.fudgeQQ = top_global->ffparams.fudgeQQ;
top->idef.cmap_grid = top_global->ffparams.cmap_grid;
}
construct_vsites(nullptr, xs, 0.0, nullptr,
- ffparams->iparams, ilist,
+ ffparams->iparams.data(), ilist,
epbcNONE, TRUE, nullptr, nullptr);
}
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)
{
* 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)
{
static void set_disres_npair(gmx_mtop_t *mtop)
{
- t_iparams *ip;
- gmx_mtop_ilistloop_t iloop;
- int nmol;
+ gmx_mtop_ilistloop_t iloop;
+ int nmol;
- ip = mtop->ffparams.iparams;
+ gmx::ArrayRef<t_iparams> ip = mtop->ffparams.iparams;
iloop = gmx_mtop_ilistloop_init(mtop);
while (const InteractionLists *ilist = gmx_mtop_ilistloop_next(iloop, &nmol))
if (!bAppend)
{
- for (type = start; (type < ffparams->ntypes); type++)
+ for (type = start; (type < ffparams->numTypes()); type++)
{
if (ffparams->functype[type] == ftype)
{
}
else
{
- type = ffparams->ntypes;
+ type = ffparams->numTypes();
}
- memcpy(&ffparams->iparams[type], &newparam, static_cast<size_t>(sizeof(newparam)));
- ffparams->ntypes++;
- ffparams->functype[type] = ftype;
+ ffparams->iparams.push_back(newparam);
+ ffparams->functype.push_back(ftype);
+
+ GMX_ASSERT(ffparams->iparams.size() == ffparams->functype.size(),
+ "sizes should match");
return type;
}
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)
int comb, double reppow, real fudgeQQ,
gmx_mtop_t *mtop)
{
- int i, maxtypes;
+ int i;
unsigned long flags;
gmx_ffparams_t *ffp;
gmx_moltype_t *molt;
t_params *plist;
- maxtypes = 0;
-
ffp = &mtop->ffparams;
- ffp->ntypes = 0;
ffp->atnr = atnr;
- ffp->functype = nullptr;
- ffp->iparams = nullptr;
+ ffp->functype.clear();
+ ffp->iparams.clear();
ffp->reppow = reppow;
enter_function(&(nbtypes[F_LJ]), static_cast<t_functype>(F_LJ), comb, reppow, ffp, nullptr,
- &maxtypes, TRUE, TRUE);
+ TRUE, TRUE);
enter_function(&(nbtypes[F_BHAM]), static_cast<t_functype>(F_BHAM), comb, reppow, ffp, nullptr,
- &maxtypes, TRUE, TRUE);
+ TRUE, TRUE);
for (size_t mt = 0; mt < mtop->moltype.size(); mt++)
{
{
enter_function(&(plist[i]), static_cast<t_functype>(i), comb, reppow,
ffp, &molt->ilist[i],
- &maxtypes, FALSE, (i == F_POSRES || i == F_FBPOSRES));
+ FALSE, (i == F_POSRES || i == F_FBPOSRES));
}
}
}
{
enter_function(&(plist[i]), static_cast<t_functype>(i), comb, reppow,
ffp, &(*mtop->intermolecular_ilist)[i],
- &maxtypes, FALSE, FALSE);
+ FALSE, FALSE);
mtop->bIntermolecularInteractions = TRUE;
}
*/
int min_steps_warn = 5;
int min_steps_note = 10;
- t_iparams *ip;
int ftype;
int i, a1, a2, w_a1, w_a2, j;
real twopi2, limit2, fc, re, m1, m2, period2, w_period2;
bool bFound, bWater, bWarn;
char warn_buf[STRLEN];
- ip = mtop->ffparams.iparams;
+ /* Get the interaction parameters */
+ gmx::ArrayRef<const t_iparams> ip = mtop->ffparams.iparams;
twopi2 = gmx::square(2*M_PI);
* involved in a single constraint; the mass of the two atoms needs to
* differ by more than \p massFactorThreshold.
*/
-static bool haveDecoupledModeInMol(const gmx_moltype_t *molt,
- const t_iparams *iparams,
- real massFactorThreshold)
+static bool haveDecoupledModeInMol(const gmx_moltype_t &molt,
+ gmx::ArrayRef<const t_iparams> iparams,
+ real massFactorThreshold)
{
- if (molt->ilist[F_CONSTR].size() == 0 &&
- molt->ilist[F_CONSTRNC].size() == 0)
+ if (molt.ilist[F_CONSTR].size() == 0 &&
+ molt.ilist[F_CONSTRNC].size() == 0)
{
return false;
}
- const t_atom * atom = molt->atoms.atom;
+ const t_atom * atom = molt.atoms.atom;
t_blocka atomToConstraints =
- gmx::make_at2con(*molt, iparams,
+ gmx::make_at2con(molt, iparams,
gmx::FlexibleConstraintTreatment::Exclude);
bool haveDecoupledMode = false;
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
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;
-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);
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);
return makeAtomsToConstraintsList(numAtoms, ilist, iparams, flexibleConstraintTreatment);
}
-t_blocka make_at2con(const gmx_moltype_t &moltype,
- const t_iparams *iparams,
- FlexibleConstraintTreatment flexibleConstraintTreatment)
+t_blocka make_at2con(const gmx_moltype_t &moltype,
+ gmx::ArrayRef<const t_iparams> iparams,
+ FlexibleConstraintTreatment flexibleConstraintTreatment)
{
- return makeAtomsToConstraintsList(moltype.atoms.nr, moltype.ilist.data(), iparams, flexibleConstraintTreatment);
+ return makeAtomsToConstraintsList(moltype.atoms.nr, moltype.ilist.data(), iparams.data(), flexibleConstraintTreatment);
}
//! Return the number of flexible constraints in the \c ilist and \c iparams.
{
int count =
countFlexibleConstraintsTemplate(mtop.moltype[molblock.type].ilist.data(),
- mtop.ffparams.iparams);
+ mtop.ffparams.iparams.data());
nflexcon += molblock.nmol*count;
}
* \param[in] flexibleConstraintTreatment The flexible constraint treatment, see enum above
* \returns a block struct with all constraints for each atom
*/
-t_blocka make_at2con(const gmx_moltype_t &moltype,
- const t_iparams *iparams,
- FlexibleConstraintTreatment flexibleConstraintTreatment);
+t_blocka make_at2con(const gmx_moltype_t &moltype,
+ gmx::ArrayRef<const t_iparams> iparams,
+ FlexibleConstraintTreatment flexibleConstraintTreatment);
/*! \brief Returns a block struct to go from atoms to constraints
*
//! Recursing function to help find all adjacent constraints.
static void constr_recur(const t_blocka *at2con,
- const InteractionLists &ilist, const t_iparams *iparams,
+ const InteractionLists &ilist,
+ gmx::ArrayRef<const t_iparams> iparams,
gmx_bool bTopB,
int at, int depth, int nc, int *path,
real r0, real r1, real *r2max,
}
//! Find the interaction radius needed for constraints for this molecule type.
-static real constr_r_max_moltype(const gmx_moltype_t *molt,
- const t_iparams *iparams,
- const t_inputrec *ir)
+static real constr_r_max_moltype(const gmx_moltype_t *molt,
+ gmx::ArrayRef<const t_iparams> iparams,
+ const t_inputrec *ir)
{
int natoms, *path, at, count;
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);
/* Cost of 1 water with one Q atom or with 1/3 water (LJ negligible) */
fqw = c_group_qw;
- iparams = mtop->ffparams.iparams;
+ gmx::ArrayRef<const t_iparams> iparams = mtop->ffparams.iparams;
atnr = mtop->ffparams.atnr;
nw = 0;
nqlj = 0;
{
int atnr, a, nqlj, nq, nlj;
gmx_bool bQRF;
- t_iparams *iparams;
real r_eff;
double c_qlj, c_q, c_lj;
double nppa;
bQRF = (EEL_RF(ir->coulombtype) || ir->coulombtype == eelCUT);
- iparams = mtop->ffparams.iparams;
+ gmx::ArrayRef<const t_iparams> iparams = mtop->ffparams.iparams;
atnr = mtop->ffparams.atnr;
nqlj = 0;
nq = 0;
}
// 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;
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;
}
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);
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, ",
#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
} gmx_cmap_t;
-typedef struct gmx_ffparams_t
+/* Struct that holds all force field parameters for the simulated system */
+struct gmx_ffparams_t
{
- int ntypes;
- int atnr;
- t_functype *functype;
- t_iparams *iparams;
- double reppow; /* The repulsion power for VdW: C12*r^-reppow */
- real fudgeQQ; /* The scaling factor for Coulomb 1-4: f*q1*q2 */
- gmx_cmap_t cmap_grid; /* The dihedral correction maps */
-} gmx_ffparams_t;
+ /* Returns the number of function types, which matches the number of elements in iparams */
+ int numTypes() const
+ {
+ GMX_ASSERT(iparams.size() == functype.size(), "Parameters and function types go together");
+
+ return functype.size();
+ }
+
+ /* TODO: Consider merging functype and iparams, either by storing
+ * the functype in t_iparams or by putting both in a single class.
+ */
+ int atnr; /* The number of non-bonded atom types */
+ std::vector<t_functype> functype; /* The function type per type */
+ std::vector<t_iparams> iparams; /* Force field parameters per type */
+ double reppow; /* The repulsion power for VdW: C12*r^-reppow */
+ real fudgeQQ; /* The scaling factor for Coulomb 1-4: f*q1*q2 */
+ gmx_cmap_t cmap_grid; /* The dihedral correction maps */
+};
enum {
ilsortUNKNOWN, ilsortNO_FE, ilsortFE_UNSORTED, ilsortFE_SORTED
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
{
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();
{
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);
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());
}
}
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);
/* 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)
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;
iabuf_nalloc = 0;
iabuf = nullptr;
- iparams = idef->iparams;
+ const t_iparams *iparams = idef->iparams;
for (ftype = 0; ftype < F_NRE; ftype++)
{