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