[cee0b57] | 1 | /** \file molecule.hpp
|
---|
[14de469] | 2 | *
|
---|
[69eb71] | 3 | * Class definitions of atom and molecule, element and periodentafel
|
---|
[14de469] | 4 | */
|
---|
| 5 |
|
---|
| 6 | #ifndef MOLECULES_HPP_
|
---|
| 7 | #define MOLECULES_HPP_
|
---|
| 8 |
|
---|
[f66195] | 9 | /*********************************************** includes ***********************************/
|
---|
| 10 |
|
---|
[962d8d] | 11 | #ifdef HAVE_CONFIG_H
|
---|
| 12 | #include <config.h>
|
---|
| 13 | #endif
|
---|
| 14 |
|
---|
[edb93c] | 15 | //// STL headers
|
---|
[14de469] | 16 | #include <map>
|
---|
| 17 | #include <set>
|
---|
[a564be] | 18 | #include <stack>
|
---|
[14de469] | 19 | #include <deque>
|
---|
[d7e30c] | 20 | #include <list>
|
---|
[5e0d1f] | 21 | #include <vector>
|
---|
[14de469] | 22 |
|
---|
[520c8b] | 23 | #include <string>
|
---|
| 24 |
|
---|
[68d781] | 25 | #include "types.hpp"
|
---|
[ad011c] | 26 | #include "CodePatterns/Observer.hpp"
|
---|
| 27 | #include "CodePatterns/ObservedIterator.hpp"
|
---|
| 28 | #include "CodePatterns/Cacheable.hpp"
|
---|
[07a47e] | 29 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
|
---|
[255829] | 30 | #include "Helpers/defs.hpp"
|
---|
[389cc8] | 31 | #include "Formula.hpp"
|
---|
[14d541] | 32 | #include "AtomSet.hpp"
|
---|
[14de469] | 33 |
|
---|
[97ebf8] | 34 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
|
---|
| 35 |
|
---|
[f66195] | 36 | /****************************************** forward declarations *****************************/
|
---|
| 37 |
|
---|
| 38 | class atom;
|
---|
| 39 | class bond;
|
---|
[b70721] | 40 | class BondedParticle;
|
---|
| 41 | class BondGraph;
|
---|
[49c059] | 42 | class DepthFirstSearchAnalysis;
|
---|
[f66195] | 43 | class element;
|
---|
| 44 | class ForceMatrix;
|
---|
[dadc74] | 45 | class Graph;
|
---|
[f66195] | 46 | class LinkedCell;
|
---|
[14de469] | 47 | class molecule;
|
---|
[2319ed] | 48 | class MoleculeLeafClass;
|
---|
[14de469] | 49 | class MoleculeListClass;
|
---|
[f66195] | 50 | class periodentafel;
|
---|
[1f91f4] | 51 | class RealSpaceMatrix;
|
---|
[f66195] | 52 | class Vector;
|
---|
[c550dd] | 53 | class Shape;
|
---|
[14de469] | 54 |
|
---|
| 55 | /******************************** Some definitions for easier reading **********************************/
|
---|
| 56 |
|
---|
| 57 | /************************************* Class definitions ****************************************/
|
---|
| 58 |
|
---|
| 59 | /** The complete molecule.
|
---|
| 60 | * Class incorporates number of types
|
---|
| 61 | */
|
---|
[34c43a] | 62 | class molecule : public Observable
|
---|
[e4afb4] | 63 | {
|
---|
[cbc5fb] | 64 | friend molecule *NewMolecule();
|
---|
| 65 | friend void DeleteMolecule(molecule *);
|
---|
[bd58fb] | 66 |
|
---|
[e4afb4] | 67 | public:
|
---|
| 68 | typedef ATOMSET(std::list) atomSet;
|
---|
| 69 | typedef std::set<atomId_t> atomIdSet;
|
---|
| 70 | typedef ObservedIterator<atomSet> iterator;
|
---|
| 71 | typedef atomSet::const_iterator const_iterator;
|
---|
| 72 |
|
---|
| 73 | const periodentafel * const elemente; //!< periodic table with each element
|
---|
| 74 | // old deprecated atom handling
|
---|
| 75 | //atom *start; //!< start of atom list
|
---|
| 76 | //atom *end; //!< end of atom list
|
---|
| 77 | //bond *first; //!< start of bond list
|
---|
| 78 | //bond *last; //!< end of bond list
|
---|
| 79 | int MDSteps; //!< The number of MD steps in Trajectories
|
---|
| 80 | mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
---|
| 81 | mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
|
---|
| 82 | mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
|
---|
| 83 | bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
|
---|
| 84 | //Vector Center; //!< Center of molecule in a global box
|
---|
| 85 | int IndexNr; //!< index of molecule in a MoleculeListClass
|
---|
| 86 | char name[MAXSTRINGSIZE]; //!< arbitrary name
|
---|
| 87 |
|
---|
| 88 | private:
|
---|
| 89 | Formula formula;
|
---|
[458c31] | 90 | Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
|
---|
| 91 | Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
|
---|
[e4afb4] | 92 | moleculeId_t id;
|
---|
| 93 | atomSet atoms; //<!list of atoms
|
---|
| 94 | atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
|
---|
| 95 | protected:
|
---|
| 96 | //void CountAtoms();
|
---|
| 97 | /**
|
---|
| 98 | * this iterator type should be used for internal variables, \
|
---|
[d3347e] | 99 | * since it will not lock
|
---|
[e4afb4] | 100 | */
|
---|
| 101 | typedef atomSet::iterator internal_iterator;
|
---|
[ac9b56] | 102 |
|
---|
[e4afb4] | 103 | molecule(const periodentafel * const teil);
|
---|
| 104 | virtual ~molecule();
|
---|
[042f82] | 105 |
|
---|
[cbc5fb] | 106 | public:
|
---|
[520c8b] | 107 | //getter and setter
|
---|
[73a857] | 108 | const std::string getName() const;
|
---|
[ea7176] | 109 | int getAtomCount() const;
|
---|
| 110 | int doCountAtoms();
|
---|
[458c31] | 111 | int getBondCount() const;
|
---|
| 112 | int doCountBonds() const;
|
---|
[73a857] | 113 | moleculeId_t getId() const;
|
---|
[cbc5fb] | 114 | void setId(moleculeId_t);
|
---|
[520c8b] | 115 | void setName(const std::string);
|
---|
[73a857] | 116 | const Formula &getFormula() const;
|
---|
| 117 | unsigned int getElementCount() const;
|
---|
[389cc8] | 118 | bool hasElement(const element*) const;
|
---|
| 119 | bool hasElement(atomicNumber_t) const;
|
---|
| 120 | bool hasElement(const std::string&) const;
|
---|
| 121 |
|
---|
[a7a087] | 122 | virtual bool changeId(atomId_t newId);
|
---|
[520c8b] | 123 |
|
---|
[9317be] | 124 | World::AtomComposite getAtomSet() const;
|
---|
[3738f0] | 125 |
|
---|
[bd58fb] | 126 | iterator begin();
|
---|
| 127 | const_iterator begin() const;
|
---|
[e87acf] | 128 | iterator end();
|
---|
| 129 | const_iterator end() const;
|
---|
[9879f6] | 130 | bool empty() const;
|
---|
| 131 | size_t size() const;
|
---|
[e4afb4] | 132 | const_iterator find(atom * key) const;
|
---|
| 133 | pair<iterator, bool> insert(atom * const key);
|
---|
[6cfa36] | 134 | bool containsAtom(atom* key);
|
---|
[bd58fb] | 135 |
|
---|
[2e4105] | 136 | private:
|
---|
| 137 | friend void atom::removeFromMolecule();
|
---|
| 138 | /** Erase an atom from the list.
|
---|
| 139 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 140 | * otherwise it is not assured that the atom knows about it.
|
---|
| 141 | *
|
---|
| 142 | * @param loc locator to atom in list
|
---|
| 143 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 144 | */
|
---|
| 145 | const_iterator erase(const_iterator loc);
|
---|
| 146 | /** Erase an atom from the list.
|
---|
| 147 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 148 | * otherwise it is not assured that the atom knows about it.
|
---|
| 149 | *
|
---|
| 150 | * @param *key key to atom in list
|
---|
| 151 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 152 | */
|
---|
| 153 | const_iterator erase(atom * key);
|
---|
| 154 |
|
---|
| 155 | public:
|
---|
| 156 |
|
---|
[042f82] | 157 | /// remove atoms from molecule.
|
---|
| 158 | bool AddAtom(atom *pointer);
|
---|
| 159 | bool RemoveAtom(atom *pointer);
|
---|
| 160 | bool UnlinkAtom(atom *pointer);
|
---|
| 161 | bool CleanupMolecule();
|
---|
[9df680] | 162 | void removeAtomsinMolecule();
|
---|
[042f82] | 163 |
|
---|
| 164 | /// Add/remove atoms to/from molecule.
|
---|
| 165 | atom * AddCopyAtom(atom *pointer);
|
---|
| 166 | bool AddXYZFile(string filename);
|
---|
[e138de] | 167 | bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
---|
[cee0b57] | 168 | bond * AddBond(atom *first, atom *second, int degree = 1);
|
---|
[042f82] | 169 | bool RemoveBond(bond *pointer);
|
---|
| 170 | bool RemoveBonds(atom *BondPartner);
|
---|
[e4afb4] | 171 | bool hasBondStructure() const;
|
---|
[042f82] | 172 |
|
---|
| 173 | /// Find atoms.
|
---|
| 174 | atom * FindAtom(int Nr) const;
|
---|
| 175 | atom * AskAtom(string text);
|
---|
| 176 |
|
---|
| 177 | /// Count and change present atoms' coordination.
|
---|
[e138de] | 178 | bool CenterInBox();
|
---|
| 179 | bool BoundInBox();
|
---|
| 180 | void CenterEdge(Vector *max);
|
---|
| 181 | void CenterOrigin();
|
---|
| 182 | void CenterPeriodic();
|
---|
| 183 | void CenterAtVector(Vector *newcenter);
|
---|
[042f82] | 184 | void Translate(const Vector *x);
|
---|
| 185 | void TranslatePeriodically(const Vector *trans);
|
---|
| 186 | void Mirror(const Vector *x);
|
---|
| 187 | void Align(Vector *n);
|
---|
[776b64] | 188 | void Scale(const double ** const factor);
|
---|
[07a47e] | 189 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenSaturation _saturation = DoSaturate);
|
---|
[4bb63c] | 190 | Vector * DetermineCenterOfGravity() const;
|
---|
[e138de] | 191 | Vector * DetermineCenterOfAll() const;
|
---|
[eddea2] | 192 | Vector * DetermineCenterOfBox() const;
|
---|
[437922] | 193 | void SetNameFromFilename(const char *filename);
|
---|
[042f82] | 194 | void SetBoxDimension(Vector *dim);
|
---|
[3c58f8] | 195 | bool ScanForPeriodicCorrection();
|
---|
[e138de] | 196 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
---|
[1f91f4] | 197 | RealSpaceMatrix getInertiaTensor() const;
|
---|
| 198 | void RotateToPrincipalAxisSystem(Vector &Axis);
|
---|
[042f82] | 199 |
|
---|
| 200 | bool CheckBounds(const Vector *x) const;
|
---|
| 201 | void GetAlignvector(struct lsq_params * par) const;
|
---|
| 202 |
|
---|
| 203 | /// Initialising routines in fragmentation
|
---|
[e138de] | 204 | void OutputBondsList() const;
|
---|
[49c059] | 205 |
|
---|
[266237] | 206 | bond * CopyBond(atom *left, atom *right, bond *CopyBond);
|
---|
| 207 |
|
---|
[e4afb4] | 208 | molecule *CopyMolecule() const;
|
---|
[c550dd] | 209 | molecule* CopyMoleculeFromSubRegion(const Shape&) const;
|
---|
[042f82] | 210 |
|
---|
| 211 | /// Fragment molecule by two different approaches:
|
---|
[e4afb4] | 212 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
---|
| 213 | bool StoreAdjacencyToFile(std::string filename, std::string path = "");
|
---|
[9879f6] | 214 | bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
|
---|
[b9772a] | 215 |
|
---|
[042f82] | 216 | // Recognize doubly appearing molecules in a list of them
|
---|
[e138de] | 217 | int * GetFatherSonAtomicMap(molecule *OtherMolecule);
|
---|
[99752a] | 218 | bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
|
---|
[c6123b] | 219 | bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount);
|
---|
[042f82] | 220 |
|
---|
| 221 | // Output routines.
|
---|
[e4afb4] | 222 | bool Output(std::ostream * const output) const;
|
---|
| 223 | bool OutputTrajectories(ofstream * const output) const;
|
---|
[e138de] | 224 | void OutputListOfBonds() const;
|
---|
| 225 | bool OutputXYZ(ofstream * const output) const;
|
---|
| 226 | bool OutputTrajectoriesXYZ(ofstream * const output);
|
---|
| 227 | bool Checkout(ofstream * const output) const;
|
---|
[042f82] | 228 |
|
---|
[c68025] | 229 | // Manipulation routines
|
---|
| 230 | void flipActiveFlag();
|
---|
| 231 |
|
---|
[e4afb4] | 232 | private:
|
---|
| 233 | int last_atom; //!< number given to last atom
|
---|
[14de469] | 234 | };
|
---|
| 235 |
|
---|
[cbc5fb] | 236 | molecule *NewMolecule();
|
---|
| 237 | void DeleteMolecule(molecule* mol);
|
---|
| 238 |
|
---|
[14de469] | 239 |
|
---|
| 240 |
|
---|
| 241 | #endif /*MOLECULES_HPP_*/
|
---|
| 242 |
|
---|