source: src/Analysis/analysis_correlation.cpp@ 72105a

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 Candidate_v1.7.0 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 72105a was 72105a, checked in by Frederik Heber <heber@…>, 14 years ago

Verbosity fix: DipoleAngularCorrelation() - info given when ZeroVector and atoms sizes mismatch.

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