source: src/Analysis/analysis_correlation.cpp@ a2b0ce

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

DipoleAngularCorrelation is now calculated per time step not over all time steps combined.

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