source: src/Analysis/analysis_correlation.cpp@ 99b87a

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

DipoleAngularCorrelation() can be told not to reset time to old value.

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