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