source: src/Fragmentation/Exporters/SphericalPointDistribution.hpp@ 23c605

Last change on this file since 23c605 was 23c605, checked in by Frederik Heber <heber@…>, 11 years ago

SphericalPointDistribution is now working with bond degree weights.

  • recurseMatching() now works on IndexTupleList_t.
  • also rewrote calculatePairwiseDistances() and calculateErrorOfMatching().
  • L1THRESHOLD in recurseMatching() moved over to class body.
  • increased verbosity level of ...Matching() functions by one, added note on eventually chosen matching and why.
  • we assert that bestL2 is not too large.
  • FIX: calculateErrorOfMatching() did not use absolute value of gap for L1 error.
  • TESTS: Regresssion test FragmentMolecule-cycles working again.
  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * SphericalPointDistribution.hpp
3 *
4 * Created on: May 29, 2014
5 * Author: heber
6 */
7
8
9#ifndef SPHERICALPOINTDISTRIBUTION_HPP_
10#define SPHERICALPOINTDISTRIBUTION_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include "CodePatterns/Assert.hpp"
18
19#include <cmath>
20#include <list>
21
22#include "LinearAlgebra/Vector.hpp"
23
24class SphericalPointDistributionTest;
25
26/** contains getters for the VSEPR model for specific number of electrons.
27 *
28 * This struct contains specialized functions returning a list of Vectors
29 * (points in space) to match the VSEPR model for the given number of electrons.
30 *
31 * This is implemented via template specialization of the function get().
32 *
33 * These specializations are taken from the python script \b CreateVspeShapes.py
34 * by Christian Neuen, 07th May 2009.
35 */
36struct SphericalPointDistribution
37{
38 /** Cstor for SphericalPointDistribution, allows setting radius of sphere
39 *
40 * \param _BondLength desired radius of sphere
41 */
42 SphericalPointDistribution(const double _Bondlength = 1.) :
43 Bondlength(_Bondlength),
44 SQRT_3(sqrt(3.0))
45 {}
46
47 //!> typedef for the list of points
48 typedef std::list<Vector> Polygon_t;
49 //!> typedef for the list of points with integral weights
50 typedef std::list<std::pair<Vector, int> > WeightedPolygon_t;
51
52 /** General getter function for the distribution of points on the surface.
53 *
54 * \warn this function needs to be specialized!
55 *
56 * \return Polygon_t with points on the surface centered at (0,0,0)
57 */
58 template <int N> Polygon_t get()
59 {
60 ASSERT(0, "SphericalPointDistribution::get() - not specialized for "+toString(N)+".");
61 }
62
63
64 /** Matches a given spherical distribution with another containing more
65 * points.
66 *
67 * The idea is to produce a matching from all points in \a _polygon to those
68 * in \a _newpolygon in such a way that their distance difference is minimal.
69 * As we just look at numbers of points determined by valency, i.e.
70 * independent of the number of atoms, we simply go through each of the possible
71 * mappings. We stop when the L1 error is below a certain \a threshold,
72 * otherwise we pick the matching with the lowest L2 error.
73 *
74 * This is a helper to determine points where to best insert saturation
75 * hydrogens.
76 *
77 * \param _polygon current occupied positions
78 * \param _newpolygon ideal distribution to match best with current occupied
79 * positions
80 * \return remaining vacant positions relative to \a _polygon
81 */
82 static Polygon_t matchSphericalPointDistributions(
83 const WeightedPolygon_t &_polygon,
84 Polygon_t &_newpolygon
85 );
86
87 //!> default radius of the spherical distribution
88 const double Bondlength;
89 //!> precalculated value for root of 3
90 const double SQRT_3;
91 //!> threshold for L1 error below which matching is immediately acceptable
92 static const double L1THRESHOLD;
93 //!> threshold for L2 error below which matching is acceptable
94 static const double L2THRESHOLD;
95
96 //!> typedef for a full rotation specification consisting of axis and angle.
97 typedef std::pair<Vector, double> Rotation_t;
98
99 //!> typedef for a list of indices (of points in a polygon)
100 typedef std::list<unsigned int> IndexList_t;
101 //!> typedef enumerating possibly multiple points accumulated as one point
102 typedef std::list< IndexList_t > IndexTupleList_t;
103 //!> typedef for a vector of indices
104 typedef std::vector<unsigned int> IndexArray_t;
105 //!> typedef for a Vector of positions
106 typedef std::vector<Vector> VectorArray_t;
107 //!> typedef for a Vector of positions with weights
108 typedef std::vector< std::pair<Vector, int> > WeightedVectorArray_t;
109 //!> typedef for a vector of degrees (or integral weights)
110 typedef std::vector<unsigned int> WeightsArray_t;
111
112 //!> amplitude up to which deviations in checks of rotations are tolerated
113 static const double warn_amplitude;
114
115private:
116 //!> grant unit tests access to private parts
117 friend class SphericalPointDistributionTest;
118
119 static std::pair<double, double> calculateErrorOfMatching(
120 const VectorArray_t &_old,
121 const VectorArray_t &_new,
122 const IndexTupleList_t &_Matching);
123
124 static Polygon_t removeMatchingPoints(
125 const VectorArray_t &_points,
126 const IndexList_t &_matchingindices
127 );
128
129 struct MatchingControlStructure {
130 bool foundflag;
131 double bestL2;
132 IndexTupleList_t bestmatching;
133 VectorArray_t oldpoints;
134 VectorArray_t newpoints;
135 WeightsArray_t weights;
136 };
137
138 static void recurseMatchings(
139 MatchingControlStructure &_MCS,
140 IndexTupleList_t &_matching,
141 IndexList_t _indices,
142 WeightsArray_t &_remainingweights,
143 WeightsArray_t::iterator _remainiter,
144 const unsigned int _matchingsize
145 );
146
147 static IndexList_t findBestMatching(
148 const WeightedPolygon_t &_polygon,
149 Polygon_t &_newpolygon
150 );
151
152 static IndexList_t joinPoints(
153 Polygon_t &_newpolygon,
154 const VectorArray_t &_newpoints,
155 const IndexTupleList_t &_bestmatching
156 );
157
158 static Rotation_t findPlaneAligningRotation(
159 const VectorArray_t &_referencepositions,
160 const VectorArray_t &_currentpositions,
161 const IndexList_t &_bestmatching
162 );
163
164 static Rotation_t findPointAligningRotation(
165 const VectorArray_t &remainingold,
166 const VectorArray_t &remainingnew,
167 const IndexList_t &_bestmatching);
168
169};
170
171// declare specializations
172
173template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>();
174template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>();
175template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>();
176template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>();
177template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>();
178template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>();
179template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>();
180template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>();
181template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>();
182template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>();
183template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>();
184template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>();
185template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>();
186template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>();
187
188#endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
Note: See TracBrowser for help on using the repository browser.