| [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 |
|
|---|
| [68d781] | 25 | #include "types.hpp"
|
|---|
| [f66195] | 26 | #include "graph.hpp"
|
|---|
| [ad011c] | 27 | #include "CodePatterns/Observer.hpp"
|
|---|
| 28 | #include "CodePatterns/ObservedIterator.hpp"
|
|---|
| 29 | #include "CodePatterns/Cacheable.hpp"
|
|---|
| [389cc8] | 30 | #include "Formula.hpp"
|
|---|
| [14d541] | 31 | #include "AtomSet.hpp"
|
|---|
| [14de469] | 32 |
|
|---|
| [97ebf8] | 33 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
|
|---|
| 34 |
|
|---|
| [f66195] | 35 | /****************************************** forward declarations *****************************/
|
|---|
| 36 |
|
|---|
| 37 | class atom;
|
|---|
| 38 | class bond;
|
|---|
| [b70721] | 39 | class BondedParticle;
|
|---|
| 40 | class BondGraph;
|
|---|
| [f66195] | 41 | class element;
|
|---|
| 42 | class ForceMatrix;
|
|---|
| 43 | class LinkedCell;
|
|---|
| [14de469] | 44 | class molecule;
|
|---|
| [2319ed] | 45 | class MoleculeLeafClass;
|
|---|
| [14de469] | 46 | class MoleculeListClass;
|
|---|
| [f66195] | 47 | class periodentafel;
|
|---|
| [1f91f4] | 48 | class RealSpaceMatrix;
|
|---|
| [f66195] | 49 | class Vector;
|
|---|
| [c550dd] | 50 | class Shape;
|
|---|
| [14de469] | 51 |
|
|---|
| 52 | /******************************** Some definitions for easier reading **********************************/
|
|---|
| 53 |
|
|---|
| [edb93c] | 54 | #define MoleculeList list <molecule *>
|
|---|
| 55 | #define MoleculeListTest pair <MoleculeList::iterator, bool>
|
|---|
| 56 |
|
|---|
| [14de469] | 57 | /************************************* Class definitions ****************************************/
|
|---|
| 58 |
|
|---|
| 59 | /** The complete molecule.
|
|---|
| 60 | * Class incorporates number of types
|
|---|
| 61 | */
|
|---|
| [34c43a] | 62 | class molecule : public Observable
|
|---|
| [e4afb4] | 63 | {
|
|---|
| [cbc5fb] | 64 | friend molecule *NewMolecule();
|
|---|
| 65 | friend void DeleteMolecule(molecule *);
|
|---|
| [bd58fb] | 66 |
|
|---|
| [e4afb4] | 67 | public:
|
|---|
| 68 | typedef ATOMSET(std::list) atomSet;
|
|---|
| [3738f0] | 69 | typedef ATOMSET(std::vector) atomVector;
|
|---|
| [e4afb4] | 70 | typedef std::set<atomId_t> atomIdSet;
|
|---|
| 71 | typedef ObservedIterator<atomSet> iterator;
|
|---|
| 72 | typedef atomSet::const_iterator const_iterator;
|
|---|
| 73 |
|
|---|
| 74 | const periodentafel * const elemente; //!< periodic table with each element
|
|---|
| 75 | // old deprecated atom handling
|
|---|
| 76 | //atom *start; //!< start of atom list
|
|---|
| 77 | //atom *end; //!< end of atom list
|
|---|
| 78 | //bond *first; //!< start of bond list
|
|---|
| 79 | //bond *last; //!< end of bond list
|
|---|
| 80 | int MDSteps; //!< The number of MD steps in Trajectories
|
|---|
| 81 | mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
|---|
| 82 | mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
|
|---|
| 83 | mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
|
|---|
| 84 | bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
|
|---|
| 85 | //Vector Center; //!< Center of molecule in a global box
|
|---|
| 86 | int IndexNr; //!< index of molecule in a MoleculeListClass
|
|---|
| 87 | char name[MAXSTRINGSIZE]; //!< arbitrary name
|
|---|
| 88 |
|
|---|
| 89 | private:
|
|---|
| 90 | Formula formula;
|
|---|
| [458c31] | 91 | Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
|
|---|
| 92 | Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
|
|---|
| [e4afb4] | 93 | moleculeId_t id;
|
|---|
| 94 | atomSet atoms; //<!list of atoms
|
|---|
| 95 | atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
|
|---|
| 96 | protected:
|
|---|
| 97 | //void CountAtoms();
|
|---|
| 98 | /**
|
|---|
| 99 | * this iterator type should be used for internal variables, \
|
|---|
| [d3347e] | 100 | * since it will not lock
|
|---|
| [e4afb4] | 101 | */
|
|---|
| 102 | typedef atomSet::iterator internal_iterator;
|
|---|
| [ac9b56] | 103 |
|
|---|
| [e4afb4] | 104 | molecule(const periodentafel * const teil);
|
|---|
| 105 | virtual ~molecule();
|
|---|
| [042f82] | 106 |
|
|---|
| [cbc5fb] | 107 | public:
|
|---|
| [520c8b] | 108 | //getter and setter
|
|---|
| [73a857] | 109 | const std::string getName() const;
|
|---|
| [ea7176] | 110 | int getAtomCount() const;
|
|---|
| 111 | int doCountAtoms();
|
|---|
| [458c31] | 112 | int getBondCount() const;
|
|---|
| 113 | int doCountBonds() const;
|
|---|
| [73a857] | 114 | moleculeId_t getId() const;
|
|---|
| [cbc5fb] | 115 | void setId(moleculeId_t);
|
|---|
| [520c8b] | 116 | void setName(const std::string);
|
|---|
| [73a857] | 117 | const Formula &getFormula() const;
|
|---|
| 118 | unsigned int getElementCount() const;
|
|---|
| [389cc8] | 119 | bool hasElement(const element*) const;
|
|---|
| 120 | bool hasElement(atomicNumber_t) const;
|
|---|
| 121 | bool hasElement(const std::string&) const;
|
|---|
| 122 |
|
|---|
| [a7a087] | 123 | virtual bool changeId(atomId_t newId);
|
|---|
| [520c8b] | 124 |
|
|---|
| [3738f0] | 125 | atomVector getAtomSet() const;
|
|---|
| 126 |
|
|---|
| [bd58fb] | 127 | iterator begin();
|
|---|
| 128 | const_iterator begin() const;
|
|---|
| [e87acf] | 129 | iterator end();
|
|---|
| 130 | const_iterator end() const;
|
|---|
| [9879f6] | 131 | bool empty() const;
|
|---|
| 132 | size_t size() const;
|
|---|
| [e4afb4] | 133 | const_iterator erase(const_iterator loc);
|
|---|
| 134 | const_iterator erase(atom * key);
|
|---|
| 135 | const_iterator find(atom * key) const;
|
|---|
| 136 | pair<iterator, bool> insert(atom * const key);
|
|---|
| [6cfa36] | 137 | bool containsAtom(atom* key);
|
|---|
| [bd58fb] | 138 |
|
|---|
| [042f82] | 139 | /// remove atoms from molecule.
|
|---|
| 140 | bool AddAtom(atom *pointer);
|
|---|
| 141 | bool RemoveAtom(atom *pointer);
|
|---|
| 142 | bool UnlinkAtom(atom *pointer);
|
|---|
| 143 | bool CleanupMolecule();
|
|---|
| [9df680] | 144 | void removeAtomsinMolecule();
|
|---|
| [042f82] | 145 |
|
|---|
| 146 | /// Add/remove atoms to/from molecule.
|
|---|
| 147 | atom * AddCopyAtom(atom *pointer);
|
|---|
| 148 | bool AddXYZFile(string filename);
|
|---|
| [e138de] | 149 | bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
|---|
| [cee0b57] | 150 | bond * AddBond(atom *first, atom *second, int degree = 1);
|
|---|
| [042f82] | 151 | bool RemoveBond(bond *pointer);
|
|---|
| 152 | bool RemoveBonds(atom *BondPartner);
|
|---|
| [e4afb4] | 153 | bool hasBondStructure() const;
|
|---|
| [042f82] | 154 |
|
|---|
| 155 | /// Find atoms.
|
|---|
| 156 | atom * FindAtom(int Nr) const;
|
|---|
| 157 | atom * AskAtom(string text);
|
|---|
| 158 |
|
|---|
| 159 | /// Count and change present atoms' coordination.
|
|---|
| [e138de] | 160 | bool CenterInBox();
|
|---|
| 161 | bool BoundInBox();
|
|---|
| 162 | void CenterEdge(Vector *max);
|
|---|
| 163 | void CenterOrigin();
|
|---|
| 164 | void CenterPeriodic();
|
|---|
| 165 | void CenterAtVector(Vector *newcenter);
|
|---|
| [042f82] | 166 | void Translate(const Vector *x);
|
|---|
| 167 | void TranslatePeriodically(const Vector *trans);
|
|---|
| 168 | void Mirror(const Vector *x);
|
|---|
| 169 | void Align(Vector *n);
|
|---|
| [776b64] | 170 | void Scale(const double ** const factor);
|
|---|
| [437922] | 171 | void DeterminePeriodicCenter(Vector ¢er);
|
|---|
| [4bb63c] | 172 | Vector * DetermineCenterOfGravity() const;
|
|---|
| [e138de] | 173 | Vector * DetermineCenterOfAll() const;
|
|---|
| [eddea2] | 174 | Vector * DetermineCenterOfBox() const;
|
|---|
| [437922] | 175 | void SetNameFromFilename(const char *filename);
|
|---|
| [042f82] | 176 | void SetBoxDimension(Vector *dim);
|
|---|
| [3c58f8] | 177 | bool ScanForPeriodicCorrection();
|
|---|
| [e138de] | 178 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
|---|
| [1f91f4] | 179 | RealSpaceMatrix getInertiaTensor() const;
|
|---|
| 180 | void RotateToPrincipalAxisSystem(Vector &Axis);
|
|---|
| [042f82] | 181 |
|
|---|
| 182 | bool CheckBounds(const Vector *x) const;
|
|---|
| 183 | void GetAlignvector(struct lsq_params * par) const;
|
|---|
| 184 |
|
|---|
| 185 | /// Initialising routines in fragmentation
|
|---|
| [e138de] | 186 | void OutputBondsList() const;
|
|---|
| [fa649a] | 187 | void CyclicBondAnalysis() const;
|
|---|
| [e138de] | 188 | void OutputGraphInfoPerAtom() const;
|
|---|
| 189 | void OutputGraphInfoPerBond() const;
|
|---|
| [b8b75d] | 190 |
|
|---|
| [042f82] | 191 | // Graph analysis
|
|---|
| [a564be] | 192 | MoleculeLeafClass * DepthFirstSearchAnalysis(std::deque<bond *> *&BackEdgeStack) const;
|
|---|
| 193 | void CyclicStructureAnalysis(std::deque<bond *> *BackEdgeStack, int *&MinimumRingSize) const;
|
|---|
| 194 | bool PickLocalBackEdges(atom **ListOfLocalAtoms, std::deque<bond *> *&ReferenceStack, std::deque<bond *> *&LocalStack) const;
|
|---|
| [fa649a] | 195 | bond * FindNextUnused(atom *vertex) const;
|
|---|
| 196 | void SetNextComponentNumber(atom *vertex, int nr) const;
|
|---|
| 197 | void ResetAllBondsToUnused() const;
|
|---|
| [e138de] | 198 | int CountCyclicBonds();
|
|---|
| 199 | bool CheckForConnectedSubgraph(KeySet *Fragment);
|
|---|
| [266237] | 200 | bond * CopyBond(atom *left, atom *right, bond *CopyBond);
|
|---|
| 201 |
|
|---|
| [e4afb4] | 202 | molecule *CopyMolecule() const;
|
|---|
| [c550dd] | 203 | molecule* CopyMoleculeFromSubRegion(const Shape&) const;
|
|---|
| [042f82] | 204 |
|
|---|
| 205 | /// Fragment molecule by two different approaches:
|
|---|
| [35b698] | 206 | int FragmentMolecule(int Order, std::string &prefix);
|
|---|
| 207 | bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path = "");
|
|---|
| [e4afb4] | 208 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
|---|
| 209 | bool StoreAdjacencyToFile(std::string filename, std::string path = "");
|
|---|
| [35b698] | 210 | bool CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms);
|
|---|
| 211 | bool ParseOrderAtSiteFromFile(std::string &path);
|
|---|
| 212 | bool StoreOrderAtSiteFile(std::string &path);
|
|---|
| 213 | bool StoreForcesFile(MoleculeListClass *BondFragments, std::string &path, int *SortIndex);
|
|---|
| [e138de] | 214 | bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
|
|---|
| [9879f6] | 215 | bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
|
|---|
| [b9772a] | 216 |
|
|---|
| [042f82] | 217 | /// -# BOSSANOVA
|
|---|
| [e138de] | 218 | void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
|
|---|
| 219 | int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
|
|---|
| 220 | bool BuildInducedSubgraph(const molecule *Father);
|
|---|
| 221 | molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);
|
|---|
| [03c77c] | 222 | void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder);
|
|---|
| [e138de] | 223 | int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList);
|
|---|
| 224 | int GuesstimateFragmentCount(int order);
|
|---|
| [042f82] | 225 |
|
|---|
| 226 | // Recognize doubly appearing molecules in a list of them
|
|---|
| [e138de] | 227 | int * GetFatherSonAtomicMap(molecule *OtherMolecule);
|
|---|
| [99752a] | 228 | bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
|
|---|
| [c6123b] | 229 | bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount);
|
|---|
| [042f82] | 230 |
|
|---|
| 231 | // Output routines.
|
|---|
| [e4afb4] | 232 | bool Output(std::ostream * const output) const;
|
|---|
| 233 | bool OutputTrajectories(ofstream * const output) const;
|
|---|
| [e138de] | 234 | void OutputListOfBonds() const;
|
|---|
| 235 | bool OutputXYZ(ofstream * const output) const;
|
|---|
| 236 | bool OutputTrajectoriesXYZ(ofstream * const output);
|
|---|
| 237 | bool Checkout(ofstream * const output) const;
|
|---|
| [042f82] | 238 |
|
|---|
| [c68025] | 239 | // Manipulation routines
|
|---|
| 240 | void flipActiveFlag();
|
|---|
| 241 |
|
|---|
| [e4afb4] | 242 | private:
|
|---|
| [00ef5c] | 243 | void init_DFS(struct DFSAccounting&) const;
|
|---|
| [e4afb4] | 244 | int last_atom; //!< number given to last atom
|
|---|
| [14de469] | 245 | };
|
|---|
| 246 |
|
|---|
| [cbc5fb] | 247 | molecule *NewMolecule();
|
|---|
| 248 | void DeleteMolecule(molecule* mol);
|
|---|
| 249 |
|
|---|
| [14de469] | 250 | /** A list of \a molecule classes.
|
|---|
| 251 | */
|
|---|
| [e4afb4] | 252 | class MoleculeListClass : public Observable
|
|---|
| 253 | {
|
|---|
| 254 | public:
|
|---|
| 255 | MoleculeList ListOfMolecules; //!< List of the contained molecules
|
|---|
| 256 | int MaxIndex;
|
|---|
| [042f82] | 257 |
|
|---|
| [cbc5fb] | 258 | MoleculeListClass(World *world);
|
|---|
| [042f82] | 259 | ~MoleculeListClass();
|
|---|
| 260 |
|
|---|
| [35b698] | 261 | bool AddHydrogenCorrection(std::string &path);
|
|---|
| 262 | bool StoreForcesFile(std::string &path, int *SortIndex);
|
|---|
| [437922] | 263 | void insert(molecule *mol);
|
|---|
| [bd6bfa] | 264 | void erase(molecule *mol);
|
|---|
| [042f82] | 265 | molecule * ReturnIndex(int index);
|
|---|
| [35b698] | 266 | bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex);
|
|---|
| [042f82] | 267 | int NumberOfActiveMolecules();
|
|---|
| [24a5e0] | 268 | void Enumerate(ostream *out);
|
|---|
| [042f82] | 269 | void Output(ofstream *out);
|
|---|
| [568be7] | 270 | int CountAllAtoms() const;
|
|---|
| [042f82] | 271 |
|
|---|
| [477bb2] | 272 | // Methods moved here from the menus
|
|---|
| 273 | // TODO: more refactoring needed on these methods
|
|---|
| 274 | void createNewMolecule(periodentafel *periode);
|
|---|
| 275 | void loadFromXYZ(periodentafel *periode);
|
|---|
| 276 | void setMoleculeFilename();
|
|---|
| 277 | void parseXYZIntoMolecule();
|
|---|
| 278 | void eraseMolecule();
|
|---|
| 279 |
|
|---|
| [e4afb4] | 280 | private:
|
|---|
| [cbc5fb] | 281 | World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
|
|---|
| [14de469] | 282 | };
|
|---|
| 283 |
|
|---|
| 284 | /** A leaf for a tree of \a molecule class
|
|---|
| 285 | * Wraps molecules in a tree structure
|
|---|
| 286 | */
|
|---|
| [e4afb4] | 287 | class MoleculeLeafClass
|
|---|
| 288 | {
|
|---|
| 289 | public:
|
|---|
| 290 | molecule *Leaf; //!< molecule of this leaf
|
|---|
| 291 | //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
|
|---|
| 292 | //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
|
|---|
| 293 | MoleculeLeafClass *previous; //!< Previous leaf on this level
|
|---|
| 294 | MoleculeLeafClass *next; //!< Next leaf on this level
|
|---|
| [042f82] | 295 |
|
|---|
| 296 | //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
|
|---|
| 297 | MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
|
|---|
| 298 | ~MoleculeLeafClass();
|
|---|
| 299 |
|
|---|
| 300 | bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
|
|---|
| [e138de] | 301 | bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
|
|---|
| 302 | bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
|
|---|
| 303 | void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
|
|---|
| [042f82] | 304 | int Count() const;
|
|---|
| [14de469] | 305 | };
|
|---|
| 306 |
|
|---|
| 307 | #endif /*MOLECULES_HPP_*/
|
|---|
| 308 |
|
|---|