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