source: src/Analysis/analysis_correlation.cpp@ 0a7fad

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 Candidate_v1.7.0 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 0a7fad was 0a7fad, checked in by Frederik Heber <heber@…>, 14 years ago

Refactored part of code in DipoleAngularCorrelation into new method CalculateZeroAngularDipole().

  • Property mode set to 100644
File size: 31.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * analysis.cpp
10 *
11 * Created on: Oct 13, 2009
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <iostream>
23#include <iomanip>
24
25#include "atom.hpp"
26#include "Bond/bond.hpp"
27#include "Tesselation/BoundaryTriangleSet.hpp"
28#include "Box.hpp"
29#include "Element/element.hpp"
30#include "CodePatterns/Info.hpp"
31#include "CodePatterns/Log.hpp"
32#include "CodePatterns/Verbose.hpp"
33#include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
34#include "Formula.hpp"
35#include "LinearAlgebra/Vector.hpp"
36#include "LinearAlgebra/RealSpaceMatrix.hpp"
37#include "molecule.hpp"
38#include "Tesselation/tesselation.hpp"
39#include "Tesselation/tesselationhelpers.hpp"
40#include "Tesselation/triangleintersectionlist.hpp"
41#include "World.hpp"
42#include "WorldTime.hpp"
43
44#include "analysis_correlation.hpp"
45
46/** Calculates the dipole vector of a given atomSet.
47 *
48 * Note that we use the following procedure as rule of thumb:
49 * -# go through every bond of the atom
50 * -# calculate the difference of electronegativities \f$\Delta\mathrm{EN}\f$
51 * -# if \f$\Delta\mathrm{EN} > 0.5\f$, we align the bond vector in direction of the more negative element
52 * -# sum up all vectors
53 * -# finally, divide by the number of summed vectors
54 *
55 * @param atomsbegin begin iterator of atomSet
56 * @param atomsend end iterator of atomset
57 * @return dipole vector
58 */
59Vector getDipole(molecule::const_iterator atomsbegin, molecule::const_iterator atomsend)
60{
61 Vector DipoleVector;
62 size_t SumOfVectors = 0;
63 // go through all atoms
64 for (molecule::const_iterator atomiter = atomsbegin;
65 atomiter != atomsend;
66 ++atomiter) {
67 // go through all bonds
68 const BondList& ListOfBonds = (*atomiter)->getListOfBonds();
69 ASSERT(ListOfBonds.begin() != ListOfBonds.end(),
70 "getDipole() - no bonds in molecule!");
71 for (BondList::const_iterator bonditer = ListOfBonds.begin();
72 bonditer != ListOfBonds.end();
73 ++bonditer) {
74 const atom * Otheratom = (*bonditer)->GetOtherAtom(*atomiter);
75 if (Otheratom->getId() > (*atomiter)->getId()) {
76 const double DeltaEN = (*atomiter)->getType()->getElectronegativity()
77 -Otheratom->getType()->getElectronegativity();
78 Vector BondDipoleVector = (*atomiter)->getPosition() - Otheratom->getPosition();
79 // DeltaEN is always positive, gives correct orientation of vector
80 BondDipoleVector.Normalize();
81 BondDipoleVector *= DeltaEN;
82 LOG(3,"INFO: Dipole vector from bond " << **bonditer << " is " << BondDipoleVector);
83 DipoleVector += BondDipoleVector;
84 SumOfVectors++;
85 }
86 }
87 }
88 LOG(3,"INFO: Sum over all bond dipole vectors is "
89 << DipoleVector << " with " << SumOfVectors << " in total.");
90 if (SumOfVectors != 0)
91 DipoleVector *= 1./(double)SumOfVectors;
92 DoLog(1) && (Log() << Verbose(1) << "Resulting dipole vector is " << DipoleVector << std::endl);
93
94 return DipoleVector;
95};
96
97/** Calculate minimum and maximum amount of trajectory steps by going through given atomic trajectories.
98 * \param vector of atoms whose trajectories to check for [min,max]
99 * \return range with [min, max]
100 */
101range<size_t> getMaximumTrajectoryBounds(std::vector<atom *> &atoms)
102{
103 // get highest trajectory size
104 LOG(0,"STATUS: Retrieving maximum amount of time steps ...");
105 size_t max_timesteps = 0;
106 size_t min_timesteps = -1;
107 BOOST_FOREACH(atom *_atom, atoms) {
108 if (_atom->getTrajectorySize() > max_timesteps)
109 max_timesteps = _atom->getTrajectorySize();
110 if ((_atom->getTrajectorySize() <= max_timesteps) && (min_timesteps == (size_t)-1))
111 min_timesteps = _atom->getTrajectorySize();
112 }
113 LOG(1,"INFO: Minimum number of time steps found is " << min_timesteps);
114 LOG(1,"INFO: Maximum number of time steps found is " << max_timesteps);
115
116 return range<size_t>(min_timesteps, max_timesteps);
117}
118
119/** Calculates the angular dipole zero orientation from current time step.
120 * \param atoms vector of atoms to calculate it for
121 * \return map with orientation vector for each atomic id given in \a atoms.
122 */
123std::map<atomId_t, Vector> CalculateZeroAngularDipole(std::vector<atom *> &atoms)
124{
125 // calculate molecules for this time step
126 std::set<molecule *> molecules;
127 BOOST_FOREACH(atom *_atom, atoms)
128 molecules.insert(_atom->getMolecule());
129
130 // get zero orientation for each molecule.
131 LOG(0,"STATUS: Calculating dipoles for first time step ...");
132 std::map<atomId_t, Vector> ZeroVector;
133 BOOST_FOREACH(molecule *_mol, molecules) {
134 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
135 for(molecule::const_iterator iter = _mol->begin(); iter != _mol->end(); ++iter)
136 ZeroVector[(*iter)->getId()] = Dipole;
137 LOG(2,"INFO: Zero alignment for molecule " << _mol->getId() << " is " << Dipole);
138 }
139 LOG(1,"INFO: We calculated zero orientation for a total of " << molecules.size() << " molecule(s).");
140
141 return ZeroVector;
142}
143
144/** Calculates the dipole angular correlation for given molecule type.
145 * Calculate the change of the dipole orientation angle over time.
146 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
147 * Angles are given in degrees.
148 * \param &atoms list of atoms of the molecules taking part (Note: molecules may
149 * change over time as bond structure is recalculated, hence we need the atoms)
150 * \return Map of doubles with values the pair of the two atoms.
151 */
152DipoleAngularCorrelationMap *DipoleAngularCorrelation(std::vector<atom *> &atoms)
153{
154 Info FunctionInfo(__func__);
155 DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
156
157 // store original time step
158 const unsigned int oldtime = WorldTime::getTime();
159 World::getInstance().setTime(0);
160
161 // calculate molecules for this time step
162 std::set<molecule *> molecules;
163 BOOST_FOREACH(atom *_atom, atoms)
164 molecules.insert(_atom->getMolecule());
165
166 BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms())
167 LOG(2, "INFO: Atom " << _atom->getId() << " "
168 << *dynamic_cast<AtomInfo *>(_atom) <<".");
169
170
171 // get zero orientation for each molecule.
172 std::map<atomId_t, Vector> ZeroVector = CalculateZeroAngularDipole(atoms);
173
174 // go through every time step
175 LOG(0,"STATUS: Calculating dipoles of following time steps ...");
176 range<size_t> timesteps = getMaximumTrajectoryBounds(atoms);
177 for (size_t step = 1; step < timesteps.first; ++step) {
178 World::getInstance().setTime(step);
179 // recalculate molecules for this time step
180 molecules.clear();
181 BOOST_FOREACH(atom *_atom, atoms)
182 molecules.insert(_atom->getMolecule());
183 size_t i=0;
184 BOOST_FOREACH(molecule *_mol, molecules) {
185 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
186 LOG(2,"INFO: Dipole vector at time step " << step << " for for molecule " << _mol->getId() << " is " << Dipole);
187 molecule::const_iterator iter = _mol->begin();
188 ASSERT(ZeroVector.count((*iter)->getId()),
189 "DipoleAngularCorrelation() - ZeroVector for atom "+toString(**iter)+" not present.");
190 const double angle = Dipole.Angle(ZeroVector[(*iter)->getId()]) * (180./M_PI);
191 LOG(1,"INFO: Resulting relative angle for molecule " << **iter << " is " << angle << ".");
192 outmap->insert ( make_pair (angle, *iter ) );
193 ++i;
194 }
195 }
196
197
198 // set original time step again
199 World::getInstance().setTime(oldtime);
200 LOG(0,"STATUS: Done.");
201
202 // and return results
203 return outmap;
204};
205
206/** Calculates the dipole correlation for given molecule type.
207 * I.e. we calculate how the angle between any two given dipoles in the
208 * systems behaves. Sort of pair correlation but distance is replaced by
209 * the orientation distance, i.e. an angle.
210 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
211 * Angles are given in degrees.
212 * \param *molecules vector of molecules
213 * \return Map of doubles with values the pair of the two atoms.
214 */
215DipoleCorrelationMap *DipoleCorrelation(std::vector<molecule *> &molecules)
216{
217 Info FunctionInfo(__func__);
218 DipoleCorrelationMap *outmap = new DipoleCorrelationMap;
219// double distance = 0.;
220// Box &domain = World::getInstance().getDomain();
221//
222 if (molecules.empty()) {
223 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
224 return outmap;
225 }
226
227 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
228 MolWalker != molecules.end(); ++MolWalker) {
229 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is "
230 << (*MolWalker)->getId() << "." << endl);
231 const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
232 std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
233 for (++MolOtherWalker;
234 MolOtherWalker != molecules.end();
235 ++MolOtherWalker) {
236 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is "
237 << (*MolOtherWalker)->getId() << "." << endl);
238 const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
239 const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
240 DoLog(1) && (Log() << Verbose(1) << "Angle is " << angle << "." << endl);
241 outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
242 }
243 }
244 return outmap;
245};
246
247
248/** Calculates the pair correlation between given elements.
249 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
250 * \param *molecules vector of molecules
251 * \param &elements vector of elements to correlate
252 * \return Map of doubles with values the pair of the two atoms.
253 */
254PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
255{
256 Info FunctionInfo(__func__);
257 PairCorrelationMap *outmap = new PairCorrelationMap;
258 double distance = 0.;
259 Box &domain = World::getInstance().getDomain();
260
261 if (molecules.empty()) {
262 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
263 return outmap;
264 }
265 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
266 (*MolWalker)->doCountAtoms();
267
268 // create all possible pairs of elements
269 set <pair<const element *,const element *> > PairsOfElements;
270 if (elements.size() >= 2) {
271 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
272 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
273 if (type1 != type2) {
274 PairsOfElements.insert( make_pair(*type1,*type2) );
275 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
276 }
277 } else if (elements.size() == 1) { // one to all are valid
278 const element *elemental = *elements.begin();
279 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
280 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
281 } else { // all elements valid
282 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
283 }
284
285 outmap = new PairCorrelationMap;
286 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
287 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
288 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
289 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
290 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
291 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
292 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
293 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
294 if ((*iter)->getId() < (*runner)->getId()){
295 for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
296 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
297 distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
298 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
299 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
300 }
301 }
302 }
303 }
304 }
305 }
306 return outmap;
307};
308
309/** Calculates the pair correlation between given elements.
310 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
311 * \param *molecules list of molecules structure
312 * \param &elements vector of elements to correlate
313 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
314 * \return Map of doubles with values the pair of the two atoms.
315 */
316PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
317{
318 Info FunctionInfo(__func__);
319 PairCorrelationMap *outmap = new PairCorrelationMap;
320 double distance = 0.;
321 int n[NDIM];
322 Vector checkX;
323 Vector periodicX;
324 int Othern[NDIM];
325 Vector checkOtherX;
326 Vector periodicOtherX;
327
328 if (molecules.empty()) {
329 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
330 return outmap;
331 }
332 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
333 (*MolWalker)->doCountAtoms();
334
335 // create all possible pairs of elements
336 set <pair<const element *,const element *> > PairsOfElements;
337 if (elements.size() >= 2) {
338 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
339 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
340 if (type1 != type2) {
341 PairsOfElements.insert( make_pair(*type1,*type2) );
342 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
343 }
344 } else if (elements.size() == 1) { // one to all are valid
345 const element *elemental = *elements.begin();
346 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
347 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
348 } else { // all elements valid
349 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
350 }
351
352 outmap = new PairCorrelationMap;
353 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
354 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
355 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
356 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
357 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
358 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
359 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
360 // go through every range in xyz and get distance
361 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
362 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
363 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
364 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
365 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
366 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
367 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
368 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
369 if ((*iter)->getId() < (*runner)->getId()){
370 for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
371 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
372 periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
373 // go through every range in xyz and get distance
374 for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
375 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
376 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
377 checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
378 distance = checkX.distance(checkOtherX);
379 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
380 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
381 }
382 }
383 }
384 }
385 }
386 }
387 }
388 }
389
390 return outmap;
391};
392
393/** Calculates the distance (pair) correlation between a given element and a point.
394 * \param *molecules list of molecules structure
395 * \param &elements vector of elements to correlate with point
396 * \param *point vector to the correlation point
397 * \return Map of dobules with values as pairs of atom and the vector
398 */
399CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
400{
401 Info FunctionInfo(__func__);
402 CorrelationToPointMap *outmap = new CorrelationToPointMap;
403 double distance = 0.;
404 Box &domain = World::getInstance().getDomain();
405
406 if (molecules.empty()) {
407 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
408 return outmap;
409 }
410 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
411 (*MolWalker)->doCountAtoms();
412 outmap = new CorrelationToPointMap;
413 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
414 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
415 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
416 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
417 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
418 if ((*type == NULL) || ((*iter)->getType() == *type)) {
419 distance = domain.periodicDistance((*iter)->getPosition(),*point);
420 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
421 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
422 }
423 }
424 }
425
426 return outmap;
427};
428
429/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
430 * \param *molecules list of molecules structure
431 * \param &elements vector of elements to correlate to point
432 * \param *point vector to the correlation point
433 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
434 * \return Map of dobules with values as pairs of atom and the vector
435 */
436CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
437{
438 Info FunctionInfo(__func__);
439 CorrelationToPointMap *outmap = new CorrelationToPointMap;
440 double distance = 0.;
441 int n[NDIM];
442 Vector periodicX;
443 Vector checkX;
444
445 if (molecules.empty()) {
446 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
447 return outmap;
448 }
449 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
450 (*MolWalker)->doCountAtoms();
451 outmap = new CorrelationToPointMap;
452 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
453 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
454 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
455 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
456 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
457 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
458 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
459 if ((*type == NULL) || ((*iter)->getType() == *type)) {
460 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
461 // go through every range in xyz and get distance
462 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
463 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
464 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
465 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
466 distance = checkX.distance(*point);
467 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
468 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
469 }
470 }
471 }
472 }
473
474 return outmap;
475};
476
477/** Calculates the distance (pair) correlation between a given element and a surface.
478 * \param *molecules list of molecules structure
479 * \param &elements vector of elements to correlate to surface
480 * \param *Surface pointer to Tesselation class surface
481 * \param *LC LinkedCell structure to quickly find neighbouring atoms
482 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
483 */
484CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
485{
486 Info FunctionInfo(__func__);
487 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
488 double distance = 0;
489 class BoundaryTriangleSet *triangle = NULL;
490 Vector centroid;
491
492 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
493 DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
494 return outmap;
495 }
496 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
497 (*MolWalker)->doCountAtoms();
498 outmap = new CorrelationToSurfaceMap;
499 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
500 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << (*MolWalker)->name << "." << endl);
501 if ((*MolWalker)->empty())
502 DoLog(2) && (2) && (Log() << Verbose(2) << "\t is empty." << endl);
503 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
504 DoLog(3) && (Log() << Verbose(3) << "\tCurrent atom is " << *(*iter) << "." << endl);
505 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
506 if ((*type == NULL) || ((*iter)->getType() == *type)) {
507 TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
508 distance = Intersections.GetSmallestDistance();
509 triangle = Intersections.GetClosestTriangle();
510 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
511 }
512 }
513 }
514
515 return outmap;
516};
517
518/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
519 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
520 * 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
521 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
522 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
523 * \param *molecules list of molecules structure
524 * \param &elements vector of elements to correlate to surface
525 * \param *Surface pointer to Tesselation class surface
526 * \param *LC LinkedCell structure to quickly find neighbouring atoms
527 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
528 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
529 */
530CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
531{
532 Info FunctionInfo(__func__);
533 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
534 double distance = 0;
535 class BoundaryTriangleSet *triangle = NULL;
536 Vector centroid;
537 int n[NDIM];
538 Vector periodicX;
539 Vector checkX;
540
541 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
542 DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
543 return outmap;
544 }
545 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
546 (*MolWalker)->doCountAtoms();
547 outmap = new CorrelationToSurfaceMap;
548 double ShortestDistance = 0.;
549 BoundaryTriangleSet *ShortestTriangle = NULL;
550 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
551 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
552 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
553 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
554 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
555 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
556 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
557 if ((*type == NULL) || ((*iter)->getType() == *type)) {
558 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
559 // go through every range in xyz and get distance
560 ShortestDistance = -1.;
561 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
562 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
563 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
564 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
565 TriangleIntersectionList Intersections(checkX,Surface,LC);
566 distance = Intersections.GetSmallestDistance();
567 triangle = Intersections.GetClosestTriangle();
568 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
569 ShortestDistance = distance;
570 ShortestTriangle = triangle;
571 }
572 }
573 // insert
574 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
575 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
576 }
577 }
578 }
579
580 return outmap;
581};
582
583/** Returns the index of the bin for a given value.
584 * \param value value whose bin to look for
585 * \param BinWidth width of bin
586 * \param BinStart first bin
587 */
588int GetBin ( const double value, const double BinWidth, const double BinStart )
589{
590 //Info FunctionInfo(__func__);
591 int bin =(int) (floor((value - BinStart)/BinWidth));
592 return (bin);
593};
594
595
596/** Adds header part that is unique to BinPairMap.
597 *
598 * @param file stream to print to
599 */
600void OutputCorrelation_Header( ofstream * const file )
601{
602 *file << "\tCount";
603};
604
605/** Prints values stored in BinPairMap iterator.
606 *
607 * @param file stream to print to
608 * @param runner iterator pointing at values to print
609 */
610void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
611{
612 *file << runner->second;
613};
614
615
616/** Adds header part that is unique to DipoleAngularCorrelationMap.
617 *
618 * @param file stream to print to
619 */
620void OutputDipoleAngularCorrelation_Header( ofstream * const file )
621{
622 *file << "\tFirstAtomOfMolecule";
623};
624
625/** Prints values stored in DipoleCorrelationMap iterator.
626 *
627 * @param file stream to print to
628 * @param runner iterator pointing at values to print
629 */
630void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
631{
632 *file << runner->second->getName();
633};
634
635
636/** Adds header part that is unique to DipoleAngularCorrelationMap.
637 *
638 * @param file stream to print to
639 */
640void OutputDipoleCorrelation_Header( ofstream * const file )
641{
642 *file << "\tMolecule";
643};
644
645/** Prints values stored in DipoleCorrelationMap iterator.
646 *
647 * @param file stream to print to
648 * @param runner iterator pointing at values to print
649 */
650void OutputDipoleCorrelation_Value( ofstream * const file, DipoleCorrelationMap::const_iterator &runner )
651{
652 *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
653};
654
655
656/** Adds header part that is unique to PairCorrelationMap.
657 *
658 * @param file stream to print to
659 */
660void OutputPairCorrelation_Header( ofstream * const file )
661{
662 *file << "\tAtom1\tAtom2";
663};
664
665/** Prints values stored in PairCorrelationMap iterator.
666 *
667 * @param file stream to print to
668 * @param runner iterator pointing at values to print
669 */
670void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner )
671{
672 *file << *(runner->second.first) << "\t" << *(runner->second.second);
673};
674
675
676/** Adds header part that is unique to CorrelationToPointMap.
677 *
678 * @param file stream to print to
679 */
680void OutputCorrelationToPoint_Header( ofstream * const file )
681{
682 *file << "\tAtom::x[i]-point.x[i]";
683};
684
685/** Prints values stored in CorrelationToPointMap iterator.
686 *
687 * @param file stream to print to
688 * @param runner iterator pointing at values to print
689 */
690void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner )
691{
692 for (int i=0;i<NDIM;i++)
693 *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
694};
695
696
697/** Adds header part that is unique to CorrelationToSurfaceMap.
698 *
699 * @param file stream to print to
700 */
701void OutputCorrelationToSurface_Header( ofstream * const file )
702{
703 *file << "\tTriangle";
704};
705
706/** Prints values stored in CorrelationToSurfaceMap iterator.
707 *
708 * @param file stream to print to
709 * @param runner iterator pointing at values to print
710 */
711void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
712{
713 *file << *(runner->second.first) << "\t" << *(runner->second.second);
714};
Note: See TracBrowser for help on using the repository browser.