2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2011,2014,2015,2016,2018,2019, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
37 #ifndef GMX_TOPOLOGY_TOPOLOGY_H
38 #define GMX_TOPOLOGY_TOPOLOGY_H
44 #include "gromacs/math/vectypes.h"
45 #include "gromacs/topology/atoms.h"
46 #include "gromacs/topology/block.h"
47 #include "gromacs/topology/forcefieldparameters.h"
48 #include "gromacs/topology/idef.h"
49 #include "gromacs/topology/symtab.h"
50 #include "gromacs/utility/unique_cptr.h"
54 egcTC, egcENER, egcACC, egcFREEZE,
55 egcUser1, egcUser2, egcVCM, egcCompressedX,
59 /* Names corresponding to groups */
60 extern const char *gtypes[egcNR+1];
62 /*! \brief Molecules type data: atoms, interactions and exclusions */
69 /*! \brief Deleted copy assignment operator to avoid (not) freeing pointers */
70 gmx_moltype_t &operator=(const gmx_moltype_t &) = delete;
72 /*! \brief Default copy constructor */
73 gmx_moltype_t(const gmx_moltype_t &) = default;
75 char **name; /**< Name of the molecule type */
76 t_atoms atoms; /**< The atoms in this molecule */
77 InteractionLists ilist; /**< Interaction list with local indices */
78 t_block cgs; /**< The charge groups */
79 t_blocka excls; /**< The exclusions */
82 /*! \brief Block of molecules of the same type, used in gmx_mtop_t */
85 int type = -1; /**< The molecule type index in mtop.moltype */
86 int nmol = 0; /**< The number of molecules in this block */
87 std::vector<gmx::RVec> posres_xA; /**< Position restraint coordinates for top A */
88 std::vector<gmx::RVec> posres_xB; /**< Position restraint coordinates for top B */
91 /*! \brief Indices for a gmx_molblock_t, derived from other gmx_mtop_t contents */
92 struct MoleculeBlockIndices
94 int numAtomsPerMolecule; /**< Number of atoms in a molecule in the block */
95 int globalAtomStart; /**< Global atom index of the first atom in the block */
96 int globalAtomEnd; /**< Global atom index + 1 of the last atom in the block */
97 int globalResidueStart; /**< Global residue index of the first residue in the block */
98 int residueNumberStart; /**< Residue numbers start from this value if the number of residues per molecule is <= maxres_renum */
99 int moleculeIndexStart; /**< Global molecule indexing starts from this value */
102 typedef struct gmx_groups_t
104 t_grps grps[egcNR]; /* Groups of things */
105 int ngrpname; /* Number of groupnames */
106 char ***grpname; /* Names of the groups */
108 unsigned char *grpnr[egcNR]; /* Group numbers or NULL */
112 * Returns group number of an input group for a given atom.
114 * Returns the group \p type for \p atom in \p group, or 0 if the
115 * entries for all atoms in the group are 0 and the pointer is thus null.
117 * \param[in] group Group to check.
118 * \param[in] type Type of group to check.
119 * \param[in] atom Atom to check if it has an entry.
121 int getGroupType (const gmx_groups_t &group, int type, int atom);
123 /* The global, complete system topology struct, based on molecule types.
124 * This structure should contain no data that is O(natoms) in memory.
126 * TODO: Find a solution for ensuring that the derived data is in sync
127 * with the primary data, possibly by converting to a class.
129 struct gmx_mtop_t //NOLINT(clang-analyzer-optin.performance.Padding)
135 //! Name of the topology.
136 char **name = nullptr;
137 //! Force field parameters used.
138 gmx_ffparams_t ffparams;
139 //! Vector of different molecule types.
140 std::vector<gmx_moltype_t> moltype;
141 //! Vector of different molecule blocks.
142 std::vector<gmx_molblock_t> molblock;
143 //! Are there intermolecular interactions?
144 bool bIntermolecularInteractions = false;
146 * List of intermolecular interactions using system wide
147 * atom indices, either NULL or size F_NRE
149 std::unique_ptr<InteractionLists> intermolecular_ilist = nullptr;
150 //! Number of global atoms.
152 //! Parameter for residue numbering.
153 int maxres_renum = 0;
154 //! The maximum residue number in moltype
156 //! Atomtype properties
157 t_atomtypes atomtypes;
158 //! Groups of atoms for different purposes
162 //! Tells whether we have valid molecule indices
163 bool haveMoleculeIndices = false;
164 /*! \brief List of global atom indices of atoms between which
165 * non-bonded interactions must be excluded.
167 std::vector<int> intermolecularExclusionGroup;
169 /* Derived data below */
170 //! Indices for each molblock entry for fast lookup of atom properties
171 std::vector<MoleculeBlockIndices> moleculeBlockIndices;
175 * The fully written out topology for a domain over its lifetime
177 * Also used in some analysis code.
179 struct gmx_localtop_t
181 //! Constructor used for normal operation, manages own resources.
186 //! The interaction function definition
188 //! Atomtype properties
189 t_atomtypes atomtypes;
190 //! The charge groups
194 //! Flag for domain decomposition so we don't free already freed memory.
195 bool useInDomainDecomp_ = false;
198 /* The old topology struct, completely written out, used in analysis tools */
199 typedef struct t_topology
201 char **name; /* Name of the topology */
202 t_idef idef; /* The interaction function definition */
203 t_atoms atoms; /* The atoms */
204 t_atomtypes atomtypes; /* Atomtype properties */
205 t_block cgs; /* The charge groups */
206 t_block mols; /* The molecules */
207 gmx_bool bIntermolecularInteractions; /* Inter.mol. int. ? */
208 t_blocka excls; /* The exclusions */
209 t_symtab symtab; /* The symbol table */
212 void init_top(t_topology *top);
213 void done_gmx_groups_t(gmx_groups_t *g);
214 void done_top(t_topology *top);
215 // Frees both t_topology and gmx_mtop_t when the former has been created from
217 void done_top_mtop(t_topology *top, gmx_mtop_t *mtop);
219 bool gmx_mtop_has_masses(const gmx_mtop_t *mtop);
220 bool gmx_mtop_has_charges(const gmx_mtop_t *mtop);
221 bool gmx_mtop_has_perturbed_charges(const gmx_mtop_t &mtop);
222 bool gmx_mtop_has_atomtypes(const gmx_mtop_t *mtop);
223 bool gmx_mtop_has_pdbinfo(const gmx_mtop_t *mtop);
225 void pr_mtop(FILE *fp, int indent, const char *title, const gmx_mtop_t *mtop,
226 gmx_bool bShowNumbers, gmx_bool bShowParameters);
227 void pr_top(FILE *fp, int indent, const char *title, const t_topology *top,
228 gmx_bool bShowNumbers, gmx_bool bShowParameters);
230 /*! \brief Compare two mtop topologies.
232 * \param[in] fp File pointer to write to.
233 * \param[in] mtop1 First topology to compare.
234 * \param[in] mtop2 Second topology to compare.
235 * \param[in] relativeTolerance Relative tolerance for comparison.
236 * \param[in] absoluteTolerance Absolute tolerance for comparison.
238 void compareMtop(FILE *fp, const gmx_mtop_t &mtop1, const gmx_mtop_t &mtop2, real relativeTolerance, real absoluteTolerance);
240 /*! \brief Check perturbation parameters in topology.
242 * \param[in] fp File pointer to write to.
243 * \param[in] mtop1 Topology to check perturbation parameters in.
244 * \param[in] relativeTolerance Relative tolerance for comparison.
245 * \param[in] absoluteTolerance Absolute tolerance for comparison.
247 void compareMtopAB(FILE *fp, const gmx_mtop_t &mtop1, real relativeTolerance, real absoluteTolerance);
249 /*! \brief Compare groups.
251 * \param[in] fp File pointer to write to.
252 * \param[in] g0 First group for comparison.
253 * \param[in] g1 Second group for comparison.
254 * \param[in] natoms0 Number of atoms for first group.
255 * \param[in] natoms1 Number of atoms for second group.
257 void compareAtomGroups(FILE *fp, const gmx_groups_t &g0, const gmx_groups_t &g1,
258 int natoms0, int natoms1);
260 //! Typedef for gmx_localtop in analysis tools.
261 using ExpandedTopologyPtr = std::unique_ptr<gmx_localtop_t>;
263 void copy_moltype(const gmx_moltype_t *src, gmx_moltype_t *dst);