| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [0aa122] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [94d5ac6] | 5 |  * 
 | 
|---|
 | 6 |  *
 | 
|---|
 | 7 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 8 |  *
 | 
|---|
 | 9 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 10 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 11 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 12 |  *    (at your option) any later version.
 | 
|---|
 | 13 |  *
 | 
|---|
 | 14 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 15 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 16 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 17 |  *    GNU General Public License for more details.
 | 
|---|
 | 18 |  *
 | 
|---|
 | 19 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 20 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
| [bcf653] | 21 |  */
 | 
|---|
 | 22 | 
 | 
|---|
| [c4d4df] | 23 | /*
 | 
|---|
 | 24 |  * analysis.cpp
 | 
|---|
 | 25 |  *
 | 
|---|
 | 26 |  *  Created on: Oct 13, 2009
 | 
|---|
 | 27 |  *      Author: heber
 | 
|---|
 | 28 |  */
 | 
|---|
 | 29 | 
 | 
|---|
| [bf3817] | 30 | // include config.h
 | 
|---|
 | 31 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 32 | #include <config.h>
 | 
|---|
 | 33 | #endif
 | 
|---|
 | 34 | 
 | 
|---|
| [ad011c] | 35 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [112b09] | 36 | 
 | 
|---|
| [c1a9d6] | 37 | #include <algorithm>
 | 
|---|
| [c4d4df] | 38 | #include <iostream>
 | 
|---|
| [36166d] | 39 | #include <iomanip>
 | 
|---|
| [505d05] | 40 | #include <limits>
 | 
|---|
| [c4d4df] | 41 | 
 | 
|---|
| [6f0841] | 42 | #include "Atom/atom.hpp"
 | 
|---|
| [129204] | 43 | #include "Bond/bond.hpp"
 | 
|---|
| [d127c8] | 44 | #include "Tesselation/BoundaryTriangleSet.hpp"
 | 
|---|
| [be945c] | 45 | #include "Box.hpp"
 | 
|---|
| [3bdb6d] | 46 | #include "Element/element.hpp"
 | 
|---|
| [ad011c] | 47 | #include "CodePatterns/Info.hpp"
 | 
|---|
 | 48 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [208237b] | 49 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [e65878] | 50 | #include "Descriptors/AtomOfMoleculeSelectionDescriptor.hpp"
 | 
|---|
 | 51 | #include "Descriptors/MoleculeFormulaDescriptor.hpp"
 | 
|---|
| [4b8630] | 52 | #include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
 | 
|---|
| [ea430a] | 53 | #include "Formula.hpp"
 | 
|---|
| [208237b] | 54 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 55 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| [c1a9d6] | 56 | #include "LinkedCell/LinkedCell_View.hpp"
 | 
|---|
| [c4d4df] | 57 | #include "molecule.hpp"
 | 
|---|
| [d127c8] | 58 | #include "Tesselation/tesselation.hpp"
 | 
|---|
 | 59 | #include "Tesselation/tesselationhelpers.hpp"
 | 
|---|
 | 60 | #include "Tesselation/triangleintersectionlist.hpp"
 | 
|---|
| [be945c] | 61 | #include "World.hpp"
 | 
|---|
| [208237b] | 62 | #include "WorldTime.hpp"
 | 
|---|
| [c4d4df] | 63 | 
 | 
|---|
| [be945c] | 64 | #include "analysis_correlation.hpp"
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | /** Calculates the dipole vector of a given atomSet.
 | 
|---|
 | 67 |  *
 | 
|---|
 | 68 |  *  Note that we use the following procedure as rule of thumb:
 | 
|---|
 | 69 |  *   -# go through every bond of the atom
 | 
|---|
| [d1912f] | 70 |  *   -# calculate the difference of electronegativities \f$\Delta\mathrm{EN}\f$
 | 
|---|
 | 71 |  *   -# if \f$\Delta\mathrm{EN} > 0.5\f$, we align the bond vector in direction of the more negative element
 | 
|---|
| [be945c] | 72 |  *   -# sum up all vectors
 | 
|---|
 | 73 |  *   -# finally, divide by the number of summed vectors
 | 
|---|
 | 74 |  *
 | 
|---|
 | 75 |  * @param atomsbegin begin iterator of atomSet
 | 
|---|
 | 76 |  * @param atomsend end iterator of atomset
 | 
|---|
 | 77 |  * @return dipole vector
 | 
|---|
 | 78 |  */
 | 
|---|
 | 79 | Vector getDipole(molecule::const_iterator atomsbegin, molecule::const_iterator atomsend)
 | 
|---|
 | 80 | {
 | 
|---|
 | 81 |   Vector DipoleVector;
 | 
|---|
 | 82 |   size_t SumOfVectors = 0;
 | 
|---|
| [8fc1a6] | 83 |   Box &domain = World::getInstance().getDomain();
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 |       // go through all atoms
 | 
|---|
| [be945c] | 86 |   for (molecule::const_iterator atomiter = atomsbegin;
 | 
|---|
 | 87 |       atomiter != atomsend;
 | 
|---|
 | 88 |       ++atomiter) {
 | 
|---|
 | 89 |     // go through all bonds
 | 
|---|
| [9d83b6] | 90 |     const BondList& ListOfBonds = (*atomiter)->getListOfBonds();
 | 
|---|
| [4fc828] | 91 |     ASSERT(ListOfBonds.begin() != ListOfBonds.end(),
 | 
|---|
 | 92 |         "getDipole() - no bonds in molecule!");
 | 
|---|
| [9d83b6] | 93 |     for (BondList::const_iterator bonditer = ListOfBonds.begin();
 | 
|---|
 | 94 |         bonditer != ListOfBonds.end();
 | 
|---|
| [be945c] | 95 |         ++bonditer) {
 | 
|---|
 | 96 |       const atom * Otheratom = (*bonditer)->GetOtherAtom(*atomiter);
 | 
|---|
 | 97 |       if (Otheratom->getId() > (*atomiter)->getId()) {
 | 
|---|
 | 98 |         const double DeltaEN = (*atomiter)->getType()->getElectronegativity()
 | 
|---|
 | 99 |             -Otheratom->getType()->getElectronegativity();
 | 
|---|
| [8fc1a6] | 100 |         // get distance and correct for boundary conditions
 | 
|---|
 | 101 |         Vector BondDipoleVector = domain.periodicDistanceVector(
 | 
|---|
 | 102 |             (*atomiter)->getPosition(),
 | 
|---|
 | 103 |             Otheratom->getPosition());
 | 
|---|
| [be945c] | 104 |         // DeltaEN is always positive, gives correct orientation of vector
 | 
|---|
 | 105 |         BondDipoleVector.Normalize();
 | 
|---|
 | 106 |         BondDipoleVector *= DeltaEN;
 | 
|---|
| [4fc828] | 107 |         LOG(3,"INFO: Dipole vector from bond " << **bonditer << " is " << BondDipoleVector);
 | 
|---|
| [be945c] | 108 |         DipoleVector += BondDipoleVector;
 | 
|---|
 | 109 |         SumOfVectors++;
 | 
|---|
 | 110 |       }
 | 
|---|
 | 111 |     }
 | 
|---|
 | 112 |   }
 | 
|---|
| [4fc828] | 113 |   LOG(3,"INFO: Sum over all bond dipole vectors is "
 | 
|---|
 | 114 |       << DipoleVector << " with " << SumOfVectors << " in total.");
 | 
|---|
 | 115 |   if (SumOfVectors != 0)
 | 
|---|
 | 116 |     DipoleVector *= 1./(double)SumOfVectors;
 | 
|---|
| [44f53e] | 117 |   LOG(2, "INFO: Resulting dipole vector is " << DipoleVector);
 | 
|---|
| [be945c] | 118 | 
 | 
|---|
 | 119 |   return DipoleVector;
 | 
|---|
 | 120 | };
 | 
|---|
 | 121 | 
 | 
|---|
| [1cc661] | 122 | /** Calculate minimum and maximum amount of trajectory steps by going through given atomic trajectories.
 | 
|---|
 | 123 |  * \param vector of atoms whose trajectories to check for [min,max]
 | 
|---|
 | 124 |  * \return range with [min, max]
 | 
|---|
 | 125 |  */
 | 
|---|
| [e65878] | 126 | range<size_t> getMaximumTrajectoryBounds(const std::vector<atom *> &atoms)
 | 
|---|
| [1cc661] | 127 | {
 | 
|---|
 | 128 |   // get highest trajectory size
 | 
|---|
 | 129 |   LOG(0,"STATUS: Retrieving maximum amount of time steps ...");
 | 
|---|
| [505d05] | 130 |   if (atoms.size() == 0)
 | 
|---|
 | 131 |     return range<size_t>(0,0);
 | 
|---|
 | 132 |   size_t max_timesteps = std::numeric_limits<size_t>::min();
 | 
|---|
 | 133 |   size_t min_timesteps = std::numeric_limits<size_t>::max();
 | 
|---|
| [1cc661] | 134 |   BOOST_FOREACH(atom *_atom, atoms) {
 | 
|---|
 | 135 |     if (_atom->getTrajectorySize() > max_timesteps)
 | 
|---|
 | 136 |       max_timesteps  = _atom->getTrajectorySize();
 | 
|---|
| [505d05] | 137 |     if (_atom->getTrajectorySize() < min_timesteps)
 | 
|---|
| [1cc661] | 138 |       min_timesteps = _atom->getTrajectorySize();
 | 
|---|
 | 139 |   }
 | 
|---|
 | 140 |   LOG(1,"INFO: Minimum number of time steps found is " << min_timesteps);
 | 
|---|
 | 141 |   LOG(1,"INFO: Maximum number of time steps found is " << max_timesteps);
 | 
|---|
 | 142 | 
 | 
|---|
 | 143 |   return range<size_t>(min_timesteps, max_timesteps);
 | 
|---|
 | 144 | }
 | 
|---|
 | 145 | 
 | 
|---|
| [0a7fad] | 146 | /** Calculates the angular dipole zero orientation from current time step.
 | 
|---|
| [e65878] | 147 |  * \param molecules vector of molecules to calculate dipoles of
 | 
|---|
| [0a7fad] | 148 |  * \return map with orientation vector for each atomic id given in \a atoms.
 | 
|---|
 | 149 |  */
 | 
|---|
| [e65878] | 150 | std::map<atomId_t, Vector> CalculateZeroAngularDipole(const std::vector<molecule *> &molecules)
 | 
|---|
| [0a7fad] | 151 | {
 | 
|---|
 | 152 |   // get zero orientation for each molecule.
 | 
|---|
| [e65878] | 153 |   LOG(0,"STATUS: Calculating dipoles for current time step ...");
 | 
|---|
| [0a7fad] | 154 |   std::map<atomId_t, Vector> ZeroVector;
 | 
|---|
 | 155 |   BOOST_FOREACH(molecule *_mol, molecules) {
 | 
|---|
 | 156 |     const Vector Dipole = getDipole(_mol->begin(), _mol->end());
 | 
|---|
 | 157 |     for(molecule::const_iterator iter = _mol->begin(); iter != _mol->end(); ++iter)
 | 
|---|
 | 158 |       ZeroVector[(*iter)->getId()] = Dipole;
 | 
|---|
 | 159 |     LOG(2,"INFO: Zero alignment for molecule " << _mol->getId() << " is " << Dipole);
 | 
|---|
 | 160 |   }
 | 
|---|
 | 161 |   LOG(1,"INFO: We calculated zero orientation for a total of " << molecules.size() << " molecule(s).");
 | 
|---|
 | 162 | 
 | 
|---|
 | 163 |   return ZeroVector;
 | 
|---|
 | 164 | }
 | 
|---|
| [1cc661] | 165 | 
 | 
|---|
| [ea430a] | 166 | /** Calculates the dipole angular correlation for given molecule type.
 | 
|---|
| [208237b] | 167 |  * Calculate the change of the dipole orientation angle over time.
 | 
|---|
| [ea430a] | 168 |  * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
 | 
|---|
| [be945c] | 169 |  * Angles are given in degrees.
 | 
|---|
| [4b8630] | 170 |  * \param &atoms list of atoms of the molecules taking part (Note: molecules may
 | 
|---|
 | 171 |  * change over time as bond structure is recalculated, hence we need the atoms)
 | 
|---|
| [cda81d] | 172 |  * \param timestep time step to calculate angular correlation for (relative to
 | 
|---|
 | 173 |  *  \a ZeroVector)
 | 
|---|
| [325687] | 174 |  * \param ZeroVector map with Zero orientation vector for each atom in \a atoms.
 | 
|---|
| [99b87a] | 175 |  * \param DontResetTime don't reset time to old value (triggers re-creation of bond system)
 | 
|---|
| [ea430a] | 176 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 177 |  */
 | 
|---|
| [325687] | 178 | DipoleAngularCorrelationMap *DipoleAngularCorrelation(
 | 
|---|
| [e65878] | 179 |     const Formula &DipoleFormula,
 | 
|---|
| [cda81d] | 180 |     const size_t timestep,
 | 
|---|
| [e65878] | 181 |     const std::map<atomId_t, Vector> &ZeroVector,
 | 
|---|
| [99b87a] | 182 |     const enum ResetWorldTime DoTimeReset
 | 
|---|
| [325687] | 183 |     )
 | 
|---|
| [ea430a] | 184 | {
 | 
|---|
 | 185 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 186 |   DipoleAngularCorrelationMap *outmap = new DipoleAngularCorrelationMap;
 | 
|---|
| [be945c] | 187 | 
 | 
|---|
| [99b87a] | 188 |   unsigned int oldtime = 0;
 | 
|---|
 | 189 |   if (DoTimeReset == DoResetTime) {
 | 
|---|
 | 190 |     // store original time step
 | 
|---|
 | 191 |     oldtime = WorldTime::getTime();
 | 
|---|
 | 192 |   }
 | 
|---|
| [0a7fad] | 193 | 
 | 
|---|
| [cda81d] | 194 |   // set time step
 | 
|---|
| [505d05] | 195 |   LOG(0,"STATUS: Stepping onto to time step " << timestep << ".");
 | 
|---|
| [cda81d] | 196 |   World::getInstance().setTime(timestep);
 | 
|---|
 | 197 | 
 | 
|---|
 | 198 |   // get all molecules for this time step
 | 
|---|
| [e65878] | 199 |   World::getInstance().clearMoleculeSelection();
 | 
|---|
 | 200 |   World::getInstance().selectAllMolecules(MoleculeByFormula(DipoleFormula));
 | 
|---|
 | 201 |   std::vector<molecule *> molecules = World::getInstance().getSelectedMolecules();
 | 
|---|
| [870b4b] | 202 |   LOG(1,"INFO: There are " << molecules.size() << " molecules for time step " << timestep << ".");
 | 
|---|
| [208237b] | 203 | 
 | 
|---|
| [cda81d] | 204 |   // calculate dipoles for each
 | 
|---|
| [870b4b] | 205 |   LOG(0,"STATUS: Calculating dipoles for time step " << timestep << " ...");
 | 
|---|
| [cda81d] | 206 |   size_t i=0;
 | 
|---|
| [870b4b] | 207 |   size_t Counter_rejections = 0;
 | 
|---|
| [cda81d] | 208 |   BOOST_FOREACH(molecule *_mol, molecules) {
 | 
|---|
 | 209 |     const Vector Dipole = getDipole(_mol->begin(), _mol->end());
 | 
|---|
| [e65878] | 210 |     LOG(3,"INFO: Dipole vector at time step " << timestep << " for for molecule "
 | 
|---|
| [cda81d] | 211 |         << _mol->getId() << " is " << Dipole);
 | 
|---|
| [e65878] | 212 |     // check that all atoms are valid (zeroVector known)
 | 
|---|
| [cda81d] | 213 |     molecule::const_iterator iter = _mol->begin();
 | 
|---|
| [e65878] | 214 |     for(; iter != _mol->end(); ++iter) {
 | 
|---|
 | 215 |       if (!ZeroVector.count((*iter)->getId()))
 | 
|---|
 | 216 |         break;
 | 
|---|
 | 217 |     }
 | 
|---|
 | 218 |     if (iter != _mol->end()) {
 | 
|---|
 | 219 |       ELOG(2, "Skipping molecule " << _mol->getName() << " as not all atoms have a valid zeroVector.");
 | 
|---|
| [870b4b] | 220 |       ++Counter_rejections;
 | 
|---|
| [e65878] | 221 |       continue;
 | 
|---|
 | 222 |     } else
 | 
|---|
 | 223 |       iter = _mol->begin();
 | 
|---|
 | 224 |     std::map<atomId_t, Vector>::const_iterator zeroValue = ZeroVector.find((*iter)->getId()); //due to iter is const
 | 
|---|
| [cda81d] | 225 |     double angle = 0.;
 | 
|---|
 | 226 |     LOG(2, "INFO: ZeroVector of first atom " << **iter << " is "
 | 
|---|
| [e65878] | 227 |         << zeroValue->second << ".");
 | 
|---|
| [cda81d] | 228 |     LOG(4, "INFO: Squared norm of difference vector is "
 | 
|---|
| [e65878] | 229 |         << (zeroValue->second - Dipole).NormSquared() << ".");
 | 
|---|
 | 230 |     if ((zeroValue->second - Dipole).NormSquared() > MYEPSILON)
 | 
|---|
 | 231 |       angle = Dipole.Angle(zeroValue->second) * (180./M_PI);
 | 
|---|
| [cda81d] | 232 |     else
 | 
|---|
 | 233 |       LOG(2, "INFO: Both vectors (almost) coincide, numerically unstable, angle set to zero.");
 | 
|---|
 | 234 |     LOG(1,"INFO: Resulting relative angle for molecule " << _mol->getName()
 | 
|---|
 | 235 |         << " is " << angle << ".");
 | 
|---|
| [59fff1] | 236 |     outmap->insert ( std::make_pair (angle, *iter ) );
 | 
|---|
| [cda81d] | 237 |     ++i;
 | 
|---|
| [208237b] | 238 |   }
 | 
|---|
| [870b4b] | 239 |   ASSERT(Counter_rejections <= molecules.size(),
 | 
|---|
 | 240 |       "DipoleAngularCorrelation() - more rejections ("+toString(Counter_rejections)
 | 
|---|
 | 241 |       +") than there are molecules ("+toString(molecules.size())+").");
 | 
|---|
 | 242 |   LOG(1,"INFO: " << Counter_rejections << " molecules have been rejected in time step " << timestep << ".");
 | 
|---|
 | 243 | 
 | 
|---|
 | 244 |   LOG(0,"STATUS: Done with calculating dipoles.");
 | 
|---|
| [208237b] | 245 | 
 | 
|---|
| [99b87a] | 246 |   if (DoTimeReset == DoResetTime) {
 | 
|---|
 | 247 |     // re-set to original time step again
 | 
|---|
 | 248 |     World::getInstance().setTime(oldtime);
 | 
|---|
 | 249 |   }
 | 
|---|
| [208237b] | 250 | 
 | 
|---|
 | 251 |   // and return results
 | 
|---|
 | 252 |   return outmap;
 | 
|---|
 | 253 | };
 | 
|---|
 | 254 | 
 | 
|---|
 | 255 | /** Calculates the dipole correlation for given molecule type.
 | 
|---|
 | 256 |  * I.e. we calculate how the angle between any two given dipoles in the
 | 
|---|
 | 257 |  * systems behaves. Sort of pair correlation but distance is replaced by
 | 
|---|
 | 258 |  * the orientation distance, i.e. an angle.
 | 
|---|
 | 259 |  * Note given element order is unimportant (i.e. g(Si, O) === g(O, Si))
 | 
|---|
 | 260 |  * Angles are given in degrees.
 | 
|---|
 | 261 |  * \param *molecules vector of molecules
 | 
|---|
 | 262 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 263 |  */
 | 
|---|
 | 264 | DipoleCorrelationMap *DipoleCorrelation(std::vector<molecule *> &molecules)
 | 
|---|
 | 265 | {
 | 
|---|
 | 266 |   Info FunctionInfo(__func__);
 | 
|---|
 | 267 |   DipoleCorrelationMap *outmap = new DipoleCorrelationMap;
 | 
|---|
 | 268 | //  double distance = 0.;
 | 
|---|
 | 269 | //  Box &domain = World::getInstance().getDomain();
 | 
|---|
 | 270 | //
 | 
|---|
 | 271 |   if (molecules.empty()) {
 | 
|---|
| [47d041] | 272 |     ELOG(1, "No molecule given.");
 | 
|---|
| [208237b] | 273 |     return outmap;
 | 
|---|
 | 274 |   }
 | 
|---|
 | 275 | 
 | 
|---|
| [be945c] | 276 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
 | 
|---|
| [92e5cb] | 277 |       MolWalker != molecules.end(); ++MolWalker) {
 | 
|---|
| [47d041] | 278 |     LOG(2, "INFO: Current molecule is " << (*MolWalker)->getId() << ".");
 | 
|---|
| [be945c] | 279 |     const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
 | 
|---|
| [92e5cb] | 280 |     std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
 | 
|---|
 | 281 |     for (++MolOtherWalker;
 | 
|---|
| [be945c] | 282 |         MolOtherWalker != molecules.end();
 | 
|---|
| [92e5cb] | 283 |         ++MolOtherWalker) {
 | 
|---|
| [47d041] | 284 |       LOG(2, "INFO: Current other molecule is " << (*MolOtherWalker)->getId() << ".");
 | 
|---|
| [be945c] | 285 |       const Vector OtherDipole = getDipole((*MolOtherWalker)->begin(), (*MolOtherWalker)->end());
 | 
|---|
 | 286 |       const double angle = Dipole.Angle(OtherDipole) * (180./M_PI);
 | 
|---|
| [47d041] | 287 |       LOG(1, "Angle is " << angle << ".");
 | 
|---|
| [be945c] | 288 |       outmap->insert ( make_pair (angle, make_pair ((*MolWalker), (*MolOtherWalker)) ) );
 | 
|---|
 | 289 |     }
 | 
|---|
 | 290 |   }
 | 
|---|
| [ea430a] | 291 |   return outmap;
 | 
|---|
 | 292 | };
 | 
|---|
 | 293 | 
 | 
|---|
| [c1a9d6] | 294 | /** Calculates the pair correlation between given atom sets.
 | 
|---|
 | 295 |  *
 | 
|---|
 | 296 |  * Note we correlate each of the \a &atomsfirst with each of the second set
 | 
|---|
 | 297 |  * \a &atoms_second. However, we are aware of double counting. If an atom is
 | 
|---|
 | 298 |  * in either set, the pair is counted only once.
 | 
|---|
 | 299 |  *
 | 
|---|
 | 300 |  * \param &atoms_first vector of atoms
 | 
|---|
 | 301 |  * \param &atoms_second vector of atoms
 | 
|---|
 | 302 |  * \param max_distance maximum distance for the correlation
 | 
|---|
| [c4d4df] | 303 |  * \return Map of doubles with values the pair of the two atoms.
 | 
|---|
 | 304 |  */
 | 
|---|
| [c1a9d6] | 305 | PairCorrelationMap *PairCorrelation(
 | 
|---|
 | 306 |     const World::AtomComposite &atoms_first,
 | 
|---|
 | 307 |     const World::AtomComposite &atoms_second,
 | 
|---|
 | 308 |     const double max_distance)
 | 
|---|
| [c4d4df] | 309 | {
 | 
|---|
| [3930eb] | 310 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 311 |   PairCorrelationMap *outmap = new PairCorrelationMap;
 | 
|---|
| [e791dc] | 312 |   //double distance = 0.;
 | 
|---|
| [014475] | 313 |   Box &domain = World::getInstance().getDomain();
 | 
|---|
| [c4d4df] | 314 | 
 | 
|---|
| [c1a9d6] | 315 |   if (atoms_first.empty() || atoms_second.empty()) {
 | 
|---|
 | 316 |     ELOG(1, "No atoms given.");
 | 
|---|
| [c4d4df] | 317 |     return outmap;
 | 
|---|
 | 318 |   }
 | 
|---|
| [c78d44] | 319 | 
 | 
|---|
| [c1a9d6] | 320 |   //!> typedef for an unsorted container, (output) compatible with STL algorithms
 | 
|---|
 | 321 |   typedef std::vector<const TesselPoint *> LinkedVector;
 | 
|---|
| [c4d4df] | 322 | 
 | 
|---|
| [c1a9d6] | 323 |   // create intersection (to know when to check for double-counting)
 | 
|---|
 | 324 |   LinkedVector intersected_atoms(atoms_second.size(), NULL);
 | 
|---|
 | 325 |   LinkedVector::iterator intersected_atoms_end =
 | 
|---|
 | 326 |       std::set_intersection(
 | 
|---|
 | 327 |           atoms_first.begin(),atoms_first.end(),
 | 
|---|
 | 328 |           atoms_second.begin(), atoms_second.end(),
 | 
|---|
 | 329 |           intersected_atoms.begin());
 | 
|---|
 | 330 |   const LinkedCell::LinkedList intersected_atoms_set(intersected_atoms.begin(), intersected_atoms.end());
 | 
|---|
| [c78d44] | 331 | 
 | 
|---|
| [c1a9d6] | 332 |   // create map
 | 
|---|
| [7ea9e6] | 333 |   outmap = new PairCorrelationMap;
 | 
|---|
| [c1a9d6] | 334 | 
 | 
|---|
 | 335 |   // get linked cell view
 | 
|---|
 | 336 |   LinkedCell::LinkedCell_View LC = World::getInstance().getLinkedCell(max_distance);
 | 
|---|
 | 337 | 
 | 
|---|
 | 338 |   // convert second to _sorted_ set
 | 
|---|
 | 339 |   LinkedCell::LinkedList atoms_second_set(atoms_second.begin(), atoms_second.end());
 | 
|---|
 | 340 |   LOG(2, "INFO: first set has " << atoms_first.size()
 | 
|---|
 | 341 |       << " and second set has " << atoms_second_set.size() << " atoms.");
 | 
|---|
 | 342 | 
 | 
|---|
 | 343 |   // fill map
 | 
|---|
 | 344 |   for (World::AtomComposite::const_iterator iter = atoms_first.begin();
 | 
|---|
 | 345 |       iter != atoms_first.end();
 | 
|---|
 | 346 |       ++iter) {
 | 
|---|
 | 347 |     const TesselPoint * const Walker = *iter;
 | 
|---|
 | 348 |     LOG(3, "INFO: Current point is " << Walker->getName() << ".");
 | 
|---|
 | 349 |     // obtain all possible neighbors (that is a sorted set)
 | 
|---|
 | 350 |     LinkedCell::LinkedList ListOfNeighbors = LC.getPointsInsideSphere(
 | 
|---|
 | 351 |         max_distance,
 | 
|---|
 | 352 |         Walker->getPosition());
 | 
|---|
 | 353 |     LOG(2, "INFO: There are " << ListOfNeighbors.size() << " neighbors.");
 | 
|---|
 | 354 | 
 | 
|---|
 | 355 |     // create intersection with second set
 | 
|---|
 | 356 |     // NOTE: STL algorithms do mostly not work on sorted container because reassignment
 | 
|---|
 | 357 |     // of a value may also require changing its position.
 | 
|---|
 | 358 |     LinkedVector intersected_set(atoms_second.size(), NULL);
 | 
|---|
 | 359 |     LinkedVector::iterator intersected_end =
 | 
|---|
 | 360 |         std::set_intersection(
 | 
|---|
 | 361 |             ListOfNeighbors.begin(),ListOfNeighbors.end(),
 | 
|---|
 | 362 |             atoms_second_set.begin(), atoms_second_set.end(),
 | 
|---|
 | 363 |             intersected_set.begin());
 | 
|---|
 | 364 |     // count remaining elements
 | 
|---|
 | 365 |     LOG(2, "INFO: Intersection with second set has " << int(intersected_end - intersected_set.begin()) << " elements.");
 | 
|---|
 | 366 |     // we have some possible candidates, go through each
 | 
|---|
 | 367 |     for (LinkedVector::const_iterator neighboriter = intersected_set.begin();
 | 
|---|
 | 368 |         neighboriter != intersected_end;
 | 
|---|
 | 369 |         ++neighboriter) {
 | 
|---|
 | 370 |       const TesselPoint * const OtherWalker = (*neighboriter);
 | 
|---|
 | 371 |       LinkedCell::LinkedList::const_iterator equaliter = intersected_atoms_set.find(OtherWalker);
 | 
|---|
 | 372 |       if ((equaliter !=  intersected_atoms_set.end()) && (OtherWalker <= Walker)) {
 | 
|---|
 | 373 |         // present in both sets, assure that we are larger
 | 
|---|
 | 374 |         continue;
 | 
|---|
| [7ea9e6] | 375 |       }
 | 
|---|
| [c1a9d6] | 376 |       LOG(3, "INFO: Current other point is " << *OtherWalker << ".");
 | 
|---|
 | 377 |       const double distance = domain.periodicDistance(OtherWalker->getPosition(),Walker->getPosition());
 | 
|---|
 | 378 |       LOG(3, "INFO: Resulting distance is " << distance << ".");
 | 
|---|
 | 379 |       outmap->insert (
 | 
|---|
 | 380 |           std::pair<double, std::pair <const TesselPoint *, const TesselPoint*> > (
 | 
|---|
 | 381 |               distance,
 | 
|---|
 | 382 |               std::make_pair (Walker, OtherWalker)
 | 
|---|
 | 383 |               )
 | 
|---|
 | 384 |           );
 | 
|---|
| [7ea9e6] | 385 |     }
 | 
|---|
| [c78d44] | 386 |   }
 | 
|---|
| [c1a9d6] | 387 |   // and return
 | 
|---|
| [7ea9e6] | 388 |   return outmap;
 | 
|---|
 | 389 | };
 | 
|---|
 | 390 | 
 | 
|---|
| [c4d4df] | 391 | /** Calculates the distance (pair) correlation between a given element and a point.
 | 
|---|
| [a5551b] | 392 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 393 |  * \param &elements vector of elements to correlate with point
 | 
|---|
| [c4d4df] | 394 |  * \param *point vector to the correlation point
 | 
|---|
 | 395 |  * \return Map of dobules with values as pairs of atom and the vector
 | 
|---|
 | 396 |  */
 | 
|---|
| [e5c0a1] | 397 | CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point )
 | 
|---|
| [c4d4df] | 398 | {
 | 
|---|
| [3930eb] | 399 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 400 |   CorrelationToPointMap *outmap = new CorrelationToPointMap;
 | 
|---|
| [c4d4df] | 401 |   double distance = 0.;
 | 
|---|
| [014475] | 402 |   Box &domain = World::getInstance().getDomain();
 | 
|---|
| [c4d4df] | 403 | 
 | 
|---|
| [e65de8] | 404 |   if (molecules.empty()) {
 | 
|---|
| [47d041] | 405 |     LOG(1, "No molecule given.");
 | 
|---|
| [c4d4df] | 406 |     return outmap;
 | 
|---|
 | 407 |   }
 | 
|---|
| [e791dc] | 408 | 
 | 
|---|
| [c4d4df] | 409 |   outmap = new CorrelationToPointMap;
 | 
|---|
| [e65de8] | 410 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
 | 
|---|
| [47d041] | 411 |     LOG(2, "Current molecule is " << *MolWalker << ".");
 | 
|---|
| [e65de8] | 412 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 413 |       LOG(3, "Current atom is " << **iter << ".");
 | 
|---|
| [e5c0a1] | 414 |       for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
 | 
|---|
| [d74077] | 415 |         if ((*type == NULL) || ((*iter)->getType() == *type)) {
 | 
|---|
 | 416 |           distance = domain.periodicDistance((*iter)->getPosition(),*point);
 | 
|---|
| [47d041] | 417 |           LOG(4, "Current distance is " << distance << ".");
 | 
|---|
| [59fff1] | 418 |           outmap->insert (
 | 
|---|
 | 419 |               std::pair<double, std::pair<const atom *, const Vector*> >(
 | 
|---|
 | 420 |                   distance,
 | 
|---|
 | 421 |                   std::pair<const atom *, const Vector*> (
 | 
|---|
 | 422 |                       (*iter),
 | 
|---|
 | 423 |                       point)
 | 
|---|
 | 424 |                   )
 | 
|---|
 | 425 |               );
 | 
|---|
| [e65de8] | 426 |         }
 | 
|---|
| [c4d4df] | 427 |     }
 | 
|---|
| [e65de8] | 428 |   }
 | 
|---|
| [c4d4df] | 429 | 
 | 
|---|
 | 430 |   return outmap;
 | 
|---|
 | 431 | };
 | 
|---|
 | 432 | 
 | 
|---|
| [7ea9e6] | 433 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and a point.
 | 
|---|
 | 434 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 435 |  * \param &elements vector of elements to correlate to point
 | 
|---|
| [7ea9e6] | 436 |  * \param *point vector to the correlation point
 | 
|---|
 | 437 |  * \param ranges[NDIM] interval boundaries for the periodic images to scan also
 | 
|---|
 | 438 |  * \return Map of dobules with values as pairs of atom and the vector
 | 
|---|
 | 439 |  */
 | 
|---|
| [e5c0a1] | 440 | CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] )
 | 
|---|
| [7ea9e6] | 441 | {
 | 
|---|
| [3930eb] | 442 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 443 |   CorrelationToPointMap *outmap = new CorrelationToPointMap;
 | 
|---|
| [7ea9e6] | 444 |   double distance = 0.;
 | 
|---|
 | 445 |   int n[NDIM];
 | 
|---|
 | 446 |   Vector periodicX;
 | 
|---|
 | 447 |   Vector checkX;
 | 
|---|
 | 448 | 
 | 
|---|
| [e65de8] | 449 |   if (molecules.empty()) {
 | 
|---|
| [47d041] | 450 |     LOG(1, "No molecule given.");
 | 
|---|
| [7ea9e6] | 451 |     return outmap;
 | 
|---|
 | 452 |   }
 | 
|---|
| [e791dc] | 453 | 
 | 
|---|
| [7ea9e6] | 454 |   outmap = new CorrelationToPointMap;
 | 
|---|
| [e65de8] | 455 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
 | 
|---|
| [cca9ef] | 456 |     RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
 | 
|---|
 | 457 |     RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
 | 
|---|
| [47d041] | 458 |     LOG(2, "Current molecule is " << *MolWalker << ".");
 | 
|---|
| [e65de8] | 459 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 460 |       LOG(3, "Current atom is " << **iter << ".");
 | 
|---|
| [e5c0a1] | 461 |       for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
 | 
|---|
| [d74077] | 462 |         if ((*type == NULL) || ((*iter)->getType() == *type)) {
 | 
|---|
 | 463 |           periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
 | 
|---|
| [e65de8] | 464 |           // go through every range in xyz and get distance
 | 
|---|
 | 465 |           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
 | 
|---|
 | 466 |             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
 | 
|---|
 | 467 |               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
 | 
|---|
 | 468 |                 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
 | 
|---|
 | 469 |                 distance = checkX.distance(*point);
 | 
|---|
| [47d041] | 470 |                 LOG(4, "Current distance is " << distance << ".");
 | 
|---|
| [59fff1] | 471 |                 outmap->insert (
 | 
|---|
 | 472 |                     std::pair<double,
 | 
|---|
 | 473 |                     std::pair<const atom *, const Vector*> >(
 | 
|---|
 | 474 |                         distance,
 | 
|---|
 | 475 |                         std::pair<const atom *, const Vector*> (
 | 
|---|
 | 476 |                             *iter,
 | 
|---|
 | 477 |                             point)
 | 
|---|
 | 478 |                         )
 | 
|---|
 | 479 |                     );
 | 
|---|
| [e65de8] | 480 |               }
 | 
|---|
 | 481 |         }
 | 
|---|
| [7ea9e6] | 482 |     }
 | 
|---|
| [e65de8] | 483 |   }
 | 
|---|
| [7ea9e6] | 484 | 
 | 
|---|
 | 485 |   return outmap;
 | 
|---|
 | 486 | };
 | 
|---|
 | 487 | 
 | 
|---|
| [c4d4df] | 488 | /** Calculates the distance (pair) correlation between a given element and a surface.
 | 
|---|
| [a5551b] | 489 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 490 |  * \param &elements vector of elements to correlate to surface
 | 
|---|
| [c4d4df] | 491 |  * \param *Surface pointer to Tesselation class surface
 | 
|---|
| [6bd7e0] | 492 |  * \param *LC LinkedCell_deprecated structure to quickly find neighbouring atoms
 | 
|---|
| [c4d4df] | 493 |  * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
 | 
|---|
 | 494 |  */
 | 
|---|
| [6bd7e0] | 495 | CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell_deprecated *LC )
 | 
|---|
| [c4d4df] | 496 | {
 | 
|---|
| [3930eb] | 497 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 498 |   CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [99593f] | 499 |   double distance = 0;
 | 
|---|
| [c4d4df] | 500 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 501 |   Vector centroid;
 | 
|---|
| [7ea9e6] | 502 | 
 | 
|---|
| [e65de8] | 503 |   if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
 | 
|---|
| [47d041] | 504 |     ELOG(1, "No Tesselation, no LinkedCell or no molecule given.");
 | 
|---|
| [7ea9e6] | 505 |     return outmap;
 | 
|---|
 | 506 |   }
 | 
|---|
| [e791dc] | 507 | 
 | 
|---|
| [7ea9e6] | 508 |   outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [e65de8] | 509 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
 | 
|---|
| [47d041] | 510 |     LOG(2, "Current molecule is " << (*MolWalker)->name << ".");
 | 
|---|
| [e65de8] | 511 |     if ((*MolWalker)->empty())
 | 
|---|
| [47d041] | 512 |       LOG(2, "\t is empty.");
 | 
|---|
| [e65de8] | 513 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 514 |       LOG(3, "\tCurrent atom is " << *(*iter) << ".");
 | 
|---|
| [e5c0a1] | 515 |       for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
 | 
|---|
| [d74077] | 516 |         if ((*type == NULL) || ((*iter)->getType() == *type)) {
 | 
|---|
 | 517 |           TriangleIntersectionList Intersections((*iter)->getPosition(),Surface,LC);
 | 
|---|
| [e65de8] | 518 |           distance = Intersections.GetSmallestDistance();
 | 
|---|
 | 519 |           triangle = Intersections.GetClosestTriangle();
 | 
|---|
| [59fff1] | 520 |           outmap->insert (
 | 
|---|
 | 521 |               std::pair<double,
 | 
|---|
 | 522 |               std::pair<const atom *, BoundaryTriangleSet*> >(
 | 
|---|
 | 523 |                   distance,
 | 
|---|
 | 524 |                   std::pair<const atom *, BoundaryTriangleSet*> (
 | 
|---|
 | 525 |                       (*iter),
 | 
|---|
 | 526 |                       triangle)
 | 
|---|
 | 527 |                   )
 | 
|---|
 | 528 |               );
 | 
|---|
| [e65de8] | 529 |         }
 | 
|---|
| [7fd416] | 530 |     }
 | 
|---|
| [e65de8] | 531 |   }
 | 
|---|
| [7ea9e6] | 532 | 
 | 
|---|
 | 533 |   return outmap;
 | 
|---|
 | 534 | };
 | 
|---|
 | 535 | 
 | 
|---|
 | 536 | /** Calculates the distance (pair) correlation between a given element, all its periodic images and and a surface.
 | 
|---|
 | 537 |  * Note that we also put all periodic images found in the cells given by [ -ranges[i], ranges[i] ] and i=0,...,NDIM-1.
 | 
|---|
 | 538 |  * 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
 | 
|---|
 | 539 |  * axis an integer from [ -ranges[i], ranges[i] ] onto it and multiply with the domain matrix to bring it back into
 | 
|---|
 | 540 |  * the real space. Then, we Tesselation::FindClosestTriangleToPoint() and DistanceToTrianglePlane().
 | 
|---|
 | 541 |  * \param *molecules list of molecules structure
 | 
|---|
| [c78d44] | 542 |  * \param &elements vector of elements to correlate to surface
 | 
|---|
| [7ea9e6] | 543 |  * \param *Surface pointer to Tesselation class surface
 | 
|---|
| [6bd7e0] | 544 |  * \param *LC LinkedCell_deprecated structure to quickly find neighbouring atoms
 | 
|---|
| [7ea9e6] | 545 |  * \param ranges[NDIM] interval boundaries for the periodic images to scan also
 | 
|---|
 | 546 |  * \return Map of doubles with values as pairs of atom and the BoundaryTriangleSet that's closest
 | 
|---|
 | 547 |  */
 | 
|---|
| [6bd7e0] | 548 | CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell_deprecated *LC, const int ranges[NDIM] )
 | 
|---|
| [7ea9e6] | 549 | {
 | 
|---|
| [3930eb] | 550 |   Info FunctionInfo(__func__);
 | 
|---|
| [caa30b] | 551 |   CorrelationToSurfaceMap *outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [7ea9e6] | 552 |   double distance = 0;
 | 
|---|
 | 553 |   class BoundaryTriangleSet *triangle = NULL;
 | 
|---|
 | 554 |   Vector centroid;
 | 
|---|
| [99593f] | 555 |   int n[NDIM];
 | 
|---|
 | 556 |   Vector periodicX;
 | 
|---|
 | 557 |   Vector checkX;
 | 
|---|
| [c4d4df] | 558 | 
 | 
|---|
| [e65de8] | 559 |   if ((Surface == NULL) || (LC == NULL) || (molecules.empty())) {
 | 
|---|
| [47d041] | 560 |     LOG(1, "No Tesselation, no LinkedCell or no molecule given.");
 | 
|---|
| [c4d4df] | 561 |     return outmap;
 | 
|---|
 | 562 |   }
 | 
|---|
| [e791dc] | 563 | 
 | 
|---|
| [c4d4df] | 564 |   outmap = new CorrelationToSurfaceMap;
 | 
|---|
| [244a84] | 565 |   double ShortestDistance = 0.;
 | 
|---|
 | 566 |   BoundaryTriangleSet *ShortestTriangle = NULL;
 | 
|---|
| [e65de8] | 567 |   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin(); MolWalker != molecules.end(); MolWalker++) {
 | 
|---|
| [cca9ef] | 568 |     RealSpaceMatrix FullMatrix = World::getInstance().getDomain().getM();
 | 
|---|
 | 569 |     RealSpaceMatrix FullInverseMatrix = World::getInstance().getDomain().getMinv();
 | 
|---|
| [47d041] | 570 |     LOG(2, "Current molecule is " << *MolWalker << ".");
 | 
|---|
| [e65de8] | 571 |     for (molecule::const_iterator iter = (*MolWalker)->begin(); iter != (*MolWalker)->end(); ++iter) {
 | 
|---|
| [47d041] | 572 |       LOG(3, "Current atom is " << **iter << ".");
 | 
|---|
| [e5c0a1] | 573 |       for (vector<const element *>::const_iterator type = elements.begin(); type != elements.end(); ++type)
 | 
|---|
| [d74077] | 574 |         if ((*type == NULL) || ((*iter)->getType() == *type)) {
 | 
|---|
 | 575 |           periodicX = FullInverseMatrix * ((*iter)->getPosition()); // x now in [0,1)^3
 | 
|---|
| [e65de8] | 576 |           // go through every range in xyz and get distance
 | 
|---|
 | 577 |           ShortestDistance = -1.;
 | 
|---|
 | 578 |           for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
 | 
|---|
 | 579 |             for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
 | 
|---|
 | 580 |               for (n[2]=-ranges[2]; n[2] <= ranges[2]; n[2]++) {
 | 
|---|
 | 581 |                 checkX = FullMatrix * (Vector(n[0], n[1], n[2]) + periodicX);
 | 
|---|
| [d74077] | 582 |                 TriangleIntersectionList Intersections(checkX,Surface,LC);
 | 
|---|
| [e65de8] | 583 |                 distance = Intersections.GetSmallestDistance();
 | 
|---|
 | 584 |                 triangle = Intersections.GetClosestTriangle();
 | 
|---|
 | 585 |                 if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
 | 
|---|
 | 586 |                   ShortestDistance = distance;
 | 
|---|
 | 587 |                   ShortestTriangle = triangle;
 | 
|---|
| [99593f] | 588 |                 }
 | 
|---|
| [e65de8] | 589 |               }
 | 
|---|
 | 590 |           // insert
 | 
|---|
| [59fff1] | 591 |           outmap->insert (
 | 
|---|
 | 592 |               std::pair<double,
 | 
|---|
 | 593 |               std::pair<const atom *, BoundaryTriangleSet*> >(
 | 
|---|
 | 594 |                   ShortestDistance,
 | 
|---|
 | 595 |                   std::pair<const atom *, BoundaryTriangleSet*> (
 | 
|---|
 | 596 |                       *iter,
 | 
|---|
 | 597 |                       ShortestTriangle)
 | 
|---|
 | 598 |                   )
 | 
|---|
 | 599 |               );
 | 
|---|
| [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 | };
 | 
|---|