source: src/Analysis/analysis_correlation.cpp@ 7ee21d

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

MEMFIX: Many analysis_correlation function allocated return map twice.

  • outmap was the culprit, probably when empty (but allocated) was returned when no atoms are allocated, two new's appeared.
  • Property mode set to 100644
File size: 28.8 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[94d5ac6]6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[bcf653]22 */
23
[c4d4df]24/*
25 * analysis.cpp
26 *
27 * Created on: Oct 13, 2009
28 * Author: heber
29 */
30
[bf3817]31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
[ad011c]36#include "CodePatterns/MemDebug.hpp"
[112b09]37
[c1a9d6]38#include <algorithm>
[c4d4df]39#include <iostream>
[36166d]40#include <iomanip>
[505d05]41#include <limits>
[c4d4df]42
[6f0841]43#include "Atom/atom.hpp"
[129204]44#include "Bond/bond.hpp"
[d127c8]45#include "Tesselation/BoundaryTriangleSet.hpp"
[be945c]46#include "Box.hpp"
[3bdb6d]47#include "Element/element.hpp"
[ad011c]48#include "CodePatterns/Info.hpp"
49#include "CodePatterns/Log.hpp"
[208237b]50#include "CodePatterns/Verbose.hpp"
[e65878]51#include "Descriptors/AtomOfMoleculeSelectionDescriptor.hpp"
52#include "Descriptors/MoleculeFormulaDescriptor.hpp"
[4b8630]53#include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
[ea430a]54#include "Formula.hpp"
[208237b]55#include "LinearAlgebra/Vector.hpp"
56#include "LinearAlgebra/RealSpaceMatrix.hpp"
[c1a9d6]57#include "LinkedCell/LinkedCell_View.hpp"
[c4d4df]58#include "molecule.hpp"
[d127c8]59#include "Tesselation/tesselation.hpp"
60#include "Tesselation/tesselationhelpers.hpp"
61#include "Tesselation/triangleintersectionlist.hpp"
[be945c]62#include "World.hpp"
[208237b]63#include "WorldTime.hpp"
[c4d4df]64
[be945c]65#include "analysis_correlation.hpp"
66
67/** Calculates the dipole vector of a given atomSet.
68 *
69 * Note that we use the following procedure as rule of thumb:
70 * -# go through every bond of the atom
[d1912f]71 * -# calculate the difference of electronegativities \f$\Delta\mathrm{EN}\f$
72 * -# if \f$\Delta\mathrm{EN} > 0.5\f$, we align the bond vector in direction of the more negative element
[be945c]73 * -# sum up all vectors
74 * -# finally, divide by the number of summed vectors
75 *
76 * @param atomsbegin begin iterator of atomSet
77 * @param atomsend end iterator of atomset
78 * @return dipole vector
79 */
80Vector getDipole(molecule::const_iterator atomsbegin, molecule::const_iterator atomsend)
81{
82 Vector DipoleVector;
83 size_t SumOfVectors = 0;
[8fc1a6]84 Box &domain = World::getInstance().getDomain();
85
86 // go through all atoms
[be945c]87 for (molecule::const_iterator atomiter = atomsbegin;
88 atomiter != atomsend;
89 ++atomiter) {
90 // go through all bonds
[9d83b6]91 const BondList& ListOfBonds = (*atomiter)->getListOfBonds();
[4fc828]92 ASSERT(ListOfBonds.begin() != ListOfBonds.end(),
93 "getDipole() - no bonds in molecule!");
[9d83b6]94 for (BondList::const_iterator bonditer = ListOfBonds.begin();
95 bonditer != ListOfBonds.end();
[be945c]96 ++bonditer) {
97 const atom * Otheratom = (*bonditer)->GetOtherAtom(*atomiter);
98 if (Otheratom->getId() > (*atomiter)->getId()) {
99 const double DeltaEN = (*atomiter)->getType()->getElectronegativity()
100 -Otheratom->getType()->getElectronegativity();
[8fc1a6]101 // get distance and correct for boundary conditions
102 Vector BondDipoleVector = domain.periodicDistanceVector(
103 (*atomiter)->getPosition(),
104 Otheratom->getPosition());
[be945c]105 // DeltaEN is always positive, gives correct orientation of vector
106 BondDipoleVector.Normalize();
107 BondDipoleVector *= DeltaEN;
[4fc828]108 LOG(3,"INFO: Dipole vector from bond " << **bonditer << " is " << BondDipoleVector);
[be945c]109 DipoleVector += BondDipoleVector;
110 SumOfVectors++;
111 }
112 }
113 }
[4fc828]114 LOG(3,"INFO: Sum over all bond dipole vectors is "
115 << DipoleVector << " with " << SumOfVectors << " in total.");
116 if (SumOfVectors != 0)
117 DipoleVector *= 1./(double)SumOfVectors;
[44f53e]118 LOG(2, "INFO: Resulting dipole vector is " << DipoleVector);
[be945c]119
120 return DipoleVector;
121};
122
[1cc661]123/** Calculate minimum and maximum amount of trajectory steps by going through given atomic trajectories.
124 * \param vector of atoms whose trajectories to check for [min,max]
125 * \return range with [min, max]
126 */
[e65878]127range<size_t> getMaximumTrajectoryBounds(const std::vector<atom *> &atoms)
[1cc661]128{
129 // get highest trajectory size
130 LOG(0,"STATUS: Retrieving maximum amount of time steps ...");
[505d05]131 if (atoms.size() == 0)
132 return range<size_t>(0,0);
133 size_t max_timesteps = std::numeric_limits<size_t>::min();
134 size_t min_timesteps = std::numeric_limits<size_t>::max();
[1cc661]135 BOOST_FOREACH(atom *_atom, atoms) {
136 if (_atom->getTrajectorySize() > max_timesteps)
137 max_timesteps = _atom->getTrajectorySize();
[505d05]138 if (_atom->getTrajectorySize() < min_timesteps)
[1cc661]139 min_timesteps = _atom->getTrajectorySize();
140 }
141 LOG(1,"INFO: Minimum number of time steps found is " << min_timesteps);
142 LOG(1,"INFO: Maximum number of time steps found is " << max_timesteps);
143
144 return range<size_t>(min_timesteps, max_timesteps);
145}
146
[0a7fad]147/** Calculates the angular dipole zero orientation from current time step.
[e65878]148 * \param molecules vector of molecules to calculate dipoles of
[0a7fad]149 * \return map with orientation vector for each atomic id given in \a atoms.
150 */
[e65878]151std::map<atomId_t, Vector> CalculateZeroAngularDipole(const std::vector<molecule *> &molecules)
[0a7fad]152{
153 // get zero orientation for each molecule.
[e65878]154 LOG(0,"STATUS: Calculating dipoles for current time step ...");
[0a7fad]155 std::map<atomId_t, Vector> ZeroVector;
156 BOOST_FOREACH(molecule *_mol, molecules) {
157 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
158 for(molecule::const_iterator iter = _mol->begin(); iter != _mol->end(); ++iter)
159 ZeroVector[(*iter)->getId()] = Dipole;
160 LOG(2,"INFO: Zero alignment for molecule " << _mol->getId() << " is " << Dipole);
161 }
162 LOG(1,"INFO: We calculated zero orientation for a total of " << molecules.size() << " molecule(s).");
163
164 return ZeroVector;
165}
[1cc661]166
[ea430a]167/** Calculates the dipole angular correlation for given molecule type.
[208237b]168 * Calculate the change of the dipole orientation angle over time.
[ea430a]169 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
[be945c]170 * Angles are given in degrees.
[4b8630]171 * \param &atoms list of atoms of the molecules taking part (Note: molecules may
172 * change over time as bond structure is recalculated, hence we need the atoms)
[cda81d]173 * \param timestep time step to calculate angular correlation for (relative to
174 * \a ZeroVector)
[325687]175 * \param ZeroVector map with Zero orientation vector for each atom in \a atoms.
[99b87a]176 * \param DontResetTime don't reset time to old value (triggers re-creation of bond system)
[ea430a]177 * \return Map of doubles with values the pair of the two atoms.
178 */
[325687]179DipoleAngularCorrelationMap *DipoleAngularCorrelation(
[e65878]180 const Formula &DipoleFormula,
[cda81d]181 const size_t timestep,
[e65878]182 const std::map<atomId_t, Vector> &ZeroVector,
[99b87a]183 const enum ResetWorldTime DoTimeReset
[325687]184 )
[ea430a]185{
186 Info FunctionInfo(__func__);
[caa30b]187 DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
[be945c]188
[99b87a]189 unsigned int oldtime = 0;
190 if (DoTimeReset == DoResetTime) {
191 // store original time step
192 oldtime = WorldTime::getTime();
193 }
[0a7fad]194
[cda81d]195 // set time step
[505d05]196 LOG(0,"STATUS: Stepping onto to time step " << timestep << ".");
[cda81d]197 World::getInstance().setTime(timestep);
198
199 // get all molecules for this time step
[e65878]200 World::getInstance().clearMoleculeSelection();
201 World::getInstance().selectAllMolecules(MoleculeByFormula(DipoleFormula));
202 std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
[870b4b]203 LOG(1,"INFO: There are " << molecules.size() << " molecules for time step " << timestep << ".");
[208237b]204
[cda81d]205 // calculate dipoles for each
[870b4b]206 LOG(0,"STATUS: Calculating dipoles for time step " << timestep << " ...");
[cda81d]207 size_t i=0;
[870b4b]208 size_t Counter_rejections = 0;
[cda81d]209 BOOST_FOREACH(molecule *_mol, molecules) {
210 const Vector Dipole = getDipole(_mol->begin(), _mol->end());
[e65878]211 LOG(3,"INFO: Dipole vector at time step " << timestep << " for for molecule "
[cda81d]212 << _mol->getId() << " is " << Dipole);
[e65878]213 // check that all atoms are valid (zeroVector known)
[cda81d]214 molecule::const_iterator iter = _mol->begin();
[e65878]215 for(; iter != _mol->end(); ++iter) {
216 if (!ZeroVector.count((*iter)->getId()))
217 break;
218 }
219 if (iter != _mol->end()) {
220 ELOG(2, "Skipping molecule " << _mol->getName() << " as not all atoms have a valid zeroVector.");
[870b4b]221 ++Counter_rejections;
[e65878]222 continue;
223 } else
224 iter = _mol->begin();
225 std::map<atomId_t, Vector>::const_iterator zeroValue = ZeroVector.find((*iter)->getId()); //due to iter is const
[cda81d]226 double angle = 0.;
227 LOG(2, "INFO: ZeroVector of first atom " << **iter << " is "
[e65878]228 << zeroValue->second << ".");
[cda81d]229 LOG(4, "INFO: Squared norm of difference vector is "
[e65878]230 << (zeroValue->second - Dipole).NormSquared() << ".");
231 if ((zeroValue->second - Dipole).NormSquared() > MYEPSILON)
232 angle = Dipole.Angle(zeroValue->second) * (180./M_PI);
[cda81d]233 else
234 LOG(2, "INFO: Both vectors (almost) coincide, numerically unstable, angle set to zero.");
[e9bdef]235 // we print six digits, hence round up to six digit precision
236 const double precision = 1e-6;
237 angle = precision*floor(angle/precision);
[cda81d]238 LOG(1,"INFO: Resulting relative angle for molecule " << _mol->getName()
239 << " is " << angle << ".");
[59fff1]240 outmap->insert ( std::make_pair (angle, *iter ) );
[cda81d]241 ++i;
[208237b]242 }
[870b4b]243 ASSERT(Counter_rejections <= molecules.size(),
244 "DipoleAngularCorrelation() - more rejections ("+toString(Counter_rejections)
245 +") than there are molecules ("+toString(molecules.size())+").");
246 LOG(1,"INFO: " << Counter_rejections << " molecules have been rejected in time step " << timestep << ".");
247
248 LOG(0,"STATUS: Done with calculating dipoles.");
[208237b]249
[99b87a]250 if (DoTimeReset == DoResetTime) {
251 // re-set to original time step again
252 World::getInstance().setTime(oldtime);
253 }
[208237b]254
255 // and return results
256 return outmap;
257};
258
259/** Calculates the dipole correlation for given molecule type.
260 * I.e. we calculate how the angle between any two given dipoles in the
261 * systems behaves. Sort of pair correlation but distance is replaced by
262 * the orientation distance, i.e. an angle.
263 * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
264 * Angles are given in degrees.
265 * \param *molecules vector of molecules
266 * \return Map of doubles with values the pair of the two atoms.
267 */
268DipoleCorrelationMap *DipoleCorrelation(std::vector<molecule *> &molecules)
269{
270 Info FunctionInfo(__func__);
271 DipoleCorrelationMap *outmap = new DipoleCorrelationMap;
272// double distance = 0.;
273// Box &domain = World::getInstance().getDomain();
274//
275 if (molecules.empty()) {
[47d041]276 ELOG(1, "No molecule given.");
[208237b]277 return outmap;
278 }
279
[be945c]280 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
[92e5cb]281 MolWalker != molecules.end(); ++MolWalker) {
[47d041]282 LOG(2, "INFO: Current molecule is " << (*MolWalker)->getId() << ".");
[be945c]283 const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
[92e5cb]284 std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
285 for (++MolOtherWalker;
[be945c]286 MolOtherWalker != molecules.end();
[92e5cb]287 ++MolOtherWalker) {
[47d041]288 LOG(2, "INFO: Current other molecule is " << (*MolOtherWalker)->getId() << ".");
[be945c]289 const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
290 const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
[47d041]291 LOG(1, "Angle is " << angle << ".");
[be945c]292 outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
293 }
294 }
[ea430a]295 return outmap;
296};
297
[c1a9d6]298/** Calculates the pair correlation between given atom sets.
299 *
300 * Note we correlate each of the \a &atomsfirst with each of the second set
301 * \a &atoms_second. However, we are aware of double counting. If an atom is
302 * in either set, the pair is counted only once.
303 *
304 * \param &atoms_first vector of atoms
305 * \param &atoms_second vector of atoms
306 * \param max_distance maximum distance for the correlation
[c4d4df]307 * \return Map of doubles with values the pair of the two atoms.
308 */
[c1a9d6]309PairCorrelationMap *PairCorrelation(
310 const World::AtomComposite &atoms_first,
311 const World::AtomComposite &atoms_second,
312 const double max_distance)
[c4d4df]313{
[3930eb]314 Info FunctionInfo(__func__);
[caa30b]315 PairCorrelationMap *outmap = new PairCorrelationMap;
[e791dc]316 //double distance = 0.;
[014475]317 Box &domain = World::getInstance().getDomain();
[c4d4df]318
[c1a9d6]319 if (atoms_first.empty() || atoms_second.empty()) {
320 ELOG(1, "No atoms given.");
[c4d4df]321 return outmap;
322 }
[c78d44]323
[c1a9d6]324 //!> typedef for an unsorted container, (output) compatible with STL algorithms
325 typedef std::vector<const TesselPoint *> LinkedVector;
[c4d4df]326
[c1a9d6]327 // create intersection (to know when to check for double-counting)
328 LinkedVector intersected_atoms(atoms_second.size(), NULL);
329 LinkedVector::iterator intersected_atoms_end =
330 std::set_intersection(
331 atoms_first.begin(),atoms_first.end(),
332 atoms_second.begin(), atoms_second.end(),
333 intersected_atoms.begin());
[a2a2f7]334 const LinkedCell::LinkedList intersected_atoms_set(intersected_atoms.begin(), intersected_atoms_end);
[c78d44]335
[c1a9d6]336 // get linked cell view
337 LinkedCell::LinkedCell_View LC = World::getInstance().getLinkedCell(max_distance);
338
339 // convert second to _sorted_ set
340 LinkedCell::LinkedList atoms_second_set(atoms_second.begin(), atoms_second.end());
341 LOG(2, "INFO: first set has " << atoms_first.size()
342 << " and second set has " << atoms_second_set.size() << " atoms.");
343
344 // fill map
345 for (World::AtomComposite::const_iterator iter = atoms_first.begin();
346 iter != atoms_first.end();
347 ++iter) {
348 const TesselPoint * const Walker = *iter;
349 LOG(3, "INFO: Current point is " << Walker->getName() << ".");
350 // obtain all possible neighbors (that is a sorted set)
351 LinkedCell::LinkedList ListOfNeighbors = LC.getPointsInsideSphere(
352 max_distance,
353 Walker->getPosition());
354 LOG(2, "INFO: There are " << ListOfNeighbors.size() << " neighbors.");
355
356 // create intersection with second set
357 // NOTE: STL algorithms do mostly not work on sorted container because reassignment
358 // of a value may also require changing its position.
359 LinkedVector intersected_set(atoms_second.size(), NULL);
360 LinkedVector::iterator intersected_end =
361 std::set_intersection(
362 ListOfNeighbors.begin(),ListOfNeighbors.end(),
363 atoms_second_set.begin(), atoms_second_set.end(),
364 intersected_set.begin());
365 // count remaining elements
366 LOG(2, "INFO: Intersection with second set has " << int(intersected_end - intersected_set.begin()) << " elements.");
367 // we have some possible candidates, go through each
368 for (LinkedVector::const_iterator neighboriter = intersected_set.begin();
369 neighboriter != intersected_end;
370 ++neighboriter) {
371 const TesselPoint * const OtherWalker = (*neighboriter);
372 LinkedCell::LinkedList::const_iterator equaliter = intersected_atoms_set.find(OtherWalker);
373 if ((equaliter != intersected_atoms_set.end()) && (OtherWalker <= Walker)) {
374 // present in both sets, assure that we are larger
375 continue;
[7ea9e6]376 }
[c1a9d6]377 LOG(3, "INFO: Current other point is " << *OtherWalker << ".");
378 const double distance = domain.periodicDistance(OtherWalker->getPosition(),Walker->getPosition());
379 LOG(3, "INFO: Resulting distance is " << distance << ".");
380 outmap->insert (
381 std::pair<double, std::pair <const TesselPoint *, const TesselPoint*> > (
382 distance,
383 std::make_pair (Walker, OtherWalker)
384 )
385 );
[7ea9e6]386 }
[c78d44]387 }
[c1a9d6]388 // and return
[7ea9e6]389 return outmap;
390};
391
[c4d4df]392/** Calculates the distance (pair) correlation between a given element and a point.
[a5551b]393 * \param *molecules list of molecules structure
[c78d44]394 * \param &elements vector of elements to correlate with point
[c4d4df]395 * \param *point vector to the correlation point
396 * \return Map of dobules with values as pairs of atom and the vector
397 */
[e5c0a1]398CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
[c4d4df]399{
[3930eb]400 Info FunctionInfo(__func__);
[caa30b]401 CorrelationToPointMap *outmap = new CorrelationToPointMap;
[c4d4df]402 double distance = 0.;
[014475]403 Box &domain = World::getInstance().getDomain();
[c4d4df]404
[e65de8]405 if (molecules.empty()) {
[47d041]406 LOG(1, "No molecule given.");
[c4d4df]407 return outmap;
408 }
[e791dc]409
[e65de8]410 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[47d041]411 LOG(2, "Current molecule is " << *MolWalker << ".");
[e65de8]412 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]413 LOG(3, "Current atom is " << **iter << ".");
[e5c0a1]414 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]415 if ((*type == NULL) || ((*iter)->getType() == *type)) {
416 distance = domain.periodicDistance((*iter)->getPosition(),*point);
[47d041]417 LOG(4, "Current distance is " << distance << ".");
[59fff1]418 outmap->insert (
419 std::pair<double, std::pair<const atom *, const Vector*> >(
420 distance,
421 std::pair<const atom *, const Vector*> (
422 (*iter),
423 point)
424 )
425 );
[e65de8]426 }
[c4d4df]427 }
[e65de8]428 }
[c4d4df]429
430 return outmap;
431};
432
[7ea9e6]433/** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
434 * \param *molecules list of molecules structure
[c78d44]435 * \param &elements vector of elements to correlate to point
[7ea9e6]436 * \param *point vector to the correlation point
437 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
438 * \return Map of dobules with values as pairs of atom and the vector
439 */
[e5c0a1]440CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
[7ea9e6]441{
[3930eb]442 Info FunctionInfo(__func__);
[caa30b]443 CorrelationToPointMap *outmap = new CorrelationToPointMap;
[7ea9e6]444 double distance = 0.;
445 int n[NDIM];
446 Vector periodicX;
447 Vector checkX;
448
[e65de8]449 if (molecules.empty()) {
[47d041]450 LOG(1, "No molecule given.");
[7ea9e6]451 return outmap;
452 }
[e791dc]453
[e65de8]454 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[cca9ef]455 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
456 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
[47d041]457 LOG(2, "Current molecule is " << *MolWalker << ".");
[e65de8]458 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]459 LOG(3, "Current atom is " << **iter << ".");
[e5c0a1]460 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]461 if ((*type == NULL) || ((*iter)->getType() == *type)) {
462 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
[e65de8]463 // go through every range in xyz and get distance
464 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
465 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
466 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
467 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
468 distance = checkX.distance(*point);
[47d041]469 LOG(4, "Current distance is " << distance << ".");
[59fff1]470 outmap->insert (
471 std::pair<double,
472 std::pair<const atom *, const Vector*> >(
473 distance,
474 std::pair<const atom *, const Vector*> (
475 *iter,
476 point)
477 )
478 );
[e65de8]479 }
480 }
[7ea9e6]481 }
[e65de8]482 }
[7ea9e6]483
484 return outmap;
485};
486
[c4d4df]487/** Calculates the distance (pair) correlation between a given element and a surface.
[a5551b]488 * \param *molecules list of molecules structure
[c78d44]489 * \param &elements vector of elements to correlate to surface
[c4d4df]490 * \param *Surface pointer to Tesselation class surface
[6bd7e0]491 * \param *LC LinkedCell_deprecated structure to quickly find neighbouring atoms
[c4d4df]492 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
493 */
[6bd7e0]494CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell_deprecated *LC )
[c4d4df]495{
[3930eb]496 Info FunctionInfo(__func__);
[caa30b]497 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
[99593f]498 double distance = 0;
[c4d4df]499 class BoundaryTriangleSet *triangle = NULL;
500 Vector centroid;
[7ea9e6]501
[e65de8]502 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
[47d041]503 ELOG(1, "No Tesselation, no LinkedCell or no molecule given.");
[7ea9e6]504 return outmap;
505 }
[e791dc]506
[e65de8]507 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[47d041]508 LOG(2, "Current molecule is " << (*MolWalker)->name << ".");
[e65de8]509 if ((*MolWalker)->empty())
[47d041]510 LOG(2, "\t is empty.");
[e65de8]511 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]512 LOG(3, "\tCurrent atom is " << *(*iter) << ".");
[e5c0a1]513 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]514 if ((*type == NULL) || ((*iter)->getType() == *type)) {
515 TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
[e65de8]516 distance = Intersections.GetSmallestDistance();
517 triangle = Intersections.GetClosestTriangle();
[59fff1]518 outmap->insert (
519 std::pair<double,
520 std::pair<const atom *, BoundaryTriangleSet*> >(
521 distance,
522 std::pair<const atom *, BoundaryTriangleSet*> (
523 (*iter),
524 triangle)
525 )
526 );
[e65de8]527 }
[7fd416]528 }
[e65de8]529 }
[7ea9e6]530
531 return outmap;
532};
533
534/** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
535 * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
536 * 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
537 * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
538 * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
539 * \param *molecules list of molecules structure
[c78d44]540 * \param &elements vector of elements to correlate to surface
[7ea9e6]541 * \param *Surface pointer to Tesselation class surface
[6bd7e0]542 * \param *LC LinkedCell_deprecated structure to quickly find neighbouring atoms
[7ea9e6]543 * \param ranges[NDIM] interval boundaries for the periodic images to scan also
544 * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
545 */
[6bd7e0]546CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell_deprecated *LC, const int ranges[NDIM] )
[7ea9e6]547{
[3930eb]548 Info FunctionInfo(__func__);
[caa30b]549 CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
[7ea9e6]550 double distance = 0;
551 class BoundaryTriangleSet *triangle = NULL;
552 Vector centroid;
[99593f]553 int n[NDIM];
554 Vector periodicX;
555 Vector checkX;
[c4d4df]556
[e65de8]557 if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
[47d041]558 LOG(1, "No Tesselation, no LinkedCell or no molecule given.");
[c4d4df]559 return outmap;
560 }
[e791dc]561
[244a84]562 double ShortestDistance = 0.;
563 BoundaryTriangleSet *ShortestTriangle = NULL;
[e65de8]564 for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
[cca9ef]565 RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
566 RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
[47d041]567 LOG(2, "Current molecule is " << *MolWalker << ".");
[e65de8]568 for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
[47d041]569 LOG(3, "Current atom is " << **iter << ".");
[e5c0a1]570 for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
[d74077]571 if ((*type == NULL) || ((*iter)->getType() == *type)) {
572 periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
[e65de8]573 // go through every range in xyz and get distance
574 ShortestDistance = -1.;
575 for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
576 for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
577 for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
578 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
[d74077]579 TriangleIntersectionList Intersections(checkX,Surface,LC);
[e65de8]580 distance = Intersections.GetSmallestDistance();
581 triangle = Intersections.GetClosestTriangle();
582 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
583 ShortestDistance = distance;
584 ShortestTriangle = triangle;
[99593f]585 }
[e65de8]586 }
587 // insert
[59fff1]588 outmap->insert (
589 std::pair<double,
590 std::pair<const atom *, BoundaryTriangleSet*> >(
591 ShortestDistance,
592 std::pair<const atom *, BoundaryTriangleSet*> (
593 *iter,
594 ShortestTriangle)
595 )
596 );
[47d041]597 //LOG(1, "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << ".");
[e65de8]598 }
[c4d4df]599 }
[e65de8]600 }
[c4d4df]601
602 return outmap;
603};
604
[bd61b41]605/** Returns the index of the bin for a given value.
[c4d4df]606 * \param value value whose bin to look for
607 * \param BinWidth width of bin
608 * \param BinStart first bin
609 */
[bd61b41]610int GetBin ( const double value, const double BinWidth, const double BinStart )
[c4d4df]611{
[92e5cb]612 //Info FunctionInfo(__func__);
[bd61b41]613 int bin =(int) (floor((value - BinStart)/BinWidth));
614 return (bin);
[c4d4df]615};
616
617
[92e5cb]618/** Adds header part that is unique to BinPairMap.
619 *
620 * @param file stream to print to
[c4d4df]621 */
[92e5cb]622void OutputCorrelation_Header( ofstream * const file )
[c4d4df]623{
[92e5cb]624 *file << "\tCount";
[c4d4df]625};
[b1f254]626
[92e5cb]627/** Prints values stored in BinPairMap iterator.
628 *
629 * @param file stream to print to
630 * @param runner iterator pointing at values to print
[be945c]631 */
[92e5cb]632void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
[be945c]633{
[92e5cb]634 *file << runner->second;
[be945c]635};
636
[92e5cb]637
638/** Adds header part that is unique to DipoleAngularCorrelationMap.
639 *
640 * @param file stream to print to
[b1f254]641 */
[92e5cb]642void OutputDipoleAngularCorrelation_Header( ofstream * const file )
[b1f254]643{
[4b8630]644 *file << "\tFirstAtomOfMolecule";
[b1f254]645};
646
[208237b]647/** Prints values stored in DipoleCorrelationMap iterator.
[92e5cb]648 *
649 * @param file stream to print to
650 * @param runner iterator pointing at values to print
[b1f254]651 */
[92e5cb]652void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
[208237b]653{
[505d05]654 *file << *(runner->second);
[208237b]655};
656
657
658/** Adds header part that is unique to DipoleAngularCorrelationMap.
659 *
660 * @param file stream to print to
661 */
662void OutputDipoleCorrelation_Header( ofstream * const file )
663{
664 *file << "\tMolecule";
665};
666
667/** Prints values stored in DipoleCorrelationMap iterator.
668 *
669 * @param file stream to print to
670 * @param runner iterator pointing at values to print
671 */
672void OutputDipoleCorrelation_Value( ofstream * const file, DipoleCorrelationMap::const_iterator &runner )
[b1f254]673{
[92e5cb]674 *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
[b1f254]675};
676
[92e5cb]677
678/** Adds header part that is unique to PairCorrelationMap.
679 *
680 * @param file stream to print to
[b1f254]681 */
[92e5cb]682void OutputPairCorrelation_Header( ofstream * const file )
[b1f254]683{
[92e5cb]684 *file << "\tAtom1\tAtom2";
685};
686
687/** Prints values stored in PairCorrelationMap iterator.
688 *
689 * @param file stream to print to
690 * @param runner iterator pointing at values to print
691 */
692void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner )
693{
694 *file << *(runner->second.first) << "\t" << *(runner->second.second);
695};
696
697
698/** Adds header part that is unique to CorrelationToPointMap.
699 *
700 * @param file stream to print to
701 */
702void OutputCorrelationToPoint_Header( ofstream * const file )
703{
704 *file << "\tAtom::x[i]-point.x[i]";
705};
706
707/** Prints values stored in CorrelationToPointMap iterator.
708 *
709 * @param file stream to print to
710 * @param runner iterator pointing at values to print
711 */
712void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner )
713{
714 for (int i=0;i<NDIM;i++)
715 *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
[b1f254]716};
717
[92e5cb]718
719/** Adds header part that is unique to CorrelationToSurfaceMap.
720 *
721 * @param file stream to print to
722 */
723void OutputCorrelationToSurface_Header( ofstream * const file )
724{
725 *file << "\tTriangle";
726};
727
728/** Prints values stored in CorrelationToSurfaceMap iterator.
729 *
730 * @param file stream to print to
731 * @param runner iterator pointing at values to print
732 */
733void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
734{
735 *file << *(runner->second.first) << "\t" << *(runner->second.second);
736};
Note: See TracBrowser for help on using the repository browser.