1 | /** \file molecules.hpp
|
---|
2 | *
|
---|
3 | * Class definitions of atom and molecule, element and periodentafel
|
---|
4 | */
|
---|
5 |
|
---|
6 | #ifndef MOLECULES_HPP_
|
---|
7 | #define MOLECULES_HPP_
|
---|
8 |
|
---|
9 | using namespace std;
|
---|
10 |
|
---|
11 | // GSL headers
|
---|
12 | #include <gsl/gsl_eigen.h>
|
---|
13 | #include <gsl/gsl_heapsort.h>
|
---|
14 | #include <gsl/gsl_linalg.h>
|
---|
15 | #include <gsl/gsl_matrix.h>
|
---|
16 | #include <gsl/gsl_multimin.h>
|
---|
17 | #include <gsl/gsl_vector.h>
|
---|
18 | #include <gsl/gsl_randist.h>
|
---|
19 |
|
---|
20 | //// STL headers
|
---|
21 | #include <map>
|
---|
22 | #include <set>
|
---|
23 | #include <deque>
|
---|
24 | #include <list>
|
---|
25 | #include <vector>
|
---|
26 |
|
---|
27 | #include "atom.hpp"
|
---|
28 | #include "bond.hpp"
|
---|
29 | #include "element.hpp"
|
---|
30 | #include "leastsquaremin.hpp"
|
---|
31 | #include "linkedcell.hpp"
|
---|
32 | #include "parser.hpp"
|
---|
33 | #include "periodentafel.hpp"
|
---|
34 | #include "stackclass.hpp"
|
---|
35 | #include "tesselation.hpp"
|
---|
36 | #include "vector.hpp"
|
---|
37 |
|
---|
38 | class molecule;
|
---|
39 | class MoleculeLeafClass;
|
---|
40 | class MoleculeListClass;
|
---|
41 |
|
---|
42 | /******************************** Some definitions for easier reading **********************************/
|
---|
43 |
|
---|
44 | #define KeyStack deque<int>
|
---|
45 | #define KeySet set<int>
|
---|
46 | #define NumberValuePair pair<int, double>
|
---|
47 | #define Graph map <KeySet, NumberValuePair, KeyCompare >
|
---|
48 | #define GraphPair pair <KeySet, NumberValuePair >
|
---|
49 | #define KeySetTestPair pair<KeySet::iterator, bool>
|
---|
50 | #define GraphTestPair pair<Graph::iterator, bool>
|
---|
51 |
|
---|
52 | #define MoleculeList list <molecule *>
|
---|
53 | #define MoleculeListTest pair <MoleculeList::iterator, bool>
|
---|
54 |
|
---|
55 | #define DistancePair pair < double, atom* >
|
---|
56 | #define DistanceMap multimap < double, atom* >
|
---|
57 | #define DistanceTestPair pair < DistanceMap::iterator, bool>
|
---|
58 |
|
---|
59 |
|
---|
60 | //#define LinkedAtoms list <atom *>
|
---|
61 |
|
---|
62 | /******************************** Some small functions and/or structures **********************************/
|
---|
63 |
|
---|
64 | struct KeyCompare
|
---|
65 | {
|
---|
66 | bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const;
|
---|
67 | };
|
---|
68 |
|
---|
69 | struct Trajectory
|
---|
70 | {
|
---|
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
|
---|
75 | };
|
---|
76 |
|
---|
77 | //bool operator < (KeySet SubgraphA, KeySet SubgraphB); //note: this declaration is important, otherwise normal < is used (producing wrong order)
|
---|
78 | inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
|
---|
79 | inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph
|
---|
80 | int CompareDoubles (const void * a, const void * b);
|
---|
81 |
|
---|
82 |
|
---|
83 | /************************************* Class definitions ****************************************/
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
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 |
|
---|
91 | /** The complete molecule.
|
---|
92 | * Class incorporates number of types
|
---|
93 | */
|
---|
94 | class molecule : public PointCloud {
|
---|
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
|
---|
118 | class Tesselation *TesselStruct;
|
---|
119 |
|
---|
120 | molecule(periodentafel *teil);
|
---|
121 | virtual ~molecule();
|
---|
122 |
|
---|
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();
|
---|
132 | bool IsEnd();
|
---|
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);
|
---|
157 | bool BoundInBox(ofstream *out);
|
---|
158 | void CenterEdge(ofstream *out, Vector *max);
|
---|
159 | void CenterOrigin(ofstream *out);
|
---|
160 | void CenterPeriodic(ofstream *out);
|
---|
161 | void CenterAtVector(ofstream *out, Vector *newcenter);
|
---|
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);
|
---|
167 | void DeterminePeriodicCenter(Vector ¢er);
|
---|
168 | Vector * DetermineCenterOfGravity(ofstream *out);
|
---|
169 | Vector * DetermineCenterOfAll(ofstream *out);
|
---|
170 | void SetNameFromFilename(const char *filename);
|
---|
171 | void SetBoxDimension(Vector *dim);
|
---|
172 | double * ReturnFullMatrixforSymmetric(double *cell_size);
|
---|
173 | void ScanForPeriodicCorrection(ofstream *out);
|
---|
174 | bool VerletForceIntegration(ofstream *out, char *file, config &configuration);
|
---|
175 | void Thermostats(config &configuration, double ActualTemp, int Thermostat);
|
---|
176 | void PrincipalAxisSystem(ofstream *out, bool DoRotate);
|
---|
177 | double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
|
---|
178 | Vector* FindEmbeddingHole(ofstream *out, molecule *srcmol);
|
---|
179 |
|
---|
180 |
|
---|
181 | double ConstrainedPotential(ofstream *out, atom **permutation, int start, int end, double *constants, bool IsAngstroem);
|
---|
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);
|
---|
185 |
|
---|
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();
|
---|
209 |
|
---|
210 | /// Fragment molecule by two different approaches:
|
---|
211 | int FragmentMolecule(ofstream *out, int Order, config *configuration);
|
---|
212 | bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
|
---|
213 | bool StoreAdjacencyToFile(ofstream *out, char *path);
|
---|
214 | bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
|
---|
215 | bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
|
---|
216 | bool StoreOrderAtSiteFile(ofstream *out, char *path);
|
---|
217 | bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
|
---|
218 | bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
|
---|
219 | bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
|
---|
220 | bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex);
|
---|
221 | bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
|
---|
222 | void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
|
---|
223 | /// -# BOSSANOVA
|
---|
224 | void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
|
---|
225 | int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
|
---|
226 | bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
|
---|
227 | molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
|
---|
228 | void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
|
---|
229 | int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
|
---|
230 | int GuesstimateFragmentCount(ofstream *out, int order);
|
---|
231 |
|
---|
232 | // Recognize doubly appearing molecules in a list of them
|
---|
233 | int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold);
|
---|
234 | int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule);
|
---|
235 |
|
---|
236 | // Output routines.
|
---|
237 | bool Output(ofstream *out);
|
---|
238 | bool OutputTrajectories(ofstream *out);
|
---|
239 | void OutputListOfBonds(ofstream *out) const;
|
---|
240 | bool OutputXYZ(ofstream *out) const;
|
---|
241 | bool OutputTrajectoriesXYZ(ofstream *out);
|
---|
242 | bool Checkout(ofstream *out) const;
|
---|
243 | bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output);
|
---|
244 |
|
---|
245 | private:
|
---|
246 | int last_atom; //!< number given to last atom
|
---|
247 | atom *InternalPointer; //!< internal pointer for PointCloud
|
---|
248 | };
|
---|
249 |
|
---|
250 | /** A list of \a molecule classes.
|
---|
251 | */
|
---|
252 | class MoleculeListClass {
|
---|
253 | public:
|
---|
254 | MoleculeList ListOfMolecules; //!< List of the contained molecules
|
---|
255 | int MaxIndex;
|
---|
256 |
|
---|
257 | MoleculeListClass();
|
---|
258 | ~MoleculeListClass();
|
---|
259 |
|
---|
260 | bool AddHydrogenCorrection(ofstream *out, char *path);
|
---|
261 | bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
|
---|
262 | void insert(molecule *mol);
|
---|
263 | molecule * ReturnIndex(int index);
|
---|
264 | bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
|
---|
265 | int NumberOfActiveMolecules();
|
---|
266 | void Enumerate(ofstream *out);
|
---|
267 | void Output(ofstream *out);
|
---|
268 |
|
---|
269 | // merging of molecules
|
---|
270 | bool SimpleMerge(molecule *mol, molecule *srcmol);
|
---|
271 | bool SimpleAdd(molecule *mol, molecule *srcmol);
|
---|
272 | bool SimpleMultiMerge(molecule *mol, int *src, int N);
|
---|
273 | bool SimpleMultiAdd(molecule *mol, int *src, int N);
|
---|
274 | bool ScatterMerge(molecule *mol, int *src, int N);
|
---|
275 | bool EmbedMerge(molecule *mol, molecule *srcmol);
|
---|
276 |
|
---|
277 | private:
|
---|
278 | };
|
---|
279 |
|
---|
280 |
|
---|
281 | /** A leaf for a tree of \a molecule class
|
---|
282 | * Wraps molecules in a tree structure
|
---|
283 | */
|
---|
284 | class MoleculeLeafClass {
|
---|
285 | public:
|
---|
286 | molecule *Leaf; //!< molecule of this leaf
|
---|
287 | //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
|
---|
288 | //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
|
---|
289 | MoleculeLeafClass *previous; //!< Previous leaf on this level
|
---|
290 | MoleculeLeafClass *next; //!< Next leaf on this level
|
---|
291 |
|
---|
292 | //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
|
---|
293 | MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
|
---|
294 | ~MoleculeLeafClass();
|
---|
295 |
|
---|
296 | bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
|
---|
297 | bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
|
---|
298 | bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
|
---|
299 | bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
|
---|
300 | bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList);
|
---|
301 | void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
|
---|
302 | int Count() const;
|
---|
303 | };
|
---|
304 |
|
---|
305 | class ConfigFileBuffer {
|
---|
306 | public:
|
---|
307 | char **buffer;
|
---|
308 | int *LineMapping;
|
---|
309 | int CurrentLine;
|
---|
310 | int NoLines;
|
---|
311 |
|
---|
312 | ConfigFileBuffer();
|
---|
313 | ConfigFileBuffer(char *filename);
|
---|
314 | ~ConfigFileBuffer();
|
---|
315 |
|
---|
316 | void InitMapping();
|
---|
317 | void MapIonTypesInBuffer(int NoAtoms);
|
---|
318 | };
|
---|
319 |
|
---|
320 |
|
---|
321 | #endif /*MOLECULES_HPP_*/
|
---|
322 |
|
---|