source: src/analysis_correlation.hpp@ cd7a87

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

New DipoleAngularCorrelationAction that calculates angular correlation between dipoles.

  • Property mode set to 100644
File size: 5.6 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 <fstream>
22
23// STL headers
24#include <map>
25#include <vector>
26
27#include "Helpers/defs.hpp"
28
29#include "atom.hpp"
30#include "CodePatterns/Verbose.hpp"
31
32/****************************************** forward declarations *****************************/
33
34class BoundaryTriangleSet;
35class Formula;
36class element;
37class LinkedCell;
38class Tesselation;
39class Vector;
40
41/********************************************** definitions *********************************/
42
43typedef multimap<double, pair<atom *, atom *> > PairCorrelationMap;
44typedef multimap<double, pair<molecule *, molecule *> > DipoleAngularCorrelationMap;
45typedef multimap<double, pair<atom *, const Vector *> > CorrelationToPointMap;
46typedef multimap<double, pair<atom *, BoundaryTriangleSet *> > CorrelationToSurfaceMap;
47typedef map<double, int> BinPairMap;
48
49/********************************************** declarations *******************************/
50
51DipoleAngularCorrelationMap *DipoleAngularCorrelation(std::vector<molecule *> &molecules);
52PairCorrelationMap *PairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements);
53CorrelationToPointMap *CorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point );
54CorrelationToSurfaceMap *CorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC );
55PairCorrelationMap *PeriodicPairCorrelation(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const int ranges[NDIM] );
56CorrelationToPointMap *PeriodicCorrelationToPoint(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Vector *point, const int ranges[NDIM] );
57CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
58int GetBin ( const double value, const double BinWidth, const double BinStart );
59void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
60void OutputDipoleAngularCorrelation( ofstream * const file, const DipoleAngularCorrelationMap * const map );
61void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map );
62void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map );
63void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map );
64
65
66/** Searches for lowest and highest value in a given map of doubles.
67 * \param *map map of doubles to scan
68 * \param &min minimum on return
69 * \param &max maximum on return
70 */
71template <typename T> void GetMinMax ( T *map, double &min, double &max)
72{
73 min = 0.;
74 max = 0.;
75 bool FirstMinFound = false;
76 bool FirstMaxFound = false;
77
78 if (map == NULL) {
79 DoeLog(0) && (eLog()<< Verbose(0) << "Nothing to min/max, map is NULL!" << endl);
80 performCriticalExit();
81 return;
82 }
83
84 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
85 if ((min > runner->first) || (!FirstMinFound)) {
86 min = runner->first;
87 FirstMinFound = true;
88 }
89 if ((max < runner->first) || (!FirstMaxFound)) {
90 max = runner->first;
91 FirstMaxFound = true;
92 }
93 }
94};
95
96/** Puts given correlation data into bins of given size (histogramming).
97 * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
98 * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater. If a
99 * certain start value is desired, give BinStart and a BinEnd that is smaller than BinStart, then only BinEnd will be
100 * calculated automatically, i.e. BinStart = 0. and BinEnd = -1. .
101 * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
102 * \param *map map of doubles to count
103 * \param BinWidth desired width of the binds
104 * \param BinStart first bin
105 * \param BinEnd last bin
106 * \return Map of doubles (the bins) with counts as values
107 */
108template <typename T> BinPairMap *BinData ( T *map, const double BinWidth, const double BinStart, const double BinEnd )
109{
110 BinPairMap *outmap = new BinPairMap;
111 int bin = 0;
112 double start = 0.;
113 double end = 0.;
114 pair <BinPairMap::iterator, bool > BinPairMapInserter;
115
116 if (map == NULL) {
117 DoeLog(0) && (eLog()<< Verbose(0) << "Nothing to bin, is NULL!" << endl);
118 performCriticalExit();
119 return outmap;
120 }
121
122 if (BinStart == BinEnd) { // if same, find range ourselves
123 GetMinMax( map, start, end);
124 } else if (BinEnd < BinStart) { // if BinEnd smaller, just look for new max
125 GetMinMax( map, start, end);
126 start = BinStart;
127 } else { // else take both values
128 start = BinStart;
129 end = BinEnd;
130 }
131 for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
132 outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
133
134 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
135 bin = GetBin (runner->first, BinWidth, start);
136 BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
137 if (!BinPairMapInserter.second) { // bin already present, increase
138 BinPairMapInserter.first->second += 1;
139 }
140 }
141
142 return outmap;
143};
144
145#endif /* ANALYSIS_HPP_ */
Note: See TracBrowser for help on using the repository browser.