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