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