source: src/analysis_correlation.cpp@ e138de

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

Huge change from ofstream * (const) out --> Log().

  • first shift was done via regular expressions
  • then via error messages from the code
  • note that class atom, class element and class molecule kept in parts their output stream, was they print to file.
  • make check runs fine
  • MISSING: Verbosity is not fixed for everything (i.e. if no endl; is present and next has Verbose(0) ...)

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 17.9 KB
Line 
1/*
2 * analysis.cpp
3 *
4 * Created on: Oct 13, 2009
5 * Author: heber
6 */
7
8#include <iostream>
9
10#include "analysis_correlation.hpp"
11#include "element.hpp"
12#include "log.hpp"
13#include "molecule.hpp"
14#include "tesselation.hpp"
15#include "tesselationhelpers.hpp"
16#include "vector.hpp"
17#include "verbose.hpp"
18
19
20/** Calculates the pair correlation between given elements.
21 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
22 * \param *out output stream for debugging
23 * \param *molecules list of molecules structure
24 * \param *type1 first element or NULL (if any element)
25 * \param *type2 second element or NULL (if any element)
26 * \return Map of doubles with values the pair of the two atoms.
27 */
28PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 )
29{
30 PairCorrelationMap *outmap = NULL;
31 double distance = 0.;
32
33 if (molecules->ListOfMolecules.empty()) {
34 eLog() << Verbose(1) <<"No molecule given." << endl;
35 return outmap;
36 }
37 outmap = new PairCorrelationMap;
38 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
39 if ((*MolWalker)->ActiveFlag) {
40 eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
41 atom *Walker = (*MolWalker)->start;
42 while (Walker->next != (*MolWalker)->end) {
43 Walker = Walker->next;
44 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
45 if ((type1 == NULL) || (Walker->type == type1)) {
46 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
47 if ((*MolOtherWalker)->ActiveFlag) {
48 Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;
49 atom *OtherWalker = (*MolOtherWalker)->start;
50 while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
51 OtherWalker = OtherWalker->next;
52 Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
53 if (Walker->nr < OtherWalker->nr)
54 if ((type2 == NULL) || (OtherWalker->type == type2)) {
55 distance = Walker->node->PeriodicDistance(OtherWalker->node, (*MolWalker)->cell_size);
56 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
57 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
58 }
59 }
60 }
61 }
62 }
63 }
64
65 return outmap;
66};
67
68/** Calculates the pair correlation between given elements.
69 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
70 * \param *out output stream for debugging
71 * \param *molecules list of molecules structure
72 * \param *type1 first element or NULL (if any element)
73 * \param *type2 second element or NULL (if any element)
74 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
75 * \return Map of doubles with values the pair of the two atoms.
76 */
77PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
78{
79 PairCorrelationMap *outmap = NULL;
80 double distance = 0.;
81 int n[NDIM];
82 Vector checkX;
83 Vector periodicX;
84 int Othern[NDIM];
85 Vector checkOtherX;
86 Vector periodicOtherX;
87
88 if (molecules->ListOfMolecules.empty()) {
89 eLog() << Verbose(1) <<"No molecule given." << endl;
90 return outmap;
91 }
92 outmap = new PairCorrelationMap;
93 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
94 if ((*MolWalker)->ActiveFlag) {
95 const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
96 const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
97 eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
98 atom *Walker = (*MolWalker)->start;
99 while (Walker->next != (*MolWalker)->end) {
100 Walker = Walker->next;
101 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
102 if ((type1 == NULL) || (Walker->type == type1)) {
103 periodicX.CopyVector(Walker->node);
104 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
105 // go through every range in xyz and get distance
106 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
107 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
108 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
109 checkX.Init(n[0], n[1], n[2]);
110 checkX.AddVector(&periodicX);
111 checkX.MatrixMultiplication(FullMatrix);
112 for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
113 if ((*MolOtherWalker)->ActiveFlag) {
114 Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;
115 atom *OtherWalker = (*MolOtherWalker)->start;
116 while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
117 OtherWalker = OtherWalker->next;
118 Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
119 if (Walker->nr < OtherWalker->nr)
120 if ((type2 == NULL) || (OtherWalker->type == type2)) {
121 periodicOtherX.CopyVector(OtherWalker->node);
122 periodicOtherX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
123 // go through every range in xyz and get distance
124 for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
125 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
126 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
127 checkOtherX.Init(Othern[0], Othern[1], Othern[2]);
128 checkOtherX.AddVector(&periodicOtherX);
129 checkOtherX.MatrixMultiplication(FullMatrix);
130 distance = checkX.Distance(&checkOtherX);
131 //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
132 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
133 }
134 }
135 }
136 }
137 }
138 }
139 }
140 }
141
142 return outmap;
143};
144
145/** Calculates the distance (pair) correlation between a given element and a point.
146 * \param *out output stream for debugging
147 * \param *molecules list of molecules structure
148 * \param *type element or NULL (if any element)
149 * \param *point vector to the correlation point
150 * \return Map of dobules with values as pairs of atom and the vector
151 */
152CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point )
153{
154 CorrelationToPointMap *outmap = NULL;
155 double distance = 0.;
156
157 if (molecules->ListOfMolecules.empty()) {
158 Log() << Verbose(1) <<"No molecule given." << endl;
159 return outmap;
160 }
161 outmap = new CorrelationToPointMap;
162 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
163 if ((*MolWalker)->ActiveFlag) {
164 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
165 atom *Walker = (*MolWalker)->start;
166 while (Walker->next != (*MolWalker)->end) {
167 Walker = Walker->next;
168 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
169 if ((type == NULL) || (Walker->type == type)) {
170 distance = Walker->node->PeriodicDistance(point, (*MolWalker)->cell_size);
171 Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
172 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
173 }
174 }
175 }
176
177 return outmap;
178};
179
180/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
181 * \param *out output stream for debugging
182 * \param *molecules list of molecules structure
183 * \param *type element or NULL (if any element)
184 * \param *point vector to the correlation point
185 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
186 * \return Map of dobules with values as pairs of atom and the vector
187 */
188CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
189{
190 CorrelationToPointMap *outmap = NULL;
191 double distance = 0.;
192 int n[NDIM];
193 Vector periodicX;
194 Vector checkX;
195
196 if (molecules->ListOfMolecules.empty()) {
197 Log() << Verbose(1) <<"No molecule given." << endl;
198 return outmap;
199 }
200 outmap = new CorrelationToPointMap;
201 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
202 if ((*MolWalker)->ActiveFlag) {
203 const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
204 const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
205 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
206 atom *Walker = (*MolWalker)->start;
207 while (Walker->next != (*MolWalker)->end) {
208 Walker = Walker->next;
209 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
210 if ((type == NULL) || (Walker->type == type)) {
211 periodicX.CopyVector(Walker->node);
212 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
213 // go through every range in xyz and get distance
214 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
215 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
216 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
217 checkX.Init(n[0], n[1], n[2]);
218 checkX.AddVector(&periodicX);
219 checkX.MatrixMultiplication(FullMatrix);
220 distance = checkX.Distance(point);
221 Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
222 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
223 }
224 }
225 }
226 }
227
228 return outmap;
229};
230
231/** Calculates the distance (pair) correlation between a given element and a surface.
232 * \param *out output stream for debugging
233 * \param *molecules list of molecules structure
234 * \param *type element or NULL (if any element)
235 * \param *Surface pointer to Tesselation class surface
236 * \param *LC LinkedCell structure to quickly find neighbouring atoms
237 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
238 */
239CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC )
240{
241 CorrelationToSurfaceMap *outmap = NULL;
242 double distance = 0;
243 class BoundaryTriangleSet *triangle = NULL;
244 Vector centroid;
245
246 if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
247 Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
248 return outmap;
249 }
250 outmap = new CorrelationToSurfaceMap;
251 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
252 if ((*MolWalker)->ActiveFlag) {
253 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
254 atom *Walker = (*MolWalker)->start;
255 while (Walker->next != (*MolWalker)->end) {
256 Walker = Walker->next;
257 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
258 if ((type == NULL) || (Walker->type == type)) {
259 triangle = Surface->FindClosestTriangleToPoint(Walker->node, LC );
260 if (triangle != NULL) {
261 distance = DistanceToTrianglePlane(Walker->node, triangle);
262 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
263 }
264 }
265 }
266 }
267
268 return outmap;
269};
270
271/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
272 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
273 * I.e. We multiply the atom::node with the inverse of the domain matrix, i.e. transform it to \f$[0,0^3\f$, then add per
274 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
275 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
276 * \param *out output stream for debugging
277 * \param *molecules list of molecules structure
278 * \param *type element or NULL (if any element)
279 * \param *Surface pointer to Tesselation class surface
280 * \param *LC LinkedCell structure to quickly find neighbouring atoms
281 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
282 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
283 */
284CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
285{
286 CorrelationToSurfaceMap *outmap = NULL;
287 double distance = 0;
288 class BoundaryTriangleSet *triangle = NULL;
289 Vector centroid;
290 int n[NDIM];
291 Vector periodicX;
292 Vector checkX;
293
294 if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
295 Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
296 return outmap;
297 }
298 outmap = new CorrelationToSurfaceMap;
299 for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
300 if ((*MolWalker)->ActiveFlag) {
301 const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
302 const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
303 Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
304 atom *Walker = (*MolWalker)->start;
305 while (Walker->next != (*MolWalker)->end) {
306 Walker = Walker->next;
307 Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
308 if ((type == NULL) || (Walker->type == type)) {
309 periodicX.CopyVector(Walker->node);
310 periodicX.MatrixMultiplication(FullInverseMatrix); // x now in [0,1)^3
311 // go through every range in xyz and get distance
312 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
313 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
314 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
315 checkX.Init(n[0], n[1], n[2]);
316 checkX.AddVector(&periodicX);
317 checkX.MatrixMultiplication(FullMatrix);
318 triangle = Surface->FindClosestTriangleToPoint(&checkX, LC );
319 if (triangle != NULL) {
320 distance = DistanceToTrianglePlane(&checkX, triangle);
321 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
322 }
323 }
324 }
325 }
326 }
327
328 return outmap;
329};
330
331/** Returns the start of the bin for a given value.
332 * \param value value whose bin to look for
333 * \param BinWidth width of bin
334 * \param BinStart first bin
335 */
336double GetBin ( const double value, const double BinWidth, const double BinStart )
337{
338 double bin =(double) (floor((value - BinStart)/BinWidth));
339 return (bin*BinWidth+BinStart);
340};
341
342
343/** Prints correlation (double, int) pairs to file.
344 * \param *file file to write to
345 * \param *map map to write
346 */
347void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
348{
349 *file << "# BinStart\tCount" << endl;
350 for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
351 *file << runner->first << "\t" << runner->second << endl;
352 }
353};
354
355/** Prints correlation (double, (atom*,atom*) ) pairs to file.
356 * \param *file file to write to
357 * \param *map map to write
358 */
359void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
360{
361 *file << "# BinStart\tAtom1\tAtom2" << endl;
362 for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
363 *file << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
364 }
365};
366
367/** Prints correlation (double, int) pairs to file.
368 * \param *file file to write to
369 * \param *map map to write
370 */
371void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
372{
373 *file << "# BinStart\tAtom::x[i]-point.x[i]" << endl;
374 for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
375 *file << runner->first;
376 for (int i=0;i<NDIM;i++)
377 *file << "\t" << (runner->second.first->node->x[i] - runner->second.second->x[i]);
378 *file << endl;
379 }
380};
381
382/** Prints correlation (double, int) pairs to file.
383 * \param *file file to write to
384 * \param *map map to write
385 */
386void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
387{
388 *file << "# BinStart\tTriangle" << endl;
389 for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
390 *file << runner->first << "\t" << *(runner->second.second) << endl;
391 }
392};
393
Note: See TracBrowser for help on using the repository browser.