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