Pass restraint data structures to bonded functions
[alexxy/gromacs.git] / src / gromacs / listed_forces / bonded.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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,2017 by the GROMACS development team.
7  * Copyright (c) 2018,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.
11  *
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.
16  *
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.
21  *
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.
26  *
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.
34  *
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.
37  */
38 /*! \libinternal \file
39  *
40  * \brief This file contains declarations necessary for low-level
41  * functions for computing energies and forces for bonded interactions.
42  *
43  * \author Mark Abraham <mark.j.abraham@gmail.com>
44  * \inlibraryapi
45  * \ingroup module_listed_forces
46  */
47
48 #ifndef GMX_LISTED_FORCES_BONDED_H
49 #define GMX_LISTED_FORCES_BONDED_H
50
51 #include <string>
52
53 #include "gromacs/math/vectypes.h"
54 #include "gromacs/topology/ifunc.h"
55 #include "gromacs/utility/basedefinitions.h"
56
57 struct gmx_cmap_t;
58 struct t_fcdata;
59 struct t_mdatom;
60 struct t_nrnb;
61 struct t_pbc;
62 struct t_disresdata;
63 struct t_oriresdata;
64
65 namespace gmx
66 {
67 template<typename EnumType, typename DataType, EnumType ArraySize>
68 struct EnumerationArray;
69 } // namespace gmx
70
71 /*! \brief Calculate bond-angle. No PBC is taken into account (use mol-shift) */
72 real bond_angle(const rvec          xi,
73                 const rvec          xj,
74                 const rvec          xk,
75                 const struct t_pbc* pbc,
76                 rvec                r_ij,
77                 rvec                r_kj,
78                 real*               costh,
79                 int*                t1,
80                 int*                t2); /* out */
81
82 /*! \brief Calculate dihedral-angle. No PBC is taken into account (use mol-shift) */
83 real dih_angle(const rvec          xi,
84                const rvec          xj,
85                const rvec          xk,
86                const rvec          xl,
87                const struct t_pbc* pbc,
88                rvec                r_ij,
89                rvec                r_kj,
90                rvec                r_kl,
91                rvec                m,
92                rvec                n, /* out */
93                int*                t1,
94                int*                t2,
95                int*                t3);
96
97 /*! \brief Do an update of the forces for dihedral potentials */
98 void do_dih_fup(int                 i,
99                 int                 j,
100                 int                 k,
101                 int                 l,
102                 real                ddphi,
103                 rvec                r_ij,
104                 rvec                r_kj,
105                 rvec                r_kl,
106                 rvec                m,
107                 rvec                n,
108                 rvec4               f[],
109                 rvec                fshift[],
110                 const struct t_pbc* pbc,
111                 const rvec*         x,
112                 int                 t1,
113                 int                 t2,
114                 int                 t3);
115
116 /*! \brief Make a dihedral fall in the range (-pi,pi) */
117 void make_dp_periodic(real* dp);
118
119 /*! \brief Compute CMAP dihedral energies and forces */
120 real cmap_dihs(int                 nbonds,
121                const t_iatom       forceatoms[],
122                const t_iparams     forceparams[],
123                const gmx_cmap_t*   cmap_grid,
124                const rvec          x[],
125                rvec4               f[],
126                rvec                fshift[],
127                const struct t_pbc* pbc,
128                real gmx_unused lambda,
129                real gmx_unused* dvdlambda,
130                const t_mdatoms gmx_unused* md,
131                t_fcdata gmx_unused* fcd,
132                t_disresdata gmx_unused* disresdata,
133                t_oriresdata gmx_unused* oriresdata,
134                int gmx_unused* global_atom_index);
135
136 /*! \brief For selecting which flavor of bonded kernel is used for simple bonded types */
137 enum class BondedKernelFlavor
138 {
139     ForcesSimdWhenAvailable, //!< Compute only forces, use SIMD when available; should not be used with perturbed parameters
140     ForcesNoSimd,             //!< Compute only forces, do not use SIMD
141     ForcesAndVirialAndEnergy, //!< Compute forces, virial and energy (no SIMD)
142     ForcesAndEnergy,          //!< Compute forces and energy (no SIMD)
143     Count                     //!< The number of flavors
144 };
145
146 //! Helper strings for human-readable messages
147 extern const gmx::EnumerationArray<BondedKernelFlavor, std::string, BondedKernelFlavor::Count> c_bondedKernelFlavorStrings;
148
149 /*! \brief Returns whether the energy should be computed */
150 static constexpr inline bool computeEnergy(const BondedKernelFlavor flavor)
151 {
152     return (flavor == BondedKernelFlavor::ForcesAndVirialAndEnergy
153             || flavor == BondedKernelFlavor::ForcesAndEnergy);
154 }
155
156 /*! \brief Returns whether the virial should be computed */
157 static constexpr inline bool computeVirial(const BondedKernelFlavor flavor)
158 {
159     return (flavor == BondedKernelFlavor::ForcesAndVirialAndEnergy);
160 }
161
162 /*! \brief Returns whether the energy and/or virial should be computed */
163 static constexpr inline bool computeEnergyOrVirial(const BondedKernelFlavor flavor)
164 {
165     return (flavor == BondedKernelFlavor::ForcesAndVirialAndEnergy
166             || flavor == BondedKernelFlavor::ForcesAndEnergy);
167 }
168
169 /*! \brief Calculates bonded interactions for simple bonded types
170  *
171  * Exits with an error when the bonded type is not simple
172  * All pointers should be non-null, except for pbc and g which can be nullptr.
173  * \returns the energy or 0 when \p bondedKernelFlavor did not request the energy.
174  */
175 real calculateSimpleBond(int                 ftype,
176                          int                 numForceatoms,
177                          const t_iatom       forceatoms[],
178                          const t_iparams     forceparams[],
179                          const rvec          x[],
180                          rvec4               f[],
181                          rvec                fshift[],
182                          const struct t_pbc* pbc,
183                          real                lambda,
184                          real*               dvdlambda,
185                          const t_mdatoms*    md,
186                          t_fcdata*           fcd,
187                          t_disresdata*       disresdata,
188                          t_oriresdata*       oriresdata,
189                          int gmx_unused*    global_atom_index,
190                          BondedKernelFlavor bondedKernelFlavor);
191
192 //! Getter for finding the flop count for an \c ftype interaction.
193 int nrnbIndex(int ftype);
194
195 #endif