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