2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2020,2021, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \inpublicapi \file
37 * Implements nblib supported bondtypes
39 * We choose to forward comparison operations to the
40 * corresponding std::tuple comparison operations.
41 * In order to do that without temporary copies,
42 * we employ std::tie, which requires lvalues as input.
43 * For this reason, bond type parameter getters are implemented
44 * with a const lvalue reference return.
46 * \author Victor Holanda <victor.holanda@cscs.ch>
47 * \author Joe Jordan <ejjordan@kth.se>
48 * \author Prashanth Kanduri <kanduri@cscs.ch>
49 * \author Sebastian Keller <keller@cscs.ch>
50 * \author Artem Zhmurov <zhmurov@gmail.com>
52 #ifndef NBLIB_LISTEDFORCES_BONDTYPES_H
53 #define NBLIB_LISTEDFORCES_BONDTYPES_H
57 #include "nblib/exception.h"
58 #include "nblib/particletype.h"
59 #include "nblib/util/util.hpp"
63 using Name = std::string;
64 using ForceConstant = real;
65 using EquilConstant = real;
66 using Exponent = real;
68 using Degrees = StrongType<real, struct DegreeParameter>;
69 using Radians = StrongType<real, struct RadianParameter>;
71 /*! \brief Basic template for interactions with 2 parameters named forceConstant and equilConstant
73 * \tparam Phantom unused template parameter for type distinction
75 * Distinct bond types can be generated from this template with using declarations
76 * and declared, but undefined structs. For example:
77 * using HarmonicBondType = TwoParameterInteraction<struct HarmonicBondTypeParameter>;
78 * Note that HarmonicBondTypeParameter does not have to be defined.
80 template<class Phantom>
81 class TwoParameterInteraction
84 TwoParameterInteraction() = default;
85 TwoParameterInteraction(ForceConstant f, EquilConstant d) : forceConstant_(f), equilConstant_(d)
89 [[nodiscard]] const ForceConstant& forceConstant() const { return forceConstant_; }
90 [[nodiscard]] const EquilConstant& equilConstant() const { return equilConstant_; }
93 ForceConstant forceConstant_;
94 EquilConstant equilConstant_;
97 template<class Phantom>
98 inline bool operator<(const TwoParameterInteraction<Phantom>& a, const TwoParameterInteraction<Phantom>& b)
100 return std::tie(a.forceConstant(), a.equilConstant())
101 < std::tie(b.forceConstant(), b.equilConstant());
104 template<class Phantom>
105 inline bool operator==(const TwoParameterInteraction<Phantom>& a, const TwoParameterInteraction<Phantom>& b)
107 return std::tie(a.forceConstant(), a.equilConstant())
108 == std::tie(b.forceConstant(), b.equilConstant());
111 /*! \brief harmonic bond type
113 * It represents the interaction of the form
114 * V(r, forceConstant, equilDistance) = 0.5 * forceConstant * (r - equilConstant)^2
116 using HarmonicBondType = TwoParameterInteraction<struct HarmonicBondTypeParameter>;
119 /*! \brief GROMOS bond type
121 * It represents the interaction of the form
122 * V(r, forceConstant, equilDistance) = 0.25 * forceConstant * (r^2 - equilConstant^2)^2
124 class G96BondType : public TwoParameterInteraction<struct G96BondTypeParameter>
127 G96BondType() = default;
128 //! \brief Store square of equilibrium distance
129 G96BondType(ForceConstant f, EquilConstant equilConstant) :
130 TwoParameterInteraction<struct G96BondTypeParameter>{ f, equilConstant * equilConstant }
136 /*! \brief FENE bond type
138 * It represents the interaction of the form
139 * V(r, forceConstant, equilDistance) = - 0.5 * forceConstant * equilDistance^2 * log( 1 - (r / equilConstant)^2)
141 using FENEBondType = TwoParameterInteraction<struct FENEBondTypeParameter>;
144 /*! \brief Half-attractive quartic bond type
146 * It represents the interaction of the form
147 * V(r, forceConstant, equilConstant) = 0.5 * forceConstant * (r - equilDistance)^4
149 using HalfAttractiveQuarticBondType =
150 TwoParameterInteraction<struct HalfAttractiveQuarticBondTypeParameter>;
153 /*! \brief Cubic bond type
155 * It represents the interaction of the form
156 * V(r, quadraticForceConstant, cubicForceConstant, equilConstant) = quadraticForceConstant * (r -
157 * equilDistance)^2 + quadraticForceConstant * cubicForceConstant * (r - equilConstant)
162 CubicBondType() = default;
163 CubicBondType(ForceConstant fq, ForceConstant fc, EquilConstant d) :
164 quadraticForceConstant_(fq), cubicForceConstant_(fc), equilDistance_(d)
168 [[nodiscard]] const ForceConstant& quadraticForceConstant() const
170 return quadraticForceConstant_;
172 [[nodiscard]] const ForceConstant& cubicForceConstant() const { return cubicForceConstant_; }
173 [[nodiscard]] const EquilConstant& equilDistance() const { return equilDistance_; }
176 ForceConstant quadraticForceConstant_;
177 ForceConstant cubicForceConstant_;
178 EquilConstant equilDistance_;
181 inline bool operator<(const CubicBondType& a, const CubicBondType& b)
183 return std::tie(a.quadraticForceConstant(), a.cubicForceConstant(), a.equilDistance())
184 < std::tie(b.quadraticForceConstant(), b.cubicForceConstant(), b.equilDistance());
187 inline bool operator==(const CubicBondType& a, const CubicBondType& b)
189 return std::tie(a.quadraticForceConstant(), a.cubicForceConstant(), a.equilDistance())
190 == std::tie(b.quadraticForceConstant(), b.cubicForceConstant(), b.equilDistance());
193 /*! \brief Morse bond type
195 * It represents the interaction of the form
196 * V(r, forceConstant, exponent, equilDistance) = forceConstant * ( 1 - exp( -exponent * (r - equilConstant))
201 MorseBondType() = default;
202 MorseBondType(ForceConstant f, Exponent e, EquilConstant d) :
203 forceConstant_(f), exponent_(e), equilDistance_(d)
207 [[nodiscard]] const ForceConstant& forceConstant() const { return forceConstant_; }
208 [[nodiscard]] const Exponent& exponent() const { return exponent_; }
209 [[nodiscard]] const EquilConstant& equilDistance() const { return equilDistance_; }
212 ForceConstant forceConstant_;
214 EquilConstant equilDistance_;
217 inline bool operator<(const MorseBondType& a, const MorseBondType& b)
219 return std::tie(a.forceConstant(), a.exponent(), a.equilDistance())
220 < std::tie(b.forceConstant(), b.exponent(), b.equilDistance());
223 inline bool operator==(const MorseBondType& a, const MorseBondType& b)
225 return std::tie(a.forceConstant(), a.exponent(), a.equilDistance())
226 == std::tie(b.forceConstant(), b.exponent(), b.equilDistance());
229 /*! \brief Non-Bonded Pair Interaction Type
231 * It represents the interaction of the form
232 * of LJ interactions, but occur between atoms
233 * of the same bonded chain
234 * V(r, c_6, c_12) = c_12*(r^-12) - c_6*(r^-6)
239 PairLJType() = default;
240 PairLJType(C6 c6, C12 c12) : c6_(c6), c12_(c12) {}
242 [[nodiscard]] const C6& c6() const { return c6_; }
243 [[nodiscard]] const C12& c12() const { return c12_; }
250 inline bool operator<(const PairLJType& a, const PairLJType& b)
252 return std::tie(a.c6(), a.c12()) < std::tie(b.c6(), b.c12());
255 inline bool operator==(const PairLJType& a, const PairLJType& b)
257 return std::tie(a.c6(), a.c12()) == std::tie(b.c6(), b.c12());
260 /*! \brief Basic template for interactions with 2 parameters named forceConstant and equilAngle
262 * \tparam Phantom unused template parameter for type distinction
264 * Distinct angle types can be generated from this template with using declarations
265 * and declared, but undefined structs. For example:
266 * using HarmonicAngleType = AngleInteractionType<struct HarmonicAngleParameter>;
267 * HarmonicAngleParameter does not have to be defined.
269 * Note: the angle is always stored as radians internally
271 template<class Phantom>
272 class AngleInteractionType : public TwoParameterInteraction<Phantom>
275 AngleInteractionType() = default;
276 //! \brief construct from angle given in radians
277 AngleInteractionType(ForceConstant f, Radians angle) :
278 TwoParameterInteraction<Phantom>{ f, angle }
282 //! \brief construct from angle given in degrees
283 AngleInteractionType(ForceConstant f, Degrees angle) :
284 TwoParameterInteraction<Phantom>{ f, angle * DEG2RAD }
289 /*! \brief Harmonic angle type
291 * It represents the interaction of the form
292 * V(theta, forceConstant, equilAngle) = 0.5 * forceConstant * (theta - equilAngle)^2
294 using HarmonicAngle = AngleInteractionType<struct HarmonicAngleParameter>;
296 /*! \brief linear angle type
298 * It represents the interaction of the form
299 * V(theta, forceConstant, a) = 0.5 * forceConstant * (dr)^2
300 * where dr = - a * r_ij - (1 - a) * r_kj
302 using LinearAngle = TwoParameterInteraction<struct LinearAngleParameter>;
304 /*! \brief Basic template for angle types that use the cosines of their equilibrium angles
305 * in their potential expression
307 template<class Phantom>
308 class CosineParamAngle : public TwoParameterInteraction<Phantom>
311 CosineParamAngle() = default;
312 //! \brief construct from angle given in radians
313 CosineParamAngle(ForceConstant f, Radians angle) :
314 TwoParameterInteraction<Phantom>{ f, std::cos(angle) }
318 //! \brief construct from angle given in degrees
319 CosineParamAngle(ForceConstant f, Degrees angle) :
320 TwoParameterInteraction<Phantom>{ f, std::cos(angle * DEG2RAD) }
325 /*! \brief G96 or Cosine-based angle type
327 * This represents the interaction of the form
328 * V(cos(theta), forceConstant, cos(equilAngle)) = 0.5 * forceConstant * (cos(theta) - cos(equilAngle))^2
330 using G96Angle = CosineParamAngle<struct G96AngleParameter>;
332 /*! \brief Restricted angle type
334 * This represents the interaction of the form
335 * V(cos(theta), forceConstant, cos(equilAngle)) =
336 * 0.5 * forceConstant * (cos(theta) - cos(equilAngle))^2 / (sin(theta))^2
338 using RestrictedAngle = CosineParamAngle<struct RestrictedAngleParameter>;
340 /*! \brief Quartic angle type
342 * It represents the interaction of the form of a fourth order polynomial
343 * V(theta, forceConstant, equilAngle) = sum[i = 0 -> 4](forceConstant_i * (theta - equilAngle)^i
348 QuarticAngle() = default;
349 //! \brief construct from given angle in radians
350 QuarticAngle(ForceConstant f0, ForceConstant f1, ForceConstant f2, ForceConstant f3, ForceConstant f4, Radians angle) :
351 forceConstants_{ f0, f1, f2, f3, f4 }, equilConstant_(angle)
355 //! \brief construct from given angle in degrees
356 QuarticAngle(ForceConstant f0, ForceConstant f1, ForceConstant f2, ForceConstant f3, ForceConstant f4, Degrees angle) :
357 forceConstants_{ f0, f1, f2, f3, f4 }, equilConstant_(angle * DEG2RAD)
361 [[nodiscard]] const std::array<ForceConstant, 5>& forceConstants() const
363 return forceConstants_;
366 ForceConstant forceConstant(int order) const
370 case 0: return forceConstants_[0];
371 case 1: return forceConstants_[1];
372 case 2: return forceConstants_[2];
373 case 3: return forceConstants_[3];
374 case 4: return forceConstants_[4];
376 throw InputException(
377 "Please enter a value between 0-4 for the Quartic Angle force constants");
381 Radians equilConstant() const { return equilConstant_; }
384 std::array<ForceConstant, 5> forceConstants_;
385 Radians equilConstant_;
388 inline bool operator<(const QuarticAngle& a, const QuarticAngle& b)
390 return (a.forceConstants() < b.forceConstants()) && (a.equilConstant() < b.equilConstant());
393 inline bool operator==(const QuarticAngle& a, const QuarticAngle& b)
395 return (a.forceConstants() == b.forceConstants()) && (a.equilConstant() == b.equilConstant());
399 /*! \brief Cross bond-bond interaction type
404 CrossBondBond() = default;
405 CrossBondBond(ForceConstant f, EquilConstant r0ij, EquilConstant r0kj) :
406 forceConstant_(f), r0ij_(r0ij), r0kj_(r0kj)
410 [[nodiscard]] const ForceConstant& forceConstant() const { return forceConstant_; }
411 [[nodiscard]] const EquilConstant& equilDistanceIJ() const { return r0ij_; }
412 [[nodiscard]] const EquilConstant& equilDistanceKJ() const { return r0kj_; }
415 ForceConstant forceConstant_;
420 inline bool operator<(const CrossBondBond& a, const CrossBondBond& b)
422 return std::tie(a.forceConstant(), a.equilDistanceIJ(), a.equilDistanceKJ())
423 < std::tie(b.forceConstant(), b.equilDistanceIJ(), b.equilDistanceKJ());
426 inline bool operator==(const CrossBondBond& a, const CrossBondBond& b)
428 return std::tie(a.forceConstant(), a.equilDistanceIJ(), a.equilDistanceKJ())
429 == std::tie(b.forceConstant(), b.equilDistanceIJ(), b.equilDistanceKJ());
432 /*! \brief Cross bond-angle interaction type
437 CrossBondAngle() = default;
438 CrossBondAngle(ForceConstant f, EquilConstant r0ij, EquilConstant r0kj, EquilConstant r0ik) :
439 forceConstant_(f), r0ij_(r0ij), r0kj_(r0kj), r0ik_(r0ik)
443 [[nodiscard]] const ForceConstant& forceConstant() const { return forceConstant_; }
444 [[nodiscard]] const EquilConstant& equilDistanceIJ() const { return r0ij_; }
445 [[nodiscard]] const EquilConstant& equilDistanceKJ() const { return r0kj_; }
446 [[nodiscard]] const EquilConstant& equilDistanceIK() const { return r0ik_; }
449 ForceConstant forceConstant_;
455 inline bool operator<(const CrossBondAngle& a, const CrossBondAngle& b)
457 return std::tie(a.forceConstant(), a.equilDistanceIJ(), a.equilDistanceKJ(), a.equilDistanceIK())
458 < std::tie(b.forceConstant(), b.equilDistanceIJ(), b.equilDistanceKJ(), b.equilDistanceIK());
461 inline bool operator==(const CrossBondAngle& a, const CrossBondAngle& b)
463 return std::tie(a.forceConstant(), a.equilDistanceIJ(), a.equilDistanceKJ(), a.equilDistanceIK())
464 == std::tie(b.forceConstant(), b.equilDistanceIJ(), b.equilDistanceKJ(), b.equilDistanceIK());
467 /*! \brief Proper Dihedral Implementation
472 using Multiplicity = int;
474 ProperDihedral() = default;
475 ProperDihedral(Radians phi, ForceConstant f, Multiplicity m) :
476 phi_(phi), forceConstant_(f), multiplicity_(m)
479 ProperDihedral(Degrees phi, ForceConstant f, Multiplicity m) :
480 phi_(phi * DEG2RAD), forceConstant_(f), multiplicity_(m)
484 [[nodiscard]] const EquilConstant& equilDistance() const { return phi_; }
485 [[nodiscard]] const ForceConstant& forceConstant() const { return forceConstant_; }
486 [[nodiscard]] const Multiplicity& multiplicity() const { return multiplicity_; }
490 ForceConstant forceConstant_;
491 Multiplicity multiplicity_;
494 inline bool operator<(const ProperDihedral& a, const ProperDihedral& b)
496 return std::tie(a.equilDistance(), a.forceConstant(), a.multiplicity())
497 < std::tie(b.equilDistance(), b.forceConstant(), b.multiplicity());
500 inline bool operator==(const ProperDihedral& a, const ProperDihedral& b)
502 return std::tie(a.equilDistance(), a.forceConstant(), a.multiplicity())
503 == std::tie(b.equilDistance(), b.forceConstant(), b.multiplicity());
507 /*! \brief Improper Dihedral Implementation
509 class ImproperDihedral : public TwoParameterInteraction<struct ImproperDihdedralParameter>
512 ImproperDihedral() = default;
513 ImproperDihedral(Radians phi, ForceConstant f) :
514 TwoParameterInteraction<struct ImproperDihdedralParameter>{ f, phi }
517 ImproperDihedral(Degrees phi, ForceConstant f) :
518 TwoParameterInteraction<struct ImproperDihdedralParameter>{ f, phi * DEG2RAD }
523 /*! \brief Ryckaert-Belleman Dihedral Implementation
525 class RyckaertBellemanDihedral
528 RyckaertBellemanDihedral() = default;
529 RyckaertBellemanDihedral(real p1, real p2, real p3, real p4, real p5, real p6) :
530 parameters_{ p1, p2, p3, p4, p5, p6 }
534 const real& operator[](std::size_t i) const { return parameters_[i]; }
536 [[nodiscard]] const std::array<real, 6>& parameters() const { return parameters_; }
538 [[nodiscard]] std::size_t size() const { return parameters_.size(); }
541 std::array<real, 6> parameters_;
544 inline bool operator<(const RyckaertBellemanDihedral& a, const RyckaertBellemanDihedral& b)
546 return a.parameters() < b.parameters();
549 inline bool operator==(const RyckaertBellemanDihedral& a, const RyckaertBellemanDihedral& b)
551 return a.parameters() == b.parameters();
555 /*! \brief Type for 5-center interaction (C-MAP)
557 * Note: no kernels currently implemented
562 Default5Center() = default;
563 Default5Center(Radians phi, Radians psi, ForceConstant fphi, ForceConstant fpsi) :
564 phi_(phi), psi_(psi), fphi_(fphi), fpsi_(fpsi)
568 [[nodiscard]] const Radians& phi() const { return phi_; }
569 [[nodiscard]] const Radians& psi() const { return psi_; }
570 [[nodiscard]] const ForceConstant& fphi() const { return fphi_; }
571 [[nodiscard]] const ForceConstant& fpsi() const { return fpsi_; }
575 ForceConstant fphi_, fpsi_;
578 inline bool operator<(const Default5Center& a, const Default5Center& b)
580 return std::tie(a.phi(), a.psi(), a.fphi(), a.fpsi())
581 < std::tie(b.phi(), b.psi(), b.fphi(), b.fpsi());
584 inline bool operator==(const Default5Center& a, const Default5Center& b)
586 return std::tie(a.phi(), a.psi(), a.fphi(), a.fpsi())
587 == std::tie(b.phi(), b.psi(), b.fphi(), b.fpsi());
592 #endif // NBLIB_LISTEDFORCES_BONDTYPES_H