indigoX
forcefield.hpp
Go to the documentation of this file.
1 
2 #include "../utils/fwd_declares.hpp"
3 #include "periodictable.hpp"
4 
5 #include <EASTL/bitset.h>
6 #include <map>
7 #include <memory>
8 #include <vector>
9 
10 #ifndef INDIGOX_CLASSES_FORCEFIELD_HPP
11 #define INDIGOX_CLASSES_FORCEFIELD_HPP
12 
13 namespace indigox {
14 
16  using FFParam = std::initializer_list<double>;
17 
18  class FFAtom {
20  friend class cereal::access;
22  friend class Forcefield;
23 
24  private:
25  template <typename Archive>
26  void serialise(Archive &archive, const uint32_t version);
27 
28  public:
31 
32  private:
38  FFAtom(int32_t id, std::string name, const Element &element,
39  const Forcefield &ff);
40 
41  public:
44  int32_t GetID() const;
45 
48  std::string GetName() const;
49 
50  Forcefield GetForcefield() const;
51  Element GetElement() const;
52 
53  private:
54  struct Impl;
55  std::shared_ptr<Impl> m_data;
56  };
57 
58  class FFBond {
59  public:
61  friend class Forcefield;
63  friend class cereal::access;
64 
68  enum class Type {
69  Empty,
70  Harmonic,
71  Quartic,
73  Morse,
75  Cubic,
76  FENE
77  };
78 
79  private:
81  enum AllowEnum {
82  Allow_ForceConstant,
83  Allow_IdealLength,
84  num_allow_positions
85  };
86 
88  enum StoreEnum {
89  Store_ForceConstant = 0,
90  Store_IdealLength = 1,
91  STORE_SIZE = 2
92  };
93 
95  using AllowedMask = eastl::bitset<num_allow_positions, uint8_t>;
96 
98  using DataStore = std::array<double, STORE_SIZE>;
99 
100  private:
101  template <typename Archive>
102  void serialise(Archive &archive, const uint32_t version);
103 
104  public:
107 
108  private:
115  FFBond(Type type, int32_t id, FFParam params, const Forcefield &ff);
116 
117  public:
122  double GetForceConstant() const;
123 
127  double GetIdealLength() const;
128 
131  Type GetType() const;
132 
135  int32_t GetID() const;
136 
141  FFBond GetLinkedType() const;
142 
143  Forcefield GetForcefield() const;
144 
145  private:
146  struct Impl;
147  std::shared_ptr<Impl> m_data;
148  };
150 
151  class FFAngle {
152  public:
154  friend class Forcefield;
156  friend class cereal::access;
157 
162 
163  private:
165  enum AllowEnum {
166  Allow_ForceConstant,
167  Allow_IdealAngle,
168  num_allow_positions
169  };
170 
172  enum StoreEnum {
173  Store_ForceConstant = 0,
174  Store_IdealAngle = 1,
175  STORE_SIZE = 2
176  };
177 
179  using DataStore = std::array<double, STORE_SIZE>;
181  using AllowedMask = eastl::bitset<num_allow_positions, uint8_t>;
182 
183  private:
184  template <typename Archive>
185  void serialise(Archive &archive, const uint32_t version);
186 
187  public:
190 
191  private:
198  FFAngle(Type type, int32_t id, FFParam parameters, const Forcefield &ff);
199 
200  public:
205  double GetForceConstant() const;
206 
210  double GetIdealAngle() const;
211 
214  Type GetType() const;
215 
218  int32_t GetID() const;
219 
224  FFAngle GetLinkedType() const;
225 
226  Forcefield GetForcefield() const;
227 
228  private:
229  struct Impl;
230  std::shared_ptr<Impl> m_data;
231  };
233 
234  class FFDihedral {
235  public:
237  friend class Forcefield;
239  friend class cereal::access;
240 
244  enum class Type {
245  Empty,
246  Proper,
247  Improper,
250  Fourier,
251  Restricted
252  };
253 
254  private:
256  enum AllowEnum {
257  Allow_PhaseShift,
258  Allow_ForceConstant,
259  Allow_Multiplicity,
260  Allow_IdealAngle,
261  num_allow_positions
262  };
263 
265  enum StoreEnum {
266  Store_PhaseShift = 0,
267  Store_ForceConstant = 1,
268  Store_Multiplicity = 2,
269  Store_IdealAngle = 0,
270  STORE_SIZE = 3
271  };
272 
274  using DataStore = std::array<double, STORE_SIZE>;
276  using AllowedMask = eastl::bitset<num_allow_positions>;
277 
278  private:
279  template <typename Archive>
280  void serialise(Archive &archive, const uint32_t version);
281 
282  public:
285 
286  private:
293  FFDihedral(Type type, int32_t id, FFParam parameters, const Forcefield &ff);
294 
295  public:
299  double GetPhaseShift() const;
300 
305  double GetForceConstant() const;
306 
310  int32_t GetMultiplicity() const;
311 
315  double GetIdealAngle() const;
316 
319  Type GetType() const;
320 
323  int32_t GetID() const;
324 
325  Forcefield GetForcefield() const;
326 
327  private:
328  struct Impl;
329  std::shared_ptr<Impl> m_data;
330  };
332 
333  class Forcefield {
335  friend class cereal::access;
336 
337  public:
341  enum class Family { Empty, GROMOS, CHARMM, AMBER, Other };
342 
343  private:
345  using AtomTypes = std::vector<FFAtom>;
347  using BondTypes = std::map<BondType, std::vector<FFBond>>;
349  using AngleTypes = std::map<AngleType, std::vector<FFAngle>>;
351  using DihedralTypes = std::map<DihedralType, std::vector<FFDihedral>>;
352 
353  public:
356 
365  Forcefield(Family family, std::string name);
366 
367  private:
368  template <typename Archive>
369  void serialise(Archive &archive, const uint32_t version);
370 
371  private:
377  FFBond NewBondType(BondType type, int32_t id, FFParam param);
378 
384  FFAngle NewAngleType(AngleType type, int32_t id, FFParam param);
385 
391  FFDihedral NewDihedralType(DihedralType type, int32_t id, FFParam param);
392 
393  public:
400  FFAtom NewAtomType(int32_t id, std::string name, const Element &element);
401 
404  void ReserveAtomTypes(size_t size);
405 
414  FFBond NewBondType(BondType type, int32_t id, double a, double b);
415 
422  void LinkBondTypes(const FFBond &a, const FFBond &b);
423 
427  void ReserveBondTypes(BondType type, size_t size);
428 
437  FFAngle NewAngleType(AngleType type, int32_t id, double a, double b);
438 
446  void LinkAngleTypes(const FFAngle &a, const FFAngle &b);
447 
451  void ReserveAngleTypes(AngleType type, size_t size);
452 
461  FFDihedral NewDihedralType(DihedralType type, int32_t id, double a,
462  double b, double c);
463 
472  FFDihedral NewDihedralType(DihedralType type, int32_t id, double a,
473  double b);
474 
478  void ReserveDihedralTypes(DihedralType type, size_t size);
479 
480  public:
484  FFAtom GetAtomType(std::string name) const;
485 
489  FFAtom GetAtomType(int32_t id) const;
490 
493  size_t NumAtomTypes() const;
494 
499  FFBond GetBondType(BondType type, int32_t id) const;
500 
506  FFBond GetBondType(int32_t id) const;
507 
512  size_t NumBondTypes() const;
513 
520  size_t NumBondTypes(BondType type) const;
521 
526  FFAngle GetAngleType(AngleType type, int32_t id) const;
527 
533  FFAngle GetAngleType(int32_t id) const;
534 
539  size_t NumAngleTypes() const;
540 
547  size_t NumAngleTypes(AngleType type) const;
548 
553  FFDihedral GetDihedralType(DihedralType type, int32_t id) const;
554 
560  FFDihedral GetDihedralType(int32_t id) const;
561 
566  size_t NumDihedralTypes() const;
567 
574  size_t NumDihedralTypes(DihedralType type) const;
575 
578  Family GetFamily() const;
579 
582  std::string GetName() const;
583 
584  private:
585  struct Impl;
586  std::shared_ptr<Impl> m_data;
587  };
589 
593 
594  std::ostream &operator<<(std::ostream &os, BondType type);
595  std::ostream &operator<<(std::ostream &os, AngleType type);
596  std::ostream &operator<<(std::ostream &os, DihedralType type);
597 } // namespace indigox
598 
599 #endif /* INDIGOX_CLASSES_FORCEFIELD_HPP */
FFAtom NewAtomType(int32_t id, std::string name, const Element &element)
Add a new atom type to the forcefield.
Definition: forcefield.hpp:18
void ReserveAngleTypes(AngleType type, size_t size)
Reserve space for angle types.
Definition: forcefield.hpp:58
size_t NumBondTypes() const
Get the total number of bond types in the forcefield.
#define INDIGOX_GENERIC_PIMPL_CLASS_DEFAULTS(class_name)
Definition: fwd_declares.hpp:18
FFAtom()=default
FFAngle()=default
int32_t GetID() const
Get the ID for this type.
Type GetType() const
Get the potential energy function type.
Family
Enum for the different families of forcefields.
Definition: forcefield.hpp:341
int32_t GetID() const
Get the ID for this type.
Type
Enum for the different function types a dihedral term can have.
Definition: forcefield.hpp:244
int32_t GetMultiplicity() const
Get the multiplicity.
void LinkBondTypes(const FFBond &a, const FFBond &b)
Link together two equivalent bond types.
FFAngle GetAngleType(AngleType type, int32_t id) const
Get the type of angle with the given id.
An empty bond type with no parameters.
Definition: forcefield.hpp:234
friend class cereal::access
Friendship allows serialisation.
Definition: forcefield.hpp:156
std::string GetName() const
Get the name for this type.
double GetIdealAngle() const
Get the ideal angle (in degrees).
Forcefield GetForcefield() const
double GetIdealLength() const
Get the ideal angle (in degrees).
FFBond()=default
FFAngle GetLinkedType() const
Get the linked type for this type.
double GetForceConstant() const
Get the force constant.
Namespace for all graph related functionality.
Definition: access.hpp:7
FFBond GetBondType(BondType type, int32_t id) const
Get the type of bond with the given id.
double GetIdealAngle() const
Get the ideal angle (in degrees).
Forcefield GetForcefield() const
size_t NumAtomTypes() const
Get the number of atom types in the forcefield.
friend class cereal::access
Friendship allows serialisation.
Definition: forcefield.hpp:335
int32_t GetID() const
Get the ID for this type.
Forcefield GetForcefield() const
Type GetType() const
Get the potential energy function type.
size_t NumDihedralTypes() const
Get the number of dihedral types in the forcefield.
int32_t GetID() const
Get the ID for this type.
Element GetElement() const
Type GetType() const
Get the potential energy function type.
friend class cereal::access
Friendship allows serialisation.
Definition: forcefield.hpp:63
Family GetFamily() const
Get the family of the forcefield.
Type
Enum for the different function types a bond term can have.
Definition: forcefield.hpp:68
double GetPhaseShift() const
Get the phase shift (in degrees).
FFDihedral GetDihedralType(DihedralType type, int32_t id) const
Get the type of dihedral with the given id.
FFAtom GetAtomType(std::string name) const
Get the AtomType with the given name.
Forcefield GetForcefield() const
friend class cereal::access
Friendship allows serialisation.
Definition: forcefield.hpp:239
Read only class for storing elemental information.
Definition: periodictable.hpp:28
void ReserveAtomTypes(size_t size)
Reserve space for atom types.
void LinkAngleTypes(const FFAngle &a, const FFAngle &b)
Link together two equivalent angle types.
Type
Enum for the different function types a angle term can have.
Definition: forcefield.hpp:161
#define INDIGOX_GENERIC_PIMPL_CLASS_OPERATORS(class_name, short_name)
Definition: fwd_declares.hpp:26
Definition: forcefield.hpp:333
double GetForceConstant() const
Get the force constant.
std::initializer_list< double > FFParam
type for collection of parameter inputs
Definition: forcefield.hpp:16
void ReserveBondTypes(BondType type, size_t size)
Reserve space for bond types.
std::ostream & operator<<(std::ostream &os, const Dihedral &dhd)
size_t NumAngleTypes() const
Get the number of angle types in the forcefield.
void ReserveDihedralTypes(DihedralType type, size_t size)
Reserve space for dihedral types.
Definition: forcefield.hpp:151
FFBond GetLinkedType() const
Get the linked type for this type.
double GetForceConstant() const
Get the force constant.
std::string GetName() const
Get the name of the forcefield.
friend class cereal::access
Friendship allows serialisation.
Definition: forcefield.hpp:20
Forcefield GenerateGROMOS54A7()