[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;
|
---|
[6d551c] | 49 | class ListOfLocalAtoms_t;
|
---|
[14de469] | 50 | class molecule;
|
---|
[2319ed] | 51 | class MoleculeLeafClass;
|
---|
[14de469] | 52 | class MoleculeListClass;
|
---|
[c67ff9] | 53 | class MoleculeUnittest;
|
---|
[1f91f4] | 54 | class RealSpaceMatrix;
|
---|
[f66195] | 55 | class Vector;
|
---|
[14de469] | 56 |
|
---|
| 57 | /************************************* Class definitions ****************************************/
|
---|
| 58 |
|
---|
[a7aebd] | 59 | /** External function to remove all atoms since this will also delete the molecule
|
---|
| 60 | *
|
---|
| 61 | * \param _mol ref pointer to molecule to destroy
|
---|
| 62 | */
|
---|
| 63 | void removeAtomsinMolecule(molecule *&_mol);
|
---|
| 64 |
|
---|
[14de469] | 65 | /** The complete molecule.
|
---|
| 66 | * Class incorporates number of types
|
---|
| 67 | */
|
---|
[34c43a] | 68 | class molecule : public Observable
|
---|
[e4afb4] | 69 | {
|
---|
[c67ff9] | 70 | //!> grant unit test access
|
---|
| 71 | friend class MoleculeUnittest;
|
---|
| 72 | //!> function may access cstor
|
---|
[cbc5fb] | 73 | friend molecule *NewMolecule();
|
---|
[c67ff9] | 74 | //!> function may access dstor
|
---|
[cbc5fb] | 75 | friend void DeleteMolecule(molecule *);
|
---|
[bd58fb] | 76 |
|
---|
[e4afb4] | 77 | public:
|
---|
[8e1f901] | 78 | typedef AtomIdSet::atomIdSet atomIdSet;
|
---|
| 79 | typedef AtomIdSet::iterator iterator;
|
---|
| 80 | typedef AtomIdSet::const_iterator const_iterator;
|
---|
[e4afb4] | 81 |
|
---|
| 82 | int MDSteps; //!< The number of MD steps in Trajectories
|
---|
| 83 | mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
|
---|
| 84 | mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
|
---|
| 85 | bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
|
---|
| 86 | int IndexNr; //!< index of molecule in a MoleculeListClass
|
---|
| 87 | char name[MAXSTRINGSIZE]; //!< arbitrary name
|
---|
| 88 |
|
---|
| 89 | private:
|
---|
| 90 | Formula formula;
|
---|
[e791dc] | 91 | Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
---|
[458c31] | 92 | Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
|
---|
[e4afb4] | 93 | moleculeId_t id;
|
---|
[8e1f901] | 94 | AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
|
---|
[560bbe] | 95 | IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
|
---|
[c6ab91] | 96 | typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
|
---|
| 97 | LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
|
---|
[560bbe] | 98 |
|
---|
[e4afb4] | 99 | protected:
|
---|
[ac9b56] | 100 |
|
---|
[4d2b33] | 101 | molecule();
|
---|
[e4afb4] | 102 | virtual ~molecule();
|
---|
[042f82] | 103 |
|
---|
[6a3c83] | 104 | public:
|
---|
| 105 |
|
---|
| 106 | /******* Notifications *******/
|
---|
| 107 |
|
---|
| 108 | //!> enumeration of present notification types: only insertion/removal of atoms or molecules
|
---|
| 109 | enum NotificationType {
|
---|
| 110 | AtomInserted,
|
---|
| 111 | AtomRemoved,
|
---|
| 112 | AtomNrChanged,
|
---|
[c32d21] | 113 | AtomMoved,
|
---|
[6b6959] | 114 | FormulaChanged,
|
---|
[6a3c83] | 115 | MoleculeNameChanged,
|
---|
[f54524] | 116 | IndexChanged,
|
---|
[24edfe] | 117 | AboutToBeRemoved,
|
---|
[6a3c83] | 118 | NotificationType_MAX
|
---|
| 119 | };
|
---|
| 120 |
|
---|
[8c001a] | 121 | //>! access to last changed element (atom)
|
---|
| 122 | const atom* lastChanged() const
|
---|
| 123 | { return _lastchangedatom; }
|
---|
| 124 |
|
---|
[cbc5fb] | 125 | public:
|
---|
[520c8b] | 126 | //getter and setter
|
---|
[73a857] | 127 | const std::string getName() const;
|
---|
[ea7176] | 128 | int getAtomCount() const;
|
---|
[e791dc] | 129 | size_t doCountNoNonHydrogen() const;
|
---|
| 130 | size_t getNoNonHydrogen() const;
|
---|
[458c31] | 131 | int getBondCount() const;
|
---|
| 132 | int doCountBonds() const;
|
---|
[73a857] | 133 | moleculeId_t getId() const;
|
---|
[cbc5fb] | 134 | void setId(moleculeId_t);
|
---|
[520c8b] | 135 | void setName(const std::string);
|
---|
[73a857] | 136 | const Formula &getFormula() const;
|
---|
| 137 | unsigned int getElementCount() const;
|
---|
[389cc8] | 138 | bool hasElement(const element*) const;
|
---|
| 139 | bool hasElement(atomicNumber_t) const;
|
---|
| 140 | bool hasElement(const std::string&) const;
|
---|
| 141 |
|
---|
[a7a087] | 142 | virtual bool changeId(atomId_t newId);
|
---|
[520c8b] | 143 |
|
---|
[f01769] | 144 | World::AtomComposite getAtomSet();
|
---|
| 145 | World::ConstAtomComposite getAtomSet() const;
|
---|
[3738f0] | 146 |
|
---|
[8e1f901] | 147 | // simply pass on all functions to AtomIdSet
|
---|
| 148 | iterator begin() {
|
---|
| 149 | return atomIds.begin();
|
---|
| 150 | }
|
---|
| 151 | const_iterator begin() const
|
---|
| 152 | {
|
---|
| 153 | return atomIds.begin();
|
---|
| 154 | }
|
---|
| 155 | iterator end()
|
---|
| 156 | {
|
---|
| 157 | return atomIds.end();
|
---|
| 158 | }
|
---|
| 159 | const_iterator end() const
|
---|
| 160 | {
|
---|
| 161 | return atomIds.end();
|
---|
| 162 | }
|
---|
| 163 | bool empty() const
|
---|
| 164 | {
|
---|
| 165 | return atomIds.empty();
|
---|
| 166 | }
|
---|
| 167 | size_t size() const
|
---|
| 168 | {
|
---|
| 169 | return atomIds.size();
|
---|
| 170 | }
|
---|
| 171 | const_iterator find(atom * key) const
|
---|
| 172 | {
|
---|
| 173 | return atomIds.find(key);
|
---|
| 174 | }
|
---|
[c67ff9] | 175 |
|
---|
| 176 | /** Returns the set of atomic ids contained in this molecule.
|
---|
| 177 | *
|
---|
| 178 | * @return set of atomic ids
|
---|
| 179 | */
|
---|
[8e1f901] | 180 | const atomIdSet & getAtomIds() const {
|
---|
| 181 | return atomIds.getAtomIds();
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | std::pair<iterator, bool> insert(atom * const key);
|
---|
| 185 |
|
---|
[6aad6f] | 186 | /** Predicate whether given \a key is contained in this molecule.
|
---|
| 187 | *
|
---|
| 188 | * @param key atom to check
|
---|
| 189 | * @return true - is contained, false - else
|
---|
| 190 | */
|
---|
| 191 | bool containsAtom(const atom* key) const
|
---|
| 192 | {
|
---|
| 193 | return atomIds.contains(key);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | /** Predicate whether given \a id is contained in this molecule.
|
---|
| 197 | *
|
---|
| 198 | * @param id atomic id to check
|
---|
| 199 | * @return true - is contained, false - else
|
---|
| 200 | */
|
---|
| 201 | bool containsAtom(const atomId_t id) const
|
---|
| 202 | {
|
---|
| 203 | return atomIds.contains(id);
|
---|
| 204 | }
|
---|
[bd58fb] | 205 |
|
---|
[2e4105] | 206 | private:
|
---|
| 207 | friend void atom::removeFromMolecule();
|
---|
| 208 | /** Erase an atom from the list.
|
---|
| 209 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 210 | * otherwise it is not assured that the atom knows about it.
|
---|
| 211 | *
|
---|
| 212 | * @param loc locator to atom in list
|
---|
| 213 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 214 | */
|
---|
| 215 | const_iterator erase(const_iterator loc);
|
---|
[8e1f901] | 216 |
|
---|
[2e4105] | 217 | /** Erase an atom from the list.
|
---|
| 218 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 219 | * otherwise it is not assured that the atom knows about it.
|
---|
| 220 | *
|
---|
| 221 | * @param *key key to atom in list
|
---|
| 222 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 223 | */
|
---|
| 224 | const_iterator erase(atom * key);
|
---|
| 225 |
|
---|
[560bbe] | 226 | private:
|
---|
| 227 | friend bool atom::changeNr(int newId);
|
---|
| 228 | /**
|
---|
| 229 | * used when changing an ParticleInfo::Nr.
|
---|
| 230 | * Note that this number is local with this molecule.
|
---|
| 231 | * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
|
---|
| 232 | *
|
---|
| 233 | * @param oldNr old Nr
|
---|
| 234 | * @param newNr new Nr to set
|
---|
| 235 | * @param *target ref to atom
|
---|
| 236 | * @return indicates wether the change could be done or not.
|
---|
| 237 | */
|
---|
| 238 | bool changeAtomNr(int oldNr, int newNr, atom* target=0);
|
---|
| 239 |
|
---|
[c6ab91] | 240 | /** Updates the internal lookup fro local to global indices.
|
---|
| 241 | *
|
---|
| 242 | * \param pointer pointer to atom
|
---|
| 243 | */
|
---|
| 244 | void InsertLocalToGlobalId(atom * const pointer);
|
---|
| 245 |
|
---|
[560bbe] | 246 | /** Sets the name of the atom.
|
---|
| 247 | *
|
---|
| 248 | * The name is set via its element symbol and its internal ParticleInfo::Nr.
|
---|
| 249 | *
|
---|
| 250 | * @param _atom atom whose name to set
|
---|
| 251 | */
|
---|
| 252 | void setAtomName(atom *_atom) const;
|
---|
| 253 |
|
---|
[9b3262b] | 254 | /** Resets the formula for this molecule.
|
---|
| 255 | *
|
---|
| 256 | * This is required in case an atom changes its element as we then don't
|
---|
| 257 | * have any knowledge about its previous element anymore.
|
---|
| 258 | */
|
---|
| 259 | void resetFormula();
|
---|
| 260 |
|
---|
[2e4105] | 261 | public:
|
---|
| 262 |
|
---|
[c67ff9] | 263 | /** Function to create a bounding spherical shape for the currently associated atoms.
|
---|
| 264 | *
|
---|
[55feea1] | 265 | * \param boundary extra boundary of shape around (i.e. distance between outermost atom
|
---|
| 266 | * and the shape's surface)
|
---|
[c67ff9] | 267 | */
|
---|
[aeb694] | 268 | Shape getBoundingSphere(const double boundary = 0.) const;
|
---|
| 269 |
|
---|
| 270 | /** Creates the bounding box by adding van der Waals-Spheres around every atom.
|
---|
| 271 | *
|
---|
| 272 | * \param scale extra scale parameter to enlarge the spheres artifically
|
---|
| 273 | */
|
---|
| 274 | Shape getBoundingShape(const double scale = 1.) const;
|
---|
[c67ff9] | 275 |
|
---|
[042f82] | 276 | /// remove atoms from molecule.
|
---|
| 277 | bool AddAtom(atom *pointer);
|
---|
| 278 | bool RemoveAtom(atom *pointer);
|
---|
| 279 | bool UnlinkAtom(atom *pointer);
|
---|
| 280 | bool CleanupMolecule();
|
---|
| 281 |
|
---|
| 282 | /// Add/remove atoms to/from molecule.
|
---|
| 283 | atom * AddCopyAtom(atom *pointer);
|
---|
[06804b] | 284 | // bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
---|
[88c8ec] | 285 | bond::ptr AddBond(atom *first, atom *second, int degree = 1);
|
---|
[e4afb4] | 286 | bool hasBondStructure() const;
|
---|
[042f82] | 287 |
|
---|
| 288 | /// Find atoms.
|
---|
| 289 | atom * FindAtom(int Nr) const;
|
---|
[955b91] | 290 | atom * AskAtom(std::string text);
|
---|
[f01769] | 291 | bool isInMolecule(const atom * const _atom) const;
|
---|
[042f82] | 292 |
|
---|
| 293 | /// Count and change present atoms' coordination.
|
---|
[e138de] | 294 | bool CenterInBox();
|
---|
| 295 | bool BoundInBox();
|
---|
[833b15] | 296 | void CenterEdge();
|
---|
[e138de] | 297 | void CenterOrigin();
|
---|
| 298 | void CenterPeriodic();
|
---|
[833b15] | 299 | void CenterAtVector(const Vector &newcenter);
|
---|
| 300 | void Translate(const Vector &x);
|
---|
| 301 | void TranslatePeriodically(const Vector &trans);
|
---|
| 302 | void Mirror(const Vector &x);
|
---|
| 303 | void Align(const Vector &n);
|
---|
| 304 | void Scale(const double *factor);
|
---|
[9291d04] | 305 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
|
---|
[833b15] | 306 | const Vector DetermineCenterOfGravity() const;
|
---|
| 307 | const Vector DetermineCenterOfAll() const;
|
---|
[437922] | 308 | void SetNameFromFilename(const char *filename);
|
---|
[3c58f8] | 309 | bool ScanForPeriodicCorrection();
|
---|
[e138de] | 310 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
---|
[1f91f4] | 311 | RealSpaceMatrix getInertiaTensor() const;
|
---|
[5b6a4b7] | 312 | void RotateToPrincipalAxisSystem(const Vector &Axis);
|
---|
[042f82] | 313 |
|
---|
| 314 | bool CheckBounds(const Vector *x) const;
|
---|
| 315 | void GetAlignvector(struct lsq_params * par) const;
|
---|
| 316 |
|
---|
| 317 | /// Initialising routines in fragmentation
|
---|
[e138de] | 318 | void OutputBondsList() const;
|
---|
[49c059] | 319 |
|
---|
[88c8ec] | 320 | bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
|
---|
[266237] | 321 |
|
---|
[f01769] | 322 | molecule *CopyMolecule(const Vector &offset = zeroVec);
|
---|
| 323 | molecule* CopyMoleculeFromSubRegion(const Shape&);
|
---|
[042f82] | 324 |
|
---|
| 325 | /// Fragment molecule by two different approaches:
|
---|
[e4afb4] | 326 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
---|
[6d551c] | 327 | bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
|
---|
[b9772a] | 328 |
|
---|
[042f82] | 329 | // Recognize doubly appearing molecules in a list of them
|
---|
[f01769] | 330 | int * GetFatherSonAtomicMap(const molecule * const OtherMolecule);
|
---|
[6d551c] | 331 | bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
|
---|
| 332 | bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
|
---|
[042f82] | 333 |
|
---|
| 334 | // Output routines.
|
---|
[e4afb4] | 335 | bool Output(std::ostream * const output) const;
|
---|
[e138de] | 336 | void OutputListOfBonds() const;
|
---|
[042f82] | 337 |
|
---|
[c68025] | 338 | // Manipulation routines
|
---|
| 339 | void flipActiveFlag();
|
---|
| 340 |
|
---|
[c32d21] | 341 | virtual void update(Observable *publisher);
|
---|
| 342 | virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
| 343 | virtual void subjectKilled(Observable *publisher);
|
---|
| 344 |
|
---|
[e4afb4] | 345 | private:
|
---|
[8c001a] | 346 | friend const atom *detail::lastChanged<atom>();
|
---|
| 347 | atom *_lastchangedatom;
|
---|
| 348 |
|
---|
[e4afb4] | 349 | int last_atom; //!< number given to last atom
|
---|
[14de469] | 350 | };
|
---|
| 351 |
|
---|
[cbc5fb] | 352 | molecule *NewMolecule();
|
---|
| 353 | void DeleteMolecule(molecule* mol);
|
---|
| 354 |
|
---|
[14de469] | 355 |
|
---|
| 356 |
|
---|
| 357 | #endif /*MOLECULES_HPP_*/
|
---|
| 358 |
|
---|