[14de469] | 1 | /** \file molecules.hpp
|
---|
| 2 | *
|
---|
[69eb71] | 3 | * Class definitions of atom and molecule, element and periodentafel
|
---|
[14de469] | 4 | */
|
---|
| 5 |
|
---|
| 6 | #ifndef MOLECULES_HPP_
|
---|
| 7 | #define MOLECULES_HPP_
|
---|
| 8 |
|
---|
| 9 | using namespace std;
|
---|
| 10 |
|
---|
| 11 | // GSL headers
|
---|
[d52ea1b] | 12 | #include <gsl/gsl_eigen.h>
|
---|
[14de469] | 13 | #include <gsl/gsl_heapsort.h>
|
---|
[6e9353] | 14 | #include <gsl/gsl_linalg.h>
|
---|
| 15 | #include <gsl/gsl_matrix.h>
|
---|
| 16 | #include <gsl/gsl_multimin.h>
|
---|
| 17 | #include <gsl/gsl_vector.h>
|
---|
[62f793] | 18 | #include <gsl/gsl_randist.h>
|
---|
[14de469] | 19 |
|
---|
[edb93c] | 20 | //// STL headers
|
---|
[14de469] | 21 | #include <map>
|
---|
| 22 | #include <set>
|
---|
| 23 | #include <deque>
|
---|
[d7e30c] | 24 | #include <list>
|
---|
[5e0d1f] | 25 | #include <vector>
|
---|
[14de469] | 26 |
|
---|
[357fba] | 27 | #include "atom.hpp"
|
---|
| 28 | #include "bond.hpp"
|
---|
[cd4ccc] | 29 | #include "element.hpp"
|
---|
[54a746] | 30 | #include "leastsquaremin.hpp"
|
---|
[357fba] | 31 | #include "linkedcell.hpp"
|
---|
[362b0e] | 32 | #include "parser.hpp"
|
---|
[68cb0f] | 33 | #include "periodentafel.hpp"
|
---|
[6d35e4] | 34 | #include "stackclass.hpp"
|
---|
[357fba] | 35 | #include "tesselation.hpp"
|
---|
[342f33f] | 36 | #include "vector.hpp"
|
---|
[14de469] | 37 |
|
---|
| 38 | class molecule;
|
---|
[2319ed] | 39 | class MoleculeLeafClass;
|
---|
[14de469] | 40 | class MoleculeListClass;
|
---|
| 41 |
|
---|
| 42 | /******************************** Some definitions for easier reading **********************************/
|
---|
| 43 |
|
---|
| 44 | #define KeyStack deque<int>
|
---|
| 45 | #define KeySet set<int>
|
---|
[5de3c9] | 46 | #define NumberValuePair pair<int, double>
|
---|
[49de64] | 47 | #define Graph map <KeySet, NumberValuePair, KeyCompare >
|
---|
| 48 | #define GraphPair pair <KeySet, NumberValuePair >
|
---|
[14de469] | 49 | #define KeySetTestPair pair<KeySet::iterator, bool>
|
---|
| 50 | #define GraphTestPair pair<Graph::iterator, bool>
|
---|
| 51 |
|
---|
[edb93c] | 52 | #define MoleculeList list <molecule *>
|
---|
| 53 | #define MoleculeListTest pair <MoleculeList::iterator, bool>
|
---|
| 54 |
|
---|
[ed060e] | 55 | #define DistancePair pair < double, atom* >
|
---|
| 56 | #define DistanceMap multimap < double, atom* >
|
---|
| 57 | #define DistanceTestPair pair < DistanceMap::iterator, bool>
|
---|
| 58 |
|
---|
[1907a7] | 59 |
|
---|
[edb93c] | 60 | //#define LinkedAtoms list <atom *>
|
---|
[3d919e] | 61 |
|
---|
[ed060e] | 62 | /******************************** Some small functions and/or structures **********************************/
|
---|
| 63 |
|
---|
[14de469] | 64 | struct KeyCompare
|
---|
| 65 | {
|
---|
[042f82] | 66 | bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const;
|
---|
[14de469] | 67 | };
|
---|
[6d35e4] | 68 |
|
---|
[d7e30c] | 69 | struct Trajectory
|
---|
| 70 | {
|
---|
[042f82] | 71 | vector<Vector> R; //!< position vector
|
---|
| 72 | vector<Vector> U; //!< velocity vector
|
---|
| 73 | vector<Vector> F; //!< last force vector
|
---|
| 74 | atom *ptr; //!< pointer to atom whose trajectory we contain
|
---|
[d7e30c] | 75 | };
|
---|
| 76 |
|
---|
[042f82] | 77 | //bool operator < (KeySet SubgraphA, KeySet SubgraphB); //note: this declaration is important, otherwise normal < is used (producing wrong order)
|
---|
[14de469] | 78 | inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
|
---|
[042f82] | 79 | inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph
|
---|
[14de469] | 80 | int CompareDoubles (const void * a, const void * b);
|
---|
| 81 |
|
---|
[6d35e4] | 82 |
|
---|
[14de469] | 83 | /************************************* Class definitions ****************************************/
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 |
|
---|
[62f793] | 87 | #define MaxThermostats 6 //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
|
---|
| 88 | enum thermostats { None, Woodcock, Gaussian, Langevin, Berendsen, NoseHoover }; //!< Thermostat names for output
|
---|
| 89 |
|
---|
| 90 |
|
---|
[14de469] | 91 | /** The complete molecule.
|
---|
| 92 | * Class incorporates number of types
|
---|
| 93 | */
|
---|
[357fba] | 94 | class molecule : public PointCloud {
|
---|
[042f82] | 95 | public:
|
---|
| 96 | double cell_size[6];//!< cell size
|
---|
| 97 | periodentafel *elemente; //!< periodic table with each element
|
---|
| 98 | atom *start; //!< start of atom list
|
---|
| 99 | atom *end; //!< end of atom list
|
---|
| 100 | bond *first; //!< start of bond list
|
---|
| 101 | bond *last; //!< end of bond list
|
---|
| 102 | bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has
|
---|
| 103 | map<atom *, struct Trajectory> Trajectories; //!< contains old trajectory points
|
---|
| 104 | int MDSteps; //!< The number of MD steps in Trajectories
|
---|
| 105 | int *NumberOfBondsPerAtom; //!< Number of Bonds each atom has
|
---|
| 106 | int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
|
---|
| 107 | int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
|
---|
| 108 | int ElementCount; //!< how many unique elements are therein
|
---|
| 109 | int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not
|
---|
| 110 | int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
|
---|
| 111 | int NoNonBonds; //!< number of non-hydrogen bonds in molecule
|
---|
| 112 | int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
|
---|
| 113 | double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
|
---|
| 114 | bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
|
---|
| 115 | Vector Center; //!< Center of molecule in a global box
|
---|
| 116 | char name[MAXSTRINGSIZE]; //!< arbitrary name
|
---|
| 117 | int IndexNr; //!< index of molecule in a MoleculeListClass
|
---|
[357fba] | 118 | class Tesselation *TesselStruct;
|
---|
[042f82] | 119 |
|
---|
| 120 | molecule(periodentafel *teil);
|
---|
[ab1932] | 121 | virtual ~molecule();
|
---|
[042f82] | 122 |
|
---|
[357fba] | 123 | // re-definition of virtual functions from PointCloud
|
---|
| 124 | Vector *GetCenter(ofstream *out);
|
---|
| 125 | TesselPoint *GetPoint();
|
---|
| 126 | TesselPoint *GetTerminalPoint();
|
---|
| 127 | void GoToNext();
|
---|
| 128 | void GoToPrevious();
|
---|
| 129 | void GoToFirst();
|
---|
| 130 | void GoToLast();
|
---|
| 131 | bool IsEmpty();
|
---|
[1999d8] | 132 | bool IsEnd();
|
---|
[042f82] | 133 |
|
---|
| 134 | /// remove atoms from molecule.
|
---|
| 135 | bool AddAtom(atom *pointer);
|
---|
| 136 | bool RemoveAtom(atom *pointer);
|
---|
| 137 | bool UnlinkAtom(atom *pointer);
|
---|
| 138 | bool CleanupMolecule();
|
---|
| 139 |
|
---|
| 140 | /// Add/remove atoms to/from molecule.
|
---|
| 141 | atom * AddCopyAtom(atom *pointer);
|
---|
| 142 | bool AddXYZFile(string filename);
|
---|
| 143 | bool AddHydrogenReplacementAtom(ofstream *out, bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bond **BondList, int NumBond, bool IsAngstroem);
|
---|
| 144 | bond * AddBond(atom *first, atom *second, int degree);
|
---|
| 145 | bool RemoveBond(bond *pointer);
|
---|
| 146 | bool RemoveBonds(atom *BondPartner);
|
---|
| 147 |
|
---|
| 148 | /// Find atoms.
|
---|
| 149 | atom * FindAtom(int Nr) const;
|
---|
| 150 | atom * AskAtom(string text);
|
---|
| 151 |
|
---|
| 152 | /// Count and change present atoms' coordination.
|
---|
| 153 | void CountAtoms(ofstream *out);
|
---|
| 154 | void CountElements();
|
---|
| 155 | void CalculateOrbitals(class config &configuration);
|
---|
| 156 | bool CenterInBox(ofstream *out);
|
---|
[f3278b] | 157 | bool BoundInBox(ofstream *out);
|
---|
[042f82] | 158 | void CenterEdge(ofstream *out, Vector *max);
|
---|
[437922] | 159 | void CenterOrigin(ofstream *out);
|
---|
| 160 | void CenterPeriodic(ofstream *out);
|
---|
| 161 | void CenterAtVector(ofstream *out, Vector *newcenter);
|
---|
[042f82] | 162 | void Translate(const Vector *x);
|
---|
| 163 | void TranslatePeriodically(const Vector *trans);
|
---|
| 164 | void Mirror(const Vector *x);
|
---|
| 165 | void Align(Vector *n);
|
---|
| 166 | void Scale(double **factor);
|
---|
[437922] | 167 | void DeterminePeriodicCenter(Vector ¢er);
|
---|
[042f82] | 168 | Vector * DetermineCenterOfGravity(ofstream *out);
|
---|
| 169 | Vector * DetermineCenterOfAll(ofstream *out);
|
---|
[437922] | 170 | void SetNameFromFilename(const char *filename);
|
---|
[042f82] | 171 | void SetBoxDimension(Vector *dim);
|
---|
| 172 | double * ReturnFullMatrixforSymmetric(double *cell_size);
|
---|
| 173 | void ScanForPeriodicCorrection(ofstream *out);
|
---|
[631dcb] | 174 | bool VerletForceIntegration(ofstream *out, char *file, config &configuration);
|
---|
[62f793] | 175 | void Thermostats(config &configuration, double ActualTemp, int Thermostat);
|
---|
[042f82] | 176 | void PrincipalAxisSystem(ofstream *out, bool DoRotate);
|
---|
| 177 | double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
|
---|
| 178 | Vector* FindEmbeddingHole(ofstream *out, molecule *srcmol);
|
---|
| 179 |
|
---|
| 180 |
|
---|
[62f793] | 181 | double ConstrainedPotential(ofstream *out, atom **permutation, int start, int end, double *constants, bool IsAngstroem);
|
---|
[631dcb] | 182 | double MinimiseConstrainedPotential(ofstream *out, atom **&permutation, int startstep, int endstep, bool IsAngstroem);
|
---|
| 183 | void EvaluateConstrainedForces(ofstream *out, int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force);
|
---|
| 184 | bool LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration);
|
---|
[d52ea1b] | 185 |
|
---|
[042f82] | 186 | bool CheckBounds(const Vector *x) const;
|
---|
| 187 | void GetAlignvector(struct lsq_params * par) const;
|
---|
| 188 |
|
---|
| 189 | /// Initialising routines in fragmentation
|
---|
| 190 | void CreateAdjacencyList2(ofstream *out, ifstream *output);
|
---|
| 191 | void CreateAdjacencyList(ofstream *out, double bonddistance, bool IsAngstroem);
|
---|
| 192 | void CreateListOfBondsPerAtom(ofstream *out);
|
---|
| 193 |
|
---|
| 194 | // Graph analysis
|
---|
| 195 | MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack);
|
---|
| 196 | void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
|
---|
| 197 | bool PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack);
|
---|
| 198 | bond * FindNextUnused(atom *vertex);
|
---|
| 199 | void SetNextComponentNumber(atom *vertex, int nr);
|
---|
| 200 | void InitComponentNumbers();
|
---|
| 201 | void OutputComponentNumber(ofstream *out, atom *vertex);
|
---|
| 202 | void ResetAllBondsToUnused();
|
---|
| 203 | void ResetAllAtomNumbers();
|
---|
| 204 | int CountCyclicBonds(ofstream *out);
|
---|
| 205 | bool CheckForConnectedSubgraph(ofstream *out, KeySet *Fragment);
|
---|
| 206 | string GetColor(enum Shading color);
|
---|
| 207 |
|
---|
| 208 | molecule *CopyMolecule();
|
---|
[89c8b2] | 209 | molecule* CopyMoleculeFromSubRegion(Vector offset, double *parallelepiped);
|
---|
[042f82] | 210 |
|
---|
| 211 | /// Fragment molecule by two different approaches:
|
---|
| 212 | int FragmentMolecule(ofstream *out, int Order, config *configuration);
|
---|
| 213 | bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
|
---|
| 214 | bool StoreAdjacencyToFile(ofstream *out, char *path);
|
---|
| 215 | bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
|
---|
| 216 | bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
|
---|
| 217 | bool StoreOrderAtSiteFile(ofstream *out, char *path);
|
---|
| 218 | bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
|
---|
| 219 | bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
|
---|
| 220 | bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
|
---|
| 221 | bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex);
|
---|
| 222 | bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
|
---|
| 223 | void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
|
---|
| 224 | /// -# BOSSANOVA
|
---|
| 225 | void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
|
---|
| 226 | int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
|
---|
| 227 | bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
|
---|
| 228 | molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
|
---|
| 229 | void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
|
---|
| 230 | int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
|
---|
| 231 | int GuesstimateFragmentCount(ofstream *out, int order);
|
---|
| 232 |
|
---|
| 233 | // Recognize doubly appearing molecules in a list of them
|
---|
| 234 | int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold);
|
---|
| 235 | int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule);
|
---|
| 236 |
|
---|
| 237 | // Output routines.
|
---|
| 238 | bool Output(ofstream *out);
|
---|
| 239 | bool OutputTrajectories(ofstream *out);
|
---|
| 240 | void OutputListOfBonds(ofstream *out) const;
|
---|
| 241 | bool OutputXYZ(ofstream *out) const;
|
---|
| 242 | bool OutputTrajectoriesXYZ(ofstream *out);
|
---|
| 243 | bool Checkout(ofstream *out) const;
|
---|
| 244 | bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output);
|
---|
| 245 |
|
---|
| 246 | private:
|
---|
| 247 | int last_atom; //!< number given to last atom
|
---|
[357fba] | 248 | atom *InternalPointer; //!< internal pointer for PointCloud
|
---|
[14de469] | 249 | };
|
---|
| 250 |
|
---|
| 251 | /** A list of \a molecule classes.
|
---|
| 252 | */
|
---|
| 253 | class MoleculeListClass {
|
---|
[042f82] | 254 | public:
|
---|
| 255 | MoleculeList ListOfMolecules; //!< List of the contained molecules
|
---|
| 256 | int MaxIndex;
|
---|
| 257 |
|
---|
| 258 | MoleculeListClass();
|
---|
| 259 | ~MoleculeListClass();
|
---|
| 260 |
|
---|
| 261 | bool AddHydrogenCorrection(ofstream *out, char *path);
|
---|
| 262 | bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
|
---|
[437922] | 263 | void insert(molecule *mol);
|
---|
[042f82] | 264 | molecule * ReturnIndex(int index);
|
---|
| 265 | bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
|
---|
| 266 | int NumberOfActiveMolecules();
|
---|
| 267 | void Enumerate(ofstream *out);
|
---|
| 268 | void Output(ofstream *out);
|
---|
| 269 |
|
---|
| 270 | // merging of molecules
|
---|
[1907a7] | 271 | bool SimpleMerge(molecule *mol, molecule *srcmol);
|
---|
| 272 | bool SimpleAdd(molecule *mol, molecule *srcmol);
|
---|
| 273 | bool SimpleMultiMerge(molecule *mol, int *src, int N);
|
---|
| 274 | bool SimpleMultiAdd(molecule *mol, int *src, int N);
|
---|
| 275 | bool ScatterMerge(molecule *mol, int *src, int N);
|
---|
| 276 | bool EmbedMerge(molecule *mol, molecule *srcmol);
|
---|
| 277 |
|
---|
[042f82] | 278 | private:
|
---|
[14de469] | 279 | };
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 | /** A leaf for a tree of \a molecule class
|
---|
| 283 | * Wraps molecules in a tree structure
|
---|
| 284 | */
|
---|
| 285 | class MoleculeLeafClass {
|
---|
[042f82] | 286 | public:
|
---|
| 287 | molecule *Leaf; //!< molecule of this leaf
|
---|
| 288 | //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
|
---|
| 289 | //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
|
---|
| 290 | MoleculeLeafClass *previous; //!< Previous leaf on this level
|
---|
| 291 | MoleculeLeafClass *next; //!< Next leaf on this level
|
---|
| 292 |
|
---|
| 293 | //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
|
---|
| 294 | MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
|
---|
| 295 | ~MoleculeLeafClass();
|
---|
| 296 |
|
---|
| 297 | bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
|
---|
| 298 | bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
|
---|
| 299 | bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
|
---|
| 300 | bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
|
---|
| 301 | bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList);
|
---|
| 302 | void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
|
---|
| 303 | int Count() const;
|
---|
[14de469] | 304 | };
|
---|
| 305 |
|
---|
[d1df9b] | 306 |
|
---|
[14de469] | 307 | #endif /*MOLECULES_HPP_*/
|
---|
| 308 |
|
---|