source: src/Analysis/analysis_correlation.hpp@ 4464ef

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4464ef 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
Line 
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
20#include <cmath>
21#include <iomanip>
22#include <fstream>
23
24// STL headers
25#include <map>
26#include <vector>
27
28#include "Helpers/defs.hpp"
29
30#include "Atom/atom.hpp"
31#include "CodePatterns/Info.hpp"
32#include "CodePatterns/Log.hpp"
33#include "CodePatterns/Range.hpp"
34#include "CodePatterns/Verbose.hpp"
35#include "Helpers/helpers.hpp"
36#include "World.hpp"
37
38/****************************************** forward declarations *****************************/
39
40class BoundaryTriangleSet;
41class Formula;
42class element;
43class LinkedCell_deprecated;
44class Tesselation;
45class Vector;
46
47/********************************************** definitions *********************************/
48
49typedef multimap<double, pair<const TesselPoint *, const TesselPoint *> > PairCorrelationMap;
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;
54typedef map<double, int> BinPairMap;
55
56enum ResetWorldTime {
57 DontResetTime,
58 DoResetTime
59};
60
61/********************************************** declarations *******************************/
62
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);
75PairCorrelationMap *PairCorrelation(
76 const World::ConstAtomComposite &atoms_first,
77 const World::ConstAtomComposite &atoms_second,
78 const double max_distance);
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 );
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
145 if (map == NULL) {
146 ELOG(0, "Nothing to min/max, map is NULL!");
147 performCriticalExit();
148 return;
149 }
150
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
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. .
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 */
175template <typename T> BinPairMap *BinData ( T *map, const double BinWidth, const double BinStart, const double BinEnd )
176{
177 BinPairMap *outmap = new BinPairMap;
178 int bin = 0;
179 double start = 0.;
180 double end = 0.;
181 pair <BinPairMap::iterator, bool > BinPairMapInserter;
182
183 if (map == NULL) {
184 ELOG(0, "Nothing to bin, is NULL!");
185 performCriticalExit();
186 return outmap;
187 }
188
189 if (BinStart == BinEnd) { // if same, find range ourselves
190 GetMinMax( map, start, end);
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
195 start = BinStart;
196 end = BinEnd;
197 }
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);
202 for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
203 outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
204
205 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
206 bin = GetBin (runner->first, BinWidth, start);
207 BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
208 if (!BinPairMapInserter.second) { // bin already present, increase
209 BinPairMapInserter.first->second += 1;
210 } else { // bin not present, then remove again
211 outmap->erase(BinPairMapInserter.first);
212 }
213 }
214
215 return outmap;
216};
217
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
256#endif /* ANALYSIS_HPP_ */
Note: See TracBrowser for help on using the repository browser.