source: src/Analysis/analysis_correlation.hpp@ fac58f

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 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 fac58f was 99db9b, checked in by Frederik Heber <heber@…>, 9 years ago

Replaced all World::getSelected...() to const version where possible.

  • also added const version of World::getSelectedAtoms().
  • Property mode set to 100644
File size: 8.4 KB
RevLine 
[c4d4df]1/*
2 * analysis.hpp
3 *
4 * Created on: Oct 13, 2009
5 * Author: heber
6 */
7
8#ifndef ANALYSIS_HPP_
9#define ANALYSIS_HPP_
10
11using namespace std;
12
13/*********************************************** includes ***********************************/
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
[146cff2]20#include <cmath>
[92e5cb]21#include <iomanip>
[c4d4df]22#include <fstream>
23
24// STL headers
25#include <map>
[e65de8]26#include <vector>
[c4d4df]27
[e4fe8d]28#include "Helpers/defs.hpp"
[c4d4df]29
[6f0841]30#include "Atom/atom.hpp"
[92e5cb]31#include "CodePatterns/Info.hpp"
32#include "CodePatterns/Log.hpp"
[1cc661]33#include "CodePatterns/Range.hpp"
[ad011c]34#include "CodePatterns/Verbose.hpp"
[255829]35#include "Helpers/helpers.hpp"
[c1a9d6]36#include "World.hpp"
[c4d4df]37
38/****************************************** forward declarations *****************************/
39
40class BoundaryTriangleSet;
[ea430a]41class Formula;
[c4d4df]42class element;
[6bd7e0]43class LinkedCell_deprecated;
[c4d4df]44class Tesselation;
45class Vector;
46
47/********************************************** definitions *********************************/
48
[c1a9d6]49typedef multimap<double, pair<const TesselPoint *, const TesselPoint *> > PairCorrelationMap;
[59fff1]50typedef multimap<double, const atom * > DipoleAngularCorrelationMap;
51typedef multimap<double, pair<const molecule *, const molecule *> > DipoleCorrelationMap;
52typedef multimap<double, pair<const atom *, const Vector *> > CorrelationToPointMap;
53typedef multimap<double, pair<const atom *, BoundaryTriangleSet *> > CorrelationToSurfaceMap;
[c4d4df]54typedef map<double, int> BinPairMap;
55
[99b87a]56enum ResetWorldTime {
57 DontResetTime,
58 DoResetTime
59};
60
[c4d4df]61/********************************************** declarations *******************************/
62
[99db9b]63range<size_t> getMaximumTrajectoryBounds(
64 const std::vector<const atom *> &atoms);
65std::map<atomId_t, Vector> CalculateZeroAngularDipole(
66 const std::vector<const molecule *> &molecules);
67
68DipoleAngularCorrelationMap *DipoleAngularCorrelation(
69 const Formula &DipoleFormula,
70 const size_t timestep,
71 const std::map<atomId_t, Vector> &ZeroVector,
72 const enum ResetWorldTime DoTimeReset = DontResetTime);
73DipoleCorrelationMap *DipoleCorrelation(
74 const std::vector<const molecule *> &molecules);
[c1a9d6]75PairCorrelationMap *PairCorrelation(
[a58c16]76 const World::ConstAtomComposite &atoms_first,
77 const World::ConstAtomComposite &atoms_second,
[c1a9d6]78 const double max_distance);
[99db9b]79CorrelationToPointMap *CorrelationToPoint(
80 const std::vector<const molecule *> &molecules,
81 const std::vector<const element *> &elements,
82 const Vector *point );
83CorrelationToSurfaceMap *CorrelationToSurface(
84 const std::vector<const molecule *> &molecules,
85 const std::vector<const element *> &elements,
86 const Tesselation * const Surface,
87 const LinkedCell_deprecated *LC );
88CorrelationToPointMap *PeriodicCorrelationToPoint(
89 const std::vector<const molecule *> &molecules,
90 const std::vector<const element *> &elements,
91 const Vector *point, const int ranges[NDIM] );
92CorrelationToSurfaceMap *PeriodicCorrelationToSurface(
93 const std::vector<const molecule *> &molecules,
94 const std::vector<const element *> &elements,
95 const Tesselation * const Surface,
96 const LinkedCell_deprecated *LC,
97 const int ranges[NDIM] );
98int GetBin (
99 const double value,
100 const double BinWidth,
101 const double BinStart );
102void OutputCorrelation_Header(
103 ofstream * const file );
104void OutputCorrelation_Value(
105 ofstream * const file,
106 BinPairMap::const_iterator &runner );
107void OutputDipoleAngularCorrelation_Header(
108 ofstream * const file );
109void OutputDipoleAngularCorrelation_Value(
110 ofstream * const file,
111 DipoleAngularCorrelationMap::const_iterator &runner );
112void OutputDipoleCorrelation_Header(
113 ofstream * const file );
114void OutputDipoleCorrelation_Value(
115 ofstream * const file,
116 DipoleCorrelationMap::const_iterator &runner );
117void OutputPairCorrelation_Header(
118 ofstream * const file );
119void OutputPairCorrelation_Value(
120 ofstream * const file,
121 PairCorrelationMap::const_iterator &runner );
122void OutputCorrelationToPoint_Header(
123 ofstream * const file );
124void OutputCorrelationToPoint_Value(
125 ofstream * const file,
126 CorrelationToPointMap::const_iterator &runner );
127void OutputCorrelationToSurface_Header(
128 ofstream * const file );
129void OutputCorrelationToSurface_Value(
130 ofstream * const file,
131 CorrelationToSurfaceMap::const_iterator &runner );
[c4d4df]132
133/** Searches for lowest and highest value in a given map of doubles.
134 * \param *map map of doubles to scan
135 * \param &min minimum on return
136 * \param &max maximum on return
137 */
138template <typename T> void GetMinMax ( T *map, double &min, double &max)
139{
140 min = 0.;
141 max = 0.;
142 bool FirstMinFound = false;
143 bool FirstMaxFound = false;
144
[f74d08]145 if (map == NULL) {
[47d041]146 ELOG(0, "Nothing to min/max, map is NULL!");
[e359a8]147 performCriticalExit();
[f74d08]148 return;
149 }
150
[c4d4df]151 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
152 if ((min > runner->first) || (!FirstMinFound)) {
153 min = runner->first;
154 FirstMinFound = true;
155 }
156 if ((max < runner->first) || (!FirstMaxFound)) {
157 max = runner->first;
158 FirstMaxFound = true;
159 }
160 }
161};
162
163/** Puts given correlation data into bins of given size (histogramming).
164 * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
[790807]165 * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater. If a
166 * certain start value is desired, give BinStart and a BinEnd that is smaller than BinStart, then only BinEnd will be
167 * calculated automatically, i.e. BinStart = 0. and BinEnd = -1. .
[c4d4df]168 * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
169 * \param *map map of doubles to count
170 * \param BinWidth desired width of the binds
171 * \param BinStart first bin
172 * \param BinEnd last bin
173 * \return Map of doubles (the bins) with counts as values
174 */
[e138de]175template <typename T> BinPairMap *BinData ( T *map, const double BinWidth, const double BinStart, const double BinEnd )
[c4d4df]176{
177 BinPairMap *outmap = new BinPairMap;
[bd61b41]178 int bin = 0;
[c4d4df]179 double start = 0.;
180 double end = 0.;
181 pair <BinPairMap::iterator, bool > BinPairMapInserter;
182
[f74d08]183 if (map == NULL) {
[47d041]184 ELOG(0, "Nothing to bin, is NULL!");
[e359a8]185 performCriticalExit();
[f74d08]186 return outmap;
187 }
188
[c4d4df]189 if (BinStart == BinEnd) { // if same, find range ourselves
190 GetMinMax( map, start, end);
[790807]191 } else if (BinEnd < BinStart) { // if BinEnd smaller, just look for new max
192 GetMinMax( map, start, end);
193 start = BinStart;
194 } else { // else take both values
[c4d4df]195 start = BinStart;
196 end = BinEnd;
197 }
[e9bdef]198 // limit precision of start and end bin to 6 digits
199 const double precision = 1e-6/BinWidth;
200 end = precision*floor(end/precision);
201 start = precision*floor(start/precision);
[85da4e]202 for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
203 outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
[c4d4df]204
205 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
206 bin = GetBin (runner->first, BinWidth, start);
[bd61b41]207 BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
[c4d4df]208 if (!BinPairMapInserter.second) { // bin already present, increase
209 BinPairMapInserter.first->second += 1;
[c1a9d6]210 } else { // bin not present, then remove again
211 outmap->erase(BinPairMapInserter.first);
[c4d4df]212 }
213 }
214
215 return outmap;
216};
217
[92e5cb]218/** Prints correlation map of template type to file.
219 * \param *file file to write to
220 * \param *map map to write
221 * \param (*header) pointer to function that adds specific part to header
222 * \param (*value) pointer to function that prints value from given iterator
223 */
224template <typename T>
225void OutputCorrelationMap(
226 ofstream * const file,
227 const T * const map,
228 void (*header)( ofstream * const file),
229 void (*value)( ofstream * const file, typename T::const_iterator &runner)
230 )
231{
232 Info FunctionInfo(__func__);
233 *file << "BinStart\tBinCenter\tBinEnd";
234 header(file);
235 *file << endl;
236 typename T::const_iterator advancer = map->begin();
237 typename T::const_iterator runner = map->begin();
238 if (advancer != map->end())
239 advancer++;
240 for ( ;(advancer != map->end()) && (runner != map->end()); ++advancer, ++runner) {
241 *file << setprecision(8)
242 << runner->first << "\t"
243 << (advancer->first + runner->first)/2. << "\t"
244 << advancer->first << "\t";
245 value(file, runner);
246 *file << endl;
247 }
248 if(runner != map->end()) {
249 *file << setprecision(8) << runner->first << "\t0\t0\t";
250 value(file, runner);
251 *file << endl;
252 }
253};
254
255
[c4d4df]256#endif /* ANALYSIS_HPP_ */
Note: See TracBrowser for help on using the repository browser.