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

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

Revert "Removing SphericalPointDistribution::getSimplePolygon() to allow for easy rebasing of very old branch on top."

This reverts commit c8fd68b29755db45c6c61c8b73eba4c88480c5bf.

Conflicts:

src/Fragmentation/Exporters/SphericalPointDistribution.cpp
src/Fragmentation/Exporters/SphericalPointDistribution.hpp

  • needed to reattach SphericalPointDistribution::getSimplifiedPolygon() that was removed in order to ease rebasing a very old branch on top.
  • SaturateAction changed to use WeightedPolygon_t and getRemainingPoints().
  • Property mode set to 100644
File size: 8.8 KB
RevLine 
[e895f7]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>
[4492f1]21#include <map>
22#include <set>
23#include <vector>
[e895f7]24
25#include "LinearAlgebra/Vector.hpp"
26
[7e9402]27class SphericalPointDistributionTest;
28
[e895f7]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.) :
[81557e]46 Bondlength(_Bondlength)
[e895f7]47 {}
48
49 //!> typedef for the list of points
50 typedef std::list<Vector> Polygon_t;
[80c119]51 //!> typedef for the list of points with integral weights
52 typedef std::list<std::pair<Vector, int> > WeightedPolygon_t;
[4492f1]53 //!> typedef for a sorted list of indices
54 typedef std::set<unsigned int> IndexSet_t;
55 //!> typedef for the adjacency list of a polygon
56 typedef std::map<unsigned int, IndexSet_t > adjacency_t;
[e895f7]57
58 /** General getter function for the distribution of points on the surface.
59 *
60 * \warn this function needs to be specialized!
61 *
62 * \return Polygon_t with points on the surface centered at (0,0,0)
63 */
[81557e]64 template <int N> Polygon_t get() const
[e895f7]65 {
66 ASSERT(0, "SphericalPointDistribution::get() - not specialized for "+toString(N)+".");
67 }
68
[4492f1]69 template <int N> adjacency_t getConnections()
70 {
71 ASSERT(0, "SphericalPointDistribution::getConnections() - not specialized for "+toString(N)+".");
72 }
73
[ec9bd2]74 /** Initializes the polygon with the given \a _NumberOfPoints.
75 *
76 * \param _NumberOfPoints number of points
77 */
78 Polygon_t getSimplePolygon(const int _NumberOfPoints) const;
79
[9cf90e]80 /** Returns vacant spots to fill to get a complete spherical point distribution from
81 * given points \a _polygon, containing then \a _N in total.
[d468b5]82 *
83 * This is a helper to determine points where to best insert saturation
84 * hydrogens.
[e895f7]85 *
[9cf90e]86 * \param _polygon already filled places to match
87 * \param _N desired total number fo points
[e895f7]88 */
[9cf90e]89 Polygon_t getRemainingPoints(const WeightedPolygon_t &_polygon, const int _N);
[d468b5]90
[e895f7]91 //!> default radius of the spherical distribution
92 const double Bondlength;
93 //!> precalculated value for root of 3
[81557e]94 static const double SQRT_3;
[4d611d]95 //!> threshold for L1 error below which matching is immediately acceptable
96 static const double L1THRESHOLD;
97 //!> threshold for L2 error below which matching is acceptable
98 static const double L2THRESHOLD;
[6cf5bb]99
[7e9402]100 //!> typedef for a full rotation specification consisting of axis and angle.
[6cf5bb]101 typedef std::pair<Vector, double> Rotation_t;
102
[7e9402]103 //!> typedef for a list of indices (of points in a polygon)
[6cf5bb]104 typedef std::list<unsigned int> IndexList_t;
[7e9402]105 //!> typedef enumerating possibly multiple points accumulated as one point
106 typedef std::list< IndexList_t > IndexTupleList_t;
107 //!> typedef for a vector of indices
[6cf5bb]108 typedef std::vector<unsigned int> IndexArray_t;
[7e9402]109 //!> typedef for a Vector of positions
[6cf5bb]110 typedef std::vector<Vector> VectorArray_t;
[7e9402]111 //!> typedef for a Vector of positions with weights
112 typedef std::vector< std::pair<Vector, int> > WeightedVectorArray_t;
[4d611d]113 //!> typedef for a vector of degrees (or integral weights)
114 typedef std::vector<unsigned int> WeightsArray_t;
[6cf5bb]115
116 //!> amplitude up to which deviations in checks of rotations are tolerated
117 static const double warn_amplitude;
118
[4b96da]119 struct PolygonWithIndices
120 {
121 //!> array with points
122 VectorArray_t polygon;
123 //!> list with indices for the above points, defining subset
124 IndexList_t indices;
125 };
126
[66700f2]127 static Vector calculateCenterOfMinimumDistance(
128 const SphericalPointDistribution::VectorArray_t &_positions,
129 const SphericalPointDistribution::IndexList_t &_indices);
130
[9cf90e]131private:
132 //!> points for the ideal distribution
133 Polygon_t points;
134 //!> connection information between these ideal points
135 adjacency_t adjacency;
136
137 /** Initialize inner status (points and adjacency) to desired number of
138 * points.
139 *
140 * \param _N number of points
141 */
142 void initSelf(const int _N);
143
[6cf5bb]144private:
[7e9402]145 //!> grant unit tests access to private parts
146 friend class SphericalPointDistributionTest;
147
[6cf5bb]148 static std::pair<double, double> calculateErrorOfMatching(
[4d611d]149 const VectorArray_t &_old,
150 const VectorArray_t &_new,
151 const IndexTupleList_t &_Matching);
[6cf5bb]152
153 static Polygon_t removeMatchingPoints(
[4b96da]154 const PolygonWithIndices &_points);
[6cf5bb]155
156 struct MatchingControlStructure {
[9cf90e]157 MatchingControlStructure(
158 const adjacency_t &_adjacency,
159 const VectorArray_t &_oldpoints,
160 const VectorArray_t &_newpoints,
161 const WeightsArray_t &_weights
162 );
[6cf5bb]163 bool foundflag;
164 double bestL2;
[9cf90e]165 const adjacency_t &adjacency;
166 const VectorArray_t oldpoints;
167 const VectorArray_t newpoints;
168 const WeightsArray_t weights;
[4d611d]169 IndexTupleList_t bestmatching;
[6cf5bb]170 };
171
172 static void recurseMatchings(
173 MatchingControlStructure &_MCS,
[4d611d]174 IndexTupleList_t &_matching,
[6cf5bb]175 IndexList_t _indices,
[4d611d]176 WeightsArray_t &_remainingweights,
177 WeightsArray_t::iterator _remainiter,
178 const unsigned int _matchingsize
179 );
[6cf5bb]180
[9cf90e]181 IndexList_t findBestMatching(const WeightedPolygon_t &_polygon);
[7e9402]182
183 static IndexList_t joinPoints(
184 Polygon_t &_newpolygon,
185 const VectorArray_t &_newpoints,
186 const IndexTupleList_t &_bestmatching
[6cf5bb]187 );
188
189 static Rotation_t findPlaneAligningRotation(
[4b96da]190 const PolygonWithIndices &_referencepositions,
191 const PolygonWithIndices &_currentpositions
[6cf5bb]192 );
193
194 static Rotation_t findPointAligningRotation(
[4b96da]195 const PolygonWithIndices &remainingold,
196 const PolygonWithIndices &remainingnew);
[e895f7]197};
198
[f54930]199// declare specializations
200
[81557e]201template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>() const;
202template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>() const;
203template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>() const;
204template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>() const;
205template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>() const;
206template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>() const;
207template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>() const;
208template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>() const;
209template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>() const;
210template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>() const;
211template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>() const;
212template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>() const;
213template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>() const;
214template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>() const;
[e895f7]215
[4492f1]216template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<0>();
217template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<1>();
218template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<2>();
219template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<3>();
220template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<4>();
221template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<5>();
222template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<6>();
223template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<7>();
224template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<8>();
225template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<9>();
226template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<10>();
227template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<11>();
228template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<12>();
229template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<14>();
230
[e895f7]231#endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
Note: See TracBrowser for help on using the repository browser.