source: src/Analysis/analysis_correlation.cpp@ e65878

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

Selection is now done inside DipoleAngularCorrelation.

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