| [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 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 21 | 
 | 
|---|
| [c4d4df] | 22 | #include <iostream>
 | 
|---|
| [36166d] | 23 | #include <iomanip>
 | 
|---|
| [505d05] | 24 | #include <limits>
 | 
|---|
| [c4d4df] | 25 | 
 | 
|---|
| [be945c] | 26 | #include "atom.hpp"
 | 
|---|
| [129204] | 27 | #include "Bond/bond.hpp"
 | 
|---|
| [d127c8] | 28 | #include "Tesselation/BoundaryTriangleSet.hpp"
 | 
|---|
| [be945c] | 29 | #include "Box.hpp"
 | 
|---|
| [3bdb6d] | 30 | #include "Element/element.hpp"
 | 
|---|
| [ad011c] | 31 | #include "CodePatterns/Info.hpp"
 | 
|---|
 | 32 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [208237b] | 33 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [e65878] | 34 | #include "Descriptors/AtomOfMoleculeSelectionDescriptor.hpp"
 | 
|---|
 | 35 | #include "Descriptors/MoleculeFormulaDescriptor.hpp"
 | 
|---|
| [4b8630] | 36 | #include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
 | 
|---|
| [ea430a] | 37 | #include "Formula.hpp"
 | 
|---|
| [208237b] | 38 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 39 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| [c4d4df] | 40 | #include "molecule.hpp"
 | 
|---|
| [d127c8] | 41 | #include "Tesselation/tesselation.hpp"
 | 
|---|
 | 42 | #include "Tesselation/tesselationhelpers.hpp"
 | 
|---|
 | 43 | #include "Tesselation/triangleintersectionlist.hpp"
 | 
|---|
| [be945c] | 44 | #include "World.hpp"
 | 
|---|
| [208237b] | 45 | #include "WorldTime.hpp"
 | 
|---|
| [c4d4df] | 46 | 
 | 
|---|
| [be945c] | 47 | #include "analysis_correlation.hpp"
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | /** Calculates the dipole vector of a given atomSet.
 | 
|---|
 | 50 |  *
 | 
|---|
 | 51 |  *  Note that we use the following procedure as rule of thumb:
 | 
|---|
 | 52 |  *   -# go through every bond of the atom
 | 
|---|
| [d1912f] | 53 |  *   -# calculate the difference of electronegativities \f$\Delta\mathrm{EN}\f$
 | 
|---|
 | 54 |  *   -# if \f$\Delta\mathrm{EN} > 0.5\f$, we align the bond vector in direction of the more negative element
 | 
|---|
| [be945c] | 55 |  *   -# sum up all vectors
 | 
|---|
 | 56 |  *   -# finally, divide by the number of summed vectors
 | 
|---|
 | 57 |  *
 | 
|---|
 | 58 |  * @param atomsbegin begin iterator of atomSet
 | 
|---|
 | 59 |  * @param atomsend end iterator of atomset
 | 
|---|
 | 60 |  * @return dipole vector
 | 
|---|
 | 61 |  */
 | 
|---|
 | 62 | Vector getDipole(molecule::const_iterator atomsbegin, molecule::const_iterator atomsend)
 | 
|---|
 | 63 | {
 | 
|---|
 | 64 |   Vector DipoleVector;
 | 
|---|
 | 65 |   size_t SumOfVectors = 0;
 | 
|---|
 | 66 |   // go through all atoms
 | 
|---|
 | 67 |   for (molecule::const_iterator atomiter = atomsbegin;
 | 
|---|
 | 68 |       atomiter != atomsend;
 | 
|---|
 | 69 |       ++atomiter) {
 | 
|---|
 | 70 |     // go through all bonds
 | 
|---|
| [9d83b6] | 71 |     const BondList& ListOfBonds = (*atomiter)->getListOfBonds();
 | 
|---|
| [4fc828] | 72 |     ASSERT(ListOfBonds.begin() != ListOfBonds.end(),
 | 
|---|
 | 73 |         "getDipole() - no bonds in molecule!");
 | 
|---|
| [9d83b6] | 74 |     for (BondList::const_iterator bonditer = ListOfBonds.begin();
 | 
|---|
 | 75 |         bonditer != ListOfBonds.end();
 | 
|---|
| [be945c] | 76 |         ++bonditer) {
 | 
|---|
 | 77 |       const atom * Otheratom = (*bonditer)->GetOtherAtom(*atomiter);
 | 
|---|
 | 78 |       if (Otheratom->getId() > (*atomiter)->getId()) {
 | 
|---|
 | 79 |         const double DeltaEN = (*atomiter)->getType()->getElectronegativity()
 | 
|---|
 | 80 |             -Otheratom->getType()->getElectronegativity();
 | 
|---|
 | 81 |         Vector BondDipoleVector = (*atomiter)->getPosition() - Otheratom->getPosition();
 | 
|---|
 | 82 |         // DeltaEN is always positive, gives correct orientation of vector
 | 
|---|
 | 83 |         BondDipoleVector.Normalize();
 | 
|---|
 | 84 |         BondDipoleVector *= DeltaEN;
 | 
|---|
| [4fc828] | 85 |         LOG(3,"INFO: Dipole vector from bond " << **bonditer << " is " << BondDipoleVector);
 | 
|---|
| [be945c] | 86 |         DipoleVector += BondDipoleVector;
 | 
|---|
 | 87 |         SumOfVectors++;
 | 
|---|
 | 88 |       }
 | 
|---|
 | 89 |     }
 | 
|---|
 | 90 |   }
 | 
|---|
| [4fc828] | 91 |   LOG(3,"INFO: Sum over all bond dipole vectors is "
 | 
|---|
 | 92 |       << DipoleVector << " with " << SumOfVectors << " in total.");
 | 
|---|
 | 93 |   if (SumOfVectors != 0)
 | 
|---|
 | 94 |     DipoleVector *= 1./(double)SumOfVectors;
 | 
|---|
| [47d041] | 95 |   LOG(1, "Resulting dipole vector is " << DipoleVector);
 | 
|---|
| [be945c] | 96 | 
 | 
|---|
 | 97 |   return DipoleVector;
 | 
|---|
 | 98 | };
 | 
|---|
 | 99 | 
 | 
|---|
| [1cc661] | 100 | /** Calculate minimum and maximum amount of trajectory steps by going through given atomic trajectories.
 | 
|---|
 | 101 |  * \param vector of atoms whose trajectories to check for [min,max]
 | 
|---|
 | 102 |  * \return range with [min, max]
 | 
|---|
 | 103 |  */
 | 
|---|
| [e65878] | 104 | range<size_t> getMaximumTrajectoryBounds(const std::vector<atom *> &atoms)
 | 
|---|
| [1cc661] | 105 | {
 | 
|---|
 | 106 |   // get highest trajectory size
 | 
|---|
 | 107 |   LOG(0,"STATUS: Retrieving maximum amount of time steps ...");
 | 
|---|
| [505d05] | 108 |   if (atoms.size() == 0)
 | 
|---|
 | 109 |     return range<size_t>(0,0);
 | 
|---|
 | 110 |   size_t max_timesteps = std::numeric_limits<size_t>::min();
 | 
|---|
 | 111 |   size_t min_timesteps = std::numeric_limits<size_t>::max();
 | 
|---|
| [1cc661] | 112 |   BOOST_FOREACH(atom *_atom, atoms) {
 | 
|---|
 | 113 |     if (_atom->getTrajectorySize() > max_timesteps)
 | 
|---|
 | 114 |       max_timesteps  = _atom->getTrajectorySize();
 | 
|---|
| [505d05] | 115 |     if (_atom->getTrajectorySize() < min_timesteps)
 | 
|---|
| [1cc661] | 116 |       min_timesteps = _atom->getTrajectorySize();
 | 
|---|
 | 117 |   }
 | 
|---|
 | 118 |   LOG(1,"INFO: Minimum number of time steps found is " << min_timesteps);
 | 
|---|
 | 119 |   LOG(1,"INFO: Maximum number of time steps found is " << max_timesteps);
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 |   return range<size_t>(min_timesteps, max_timesteps);
 | 
|---|
 | 122 | }
 | 
|---|
 | 123 | 
 | 
|---|
| [0a7fad] | 124 | /** Calculates the angular dipole zero orientation from current time step.
 | 
|---|
| [e65878] | 125 |  * \param molecules vector of molecules to calculate dipoles of
 | 
|---|
| [0a7fad] | 126 |  * \return map with orientation vector for each atomic id given in \a atoms.
 | 
|---|
 | 127 |  */
 | 
|---|
| [e65878] | 128 | std::map<atomId_t, Vector> CalculateZeroAngularDipole(const std::vector<molecule *> &molecules)
 | 
|---|
| [0a7fad] | 129 | {
 | 
|---|
 | 130 |   // get zero orientation for each molecule.
 | 
|---|
| [e65878] | 131 |   LOG(0,"STATUS: Calculating dipoles for current time step ...");
 | 
|---|
| [0a7fad] | 132 |   std::map<atomId_t, Vector> ZeroVector;
 | 
|---|
 | 133 |   BOOST_FOREACH(molecule *_mol, molecules) {
 | 
|---|
 | 134 |     const Vector Dipole = getDipole(_mol->begin(), _mol->end());
 | 
|---|
 | 135 |     for(molecule::const_iterator iter = _mol->begin(); iter != _mol->end(); ++iter)
 | 
|---|
 | 136 |       ZeroVector[(*iter)->getId()] = Dipole;
 | 
|---|
 | 137 |     LOG(2,"INFO: Zero alignment for molecule " << _mol->getId() << " is " << Dipole);
 | 
|---|
 | 138 |   }
 | 
|---|
 | 139 |   LOG(1,"INFO: We calculated zero orientation for a total of " << molecules.size() << " molecule(s).");
 | 
|---|
 | 140 | 
 | 
|---|
 | 141 |   return ZeroVector;
 | 
|---|
 | 142 | }
 | 
|---|
| [1cc661] | 143 | 
 | 
|---|
| [ea430a] | 144 | /** Calculates the dipole angular correlation for given molecule type.
 | 
|---|
| [208237b] | 145 |  * Calculate the change of the dipole orientation angle over time.
 | 
|---|
| [ea430a] | 146 |  * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
 | 
|---|
| [be945c] | 147 |  * Angles are given in degrees.
 | 
|---|
| [4b8630] | 148 |  * \param &atoms list of atoms of the molecules taking part (Note: molecules may
 | 
|---|
 | 149 |  * change over time as bond structure is recalculated, hence we need the atoms)
 | 
|---|
| [cda81d] | 150 |  * \param timestep time step to calculate angular correlation for (relative to
 | 
|---|
 | 151 |  *  \a ZeroVector)
 | 
|---|
| [325687] | 152 |  * \param ZeroVector map with Zero orientation vector for each atom in \a atoms.
 | 
|---|
| [99b87a] | 153 |  * \param DontResetTime don't reset time to old value (triggers re-creation of bond system)
 | 
|---|
| [ea430a] | 154 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 155 |  */
 | 
|---|
| [325687] | 156 | DipoleAngularCorrelationMap *DipoleAngularCorrelation(
 | 
|---|
| [e65878] | 157 |     const Formula &DipoleFormula,
 | 
|---|
| [cda81d] | 158 |     const size_t timestep,
 | 
|---|
| [e65878] | 159 |     const std::map<atomId_t, Vector> &ZeroVector,
 | 
|---|
| [99b87a] | 160 |     const enum ResetWorldTime DoTimeReset
 | 
|---|
| [325687] | 161 |     )
 | 
|---|
| [ea430a] | 162 | {
 | 
|---|
 | 163 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 164 |   DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
 | 
|---|
| [be945c] | 165 | 
 | 
|---|
| [99b87a] | 166 |   unsigned int oldtime = 0;
 | 
|---|
 | 167 |   if (DoTimeReset == DoResetTime) {
 | 
|---|
 | 168 |     // store original time step
 | 
|---|
 | 169 |     oldtime = WorldTime::getTime();
 | 
|---|
 | 170 |   }
 | 
|---|
| [0a7fad] | 171 | 
 | 
|---|
| [cda81d] | 172 |   // set time step
 | 
|---|
| [505d05] | 173 |   LOG(0,"STATUS: Stepping onto to time step " << timestep << ".");
 | 
|---|
| [cda81d] | 174 |   World::getInstance().setTime(timestep);
 | 
|---|
 | 175 | 
 | 
|---|
 | 176 |   // get all molecules for this time step
 | 
|---|
| [e65878] | 177 |   World::getInstance().clearMoleculeSelection();
 | 
|---|
 | 178 |   World::getInstance().selectAllMolecules(MoleculeByFormula(DipoleFormula));
 | 
|---|
 | 179 |   std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
 | 
|---|
| [870b4b] | 180 |   LOG(1,"INFO: There are " << molecules.size() << " molecules for time step " << timestep << ".");
 | 
|---|
| [208237b] | 181 | 
 | 
|---|
| [cda81d] | 182 |   // calculate dipoles for each
 | 
|---|
| [870b4b] | 183 |   LOG(0,"STATUS: Calculating dipoles for time step " << timestep << " ...");
 | 
|---|
| [cda81d] | 184 |   size_t i=0;
 | 
|---|
| [870b4b] | 185 |   size_t Counter_rejections = 0;
 | 
|---|
| [cda81d] | 186 |   BOOST_FOREACH(molecule *_mol, molecules) {
 | 
|---|
 | 187 |     const Vector Dipole = getDipole(_mol->begin(), _mol->end());
 | 
|---|
| [e65878] | 188 |     LOG(3,"INFO: Dipole vector at time step " << timestep << " for for molecule "
 | 
|---|
| [cda81d] | 189 |         << _mol->getId() << " is " << Dipole);
 | 
|---|
| [e65878] | 190 |     // check that all atoms are valid (zeroVector known)
 | 
|---|
| [cda81d] | 191 |     molecule::const_iterator iter = _mol->begin();
 | 
|---|
| [e65878] | 192 |     for(; iter != _mol->end(); ++iter) {
 | 
|---|
 | 193 |       if (!ZeroVector.count((*iter)->getId()))
 | 
|---|
 | 194 |         break;
 | 
|---|
 | 195 |     }
 | 
|---|
 | 196 |     if (iter != _mol->end()) {
 | 
|---|
 | 197 |       ELOG(2, "Skipping molecule " << _mol->getName() << " as not all atoms have a valid zeroVector.");
 | 
|---|
| [870b4b] | 198 |       ++Counter_rejections;
 | 
|---|
| [e65878] | 199 |       continue;
 | 
|---|
 | 200 |     } else
 | 
|---|
 | 201 |       iter = _mol->begin();
 | 
|---|
 | 202 |     std::map<atomId_t, Vector>::const_iterator zeroValue = ZeroVector.find((*iter)->getId()); //due to iter is const
 | 
|---|
| [cda81d] | 203 |     double angle = 0.;
 | 
|---|
 | 204 |     LOG(2, "INFO: ZeroVector of first atom " << **iter << " is "
 | 
|---|
| [e65878] | 205 |         << zeroValue->second << ".");
 | 
|---|
| [cda81d] | 206 |     LOG(4, "INFO: Squared norm of difference vector is "
 | 
|---|
| [e65878] | 207 |         << (zeroValue->second - Dipole).NormSquared() << ".");
 | 
|---|
 | 208 |     if ((zeroValue->second - Dipole).NormSquared() > MYEPSILON)
 | 
|---|
 | 209 |       angle = Dipole.Angle(zeroValue->second) * (180./M_PI);
 | 
|---|
| [cda81d] | 210 |     else
 | 
|---|
 | 211 |       LOG(2, "INFO: Both vectors (almost) coincide, numerically unstable, angle set to zero.");
 | 
|---|
 | 212 |     LOG(1,"INFO: Resulting relative angle for molecule " << _mol->getName()
 | 
|---|
 | 213 |         << " is " << angle << ".");
 | 
|---|
 | 214 |     outmap->insert ( make_pair (angle, *iter ) );
 | 
|---|
 | 215 |     ++i;
 | 
|---|
| [208237b] | 216 |   }
 | 
|---|
| [870b4b] | 217 |   ASSERT(Counter_rejections <= molecules.size(),
 | 
|---|
 | 218 |       "DipoleAngularCorrelation() - more rejections ("+toString(Counter_rejections)
 | 
|---|
 | 219 |       +") than there are molecules ("+toString(molecules.size())+").");
 | 
|---|
 | 220 |   LOG(1,"INFO: " << Counter_rejections << " molecules have been rejected in time step " << timestep << ".");
 | 
|---|
 | 221 | 
 | 
|---|
 | 222 |   LOG(0,"STATUS: Done with calculating dipoles.");
 | 
|---|
| [208237b] | 223 | 
 | 
|---|
| [99b87a] | 224 |   if (DoTimeReset == DoResetTime) {
 | 
|---|
 | 225 |     // re-set to original time step again
 | 
|---|
 | 226 |     World::getInstance().setTime(oldtime);
 | 
|---|
 | 227 |   }
 | 
|---|
| [208237b] | 228 | 
 | 
|---|
 | 229 |   // and return results
 | 
|---|
 | 230 |   return outmap;
 | 
|---|
 | 231 | };
 | 
|---|
 | 232 | 
 | 
|---|
 | 233 | /** Calculates the dipole correlation for given molecule type.
 | 
|---|
 | 234 |  * I.e. we calculate how the angle between any two given dipoles in the
 | 
|---|
 | 235 |  * systems behaves. Sort of pair correlation but distance is replaced by
 | 
|---|
 | 236 |  * the orientation distance, i.e. an angle.
 | 
|---|
 | 237 |  * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
 | 
|---|
 | 238 |  * Angles are given in degrees.
 | 
|---|
 | 239 |  * \param *molecules vector of molecules
 | 
|---|
 | 240 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 241 |  */
 | 
|---|
 | 242 | DipoleCorrelationMap *DipoleCorrelation(std::vector<molecule *> &molecules)
 | 
|---|
 | 243 | {
 | 
|---|
 | 244 |   Info FunctionInfo(__func__);
 | 
|---|
 | 245 |   DipoleCorrelationMap *outmap = new DipoleCorrelationMap;
 | 
|---|
 | 246 | //  double distance = 0.;
 | 
|---|
 | 247 | //  Box &domain = World::getInstance().getDomain();
 | 
|---|
 | 248 | //
 | 
|---|
 | 249 |   if (molecules.empty()) {
 | 
|---|
| [47d041] | 250 |     ELOG(1, "No molecule given.");
 | 
|---|
| [208237b] | 251 |     return outmap;
 | 
|---|
 | 252 |   }
 | 
|---|
 | 253 | 
 | 
|---|
| [be945c] | 254 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
 | 
|---|
| [92e5cb] | 255 |       MolWalker != molecules.end(); ++MolWalker) {
 | 
|---|
| [47d041] | 256 |     LOG(2, "INFO: Current molecule is " << (*MolWalker)->getId() << ".");
 | 
|---|
| [be945c] | 257 |     const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
 | 
|---|
| [92e5cb] | 258 |     std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
 | 
|---|
 | 259 |     for (++MolOtherWalker;
 | 
|---|
| [be945c] | 260 |         MolOtherWalker != molecules.end();
 | 
|---|
| [92e5cb] | 261 |         ++MolOtherWalker) {
 | 
|---|
| [47d041] | 262 |       LOG(2, "INFO: Current other molecule is " << (*MolOtherWalker)->getId() << ".");
 | 
|---|
| [be945c] | 263 |       const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
 | 
|---|
 | 264 |       const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
 | 
|---|
| [47d041] | 265 |       LOG(1, "Angle is " << angle << ".");
 | 
|---|
| [be945c] | 266 |       outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
 | 
|---|
 | 267 |     }
 | 
|---|
 | 268 |   }
 | 
|---|
| [ea430a] | 269 |   return outmap;
 | 
|---|
 | 270 | };
 | 
|---|
 | 271 | 
 | 
|---|
| [c4d4df] | 272 | 
 | 
|---|
 | 273 | /** Calculates the pair correlation between given elements.
 | 
|---|
 | 274 |  * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
 | 
|---|
| [e65de8] | 275 |  * \param *molecules vector of molecules
 | 
|---|
| [c78d44] | 276 |  * \param &elements vector of elements to correlate
 | 
|---|
| [c4d4df] | 277 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 278 |  */
 | 
|---|
| [e5c0a1] | 279 | PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements)
 | 
|---|
| [c4d4df] | 280 | {
 | 
|---|
| [3930eb] | 281 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 282 |   PairCorrelationMap *outmap = new PairCorrelationMap;
 | 
|---|
| [c4d4df] | 283 |   double distance = 0.;
 | 
|---|
| [014475] | 284 |   Box &domain = World::getInstance().getDomain();
 | 
|---|
| [c4d4df] | 285 | 
 | 
|---|
| [e65de8] | 286 |   if (molecules.empty()) {
 | 
|---|
| [47d041] | 287 |     ELOG(1, "No molecule given.");
 | 
|---|
| [c4d4df] | 288 |     return outmap;
 | 
|---|
 | 289 |   }
 | 
|---|
| [e65de8] | 290 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
 | 
|---|
| [009607e] | 291 |     (*MolWalker)->doCountAtoms();
 | 
|---|
| [c78d44] | 292 | 
 | 
|---|
 | 293 |   // create all possible pairs of elements
 | 
|---|
| [e5c0a1] | 294 |   set <pair<const element *,const element *> > PairsOfElements;
 | 
|---|
| [c78d44] | 295 |   if (elements.size() >= 2) {
 | 
|---|
| [e5c0a1] | 296 |     for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
 | 
|---|
 | 297 |       for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
 | 
|---|
| [c78d44] | 298 |         if (type1 != type2) {
 | 
|---|
| [e5c0a1] | 299 |           PairsOfElements.insert( make_pair(*type1,*type2) );
 | 
|---|
| [47d041] | 300 |           LOG(1, "Creating element pair " << *(*type1) << " and " << *(*type2) << ".");
 | 
|---|
| [c78d44] | 301 |         }
 | 
|---|
 | 302 |   } else if (elements.size() == 1) { // one to all are valid
 | 
|---|
| [e5c0a1] | 303 |     const element *elemental = *elements.begin();
 | 
|---|
 | 304 |     PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
 | 
|---|
 | 305 |     PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
 | 
|---|
| [c78d44] | 306 |   } else { // all elements valid
 | 
|---|
 | 307 |     PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
 | 
|---|
 | 308 |   }
 | 
|---|
 | 309 | 
 | 
|---|
| [c4d4df] | 310 |   outmap = new PairCorrelationMap;
 | 
|---|
| [e65de8] | 311 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
 | 
|---|
| [47d041] | 312 |     LOG(2, "Current molecule is " << (*MolWalker)->getName() << ".");
 | 
|---|
| [e65de8] | 313 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 314 |       LOG(3, "Current atom is " << **iter << ".");
 | 
|---|
| [e65de8] | 315 |       for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
 | 
|---|
| [47d041] | 316 |         LOG(2, "Current other molecule is " << (*MolOtherWalker)->getName() << ".");
 | 
|---|
| [e65de8] | 317 |         for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
 | 
|---|
| [47d041] | 318 |           LOG(3, "Current otheratom is " << **runner << ".");
 | 
|---|
| [e65de8] | 319 |           if ((*iter)->getId() < (*runner)->getId()){
 | 
|---|
| [b5c53d] | 320 |             for (set <pair<const element *, const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
 | 
|---|
| [d74077] | 321 |               if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
 | 
|---|
 | 322 |                 distance = domain.periodicDistance((*iter)->getPosition(),(*runner)->getPosition());
 | 
|---|
| [47d041] | 323 |                 //LOG(1, "Inserting " << *(*iter) << " and " << *(*runner));
 | 
|---|
| [e65de8] | 324 |                 outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
 | 
|---|
| [a5551b] | 325 |               }
 | 
|---|
| [c4d4df] | 326 |           }
 | 
|---|
| [a5551b] | 327 |         }
 | 
|---|
| [c4d4df] | 328 |       }
 | 
|---|
 | 329 |     }
 | 
|---|
| [24725c] | 330 |   }
 | 
|---|
| [c4d4df] | 331 |   return outmap;
 | 
|---|
 | 332 | };
 | 
|---|
 | 333 | 
 | 
|---|
| [7ea9e6] | 334 | /** Calculates the pair correlation between given elements.
 | 
|---|
 | 335 |  * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
 | 
|---|
 | 336 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 337 |  * \param &elements vector of elements to correlate
 | 
|---|
| [7ea9e6] | 338 |  * \param ranges[NDIM] interval boundaries for the periodic images to scan also
 | 
|---|
 | 339 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 340 |  */
 | 
|---|
| [e5c0a1] | 341 | PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] )
 | 
|---|
| [7ea9e6] | 342 | {
 | 
|---|
| [3930eb] | 343 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 344 |   PairCorrelationMap *outmap = new PairCorrelationMap;
 | 
|---|
| [7ea9e6] | 345 |   double distance = 0.;
 | 
|---|
 | 346 |   int n[NDIM];
 | 
|---|
 | 347 |   Vector checkX;
 | 
|---|
 | 348 |   Vector periodicX;
 | 
|---|
 | 349 |   int Othern[NDIM];
 | 
|---|
 | 350 |   Vector checkOtherX;
 | 
|---|
 | 351 |   Vector periodicOtherX;
 | 
|---|
 | 352 | 
 | 
|---|
| [e65de8] | 353 |   if (molecules.empty()) {
 | 
|---|
| [47d041] | 354 |     ELOG(1, "No molecule given.");
 | 
|---|
| [7ea9e6] | 355 |     return outmap;
 | 
|---|
 | 356 |   }
 | 
|---|
| [e65de8] | 357 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
 | 
|---|
| [009607e] | 358 |     (*MolWalker)->doCountAtoms();
 | 
|---|
| [c78d44] | 359 | 
 | 
|---|
 | 360 |   // create all possible pairs of elements
 | 
|---|
| [e5c0a1] | 361 |   set <pair<const element *,const element *> > PairsOfElements;
 | 
|---|
| [c78d44] | 362 |   if (elements.size() >= 2) {
 | 
|---|
| [e5c0a1] | 363 |     for (vector<const element *>::const_iterator type1 = elements.begin(); type1 != elements.end(); ++type1)
 | 
|---|
 | 364 |       for (vector<const element *>::const_iterator type2 = elements.begin(); type2 != elements.end(); ++type2)
 | 
|---|
| [c78d44] | 365 |         if (type1 != type2) {
 | 
|---|
| [e5c0a1] | 366 |           PairsOfElements.insert( make_pair(*type1,*type2) );
 | 
|---|
| [47d041] | 367 |           LOG(1, "Creating element pair " << *(*type1) << " and " << *(*type2) << ".");
 | 
|---|
| [c78d44] | 368 |         }
 | 
|---|
 | 369 |   } else if (elements.size() == 1) { // one to all are valid
 | 
|---|
| [e5c0a1] | 370 |     const element *elemental = *elements.begin();
 | 
|---|
 | 371 |     PairsOfElements.insert( pair<const element *,const element*>(elemental,0) );
 | 
|---|
 | 372 |     PairsOfElements.insert( pair<const element *,const element*>(0,elemental) );
 | 
|---|
| [c78d44] | 373 |   } else { // all elements valid
 | 
|---|
 | 374 |     PairsOfElements.insert( pair<element *, element*>((element *)NULL, (element *)NULL) );
 | 
|---|
 | 375 |   }
 | 
|---|
 | 376 | 
 | 
|---|
| [7ea9e6] | 377 |   outmap = new PairCorrelationMap;
 | 
|---|
| [e65de8] | 378 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++){
 | 
|---|
| [cca9ef] | 379 |     RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
 | 
|---|
 | 380 |     RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
 | 
|---|
| [47d041] | 381 |     LOG(2, "Current molecule is " << *MolWalker << ".");
 | 
|---|
| [e65de8] | 382 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 383 |       LOG(3, "Current atom is " << **iter << ".");
 | 
|---|
| [d74077] | 384 |       periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
 | 
|---|
| [e65de8] | 385 |       // go through every range in xyz and get distance
 | 
|---|
 | 386 |       for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
 | 
|---|
 | 387 |         for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
 | 
|---|
 | 388 |           for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
 | 
|---|
 | 389 |             checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
 | 
|---|
 | 390 |             for (std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules.end(); MolOtherWalker++){
 | 
|---|
| [47d041] | 391 |                 LOG(2, "Current other molecule is " << *MolOtherWalker << ".");
 | 
|---|
| [e65de8] | 392 |                 for (molecule::const_iterator runner = (*MolOtherWalker)->begin(); runner != (*MolOtherWalker)->end(); ++runner) {
 | 
|---|
| [47d041] | 393 |                   LOG(3, "Current otheratom is " << **runner << ".");
 | 
|---|
| [e65de8] | 394 |                   if ((*iter)->getId() < (*runner)->getId()){
 | 
|---|
| [e5c0a1] | 395 |                     for (set <pair<const element *,const element *> >::iterator PairRunner = PairsOfElements.begin(); PairRunner != PairsOfElements.end(); ++PairRunner)
 | 
|---|
| [d74077] | 396 |                       if ((PairRunner->first == (**iter).getType()) && (PairRunner->second == (**runner).getType())) {
 | 
|---|
 | 397 |                         periodicOtherX = FullInverseMatrix * ((*runner)->getPosition()); // x now in [0,1)^3
 | 
|---|
| [e65de8] | 398 |                         // go through every range in xyz and get distance
 | 
|---|
 | 399 |                         for (Othern[0]=-ranges[0]; Othern[0] <= ranges[0]; Othern[0]++)
 | 
|---|
 | 400 |                           for (Othern[1]=-ranges[1]; Othern[1] <= ranges[1]; Othern[1]++)
 | 
|---|
 | 401 |                             for (Othern[2]=-ranges[2]; Othern[2] <= ranges[2]; Othern[2]++) {
 | 
|---|
 | 402 |                               checkOtherX = FullMatrix * (Vector(Othern[0], Othern[1], Othern[2]) + periodicOtherX);
 | 
|---|
 | 403 |                               distance = checkX.distance(checkOtherX);
 | 
|---|
| [47d041] | 404 |                               //LOG(1, "Inserting " << *(*iter) << " and " << *(*runner));
 | 
|---|
| [e65de8] | 405 |                               outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> ((*iter), (*runner)) ) );
 | 
|---|
 | 406 |                             }
 | 
|---|
 | 407 |                       }
 | 
|---|
| [c78d44] | 408 |                     }
 | 
|---|
| [7ea9e6] | 409 |                   }
 | 
|---|
| [c78d44] | 410 |                 }
 | 
|---|
| [7ea9e6] | 411 |       }
 | 
|---|
 | 412 |     }
 | 
|---|
| [c78d44] | 413 |   }
 | 
|---|
| [7ea9e6] | 414 | 
 | 
|---|
 | 415 |   return outmap;
 | 
|---|
 | 416 | };
 | 
|---|
 | 417 | 
 | 
|---|
| [c4d4df] | 418 | /** Calculates the distance (pair) correlation between a given element and a point.
 | 
|---|
| [a5551b] | 419 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 420 |  * \param &elements vector of elements to correlate with point
 | 
|---|
| [c4d4df] | 421 |  * \param *point vector to the correlation point
 | 
|---|
 | 422 |  * \return Map of dobules with values as pairs of atom and the vector
 | 
|---|
 | 423 |  */
 | 
|---|
| [e5c0a1] | 424 | CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
 | 
|---|
| [c4d4df] | 425 | {
 | 
|---|
| [3930eb] | 426 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 427 |   CorrelationToPointMap *outmap = new CorrelationToPointMap;
 | 
|---|
| [c4d4df] | 428 |   double distance = 0.;
 | 
|---|
| [014475] | 429 |   Box &domain = World::getInstance().getDomain();
 | 
|---|
| [c4d4df] | 430 | 
 | 
|---|
| [e65de8] | 431 |   if (molecules.empty()) {
 | 
|---|
| [47d041] | 432 |     LOG(1, "No molecule given.");
 | 
|---|
| [c4d4df] | 433 |     return outmap;
 | 
|---|
 | 434 |   }
 | 
|---|
| [e65de8] | 435 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
 | 
|---|
| [009607e] | 436 |     (*MolWalker)->doCountAtoms();
 | 
|---|
| [c4d4df] | 437 |   outmap = new CorrelationToPointMap;
 | 
|---|
| [e65de8] | 438 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
 | 
|---|
| [47d041] | 439 |     LOG(2, "Current molecule is " << *MolWalker << ".");
 | 
|---|
| [e65de8] | 440 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 441 |       LOG(3, "Current atom is " << **iter << ".");
 | 
|---|
| [e5c0a1] | 442 |       for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
 | 
|---|
| [d74077] | 443 |         if ((*type == NULL) || ((*iter)->getType() == *type)) {
 | 
|---|
 | 444 |           distance = domain.periodicDistance((*iter)->getPosition(),*point);
 | 
|---|
| [47d041] | 445 |           LOG(4, "Current distance is " << distance << ".");
 | 
|---|
| [e65de8] | 446 |           outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> ((*iter), point) ) );
 | 
|---|
 | 447 |         }
 | 
|---|
| [c4d4df] | 448 |     }
 | 
|---|
| [e65de8] | 449 |   }
 | 
|---|
| [c4d4df] | 450 | 
 | 
|---|
 | 451 |   return outmap;
 | 
|---|
 | 452 | };
 | 
|---|
 | 453 | 
 | 
|---|
| [7ea9e6] | 454 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
 | 
|---|
 | 455 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 456 |  * \param &elements vector of elements to correlate to point
 | 
|---|
| [7ea9e6] | 457 |  * \param *point vector to the correlation point
 | 
|---|
 | 458 |  * \param ranges[NDIM] interval boundaries for the periodic images to scan also
 | 
|---|
 | 459 |  * \return Map of dobules with values as pairs of atom and the vector
 | 
|---|
 | 460 |  */
 | 
|---|
| [e5c0a1] | 461 | CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
 | 
|---|
| [7ea9e6] | 462 | {
 | 
|---|
| [3930eb] | 463 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 464 |   CorrelationToPointMap *outmap = new CorrelationToPointMap;
 | 
|---|
| [7ea9e6] | 465 |   double distance = 0.;
 | 
|---|
 | 466 |   int n[NDIM];
 | 
|---|
 | 467 |   Vector periodicX;
 | 
|---|
 | 468 |   Vector checkX;
 | 
|---|
 | 469 | 
 | 
|---|
| [e65de8] | 470 |   if (molecules.empty()) {
 | 
|---|
| [47d041] | 471 |     LOG(1, "No molecule given.");
 | 
|---|
| [7ea9e6] | 472 |     return outmap;
 | 
|---|
 | 473 |   }
 | 
|---|
| [e65de8] | 474 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
 | 
|---|
| [009607e] | 475 |     (*MolWalker)->doCountAtoms();
 | 
|---|
| [7ea9e6] | 476 |   outmap = new CorrelationToPointMap;
 | 
|---|
| [e65de8] | 477 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
 | 
|---|
| [cca9ef] | 478 |     RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
 | 
|---|
 | 479 |     RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
 | 
|---|
| [47d041] | 480 |     LOG(2, "Current molecule is " << *MolWalker << ".");
 | 
|---|
| [e65de8] | 481 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 482 |       LOG(3, "Current atom is " << **iter << ".");
 | 
|---|
| [e5c0a1] | 483 |       for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
 | 
|---|
| [d74077] | 484 |         if ((*type == NULL) || ((*iter)->getType() == *type)) {
 | 
|---|
 | 485 |           periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
 | 
|---|
| [e65de8] | 486 |           // go through every range in xyz and get distance
 | 
|---|
 | 487 |           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
 | 
|---|
 | 488 |             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
 | 
|---|
 | 489 |               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
 | 
|---|
 | 490 |                 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
 | 
|---|
 | 491 |                 distance = checkX.distance(*point);
 | 
|---|
| [47d041] | 492 |                 LOG(4, "Current distance is " << distance << ".");
 | 
|---|
| [e65de8] | 493 |                 outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (*iter, point) ) );
 | 
|---|
 | 494 |               }
 | 
|---|
 | 495 |         }
 | 
|---|
| [7ea9e6] | 496 |     }
 | 
|---|
| [e65de8] | 497 |   }
 | 
|---|
| [7ea9e6] | 498 | 
 | 
|---|
 | 499 |   return outmap;
 | 
|---|
 | 500 | };
 | 
|---|
 | 501 | 
 | 
|---|
| [c4d4df] | 502 | /** Calculates the distance (pair) correlation between a given element and a surface.
 | 
|---|
| [a5551b] | 503 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 504 |  * \param &elements vector of elements to correlate to surface
 | 
|---|
| [c4d4df] | 505 |  * \param *Surface pointer to Tesselation class surface
 | 
|---|
 | 506 |  * \param *LC LinkedCell structure to quickly find neighbouring atoms
 | 
|---|
 | 507 |  * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
 | 
|---|
 | 508 |  */
 | 
|---|
| [e5c0a1] | 509 | CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC )
 | 
|---|
| [c4d4df] | 510 | {
 | 
|---|
| [3930eb] | 511 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 512 |   CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [99593f] | 513 |   double distance = 0;
 | 
|---|
| [c4d4df] | 514 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 515 |   Vector centroid;
 | 
|---|
| [7ea9e6] | 516 | 
 | 
|---|
| [e65de8] | 517 |   if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
 | 
|---|
| [47d041] | 518 |     ELOG(1, "No Tesselation, no LinkedCell or no molecule given.");
 | 
|---|
| [7ea9e6] | 519 |     return outmap;
 | 
|---|
 | 520 |   }
 | 
|---|
| [e65de8] | 521 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
 | 
|---|
| [009607e] | 522 |     (*MolWalker)->doCountAtoms();
 | 
|---|
| [7ea9e6] | 523 |   outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [e65de8] | 524 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
 | 
|---|
| [47d041] | 525 |     LOG(2, "Current molecule is " << (*MolWalker)->name << ".");
 | 
|---|
| [e65de8] | 526 |     if ((*MolWalker)->empty())
 | 
|---|
| [47d041] | 527 |       LOG(2, "\t is empty.");
 | 
|---|
| [e65de8] | 528 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 529 |       LOG(3, "\tCurrent atom is " << *(*iter) << ".");
 | 
|---|
| [e5c0a1] | 530 |       for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
 | 
|---|
| [d74077] | 531 |         if ((*type == NULL) || ((*iter)->getType() == *type)) {
 | 
|---|
 | 532 |           TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
 | 
|---|
| [e65de8] | 533 |           distance = Intersections.GetSmallestDistance();
 | 
|---|
 | 534 |           triangle = Intersections.GetClosestTriangle();
 | 
|---|
 | 535 |           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> ((*iter), triangle) ) );
 | 
|---|
 | 536 |         }
 | 
|---|
| [7fd416] | 537 |     }
 | 
|---|
| [e65de8] | 538 |   }
 | 
|---|
| [7ea9e6] | 539 | 
 | 
|---|
 | 540 |   return outmap;
 | 
|---|
 | 541 | };
 | 
|---|
 | 542 | 
 | 
|---|
 | 543 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
 | 
|---|
 | 544 |  * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
 | 
|---|
 | 545 |  * 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
 | 
|---|
 | 546 |  * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
 | 
|---|
 | 547 |  * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
 | 
|---|
 | 548 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 549 |  * \param &elements vector of elements to correlate to surface
 | 
|---|
| [7ea9e6] | 550 |  * \param *Surface pointer to Tesselation class surface
 | 
|---|
 | 551 |  * \param *LC LinkedCell structure to quickly find neighbouring atoms
 | 
|---|
 | 552 |  * \param ranges[NDIM] interval boundaries for the periodic images to scan also
 | 
|---|
 | 553 |  * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
 | 
|---|
 | 554 |  */
 | 
|---|
| [e5c0a1] | 555 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
 | 
|---|
| [7ea9e6] | 556 | {
 | 
|---|
| [3930eb] | 557 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 558 |   CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [7ea9e6] | 559 |   double distance = 0;
 | 
|---|
 | 560 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 561 |   Vector centroid;
 | 
|---|
| [99593f] | 562 |   int n[NDIM];
 | 
|---|
 | 563 |   Vector periodicX;
 | 
|---|
 | 564 |   Vector checkX;
 | 
|---|
| [c4d4df] | 565 | 
 | 
|---|
| [e65de8] | 566 |   if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
 | 
|---|
| [47d041] | 567 |     LOG(1, "No Tesselation, no LinkedCell or no molecule given.");
 | 
|---|
| [c4d4df] | 568 |     return outmap;
 | 
|---|
 | 569 |   }
 | 
|---|
| [e65de8] | 570 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++)
 | 
|---|
| [009607e] | 571 |     (*MolWalker)->doCountAtoms();
 | 
|---|
| [c4d4df] | 572 |   outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [244a84] | 573 |   double ShortestDistance = 0.;
 | 
|---|
 | 574 |   BoundaryTriangleSet *ShortestTriangle = NULL;
 | 
|---|
| [e65de8] | 575 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
 | 
|---|
| [cca9ef] | 576 |     RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
 | 
|---|
 | 577 |     RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
 | 
|---|
| [47d041] | 578 |     LOG(2, "Current molecule is " << *MolWalker << ".");
 | 
|---|
| [e65de8] | 579 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 580 |       LOG(3, "Current atom is " << **iter << ".");
 | 
|---|
| [e5c0a1] | 581 |       for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
 | 
|---|
| [d74077] | 582 |         if ((*type == NULL) || ((*iter)->getType() == *type)) {
 | 
|---|
 | 583 |           periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
 | 
|---|
| [e65de8] | 584 |           // go through every range in xyz and get distance
 | 
|---|
 | 585 |           ShortestDistance = -1.;
 | 
|---|
 | 586 |           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
 | 
|---|
 | 587 |             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
 | 
|---|
 | 588 |               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
 | 
|---|
 | 589 |                 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
 | 
|---|
| [d74077] | 590 |                 TriangleIntersectionList Intersections(checkX,Surface,LC);
 | 
|---|
| [e65de8] | 591 |                 distance = Intersections.GetSmallestDistance();
 | 
|---|
 | 592 |                 triangle = Intersections.GetClosestTriangle();
 | 
|---|
 | 593 |                 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
 | 
|---|
 | 594 |                   ShortestDistance = distance;
 | 
|---|
 | 595 |                   ShortestTriangle = triangle;
 | 
|---|
| [99593f] | 596 |                 }
 | 
|---|
| [e65de8] | 597 |               }
 | 
|---|
 | 598 |           // insert
 | 
|---|
 | 599 |           outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (*iter, ShortestTriangle) ) );
 | 
|---|
| [47d041] | 600 |           //LOG(1, "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << ".");
 | 
|---|
| [e65de8] | 601 |         }
 | 
|---|
| [c4d4df] | 602 |     }
 | 
|---|
| [e65de8] | 603 |   }
 | 
|---|
| [c4d4df] | 604 | 
 | 
|---|
 | 605 |   return outmap;
 | 
|---|
 | 606 | };
 | 
|---|
 | 607 | 
 | 
|---|
| [bd61b41] | 608 | /** Returns the index of the bin for a given value.
 | 
|---|
| [c4d4df] | 609 |  * \param value value whose bin to look for
 | 
|---|
 | 610 |  * \param BinWidth width of bin
 | 
|---|
 | 611 |  * \param BinStart first bin
 | 
|---|
 | 612 |  */
 | 
|---|
| [bd61b41] | 613 | int GetBin ( const double value, const double BinWidth, const double BinStart )
 | 
|---|
| [c4d4df] | 614 | {
 | 
|---|
| [92e5cb] | 615 |   //Info FunctionInfo(__func__);
 | 
|---|
| [bd61b41] | 616 |   int bin =(int) (floor((value - BinStart)/BinWidth));
 | 
|---|
 | 617 |   return (bin);
 | 
|---|
| [c4d4df] | 618 | };
 | 
|---|
 | 619 | 
 | 
|---|
 | 620 | 
 | 
|---|
| [92e5cb] | 621 | /** Adds header part that is unique to BinPairMap.
 | 
|---|
 | 622 |  *
 | 
|---|
 | 623 |  * @param file stream to print to
 | 
|---|
| [c4d4df] | 624 |  */
 | 
|---|
| [92e5cb] | 625 | void OutputCorrelation_Header( ofstream * const file )
 | 
|---|
| [c4d4df] | 626 | {
 | 
|---|
| [92e5cb] | 627 |   *file << "\tCount";
 | 
|---|
| [c4d4df] | 628 | };
 | 
|---|
| [b1f254] | 629 | 
 | 
|---|
| [92e5cb] | 630 | /** Prints values stored in BinPairMap iterator.
 | 
|---|
 | 631 |  *
 | 
|---|
 | 632 |  * @param file stream to print to
 | 
|---|
 | 633 |  * @param runner iterator pointing at values to print
 | 
|---|
| [be945c] | 634 |  */
 | 
|---|
| [92e5cb] | 635 | void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
 | 
|---|
| [be945c] | 636 | {
 | 
|---|
| [92e5cb] | 637 |   *file << runner->second;
 | 
|---|
| [be945c] | 638 | };
 | 
|---|
 | 639 | 
 | 
|---|
| [92e5cb] | 640 | 
 | 
|---|
 | 641 | /** Adds header part that is unique to DipoleAngularCorrelationMap.
 | 
|---|
 | 642 |  *
 | 
|---|
 | 643 |  * @param file stream to print to
 | 
|---|
| [b1f254] | 644 |  */
 | 
|---|
| [92e5cb] | 645 | void OutputDipoleAngularCorrelation_Header( ofstream * const file )
 | 
|---|
| [b1f254] | 646 | {
 | 
|---|
| [4b8630] | 647 |   *file << "\tFirstAtomOfMolecule";
 | 
|---|
| [b1f254] | 648 | };
 | 
|---|
 | 649 | 
 | 
|---|
| [208237b] | 650 | /** Prints values stored in DipoleCorrelationMap iterator.
 | 
|---|
| [92e5cb] | 651 |  *
 | 
|---|
 | 652 |  * @param file stream to print to
 | 
|---|
 | 653 |  * @param runner iterator pointing at values to print
 | 
|---|
| [b1f254] | 654 |  */
 | 
|---|
| [92e5cb] | 655 | void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
 | 
|---|
| [208237b] | 656 | {
 | 
|---|
| [505d05] | 657 |   *file << *(runner->second);
 | 
|---|
| [208237b] | 658 | };
 | 
|---|
 | 659 | 
 | 
|---|
 | 660 | 
 | 
|---|
 | 661 | /** Adds header part that is unique to DipoleAngularCorrelationMap.
 | 
|---|
 | 662 |  *
 | 
|---|
 | 663 |  * @param file stream to print to
 | 
|---|
 | 664 |  */
 | 
|---|
 | 665 | void OutputDipoleCorrelation_Header( ofstream * const file )
 | 
|---|
 | 666 | {
 | 
|---|
 | 667 |   *file << "\tMolecule";
 | 
|---|
 | 668 | };
 | 
|---|
 | 669 | 
 | 
|---|
 | 670 | /** Prints values stored in DipoleCorrelationMap iterator.
 | 
|---|
 | 671 |  *
 | 
|---|
 | 672 |  * @param file stream to print to
 | 
|---|
 | 673 |  * @param runner iterator pointing at values to print
 | 
|---|
 | 674 |  */
 | 
|---|
 | 675 | void OutputDipoleCorrelation_Value( ofstream * const file, DipoleCorrelationMap::const_iterator &runner )
 | 
|---|
| [b1f254] | 676 | {
 | 
|---|
| [92e5cb] | 677 |   *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
 | 
|---|
| [b1f254] | 678 | };
 | 
|---|
 | 679 | 
 | 
|---|
| [92e5cb] | 680 | 
 | 
|---|
 | 681 | /** Adds header part that is unique to PairCorrelationMap.
 | 
|---|
 | 682 |  *
 | 
|---|
 | 683 |  * @param file stream to print to
 | 
|---|
| [b1f254] | 684 |  */
 | 
|---|
| [92e5cb] | 685 | void OutputPairCorrelation_Header( ofstream * const file )
 | 
|---|
| [b1f254] | 686 | {
 | 
|---|
| [92e5cb] | 687 |   *file << "\tAtom1\tAtom2";
 | 
|---|
 | 688 | };
 | 
|---|
 | 689 | 
 | 
|---|
 | 690 | /** Prints values stored in PairCorrelationMap iterator.
 | 
|---|
 | 691 |  *
 | 
|---|
 | 692 |  * @param file stream to print to
 | 
|---|
 | 693 |  * @param runner iterator pointing at values to print
 | 
|---|
 | 694 |  */
 | 
|---|
 | 695 | void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner )
 | 
|---|
 | 696 | {
 | 
|---|
 | 697 |   *file << *(runner->second.first) << "\t" << *(runner->second.second);
 | 
|---|
 | 698 | };
 | 
|---|
 | 699 | 
 | 
|---|
 | 700 | 
 | 
|---|
 | 701 | /** Adds header part that is unique to CorrelationToPointMap.
 | 
|---|
 | 702 |  *
 | 
|---|
 | 703 |  * @param file stream to print to
 | 
|---|
 | 704 |  */
 | 
|---|
 | 705 | void OutputCorrelationToPoint_Header( ofstream * const file )
 | 
|---|
 | 706 | {
 | 
|---|
 | 707 |   *file << "\tAtom::x[i]-point.x[i]";
 | 
|---|
 | 708 | };
 | 
|---|
 | 709 | 
 | 
|---|
 | 710 | /** Prints values stored in CorrelationToPointMap iterator.
 | 
|---|
 | 711 |  *
 | 
|---|
 | 712 |  * @param file stream to print to
 | 
|---|
 | 713 |  * @param runner iterator pointing at values to print
 | 
|---|
 | 714 |  */
 | 
|---|
 | 715 | void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner )
 | 
|---|
 | 716 | {
 | 
|---|
 | 717 |   for (int i=0;i<NDIM;i++)
 | 
|---|
 | 718 |     *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
 | 
|---|
| [b1f254] | 719 | };
 | 
|---|
 | 720 | 
 | 
|---|
| [92e5cb] | 721 | 
 | 
|---|
 | 722 | /** Adds header part that is unique to CorrelationToSurfaceMap.
 | 
|---|
 | 723 |  *
 | 
|---|
 | 724 |  * @param file stream to print to
 | 
|---|
 | 725 |  */
 | 
|---|
 | 726 | void OutputCorrelationToSurface_Header( ofstream * const file )
 | 
|---|
 | 727 | {
 | 
|---|
 | 728 |   *file << "\tTriangle";
 | 
|---|
 | 729 | };
 | 
|---|
 | 730 | 
 | 
|---|
 | 731 | /** Prints values stored in CorrelationToSurfaceMap iterator.
 | 
|---|
 | 732 |  *
 | 
|---|
 | 733 |  * @param file stream to print to
 | 
|---|
 | 734 |  * @param runner iterator pointing at values to print
 | 
|---|
 | 735 |  */
 | 
|---|
 | 736 | void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
 | 
|---|
 | 737 | {
 | 
|---|
 | 738 |   *file << *(runner->second.first) << "\t" << *(runner->second.second);
 | 
|---|
 | 739 | };
 | 
|---|