source: src/Analysis/analysis_correlation.hpp@ 47d041

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 47d041 was 47d041, checked in by Frederik Heber <heber@…>, 13 years ago

HUGE: Removed all calls to Log(), eLog(), replaced by LOG() and ELOG().

  • Replaced DoLog(.) && (Log() << Verbose(.) << ... << std::endl) by Log(., ...).
  • Replaced Log() << Verbose(.) << .. << by Log(., ...)
  • on multiline used stringstream to generate and message which was finally used in LOG(., output.str())
  • there should be no more occurence of Log(). LOG() and ELOG() must be used instead.
  • Eventually, this will allow for storing all errors and re-printing them on program exit which would be very helpful to ascertain error-free runs for the user.
  • Property mode set to 100644
File size: 7.9 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.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
37/****************************************** forward declarations *****************************/
38
39class BoundaryTriangleSet;
40class Formula;
41class element;
42class LinkedCell;
43class Tesselation;
44class Vector;
45
46/********************************************** definitions *********************************/
47
48typedef multimap<double, pair<atom *, atom *> > PairCorrelationMap;
49typedef multimap<double, atom * > DipoleAngularCorrelationMap;
50typedef multimap<double, pair<molecule *, molecule *> > DipoleCorrelationMap;
51typedef multimap<double, pair<atom *, const Vector *> > CorrelationToPointMap;
52typedef multimap<double, pair<atom *, BoundaryTriangleSet *> > CorrelationToSurfaceMap;
53typedef map<double, int> BinPairMap;
54
55enum ResetWorldTime {
56 DontResetTime,
57 DoResetTime
58};
59
60/********************************************** declarations *******************************/
61
62range<size_t> getMaximumTrajectoryBounds(const std::vector<atom *> &atoms);
63std::map<atomId_t, Vector> CalculateZeroAngularDipole(const std::vector<molecule *> &molecules);
64
65DipoleAngularCorrelationMap *DipoleAngularCorrelation(const Formula &DipoleFormula, const size_t timestep, const std::map<atomId_t, Vector> &ZeroVector, const enum ResetWorldTime DoTimeReset = DontResetTime);
66DipoleCorrelationMap *DipoleCorrelation(std::vector<molecule *> &molecules);
67PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements);
68CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point );
69CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC );
70PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] );
71CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] );
72CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
73int GetBin ( const double value, const double BinWidth, const double BinStart );
74void OutputCorrelation_Header( ofstream * const file );
75void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner );
76void OutputDipoleAngularCorrelation_Header( ofstream * const file );
77void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner );
78void OutputDipoleCorrelation_Header( ofstream * const file );
79void OutputDipoleCorrelation_Value( ofstream * const file, DipoleCorrelationMap::const_iterator &runner );
80void OutputPairCorrelation_Header( ofstream * const file );
81void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner );
82void OutputCorrelationToPoint_Header( ofstream * const file );
83void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner );
84void OutputCorrelationToSurface_Header( ofstream * const file );
85void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner );
86
87/** Searches for lowest and highest value in a given map of doubles.
88 * \param *map map of doubles to scan
89 * \param &min minimum on return
90 * \param &max maximum on return
91 */
92template <typename T> void GetMinMax ( T *map, double &min, double &max)
93{
94 min = 0.;
95 max = 0.;
96 bool FirstMinFound = false;
97 bool FirstMaxFound = false;
98
99 if (map == NULL) {
100 ELOG(0, "Nothing to min/max, map is NULL!");
101 performCriticalExit();
102 return;
103 }
104
105 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
106 if ((min > runner->first) || (!FirstMinFound)) {
107 min = runner->first;
108 FirstMinFound = true;
109 }
110 if ((max < runner->first) || (!FirstMaxFound)) {
111 max = runner->first;
112 FirstMaxFound = true;
113 }
114 }
115};
116
117/** Puts given correlation data into bins of given size (histogramming).
118 * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
119 * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater. If a
120 * certain start value is desired, give BinStart and a BinEnd that is smaller than BinStart, then only BinEnd will be
121 * calculated automatically, i.e. BinStart = 0. and BinEnd = -1. .
122 * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
123 * \param *map map of doubles to count
124 * \param BinWidth desired width of the binds
125 * \param BinStart first bin
126 * \param BinEnd last bin
127 * \return Map of doubles (the bins) with counts as values
128 */
129template <typename T> BinPairMap *BinData ( T *map, const double BinWidth, const double BinStart, const double BinEnd )
130{
131 BinPairMap *outmap = new BinPairMap;
132 int bin = 0;
133 double start = 0.;
134 double end = 0.;
135 pair <BinPairMap::iterator, bool > BinPairMapInserter;
136
137 if (map == NULL) {
138 ELOG(0, "Nothing to bin, is NULL!");
139 performCriticalExit();
140 return outmap;
141 }
142
143 if (BinStart == BinEnd) { // if same, find range ourselves
144 GetMinMax( map, start, end);
145 } else if (BinEnd < BinStart) { // if BinEnd smaller, just look for new max
146 GetMinMax( map, start, end);
147 start = BinStart;
148 } else { // else take both values
149 start = BinStart;
150 end = BinEnd;
151 }
152 for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
153 outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
154
155 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
156 bin = GetBin (runner->first, BinWidth, start);
157 BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
158 if (!BinPairMapInserter.second) { // bin already present, increase
159 BinPairMapInserter.first->second += 1;
160 }
161 }
162
163 return outmap;
164};
165
166/** Prints correlation map of template type to file.
167 * \param *file file to write to
168 * \param *map map to write
169 * \param (*header) pointer to function that adds specific part to header
170 * \param (*value) pointer to function that prints value from given iterator
171 */
172template <typename T>
173void OutputCorrelationMap(
174 ofstream * const file,
175 const T * const map,
176 void (*header)( ofstream * const file),
177 void (*value)( ofstream * const file, typename T::const_iterator &runner)
178 )
179{
180 Info FunctionInfo(__func__);
181 *file << "BinStart\tBinCenter\tBinEnd";
182 header(file);
183 *file << endl;
184 typename T::const_iterator advancer = map->begin();
185 typename T::const_iterator runner = map->begin();
186 if (advancer != map->end())
187 advancer++;
188 for ( ;(advancer != map->end()) && (runner != map->end()); ++advancer, ++runner) {
189 *file << setprecision(8)
190 << runner->first << "\t"
191 << (advancer->first + runner->first)/2. << "\t"
192 << advancer->first << "\t";
193 value(file, runner);
194 *file << endl;
195 }
196 if(runner != map->end()) {
197 *file << setprecision(8) << runner->first << "\t0\t0\t";
198 value(file, runner);
199 *file << endl;
200 }
201};
202
203
204#endif /* ANALYSIS_HPP_ */
Note: See TracBrowser for help on using the repository browser.