source: src/molecules.hpp@ 68cb0f

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 68cb0f was 68cb0f, checked in by Frederik Heber <heber@…>, 17 years ago

introduced shieldings to analyzer and joiner

both now handle pcp.sigma_all...csv files just as pcp.forces.all. Therefore the data format in pcp/perturbed.c was adapted a bit, as we need a header.
periodentafel.hpp got periodentafel and element class from molecules.hpp

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