[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,
|
---|
[6a3c83] | 114 | MoleculeNameChanged,
|
---|
[24edfe] | 115 | AboutToBeRemoved,
|
---|
[6a3c83] | 116 | NotificationType_MAX
|
---|
| 117 | };
|
---|
| 118 |
|
---|
[8c001a] | 119 | //>! access to last changed element (atom)
|
---|
| 120 | const atom* lastChanged() const
|
---|
| 121 | { return _lastchangedatom; }
|
---|
| 122 |
|
---|
[cbc5fb] | 123 | public:
|
---|
[520c8b] | 124 | //getter and setter
|
---|
[73a857] | 125 | const std::string getName() const;
|
---|
[ea7176] | 126 | int getAtomCount() const;
|
---|
[e791dc] | 127 | size_t doCountNoNonHydrogen() const;
|
---|
| 128 | size_t getNoNonHydrogen() const;
|
---|
[458c31] | 129 | int getBondCount() const;
|
---|
| 130 | int doCountBonds() const;
|
---|
[73a857] | 131 | moleculeId_t getId() const;
|
---|
[cbc5fb] | 132 | void setId(moleculeId_t);
|
---|
[520c8b] | 133 | void setName(const std::string);
|
---|
[73a857] | 134 | const Formula &getFormula() const;
|
---|
| 135 | unsigned int getElementCount() const;
|
---|
[389cc8] | 136 | bool hasElement(const element*) const;
|
---|
| 137 | bool hasElement(atomicNumber_t) const;
|
---|
| 138 | bool hasElement(const std::string&) const;
|
---|
| 139 |
|
---|
[a7a087] | 140 | virtual bool changeId(atomId_t newId);
|
---|
[520c8b] | 141 |
|
---|
[9317be] | 142 | World::AtomComposite getAtomSet() const;
|
---|
[3738f0] | 143 |
|
---|
[8e1f901] | 144 | // simply pass on all functions to AtomIdSet
|
---|
| 145 | iterator begin() {
|
---|
| 146 | return atomIds.begin();
|
---|
| 147 | }
|
---|
| 148 | const_iterator begin() const
|
---|
| 149 | {
|
---|
| 150 | return atomIds.begin();
|
---|
| 151 | }
|
---|
| 152 | iterator end()
|
---|
| 153 | {
|
---|
| 154 | return atomIds.end();
|
---|
| 155 | }
|
---|
| 156 | const_iterator end() const
|
---|
| 157 | {
|
---|
| 158 | return atomIds.end();
|
---|
| 159 | }
|
---|
| 160 | bool empty() const
|
---|
| 161 | {
|
---|
| 162 | return atomIds.empty();
|
---|
| 163 | }
|
---|
| 164 | size_t size() const
|
---|
| 165 | {
|
---|
| 166 | return atomIds.size();
|
---|
| 167 | }
|
---|
| 168 | const_iterator find(atom * key) const
|
---|
| 169 | {
|
---|
| 170 | return atomIds.find(key);
|
---|
| 171 | }
|
---|
[c67ff9] | 172 |
|
---|
| 173 | /** Returns the set of atomic ids contained in this molecule.
|
---|
| 174 | *
|
---|
| 175 | * @return set of atomic ids
|
---|
| 176 | */
|
---|
[8e1f901] | 177 | const atomIdSet & getAtomIds() const {
|
---|
| 178 | return atomIds.getAtomIds();
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | std::pair<iterator, bool> insert(atom * const key);
|
---|
| 182 |
|
---|
[6aad6f] | 183 | /** Predicate whether given \a key is contained in this molecule.
|
---|
| 184 | *
|
---|
| 185 | * @param key atom to check
|
---|
| 186 | * @return true - is contained, false - else
|
---|
| 187 | */
|
---|
| 188 | bool containsAtom(const atom* key) const
|
---|
| 189 | {
|
---|
| 190 | return atomIds.contains(key);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | /** Predicate whether given \a id is contained in this molecule.
|
---|
| 194 | *
|
---|
| 195 | * @param id atomic id to check
|
---|
| 196 | * @return true - is contained, false - else
|
---|
| 197 | */
|
---|
| 198 | bool containsAtom(const atomId_t id) const
|
---|
| 199 | {
|
---|
| 200 | return atomIds.contains(id);
|
---|
| 201 | }
|
---|
[bd58fb] | 202 |
|
---|
[2e4105] | 203 | private:
|
---|
| 204 | friend void atom::removeFromMolecule();
|
---|
| 205 | /** Erase an atom from the list.
|
---|
| 206 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 207 | * otherwise it is not assured that the atom knows about it.
|
---|
| 208 | *
|
---|
| 209 | * @param loc locator to atom in list
|
---|
| 210 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 211 | */
|
---|
| 212 | const_iterator erase(const_iterator loc);
|
---|
[8e1f901] | 213 |
|
---|
[2e4105] | 214 | /** Erase an atom from the list.
|
---|
| 215 | * \note This should only be called by atom::removeFromMolecule(),
|
---|
| 216 | * otherwise it is not assured that the atom knows about it.
|
---|
| 217 | *
|
---|
| 218 | * @param *key key to atom in list
|
---|
| 219 | * @return iterator to just after removed item (compliant with standard)
|
---|
| 220 | */
|
---|
| 221 | const_iterator erase(atom * key);
|
---|
| 222 |
|
---|
[560bbe] | 223 | private:
|
---|
| 224 | friend bool atom::changeNr(int newId);
|
---|
| 225 | /**
|
---|
| 226 | * used when changing an ParticleInfo::Nr.
|
---|
| 227 | * Note that this number is local with this molecule.
|
---|
| 228 | * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
|
---|
| 229 | *
|
---|
| 230 | * @param oldNr old Nr
|
---|
| 231 | * @param newNr new Nr to set
|
---|
| 232 | * @param *target ref to atom
|
---|
| 233 | * @return indicates wether the change could be done or not.
|
---|
| 234 | */
|
---|
| 235 | bool changeAtomNr(int oldNr, int newNr, atom* target=0);
|
---|
| 236 |
|
---|
[c6ab91] | 237 | /** Updates the internal lookup fro local to global indices.
|
---|
| 238 | *
|
---|
| 239 | * \param pointer pointer to atom
|
---|
| 240 | */
|
---|
| 241 | void InsertLocalToGlobalId(atom * const pointer);
|
---|
| 242 |
|
---|
[560bbe] | 243 | /** Sets the name of the atom.
|
---|
| 244 | *
|
---|
| 245 | * The name is set via its element symbol and its internal ParticleInfo::Nr.
|
---|
| 246 | *
|
---|
| 247 | * @param _atom atom whose name to set
|
---|
| 248 | */
|
---|
| 249 | void setAtomName(atom *_atom) const;
|
---|
| 250 |
|
---|
[2e4105] | 251 | public:
|
---|
| 252 |
|
---|
[c67ff9] | 253 | /** Function to create a bounding spherical shape for the currently associated atoms.
|
---|
| 254 | *
|
---|
[55feea1] | 255 | * \param boundary extra boundary of shape around (i.e. distance between outermost atom
|
---|
| 256 | * and the shape's surface)
|
---|
[c67ff9] | 257 | */
|
---|
[aeb694] | 258 | Shape getBoundingSphere(const double boundary = 0.) const;
|
---|
| 259 |
|
---|
| 260 | /** Creates the bounding box by adding van der Waals-Spheres around every atom.
|
---|
| 261 | *
|
---|
| 262 | * \param scale extra scale parameter to enlarge the spheres artifically
|
---|
| 263 | */
|
---|
| 264 | Shape getBoundingShape(const double scale = 1.) const;
|
---|
[c67ff9] | 265 |
|
---|
[042f82] | 266 | /// remove atoms from molecule.
|
---|
| 267 | bool AddAtom(atom *pointer);
|
---|
| 268 | bool RemoveAtom(atom *pointer);
|
---|
| 269 | bool UnlinkAtom(atom *pointer);
|
---|
| 270 | bool CleanupMolecule();
|
---|
| 271 |
|
---|
| 272 | /// Add/remove atoms to/from molecule.
|
---|
| 273 | atom * AddCopyAtom(atom *pointer);
|
---|
[06804b] | 274 | // bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
---|
[88c8ec] | 275 | bond::ptr AddBond(atom *first, atom *second, int degree = 1);
|
---|
[e4afb4] | 276 | bool hasBondStructure() const;
|
---|
[042f82] | 277 |
|
---|
| 278 | /// Find atoms.
|
---|
| 279 | atom * FindAtom(int Nr) const;
|
---|
[955b91] | 280 | atom * AskAtom(std::string text);
|
---|
[59fff1] | 281 | bool isInMolecule(const atom * const _atom);
|
---|
[042f82] | 282 |
|
---|
| 283 | /// Count and change present atoms' coordination.
|
---|
[e138de] | 284 | bool CenterInBox();
|
---|
| 285 | bool BoundInBox();
|
---|
[833b15] | 286 | void CenterEdge();
|
---|
[e138de] | 287 | void CenterOrigin();
|
---|
| 288 | void CenterPeriodic();
|
---|
[833b15] | 289 | void CenterAtVector(const Vector &newcenter);
|
---|
| 290 | void Translate(const Vector &x);
|
---|
| 291 | void TranslatePeriodically(const Vector &trans);
|
---|
| 292 | void Mirror(const Vector &x);
|
---|
| 293 | void Align(const Vector &n);
|
---|
| 294 | void Scale(const double *factor);
|
---|
[9291d04] | 295 | void DeterminePeriodicCenter(Vector ¢er, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
|
---|
[833b15] | 296 | const Vector DetermineCenterOfGravity() const;
|
---|
| 297 | const Vector DetermineCenterOfAll() const;
|
---|
[437922] | 298 | void SetNameFromFilename(const char *filename);
|
---|
[3c58f8] | 299 | bool ScanForPeriodicCorrection();
|
---|
[e138de] | 300 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
---|
[1f91f4] | 301 | RealSpaceMatrix getInertiaTensor() const;
|
---|
[5b6a4b7] | 302 | void RotateToPrincipalAxisSystem(const Vector &Axis);
|
---|
[042f82] | 303 |
|
---|
| 304 | bool CheckBounds(const Vector *x) const;
|
---|
| 305 | void GetAlignvector(struct lsq_params * par) const;
|
---|
| 306 |
|
---|
| 307 | /// Initialising routines in fragmentation
|
---|
[e138de] | 308 | void OutputBondsList() const;
|
---|
[49c059] | 309 |
|
---|
[88c8ec] | 310 | bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
|
---|
[266237] | 311 |
|
---|
[c67ff9] | 312 | molecule *CopyMolecule(const Vector &offset = zeroVec) const;
|
---|
[c550dd] | 313 | molecule* CopyMoleculeFromSubRegion(const Shape&) const;
|
---|
[042f82] | 314 |
|
---|
| 315 | /// Fragment molecule by two different approaches:
|
---|
[e4afb4] | 316 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
---|
[6d551c] | 317 | bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
|
---|
[b9772a] | 318 |
|
---|
[042f82] | 319 | // Recognize doubly appearing molecules in a list of them
|
---|
[e138de] | 320 | int * GetFatherSonAtomicMap(molecule *OtherMolecule);
|
---|
[6d551c] | 321 | bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
|
---|
| 322 | bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
|
---|
[042f82] | 323 |
|
---|
| 324 | // Output routines.
|
---|
[e4afb4] | 325 | bool Output(std::ostream * const output) const;
|
---|
[e138de] | 326 | void OutputListOfBonds() const;
|
---|
[042f82] | 327 |
|
---|
[c68025] | 328 | // Manipulation routines
|
---|
| 329 | void flipActiveFlag();
|
---|
| 330 |
|
---|
[c32d21] | 331 | virtual void update(Observable *publisher);
|
---|
| 332 | virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
| 333 | virtual void subjectKilled(Observable *publisher);
|
---|
| 334 |
|
---|
[e4afb4] | 335 | private:
|
---|
[8c001a] | 336 | friend const atom *detail::lastChanged<atom>();
|
---|
| 337 | atom *_lastchangedatom;
|
---|
| 338 |
|
---|
[e4afb4] | 339 | int last_atom; //!< number given to last atom
|
---|
[14de469] | 340 | };
|
---|
| 341 |
|
---|
[cbc5fb] | 342 | molecule *NewMolecule();
|
---|
| 343 | void DeleteMolecule(molecule* mol);
|
---|
| 344 |
|
---|
[14de469] | 345 |
|
---|
| 346 |
|
---|
| 347 | #endif /*MOLECULES_HPP_*/
|
---|
| 348 |
|
---|