source: src/molecules.hpp@ cdee6b

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since cdee6b was 49de64, checked in by Frederik Heber <heber@…>, 17 years ago

VolumeOfConvexEnvelope() finished and tested with SiOH4, 1_2_dimethoxyethane and CSHCluster (Ratio1-1)

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