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) 2013,2014,2015,2016,2018 by the GROMACS development team.
7 * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
38 #ifndef GMX_TOPOLOGY_IDEF_H
39 #define GMX_TOPOLOGY_IDEF_H
46 #include "gromacs/math/vectypes.h"
47 #include "gromacs/topology/ifunc.h"
48 #include "gromacs/utility/real.h"
50 struct gmx_ffparams_t;
52 typedef union t_iparams
54 /* Some parameters have A and B values for free energy calculations.
55 * The B values are not used for regular simulations of course.
56 * Free Energy for nonbondeds can be computed by changing the atom type.
57 * The harmonic type is used for all harmonic potentials:
58 * bonds, angles and improper dihedrals
66 real rA, krA, rB, krB;
70 real klinA, aA, klinB, aB;
74 real lowA, up1A, up2A, kA, lowB, up1B, up2B, kB;
76 /* No free energy supported for cubic bonds, FENE, WPOL or cross terms */
91 real r1e, r2e, r3e, krt;
95 real thetaA, kthetaA, r13A, kUBA, thetaB, kthetaB, r13B, kUBB;
107 real alpha, drcut, khyp;
111 real al_x, al_y, al_z, rOH, rHH, rOD;
115 real a, alpha1, alpha2;
123 real c6A, c12A, c6B, c12B;
127 real fqq, qi, qj, c6, c12;
131 real qi, qj, c6, c12;
133 /* Proper dihedrals can not have different multiplicity when
134 * doing free energy calculations, because the potential would not
135 * be periodic anymore.
147 /* Settle can not be used for Free energy calculations of water bond geometry.
148 * Use shake (or lincs) instead if you have to change the water bonds.
156 real b0A, cbA, betaA, b0B, cbB, betaB;
160 real pos0A[DIM], fcA[DIM], pos0B[DIM], fcB[DIM];
164 real pos0[DIM], r, k;
169 real rbcA[NR_RBDIHS], rbcB[NR_RBDIHS];
173 real cbtcA[NR_CBTDIHS], cbtcB[NR_CBTDIHS];
177 real a, b, c, d, e, f;
184 /* NOTE: npair is only set after reading the tpx file */
187 real low, up1, up2, kfac;
188 int type, label, npair;
192 real phiA, dphiA, kfacA, phiB, dphiB, kfacB;
196 int ex, power, label;
211 real buf[MAXFORCEPARAM];
212 } generic; /* Conversion */
215 typedef int t_functype;
217 /* List of listed interactions, see description further down.
219 * TODO: Consider storing the function type as well.
220 * TODO: Consider providing per interaction access.
222 struct InteractionList
224 /* Returns the total number of elements in iatoms */
225 int size() const { return static_cast<int>(iatoms.size()); }
227 /* Returns whether the list is empty */
228 bool empty() const { return iatoms.empty(); }
230 /* Adds one interaction to the list */
231 template<std::size_t numAtoms>
232 void push_back(const int parameterType, const std::array<int, numAtoms>& atoms)
234 const std::size_t oldSize = iatoms.size();
235 iatoms.resize(iatoms.size() + 1 + numAtoms);
236 iatoms[oldSize] = parameterType;
237 for (std::size_t i = 0; i < numAtoms; i++)
239 iatoms[oldSize + 1 + i] = atoms[i];
243 /* Adds one interaction to the list */
244 void push_back(const int parameterType, const int numAtoms, const int* atoms)
246 const std::size_t oldSize = iatoms.size();
247 iatoms.resize(iatoms.size() + 1 + numAtoms);
248 iatoms[oldSize] = parameterType;
249 for (int i = 0; i < numAtoms; i++)
251 iatoms[oldSize + 1 + i] = atoms[i];
255 /* Appends \p ilist at the back of the list */
256 void append(const InteractionList& ilist)
258 iatoms.insert(iatoms.end(), ilist.iatoms.begin(), ilist.iatoms.end());
261 /* Clears the list */
262 void clear() { iatoms.clear(); }
264 /* List of interactions, see explanation further down */
265 std::vector<int> iatoms;
268 /* List of interaction lists, one list for each interaction type
270 * TODO: Consider only including entries in use instead of all F_NRE
272 using InteractionLists = std::array<InteractionList, F_NRE>;
274 /* Deprecated list of listed interactions */
277 /* Returns the total number of elements in iatoms */
278 int size() const { return nr; }
280 /* Returns whether the list is empty */
281 bool empty() const { return nr == 0; }
288 /* TODO: Remove t_ilist and remove templating on list type in mshift.cpp */
291 * The structs InteractionList and t_ilist defines a list of atoms with their interactions.
292 * General field description:
294 * the size (nr elements) of the interactions array (iatoms[]).
296 * specifies which atoms are involved in an interaction of a certain
297 * type. The layout of this array is as follows:
299 * +-----+---+---+---+-----+---+---+-----+---+---+---+-----+---+---+...
300 * |type1|at1|at2|at3|type2|at1|at2|type1|at1|at2|at3|type3|at1|at2|
301 * +-----+---+---+---+-----+---+---+-----+---+---+---+-----+---+---+...
303 * So for interaction type type1 3 atoms are needed, and for type2 and
304 * type3 only 2. The type identifier is used to select the function to
305 * calculate the interaction and its actual parameters. This type
306 * identifier is an index in a params[] and functype[] array.
309 /*! \brief Type for returning a list of InteractionList references
311 * TODO: Remove when the function type is made part of InteractionList
313 struct InteractionListHandle
315 const int functionType; //!< The function type
316 const std::vector<int>& iatoms; //!< Reference to interaction list
319 /*! \brief Returns a list of all non-empty InteractionList entries with any of the interaction flags in \p flags set
321 * \param[in] ilists Set of interaction lists
322 * \param[in] flags Bit mask with one or more IF_... bits set
324 static inline std::vector<InteractionListHandle> extractILists(const InteractionLists& ilists, int flags)
326 std::vector<InteractionListHandle> handles;
327 for (size_t ftype = 0; ftype < ilists.size(); ftype++)
329 if ((interaction_function[ftype].flags & flags) && !ilists[ftype].empty())
331 handles.push_back({ static_cast<int>(ftype), ilists[ftype].iatoms });
337 /*! \brief Returns the stride for the iatoms array in \p ilistHandle
339 * \param[in] ilistHandle The ilist to return the stride for
341 static inline int ilistStride(const InteractionListHandle& ilistHandle)
343 return 1 + NRAL(ilistHandle.functionType);
346 struct gmx_cmapdata_t
348 std::vector<real> cmap; /* Has length 4*grid_spacing*grid_spacing, */
349 /* there are 4 entries for each cmap type (V,dVdx,dVdy,d2dVdxdy) */
354 int grid_spacing = 0; /* Grid spacing */
355 std::vector<gmx_cmapdata_t> cmapdata; /* Lists of grids with actual, pre-interpolated data */
366 /* Struct with list of interaction parameters and lists of interactions
368 * TODO: Convert to a proper class with private data members so we can
369 * ensure that the free-energy sorting and sorting setting is consistent.
371 class InteractionDefinitions
376 * \param[in] ffparams The interaction parameters, the lifetime of the created object should not exceed the lifetime of the passed parameters
378 InteractionDefinitions(const gmx_ffparams_t& ffparams);
380 // Clears data not read in from ffparams
383 // The interaction parameters
384 const std::vector<t_iparams>& iparams;
385 // The function type per type
386 const std::vector<int>& functype;
387 // Position restraint interaction parameters
388 std::vector<t_iparams> iparams_posres;
389 // Flat-bottomed position restraint parameters
390 std::vector<t_iparams> iparams_fbposres;
391 // The list of interactions for each type. Note that some, such as LJ and COUL will have 0 entries.
392 std::array<InteractionList, F_NRE> il;
393 /* The number of non-perturbed interactions at the start of each entry in il */
394 std::array<int, F_NRE> numNonperturbedInteractions;
395 // The sorting state of interaction in il
396 int ilsort = ilsortUNKNOWN;
397 // The dihedral correction maps
398 gmx_cmap_t cmap_grid;
401 /* Deprecated interation definitions, used in t_topology */
406 t_functype* functype;
409 t_iparams * iparams_posres, *iparams_fbposres;
416 * The struct t_idef defines all the interactions for the complete
417 * simulation. The structure is setup in such a way that the multinode
418 * version of the program can use it as easy as the single node version.
419 * General field description:
421 * defines the number of elements in functype[] and param[].
423 * the node id (if parallel machines)
425 * the number of atomtypes
426 * t_functype *functype
427 * array of length ntypes, defines for every force type what type of
428 * function to use. Every "bond" with the same function but different
429 * force parameters is a different force type. The type identifier in the
430 * forceatoms[] array is an index in this array.
432 * array of length ntypes, defines the parameters for every interaction
433 * type. The type identifier in the actual interaction list
434 * (ilist[ftype].iatoms[]) is an index in this array.
435 * gmx_cmap_t cmap_grid
436 * the grid for the dihedral pair correction maps.
437 * t_iparams *iparams_posres, *iparams_fbposres
438 * defines the parameters for position restraints only.
439 * Position restraints are the only interactions that have different
440 * parameters (reference positions) for different molecules
441 * of the same type. ilist[F_POSRES].iatoms[] is an index in this array.
443 * The list of interactions for each type. Note that some,
444 * such as LJ and COUL will have 0 entries.
446 * The state of the sorting of il, values are provided above.
454 void printInteractionParameters(gmx::TextWriter* writer, t_functype ftype, const t_iparams& iparams);
455 void pr_iparams(FILE* fp, t_functype ftype, const t_iparams& iparams);
456 void pr_ilist(FILE* fp,
459 const t_functype* functype,
460 const InteractionList& ilist,
462 bool bShowParameters,
463 const t_iparams* iparams);
464 void pr_idef(FILE* fp, int indent, const char* title, const t_idef* idef, bool bShowNumbers, bool bShowParameters);
467 * Properly initialize idef struct.
469 * \param[in] idef Pointer to idef struct to initialize.
471 void init_idef(t_idef* idef);
474 * Properly clean up idef struct.
476 * \param[in] idef Pointer to idef struct to clean up.
478 void done_idef(t_idef* idef);