[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 |
|
---|
| 13 | #include "analysis_correlation.hpp"
|
---|
| 14 | #include "element.hpp"
|
---|
[3930eb] | 15 | #include "info.hpp"
|
---|
[e138de] | 16 | #include "log.hpp"
|
---|
[c4d4df] | 17 | #include "molecule.hpp"
|
---|
| 18 | #include "tesselation.hpp"
|
---|
| 19 | #include "tesselationhelpers.hpp"
|
---|
[8db598] | 20 | #include "triangleintersectionlist.hpp"
|
---|
[c4d4df] | 21 | #include "vector.hpp"
|
---|
[c94eeb] | 22 | #include "Matrix.hpp"
|
---|
[a5551b] | 23 | #include "verbose.hpp"
|
---|
[b34306] | 24 | #include "World.hpp"
|
---|
[84c494] | 25 | #include "Box.hpp"
|
---|
[c4d4df] | 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))
|
---|
[a5551b] | 30 | * \param *molecules list of molecules structure
|
---|
[c78d44] | 31 | * \param &elements vector of elements to correlate
|
---|
[c4d4df] | 32 | * \return Map of doubles with values the pair of the two atoms.
|
---|
| 33 | */
|
---|
[c78d44] | 34 | PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements)
|
---|
[c4d4df] | 35 | {
|
---|
[3930eb] | 36 | Info FunctionInfo(__func__);
|
---|
[c4d4df] | 37 | PairCorrelationMap *outmap = NULL;
|
---|
| 38 | double distance = 0.;
|
---|
[014475] | 39 | Box &domain = World::getInstance().getDomain();
|
---|
[c4d4df] | 40 |
|
---|
[a5551b] | 41 | if (molecules->ListOfMolecules.empty()) {
|
---|
[58ed4a] | 42 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
[c4d4df] | 43 | return outmap;
|
---|
| 44 | }
|
---|
[009607e] | 45 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 46 | (*MolWalker)->doCountAtoms();
|
---|
[c78d44] | 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 |
|
---|
[c4d4df] | 65 | outmap = new PairCorrelationMap;
|
---|
[24725c] | 66 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
|
---|
[a5551b] | 67 | if ((*MolWalker)->ActiveFlag) {
|
---|
[58ed4a] | 68 | DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
[e138de] | 69 | eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
|
---|
[9879f6] | 70 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
[a7b761b] | 71 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
[c78d44] | 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)) {
|
---|
[014475] | 80 | distance = domain.periodicDistance(*(*iter)->node,*(*runner)->node);
|
---|
[9879f6] | 81 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
---|
| 82 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
---|
[a5551b] | 83 | }
|
---|
| 84 | }
|
---|
[24725c] | 85 | }
|
---|
[c4d4df] | 86 | }
|
---|
[a5551b] | 87 | }
|
---|
[c4d4df] | 88 | }
|
---|
| 89 | }
|
---|
[24725c] | 90 | }
|
---|
[c4d4df] | 91 | return outmap;
|
---|
| 92 | };
|
---|
| 93 |
|
---|
[7ea9e6] | 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
|
---|
[c78d44] | 97 | * \param &elements vector of elements to correlate
|
---|
[7ea9e6] | 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 | */
|
---|
[c78d44] | 101 | PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const int ranges[NDIM] )
|
---|
[7ea9e6] | 102 | {
|
---|
[3930eb] | 103 | Info FunctionInfo(__func__);
|
---|
[7ea9e6] | 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()) {
|
---|
[58ed4a] | 114 | DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
|
---|
[7ea9e6] | 115 | return outmap;
|
---|
| 116 | }
|
---|
[009607e] | 117 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 118 | (*MolWalker)->doCountAtoms();
|
---|
[c78d44] | 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 |
|
---|
[7ea9e6] | 137 | outmap = new PairCorrelationMap;
|
---|
[c78d44] | 138 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++){
|
---|
[7ea9e6] | 139 | if ((*MolWalker)->ActiveFlag) {
|
---|
[84c494] | 140 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
| 141 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
[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);
|
---|
[5108e1] | 146 | periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
|
---|
[c78d44] | 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]++) {
|
---|
[5108e1] | 151 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
[c78d44] | 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)) {
|
---|
[5108e1] | 160 | periodicOtherX = FullInverseMatrix * (*(*runner)->node); // x now in [0,1)^3
|
---|
[7ea9e6] | 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]++) {
|
---|
[5108e1] | 165 | checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
|
---|
[1513a74] | 166 | distance = checkX.distance(checkOtherX);
|
---|
[9879f6] | 167 | //Log() << Verbose(1) <<"Inserting " << *(*iter) << " and " << *(*runner) << endl;
|
---|
| 168 | outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
|
---|
[7ea9e6] | 169 | }
|
---|
| 170 | }
|
---|
[c78d44] | 171 | }
|
---|
[7ea9e6] | 172 | }
|
---|
[c78d44] | 173 | }
|
---|
[7ea9e6] | 174 | }
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
[c78d44] | 178 | }
|
---|
[7ea9e6] | 179 |
|
---|
| 180 | return outmap;
|
---|
| 181 | };
|
---|
| 182 |
|
---|
[c4d4df] | 183 | /** Calculates the distance (pair) correlation between a given element and a point.
|
---|
[a5551b] | 184 | * \param *molecules list of molecules structure
|
---|
[c78d44] | 185 | * \param &elements vector of elements to correlate with point
|
---|
[c4d4df] | 186 | * \param *point vector to the correlation point
|
---|
| 187 | * \return Map of dobules with values as pairs of atom and the vector
|
---|
| 188 | */
|
---|
[c78d44] | 189 | CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point )
|
---|
[c4d4df] | 190 | {
|
---|
[3930eb] | 191 | Info FunctionInfo(__func__);
|
---|
[c4d4df] | 192 | CorrelationToPointMap *outmap = NULL;
|
---|
| 193 | double distance = 0.;
|
---|
[014475] | 194 | Box &domain = World::getInstance().getDomain();
|
---|
[c4d4df] | 195 |
|
---|
[a5551b] | 196 | if (molecules->ListOfMolecules.empty()) {
|
---|
[a67d19] | 197 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
[c4d4df] | 198 | return outmap;
|
---|
| 199 | }
|
---|
[009607e] | 200 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 201 | (*MolWalker)->doCountAtoms();
|
---|
[c4d4df] | 202 | outmap = new CorrelationToPointMap;
|
---|
[a5551b] | 203 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 204 | if ((*MolWalker)->ActiveFlag) {
|
---|
[a67d19] | 205 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
[9879f6] | 206 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
[a7b761b] | 207 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
[c78d44] | 208 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
| 209 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
---|
[014475] | 210 | distance = domain.periodicDistance(*(*iter)->node,*point);
|
---|
[c78d44] | 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 | }
|
---|
[a5551b] | 214 | }
|
---|
[c4d4df] | 215 | }
|
---|
| 216 |
|
---|
| 217 | return outmap;
|
---|
| 218 | };
|
---|
| 219 |
|
---|
[7ea9e6] | 220 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
|
---|
| 221 | * \param *molecules list of molecules structure
|
---|
[c78d44] | 222 | * \param &elements vector of elements to correlate to point
|
---|
[7ea9e6] | 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 | */
|
---|
[c78d44] | 227 | CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Vector *point, const int ranges[NDIM] )
|
---|
[7ea9e6] | 228 | {
|
---|
[3930eb] | 229 | Info FunctionInfo(__func__);
|
---|
[7ea9e6] | 230 | CorrelationToPointMap *outmap = NULL;
|
---|
| 231 | double distance = 0.;
|
---|
| 232 | int n[NDIM];
|
---|
| 233 | Vector periodicX;
|
---|
| 234 | Vector checkX;
|
---|
| 235 |
|
---|
| 236 | if (molecules->ListOfMolecules.empty()) {
|
---|
[a67d19] | 237 | DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
|
---|
[7ea9e6] | 238 | return outmap;
|
---|
| 239 | }
|
---|
[009607e] | 240 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 241 | (*MolWalker)->doCountAtoms();
|
---|
[7ea9e6] | 242 | outmap = new CorrelationToPointMap;
|
---|
| 243 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 244 | if ((*MolWalker)->ActiveFlag) {
|
---|
[84c494] | 245 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
| 246 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
[a67d19] | 247 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
[9879f6] | 248 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
[a7b761b] | 249 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
[c78d44] | 250 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
| 251 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
---|
[5108e1] | 252 | periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
|
---|
[c78d44] | 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]++) {
|
---|
[5108e1] | 257 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
[c78d44] | 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 | }
|
---|
[7ea9e6] | 263 | }
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | return outmap;
|
---|
| 267 | };
|
---|
| 268 |
|
---|
[c4d4df] | 269 | /** Calculates the distance (pair) correlation between a given element and a surface.
|
---|
[a5551b] | 270 | * \param *molecules list of molecules structure
|
---|
[c78d44] | 271 | * \param &elements vector of elements to correlate to surface
|
---|
[c4d4df] | 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 | */
|
---|
[c78d44] | 276 | CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
|
---|
[c4d4df] | 277 | {
|
---|
[3930eb] | 278 | Info FunctionInfo(__func__);
|
---|
[c4d4df] | 279 | CorrelationToSurfaceMap *outmap = NULL;
|
---|
[99593f] | 280 | double distance = 0;
|
---|
[c4d4df] | 281 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 282 | Vector centroid;
|
---|
[7ea9e6] | 283 |
|
---|
| 284 | if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
|
---|
[58ed4a] | 285 | DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
[7ea9e6] | 286 | return outmap;
|
---|
| 287 | }
|
---|
[009607e] | 288 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 289 | (*MolWalker)->doCountAtoms();
|
---|
[7ea9e6] | 290 | outmap = new CorrelationToSurfaceMap;
|
---|
| 291 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 292 | if ((*MolWalker)->ActiveFlag) {
|
---|
[a67d19] | 293 | DoLog(1) && (Log() << Verbose(1) << "Current molecule is " << (*MolWalker)->name << "." << endl);
|
---|
[7fd416] | 294 | if ((*MolWalker)->empty())
|
---|
| 295 | DoLog(1) && (1) && (Log() << Verbose(1) << "\t is empty." << endl);
|
---|
[9879f6] | 296 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
[7fd416] | 297 | DoLog(1) && (Log() << Verbose(1) << "\tCurrent atom is " << *(*iter) << "." << endl);
|
---|
[c78d44] | 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 | }
|
---|
[7ea9e6] | 305 | }
|
---|
[7fd416] | 306 | } else {
|
---|
[a67d19] | 307 | DoLog(1) && (Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl);
|
---|
[7fd416] | 308 | }
|
---|
[7ea9e6] | 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
|
---|
[c78d44] | 319 | * \param &elements vector of elements to correlate to surface
|
---|
[7ea9e6] | 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 | */
|
---|
[c78d44] | 325 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const std::vector<element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
|
---|
[7ea9e6] | 326 | {
|
---|
[3930eb] | 327 | Info FunctionInfo(__func__);
|
---|
[7ea9e6] | 328 | CorrelationToSurfaceMap *outmap = NULL;
|
---|
| 329 | double distance = 0;
|
---|
| 330 | class BoundaryTriangleSet *triangle = NULL;
|
---|
| 331 | Vector centroid;
|
---|
[99593f] | 332 | int n[NDIM];
|
---|
| 333 | Vector periodicX;
|
---|
| 334 | Vector checkX;
|
---|
[c4d4df] | 335 |
|
---|
[a5551b] | 336 | if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
|
---|
[a67d19] | 337 | DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
|
---|
[c4d4df] | 338 | return outmap;
|
---|
| 339 | }
|
---|
[009607e] | 340 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 341 | (*MolWalker)->doCountAtoms();
|
---|
[c4d4df] | 342 | outmap = new CorrelationToSurfaceMap;
|
---|
[244a84] | 343 | double ShortestDistance = 0.;
|
---|
| 344 | BoundaryTriangleSet *ShortestTriangle = NULL;
|
---|
[a5551b] | 345 | for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
|
---|
| 346 | if ((*MolWalker)->ActiveFlag) {
|
---|
[84c494] | 347 | Matrix FullMatrix = World::getInstance().getDomain().getM();
|
---|
| 348 | Matrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
|
---|
[a67d19] | 349 | DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
|
---|
[9879f6] | 350 | for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
|
---|
[a7b761b] | 351 | DoLog(3) && (Log() << Verbose(3) << "Current atom is " << **iter << "." << endl);
|
---|
[c78d44] | 352 | for (vector<element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
|
---|
| 353 | if ((*type == NULL) || ((*iter)->type == *type)) {
|
---|
[5108e1] | 354 | periodicX = FullInverseMatrix * (*(*iter)->node); // x now in [0,1)^3
|
---|
[c78d44] | 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]++) {
|
---|
[5108e1] | 360 | checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
|
---|
[c78d44] | 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 | }
|
---|
[99593f] | 368 | }
|
---|
[c78d44] | 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 | }
|
---|
[c4d4df] | 373 | }
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | return outmap;
|
---|
| 377 | };
|
---|
| 378 |
|
---|
[bd61b41] | 379 | /** Returns the index of the bin for a given value.
|
---|
[c4d4df] | 380 | * \param value value whose bin to look for
|
---|
| 381 | * \param BinWidth width of bin
|
---|
| 382 | * \param BinStart first bin
|
---|
| 383 | */
|
---|
[bd61b41] | 384 | int GetBin ( const double value, const double BinWidth, const double BinStart )
|
---|
[c4d4df] | 385 | {
|
---|
[3930eb] | 386 | Info FunctionInfo(__func__);
|
---|
[bd61b41] | 387 | int bin =(int) (floor((value - BinStart)/BinWidth));
|
---|
| 388 | return (bin);
|
---|
[c4d4df] | 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 | */
|
---|
[a5551b] | 396 | void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
|
---|
[c4d4df] | 397 | {
|
---|
[3930eb] | 398 | Info FunctionInfo(__func__);
|
---|
[790807] | 399 | *file << "BinStart\tCount" << endl;
|
---|
[776b64] | 400 | for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
[775d133] | 401 | *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
|
---|
[c4d4df] | 402 | }
|
---|
| 403 | };
|
---|
[b1f254] | 404 |
|
---|
| 405 | /** Prints correlation (double, (atom*,atom*) ) pairs to file.
|
---|
| 406 | * \param *file file to write to
|
---|
| 407 | * \param *map map to write
|
---|
| 408 | */
|
---|
[a5551b] | 409 | void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
|
---|
[b1f254] | 410 | {
|
---|
[3930eb] | 411 | Info FunctionInfo(__func__);
|
---|
[790807] | 412 | *file << "BinStart\tAtom1\tAtom2" << endl;
|
---|
[776b64] | 413 | for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
[775d133] | 414 | *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
|
---|
[b1f254] | 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 | */
|
---|
[a5551b] | 422 | void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
|
---|
[b1f254] | 423 | {
|
---|
[3930eb] | 424 | Info FunctionInfo(__func__);
|
---|
[790807] | 425 | *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
|
---|
[776b64] | 426 | for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
[b1f254] | 427 | *file << runner->first;
|
---|
| 428 | for (int i=0;i<NDIM;i++)
|
---|
[8cbb97] | 429 | *file << "\t" << setprecision(8) << (runner->second.first->node->at(i) - runner->second.second->at(i));
|
---|
[b1f254] | 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 | */
|
---|
[a5551b] | 438 | void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
|
---|
[b1f254] | 439 | {
|
---|
[3930eb] | 440 | Info FunctionInfo(__func__);
|
---|
[790807] | 441 | *file << "BinStart\tTriangle" << endl;
|
---|
[8db598] | 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 | }
|
---|
[b1f254] | 446 | };
|
---|
| 447 |
|
---|