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