source: molecuilder/src/molecules.hpp@ 848729

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

Just a temporary commit

  • Property mode set to 100755
File size: 17.6 KB
RevLine 
[a0bcf1]1/** \file molecules.hpp
2 *
[e0c5b1]3 * Class definitions of atom and molecule, element and periodentafel
[a0bcf1]4 */
5
6#ifndef MOLECULES_HPP_
7#define MOLECULES_HPP_
8
9using namespace std;
10
11// GSL headers
12#include <gsl/gsl_multimin.h>
13#include <gsl/gsl_vector.h>
14#include <gsl/gsl_matrix.h>
[32b6dc]15#include <gsl/gsl_eigen.h>
[a0bcf1]16#include <gsl/gsl_heapsort.h>
17
18// STL headers
19#include <map>
20#include <set>
21#include <deque>
[0a08df]22#include <list>
[67f102]23#include <vector>
[a0bcf1]24
25#include "helpers.hpp"
[644ba1]26#include "parser.hpp"
[375dcf]27#include "periodentafel.hpp"
[d50d2a]28#include "stackclass.hpp"
[725869]29#include "vector.hpp"
[a0bcf1]30
31class atom;
32class bond;
33class config;
34class molecule;
35class MoleculeListClass;
36class Verbose;
37
38/******************************** Some definitions for easier reading **********************************/
39
40#define KeyStack deque<int>
41#define KeySet set<int>
[a3ff7b2]42#define NumberValuePair pair<int, double>
[2259f4]43#define Graph map <KeySet, NumberValuePair, KeyCompare >
44#define GraphPair pair <KeySet, NumberValuePair >
[a0bcf1]45#define KeySetTestPair pair<KeySet::iterator, bool>
46#define GraphTestPair pair<Graph::iterator, bool>
47
[dfc1c7]48#define DistancePair pair < double, atom* >
49#define DistanceMap multimap < double, atom* >
50#define DistanceTestPair pair < DistanceMap::iterator, bool>
51
52#define Boundaries map <double, DistancePair >
53#define BoundariesPair pair<double, DistancePair >
54#define BoundariesTestPair pair< Boundaries::iterator, bool>
55
[e0c5b1]56#define PointMap map < int, class BoundaryPointSet * >
57#define PointPair pair < int, class BoundaryPointSet * >
58#define PointTestPair pair < PointMap::iterator, bool >
[dfc1c7]59
[e0c5b1]60#define LineMap map < int, class BoundaryLineSet * >
61#define LinePair pair < int, class BoundaryLineSet * >
[848729]62#define LineTestPair pair < LineMap::iterator, bool >
[dfc1c7]63
[e0c5b1]64#define TriangleMap map < int, class BoundaryTriangleSet * >
65#define TrianglePair pair < int, class BoundaryTriangleSet * >
66#define TriangleTestPair pair < TrianglePair::iterator, bool >
[dfc1c7]67
68#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
69#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
70
71/******************************** Some small functions and/or structures **********************************/
72
[a0bcf1]73struct KeyCompare
74{
75 bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const;
76};
[d50d2a]77
[0a08df]78struct Trajectory
79{
[67f102]80 vector<Vector> R; //!< position vector
81 vector<Vector> U; //!< velocity vector
82 vector<Vector> F; //!< last force vector
83 atom *ptr; //!< pointer to atom whose trajectory we contain
[0a08df]84};
85
[a0bcf1]86//bool operator < (KeySet SubgraphA, KeySet SubgraphB); //note: this declaration is important, otherwise normal < is used (producing wrong order)
87inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
[e0c5b1]88inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph
[a0bcf1]89int CompareDoubles (const void * a, const void * b);
90
[d50d2a]91
[a0bcf1]92/************************************* Class definitions ****************************************/
93
94
95// some algebraic matrix stuff
96#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
97#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix
98
99
100/** Parameter structure for least square minimsation.
101 */
102struct LSQ_params {
[8f8621]103 Vector **vectors;
[a0bcf1]104 int num;
105};
106
107double LSQ(const gsl_vector * x, void * params);
108
109/** Parameter structure for least square minimsation.
110 */
111struct lsq_params {
112 gsl_vector *x;
113 const molecule *mol;
114 element *type;
115};
116
117
118
119/** Single atom.
120 * Class incoporates position, type
121 */
122class atom {
123 public:
[8f8621]124 Vector x; //!< coordinate array of atom, giving position within cell
125 Vector v; //!< velocity array of atom
[a0bcf1]126 element *type; //!< pointing to element
127 atom *previous; //!< previous atom in molecule list
128 atom *next; //!< next atom in molecule list
129 atom *father; //!< In many-body bond order fragmentations points to originating atom
130 atom *Ancestor; //!< "Father" in Depth-First-Search
131 char *Name; //!< unique name used during many-body bond-order fragmentation
[090299]132 int FixedIon; //!< config variable that states whether forces act on the ion or not
[a0bcf1]133 int *sort; //!< sort criteria
134 int nr; //!< continuous, unique number
135 int GraphNr; //!< unique number, given in DepthFirstSearchAnalysis()
136 int *ComponentNr;//!< belongs to this nonseparable components, given in DepthFirstSearchAnalysis() (if more than one, then is SeparationVertex)
137 int LowpointNr; //!< needed in DepthFirstSearchAnalysis() to detect nonseparable components, is the lowest possible number of an atom to reach via tree edges only followed by at most one back edge.
[126934]138 bool SeparationVertex; //!< whether this atom separates off subsets of atoms or not, determined in DepthFirstSearchAnalysis()
139 bool IsCyclic; //!< whether atom belong to as cycle or not, determined in DepthFirstSearchAnalysis()
[c75363]140 unsigned char AdaptiveOrder; //!< current present bond order at site (0 means "not set")
[644ba1]141 bool MaxOrder; //!< whether this atom as a root in fragmentation still creates more fragments on higher orders or not
[e0c5b1]142
[a0bcf1]143 atom();
144 ~atom();
[e0c5b1]145
[a0bcf1]146 bool Output(int ElementNo, int AtomNo, ofstream *out) const;
147 bool OutputXYZLine(ofstream *out) const;
148 atom *GetTrueFather();
149 bool Compare(atom &ptr);
[e0c5b1]150
[a0bcf1]151 private:
152};
153
154ostream & operator << (ostream &ost, atom &a);
155
156/** Bonds between atoms.
157 * Class incorporates bonds between atoms in a molecule,
158 * used to derive tge fragments in many-body bond order
159 * calculations.
160 */
161class bond {
162 public:
163 atom *leftatom; //!< first bond partner
164 atom *rightatom; //!< second bond partner
165 bond *previous; //!< previous atom in molecule list
166 bond *next; //!< next atom in molecule list
167 int HydrogenBond; //!< Number of hydrogen atoms in the bond
168 int BondDegree; //!< single, double, triple, ... bond
169 int nr; //!< unique number in a molecule, updated by molecule::CreateAdjacencyList()
170 bool Cyclic; //!< flag whether bond is part of a cycle or not, given in DepthFirstSearchAnalysis()
[e0c5b1]171 enum EdgeType Type;//!< whether this is a tree or back edge
172
[a0bcf1]173 atom * GetOtherAtom(atom *Atom) const;
174 bond * GetFirstBond();
175 bond * GetLastBond();
[e0c5b1]176
[a0bcf1]177 bool MarkUsed(enum Shading color);
178 enum Shading IsUsed();
179 void ResetUsed();
180 bool Contains(const atom *ptr);
181 bool Contains(const int nr);
[e0c5b1]182
[a0bcf1]183 bond();
184 bond(atom *left, atom *right);
185 bond(atom *left, atom *right, int degree);
186 bond(atom *left, atom *right, int degree, int number);
187 ~bond();
[e0c5b1]188
189 private:
[a0bcf1]190 enum Shading Used; //!< marker in depth-first search, DepthFirstSearchAnalysis()
191};
192
193ostream & operator << (ostream &ost, bond &b);
194
195class MoleculeLeafClass;
196
197/** The complete molecule.
198 * Class incorporates number of types
199 */
200class molecule {
201 public:
202 double cell_size[6];//!< cell size
203 periodentafel *elemente; //!< periodic table with each element
204 atom *start; //!< start of atom list
205 atom *end; //!< end of atom list
206 bond *first; //!< start of bond list
207 bond *last; //!< end of bond list
208 bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has
[67f102]209 map<atom *, struct Trajectory> Trajectories; //!< contains old trajectory points
210 int MDSteps; //!< The number of MD steps in Trajectories
[a0bcf1]211 int *NumberOfBondsPerAtom; //!< Number of Bonds each atom has
212 int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
213 int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
214 int ElementCount; //!< how many unique elements are therein
215 int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not
216 int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
217 int NoNonBonds; //!< number of non-hydrogen bonds in molecule
218 int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
219 double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
[e0c5b1]220
[a0bcf1]221 molecule(periodentafel *teil);
222 ~molecule();
[e0c5b1]223
[a0bcf1]224 /// remove atoms from molecule.
225 bool AddAtom(atom *pointer);
226 bool RemoveAtom(atom *pointer);
227 bool CleanupMolecule();
228
229 /// Add/remove atoms to/from molecule.
230 atom * AddCopyAtom(atom *pointer);
231 bool AddXYZFile(string filename);
[e0c5b1]232 bool AddHydrogenReplacementAtom(ofstream *out, bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bond **BondList, int NumBond, bool IsAngstroem);
[a0bcf1]233 bond * AddBond(atom *first, atom *second, int degree);
234 bool RemoveBond(bond *pointer);
235 bool RemoveBonds(atom *BondPartner);
[e0c5b1]236
[a0bcf1]237 /// Find atoms.
[e0c5b1]238 atom * FindAtom(int Nr) const;
[725869]239 atom * AskAtom(string text);
[a0bcf1]240
241 /// Count and change present atoms' coordination.
242 void CountAtoms(ofstream *out);
243 void CountElements();
244 void CalculateOrbitals(class config &configuration);
[8f8621]245 bool CenterInBox(ofstream *out, Vector *BoxLengths);
[e0c5b1]246 void CenterEdge(ofstream *out, Vector *max);
247 void CenterOrigin(ofstream *out, Vector *max);
[8f8621]248 void CenterGravity(ofstream *out, Vector *max);
249 void Translate(const Vector *x);
250 void Mirror(const Vector *x);
251 void Align(Vector *n);
[a0bcf1]252 void Scale(double **factor);
[8f8621]253 void DetermineCenter(Vector &center);
254 Vector * DetermineCenterOfGravity(ofstream *out);
[d473c3]255 Vector * DetermineCenterOfAll(ofstream *out);
[8f8621]256 void SetBoxDimension(Vector *dim);
[a0bcf1]257 double * ReturnFullMatrixforSymmetric(double *cell_size);
258 void ScanForPeriodicCorrection(ofstream *out);
[32b6dc]259 void PrincipalAxisSystem(ofstream *out, bool DoRotate);
260 double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
[644ba1]261 bool VerletForceIntegration(char *file, double delta_t, bool IsAngstroem);
[e0c5b1]262
[8f8621]263 bool CheckBounds(const Vector *x) const;
[0a08df]264 void GetAlignvector(struct lsq_params * par) const;
[a0bcf1]265
[e0c5b1]266 /// Initialising routines in fragmentation
267 void CreateAdjacencyList2(ofstream *out, ifstream *output);
[5eb05a]268 void CreateAdjacencyList(ofstream *out, double bonddistance, bool IsAngstroem);
[a0bcf1]269 void CreateListOfBondsPerAtom(ofstream *out);
[e0c5b1]270
[a0bcf1]271 // Graph analysis
[5a78f5]272 MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack);
[0716ff4]273 void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
[5a78f5]274 bool PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack);
[a0bcf1]275 bond * FindNextUnused(atom *vertex);
276 void SetNextComponentNumber(atom *vertex, int nr);
277 void InitComponentNumbers();
278 void OutputComponentNumber(ofstream *out, atom *vertex);
279 void ResetAllBondsToUnused();
280 void ResetAllAtomNumbers();
281 int CountCyclicBonds(ofstream *out);
[7670cab]282 bool CheckForConnectedSubgraph(ofstream *out, KeySet *Fragment);
[725869]283 string GetColor(enum Shading color);
[a0bcf1]284
285 molecule *CopyMolecule();
[e0c5b1]286
[a0bcf1]287 /// Fragment molecule by two different approaches:
[644ba1]288 int FragmentMolecule(ofstream *out, int Order, config *configuration);
[747b10]289 bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
[c75363]290 bool StoreAdjacencyToFile(ofstream *out, char *path);
291 bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
292 bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
293 bool StoreOrderAtSiteFile(ofstream *out, char *path);
[32b6dc]294 bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
[115bf4]295 bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
296 bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
[d88597]297 bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex);
[34d37c]298 bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
[c75363]299 void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
[a0bcf1]300 /// -# BOSSANOVA
[0716ff4]301 void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
[115bf4]302 int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
[a0bcf1]303 bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
[2614f83]304 molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
[a0bcf1]305 void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
306 int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
307 int GuesstimateFragmentCount(ofstream *out, int order);
[e0c5b1]308
309 // Recognize doubly appearing molecules in a list of them
[a0bcf1]310 int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold);
311 int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule);
[e0c5b1]312
[a0bcf1]313 // Output routines.
314 bool Output(ofstream *out);
[67f102]315 bool OutputTrajectories(ofstream *out);
[169b24]316 void OutputListOfBonds(ofstream *out) const;
[a0bcf1]317 bool OutputXYZ(ofstream *out) const;
[644ba1]318 bool OutputTrajectoriesXYZ(ofstream *out);
[a0bcf1]319 bool Checkout(ofstream *out) const;
[79cd79]320 bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output);
[a0bcf1]321
322 private:
323 int last_atom; //!< number given to last atom
324};
325
326/** A list of \a molecule classes.
327 */
328class MoleculeListClass {
329 public:
330 molecule **ListOfMolecules; //!< pointer list of fragment molecules to check for equality
331 int NumberOfMolecules; //!< Number of entries in \a **FragmentList and of to be returned one.
332 int NumberOfTopAtoms; //!< Number of atoms in the molecule from which all fragments originate
[e0c5b1]333
[a0bcf1]334 MoleculeListClass();
335 MoleculeListClass(int Num, int NumAtoms);
336 ~MoleculeListClass();
337
338 /// Output configs.
[db3ea3]339 bool AddHydrogenCorrection(ofstream *out, char *path);
[115bf4]340 bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
[c75363]341 bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
[a0bcf1]342 void Output(ofstream *out);
[e0c5b1]343
[a0bcf1]344 private:
345};
346
347
348/** A leaf for a tree of \a molecule class
349 * Wraps molecules in a tree structure
350 */
351class MoleculeLeafClass {
352 public:
[e0c5b1]353 molecule *Leaf; //!< molecule of this leaf
[a0bcf1]354 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
355 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
356 MoleculeLeafClass *previous; //!< Previous leaf on this level
357 MoleculeLeafClass *next; //!< Next leaf on this level
358
359 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
360 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
361 ~MoleculeLeafClass();
362
363 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
[9c3496]364 bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
[0716ff4]365 bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
[169b24]366 bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
[5a78f5]367 bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList);
[2b79c3]368 void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
[169b24]369 int Count() const;
[a0bcf1]370};
371
372/** The config file.
373 * The class contains all parameters that control a dft run also functions to load and save.
374 */
375class config {
376 public:
377 int PsiType;
378 int MaxPsiDouble;
379 int PsiMaxNoUp;
380 int PsiMaxNoDown;
381 int MaxMinStopStep;
382 int InitMaxMinStopStep;
383 int ProcPEGamma;
384 int ProcPEPsi;
[f5306f]385 char *configpath;
[7b1cea]386 char *configname;
[2259f4]387 bool FastParsing;
[644ba1]388 double Deltat;
[e0c5b1]389
[a0bcf1]390 private:
391 char *mainname;
392 char *defaultpath;
393 char *pseudopotpath;
[e0c5b1]394
[a0bcf1]395 int DoOutVis;
396 int DoOutMes;
397 int DoOutNICS;
398 int DoOutOrbitals;
399 int DoOutCurrent;
400 int DoFullCurrent;
401 int DoPerturbation;
[4917ddd]402 int DoWannier;
[a0bcf1]403 int CommonWannier;
404 double SawtoothStart;
405 int VectorPlane;
406 double VectorCut;
407 int UseAddGramSch;
408 int Seed;
[e0c5b1]409
[a0bcf1]410 int MaxOuterStep;
411 int OutVisStep;
412 int OutSrcStep;
413 double TargetTemp;
414 int ScaleTempStep;
415 int MaxPsiStep;
416 double EpsWannier;
[e0c5b1]417
[a0bcf1]418 int MaxMinStep;
419 double RelEpsTotalEnergy;
420 double RelEpsKineticEnergy;
421 int MaxMinGapStopStep;
422 int MaxInitMinStep;
423 double InitRelEpsTotalEnergy;
424 double InitRelEpsKineticEnergy;
425 int InitMaxMinGapStopStep;
[e0c5b1]426
[a0bcf1]427 //double BoxLength[NDIM*NDIM];
[e0c5b1]428
[a0bcf1]429 double ECut;
430 int MaxLevel;
431 int RiemannTensor;
432 int LevRFactor;
433 int RiemannLevel;
434 int Lev0Factor;
435 int RTActualUse;
436 int AddPsis;
[e0c5b1]437
[a0bcf1]438 double RCut;
439 int StructOpt;
440 int IsAngstroem;
441 int RelativeCoord;
442 int MaxTypes;
443
[e0c5b1]444
[a0bcf1]445 int ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical);
[e0c5b1]446
[a0bcf1]447 public:
448 config();
449 ~config();
450
[f5306f]451 int TestSyntax(char *filename, periodentafel *periode, molecule *mol);
452 void Load(char *filename, periodentafel *periode, molecule *mol);
453 void LoadOld(char *filename, periodentafel *periode, molecule *mol);
[f75030]454 void RetrieveConfigPathAndName(string filename);
[f89a9e]455 bool Save(const char *filename, periodentafel *periode, molecule *mol) const;
456 bool SaveMPQC(const char *filename, molecule *mol) const;
[a0bcf1]457 void Edit(molecule *mol);
458 bool GetIsAngstroem() const;
459 char *GetDefaultPath() const;
[725869]460 void SetDefaultPath(const char *path);
[a0bcf1]461};
462
463#endif /*MOLECULES_HPP_*/
464
Note: See TracBrowser for help on using the repository browser.