1 | /*
|
---|
2 | * analysis.cpp
|
---|
3 | *
|
---|
4 | * Created on: Oct 13, 2009
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include <iostream>
|
---|
11 | #include <iomanip>
|
---|
12 |
|
---|
13 | #include "analysis_correlation.hpp"
|
---|
14 | #include "element.hpp"
|
---|
15 | #include "info.hpp"
|
---|
16 | #include "log.hpp"
|
---|
17 | #include "molecule.hpp"
|
---|
18 | #include "tesselation.hpp"
|
---|
19 | #include "tesselationhelpers.hpp"
|
---|
20 | #include "triangleintersectionlist.hpp"
|
---|
21 | #include "vector.hpp"
|
---|
22 | #include "Matrix.hpp"
|
---|
23 | #include "verbose.hpp"
|
---|
24 | #include "World.hpp"
|
---|
25 | #include "Box.hpp"
|
---|
26 |
|
---|
27 |
|
---|
28 | /** Calculates the pair correlation between given elements.
|
---|
29 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
|
---|
30 | * \param *molecules list of molecules structure
|
---|
31 | * \param &elements vector of elements to correlate
|
---|
32 | * \return Map of doubles with values the pair of the two atoms.
|
---|
33 | */
|
---|
34 | PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements)
|
---|
35 | {
|
---|
36 | Info FunctionInfo(__func__);
|
---|
37 | PairCorrelationMap *outmap = NULL;
|
---|
38 | double distance = 0.;
|
---|
39 | Box &domain = World::getInstance().getDomain();
|
---|
40 |
|
---|
41 | if (molecules->ListOfMolecules.empty()) {
|
---|
42 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
43 | return outmap;
|
---|
44 | }
|
---|
45 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
46 | (*MolWalker)->doCountAtoms();
|
---|
47 |
|
---|
48 | // create all possible pairs of elements
|
---|
49 | set <pair<element *, element *> > PairsOfElements;
|
---|
50 | if (elements.size() >= 2) {
|
---|
51 | for (vector<element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
|
---|
52 | for (vector<element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
|
---|
53 | if (type1 != type2) {
|
---|
54 | PairsOfElements.insert( pair<element *, element*>(*type1,*type2) );
|
---|
55 | DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << (*type1)->symbol << " and " << (*type2)->symbol << "." << endl);
|
---|
56 | }
|
---|
57 | } else if (elements.size() == 1) { // one to all are valid
|
---|
58 | element *elemental = *elements.begin();
|
---|
59 | PairsOfElements.insert( pair<element *, element*>(elemental,(element *)NULL) );
|
---|
60 | PairsOfElements.insert( pair<element *, element*>((element *)NULL,elemental) );
|
---|
61 | } else { // all elements valid
|
---|
62 | PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
|
---|
63 | }
|
---|
64 |
|
---|
65 | outmap = new PairCorrelationMap;
|
---|
66 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
|
---|
67 | if ((*MolWalker)->ActiveFlag) {
|
---|
68 | DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
69 | eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
|
---|
70 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
71 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
72 | for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
|
---|
73 | if ((*MolOtherWalker)->ActiveFlag) {
|
---|
74 | DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
|
---|
75 | for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
|
---|
76 | DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
|
---|
77 | if ((*iter)->getId() < (*runner)->getId()){
|
---|
78 | for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
---|
79 | if ((PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {
|
---|
80 | distance = domain.periodicDistance(*(*iter)->node,*(*runner)->node);
|
---|
81 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
---|
82 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|
91 | return outmap;
|
---|
92 | };
|
---|
93 |
|
---|
94 | /** Calculates the pair correlation between given elements.
|
---|
95 | * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
|
---|
96 | * \param *molecules list of molecules structure
|
---|
97 | * \param &elements vector of elements to correlate
|
---|
98 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also
|
---|
99 | * \return Map of doubles with values the pair of the two atoms.
|
---|
100 | */
|
---|
101 | PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const int ranges[NDIM] )
|
---|
102 | {
|
---|
103 | Info FunctionInfo(__func__);
|
---|
104 | PairCorrelationMap *outmap = NULL;
|
---|
105 | double distance = 0.;
|
---|
106 | int n[NDIM];
|
---|
107 | Vector checkX;
|
---|
108 | Vector periodicX;
|
---|
109 | int Othern[NDIM];
|
---|
110 | Vector checkOtherX;
|
---|
111 | Vector periodicOtherX;
|
---|
112 |
|
---|
113 | if (molecules->ListOfMolecules.empty()) {
|
---|
114 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
115 | return outmap;
|
---|
116 | }
|
---|
117 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
118 | (*MolWalker)->doCountAtoms();
|
---|
119 |
|
---|
120 | // create all possible pairs of elements
|
---|
121 | set <pair<element *, element *> > PairsOfElements;
|
---|
122 | if (elements.size() >= 2) {
|
---|
123 | for (vector<element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
|
---|
124 | for (vector<element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
|
---|
125 | if (type1 != type2) {
|
---|
126 | PairsOfElements.insert( pair<element *, element*>(*type1,*type2) );
|
---|
127 | DoLog(1) && (Log() << Verbose(1) << "Creating element pair " << (*type1)->symbol << " and " << (*type2)->symbol << "." << endl);
|
---|
128 | }
|
---|
129 | } else if (elements.size() == 1) { // one to all are valid
|
---|
130 | element *elemental = *elements.begin();
|
---|
131 | PairsOfElements.insert( pair<element *, element*>(elemental,(element *)NULL) );
|
---|
132 | PairsOfElements.insert( pair<element *, element*>((element *)NULL,elemental) );
|
---|
133 | } else { // all elements valid
|
---|
134 | PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
|
---|
135 | }
|
---|
136 |
|
---|
137 | outmap = new PairCorrelationMap;
|
---|
138 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
|
---|
139 | if ((*MolWalker)->ActiveFlag) {
|
---|
140 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
141 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
142 | DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
143 | eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
|
---|
144 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
145 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
146 | periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
|
---|
147 | // go through every range in xyz and get distance
|
---|
148 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
---|
149 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
---|
150 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
---|
151 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
152 | for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++){
|
---|
153 | if ((*MolOtherWalker)->ActiveFlag) {
|
---|
154 | DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
|
---|
155 | for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
|
---|
156 | DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << **runner << "." << endl);
|
---|
157 | if ((*iter)->getId() < (*runner)->getId()){
|
---|
158 | for (set <pair<element *, element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
|
---|
159 | if ((PairRunner->first == (**iter).type) && (PairRunner->second == (**runner).type)) {
|
---|
160 | periodicOtherX = FullInverseMatrix * (*(*runner)->node); // x now in [0,1)^3
|
---|
161 | // go through every range in xyz and get distance
|
---|
162 | for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
|
---|
163 | for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
|
---|
164 | for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
|
---|
165 | checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
|
---|
166 | distance = checkX.distance(checkOtherX);
|
---|
167 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
---|
168 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
---|
169 | }
|
---|
170 | }
|
---|
171 | }
|
---|
172 | }
|
---|
173 | }
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | return outmap;
|
---|
181 | };
|
---|
182 |
|
---|
183 | /** Calculates the distance (pair) correlation between a given element and a point.
|
---|
184 | * \param *molecules list of molecules structure
|
---|
185 | * \param &elements vector of elements to correlate with point
|
---|
186 | * \param *point vector to the correlation point
|
---|
187 | * \return Map of dobules with values as pairs of atom and the vector
|
---|
188 | */
|
---|
189 | CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point )
|
---|
190 | {
|
---|
191 | Info FunctionInfo(__func__);
|
---|
192 | CorrelationToPointMap *outmap = NULL;
|
---|
193 | double distance = 0.;
|
---|
194 | Box &domain = World::getInstance().getDomain();
|
---|
195 |
|
---|
196 | if (molecules->ListOfMolecules.empty()) {
|
---|
197 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
198 | return outmap;
|
---|
199 | }
|
---|
200 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
201 | (*MolWalker)->doCountAtoms();
|
---|
202 | outmap = new CorrelationToPointMap;
|
---|
203 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
204 | if ((*MolWalker)->ActiveFlag) {
|
---|
205 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
206 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
207 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
208 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
209 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
---|
210 | distance = domain.periodicDistance(*(*iter)->node,*point);
|
---|
211 | DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
|
---|
212 | outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
|
---|
213 | }
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | return outmap;
|
---|
218 | };
|
---|
219 |
|
---|
220 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
|
---|
221 | * \param *molecules list of molecules structure
|
---|
222 | * \param &elements vector of elements to correlate to point
|
---|
223 | * \param *point vector to the correlation point
|
---|
224 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also
|
---|
225 | * \return Map of dobules with values as pairs of atom and the vector
|
---|
226 | */
|
---|
227 | CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point, const int ranges[NDIM] )
|
---|
228 | {
|
---|
229 | Info FunctionInfo(__func__);
|
---|
230 | CorrelationToPointMap *outmap = NULL;
|
---|
231 | double distance = 0.;
|
---|
232 | int n[NDIM];
|
---|
233 | Vector periodicX;
|
---|
234 | Vector checkX;
|
---|
235 |
|
---|
236 | if (molecules->ListOfMolecules.empty()) {
|
---|
237 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
238 | return outmap;
|
---|
239 | }
|
---|
240 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
241 | (*MolWalker)->doCountAtoms();
|
---|
242 | outmap = new CorrelationToPointMap;
|
---|
243 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
244 | if ((*MolWalker)->ActiveFlag) {
|
---|
245 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
246 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
247 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
248 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
249 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
250 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
251 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
---|
252 | periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
|
---|
253 | // go through every range in xyz and get distance
|
---|
254 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
---|
255 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
---|
256 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
---|
257 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
258 | distance = checkX.distance(*point);
|
---|
259 | DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
|
---|
260 | outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
|
---|
261 | }
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 |
|
---|
266 | return outmap;
|
---|
267 | };
|
---|
268 |
|
---|
269 | /** Calculates the distance (pair) correlation between a given element and a surface.
|
---|
270 | * \param *molecules list of molecules structure
|
---|
271 | * \param &elements vector of elements to correlate to surface
|
---|
272 | * \param *Surface pointer to Tesselation class surface
|
---|
273 | * \param *LC LinkedCell structure to quickly find neighbouring atoms
|
---|
274 | * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
|
---|
275 | */
|
---|
276 | CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
|
---|
277 | {
|
---|
278 | Info FunctionInfo(__func__);
|
---|
279 | CorrelationToSurfaceMap *outmap = NULL;
|
---|
280 | double distance = 0;
|
---|
281 | class BoundaryTriangleSet *triangle = NULL;
|
---|
282 | Vector centroid;
|
---|
283 |
|
---|
284 | if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
|
---|
285 | DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
286 | return outmap;
|
---|
287 | }
|
---|
288 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
289 | (*MolWalker)->doCountAtoms();
|
---|
290 | outmap = new CorrelationToSurfaceMap;
|
---|
291 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
292 | if ((*MolWalker)->ActiveFlag) {
|
---|
293 | DoLog(1) && (Log() << Verbose(1) << "Current molecule is " << (*MolWalker)->name << "." << endl);
|
---|
294 | if ((*MolWalker)->empty())
|
---|
295 | DoLog(1) && (1) && (Log() << Verbose(1) << "\t is empty." << endl);
|
---|
296 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
297 | DoLog(1) && (Log() << Verbose(1) << "\tCurrent atom is " << *(*iter) << "." << endl);
|
---|
298 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
299 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
---|
300 | TriangleIntersectionList Intersections((*iter)->node,Surface,LC);
|
---|
301 | distance = Intersections.GetSmallestDistance();
|
---|
302 | triangle = Intersections.GetClosestTriangle();
|
---|
303 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
|
---|
304 | }
|
---|
305 | }
|
---|
306 | } else {
|
---|
307 | DoLog(1) && (Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl);
|
---|
308 | }
|
---|
309 |
|
---|
310 | return outmap;
|
---|
311 | };
|
---|
312 |
|
---|
313 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
|
---|
314 | * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
|
---|
315 | * 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
|
---|
316 | * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
|
---|
317 | * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
|
---|
318 | * \param *molecules list of molecules structure
|
---|
319 | * \param &elements vector of elements to correlate to surface
|
---|
320 | * \param *Surface pointer to Tesselation class surface
|
---|
321 | * \param *LC LinkedCell structure to quickly find neighbouring atoms
|
---|
322 | * \param ranges[NDIM] interval boundaries for the periodic images to scan also
|
---|
323 | * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
|
---|
324 | */
|
---|
325 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
|
---|
326 | {
|
---|
327 | Info FunctionInfo(__func__);
|
---|
328 | CorrelationToSurfaceMap *outmap = NULL;
|
---|
329 | double distance = 0;
|
---|
330 | class BoundaryTriangleSet *triangle = NULL;
|
---|
331 | Vector centroid;
|
---|
332 | int n[NDIM];
|
---|
333 | Vector periodicX;
|
---|
334 | Vector checkX;
|
---|
335 |
|
---|
336 | if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
|
---|
337 | DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
338 | return outmap;
|
---|
339 | }
|
---|
340 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
341 | (*MolWalker)->doCountAtoms();
|
---|
342 | outmap = new CorrelationToSurfaceMap;
|
---|
343 | double ShortestDistance = 0.;
|
---|
344 | BoundaryTriangleSet *ShortestTriangle = NULL;
|
---|
345 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
346 | if ((*MolWalker)->ActiveFlag) {
|
---|
347 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
348 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
349 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
350 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
351 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
352 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
353 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
---|
354 | periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
|
---|
355 | // go through every range in xyz and get distance
|
---|
356 | ShortestDistance = -1.;
|
---|
357 | for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
|
---|
358 | for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
|
---|
359 | for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
|
---|
360 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
361 | TriangleIntersectionList Intersections(&checkX,Surface,LC);
|
---|
362 | distance = Intersections.GetSmallestDistance();
|
---|
363 | triangle = Intersections.GetClosestTriangle();
|
---|
364 | if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
|
---|
365 | ShortestDistance = distance;
|
---|
366 | ShortestTriangle = triangle;
|
---|
367 | }
|
---|
368 | }
|
---|
369 | // insert
|
---|
370 | outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
|
---|
371 | //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
|
---|
372 | }
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | return outmap;
|
---|
377 | };
|
---|
378 |
|
---|
379 | /** Returns the index of the bin for a given value.
|
---|
380 | * \param value value whose bin to look for
|
---|
381 | * \param BinWidth width of bin
|
---|
382 | * \param BinStart first bin
|
---|
383 | */
|
---|
384 | int GetBin ( const double value, const double BinWidth, const double BinStart )
|
---|
385 | {
|
---|
386 | Info FunctionInfo(__func__);
|
---|
387 | int bin =(int) (floor((value - BinStart)/BinWidth));
|
---|
388 | return (bin);
|
---|
389 | };
|
---|
390 |
|
---|
391 |
|
---|
392 | /** Prints correlation (double, int) pairs to file.
|
---|
393 | * \param *file file to write to
|
---|
394 | * \param *map map to write
|
---|
395 | */
|
---|
396 | void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
|
---|
397 | {
|
---|
398 | Info FunctionInfo(__func__);
|
---|
399 | *file << "BinStart\tCount" << endl;
|
---|
400 | for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
401 | *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
|
---|
402 | }
|
---|
403 | };
|
---|
404 |
|
---|
405 | /** Prints correlation (double, (atom*,atom*) ) pairs to file.
|
---|
406 | * \param *file file to write to
|
---|
407 | * \param *map map to write
|
---|
408 | */
|
---|
409 | void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
|
---|
410 | {
|
---|
411 | Info FunctionInfo(__func__);
|
---|
412 | *file << "BinStart\tAtom1\tAtom2" << endl;
|
---|
413 | for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
414 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
|
---|
415 | }
|
---|
416 | };
|
---|
417 |
|
---|
418 | /** Prints correlation (double, int) pairs to file.
|
---|
419 | * \param *file file to write to
|
---|
420 | * \param *map map to write
|
---|
421 | */
|
---|
422 | void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
|
---|
423 | {
|
---|
424 | Info FunctionInfo(__func__);
|
---|
425 | *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
|
---|
426 | for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
427 | *file << runner->first;
|
---|
428 | for (int i=0;i<NDIM;i++)
|
---|
429 | *file << "\t" << setprecision(8) << (runner->second.first->node->at(i) - runner->second.second->at(i));
|
---|
430 | *file << endl;
|
---|
431 | }
|
---|
432 | };
|
---|
433 |
|
---|
434 | /** Prints correlation (double, int) pairs to file.
|
---|
435 | * \param *file file to write to
|
---|
436 | * \param *map map to write
|
---|
437 | */
|
---|
438 | void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
|
---|
439 | {
|
---|
440 | Info FunctionInfo(__func__);
|
---|
441 | *file << "BinStart\tTriangle" << endl;
|
---|
442 | if (!map->empty())
|
---|
443 | for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
444 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
|
---|
445 | }
|
---|
446 | };
|
---|
447 |
|
---|