source: src/molecules.hpp@ 1f066fe

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 1f066fe was 110ceb, checked in by Frederik Heber <heber@…>, 17 years ago

VolumeOfConvexEnvelope: Works!

VolumeOfConvexEnvelope has been analysed into various smaller functions and approach is working.
two new files: boundary.?pp
various new functions:
class Tesselation with AddPoint(), TesselateOnBoundary() and GuessStartingTriangle() does the actual tesselation
CreateClustersinWater() will create the repetition of the cluster with correct spacing (unfinished).
GetDiametersOfCluster() calculate the greatest diameter in projection per axis
GetBoundaryPoints() gets the boundary on the convex envelope by projection for a molecular cluster
GetCommonEndpoint() finds the endpoint two lines are sharing

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