source: src/analysis_correlation.cpp@ 24725c

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 24725c was 24725c, checked in by Tillmann Crueger <crueger@…>, 15 years ago

FIX: repaired PairCorrelation() by using IDs assigned by the world instead of internal molecule numbers

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