source: src/Analysis/analysis_correlation.cpp@ 1cc661

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

Refactored part of DipoleAngularCorrelation into method getTrajectoryBounds().

  • Property mode set to 100644
File size: 30.8 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
120/** Calculates the dipole angular correlation for given molecule type.
121 * Calculate the change of the dipole orientation angle over time.
122 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
123 * Angles are given in degrees.
124 * \param &atoms list of atoms of the molecules taking part (Note: molecules may
125 * change over time as bond structure is recalculated, hence we need the atoms)
126 * \return Map of doubles with values the pair of the two atoms.
127 */
128DipoleAngularCorrelationMap *DipoleAngularCorrelation(std::vector<atom *> &atoms)
129{
130 Info FunctionInfo(__func__);
131 DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
132 std::set<molecule *> molecules;
133
134 // store original time step
135 const unsigned int oldtime = WorldTime::getTime();
136 World::getInstance().setTime(0);
137 // calculate molecules for this time step
138 BOOST_FOREACH(atom *_atom, atoms)
139 molecules.insert(_atom->getMolecule());
140
141 BOOST_FOREACH(atom *_atom, World::getInstance().getAllAtoms())
142 LOG(2, "INFO: Atom " << _atom->getId() << " "
143 << *dynamic_cast<AtomInfo *>(_atom) <<".");
144
145
146 // get zero orientation for each molecule.
147 LOG(0,"STATUS: Calculating dipoles for first time step ...");
148 std::map<atomId_t, Vector> ZeroVector;
149 BOOST_FOREACH(molecule *_mol, molecules) {
150 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
151 for(molecule::const_iterator iter = _mol->begin(); iter != _mol->end(); ++iter)
152 ZeroVector[(*iter)->getId()] = Dipole;
153 LOG(2,"INFO: Zero alignment for molecule " << _mol->getId() << " is " << Dipole);
154 }
155 LOG(1,"INFO: We calculated zero orientation for a total of " << molecules.size() << " molecules.");
156
157 // go through every time step
158 LOG(0,"STATUS: Calculating dipoles of following time steps ...");
159 range<size_t> timesteps = getMaximumTrajectoryBounds(atoms);
160 for (size_t step = 1; step < timesteps.first; ++step) {
161 World::getInstance().setTime(step);
162 // recalculate molecules for this time step
163 molecules.clear();
164 BOOST_FOREACH(atom *_atom, atoms)
165 molecules.insert(_atom->getMolecule());
166 size_t i=0;
167 BOOST_FOREACH(molecule *_mol, molecules) {
168 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
169 LOG(2,"INFO: Dipole vector at time step " << step << " for for molecule " << _mol->getId() << " is " << Dipole);
170 molecule::const_iterator iter = _mol->begin();
171 ASSERT(ZeroVector.count((*iter)->getId()),
172 "DipoleAngularCorrelation() - ZeroVector for atom "+toString(**iter)+" not present.");
173 const double angle = Dipole.Angle(ZeroVector[(*iter)->getId()]) * (180./M_PI);
174 LOG(1,"INFO: Resulting relative angle for molecule " << **iter << " is " << angle << ".");
175 outmap->insert ( make_pair (angle, *iter ) );
176 ++i;
177 }
178 }
179
180
181 // set original time step again
182 World::getInstance().setTime(oldtime);
183 LOG(0,"STATUS: Done.");
184
185 // and return results
186 return outmap;
187};
188
189/** Calculates the dipole correlation for given molecule type.
190 * I.e. we calculate how the angle between any two given dipoles in the
191 * systems behaves. Sort of pair correlation but distance is replaced by
192 * the orientation distance, i.e. an angle.
193 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
194 * Angles are given in degrees.
195 * \param *molecules vector of molecules
196 * \return Map of doubles with values the pair of the two atoms.
197 */
198DipoleCorrelationMap *DipoleCorrelation(std::vector<molecule *> &molecules)
199{
200 Info FunctionInfo(__func__);
201 DipoleCorrelationMap *outmap = new DipoleCorrelationMap;
202// double distance = 0.;
203// Box &domain = World::getInstance().getDomain();
204//
205 if (molecules.empty()) {
206 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
207 return outmap;
208 }
209
210 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
211 MolWalker != molecules.end(); ++MolWalker) {
212 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is "
213 << (*MolWalker)->getId() << "." << endl);
214 const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
215 std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
216 for (++MolOtherWalker;
217 MolOtherWalker != molecules.end();
218 ++MolOtherWalker) {
219 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is "
220 << (*MolOtherWalker)->getId() << "." << endl);
221 const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
222 const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
223 DoLog(1) && (Log() << Verbose(1) << "Angle is " << angle << "." << endl);
224 outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
225 }
226 }
227 return outmap;
228};
229
230
231/** Calculates the pair correlation between given elements.
232 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
233 * \param *molecules vector of molecules
234 * \param &elements vector of elements to correlate
235 * \return Map of doubles with values the pair of the two atoms.
236 */
237PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
238{
239 Info FunctionInfo(__func__);
240 PairCorrelationMap *outmap = new PairCorrelationMap;
241 double distance = 0.;
242 Box &domain = World::getInstance().getDomain();
243
244 if (molecules.empty()) {
245 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
246 return outmap;
247 }
248 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
249 (*MolWalker)->doCountAtoms();
250
251 // create all possible pairs of elements
252 set <pair<const element *,const element *> > PairsOfElements;
253 if (elements.size() >= 2) {
254 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
255 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
256 if (type1 != type2) {
257 PairsOfElements.insert( make_pair(*type1,*type2) );
258 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
259 }
260 } else if (elements.size() == 1) { // one to all are valid
261 const element *elemental = *elements.begin();
262 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
263 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
264 } else { // all elements valid
265 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
266 }
267
268 outmap = new PairCorrelationMap;
269 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
270 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
271 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
272 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
273 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
274 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
275 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
276 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
277 if ((*iter)->getId() < (*runner)->getId()){
278 for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
279 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
280 distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
281 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
282 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
283 }
284 }
285 }
286 }
287 }
288 }
289 return outmap;
290};
291
292/** Calculates the pair correlation between given elements.
293 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
294 * \param *molecules list of molecules structure
295 * \param &elements vector of elements to correlate
296 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
297 * \return Map of doubles with values the pair of the two atoms.
298 */
299PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
300{
301 Info FunctionInfo(__func__);
302 PairCorrelationMap *outmap = new PairCorrelationMap;
303 double distance = 0.;
304 int n[NDIM];
305 Vector checkX;
306 Vector periodicX;
307 int Othern[NDIM];
308 Vector checkOtherX;
309 Vector periodicOtherX;
310
311 if (molecules.empty()) {
312 DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
313 return outmap;
314 }
315 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
316 (*MolWalker)->doCountAtoms();
317
318 // create all possible pairs of elements
319 set <pair<const element *,const element *> > PairsOfElements;
320 if (elements.size() >= 2) {
321 for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
322 for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
323 if (type1 != type2) {
324 PairsOfElements.insert( make_pair(*type1,*type2) );
325 DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << *(*type1) << " and " << *(*type2) << "." << endl);
326 }
327 } else if (elements.size() == 1) { // one to all are valid
328 const element *elemental = *elements.begin();
329 PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
330 PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
331 } else { // all elements valid
332 PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
333 }
334
335 outmap = new PairCorrelationMap;
336 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
337 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
338 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
339 DoLog(2) && (Log()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
340 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
341 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
342 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
343 // go through every range in xyz and get distance
344 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
345 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
346 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
347 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
348 for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
349 DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
350 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
351 DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
352 if ((*iter)->getId() < (*runner)->getId()){
353 for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
354 if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
355 periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
356 // go through every range in xyz and get distance
357 for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
358 for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
359 for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
360 checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
361 distance = checkX.distance(checkOtherX);
362 //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
363 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
364 }
365 }
366 }
367 }
368 }
369 }
370 }
371 }
372
373 return outmap;
374};
375
376/** Calculates the distance (pair) correlation between a given element and a point.
377 * \param *molecules list of molecules structure
378 * \param &elements vector of elements to correlate with point
379 * \param *point vector to the correlation point
380 * \return Map of dobules with values as pairs of atom and the vector
381 */
382CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
383{
384 Info FunctionInfo(__func__);
385 CorrelationToPointMap *outmap = new CorrelationToPointMap;
386 double distance = 0.;
387 Box &domain = World::getInstance().getDomain();
388
389 if (molecules.empty()) {
390 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
391 return outmap;
392 }
393 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
394 (*MolWalker)->doCountAtoms();
395 outmap = new CorrelationToPointMap;
396 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
397 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
398 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
399 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
400 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
401 if ((*type == NULL) || ((*iter)->getType() == *type)) {
402 distance = domain.periodicDistance((*iter)->getPosition(),*point);
403 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
404 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
405 }
406 }
407 }
408
409 return outmap;
410};
411
412/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
413 * \param *molecules list of molecules structure
414 * \param &elements vector of elements to correlate to point
415 * \param *point vector to the correlation point
416 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
417 * \return Map of dobules with values as pairs of atom and the vector
418 */
419CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
420{
421 Info FunctionInfo(__func__);
422 CorrelationToPointMap *outmap = new CorrelationToPointMap;
423 double distance = 0.;
424 int n[NDIM];
425 Vector periodicX;
426 Vector checkX;
427
428 if (molecules.empty()) {
429 DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
430 return outmap;
431 }
432 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
433 (*MolWalker)->doCountAtoms();
434 outmap = new CorrelationToPointMap;
435 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
436 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
437 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
438 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
439 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
440 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
441 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
442 if ((*type == NULL) || ((*iter)->getType() == *type)) {
443 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
444 // go through every range in xyz and get distance
445 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
446 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
447 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
448 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
449 distance = checkX.distance(*point);
450 DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
451 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
452 }
453 }
454 }
455 }
456
457 return outmap;
458};
459
460/** Calculates the distance (pair) correlation between a given element and a surface.
461 * \param *molecules list of molecules structure
462 * \param &elements vector of elements to correlate to surface
463 * \param *Surface pointer to Tesselation class surface
464 * \param *LC LinkedCell structure to quickly find neighbouring atoms
465 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
466 */
467CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
468{
469 Info FunctionInfo(__func__);
470 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
471 double distance = 0;
472 class BoundaryTriangleSet *triangle = NULL;
473 Vector centroid;
474
475 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
476 DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
477 return outmap;
478 }
479 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
480 (*MolWalker)->doCountAtoms();
481 outmap = new CorrelationToSurfaceMap;
482 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
483 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << (*MolWalker)->name << "." << endl);
484 if ((*MolWalker)->empty())
485 DoLog(2) && (2) && (Log() << Verbose(2) << "\t is empty." << endl);
486 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
487 DoLog(3) && (Log() << Verbose(3) << "\tCurrent atom is " << *(*iter) << "." << endl);
488 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
489 if ((*type == NULL) || ((*iter)->getType() == *type)) {
490 TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
491 distance = Intersections.GetSmallestDistance();
492 triangle = Intersections.GetClosestTriangle();
493 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
494 }
495 }
496 }
497
498 return outmap;
499};
500
501/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
502 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
503 * 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
504 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
505 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
506 * \param *molecules list of molecules structure
507 * \param &elements vector of elements to correlate to surface
508 * \param *Surface pointer to Tesselation class surface
509 * \param *LC LinkedCell structure to quickly find neighbouring atoms
510 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
511 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
512 */
513CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
514{
515 Info FunctionInfo(__func__);
516 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
517 double distance = 0;
518 class BoundaryTriangleSet *triangle = NULL;
519 Vector centroid;
520 int n[NDIM];
521 Vector periodicX;
522 Vector checkX;
523
524 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
525 DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
526 return outmap;
527 }
528 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
529 (*MolWalker)->doCountAtoms();
530 outmap = new CorrelationToSurfaceMap;
531 double ShortestDistance = 0.;
532 BoundaryTriangleSet *ShortestTriangle = NULL;
533 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
534 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
535 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
536 DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
537 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
538 DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
539 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
540 if ((*type == NULL) || ((*iter)->getType() == *type)) {
541 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
542 // go through every range in xyz and get distance
543 ShortestDistance = -1.;
544 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
545 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
546 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
547 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
548 TriangleIntersectionList Intersections(checkX,Surface,LC);
549 distance = Intersections.GetSmallestDistance();
550 triangle = Intersections.GetClosestTriangle();
551 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
552 ShortestDistance = distance;
553 ShortestTriangle = triangle;
554 }
555 }
556 // insert
557 outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
558 //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
559 }
560 }
561 }
562
563 return outmap;
564};
565
566/** Returns the index of the bin for a given value.
567 * \param value value whose bin to look for
568 * \param BinWidth width of bin
569 * \param BinStart first bin
570 */
571int GetBin ( const double value, const double BinWidth, const double BinStart )
572{
573 //Info FunctionInfo(__func__);
574 int bin =(int) (floor((value - BinStart)/BinWidth));
575 return (bin);
576};
577
578
579/** Adds header part that is unique to BinPairMap.
580 *
581 * @param file stream to print to
582 */
583void OutputCorrelation_Header( ofstream * const file )
584{
585 *file << "\tCount";
586};
587
588/** Prints values stored in BinPairMap iterator.
589 *
590 * @param file stream to print to
591 * @param runner iterator pointing at values to print
592 */
593void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
594{
595 *file << runner->second;
596};
597
598
599/** Adds header part that is unique to DipoleAngularCorrelationMap.
600 *
601 * @param file stream to print to
602 */
603void OutputDipoleAngularCorrelation_Header( ofstream * const file )
604{
605 *file << "\tFirstAtomOfMolecule";
606};
607
608/** Prints values stored in DipoleCorrelationMap iterator.
609 *
610 * @param file stream to print to
611 * @param runner iterator pointing at values to print
612 */
613void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
614{
615 *file << runner->second->getName();
616};
617
618
619/** Adds header part that is unique to DipoleAngularCorrelationMap.
620 *
621 * @param file stream to print to
622 */
623void OutputDipoleCorrelation_Header( ofstream * const file )
624{
625 *file << "\tMolecule";
626};
627
628/** Prints values stored in DipoleCorrelationMap iterator.
629 *
630 * @param file stream to print to
631 * @param runner iterator pointing at values to print
632 */
633void OutputDipoleCorrelation_Value( ofstream * const file, DipoleCorrelationMap::const_iterator &runner )
634{
635 *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
636};
637
638
639/** Adds header part that is unique to PairCorrelationMap.
640 *
641 * @param file stream to print to
642 */
643void OutputPairCorrelation_Header( ofstream * const file )
644{
645 *file << "\tAtom1\tAtom2";
646};
647
648/** Prints values stored in PairCorrelationMap iterator.
649 *
650 * @param file stream to print to
651 * @param runner iterator pointing at values to print
652 */
653void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner )
654{
655 *file << *(runner->second.first) << "\t" << *(runner->second.second);
656};
657
658
659/** Adds header part that is unique to CorrelationToPointMap.
660 *
661 * @param file stream to print to
662 */
663void OutputCorrelationToPoint_Header( ofstream * const file )
664{
665 *file << "\tAtom::x[i]-point.x[i]";
666};
667
668/** Prints values stored in CorrelationToPointMap iterator.
669 *
670 * @param file stream to print to
671 * @param runner iterator pointing at values to print
672 */
673void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner )
674{
675 for (int i=0;i<NDIM;i++)
676 *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
677};
678
679
680/** Adds header part that is unique to CorrelationToSurfaceMap.
681 *
682 * @param file stream to print to
683 */
684void OutputCorrelationToSurface_Header( ofstream * const file )
685{
686 *file << "\tTriangle";
687};
688
689/** Prints values stored in CorrelationToSurfaceMap iterator.
690 *
691 * @param file stream to print to
692 * @param runner iterator pointing at values to print
693 */
694void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
695{
696 *file << *(runner->second.first) << "\t" << *(runner->second.second);
697};
Note: See TracBrowser for help on using the repository browser.