source: src/Analysis/analysis_correlation.hpp@ aec098

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

Rewrote PairCorrelation() to make use of new LinkedCell construct.

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