source: src/molecules.hpp@ 1999d8

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 1999d8 was 1999d8, checked in by Frederik Heber <heber@…>, 15 years ago

BUGFIX: PointCloud implementation in molecule stopped one before last, IsLast() -> IsEnd()

  • Property mode set to 100755
File size: 13.8 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_eigen.h>
13#include <gsl/gsl_heapsort.h>
14#include <gsl/gsl_linalg.h>
15#include <gsl/gsl_matrix.h>
16#include <gsl/gsl_multimin.h>
17#include <gsl/gsl_vector.h>
18#include <gsl/gsl_randist.h>
19
20//// STL headers
21#include <map>
22#include <set>
23#include <deque>
24#include <list>
25#include <vector>
26
27#include "atom.hpp"
28#include "bond.hpp"
29#include "element.hpp"
30#include "linkedcell.hpp"
31#include "parser.hpp"
32#include "periodentafel.hpp"
33#include "stackclass.hpp"
34#include "tesselation.hpp"
35#include "vector.hpp"
36
37class molecule;
38class MoleculeLeafClass;
39class MoleculeListClass;
40
41/******************************** Some definitions for easier reading **********************************/
42
43#define KeyStack deque<int>
44#define KeySet set<int>
45#define NumberValuePair pair<int, double>
46#define Graph map <KeySet, NumberValuePair, KeyCompare >
47#define GraphPair pair <KeySet, NumberValuePair >
48#define KeySetTestPair pair<KeySet::iterator, bool>
49#define GraphTestPair pair<Graph::iterator, bool>
50
51#define MoleculeList list <molecule *>
52#define MoleculeListTest pair <MoleculeList::iterator, bool>
53
54#define DistancePair pair < double, atom* >
55#define DistanceMap multimap < double, atom* >
56#define DistanceTestPair pair < DistanceMap::iterator, bool>
57
58
59//#define LinkedAtoms list <atom *>
60
61/******************************** Some small functions and/or structures **********************************/
62
63struct KeyCompare
64{
65 bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const;
66};
67
68struct Trajectory
69{
70 vector<Vector> R; //!< position vector
71 vector<Vector> U; //!< velocity vector
72 vector<Vector> F; //!< last force vector
73 atom *ptr; //!< pointer to atom whose trajectory we contain
74};
75
76//bool operator < (KeySet SubgraphA, KeySet SubgraphB); //note: this declaration is important, otherwise normal < is used (producing wrong order)
77inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
78inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter); // Insert all KeySet's in a Graph into another Graph
79int CompareDoubles (const void * a, const void * b);
80
81
82/************************************* Class definitions ****************************************/
83
84
85// some algebraic matrix stuff
86#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
87#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix
88
89
90/** Parameter structure for least square minimsation.
91 */
92struct LSQ_params {
93 Vector **vectors;
94 int num;
95};
96
97double LSQ(const gsl_vector * x, void * params);
98
99/** Parameter structure for least square minimsation.
100 */
101struct lsq_params {
102 gsl_vector *x;
103 const molecule *mol;
104 element *type;
105};
106
107#define MaxThermostats 6 //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
108enum thermostats { None, Woodcock, Gaussian, Langevin, Berendsen, NoseHoover }; //!< Thermostat names for output
109
110
111/** The complete molecule.
112 * Class incorporates number of types
113 */
114class molecule : public PointCloud {
115 public:
116 double cell_size[6];//!< cell size
117 periodentafel *elemente; //!< periodic table with each element
118 atom *start; //!< start of atom list
119 atom *end; //!< end of atom list
120 bond *first; //!< start of bond list
121 bond *last; //!< end of bond list
122 bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has
123 map<atom *, struct Trajectory> Trajectories; //!< contains old trajectory points
124 int MDSteps; //!< The number of MD steps in Trajectories
125 int *NumberOfBondsPerAtom; //!< Number of Bonds each atom has
126 int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
127 int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
128 int ElementCount; //!< how many unique elements are therein
129 int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not
130 int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
131 int NoNonBonds; //!< number of non-hydrogen bonds in molecule
132 int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
133 double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
134 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
135 Vector Center; //!< Center of molecule in a global box
136 char name[MAXSTRINGSIZE]; //!< arbitrary name
137 int IndexNr; //!< index of molecule in a MoleculeListClass
138 class Tesselation *TesselStruct;
139
140 molecule(periodentafel *teil);
141 virtual ~molecule();
142
143 // re-definition of virtual functions from PointCloud
144 Vector *GetCenter(ofstream *out);
145 TesselPoint *GetPoint();
146 TesselPoint *GetTerminalPoint();
147 void GoToNext();
148 void GoToPrevious();
149 void GoToFirst();
150 void GoToLast();
151 bool IsEmpty();
152 bool IsEnd();
153
154 /// remove atoms from molecule.
155 bool AddAtom(atom *pointer);
156 bool RemoveAtom(atom *pointer);
157 bool UnlinkAtom(atom *pointer);
158 bool CleanupMolecule();
159
160 /// Add/remove atoms to/from molecule.
161 atom * AddCopyAtom(atom *pointer);
162 bool AddXYZFile(string filename);
163 bool AddHydrogenReplacementAtom(ofstream *out, bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bond **BondList, int NumBond, bool IsAngstroem);
164 bond * AddBond(atom *first, atom *second, int degree);
165 bool RemoveBond(bond *pointer);
166 bool RemoveBonds(atom *BondPartner);
167
168 /// Find atoms.
169 atom * FindAtom(int Nr) const;
170 atom * AskAtom(string text);
171
172 /// Count and change present atoms' coordination.
173 void CountAtoms(ofstream *out);
174 void CountElements();
175 void CalculateOrbitals(class config &configuration);
176 bool CenterInBox(ofstream *out);
177 bool BoundInBox(ofstream *out);
178 void CenterEdge(ofstream *out, Vector *max);
179 void CenterOrigin(ofstream *out);
180 void CenterPeriodic(ofstream *out);
181 void CenterAtVector(ofstream *out, Vector *newcenter);
182 void Translate(const Vector *x);
183 void TranslatePeriodically(const Vector *trans);
184 void Mirror(const Vector *x);
185 void Align(Vector *n);
186 void Scale(double **factor);
187 void DeterminePeriodicCenter(Vector &center);
188 Vector * DetermineCenterOfGravity(ofstream *out);
189 Vector * DetermineCenterOfAll(ofstream *out);
190 void SetNameFromFilename(const char *filename);
191 void SetBoxDimension(Vector *dim);
192 double * ReturnFullMatrixforSymmetric(double *cell_size);
193 void ScanForPeriodicCorrection(ofstream *out);
194 bool VerletForceIntegration(ofstream *out, char *file, config &configuration);
195 void Thermostats(config &configuration, double ActualTemp, int Thermostat);
196 void PrincipalAxisSystem(ofstream *out, bool DoRotate);
197 double VolumeOfConvexEnvelope(ofstream *out, bool IsAngstroem);
198 Vector* FindEmbeddingHole(ofstream *out, molecule *srcmol);
199
200
201 double ConstrainedPotential(ofstream *out, atom **permutation, int start, int end, double *constants, bool IsAngstroem);
202 double MinimiseConstrainedPotential(ofstream *out, atom **&permutation, int startstep, int endstep, bool IsAngstroem);
203 void EvaluateConstrainedForces(ofstream *out, int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force);
204 bool LinearInterpolationBetweenConfiguration(ofstream *out, int startstep, int endstep, const char *prefix, config &configuration);
205
206 bool CheckBounds(const Vector *x) const;
207 void GetAlignvector(struct lsq_params * par) const;
208
209 /// Initialising routines in fragmentation
210 void CreateAdjacencyList2(ofstream *out, ifstream *output);
211 void CreateAdjacencyList(ofstream *out, double bonddistance, bool IsAngstroem);
212 void CreateListOfBondsPerAtom(ofstream *out);
213
214 // Graph analysis
215 MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, class StackClass<bond *> *&BackEdgeStack);
216 void CyclicStructureAnalysis(ofstream *out, class StackClass<bond *> *BackEdgeStack, int *&MinimumRingSize);
217 bool PickLocalBackEdges(ofstream *out, atom **ListOfLocalAtoms, class StackClass<bond *> *&ReferenceStack, class StackClass<bond *> *&LocalStack);
218 bond * FindNextUnused(atom *vertex);
219 void SetNextComponentNumber(atom *vertex, int nr);
220 void InitComponentNumbers();
221 void OutputComponentNumber(ofstream *out, atom *vertex);
222 void ResetAllBondsToUnused();
223 void ResetAllAtomNumbers();
224 int CountCyclicBonds(ofstream *out);
225 bool CheckForConnectedSubgraph(ofstream *out, KeySet *Fragment);
226 string GetColor(enum Shading color);
227
228 molecule *CopyMolecule();
229
230 /// Fragment molecule by two different approaches:
231 int FragmentMolecule(ofstream *out, int Order, config *configuration);
232 bool CheckOrderAtSite(ofstream *out, bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
233 bool StoreAdjacencyToFile(ofstream *out, char *path);
234 bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms);
235 bool ParseOrderAtSiteFromFile(ofstream *out, char *path);
236 bool StoreOrderAtSiteFile(ofstream *out, char *path);
237 bool ParseKeySetFile(ofstream *out, char *filename, Graph *&FragmentList);
238 bool StoreKeySetFile(ofstream *out, Graph &KeySetList, char *path);
239 bool StoreForcesFile(ofstream *out, MoleculeListClass *BondFragments, char *path, int *SortIndex);
240 bool CreateMappingLabelsToConfigSequence(ofstream *out, int *&SortIndex);
241 bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet);
242 void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
243 /// -# BOSSANOVA
244 void FragmentBOSSANOVA(ofstream *out, Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
245 int PowerSetGenerator(ofstream *out, int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
246 bool BuildInducedSubgraph(ofstream *out, const molecule *Father);
247 molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem);
248 void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
249 int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList);
250 int GuesstimateFragmentCount(ofstream *out, int order);
251
252 // Recognize doubly appearing molecules in a list of them
253 int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold);
254 int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule);
255
256 // Output routines.
257 bool Output(ofstream *out);
258 bool OutputTrajectories(ofstream *out);
259 void OutputListOfBonds(ofstream *out) const;
260 bool OutputXYZ(ofstream *out) const;
261 bool OutputTrajectoriesXYZ(ofstream *out);
262 bool Checkout(ofstream *out) const;
263 bool OutputTemperatureFromTrajectories(ofstream *out, int startstep, int endstep, ofstream *output);
264
265 private:
266 int last_atom; //!< number given to last atom
267 atom *InternalPointer; //!< internal pointer for PointCloud
268};
269
270/** A list of \a molecule classes.
271 */
272class MoleculeListClass {
273 public:
274 MoleculeList ListOfMolecules; //!< List of the contained molecules
275 int MaxIndex;
276
277 MoleculeListClass();
278 ~MoleculeListClass();
279
280 bool AddHydrogenCorrection(ofstream *out, char *path);
281 bool StoreForcesFile(ofstream *out, char *path, int *SortIndex);
282 void insert(molecule *mol);
283 molecule * ReturnIndex(int index);
284 bool OutputConfigForListOfFragments(ofstream *out, config *configuration, int *SortIndex);
285 int NumberOfActiveMolecules();
286 void Enumerate(ofstream *out);
287 void Output(ofstream *out);
288
289 // merging of molecules
290 bool SimpleMerge(molecule *mol, molecule *srcmol);
291 bool SimpleAdd(molecule *mol, molecule *srcmol);
292 bool SimpleMultiMerge(molecule *mol, int *src, int N);
293 bool SimpleMultiAdd(molecule *mol, int *src, int N);
294 bool ScatterMerge(molecule *mol, int *src, int N);
295 bool EmbedMerge(molecule *mol, molecule *srcmol);
296
297 private:
298};
299
300
301/** A leaf for a tree of \a molecule class
302 * Wraps molecules in a tree structure
303 */
304class MoleculeLeafClass {
305 public:
306 molecule *Leaf; //!< molecule of this leaf
307 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
308 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
309 MoleculeLeafClass *previous; //!< Previous leaf on this level
310 MoleculeLeafClass *next; //!< Next leaf on this level
311
312 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
313 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
314 ~MoleculeLeafClass();
315
316 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
317 bool FillBondStructureFromReference(ofstream *out, molecule *reference, int &FragmentCounter, atom ***&ListOfLocalAtoms, bool FreeList = false);
318 bool FillRootStackForSubgraphs(ofstream *out, KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
319 bool AssignKeySetsToFragment(ofstream *out, molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
320 bool FillListOfLocalAtoms(ofstream *out, atom ***&ListOfLocalAtoms, const int FragmentCounter, const int GlobalAtomCount, bool &FreeList);
321 void TranslateIndicesToGlobalIDs(ofstream *out, Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
322 int Count() const;
323};
324
325class ConfigFileBuffer {
326 public:
327 char **buffer;
328 int *LineMapping;
329 int CurrentLine;
330 int NoLines;
331
332 ConfigFileBuffer();
333 ConfigFileBuffer(char *filename);
334 ~ConfigFileBuffer();
335
336 void InitMapping();
337 void MapIonTypesInBuffer(int NoAtoms);
338};
339
340
341#endif /*MOLECULES_HPP_*/
342
Note: See TracBrowser for help on using the repository browser.