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

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

Extended SphericalPointDistribution::Polygon_t to WeightedPolygon_t.

  • contains additionally the weights from the already present points.
  • in order to deal sensibly with present bonds of higher degree (>1) that shift neighboring occupied orbitals even further away, we additionally pass on the bond degree. This indicates how many points of the N points have to be accumulated for this on present bond.
  • TESTS: Regression test FragmentMolecule-cylces failing for the moment.
  • Property mode set to 100644
File size: 5.4 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
24/** contains getters for the VSEPR model for specific number of electrons.
25 *
26 * This struct contains specialized functions returning a list of Vectors
27 * (points in space) to match the VSEPR model for the given number of electrons.
28 *
29 * This is implemented via template specialization of the function get().
30 *
31 * These specializations are taken from the python script \b CreateVspeShapes.py
32 * by Christian Neuen, 07th May 2009.
33 */
34struct SphericalPointDistribution
35{
36 /** Cstor for SphericalPointDistribution, allows setting radius of sphere
37 *
38 * \param _BondLength desired radius of sphere
39 */
40 SphericalPointDistribution(const double _Bondlength = 1.) :
41 Bondlength(_Bondlength),
42 SQRT_3(sqrt(3.0))
43 {}
44
45 //!> typedef for the list of points
46 typedef std::list<Vector> Polygon_t;
47 //!> typedef for the list of points with integral weights
48 typedef std::list<std::pair<Vector, int> > WeightedPolygon_t;
49
50 /** General getter function for the distribution of points on the surface.
51 *
52 * \warn this function needs to be specialized!
53 *
54 * \return Polygon_t with points on the surface centered at (0,0,0)
55 */
56 template <int N> Polygon_t get()
57 {
58 ASSERT(0, "SphericalPointDistribution::get() - not specialized for "+toString(N)+".");
59 }
60
61
62 /** Matches a given spherical distribution with another containing more
63 * points.
64 *
65 * The idea is to produce a matching from all points in \a _polygon to those
66 * in \a _newpolygon in such a way that their distance difference is minimal.
67 * As we just look at numbers of points determined by valency, i.e.
68 * independent of the number of atoms, we simply go through each of the possible
69 * mappings. We stop when the L1 error is below a certain \a threshold,
70 * otherwise we pick the matching with the lowest L2 error.
71 *
72 * This is a helper to determine points where to best insert saturation
73 * hydrogens.
74 *
75 * \param _polygon current occupied positions
76 * \param _newpolygon ideal distribution to match best with current occupied
77 * positions
78 * \return remaining vacant positions relative to \a _polygon
79 */
80 static Polygon_t matchSphericalPointDistributions(
81 const WeightedPolygon_t &_polygon,
82 const Polygon_t &_newpolygon
83 );
84
85 //!> default radius of the spherical distribution
86 const double Bondlength;
87 //!> precalculated value for root of 3
88 const double SQRT_3;
89
90 typedef std::pair<Vector, double> Rotation_t;
91
92 typedef std::list<unsigned int> IndexList_t;
93 typedef std::vector<unsigned int> IndexArray_t;
94 typedef std::vector<Vector> VectorArray_t;
95
96 //!> amplitude up to which deviations in checks of rotations are tolerated
97 static const double warn_amplitude;
98
99private:
100 static std::pair<double, double> calculateErrorOfMatching(
101 const std::vector<Vector> &_old,
102 const std::vector<Vector> &_new,
103 const IndexList_t &_Matching);
104
105 static Polygon_t removeMatchingPoints(
106 const VectorArray_t &_points,
107 const IndexList_t &_matchingindices
108 );
109
110 struct MatchingControlStructure {
111 bool foundflag;
112 double bestL2;
113 IndexList_t bestmatching;
114 VectorArray_t oldpoints;
115 VectorArray_t newpoints;
116 };
117
118 static void recurseMatchings(
119 MatchingControlStructure &_MCS,
120 IndexList_t &_matching,
121 IndexList_t _indices,
122 unsigned int _matchingsize);
123
124 static IndexList_t findBestMatching(
125 const WeightedPolygon_t &_polygon,
126 const Polygon_t &_newpolygon
127 );
128
129 static Rotation_t findPlaneAligningRotation(
130 const VectorArray_t &_referencepositions,
131 const VectorArray_t &_currentpositions,
132 const IndexList_t &_bestmatching
133 );
134
135 static Rotation_t findPointAligningRotation(
136 const VectorArray_t &remainingold,
137 const VectorArray_t &remainingnew,
138 const IndexList_t &_bestmatching);
139
140};
141
142// declare specializations
143
144template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>();
145template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>();
146template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>();
147template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>();
148template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>();
149template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>();
150template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>();
151template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>();
152template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>();
153template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>();
154template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>();
155template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>();
156template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>();
157template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>();
158
159#endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
Note: See TracBrowser for help on using the repository browser.