| 1 | /** \file molecule.hpp | 
|---|
| 2 | * | 
|---|
| 3 | * Class definitions of atom and molecule, element and periodentafel | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef MOLECULES_HPP_ | 
|---|
| 7 | #define MOLECULES_HPP_ | 
|---|
| 8 |  | 
|---|
| 9 | /*********************************************** includes ***********************************/ | 
|---|
| 10 |  | 
|---|
| 11 | #ifdef HAVE_CONFIG_H | 
|---|
| 12 | #include <config.h> | 
|---|
| 13 | #endif | 
|---|
| 14 |  | 
|---|
| 15 | //// STL headers | 
|---|
| 16 | #include <map> | 
|---|
| 17 | #include <set> | 
|---|
| 18 | #include <stack> | 
|---|
| 19 | #include <deque> | 
|---|
| 20 | #include <list> | 
|---|
| 21 | #include <vector> | 
|---|
| 22 |  | 
|---|
| 23 | #include <string> | 
|---|
| 24 |  | 
|---|
| 25 | #include "types.hpp" | 
|---|
| 26 | #include "CodePatterns/Observer.hpp" | 
|---|
| 27 | #include "CodePatterns/ObservedIterator.hpp" | 
|---|
| 28 | #include "CodePatterns/Cacheable.hpp" | 
|---|
| 29 | #include "Fragmentation/HydrogenSaturation_enum.hpp" | 
|---|
| 30 | #include "Helpers/defs.hpp" | 
|---|
| 31 | #include "Formula.hpp" | 
|---|
| 32 | #include "AtomSet.hpp" | 
|---|
| 33 |  | 
|---|
| 34 | #include "Descriptors/MoleculeDescriptor_impl.hpp" | 
|---|
| 35 |  | 
|---|
| 36 | /****************************************** forward declarations *****************************/ | 
|---|
| 37 |  | 
|---|
| 38 | class atom; | 
|---|
| 39 | class bond; | 
|---|
| 40 | class BondedParticle; | 
|---|
| 41 | class BondGraph; | 
|---|
| 42 | class DepthFirstSearchAnalysis; | 
|---|
| 43 | class element; | 
|---|
| 44 | class ForceMatrix; | 
|---|
| 45 | class Graph; | 
|---|
| 46 | class LinkedCell; | 
|---|
| 47 | class molecule; | 
|---|
| 48 | class MoleculeLeafClass; | 
|---|
| 49 | class MoleculeListClass; | 
|---|
| 50 | class periodentafel; | 
|---|
| 51 | class RealSpaceMatrix; | 
|---|
| 52 | class Vector; | 
|---|
| 53 | class Shape; | 
|---|
| 54 |  | 
|---|
| 55 | /******************************** Some definitions for easier reading **********************************/ | 
|---|
| 56 |  | 
|---|
| 57 | /************************************* Class definitions ****************************************/ | 
|---|
| 58 |  | 
|---|
| 59 | /** The complete molecule. | 
|---|
| 60 | * Class incorporates number of types | 
|---|
| 61 | */ | 
|---|
| 62 | class molecule : public Observable | 
|---|
| 63 | { | 
|---|
| 64 | friend molecule *NewMolecule(); | 
|---|
| 65 | friend void DeleteMolecule(molecule *); | 
|---|
| 66 |  | 
|---|
| 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; | 
|---|
| 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() | 
|---|
| 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, \ | 
|---|
| 99 | * since it will not lock | 
|---|
| 100 | */ | 
|---|
| 101 | typedef atomSet::iterator internal_iterator; | 
|---|
| 102 |  | 
|---|
| 103 | molecule(const periodentafel * const teil); | 
|---|
| 104 | virtual ~molecule(); | 
|---|
| 105 |  | 
|---|
| 106 | public: | 
|---|
| 107 | //getter and setter | 
|---|
| 108 | const std::string getName() const; | 
|---|
| 109 | int getAtomCount() const; | 
|---|
| 110 | int doCountAtoms(); | 
|---|
| 111 | int getBondCount() const; | 
|---|
| 112 | int doCountBonds() const; | 
|---|
| 113 | moleculeId_t getId() const; | 
|---|
| 114 | void setId(moleculeId_t); | 
|---|
| 115 | void setName(const std::string); | 
|---|
| 116 | const Formula &getFormula() const; | 
|---|
| 117 | unsigned int getElementCount() const; | 
|---|
| 118 | bool hasElement(const element*) const; | 
|---|
| 119 | bool hasElement(atomicNumber_t) const; | 
|---|
| 120 | bool hasElement(const std::string&) const; | 
|---|
| 121 |  | 
|---|
| 122 | virtual bool changeId(atomId_t newId); | 
|---|
| 123 |  | 
|---|
| 124 | World::AtomComposite getAtomSet() const; | 
|---|
| 125 |  | 
|---|
| 126 | iterator begin(); | 
|---|
| 127 | const_iterator begin() const; | 
|---|
| 128 | iterator end(); | 
|---|
| 129 | const_iterator end() const; | 
|---|
| 130 | bool empty() const; | 
|---|
| 131 | size_t size() const; | 
|---|
| 132 | const_iterator find(atom * key) const; | 
|---|
| 133 | pair<iterator, bool> insert(atom * const key); | 
|---|
| 134 | bool containsAtom(atom* key); | 
|---|
| 135 |  | 
|---|
| 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 |  | 
|---|
| 157 | /// remove atoms from molecule. | 
|---|
| 158 | bool AddAtom(atom *pointer); | 
|---|
| 159 | bool RemoveAtom(atom *pointer); | 
|---|
| 160 | bool UnlinkAtom(atom *pointer); | 
|---|
| 161 | bool CleanupMolecule(); | 
|---|
| 162 | void removeAtomsinMolecule(); | 
|---|
| 163 |  | 
|---|
| 164 | /// Add/remove atoms to/from molecule. | 
|---|
| 165 | atom * AddCopyAtom(atom *pointer); | 
|---|
| 166 | bool AddXYZFile(string filename); | 
|---|
| 167 | bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem); | 
|---|
| 168 | bond * AddBond(atom *first, atom *second, int degree = 1); | 
|---|
| 169 | bool RemoveBond(bond *pointer); | 
|---|
| 170 | bool RemoveBonds(atom *BondPartner); | 
|---|
| 171 | bool hasBondStructure() const; | 
|---|
| 172 |  | 
|---|
| 173 | /// Find atoms. | 
|---|
| 174 | atom * FindAtom(int Nr) const; | 
|---|
| 175 | atom * AskAtom(string text); | 
|---|
| 176 |  | 
|---|
| 177 | /// Count and change present atoms' coordination. | 
|---|
| 178 | bool CenterInBox(); | 
|---|
| 179 | bool BoundInBox(); | 
|---|
| 180 | void CenterEdge(Vector *max); | 
|---|
| 181 | void CenterOrigin(); | 
|---|
| 182 | void CenterPeriodic(); | 
|---|
| 183 | void CenterAtVector(Vector *newcenter); | 
|---|
| 184 | void Translate(const Vector *x); | 
|---|
| 185 | void TranslatePeriodically(const Vector *trans); | 
|---|
| 186 | void Mirror(const Vector *x); | 
|---|
| 187 | void Align(Vector *n); | 
|---|
| 188 | void Scale(const double ** const factor); | 
|---|
| 189 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenSaturation _saturation = DoSaturate); | 
|---|
| 190 | Vector * DetermineCenterOfGravity() const; | 
|---|
| 191 | Vector * DetermineCenterOfAll() const; | 
|---|
| 192 | Vector * DetermineCenterOfBox() const; | 
|---|
| 193 | void SetNameFromFilename(const char *filename); | 
|---|
| 194 | void SetBoxDimension(Vector *dim); | 
|---|
| 195 | bool ScanForPeriodicCorrection(); | 
|---|
| 196 | double VolumeOfConvexEnvelope(bool IsAngstroem); | 
|---|
| 197 | RealSpaceMatrix getInertiaTensor() const; | 
|---|
| 198 | void RotateToPrincipalAxisSystem(Vector &Axis); | 
|---|
| 199 |  | 
|---|
| 200 | bool CheckBounds(const Vector *x) const; | 
|---|
| 201 | void GetAlignvector(struct lsq_params * par) const; | 
|---|
| 202 |  | 
|---|
| 203 | /// Initialising routines in fragmentation | 
|---|
| 204 | void OutputBondsList() const; | 
|---|
| 205 |  | 
|---|
| 206 | bond * CopyBond(atom *left, atom *right, bond *CopyBond); | 
|---|
| 207 |  | 
|---|
| 208 | molecule *CopyMolecule() const; | 
|---|
| 209 | molecule* CopyMoleculeFromSubRegion(const Shape&) const; | 
|---|
| 210 |  | 
|---|
| 211 | /// Fragment molecule by two different approaches: | 
|---|
| 212 | bool StoreBondsToFile(std::string filename, std::string path = ""); | 
|---|
| 213 | bool StoreAdjacencyToFile(std::string filename, std::string path = ""); | 
|---|
| 214 | bool CreateFatherLookupTable(atom **&LookupTable, int count = 0); | 
|---|
| 215 |  | 
|---|
| 216 | // Recognize doubly appearing molecules in a list of them | 
|---|
| 217 | int * GetFatherSonAtomicMap(molecule *OtherMolecule); | 
|---|
| 218 | bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false); | 
|---|
| 219 | bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount); | 
|---|
| 220 |  | 
|---|
| 221 | // Output routines. | 
|---|
| 222 | bool Output(std::ostream * const output) const; | 
|---|
| 223 | bool OutputTrajectories(ofstream * const output) const; | 
|---|
| 224 | void OutputListOfBonds() const; | 
|---|
| 225 | bool OutputXYZ(ofstream * const output) const; | 
|---|
| 226 | bool OutputTrajectoriesXYZ(ofstream * const output); | 
|---|
| 227 | bool Checkout(ofstream * const output) const; | 
|---|
| 228 |  | 
|---|
| 229 | // Manipulation routines | 
|---|
| 230 | void flipActiveFlag(); | 
|---|
| 231 |  | 
|---|
| 232 | private: | 
|---|
| 233 | int last_atom; //!< number given to last atom | 
|---|
| 234 | }; | 
|---|
| 235 |  | 
|---|
| 236 | molecule *NewMolecule(); | 
|---|
| 237 | void DeleteMolecule(molecule* mol); | 
|---|
| 238 |  | 
|---|
| 239 |  | 
|---|
| 240 |  | 
|---|
| 241 | #endif /*MOLECULES_HPP_*/ | 
|---|
| 242 |  | 
|---|