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