source: molecuilder/src/molecules.hpp@ e78824

Last change on this file since e78824 was e78824, checked in by Frederik Heber <heber@…>, 16 years ago

class config definitions moved to their own header file.

NOTE: Tesselation of heptan was working correctly! (The config file just grew bigger and bigger that's why more and more triangles were added)

  • Property mode set to 100755
File size: 14.0 KB
Line 
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
9using 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 "helpers.hpp"
30#include "linkedcell.hpp"
31#include "parser.hpp"
32#include "periodentafel.hpp"
33#include "stackclass.hpp"
34#include "tesselation.hpp"
35#include "vector.hpp"
36
37class molecule;
38class MoleculeLeafClass;
39class MoleculeListClass;
40class Verbose;
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 DistancePair pair < double, atom* >
53#define DistanceMap multimap < double, atom* >
54#define DistanceTestPair pair < DistanceMap::iterator, bool>
55
56#define Boundaries map <double, DistancePair >
57#define BoundariesPair pair<double, DistancePair >
58#define BoundariesTestPair pair< Boundaries::iterator, bool>
59
60#define MoleculeList list <molecule *>
61#define MoleculeListTest pair <MoleculeList::iterator, bool>
62
63#define LinkedAtoms list <atom *>
64
65/******************************** Some small functions and/or structures **********************************/
66
67struct KeyCompare
68{
69 bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const;
70};
71
72struct Trajectory
73{
74 vector<Vector> R; //!< position vector
75 vector<Vector> U; //!< velocity vector
76 vector<Vector> F; //!< last force vector
77 atom *ptr; //!< pointer to atom whose trajectory we contain
78};
79
80//bool operator < (KeySet SubgraphA, KeySet SubgraphB); //note: this declaration is important, otherwise normal < is used (producing wrong order)
81inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
82inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph
83int CompareDoubles (const void * a, const void * b);
84
85
86/************************************* Class definitions ****************************************/
87
88
89// some algebraic matrix stuff
90#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
91#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix
92
93
94/** Parameter structure for least square minimsation.
95 */
96struct LSQ_params {
97 Vector **vectors;
98 int num;
99};
100
101double LSQ(const gsl_vector * x, void * params);
102
103/** Parameter structure for least square minimsation.
104 */
105struct lsq_params {
106 gsl_vector *x;
107 const molecule *mol;
108 element *type;
109};
110
111
112#define MaxThermostats 6 //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
113enum thermostats { None, Woodcock, Gaussian, Langevin, Berendsen, NoseHoover }; //!< Thermostat names for output
114
115
116/** The complete molecule.
117 * Class incorporates number of types
118 */
119class molecule : public PointCloud {
120 public:
121 double cell_size[6];//!< cell size
122 periodentafel *elemente; //!< periodic table with each element
123 atom *start; //!< start of atom list
124 atom *end; //!< end of atom list
125 bond *first; //!< start of bond list
126 bond *last; //!< end of bond list
127 bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has
128 map<atom *, struct Trajectory> Trajectories; //!< contains old trajectory points
129 int MDSteps; //!< The number of MD steps in Trajectories
130 int *NumberOfBondsPerAtom; //!< Number of Bonds each atom has
131 int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
132 int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
133 int ElementCount; //!< how many unique elements are therein
134 int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not
135 int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
136 int NoNonBonds; //!< number of non-hydrogen bonds in molecule
137 int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
138 double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
139 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
140 Vector Center; //!< Center of molecule in a global box
141 char name[MAXSTRINGSIZE]; //!< arbitrary name
142 int IndexNr; //!< index of molecule in a MoleculeListClass
143 class Tesselation *TesselStruct;
144
145 molecule(periodentafel *teil);
146 ~molecule();
147
148 // re-definition of virtual functions from PointCloud
149 Vector *GetCenter(ofstream *out);
150 TesselPoint *GetPoint();
151 TesselPoint *GetTerminalPoint();
152 void GoToNext();
153 void GoToPrevious();
154 void GoToFirst();
155 void GoToLast();
156 bool IsEmpty();
157 bool IsLast();
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);
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 void CenterEdge(ofstream *out, Vector *max);
183 void CenterOrigin(ofstream *out);
184 void CenterPeriodic(ofstream *out);
185 void CenterAtVector(ofstream *out, Vector *newcenter);
186 void Translate(const Vector *x);
187 void TranslatePeriodically(const Vector *trans);
188 void Mirror(const Vector *x);
189 void Align(Vector *n);
190 void Scale(double **factor);
191 void DeterminePeriodicCenter(Vector &center);
192 Vector * DetermineCenterOfGravity(ofstream *out);
193 Vector * DetermineCenterOfAll(ofstream *out);
194 void SetNameFromFilename(const char *filename);
195 void SetBoxDimension(Vector *dim);
196 double * ReturnFullMatrixforSymmetric(double *cell_size);
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);
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
234 /// Fragment molecule by two different approaches:
235 int FragmentMolecule(ofstream *out, int Order, config *configuration);
236 bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
237 bool StoreAdjacencyToFile(ofstream *out, char *path);
238 bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
239 bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
240 bool StoreOrderAtSiteFile(ofstream *out, char *path);
241 bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
242 bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
243 bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
244 bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex);
245 bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
246 void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
247 /// -# BOSSANOVA
248 void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
249 int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
250 bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
251 molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
252 void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
253 int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
254 int GuesstimateFragmentCount(ofstream *out, int order);
255
256 // Recognize doubly appearing molecules in a list of them
257 int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold);
258 int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule);
259
260 // Output routines.
261 bool Output(ofstream *out);
262 bool OutputTrajectories(ofstream *out);
263 void OutputListOfBonds(ofstream *out) const;
264 bool OutputXYZ(ofstream *out) const;
265 bool OutputTrajectoriesXYZ(ofstream *out);
266 bool Checkout(ofstream *out) const;
267 bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output);
268
269 private:
270 int last_atom; //!< number given to last atom
271 atom *InternalPointer; //!< internal pointer for PointCloud
272};
273
274/** A list of \a molecule classes.
275 */
276class MoleculeListClass {
277 public:
278 MoleculeList ListOfMolecules; //!< List of the contained molecules
279 int MaxIndex;
280
281 MoleculeListClass();
282 ~MoleculeListClass();
283
284 bool AddHydrogenCorrection(ofstream *out, char *path);
285 bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
286 void insert(molecule *mol);
287 molecule * ReturnIndex(int index);
288 bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
289 int NumberOfActiveMolecules();
290 void Enumerate(ofstream *out);
291 void Output(ofstream *out);
292
293 // merging of molecules
294 bool SimpleMerge(molecule *mol, molecule *srcmol);
295 bool SimpleAdd(molecule *mol, molecule *srcmol);
296 bool SimpleMultiMerge(molecule *mol, int *src, int N);
297 bool SimpleMultiAdd(molecule *mol, int *src, int N);
298 bool ScatterMerge(molecule *mol, int *src, int N);
299 bool EmbedMerge(molecule *mol, molecule *srcmol);
300
301 private:
302};
303
304
305/** A leaf for a tree of \a molecule class
306 * Wraps molecules in a tree structure
307 */
308class MoleculeLeafClass {
309 public:
310 molecule *Leaf; //!< molecule of this leaf
311 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
312 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
313 MoleculeLeafClass *previous; //!< Previous leaf on this level
314 MoleculeLeafClass *next; //!< Next leaf on this level
315
316 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
317 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
318 ~MoleculeLeafClass();
319
320 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
321 bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
322 bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
323 bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
324 bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList);
325 void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
326 int Count() const;
327};
328
329class ConfigFileBuffer {
330 public:
331 char **buffer;
332 int *LineMapping;
333 int CurrentLine;
334 int NoLines;
335
336 ConfigFileBuffer();
337 ConfigFileBuffer(char *filename);
338 ~ConfigFileBuffer();
339
340 void InitMapping();
341 void MapIonTypesInBuffer(int NoAtoms);
342};
343
344
345#endif /*MOLECULES_HPP_*/
346
Note: See TracBrowser for help on using the repository browser.