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 {
53 /* Some parameters have A and B values for free energy calculations.
54 * The B values are not used for regular simulations of course.
55 * Free Energy for nonbondeds can be computed by changing the atom type.
56 * The harmonic type is used for all harmonic potentials:
57 * bonds, angles and improper dihedrals
65 real rA, krA, rB, krB;
69 real klinA, aA, klinB, aB;
73 real lowA, up1A, up2A, kA, lowB, up1B, up2B, kB;
75 /* No free energy supported for cubic bonds, FENE, WPOL or cross terms */
90 real r1e, r2e, r3e, krt;
94 real thetaA, kthetaA, r13A, kUBA, thetaB, kthetaB, r13B, kUBB;
106 real alpha, drcut, khyp;
110 real al_x, al_y, al_z, rOH, rHH, rOD;
114 real a, alpha1, alpha2, rfac;
122 real c6A, c12A, c6B, c12B;
126 real fqq, qi, qj, c6, c12;
130 real qi, qj, c6, c12;
132 /* Proper dihedrals can not have different multiplicity when
133 * doing free energy calculations, because the potential would not
134 * be periodic anymore.
146 /* Settle can not be used for Free energy calculations of water bond geometry.
147 * Use shake (or lincs) instead if you have to change the water bonds.
155 real b0A, cbA, betaA, b0B, cbB, betaB;
159 real pos0A[DIM], fcA[DIM], pos0B[DIM], fcB[DIM];
163 real pos0[DIM], r, k;
168 real rbcA[NR_RBDIHS], rbcB[NR_RBDIHS];
172 real cbtcA[NR_CBTDIHS], cbtcB[NR_CBTDIHS];
176 real a, b, c, d, e, f;
183 /* NOTE: npair is only set after reading the tpx file */
186 real low, up1, up2, kfac;
187 int type, label, npair;
191 real phiA, dphiA, kfacA, phiB, dphiB, kfacB;
195 int ex, power, label;
210 real buf[MAXFORCEPARAM];
211 } generic; /* Conversion */
214 typedef int t_functype;
216 /* List of listed interactions, see description further down.
218 * TODO: Consider storing the function type as well.
219 * TODO: Consider providing per interaction access.
221 struct InteractionList
223 /* Returns the total number of elements in iatoms */
224 int size() const { return static_cast<int>(iatoms.size()); }
226 /* Returns whether the list is empty */
227 bool empty() const { return iatoms.empty(); }
229 /* Adds one interaction to the list */
230 template<std::size_t numAtoms>
231 void push_back(const int parameterType, const std::array<int, numAtoms>& atoms)
233 const std::size_t oldSize = iatoms.size();
234 iatoms.resize(iatoms.size() + 1 + numAtoms);
235 iatoms[oldSize] = parameterType;
236 for (std::size_t i = 0; i < numAtoms; i++)
238 iatoms[oldSize + 1 + i] = atoms[i];
242 /* Adds one interaction to the list */
243 void push_back(const int parameterType, const int numAtoms, const int* atoms)
245 const std::size_t oldSize = iatoms.size();
246 iatoms.resize(iatoms.size() + 1 + numAtoms);
247 iatoms[oldSize] = parameterType;
248 for (int i = 0; i < numAtoms; i++)
250 iatoms[oldSize + 1 + i] = atoms[i];
254 /* Appends \p ilist at the back of the list */
255 void append(const InteractionList& ilist)
257 iatoms.insert(iatoms.end(), ilist.iatoms.begin(), ilist.iatoms.end());
260 /* Clears the list */
261 void clear() { iatoms.clear(); }
263 /* List of interactions, see explanation further down */
264 std::vector<int> iatoms;
267 /* List of interaction lists, one list for each interaction type
269 * TODO: Consider only including entries in use instead of all F_NRE
271 using InteractionLists = std::array<InteractionList, F_NRE>;
273 /* Deprecated list of listed interactions */
276 /* Returns the total number of elements in iatoms */
277 int size() const { return nr; }
279 /* Returns whether the list is empty */
280 bool empty() const { return nr == 0; }
287 /* TODO: Remove t_ilist and remove templating on list type in mshift.cpp */
290 * The structs InteractionList and t_ilist defines a list of atoms with their interactions.
291 * General field description:
293 * the size (nr elements) of the interactions array (iatoms[]).
295 * specifies which atoms are involved in an interaction of a certain
296 * type. The layout of this array is as follows:
298 * +-----+---+---+---+-----+---+---+-----+---+---+---+-----+---+---+...
299 * |type1|at1|at2|at3|type2|at1|at2|type1|at1|at2|at3|type3|at1|at2|
300 * +-----+---+---+---+-----+---+---+-----+---+---+---+-----+---+---+...
302 * So for interaction type type1 3 atoms are needed, and for type2 and
303 * type3 only 2. The type identifier is used to select the function to
304 * calculate the interaction and its actual parameters. This type
305 * identifier is an index in a params[] and functype[] array.
308 /*! \brief Type for returning a list of InteractionList references
310 * TODO: Remove when the function type is made part of InteractionList
312 struct InteractionListHandle
314 const int functionType; //!< The function type
315 const std::vector<int>& iatoms; //!< Reference to interaction list
318 /*! \brief Returns a list of all non-empty InteractionList entries with any of the interaction flags in \p flags set
320 * \param[in] ilists Set of interaction lists
321 * \param[in] flags Bit mask with one or more IF_... bits set
323 static inline std::vector<InteractionListHandle> extractILists(const InteractionLists& ilists, int flags)
325 std::vector<InteractionListHandle> handles;
326 for (size_t ftype = 0; ftype < ilists.size(); ftype++)
328 if ((interaction_function[ftype].flags & flags) && !ilists[ftype].empty())
330 handles.push_back({ static_cast<int>(ftype), ilists[ftype].iatoms });
336 /*! \brief Returns the stride for the iatoms array in \p ilistHandle
338 * \param[in] ilistHandle The ilist to return the stride for
340 static inline int ilistStride(const InteractionListHandle& ilistHandle)
342 return 1 + NRAL(ilistHandle.functionType);
345 struct gmx_cmapdata_t
347 std::vector<real> cmap; /* Has length 4*grid_spacing*grid_spacing, */
348 /* there are 4 entries for each cmap type (V,dVdx,dVdy,d2dVdxdy) */
353 int grid_spacing = 0; /* Grid spacing */
354 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);