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