[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"
|
---|
[88b400] | 27 | #include "PointCloud.hpp"
|
---|
[d5f216] | 28 | #include "Patterns/Observer.hpp"
|
---|
[bd58fb] | 29 | #include "Patterns/ObservedIterator.hpp"
|
---|
[ac9b56] | 30 | #include "Patterns/Cacheable.hpp"
|
---|
[389cc8] | 31 | #include "Formula.hpp"
|
---|
[14d541] | 32 | #include "AtomSet.hpp"
|
---|
[14de469] | 33 |
|
---|
[97ebf8] | 34 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
|
---|
| 35 |
|
---|
[f66195] | 36 | /****************************************** forward declarations *****************************/
|
---|
| 37 |
|
---|
| 38 | class atom;
|
---|
| 39 | class bond;
|
---|
[b70721] | 40 | class BondedParticle;
|
---|
| 41 | class BondGraph;
|
---|
[f66195] | 42 | class element;
|
---|
| 43 | class ForceMatrix;
|
---|
| 44 | class LinkedCell;
|
---|
[14de469] | 45 | class molecule;
|
---|
[2319ed] | 46 | class MoleculeLeafClass;
|
---|
[14de469] | 47 | class MoleculeListClass;
|
---|
[f66195] | 48 | class periodentafel;
|
---|
| 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 |
|
---|
[ed060e] | 57 | #define DistancePair pair < double, atom* >
|
---|
| 58 | #define DistanceMap multimap < double, atom* >
|
---|
| 59 | #define DistanceTestPair pair < DistanceMap::iterator, bool>
|
---|
| 60 |
|
---|
[1907a7] | 61 |
|
---|
[14de469] | 62 | /************************************* Class definitions ****************************************/
|
---|
| 63 |
|
---|
[ccd9f5] | 64 | /** Structure to contain parameters needed for evaluation of constraint potential.
|
---|
| 65 | */
|
---|
| 66 | struct EvaluatePotential
|
---|
| 67 | {
|
---|
[e4afb4] | 68 | int startstep; //!< start configuration (MDStep in atom::trajectory)
|
---|
| 69 | int endstep; //!< end configuration (MDStep in atom::trajectory)
|
---|
| 70 | atom **PermutationMap; //!< gives target ptr for each atom, array of size molecule::AtomCount (this is "x" in \f$ V^{con}(x) \f$ )
|
---|
[ccd9f5] | 71 | DistanceMap **DistanceList; //!< distance list of each atom to each atom
|
---|
| 72 | DistanceMap::iterator *StepList; //!< iterator to ascend through NearestNeighbours \a **DistanceList
|
---|
[e4afb4] | 73 | int *DoubleList; //!< count of which sources want to move to this target, basically the injective measure (>1 -> not injective)
|
---|
[ccd9f5] | 74 | DistanceMap::iterator *DistanceIterators; //!< marks which was the last picked target as injective candidate with smallest distance
|
---|
[e4afb4] | 75 | bool IsAngstroem; //!< whether coordinates are in angstroem (true) or bohrradius (false)
|
---|
| 76 | double *PenaltyConstants; //!< penalty constant in front of each term
|
---|
[ccd9f5] | 77 | };
|
---|
[14de469] | 78 |
|
---|
| 79 | /** The complete molecule.
|
---|
| 80 | * Class incorporates number of types
|
---|
| 81 | */
|
---|
[e4afb4] | 82 | class molecule : public PointCloud, public Observable
|
---|
| 83 | {
|
---|
[cbc5fb] | 84 | friend molecule *NewMolecule();
|
---|
| 85 | friend void DeleteMolecule(molecule *);
|
---|
[bd58fb] | 86 |
|
---|
[e4afb4] | 87 | public:
|
---|
| 88 | typedef ATOMSET(std::list) atomSet;
|
---|
| 89 | typedef std::set<atomId_t> atomIdSet;
|
---|
| 90 | typedef ObservedIterator<atomSet> iterator;
|
---|
| 91 | typedef atomSet::const_iterator const_iterator;
|
---|
| 92 |
|
---|
| 93 | const periodentafel * const elemente; //!< periodic table with each element
|
---|
| 94 | // old deprecated atom handling
|
---|
| 95 | //atom *start; //!< start of atom list
|
---|
| 96 | //atom *end; //!< end of atom list
|
---|
| 97 | //bond *first; //!< start of bond list
|
---|
| 98 | //bond *last; //!< end of bond list
|
---|
| 99 | int MDSteps; //!< The number of MD steps in Trajectories
|
---|
| 100 | //int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
|
---|
| 101 | int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
|
---|
| 102 | mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
---|
| 103 | mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
|
---|
| 104 | mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
|
---|
| 105 | double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
|
---|
| 106 | bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
|
---|
| 107 | //Vector Center; //!< Center of molecule in a global box
|
---|
| 108 | int IndexNr; //!< index of molecule in a MoleculeListClass
|
---|
| 109 | char name[MAXSTRINGSIZE]; //!< arbitrary name
|
---|
| 110 |
|
---|
| 111 | private:
|
---|
| 112 | Formula formula;
|
---|
| 113 | Cacheable<int> AtomCount;
|
---|
| 114 | moleculeId_t id;
|
---|
| 115 | atomSet atoms; //<!list of atoms
|
---|
| 116 | atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
|
---|
| 117 | protected:
|
---|
| 118 | //void CountAtoms();
|
---|
| 119 | /**
|
---|
| 120 | * this iterator type should be used for internal variables, \
|
---|
[d3347e] | 121 | * since it will not lock
|
---|
[e4afb4] | 122 | */
|
---|
| 123 | typedef atomSet::iterator internal_iterator;
|
---|
[ac9b56] | 124 |
|
---|
[e4afb4] | 125 | molecule(const periodentafel * const teil);
|
---|
| 126 | virtual ~molecule();
|
---|
[042f82] | 127 |
|
---|
[cbc5fb] | 128 | public:
|
---|
[520c8b] | 129 | //getter and setter
|
---|
[73a857] | 130 | const std::string getName() const;
|
---|
[ea7176] | 131 | int getAtomCount() const;
|
---|
| 132 | int doCountAtoms();
|
---|
[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 |
|
---|
[af2c424] | 144 | TesselPoint * getValue(const_iterator &rhs) const;
|
---|
| 145 | TesselPoint * getValue(iterator &rhs) const;
|
---|
[bd58fb] | 146 | iterator begin();
|
---|
| 147 | const_iterator begin() const;
|
---|
[e87acf] | 148 | iterator end();
|
---|
| 149 | const_iterator end() const;
|
---|
[9879f6] | 150 | bool empty() const;
|
---|
| 151 | size_t size() const;
|
---|
[e4afb4] | 152 | const_iterator erase(const_iterator loc);
|
---|
| 153 | const_iterator erase(atom * key);
|
---|
| 154 | const_iterator find(atom * key) const;
|
---|
| 155 | pair<iterator, bool> insert(atom * const key);
|
---|
[6cfa36] | 156 | bool containsAtom(atom* key);
|
---|
[bd58fb] | 157 |
|
---|
[357fba] | 158 | // re-definition of virtual functions from PointCloud
|
---|
[6a7f78c] | 159 | const char * const GetName() const;
|
---|
[e4afb4] | 160 | Vector *GetCenter() const;
|
---|
| 161 | TesselPoint *GetPoint() const;
|
---|
[71b20e] | 162 | int GetMaxId() const;
|
---|
[e4afb4] | 163 | void GoToNext() const;
|
---|
| 164 | void GoToFirst() const;
|
---|
| 165 | bool IsEmpty() const;
|
---|
| 166 | bool IsEnd() const;
|
---|
[042f82] | 167 |
|
---|
| 168 | /// remove atoms from molecule.
|
---|
| 169 | bool AddAtom(atom *pointer);
|
---|
| 170 | bool RemoveAtom(atom *pointer);
|
---|
| 171 | bool UnlinkAtom(atom *pointer);
|
---|
| 172 | bool CleanupMolecule();
|
---|
| 173 |
|
---|
| 174 | /// Add/remove atoms to/from molecule.
|
---|
| 175 | atom * AddCopyAtom(atom *pointer);
|
---|
| 176 | bool AddXYZFile(string filename);
|
---|
[e138de] | 177 | bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
|
---|
[cee0b57] | 178 | bond * AddBond(atom *first, atom *second, int degree = 1);
|
---|
[042f82] | 179 | bool RemoveBond(bond *pointer);
|
---|
| 180 | bool RemoveBonds(atom *BondPartner);
|
---|
[e4afb4] | 181 | bool hasBondStructure() const;
|
---|
[e08c46] | 182 | unsigned int CountBonds() const;
|
---|
[042f82] | 183 |
|
---|
| 184 | /// Find atoms.
|
---|
| 185 | atom * FindAtom(int Nr) const;
|
---|
| 186 | atom * AskAtom(string text);
|
---|
| 187 |
|
---|
| 188 | /// Count and change present atoms' coordination.
|
---|
[e138de] | 189 | bool CenterInBox();
|
---|
| 190 | bool BoundInBox();
|
---|
| 191 | void CenterEdge(Vector *max);
|
---|
| 192 | void CenterOrigin();
|
---|
| 193 | void CenterPeriodic();
|
---|
| 194 | void CenterAtVector(Vector *newcenter);
|
---|
[042f82] | 195 | void Translate(const Vector *x);
|
---|
| 196 | void TranslatePeriodically(const Vector *trans);
|
---|
| 197 | void Mirror(const Vector *x);
|
---|
| 198 | void Align(Vector *n);
|
---|
[776b64] | 199 | void Scale(const double ** const factor);
|
---|
[437922] | 200 | void DeterminePeriodicCenter(Vector ¢er);
|
---|
[4bb63c] | 201 | Vector * DetermineCenterOfGravity() const;
|
---|
[e138de] | 202 | Vector * DetermineCenterOfAll() const;
|
---|
[eddea2] | 203 | Vector * DetermineCenterOfBox() const;
|
---|
[437922] | 204 | void SetNameFromFilename(const char *filename);
|
---|
[042f82] | 205 | void SetBoxDimension(Vector *dim);
|
---|
[e138de] | 206 | void ScanForPeriodicCorrection();
|
---|
[ef7d30] | 207 | bool VerletForceIntegration(char *file, config &configuration, const size_t offset);
|
---|
[e138de] | 208 | double VolumeOfConvexEnvelope(bool IsAngstroem);
|
---|
[042f82] | 209 |
|
---|
[e138de] | 210 | double ConstrainedPotential(struct EvaluatePotential &Params);
|
---|
| 211 | double MinimiseConstrainedPotential(atom **&permutation, int startstep, int endstep, bool IsAngstroem);
|
---|
| 212 | void EvaluateConstrainedForces(int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force);
|
---|
[e4afb4] | 213 | bool LinearInterpolationBetweenConfiguration(int startstep, int endstep, std::string prefix, config &configuration, bool MapByIdentity);
|
---|
| 214 |
|
---|
[042f82] | 215 | bool CheckBounds(const Vector *x) const;
|
---|
| 216 | void GetAlignvector(struct lsq_params * par) const;
|
---|
| 217 |
|
---|
| 218 | /// Initialising routines in fragmentation
|
---|
[e138de] | 219 | void CreateAdjacencyListFromDbondFile(ifstream *output);
|
---|
[e4afb4] | 220 | void CreateAdjacencyList(double bonddistance, bool IsAngstroem, void(BondGraph::*f)(BondedParticle * const , BondedParticle * const , double &, double &, bool), BondGraph *BG = NULL);
|
---|
[e138de] | 221 | int CorrectBondDegree() const;
|
---|
| 222 | void OutputBondsList() const;
|
---|
[fa649a] | 223 | void CyclicBondAnalysis() const;
|
---|
[e138de] | 224 | void OutputGraphInfoPerAtom() const;
|
---|
| 225 | void OutputGraphInfoPerBond() const;
|
---|
[b8b75d] | 226 |
|
---|
[042f82] | 227 | // Graph analysis
|
---|
[a564be] | 228 | MoleculeLeafClass * DepthFirstSearchAnalysis(std::deque<bond *> *&BackEdgeStack) const;
|
---|
| 229 | void CyclicStructureAnalysis(std::deque<bond *> *BackEdgeStack, int *&MinimumRingSize) const;
|
---|
| 230 | bool PickLocalBackEdges(atom **ListOfLocalAtoms, std::deque<bond *> *&ReferenceStack, std::deque<bond *> *&LocalStack) const;
|
---|
[fa649a] | 231 | bond * FindNextUnused(atom *vertex) const;
|
---|
| 232 | void SetNextComponentNumber(atom *vertex, int nr) const;
|
---|
| 233 | void ResetAllBondsToUnused() const;
|
---|
[e138de] | 234 | int CountCyclicBonds();
|
---|
| 235 | bool CheckForConnectedSubgraph(KeySet *Fragment);
|
---|
[fa649a] | 236 | string GetColor(enum Shading color) const;
|
---|
[266237] | 237 | bond * CopyBond(atom *left, atom *right, bond *CopyBond);
|
---|
| 238 |
|
---|
[e4afb4] | 239 | molecule *CopyMolecule() const;
|
---|
[c550dd] | 240 | molecule* CopyMoleculeFromSubRegion(const Shape&) const;
|
---|
[042f82] | 241 |
|
---|
| 242 | /// Fragment molecule by two different approaches:
|
---|
[35b698] | 243 | int FragmentMolecule(int Order, std::string &prefix);
|
---|
| 244 | bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path = "");
|
---|
[e4afb4] | 245 | bool StoreBondsToFile(std::string filename, std::string path = "");
|
---|
| 246 | bool StoreAdjacencyToFile(std::string filename, std::string path = "");
|
---|
[35b698] | 247 | bool CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms);
|
---|
| 248 | bool ParseOrderAtSiteFromFile(std::string &path);
|
---|
| 249 | bool StoreOrderAtSiteFile(std::string &path);
|
---|
| 250 | bool StoreForcesFile(MoleculeListClass *BondFragments, std::string &path, int *SortIndex);
|
---|
[e138de] | 251 | bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
|
---|
[9879f6] | 252 | bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
|
---|
[e138de] | 253 | void BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
|
---|
[042f82] | 254 | /// -# BOSSANOVA
|
---|
[e138de] | 255 | void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
|
---|
| 256 | int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
|
---|
| 257 | bool BuildInducedSubgraph(const molecule *Father);
|
---|
| 258 | molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);
|
---|
| 259 | void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
|
---|
| 260 | int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList);
|
---|
| 261 | int GuesstimateFragmentCount(int order);
|
---|
[042f82] | 262 |
|
---|
| 263 | // Recognize doubly appearing molecules in a list of them
|
---|
[e138de] | 264 | int * GetFatherSonAtomicMap(molecule *OtherMolecule);
|
---|
[042f82] | 265 |
|
---|
| 266 | // Output routines.
|
---|
[e4afb4] | 267 | bool Output(std::ostream * const output) const;
|
---|
| 268 | bool OutputTrajectories(ofstream * const output) const;
|
---|
[e138de] | 269 | void OutputListOfBonds() const;
|
---|
| 270 | bool OutputXYZ(ofstream * const output) const;
|
---|
| 271 | bool OutputTrajectoriesXYZ(ofstream * const output);
|
---|
| 272 | bool Checkout(ofstream * const output) const;
|
---|
| 273 | bool OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep);
|
---|
[042f82] | 274 |
|
---|
[c68025] | 275 | // Manipulation routines
|
---|
| 276 | void flipActiveFlag();
|
---|
| 277 |
|
---|
[e4afb4] | 278 | private:
|
---|
[00ef5c] | 279 | void init_DFS(struct DFSAccounting&) const;
|
---|
[e4afb4] | 280 | int last_atom; //!< number given to last atom
|
---|
| 281 | mutable internal_iterator InternalPointer; //!< internal pointer for PointCloud
|
---|
[14de469] | 282 | };
|
---|
| 283 |
|
---|
[cbc5fb] | 284 | molecule *NewMolecule();
|
---|
| 285 | void DeleteMolecule(molecule* mol);
|
---|
| 286 |
|
---|
[14de469] | 287 | /** A list of \a molecule classes.
|
---|
| 288 | */
|
---|
[e4afb4] | 289 | class MoleculeListClass : public Observable
|
---|
| 290 | {
|
---|
| 291 | public:
|
---|
| 292 | MoleculeList ListOfMolecules; //!< List of the contained molecules
|
---|
| 293 | int MaxIndex;
|
---|
[042f82] | 294 |
|
---|
[cbc5fb] | 295 | MoleculeListClass(World *world);
|
---|
[042f82] | 296 | ~MoleculeListClass();
|
---|
| 297 |
|
---|
[35b698] | 298 | bool AddHydrogenCorrection(std::string &path);
|
---|
| 299 | bool StoreForcesFile(std::string &path, int *SortIndex);
|
---|
[437922] | 300 | void insert(molecule *mol);
|
---|
[bd6bfa] | 301 | void erase(molecule *mol);
|
---|
[042f82] | 302 | molecule * ReturnIndex(int index);
|
---|
[35b698] | 303 | bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex);
|
---|
[042f82] | 304 | int NumberOfActiveMolecules();
|
---|
[24a5e0] | 305 | void Enumerate(ostream *out);
|
---|
[042f82] | 306 | void Output(ofstream *out);
|
---|
[568be7] | 307 | int CountAllAtoms() const;
|
---|
[042f82] | 308 |
|
---|
[477bb2] | 309 | // Methods moved here from the menus
|
---|
| 310 | // TODO: more refactoring needed on these methods
|
---|
| 311 | void createNewMolecule(periodentafel *periode);
|
---|
| 312 | void loadFromXYZ(periodentafel *periode);
|
---|
| 313 | void setMoleculeFilename();
|
---|
| 314 | void parseXYZIntoMolecule();
|
---|
| 315 | void eraseMolecule();
|
---|
| 316 |
|
---|
[e4afb4] | 317 | private:
|
---|
[cbc5fb] | 318 | World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
|
---|
[14de469] | 319 | };
|
---|
| 320 |
|
---|
| 321 | /** A leaf for a tree of \a molecule class
|
---|
| 322 | * Wraps molecules in a tree structure
|
---|
| 323 | */
|
---|
[e4afb4] | 324 | class MoleculeLeafClass
|
---|
| 325 | {
|
---|
| 326 | public:
|
---|
| 327 | molecule *Leaf; //!< molecule of this leaf
|
---|
| 328 | //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
|
---|
| 329 | //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
|
---|
| 330 | MoleculeLeafClass *previous; //!< Previous leaf on this level
|
---|
| 331 | MoleculeLeafClass *next; //!< Next leaf on this level
|
---|
[042f82] | 332 |
|
---|
| 333 | //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
|
---|
| 334 | MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
|
---|
| 335 | ~MoleculeLeafClass();
|
---|
| 336 |
|
---|
| 337 | bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
|
---|
[c27778] | 338 | bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
|
---|
[e138de] | 339 | bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
|
---|
| 340 | bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
|
---|
[c27778] | 341 | bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount, bool &FreeList);
|
---|
[e138de] | 342 | void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
|
---|
[042f82] | 343 | int Count() const;
|
---|
[14de469] | 344 | };
|
---|
| 345 |
|
---|
| 346 | #endif /*MOLECULES_HPP_*/
|
---|
| 347 |
|
---|