indigoX
molecule.hpp
Go to the documentation of this file.
1 
2 #include "../utils/fwd_declares.hpp"
3 
4 #include <bitset>
5 #include <cstdint>
6 #include <map>
7 #include <unordered_map>
8 #include <vector>
9 
10 #ifndef INDIGOX_CLASSES_MOLECULE_HPP
11 #define INDIGOX_CLASSES_MOLECULE_HPP
12 
13 namespace indigox {
14 
15  class Molecule {
17  friend class cereal::access;
18 
19  public:
22  using MoleculeAtoms = std::vector<Atom>;
25  using MoleculeBonds = std::vector<Bond>;
28  using MoleculeAngles = std::vector<Angle>;
31  using MoleculeDihedrals = std::vector<Dihedral>;
32 
33  using MoleculeResidues = std::vector<Residue>;
34 
35  private:
36  template <typename Archive>
37  void serialise(Archive &archive, const uint32_t version);
38 
39  public:
43  Molecule(std::string name);
44 
45  public:
48 
49  public:
53  bool HasAtom(const Atom &atom) const;
54 
58  bool HasBond(const Bond &bond) const;
59 
63  bool HasBond(const Atom &a, const Atom &b) const;
64 
68  bool HasAngle(const Angle &angle) const;
69 
76  bool HasAngle(const Atom &a, const Atom &b, const Atom &c);
77 
81  bool HasDihedral(const Dihedral &dihedral) const;
82 
88  bool HasDihedral(const Atom &a, const Atom &b, const Atom &c,
89  const Atom &d);
90 
93  int64_t NumAtoms() const;
94 
97  int64_t NumBonds() const;
98 
103  int64_t NumAngles();
104 
109  int64_t NumDihedrals();
110 
111  public:
118  Atom GetAtom(uint32_t pos) const;
119 
125  Atom GetAtomID(int64_t id) const;
126 
132  Atom GetAtomTag(int64_t tag) const;
133 
140  Bond GetBond(uint32_t pos) const;
141 
147  Bond GetBond(const Atom &a, const Atom &b) const;
148 
154  Bond GetBondID(int64_t id) const;
155 
161  Bond GetBondTag(int64_t tag) const;
162 
170  Angle GetAngle(uint32_t pos);
171 
179  Angle GetAngle(const Atom &a, const Atom &b, const Atom &c);
180 
187  Angle GetAngleID(int64_t id) const;
188 
195  Angle GetAngleTag(int64_t tag) const;
196 
204  Dihedral GetDihedral(uint32_t pos);
205 
212  Dihedral GetDihedral(const Atom &a, const Atom &b, const Atom &c,
213  const Atom &d);
214 
222  Dihedral GetDihedralID(int64_t id) const;
223 
231  Dihedral GetDihedralTag(int64_t tag) const;
232 
240  std::string GetFormula();
241 
244  const graph::MolecularGraph &GetGraph() const;
245 
247 
250  const std::string &GetName() const;
251 
254  int32_t GetMolecularCharge() const;
255 
258  void SetName(std::string name);
259 
263  void SetMolecularCharge(int32_t q);
264 
267  Atom NewAtom();
268 
272  Atom NewAtom(const Element &element);
273 
278  Atom NewAtom(const Element &element, double x, double y, double z);
279 
286  Bond NewBond(const Atom &a, const Atom &b);
287 
288  private:
292  Angle NewAngle(const Atom &a, const Atom &b, const Atom &c);
293 
294  Dihedral NewDihedral(const Atom &a, const Atom &b, const Atom &c,
295  const Atom &d, bool manual);
296 
297  public:
301  Dihedral NewDihedral(const Atom &a, const Atom &b, const Atom &c,
302  const Atom &d);
303 
310  bool RemoveAtom(const Atom &atom);
311 
318  bool RemoveBond(const Bond &bond);
319 
323  bool RemoveBond(const Atom &a, const Atom &b);
324 
325  public:
332  int64_t PerceiveAngles();
333 
340  int64_t PerceiveDihedrals();
341 
342  int32_t PerceiveResidues();
343  // size_t AssignElectrons();
344  // bool ApplyElectronAssignment(size_t);
345  // FCSCORE GetMinimumElectronAssignmentScore();
346 
352  void ReserveAtoms(int64_t num);
353 
359  void ReserveBonds(int64_t num);
360 
361  const MoleculeAtoms &GetAtoms() const;
362 
363  const MoleculeBonds &GetBonds() const;
364 
365  const MoleculeAngles &GetAngles(); // percevie first
366 
367  const MoleculeDihedrals &GetDihedrals(); // perceive first
368 
369  Residue GetResidueID(int32_t id); // perceive first
370 
371  const MoleculeResidues &GetResidues(); // perceive first
372 
373  const Forcefield &GetForcefield() const;
374 
375  void SetForcefield(const Forcefield &ff);
376 
377  void ResetForcefield(const Forcefield &ff);
378 
379  bool HasForcefield() const;
380 
381  void OptimiseChargeGroups();
382 
383  void ReorderAtoms(MoleculeAtoms &new_order);
384 
385  void ModificationMade();
386 
387  private:
388  struct Impl;
389  std::shared_ptr<Impl> m_data;
390  };
391 
392  void SaveMolecule(const Molecule &mol, std::string path);
393  Molecule LoadMolecule(std::string path);
394 
395 } // namespace indigox
396 
397 #endif /* INDIGOX_CLASSES_MOLECULE_HPP */
void OptimiseChargeGroups()
std::vector< Angle > MoleculeAngles
Container for storing IXAngle instances.
Definition: molecule.hpp:28
void SetForcefield(const Forcefield &ff)
Residue GetResidueID(int32_t id)
Angle GetAngle(uint32_t pos)
Get the angle at position pos.
#define INDIGOX_GENERIC_PIMPL_CLASS_DEFAULTS(class_name)
Definition: fwd_declares.hpp:18
std::vector< Atom > MoleculeAtoms
Container for storing IXAtom instances.
Definition: molecule.hpp:22
Definition: bond.hpp:11
void ResetForcefield(const Forcefield &ff)
bool RemoveBond(const Bond &bond)
Remove a bond from the molecule.
Definition: atom.hpp:13
int64_t PerceiveAngles()
Determine angles in the molecule.
const std::string & GetName() const
Get the name of the molecule.
Definition: condensed.hpp:131
Definition: residue.hpp:11
void ReserveAtoms(int64_t num)
Reserve storage space for atoms.
int64_t NumBonds() const
Get the number of bonds in the molecule.
const MoleculeResidues & GetResidues()
const MoleculeAtoms & GetAtoms() const
int64_t NumDihedrals()
Get the number of dihedrals in the molecule.
const graph::CondensedMolecularGraph & GetCondensedGraph() const
bool RemoveAtom(const Atom &atom)
Remove an atom from the molecule.
int32_t GetMolecularCharge() const
Get the molecular charge of the molecule.
void SetMolecularCharge(int32_t q)
Set the molecular charge of the molecule.
Class containing a graph representation of a molecule.
Definition: molecular.hpp:95
const Forcefield & GetForcefield() const
Molecule LoadMolecule(std::string path)
std::vector< Residue > MoleculeResidues
Definition: molecule.hpp:33
Namespace for all graph related functionality.
Definition: access.hpp:7
Atom GetAtomTag(int64_t tag) const
Get the first atom with the given tag.
Dihedral GetDihedralTag(int64_t tag) const
Get the first dihedral with the given tag.
bool HasAngle(const Angle &angle) const
Check if the angle is owned by this molecule.
int32_t PerceiveResidues()
Definition: angle.hpp:12
friend class cereal::access
Friendship allows serialisation.
Definition: molecule.hpp:17
const MoleculeAngles & GetAngles()
Atom GetAtom(uint32_t pos) const
Get the atom at position pos.
void SetName(std::string name)
Set the name of the molecule.
std::vector< Dihedral > MoleculeDihedrals
Container for storing IXDihedral instances.
Definition: molecule.hpp:31
std::vector< Bond > MoleculeBonds
Container for storing IXBond instances.
Definition: molecule.hpp:25
Angle GetAngleID(int64_t id) const
Get the angle with the given id.
const graph::MolecularGraph & GetGraph() const
Get the molecular graph for this molecule.
bool HasForcefield() const
void ReorderAtoms(MoleculeAtoms &new_order)
Definition: dihedral.hpp:14
void SaveMolecule(const Molecule &mol, std::string path)
Molecule()=default
Definition: molecule_impl.hpp:145
Bond GetBondID(int64_t id) const
Get the bond with the given id.
Definition: molecule.hpp:15
Read only class for storing elemental information.
Definition: periodictable.hpp:28
Bond GetBond(uint32_t pos) const
Get the bond at position pos.
bool HasDihedral(const Dihedral &dihedral) const
Check if the dihedral is owned by this molecule.
#define INDIGOX_GENERIC_PIMPL_CLASS_OPERATORS(class_name, short_name)
Definition: fwd_declares.hpp:26
Definition: forcefield.hpp:333
int64_t PerceiveDihedrals()
Determine dihedrals in the molecule.
int64_t NumAngles()
Get the number of angles in the molecule.
bool HasAtom(const Atom &atom) const
Check if the atom is owned by this molecule.
Dihedral GetDihedral(uint32_t pos)
Get the angle at position pos.
bool HasBond(const Bond &bond) const
Check if the bond is owned by this molecule.
Atom GetAtomID(int64_t id) const
Get the atom with the given id.
Atom NewAtom()
Create a new atom owned by the molecule.
Bond NewBond(const Atom &a, const Atom &b)
Create a bond between two atoms.
int64_t NumAtoms() const
Get the number of atoms in the molecule.
const MoleculeDihedrals & GetDihedrals()
Angle GetAngleTag(int64_t tag) const
Get the first angle with the given tag.
std::string GetFormula()
Get the molecular formula of the molecule.
const MoleculeBonds & GetBonds() const
Bond GetBondTag(int64_t tag) const
Get the first bond with the given tag.
void ReserveBonds(int64_t num)
Reserve storage space for bonds.
Dihedral GetDihedralID(int64_t id) const
Get the dihedral with the given id.