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