*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2011,2014,2015,2016,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2011,2014,2015,2016,2018, The GROMACS development team.
+ * Copyright (c) 2019,2020,2021, 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.
#include "gromacs/topology/idef.h"
#include "gromacs/topology/symtab.h"
#include "gromacs/utility/enumerationhelpers.h"
+#include "gromacs/utility/listoflists.h"
#include "gromacs/utility/unique_cptr.h"
enum class SimulationAtomGroupType : int
};
//! Short strings used for describing atom groups in log and energy files
-const char *shortName(SimulationAtomGroupType type);
+const char* shortName(SimulationAtomGroupType type);
-//const char *shortName(int type); // if necessary
+// const char *shortName(int type); // if necessary
/*! \brief Molecules type data: atoms, interactions and exclusions */
struct gmx_moltype_t
~gmx_moltype_t();
/*! \brief Deleted copy assignment operator to avoid (not) freeing pointers */
- gmx_moltype_t &operator=(const gmx_moltype_t &) = delete;
+ gmx_moltype_t& operator=(const gmx_moltype_t&) = delete;
/*! \brief Default copy constructor */
- gmx_moltype_t(const gmx_moltype_t &) = default;
+ gmx_moltype_t(const gmx_moltype_t&) = default;
- char **name; /**< Name of the molecule type */
- t_atoms atoms; /**< The atoms in this molecule */
- InteractionLists ilist; /**< Interaction list with local indices */
- t_block cgs; /**< The charge groups */
- t_blocka excls; /**< The exclusions */
+ char** name; /**< Name of the molecule type */
+ t_atoms atoms; /**< The atoms in this molecule */
+ InteractionLists ilist; /**< Interaction list with local indices */
+ gmx::ListOfLists<int> excls; /**< The exclusions */
};
/*! \brief Block of molecules of the same type, used in gmx_mtop_t */
/*! \brief Indices for a gmx_molblock_t, derived from other gmx_mtop_t contents */
struct MoleculeBlockIndices
{
- 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 */
+ 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 */
};
/*! \brief Contains the simulation atom groups.
*/
struct SimulationGroups
{
- SimulationGroups();
-
- ~SimulationGroups();
-
- //! Groups of particles
- gmx::EnumerationArray<SimulationAtomGroupType, t_grps> groups;
+ // TODO: collect groups and groupNumbers in a struct for each group type
+ //! Group numbers for each of the different SimulationAtomGroupType groups.
+ gmx::EnumerationArray<SimulationAtomGroupType, AtomGroupIndices> groups;
//! Names of groups, stored as pointer to the entries in the symbol table.
- std::vector<char **> groupNames;
- //! Group numbers for the different SimulationAtomGroupType groups.
- gmx::EnumerationArray < SimulationAtomGroupType, std::vector < unsigned char>> groupNumbers;
+ std::vector<char**> groupNames;
+ //! Indices into groups for each atom for each of the different SimulationAtomGroupType groups.
+ gmx::EnumerationArray<SimulationAtomGroupType, std::vector<unsigned char>> groupNumbers;
/*! \brief
- * Number of group numbers for a single SimulationGroup.
+ * Number of atoms for which group numbers are stored for a single SimulationGroup.
*
- * \param[in] group Integer value for the group type.
+ * \param[in] group The group type.
*/
- int numberOfGroupNumbers(SimulationAtomGroupType group) const { return groupNumbers[group].size(); }
+ int numberOfGroupNumbers(SimulationAtomGroupType group) const
+ {
+ return static_cast<int>(groupNumbers[group].size());
+ }
};
/*! \brief
* \param[in] type Type of group to check.
* \param[in] atom Atom to check if it has an entry.
*/
-int getGroupType (const SimulationGroups &group, SimulationAtomGroupType type, int atom);
+int getGroupType(const SimulationGroups& group, SimulationAtomGroupType type, int atom);
/* The global, complete system topology struct, based on molecule types.
* This structure should contain no data that is O(natoms) in memory.
~gmx_mtop_t();
//! Name of the topology.
- char **name = nullptr;
+ char** name = nullptr;
//! Force field parameters used.
- gmx_ffparams_t ffparams;
+ gmx_ffparams_t ffparams;
//! Vector of different molecule types.
- std::vector<gmx_moltype_t> moltype;
+ std::vector<gmx_moltype_t> moltype;
//! Vector of different molecule blocks.
- std::vector<gmx_molblock_t> molblock;
+ std::vector<gmx_molblock_t> molblock;
//! Are there intermolecular interactions?
- bool bIntermolecularInteractions = false;
+ bool bIntermolecularInteractions = false;
/* \brief
* List of intermolecular interactions using system wide
* atom indices, either NULL or size F_NRE
*/
- std::unique_ptr<InteractionLists> intermolecular_ilist = nullptr;
+ std::unique_ptr<InteractionLists> intermolecular_ilist = nullptr;
//! Number of global atoms.
- int natoms = 0;
- //! Parameter for residue numbering.
- int maxres_renum = 0;
- //! The maximum residue number in moltype
- int maxresnr = -1;
+ int natoms = 0;
//! Atomtype properties
- t_atomtypes atomtypes;
+ t_atomtypes atomtypes;
//! Groups of atoms for different purposes
- SimulationGroups groups;
- //! The symbol table
- t_symtab symtab;
+ SimulationGroups groups;
+ //! The legacy symbol table
+ t_symtab symtab;
//! Tells whether we have valid molecule indices
- bool haveMoleculeIndices = false;
+ bool haveMoleculeIndices = false;
/*! \brief List of global atom indices of atoms between which
* non-bonded interactions must be excluded.
*/
- std::vector<int> intermolecularExclusionGroup;
+ std::vector<int> intermolecularExclusionGroup;
+
+ //! Maximum number of residues in molecule to trigger renumbering of residues
+ int maxResiduesPerMoleculeToTriggerRenumber() const
+ {
+ return maxResiduesPerMoleculeToTriggerRenumber_;
+ }
+ //! Maximum residue number that is not renumbered.
+ int maxResNumberNotRenumbered() const { return maxResNumberNotRenumbered_; }
+ /*! \brief Finalize this data structure.
+ *
+ * Should be called after generating or reading mtop, to set some compute
+ * intesive variables to avoid N^2 operations later on.
+ *
+ * \todo Move into a builder class, once available.
+ */
+ void finalize();
- /* Derived data below */
+ /* Derived data below */
//! Indices for each molblock entry for fast lookup of atom properties
std::vector<MoleculeBlockIndices> moleculeBlockIndices;
+
+private:
+ //! Build the molblock indices
+ void buildMolblockIndices();
+ //! Maximum number of residues in molecule to trigger renumbering of residues
+ int maxResiduesPerMoleculeToTriggerRenumber_ = 0;
+ //! The maximum residue number in moltype that is not renumbered
+ int maxResNumberNotRenumbered_ = -1;
};
/*! \brief
struct gmx_localtop_t
{
//! Constructor used for normal operation, manages own resources.
- gmx_localtop_t();
-
- ~gmx_localtop_t();
+ gmx_localtop_t(const gmx_ffparams_t& ffparams);
//! The interaction function definition
- t_idef idef;
- //! Atomtype properties
- t_atomtypes atomtypes;
+ InteractionDefinitions idef;
//! The exclusions
- t_blocka excls;
- //! Flag for domain decomposition so we don't free already freed memory.
- bool useInDomainDecomp_ = false;
+ gmx::ListOfLists<int> excls;
};
/* The old topology struct, completely written out, used in analysis tools */
typedef struct t_topology
{
- char **name; /* Name of the topology */
- t_idef idef; /* The interaction function definition */
- t_atoms atoms; /* The atoms */
- t_atomtypes atomtypes; /* Atomtype properties */
- t_block cgs; /* The charge groups */
- t_block mols; /* The molecules */
- gmx_bool bIntermolecularInteractions; /* Inter.mol. int. ? */
- t_blocka excls; /* The exclusions */
- t_symtab symtab; /* The symbol table */
+ char** name; /* Name of the topology */
+ t_idef idef; /* The interaction function definition */
+ t_atoms atoms; /* The atoms */
+ t_atomtypes atomtypes; /* Atomtype properties */
+ t_block mols; /* The molecules */
+ gmx_bool bIntermolecularInteractions; /* Inter.mol. int. ? */
+ /* Note that the exclusions are not stored in t_topology */
+ t_symtab symtab; /* The symbol table */
} t_topology;
-void init_top(t_topology *top);
-void done_top(t_topology *top);
+void init_top(t_topology* top);
+void done_top(t_topology* top);
// Frees both t_topology and gmx_mtop_t when the former has been created from
// the latter.
-void done_top_mtop(t_topology *top, gmx_mtop_t *mtop);
+void done_top_mtop(t_topology* top, gmx_mtop_t* mtop);
-bool gmx_mtop_has_masses(const gmx_mtop_t *mtop);
-bool gmx_mtop_has_charges(const gmx_mtop_t *mtop);
-bool gmx_mtop_has_perturbed_charges(const gmx_mtop_t &mtop);
-bool gmx_mtop_has_atomtypes(const gmx_mtop_t *mtop);
-bool gmx_mtop_has_pdbinfo(const gmx_mtop_t *mtop);
+bool gmx_mtop_has_masses(const gmx_mtop_t* mtop);
+bool gmx_mtop_has_charges(const gmx_mtop_t* mtop);
+bool gmx_mtop_has_perturbed_charges(const gmx_mtop_t& mtop);
+bool gmx_mtop_has_atomtypes(const gmx_mtop_t* mtop);
+bool gmx_mtop_has_pdbinfo(const gmx_mtop_t* mtop);
-void pr_mtop(FILE *fp, int indent, const char *title, const gmx_mtop_t *mtop,
- gmx_bool bShowNumbers, gmx_bool bShowParameters);
-void pr_top(FILE *fp, int indent, const char *title, const t_topology *top,
- gmx_bool bShowNumbers, gmx_bool bShowParameters);
+void pr_mtop(FILE* fp, int indent, const char* title, const gmx_mtop_t* mtop, gmx_bool bShowNumbers, gmx_bool bShowParameters);
+void pr_top(FILE* fp, int indent, const char* title, const t_topology* top, gmx_bool bShowNumbers, gmx_bool bShowParameters);
/*! \brief Compare two mtop topologies.
*
* \param[in] relativeTolerance Relative tolerance for comparison.
* \param[in] absoluteTolerance Absolute tolerance for comparison.
*/
-void compareMtop(FILE *fp, const gmx_mtop_t &mtop1, const gmx_mtop_t &mtop2, real relativeTolerance, real absoluteTolerance);
+void compareMtop(FILE* fp, const gmx_mtop_t& mtop1, const gmx_mtop_t& mtop2, real relativeTolerance, real absoluteTolerance);
/*! \brief Check perturbation parameters in topology.
*
* \param[in] relativeTolerance Relative tolerance for comparison.
* \param[in] absoluteTolerance Absolute tolerance for comparison.
*/
-void compareMtopAB(FILE *fp, const gmx_mtop_t &mtop1, real relativeTolerance, real absoluteTolerance);
+void compareMtopAB(FILE* fp, const gmx_mtop_t& mtop1, real relativeTolerance, real absoluteTolerance);
/*! \brief Compare groups.
*
* \param[in] natoms0 Number of atoms for first group.
* \param[in] natoms1 Number of atoms for second group.
*/
-void compareAtomGroups(FILE *fp, const SimulationGroups &g0, const SimulationGroups &g1,
- int natoms0, int natoms1);
+void compareAtomGroups(FILE* fp, const SimulationGroups& g0, const SimulationGroups& g1, int natoms0, int natoms1);
//! Typedef for gmx_localtop in analysis tools.
using ExpandedTopologyPtr = std::unique_ptr<gmx_localtop_t>;
-void copy_moltype(const gmx_moltype_t *src, gmx_moltype_t *dst);
+void copy_moltype(const gmx_moltype_t* src, gmx_moltype_t* dst);
#endif