natoms_mol is derived information, so moved to MolecluleBlockIndices.
Change-Id: I10080dc8fd43bac1f1976551d66218fcc1d2c53c
/*! \brief The number of integer item in the local state, used for broadcasting of the state */
#define NITEM_DD_INIT_LOCAL_STATE 5
-typedef struct {
- int *index; /* Index for each atom into il */
- int *il; /* ftype|type|a0|...|an|ftype|... */
-} reverse_ilist_t;
+struct reverse_ilist_t
+{
+ int *index; /* Index for each atom into il */
+ int *il; /* ftype|type|a0|...|an|ftype|... */
+ int numAtomsInMolecule; /* The number of atoms in this molecule */
+};
typedef struct {
int a_start;
int a_end = 0;
for (const gmx_molblock_t &molb : mtop->molblock)
{
- int a_start = a_end;
- a_end = a_start + molb.nmol*molb.natoms_mol;
+ const gmx_moltype_t &moltype = mtop->moltype[molb.type];
+ int a_start = a_end;
+ a_end = a_start + molb.nmol*moltype.atoms.nr;
print_missing_interactions_mb(fplog, cr, rt,
- *(mtop->moltype[molb.type].name),
+ *(moltype.name),
&rt->ril_mt[molb.type],
- a_start, a_end, molb.natoms_mol,
+ a_start, a_end, moltype.atoms.nr,
molb.nmol,
idef);
}
sfree(count);
+ ril_mt->numAtomsInMolecule = atoms->nr;
+
return nint_mt;
}
int i = 0;
for (size_t mb = 0; mb < mtop->molblock.size(); mb++)
{
- rt->mbi[mb].a_start = i;
- i += mtop->molblock[mb].nmol*mtop->molblock[mb].natoms_mol;
- rt->mbi[mb].a_end = i;
- rt->mbi[mb].natoms_mol = mtop->molblock[mb].natoms_mol;
- rt->mbi[mb].type = mtop->molblock[mb].type;
+ const gmx_molblock_t &molb = mtop->molblock[mb];
+ int numAtomsPerMol = mtop->moltype[molb.type].atoms.nr;
+ rt->mbi[mb].a_start = i;
+ i += molb.nmol*numAtomsPerMol;
+ rt->mbi[mb].a_end = i;
+ rt->mbi[mb].natoms_mol = numAtomsPerMol;
+ rt->mbi[mb].type = molb.type;
}
rt->nthread = gmx_omp_nthreads_get(emntDomdec);
}
/*! \brief Store a position restraint in idef and iatoms, complex because the parameters are different for each entry */
-static void add_posres(int mol, int a_mol, const gmx_molblock_t *molb,
+static void add_posres(int mol, int a_mol, int numAtomsInMolecule,
+ const gmx_molblock_t *molb,
t_iatom *iatoms, const t_iparams *ip_in,
t_idef *idef)
{
*ip = ip_in[iatoms[0]];
/* Get the position restraint coordinates from the molblock */
- a_molb = mol*molb->natoms_mol + a_mol;
- if (a_molb >= static_cast<int>(molb->posres_xA.size()))
- {
- gmx_incons("Not enough position restraint coordinates");
- }
+ a_molb = mol*numAtomsInMolecule + a_mol;
+ GMX_ASSERT(a_molb < static_cast<int>(molb->posres_xA.size()), "We need a sufficient number of position restraint coordinates");
ip->posres.pos0A[XX] = molb->posres_xA[a_molb][XX];
ip->posres.pos0A[YY] = molb->posres_xA[a_molb][YY];
ip->posres.pos0A[ZZ] = molb->posres_xA[a_molb][ZZ];
}
/*! \brief Store a flat-bottomed position restraint in idef and iatoms, complex because the parameters are different for each entry */
-static void add_fbposres(int mol, int a_mol, const gmx_molblock_t *molb,
+static void add_fbposres(int mol, int a_mol, int numAtomsInMolecule,
+ const gmx_molblock_t *molb,
t_iatom *iatoms, const t_iparams *ip_in,
t_idef *idef)
{
/* Copy the force constants */
*ip = ip_in[iatoms[0]];
- /* Get the position restriant coordinats from the molblock */
- a_molb = mol*molb->natoms_mol + a_mol;
- if (a_molb >= static_cast<int>(molb->posres_xA.size()))
- {
- gmx_incons("Not enough position restraint coordinates");
- }
+ /* Get the position restraint coordinats from the molblock */
+ a_molb = mol*numAtomsInMolecule + a_mol;
+ GMX_ASSERT(a_molb < static_cast<int>(molb->posres_xA.size()), "We need a sufficient number of position restraint coordinates");
/* Take reference positions from A position of normal posres */
ip->fbposres.pos0[XX] = molb->posres_xA[a_molb][XX];
ip->fbposres.pos0[YY] = molb->posres_xA[a_molb][YY];
static inline void
check_assign_interactions_atom(int i, int i_gl,
int mol, int i_mol,
+ int numAtomsInMolecule,
const int *index, const int *rtil,
gmx_bool bInterMolInteractions,
int ind_start, int ind_end,
tiatoms[1] = i;
if (ftype == F_POSRES)
{
- add_posres(mol, i_mol, molb, tiatoms, ip_in,
- idef);
+ add_posres(mol, i_mol, numAtomsInMolecule,
+ molb, tiatoms, ip_in, idef);
}
else if (ftype == F_FBPOSRES)
{
- add_fbposres(mol, i_mol, molb, tiatoms, ip_in,
- idef);
+ add_fbposres(mol, i_mol, numAtomsInMolecule,
+ molb, tiatoms, ip_in, idef);
}
}
else
rtil = rt->ril_mt[mt].il;
check_assign_interactions_atom(i, i_gl, mol, i_mol,
+ rt->ril_mt[mt].numAtomsInMolecule,
index, rtil, FALSE,
index[i_mol], index[i_mol+1],
dd, zones,
rtil = rt->ril_intermol.il;
check_assign_interactions_atom(i, i_gl, mol, i_mol,
+ rt->ril_mt[mt].numAtomsInMolecule,
index, rtil, TRUE,
index[i_gl], index[i_gl + 1],
dd, zones,
do_blocka(fio, &molt->excls, bRead);
}
-static void do_molblock(t_fileio *fio, gmx_molblock_t *molb, gmx_bool bRead)
+static void do_molblock(t_fileio *fio, gmx_molblock_t *molb,
+ int numAtomsPerMolecule,
+ gmx_bool bRead)
{
gmx_fio_do_int(fio, molb->type);
gmx_fio_do_int(fio, molb->nmol);
- gmx_fio_do_int(fio, molb->natoms_mol);
+ /* To maintain forward topology reading compatibility, we store #atoms.
+ * TODO: Change this to conditional reading of a dummy int when we
+ * increase tpx_generation.
+ */
+ gmx_fio_do_int(fio, numAtomsPerMolecule);
/* Position restraint coordinates */
int numPosres_xA = molb->posres_xA.size();
gmx_fio_do_int(fio, numPosres_xA);
}
for (gmx_molblock_t &molblock : mtop->molblock)
{
- do_molblock(fio, &molblock, bRead);
+ int numAtomsPerMolecule = (bRead ? 0 : mtop->moltype[molblock.type].atoms.nr);
+ do_molblock(fio, &molblock, numAtomsPerMolecule, bRead);
}
gmx_fio_do_int(fio, mtop->natoms);
}
}
}
- a_mol += molb.natoms_mol;
+ a_mol += molt->atoms.nr;
}
}
{
/* Merge consecutive blocks with the same molecule type */
sys->molblock.back().nmol += molb.nmol;
- sys->natoms += molb.nmol*sys->molblock.back().natoms_mol;
+ sys->natoms += molb.nmol*sys->moltype[sys->molblock.back().type].atoms.nr;
}
else if (molb.nmol > 0)
{
/* Add a new molblock to the topology */
sys->molblock.push_back(molb);
gmx_molblock_t &molbs = sys->molblock.back();
- molbs.natoms_mol = molinfo[molbs.type].atoms.nr;
- sys->natoms += molbs.nmol*molbs.natoms_mol;
+ sys->natoms += molbs.nmol*molinfo[molbs.type].atoms.nr;
}
}
if (sys->molblock.empty())
block_bc(cr, molb->nmol);
bc_vector_of_rvec(cr, &molb->posres_xA);
bc_vector_of_rvec(cr, &molb->posres_xB);
- block_bc(cr, molb->natoms_mol);
if (debug)
{
fprintf(debug, "after bc_molblock\n");
mem_p->zmed = (zmax-zmin)/2+zmin;
/*number of membrane molecules in protein box*/
- nmolbox = count/mtop->molblock[block].natoms_mol;
+ nmolbox = count/mtop->moltype[mtop->molblock[block].type].atoms.nr;
/*membrane area within the box defined by the min and max coordinates of the embedded molecule*/
mem_area = (pos_ins->xmax[XX]-pos_ins->xmin[XX])*(pos_ins->xmax[YY]-pos_ins->xmin[YY]);
/*rough estimate of area per lipid, assuming there is only one type of lipid in the membrane*/
{
z_lip += r[k][ZZ];
}
- z_lip /= mtop->molblock[block].natoms_mol;
+ z_lip /= molecules.index[mol_id+1] - molecules.index[mol_id];
if (z_lip < mem_p->zmed)
{
nlower++;
{
z_lip += r[k][ZZ];
}
- z_lip /= mtop->molblock[block].natoms_mol;
+ z_lip /= molecules.index[mol_id+1] - molecules.index[mol_id];
if (nupper > nlower && z_lip < mem_p->zmed)
{
rm_p->mol[nrm] = mol_id;
at = molecules.index[mol_id];
block = rm_p->block[i];
mtop->molblock[block].nmol--;
- for (j = 0; j < mtop->molblock[block].natoms_mol; j++)
+ for (j = 0; j < mtop->moltype[mtop->molblock[block].type].atoms.nr; j++)
{
list[n] = at+j;
n++;
{
/*loop over molecule blocks*/
type = mtop->molblock[i].type;
- natom = mtop->molblock[i].natoms_mol;
+ natom = mtop->moltype[type].atoms.nr;
nmol = mtop->molblock[i].nmol;
for (j = 0; j < natom*nmol && bRM[type] == TRUE; j++)
as = 0;
for (const gmx_molblock_t &molb : mtop->molblock)
{
- if (molb.natoms_mol == 1 ||
- (!bFirst && mtop->moltype[molb.type].cgs.nr == 1))
+ const gmx_moltype_t &moltype = mtop->moltype[molb.type];
+ if (moltype.atoms.nr == 1 ||
+ (!bFirst && moltype.cgs.nr == 1))
{
/* Just one atom or charge group in the molecule, no PBC required */
- as += molb.nmol*molb.natoms_mol;
+ as += molb.nmol*moltype.atoms.nr;
}
else
{
/* Pass NULL iso fplog to avoid graph prints for each molecule type */
- mk_graph_ilist(nullptr, mtop->moltype[molb.type].ilist,
- 0, molb.natoms_mol, FALSE, FALSE, graph);
+ mk_graph_ilist(nullptr, moltype.ilist,
+ 0, moltype.atoms.nr, FALSE, FALSE, graph);
for (mol = 0; mol < molb.nmol; mol++)
{
* since we no longer need this graph.
*/
- as += molb.natoms_mol;
+ as += moltype.atoms.nr;
}
done_graph(graph);
}
--first_atom;
}
int first_mol_atom = top->moleculeBlockIndices[molb].globalAtomStart;
- first_mol_atom += molnr*top->molblock[molb].natoms_mol;
+ first_mol_atom += molnr*top->moleculeBlockIndices[molb].numAtomsPerMolecule;
first_atom = first_mol_atom + first_atom + 1;
last_atom = first_mol_atom + last_atom - 1;
for (int j = first_atom; j <= last_atom; ++j)
{
++molb;
}
- const int numAtomsInMol = top->molblock[molb].natoms_mol;
const MoleculeBlockIndices &blockIndices = top->moleculeBlockIndices[molb];
- const int atomStart = blockIndices.globalAtomStart + (id - blockIndices.moleculeIndexStart)*numAtomsInMol;
- for (int j = 0; j < numAtomsInMol; ++j)
+ const int atomStart = blockIndices.globalAtomStart + (id - blockIndices.moleculeIndexStart)*blockIndices.numAtomsPerMolecule;
+ for (int j = 0; j < blockIndices.numAtomsPerMolecule; ++j)
{
t->a[t->nra++] = atomStart + j;
}
mtop_->molblock.resize(1);
mtop_->molblock[0].type = 0;
mtop_->molblock[0].nmol = 1;
- mtop_->molblock[0].natoms_mol = count;
mtop_->natoms = count;
mtop_->maxres_renum = 0;
gmx_mtop_finalize(mtop_.get());
GMX_RELEASE_ASSERT(atoms.atom[atoms.nr-1].resind != nres,
"The residues should break at molecule boundaries");
atoms.nres = nres;
- molblock.natoms_mol = moleculeSize;
mtop_->haveMoleculeIndices = true;
+ gmx_mtop_finalize(mtop_.get());
}
void TopologyManager::initFrameIndices(const ArrayRef<const int> &index)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* first solvent atom: */
int molb = 0;
mtopGetMolblockIndex(mtop, ind[0], &molb, nullptr, nullptr);
- int apm = mtop->molblock[molb].natoms_mol;
+ int apm = mtop->moleculeBlockIndices[molb].numAtomsPerMolecule;
if (bVerbose)
{
for (int i = 1; i < nat; i++)
{
mtopGetMolblockIndex(mtop, ind[i], &molb, nullptr, nullptr);
- if (apm != mtop->molblock[molb].natoms_mol)
+ if (apm != mtop->moleculeBlockIndices[molb].numAtomsPerMolecule)
{
gmx_fatal(FARGS, "Not all molecules of swap group %d consist of %d atoms.",
igroup, apm);
mtop->moltype[0].excls = top.excls;
mtop->molblock.resize(1);
- mtop->molblock[0].type = 0;
- mtop->molblock[0].nmol = 1;
- mtop->molblock[0].natoms_mol = top.atoms.nr;
+ mtop->molblock[0].type = 0;
+ mtop->molblock[0].nmol = 1;
- mtop->natoms = top.atoms.nr;
+ mtop->natoms = top.atoms.nr;
}
static void zeroq(int index[], gmx_mtop_t *mtop)
{
GMX_ASSERT(globalAtomIndex >= 0 && globalAtomIndex < mtop->natoms, "The atom index to look up should be within range");
GMX_ASSERT(moleculeBlock != nullptr, "molBlock can not be NULL");
- GMX_ASSERT(*moleculeBlock >= 0 && *moleculeBlock < static_cast<int>(mtop->molblock.size()), "The starting molecule block index for the search should be within range");
- GMX_ASSERT(!mtop->moleculeBlockIndices.empty(), "The molecule block indices should be present when calling mtopGetMoleculeBlockIndex");
+ GMX_ASSERT(*moleculeBlock >= 0 && *moleculeBlock < static_cast<int>(mtop->moleculeBlockIndices.size()), "The starting molecule block index for the search should be within range and moleculeBlockIndices should not be empty");
/* Search the molecue block index using bisection */
int molBlock0 = -1;
*moleculeBlock = ((molBlock0 + molBlock1 + 1) >> 1);
}
- int molIndex = (globalAtomIndex - globalAtomStart) / mtop->molblock[*moleculeBlock].natoms_mol;
+ int molIndex = (globalAtomIndex - globalAtomStart) / mtop->moleculeBlockIndices[*moleculeBlock].numAtomsPerMolecule;
if (moleculeIndex != nullptr)
{
*moleculeIndex = molIndex;
}
if (atomIndexInMolecule != nullptr)
{
- *atomIndexInMolecule = globalAtomIndex - globalAtomStart - molIndex*mtop->molblock[*moleculeBlock].natoms_mol;
+ *atomIndexInMolecule = globalAtomIndex - globalAtomStart - molIndex*mtop->moleculeBlockIndices[*moleculeBlock].numAtomsPerMolecule;
}
}
MoleculeBlockIndices &indices = mtop->moleculeBlockIndices[mb];
const int numResPerMol = mtop->moltype[molb.type].atoms.nres;
+ indices.numAtomsPerMolecule = mtop->moltype[molb.type].atoms.nr;
indices.globalAtomStart = atomIndex;
indices.globalResidueStart = residueIndex;
- atomIndex += molb.nmol*molb.natoms_mol;
+ atomIndex += molb.nmol*indices.numAtomsPerMolecule;
residueIndex += molb.nmol*numResPerMol;
indices.globalAtomEnd = atomIndex;
indices.residueNumberStart = residueNumberStart;
if (iloop->mol >= 0)
{
- iloop->a_offset += iloop->mtop->molblock[iloop->mblock].natoms_mol;
+ iloop->a_offset += iloop->mtop->moleculeBlockIndices[iloop->mblock].numAtomsPerMolecule;
}
iloop->mol++;
index[globalMolIndex] = globalAtomIndex;
for (const gmx_molblock_t &molb : mtop.molblock)
{
+ int numAtomsPerMolecule = mtop.moltype[molb.type].atoms.nr;
for (int mol = 0; mol < molb.nmol; mol++)
{
- globalAtomIndex += molb.natoms_mol;
+ globalAtomIndex += numAtomsPerMolecule;
globalMolIndex += 1;
index[globalMolIndex] = globalAtomIndex;
}
mtop->molblock.resize(1);
mtop->molblock[0].type = 0;
mtop->molblock[0].nmol = 1;
- mtop->molblock[0].natoms_mol = mtop->moltype[mtop->molblock[0].type].atoms.nr;
mtop->bIntermolecularInteractions = FALSE;
- mtop->natoms = mtop->molblock[0].natoms_mol;
+ mtop->natoms = atoms->nr;
mtop->haveMoleculeIndices = false;
fprintf(fp, "%-20s = %d \"%s\"\n",
"moltype", molb->type, *(molt[molb->type].name));
pr_int(fp, indent, "#molecules", molb->nmol);
- pr_int(fp, indent, "#atoms_mol", molb->natoms_mol);
pr_int(fp, indent, "#posres_xA", molb->posres_xA.size());
if (!molb->posres_xA.empty())
{
int nmol = 0; /**< The number of molecules in this block */
std::vector<gmx::RVec> posres_xA; /**< Position restraint coordinates for top A */
std::vector<gmx::RVec> posres_xB; /**< Position restraint coordinates for top B */
-
- /* Convenience information, derived from other gmx_mtop_t contents */
- int natoms_mol = 0; /**< The number of atoms in one molecule */
};
/*! \brief Indices for a gmx_molblock_t, derived from other gmx_mtop_t contents */
struct MoleculeBlockIndices
{
- int globalAtomStart; /**< Global atom index of the first atom in the block */
- int globalAtomEnd; /**< Global atom index + 1 of the last atom in the block */
- int globalResidueStart; /**< Global residue index of the first residue in the block */
- int residueNumberStart; /**< Residue numbers start from this value if the number of residues per molecule is <= maxres_renum */
- int moleculeIndexStart; /**< Global molecule indexing starts from this value */
+ int numAtomsPerMolecule; /**< Number of atoms in a molecule in the block */
+ int globalAtomStart; /**< Global atom index of the first atom in the block */
+ int globalAtomEnd; /**< Global atom index + 1 of the last atom in the block */
+ int globalResidueStart; /**< Global residue index of the first residue in the block */
+ int residueNumberStart; /**< Residue numbers start from this value if the number of residues per molecule is <= maxres_renum */
+ int moleculeIndexStart; /**< Global molecule indexing starts from this value */
};
typedef struct gmx_groups_t