source: src/Analysis/analysis_correlation.cpp@ 505d05

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

DipoleAngularCorrelation: output now contains name _and position_ of first atom of dipole molecule.

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