+//! Container for returning molecule type and index information for an atom
+struct AtomIndexSet
+{
+ int local; //!< The local index
+ int global; //!< The global index
+ int withinMolecule; //!< The index in the molecule this atom belongs to
+};
+
+//! Container for returning molecule type and index information for an atom
+struct AtomInMolblock
+{
+ int molblockIndex; //!< The index into the molecule block array
+ int moleculeType; //!< The molecule type
+ int moleculeIndex; //!< The index of the molecule in the molecule block
+ int atomIndexInMolecule; //!< The index of the atom in the molecule
+};
+
+/*! \brief Return global topology molecule information for global atom index \p i_gl */
+static AtomInMolblock atomInMolblockFromGlobalAtomnr(ArrayRef<const MolblockIndices> molblockIndices,
+ const int globalAtomIndex)
+{
+ // Find the molecule block whose range of global atom indices
+ // includes globalAtomIndex, by being the first for which
+ // globalAtomIndex is not greater than its end.
+ auto molblockIt = std::partition_point(
+ molblockIndices.begin(),
+ molblockIndices.end(),
+ [globalAtomIndex](const MolblockIndices& mbi) { return mbi.a_end <= globalAtomIndex; });
+
+ AtomInMolblock aim;
+
+ aim.molblockIndex = std::distance(molblockIndices.begin(), molblockIt);
+ aim.moleculeType = molblockIt->type;
+ aim.moleculeIndex = (globalAtomIndex - molblockIt->a_start) / molblockIt->natoms_mol;
+ aim.atomIndexInMolecule =
+ (globalAtomIndex - molblockIt->a_start) - (aim.moleculeIndex) * molblockIt->natoms_mol;
+
+ return aim;
+}
+
+/*! \brief Store a vsite at the end of \p il, returns an array with parameter and atom indices