source: src/analysis_correlation.hpp@ 4217e7

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 4217e7 was 255829, checked in by Frederik Heber <heber@…>, 14 years ago

Removed Helpers.hpp, deleted Helpers.cpp and libMoleCuilderHelpers.la is history.

  • defs.cpp is now compiled into libmolecuilder.la.
  • ShapeUnitTest alone needs defs.cpp.
  • Most changes are removal of Helpers/helpers.hpp.
  • performCriticalExit() now inline function in Helpers/helpers.hpp.
  • also inclusion possible where performCriticalExit() is needed.
  • Helpers/helpers.hpp does not include defs.hpp anymore and this causes lots of missing Helpers/defs.hpp, CodePatterns/Log.hpp and alikes.
  • removed src/Helpers from configure.ac.
  • Property mode set to 100644
File size: 7.3 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/Verbose.hpp"
34#include "Helpers/helpers.hpp"
35
36/****************************************** forward declarations *****************************/
37
38class BoundaryTriangleSet;
39class Formula;
40class element;
41class LinkedCell;
42class Tesselation;
43class Vector;
44
45/********************************************** definitions *********************************/
46
47typedef multimap<double, pair<atom *, atom *> > PairCorrelationMap;
48typedef multimap<double, pair<molecule *, molecule *> > DipoleAngularCorrelationMap;
49typedef multimap<double, pair<atom *, const Vector *> > CorrelationToPointMap;
50typedef multimap<double, pair<atom *, BoundaryTriangleSet *> > CorrelationToSurfaceMap;
51typedef map<double, int> BinPairMap;
52
53/********************************************** declarations *******************************/
54
55DipoleAngularCorrelationMap *DipoleAngularCorrelation(std::vector<molecule *> &molecules);
56PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements);
57CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point );
58CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC );
59PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] );
60CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] );
61CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
62int GetBin ( const double value, const double BinWidth, const double BinStart );
63void OutputCorrelation_Header( ofstream * const file );
64void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner );
65void OutputDipoleAngularCorrelation_Header( ofstream * const file );
66void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner );
67void OutputPairCorrelation_Header( ofstream * const file );
68void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner );
69void OutputCorrelationToPoint_Header( ofstream * const file );
70void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner );
71void OutputCorrelationToSurface_Header( ofstream * const file );
72void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner );
73
74/** Searches for lowest and highest value in a given map of doubles.
75 * \param *map map of doubles to scan
76 * \param &min minimum on return
77 * \param &max maximum on return
78 */
79template <typename T> void GetMinMax ( T *map, double &min, double &max)
80{
81 min = 0.;
82 max = 0.;
83 bool FirstMinFound = false;
84 bool FirstMaxFound = false;
85
86 if (map == NULL) {
87 DoeLog(0) && (eLog()<< Verbose(0) << "Nothing to min/max, map is NULL!" << endl);
88 performCriticalExit();
89 return;
90 }
91
92 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
93 if ((min > runner->first) || (!FirstMinFound)) {
94 min = runner->first;
95 FirstMinFound = true;
96 }
97 if ((max < runner->first) || (!FirstMaxFound)) {
98 max = runner->first;
99 FirstMaxFound = true;
100 }
101 }
102};
103
104/** Puts given correlation data into bins of given size (histogramming).
105 * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
106 * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater. If a
107 * certain start value is desired, give BinStart and a BinEnd that is smaller than BinStart, then only BinEnd will be
108 * calculated automatically, i.e. BinStart = 0. and BinEnd = -1. .
109 * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
110 * \param *map map of doubles to count
111 * \param BinWidth desired width of the binds
112 * \param BinStart first bin
113 * \param BinEnd last bin
114 * \return Map of doubles (the bins) with counts as values
115 */
116template <typename T> BinPairMap *BinData ( T *map, const double BinWidth, const double BinStart, const double BinEnd )
117{
118 BinPairMap *outmap = new BinPairMap;
119 int bin = 0;
120 double start = 0.;
121 double end = 0.;
122 pair <BinPairMap::iterator, bool > BinPairMapInserter;
123
124 if (map == NULL) {
125 DoeLog(0) && (eLog()<< Verbose(0) << "Nothing to bin, is NULL!" << endl);
126 performCriticalExit();
127 return outmap;
128 }
129
130 if (BinStart == BinEnd) { // if same, find range ourselves
131 GetMinMax( map, start, end);
132 } else if (BinEnd < BinStart) { // if BinEnd smaller, just look for new max
133 GetMinMax( map, start, end);
134 start = BinStart;
135 } else { // else take both values
136 start = BinStart;
137 end = BinEnd;
138 }
139 for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
140 outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
141
142 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
143 bin = GetBin (runner->first, BinWidth, start);
144 BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
145 if (!BinPairMapInserter.second) { // bin already present, increase
146 BinPairMapInserter.first->second += 1;
147 }
148 }
149
150 return outmap;
151};
152
153/** Prints correlation map of template type to file.
154 * \param *file file to write to
155 * \param *map map to write
156 * \param (*header) pointer to function that adds specific part to header
157 * \param (*value) pointer to function that prints value from given iterator
158 */
159template <typename T>
160void OutputCorrelationMap(
161 ofstream * const file,
162 const T * const map,
163 void (*header)( ofstream * const file),
164 void (*value)( ofstream * const file, typename T::const_iterator &runner)
165 )
166{
167 Info FunctionInfo(__func__);
168 *file << "BinStart\tBinCenter\tBinEnd";
169 header(file);
170 *file << endl;
171 typename T::const_iterator advancer = map->begin();
172 typename T::const_iterator runner = map->begin();
173 if (advancer != map->end())
174 advancer++;
175 for ( ;(advancer != map->end()) && (runner != map->end()); ++advancer, ++runner) {
176 *file << setprecision(8)
177 << runner->first << "\t"
178 << (advancer->first + runner->first)/2. << "\t"
179 << advancer->first << "\t";
180 value(file, runner);
181 *file << endl;
182 }
183 if(runner != map->end()) {
184 *file << setprecision(8) << runner->first << "\t0\t0\t";
185 value(file, runner);
186 *file << endl;
187 }
188};
189
190
191#endif /* ANALYSIS_HPP_ */
Note: See TracBrowser for help on using the repository browser.