source: src/molecules.hpp@ 5e0d1f

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 5e0d1f was 5e0d1f, checked in by Frederik Heber <heber@…>, 16 years ago

config::Save() and config::Load() parse MD steps into and out of molecule::Trajectories. Tested.

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