source: src/Fragmentation/Exporters/SphericalPointDistribution.hpp@ 1ae9aa

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

Extracted joinPoints() function to make it accessible to tests.

  • added unit test.
  • moved some function definitions around and added documentation.
  • Property mode set to 100644
File size: 6.1 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
92 //!> typedef for a full rotation specification consisting of axis and angle.
93 typedef std::pair<Vector, double> Rotation_t;
94
95 //!> typedef for a list of indices (of points in a polygon)
96 typedef std::list<unsigned int> IndexList_t;
97 //!> typedef enumerating possibly multiple points accumulated as one point
98 typedef std::list< IndexList_t > IndexTupleList_t;
99 //!> typedef for a vector of indices
100 typedef std::vector<unsigned int> IndexArray_t;
101 //!> typedef for a Vector of positions
102 typedef std::vector<Vector> VectorArray_t;
103 //!> typedef for a Vector of positions with weights
104 typedef std::vector< std::pair<Vector, int> > WeightedVectorArray_t;
105
106 //!> amplitude up to which deviations in checks of rotations are tolerated
107 static const double warn_amplitude;
108
109private:
110 //!> grant unit tests access to private parts
111 friend class SphericalPointDistributionTest;
112
113 static std::pair<double, double> calculateErrorOfMatching(
114 const std::vector<Vector> &_old,
115 const std::vector<Vector> &_new,
116 const IndexList_t &_Matching);
117
118 static Polygon_t removeMatchingPoints(
119 const VectorArray_t &_points,
120 const IndexList_t &_matchingindices
121 );
122
123 struct MatchingControlStructure {
124 bool foundflag;
125 double bestL2;
126 IndexList_t bestmatching;
127 VectorArray_t oldpoints;
128 VectorArray_t newpoints;
129 };
130
131 static void recurseMatchings(
132 MatchingControlStructure &_MCS,
133 IndexList_t &_matching,
134 IndexList_t _indices,
135 unsigned int _matchingsize);
136
137 static IndexList_t findBestMatching(
138 const WeightedPolygon_t &_polygon,
139 Polygon_t &_newpolygon
140 );
141
142 static IndexList_t joinPoints(
143 Polygon_t &_newpolygon,
144 const VectorArray_t &_newpoints,
145 const IndexTupleList_t &_bestmatching
146 );
147
148 static Rotation_t findPlaneAligningRotation(
149 const VectorArray_t &_referencepositions,
150 const VectorArray_t &_currentpositions,
151 const IndexList_t &_bestmatching
152 );
153
154 static Rotation_t findPointAligningRotation(
155 const VectorArray_t &remainingold,
156 const VectorArray_t &remainingnew,
157 const IndexList_t &_bestmatching);
158
159};
160
161// declare specializations
162
163template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>();
164template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>();
165template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>();
166template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>();
167template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>();
168template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>();
169template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>();
170template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>();
171template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>();
172template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>();
173template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>();
174template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>();
175template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>();
176template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>();
177
178#endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
Note: See TracBrowser for help on using the repository browser.