faunus
bonds.h
1 #pragma once
2 #include "particle.h"
3 
4 namespace Faunus::pairpotential {
5 
17 struct BondData
18 {
19  enum class Variant
20  {
21  HARMONIC = 0,
22  FENE,
23  FENEWCA,
24  HARMONIC_TORSION,
25  GROMOS_TORSION,
26  PERIODIC_DIHEDRAL,
27  HARMONIC_DIHEDRAL,
28  INVALID
29  };
30  std::vector<int> indices;
31 
33  std::function<double(Geometry::DistanceFunction)> energyFunc = nullptr;
34 
35  using IndexAndForce =
36  std::pair<int, Point>;
37 
39  std::function<std::vector<IndexAndForce>(Geometry::DistanceFunction)> forceFunc = nullptr;
40 
41  virtual void from_json(const json&) = 0;
42  virtual void to_json(json&) const = 0;
43  [[nodiscard]] virtual int numindex() const = 0;
44  [[nodiscard]] virtual Variant type() const = 0;
45  [[nodiscard]] virtual std::shared_ptr<BondData>
46  clone() const = 0;
47  virtual void setEnergyFunction(
48  const ParticleVector& particles) = 0;
49  [[nodiscard]] bool hasEnergyFunction() const;
50  [[nodiscard]] bool hasForceFunction() const;
51  void shiftIndices(int offset);
52  BondData() = default;
53  explicit BondData(const std::vector<int>& indices);
54  virtual ~BondData() = default;
55 };
56 
57 NLOHMANN_JSON_SERIALIZE_ENUM(BondData::Variant,
58  {{BondData::Variant::INVALID, nullptr},
59  {BondData::Variant::HARMONIC, "harmonic"},
60  {BondData::Variant::FENE, "fene"},
61  {BondData::Variant::FENEWCA, "fene+wca"},
62  {BondData::Variant::HARMONIC_TORSION, "harmonic_torsion"},
63  {BondData::Variant::GROMOS_TORSION, "gromos_torsion"},
64  {BondData::Variant::PERIODIC_DIHEDRAL, "periodic_dihedral"},
65  {BondData::Variant::HARMONIC_DIHEDRAL, "harmonic_dihedral"}})
66 
67 struct StretchData : public BondData
68 {
69  [[nodiscard]] int numindex() const override;
70  StretchData() = default;
71  explicit StretchData(const std::vector<int>& indices);
72 };
73 
74 struct TorsionData : public BondData
75 {
76  [[nodiscard]] int numindex() const override;
77  TorsionData() = default;
78  explicit TorsionData(const std::vector<int>& indices);
79 };
80 
86 struct HarmonicBond : public StretchData
87 {
88  double half_force_constant = 0.0;
89  double equilibrium_distance = 0.0;
90  [[nodiscard]] Variant type() const override;
91  [[nodiscard]] std::shared_ptr<BondData> clone() const override;
92  void from_json(const json& j) override;
93  void to_json(json& j) const override;
94  void
95  setEnergyFunction(const ParticleVector& particles) override;
96  HarmonicBond() = default;
97  HarmonicBond(double k, double req, const std::vector<int>& indices);
98 };
99 
105 struct FENEBond : public StretchData
106 {
107  double half_force_constant = 0.0;
108  double max_squared_distance = 0.0;
109  [[nodiscard]] Variant type() const override;
110  [[nodiscard]] std::shared_ptr<BondData> clone() const override;
111  void from_json(const json& j) override;
112  void to_json(json& j) const override;
113  void setEnergyFunction(const ParticleVector& particles) override;
114  FENEBond() = default;
115  FENEBond(double k, double rmax, const std::vector<int>& indices);
116 };
117 
121 struct FENEWCABond : public StretchData
122 {
123  double half_force_constant = 0.0;
124  double max_distance_squared = 0.0;
125  double epsilon = 0.0;
126  double sigma_squared = 0.0;
127  std::array<double, 4> k = {{0.0, 0.0, 0.0, 0.0}};
128  [[nodiscard]] Variant type() const override;
129  [[nodiscard]] std::shared_ptr<BondData> clone() const override;
130  void from_json(const json& j) override;
131  void to_json(json& j) const override;
132  void setEnergyFunction(const ParticleVector& calculateDistance) override;
133  FENEWCABond() = default;
134  FENEWCABond(double k, double rmax, double epsilon, double sigma,
135  const std::vector<int>& indices);
136 };
137 
144 {
145  double half_force_constant = 0.0;
146  double equilibrium_angle = 0.0;
147  [[nodiscard]] std::shared_ptr<BondData> clone() const override;
148  void from_json(const json& j) override;
149  void to_json(json& j) const override;
150  [[nodiscard]] Variant type() const override;
151  void setEnergyFunction(const ParticleVector& particles) override;
152  HarmonicTorsion() = default;
153  HarmonicTorsion(double k, double aeq, const std::vector<int>& indices);
154 };
155 
161 struct GromosTorsion : public TorsionData
162 {
163  double half_force_constant = 0.0;
164  double cosine_equilibrium_angle = 0.0;
165  [[nodiscard]] std::shared_ptr<BondData> clone() const override;
166  void from_json(const json& j) override;
167  void to_json(json& j) const override;
168  [[nodiscard]] Variant type() const override;
169  void setEnergyFunction(const ParticleVector& calculateDistance) override;
170  GromosTorsion() = default;
171  GromosTorsion(double k, double cos_aeq, const std::vector<int>& indices);
172 };
173 
179 struct PeriodicDihedral : public BondData
180 {
181  double force_constant = 0.0;
182  double phase_angle = 0.0;
183  double periodicity = 1.0;
184  [[nodiscard]] int numindex() const override;
185  [[nodiscard]] std::shared_ptr<BondData> clone() const override;
186  void from_json(const json& j) override;
187  void to_json(json& j) const override;
188  [[nodiscard]] Variant type() const override;
189  void setEnergyFunction(const ParticleVector& particles) override;
190  PeriodicDihedral() = default;
191  PeriodicDihedral(double k, double phi, double n, const std::vector<int>& indices);
192 };
193 
199 struct HarmonicDihedral : public BondData
200 {
201  double half_force_constant = 0.0;
202  double equilibrium_dihedral = 0.0;
203  [[nodiscard]] int numindex() const override;
204  [[nodiscard]] std::shared_ptr<BondData> clone() const override;
205  void from_json(const json& j) override;
206  void to_json(json& j) const override;
207  [[nodiscard]] Variant type() const override;
208  void setEnergyFunction(const ParticleVector& particles) override;
209  HarmonicDihedral() = default;
210  HarmonicDihedral(double k, double deq, const std::vector<int>& indices);
211 };
212 
213 void from_json(const json& j, std::shared_ptr<BondData>& bond);
214 void to_json(json& j, const std::shared_ptr<const BondData>& bond);
215 void to_json(json& j, const BondData& bond);
216 
217 } // namespace Faunus::pairpotential
nlohmann::json json
JSON object.
Definition: json_support.h:10
bool hasEnergyFunction() const
test if energy function has been set
Definition: bonds.cpp:77
Gromos torsion.
Definition: bonds.h:161
void shiftIndices(int offset)
Add offset to particle indices.
Definition: bonds.cpp:70
std::function< Point(const Point &, const Point &)> DistanceFunction
Function to calculate the (minimum) distance between two points.
Definition: core.h:32
std::vector< int > indices
Absolute indiced of participating particles.
Definition: bonds.h:30
Periodic dihedral.
Definition: bonds.h:179
Harmonic Bond.
Definition: bonds.h:86
virtual Variant type() const =0
Returns bond type (sett Variant enum)
FENE+WCA bond.
Definition: bonds.h:121
std::vector< Particle > ParticleVector
Storage type for collections of particles.
Definition: particle.h:253
Base class for bonded potentials.
Definition: bonds.h:17
FENE bond.
Definition: bonds.h:105
Finite Extensible Nonlinear Elastic (FENE) potential.
Definition: potentials.h:551
std::function< double(Geometry::DistanceFunction)> energyFunc
Calculates potential energy of bonded atoms(kT)
Definition: bonds.h:33
std::pair< int, Point > IndexAndForce
Force (second) on particle w. absolute index (first)
Definition: bonds.h:36
bool hasForceFunction() const
test if force function has been set
Definition: bonds.cpp:82
virtual int numindex() const =0
Required number of atom indices for bond.
Namespace for particle pair-potentials.
Definition: analysis.h:18
Harmonic torsion.
Definition: bonds.h:143
virtual void setEnergyFunction(const ParticleVector &particles)=0
Set energy function; store particles ref.
NLOHMANN_JSON_SERIALIZE_ENUM(SpheroCylinderData::PatchType, {{SpheroCylinderData::PatchType::Invalid, nullptr}, {SpheroCylinderData::PatchType::Full, "full"}, {SpheroCylinderData::PatchType::Capped, "capped"}, {SpheroCylinderData::PatchType::None, "none"}}) class AtomData
General properties for atoms.
Definition: atomdata.h:61
Harmonic dihedral.
Definition: bonds.h:199
virtual std::shared_ptr< BondData > clone() const =0
Make shared pointer copy of data.
std::function< std::vector< IndexAndForce >Geometry::DistanceFunction)> forceFunc
Calculates forces on bonded atoms (kT/Å)
Definition: bonds.h:39