[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 |
|
---|
[30c753] | 23 | #include <boost/iterator/transform_iterator.hpp>
|
---|
| 24 |
|
---|
[520c8b] | 25 | #include <string>
|
---|
| 26 |
|
---|
[6f0841] | 27 | #include "Atom/AtomSet.hpp"
|
---|
[ad011c] | 28 | #include "CodePatterns/Cacheable.hpp"
|
---|
[02ce36] | 29 | #include "CodePatterns/Observer/Observable.hpp"
|
---|
| 30 | #include "CodePatterns/Observer/ObservedIterator.hpp"
|
---|
[30c753] | 31 | #include "Descriptors/AtomIdDescriptor.hpp"
|
---|
[07a47e] | 32 | #include "Fragmentation/HydrogenSaturation_enum.hpp"
|
---|
[389cc8] | 33 | #include "Formula.hpp"
|
---|
[30c753] | 34 | #include "Helpers/defs.hpp"
|
---|
| 35 | #include "types.hpp"
|
---|
[14de469] | 36 |
|
---|
[30c753] | 37 | // TODO: Was is the include of MoleculeDescriptor_impl.hpp doing in molecule.hpp
|
---|
[97ebf8] | 38 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
|
---|
| 39 |
|
---|
[f66195] | 40 | /****************************************** forward declarations *****************************/
|
---|
| 41 |
|
---|
| 42 | class atom;
|
---|
| 43 | class bond;
|
---|
[b70721] | 44 | class BondedParticle;
|
---|
| 45 | class BondGraph;
|
---|
[49c059] | 46 | class DepthFirstSearchAnalysis;
|
---|
[f66195] | 47 | class element;
|
---|
| 48 | class ForceMatrix;
|
---|
[dadc74] | 49 | class Graph;
|
---|
[6bd7e0] | 50 | class LinkedCell_deprecated;
|
---|
[14de469] | 51 | class molecule;
|
---|
[2319ed] | 52 | class MoleculeLeafClass;
|
---|
[14de469] | 53 | class MoleculeListClass;
|
---|
[f66195] | 54 | class periodentafel;
|
---|
[1f91f4] | 55 | class RealSpaceMatrix;
|
---|
[f66195] | 56 | class Vector;
|
---|
[c550dd] | 57 | class Shape;
|
---|
[14de469] | 58 |
|
---|
| 59 | /******************************** Some definitions for easier reading **********************************/
|
---|
| 60 |
|
---|
[30c753] | 61 | struct FromIdToAtom :
|
---|
| 62 | public std::unary_function<atom *, atomId_t>
|
---|
| 63 | {
|
---|
| 64 | atom * operator()(atomId_t id) const {
|
---|
| 65 | return World::getInstance().getAtom(AtomById(id));
|
---|
| 66 | }
|
---|
| 67 | };
|
---|
| 68 |
|
---|
[14de469] | 69 | /************************************* Class definitions ****************************************/
|
---|
| 70 |
|
---|
| 71 | /** The complete molecule.
|
---|
| 72 | * Class incorporates number of types
|
---|
| 73 | */
|
---|
[34c43a] | 74 | class molecule : public Observable
|
---|
[e4afb4] | 75 | {
|
---|
[cbc5fb] | 76 | friend molecule *NewMolecule();
|
---|
| 77 | friend void DeleteMolecule(molecule *);
|
---|
[bd58fb] | 78 |
|
---|
[e4afb4] | 79 | public:
|
---|
| 80 | typedef std::set<atomId_t> atomIdSet;
|
---|
[30c753] | 81 | typedef boost::transform_iterator<FromIdToAtom, atomIdSet::iterator, atom *, atomId_t> iterator;
|
---|
[59fff1] | 82 | typedef boost::transform_iterator<FromIdToAtom, atomIdSet::const_iterator, const atom *, atomId_t const &> const_iterator;
|
---|
[e4afb4] | 83 |
|
---|
| 84 | const periodentafel * const elemente; //!< periodic table with each element
|
---|
| 85 | int MDSteps; //!< The number of MD steps in Trajectories
|
---|
| 86 | mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
---|
| 87 | mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
|
---|
| 88 | mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
|
---|
| 89 | bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
|
---|
| 90 | int IndexNr; //!< index of molecule in a MoleculeListClass
|
---|
| 91 | char name[MAXSTRINGSIZE]; //!< arbitrary name
|
---|
| 92 |
|
---|
| 93 | private:
|
---|
| 94 | Formula formula;
|
---|
[458c31] | 95 | Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
|
---|
| 96 | Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
|
---|
[e4afb4] | 97 | moleculeId_t id;
|
---|
| 98 | atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
|
---|
| 99 | protected:
|
---|
[ac9b56] | 100 |
|
---|
[e4afb4] | 101 | molecule(const periodentafel * const teil);
|
---|
| 102 | virtual ~molecule();
|
---|
[042f82] | 103 |
|
---|
[cbc5fb] | 104 | public:
|
---|
[520c8b] | 105 | //getter and setter
|
---|
[73a857] | 106 | const std::string getName() const;
|
---|
[ea7176] | 107 | int getAtomCount() const;
|
---|
| 108 | int doCountAtoms();
|
---|
[458c31] | 109 | int getBondCount() const;
|
---|
| 110 | int doCountBonds() const;
|
---|
[73a857] | 111 | moleculeId_t getId() const;
|
---|
[cbc5fb] | 112 | void setId(moleculeId_t);
|
---|
[520c8b] | 113 | void setName(const std::string);
|
---|
[73a857] | 114 | const Formula &getFormula() const;
|
---|
| 115 | unsigned int getElementCount() const;
|
---|
[389cc8] | 116 | bool hasElement(const element*) const;
|
---|
| 117 | bool hasElement(atomicNumber_t) const;
|
---|
| 118 | bool hasElement(const std::string&) const;
|
---|
| 119 |
|
---|
[a7a087] | 120 | virtual bool changeId(atomId_t newId);
|
---|
[520c8b] | 121 |
|
---|
[9317be] | 122 | World::AtomComposite getAtomSet() const;
|
---|
[3738f0] | 123 |
|
---|
[bd58fb] | 124 | iterator begin();
|
---|
| 125 | const_iterator begin() const;
|
---|
[e87acf] | 126 | iterator end();
|
---|
| 127 | const_iterator end() const;
|
---|
[9879f6] | 128 | bool empty() const;
|
---|
| 129 | size_t size() const;
|
---|
[e4afb4] | 130 | const_iterator find(atom * key) const;
|
---|
| 131 | pair<iterator, bool> insert(atom * const key);
|
---|
[6cfa36] | 132 | bool containsAtom(atom* key);
|
---|
[bd58fb] | 133 |
|
---|
[2e4105] | 134 | private:
|
---|
| 135 | friend void atom::removeFromMolecule();
|
---|
| 136 | /** Erase an atom from the list.
|
---|
| 137 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 138 | * otherwise it is not assured that the atom knows about it.
|
---|
| 139 | *
|
---|
| 140 | * @param loc locator to atom in list
|
---|
| 141 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 142 | */
|
---|
| 143 | const_iterator erase(const_iterator loc);
|
---|
| 144 | /** Erase an atom from the list.
|
---|
| 145 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 146 | * otherwise it is not assured that the atom knows about it.
|
---|
| 147 | *
|
---|
| 148 | * @param *key key to atom in list
|
---|
| 149 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 150 | */
|
---|
| 151 | const_iterator erase(atom * key);
|
---|
| 152 |
|
---|
| 153 | public:
|
---|
| 154 |
|
---|
[042f82] | 155 | /// remove atoms from molecule.
|
---|
| 156 | bool AddAtom(atom *pointer);
|
---|
| 157 | bool RemoveAtom(atom *pointer);
|
---|
| 158 | bool UnlinkAtom(atom *pointer);
|
---|
| 159 | bool CleanupMolecule();
|
---|
[9df680] | 160 | void removeAtomsinMolecule();
|
---|
[042f82] | 161 |
|
---|
| 162 | /// Add/remove atoms to/from molecule.
|
---|
| 163 | atom * AddCopyAtom(atom *pointer);
|
---|
| 164 | bool AddXYZFile(string filename);
|
---|
[e138de] | 165 | bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
---|
[cee0b57] | 166 | bond * AddBond(atom *first, atom *second, int degree = 1);
|
---|
[042f82] | 167 | bool RemoveBond(bond *pointer);
|
---|
| 168 | bool RemoveBonds(atom *BondPartner);
|
---|
[e4afb4] | 169 | bool hasBondStructure() const;
|
---|
[042f82] | 170 |
|
---|
| 171 | /// Find atoms.
|
---|
| 172 | atom * FindAtom(int Nr) const;
|
---|
| 173 | atom * AskAtom(string text);
|
---|
[59fff1] | 174 | bool isInMolecule(const atom * const _atom);
|
---|
[042f82] | 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);
|
---|
[07a47e] | 188 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenSaturation _saturation = DoSaturate);
|
---|
[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 |
|
---|