source: src/Fragmentation/Exporters/SphericalPointDistribution.hpp@ f5fa48

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

Added getAssociatedPoints().

  • the general problem with getRemainingPoints() for saturating fragments with dangling bonds is that we violate the "Saturation Consistency Principle": Common saturation hydrogens for a specific fragments must remain at the exact same position for all containing fragments.
  • only there do we ascertain that the eigenvalue is (due to the invariance of hydrogen to changes in its chemical neighborhood, valid to a good degree) actually removed by higher order fragments.
  • this function is the first step to calculate a "global" set of saturation positions per atom.
  • added also getIdentityAssociation() in case the association is trivial (i.e. in case of only bonds of degree 1).
  • Property mode set to 100644
File size: 11.0 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#include <map>
22#include <set>
23#include <vector>
24
25#include "LinearAlgebra/Vector.hpp"
26
27class SphericalPointDistributionTest;
28
29/** contains getters for the VSEPR model for specific number of electrons.
30 *
31 * This struct contains specialized functions returning a list of Vectors
32 * (points in space) to match the VSEPR model for the given number of electrons.
33 *
34 * This is implemented via template specialization of the function get().
35 *
36 * These specializations are taken from the python script \b CreateVspeShapes.py
37 * by Christian Neuen, 07th May 2009.
38 */
39struct SphericalPointDistribution
40{
41 /** Cstor for SphericalPointDistribution, allows setting radius of sphere
42 *
43 * \param _BondLength desired radius of sphere
44 */
45 SphericalPointDistribution(const double _Bondlength = 1.) :
46 Bondlength(_Bondlength),
47 SQRT_3(sqrt(3.0))
48 {}
49
50 //!> typedef for the list of points
51 typedef std::list<Vector> Polygon_t;
52 //!> typedef for the list of points with integral weights
53 typedef std::list<std::pair<Vector, int> > WeightedPolygon_t;
54 //!> typedef for a sorted list of indices
55 typedef std::set<unsigned int> IndexSet_t;
56 //!> typedef for the adjacency list of a polygon
57 typedef std::map<unsigned int, IndexSet_t > adjacency_t;
58
59 /** General getter function for the distribution of points on the surface.
60 *
61 * \warn this function needs to be specialized!
62 *
63 * \return Polygon_t with points on the surface centered at (0,0,0)
64 */
65 template <int N> Polygon_t get()
66 {
67 ASSERT(0, "SphericalPointDistribution::get() - not specialized for "+toString(N)+".");
68 }
69
70 template <int N> adjacency_t getConnections()
71 {
72 ASSERT(0, "SphericalPointDistribution::getConnections() - not specialized for "+toString(N)+".");
73 }
74
75 /** Returns vacant spots to fill to get a complete spherical point distribution from
76 * given points \a _polygon, containing then \a _N in total.
77 *
78 * The idea is to produce a matching from all points in \a _polygon to those
79 * in \a _newpolygon in such a way that their distance difference is minimal.
80 * As we just look at numbers of points determined by valency, i.e.
81 * independent of the number of atoms, we simply go through each of the possible
82 * mappings. We stop when the L1 error is below a certain \a threshold,
83 * otherwise we pick the matching with the lowest L2 error.
84 *
85 * This is a helper to determine points where to best insert saturation
86 * hydrogens.
87 *
88 * \param _polygon already filled places to match
89 * \param _N desired total number fo points
90 */
91 Polygon_t getRemainingPoints(const WeightedPolygon_t &_polygon, const int _N);
92
93 //!> default radius of the spherical distribution
94 const double Bondlength;
95 //!> precalculated value for root of 3
96 const double SQRT_3;
97 //!> threshold for L1 error below which matching is immediately acceptable
98 static const double L1THRESHOLD;
99 //!> threshold for L2 error below which matching is acceptable
100 static const double L2THRESHOLD;
101
102 //!> typedef for a full rotation specification consisting of axis and angle.
103 typedef std::pair<Vector, double> Rotation_t;
104
105 //!> typedef for a list of indices (of points in a polygon)
106 typedef std::list<unsigned int> IndexList_t;
107 //!> typedef enumerating possibly multiple points accumulated as one point
108 typedef std::list< IndexList_t > IndexTupleList_t;
109 //!> typedef for a vector of indices
110 typedef std::vector<unsigned int> IndexArray_t;
111 //!> typedef for a Vector of positions
112 typedef std::vector<Vector> VectorArray_t;
113 //!> typedef for a Vector of positions with weights
114 typedef std::vector< std::pair<Vector, int> > WeightedVectorArray_t;
115 //!> typedef for a vector of degrees (or integral weights)
116 typedef std::vector<unsigned int> WeightsArray_t;
117
118 //!> amplitude up to which deviations in checks of rotations are tolerated
119 static const double warn_amplitude;
120
121 struct PolygonWithIndices
122 {
123 //!> array with points
124 VectorArray_t polygon;
125 //!> list with indices for the above points, defining subset
126 IndexList_t indices;
127 };
128
129 struct PolygonWithIndexTuples
130 {
131 //!> array with points
132 VectorArray_t polygon;
133 //!> list with tuples of indices for the above points, defining subset
134 IndexTupleList_t indices;
135 };
136
137 /** Returns associated \a _N points equally distributed on a sphere's surface
138 * with respect to the given set of points \a _polygon.
139 *
140 * This function is similar to getRemainingPoints() in that both calculate
141 * a matching between the given points \a _polygon and the \a _N equally
142 * distributed points. The difference is that getRemainingPoints() returns
143 * the unmatched points. This function however is supposed to match (almost)
144 * all and return for each of the points a respective set of points where to
145 * place saturation hydrogens.
146 *
147 * This set of points is then used as a "global" reference set over all
148 * fragments (\sa FragmentationFragmentationAction::performCall()) such that
149 * the common saturation hydrogens for the same atom over all containing
150 * fragments remain at exactly the same position, the saturation consistency
151 * principle. Only by that do we maintain same eigenvalues and hence minimal
152 * disturbance (due to approximate invariance of hydrogen to its chemical
153 * neighborhood) when using the fragmention method with closed-shell
154 * calculations requiring this saturation of dangling bonds.
155 *
156 * \param _polygon already filled places to match
157 * \param _N desired total number fo points
158 * \return a set of positions and a list of tuples of indices such that each
159 * point in \a _polygon is related to one of the tuples and designates
160 * those positions where a number of hydrogens should be placed when
161 * the bond associated with this point is removed, i.e. the bond
162 * becomes a dangling one.
163 */
164 PolygonWithIndexTuples getAssociatedPoints(
165 const WeightedPolygon_t &_polygon,
166 const int _N);
167
168 static PolygonWithIndexTuples getIdentityAssociation(
169 const WeightedPolygon_t &_polygon);
170
171 static Vector calculateCenterOfMinimumDistance(
172 const SphericalPointDistribution::VectorArray_t &_positions,
173 const SphericalPointDistribution::IndexList_t &_indices);
174
175private:
176 //!> points for the ideal distribution
177 Polygon_t points;
178 //!> connection information between these ideal points
179 adjacency_t adjacency;
180
181 /** Initialize inner status (points and adjacency) to desired number of
182 * points.
183 *
184 * \param _N number of points
185 */
186 void initSelf(const int _N);
187
188private:
189 //!> grant unit tests access to private parts
190 friend class SphericalPointDistributionTest;
191
192 static std::pair<double, double> calculateErrorOfMatching(
193 const VectorArray_t &_old,
194 const VectorArray_t &_new,
195 const IndexTupleList_t &_Matching);
196
197 static Polygon_t removeMatchingPoints(
198 const PolygonWithIndices &_points);
199
200 struct MatchingControlStructure {
201 MatchingControlStructure(
202 const adjacency_t &_adjacency,
203 const VectorArray_t &_oldpoints,
204 const VectorArray_t &_newpoints,
205 const WeightsArray_t &_weights
206 );
207 bool foundflag;
208 double bestL2;
209 const adjacency_t &adjacency;
210 const VectorArray_t oldpoints;
211 const VectorArray_t newpoints;
212 const WeightsArray_t weights;
213 IndexTupleList_t bestmatching;
214 };
215
216 static void recurseMatchings(
217 MatchingControlStructure &_MCS,
218 IndexTupleList_t &_matching,
219 IndexList_t _indices,
220 WeightsArray_t &_remainingweights,
221 WeightsArray_t::iterator _remainiter,
222 const unsigned int _matchingsize
223 );
224
225 MatchingControlStructure findBestMatching(const WeightedPolygon_t &_polygon);
226
227 static IndexList_t joinPoints(
228 Polygon_t &_newpolygon,
229 const VectorArray_t &_newpoints,
230 const IndexTupleList_t &_bestmatching
231 );
232
233 static Rotation_t findPlaneAligningRotation(
234 const PolygonWithIndices &_referencepositions,
235 const PolygonWithIndices &_currentpositions
236 );
237
238 static Rotation_t findPointAligningRotation(
239 const PolygonWithIndices &remainingold,
240 const PolygonWithIndices &remainingnew);
241};
242
243// declare specializations
244
245template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>();
246template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>();
247template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>();
248template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>();
249template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>();
250template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>();
251template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>();
252template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>();
253template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>();
254template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>();
255template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>();
256template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>();
257template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>();
258template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>();
259
260template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<0>();
261template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<1>();
262template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<2>();
263template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<3>();
264template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<4>();
265template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<5>();
266template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<6>();
267template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<7>();
268template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<8>();
269template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<9>();
270template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<10>();
271template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<11>();
272template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<12>();
273template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<14>();
274
275#endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
Note: See TracBrowser for help on using the repository browser.