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