| 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 | class 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 | */
|
|---|
| 36 | struct 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 | {}
|
|---|
| 45 |
|
|---|
| 46 | //!> typedef for the list of points
|
|---|
| 47 | typedef std::list<Vector> Polygon_t;
|
|---|
| 48 | //!> typedef for the list of points with integral weights
|
|---|
| 49 | typedef std::list<std::pair<Vector, int> > WeightedPolygon_t;
|
|---|
| 50 |
|
|---|
| 51 | /** General getter function for the distribution of points on the surface.
|
|---|
| 52 | *
|
|---|
| 53 | * \warn this function needs to be specialized!
|
|---|
| 54 | *
|
|---|
| 55 | * \return Polygon_t with points on the surface centered at (0,0,0)
|
|---|
| 56 | */
|
|---|
| 57 | template <int N> Polygon_t get() const
|
|---|
| 58 | {
|
|---|
| 59 | ASSERT(0, "SphericalPointDistribution::get() - not specialized for "+toString(N)+".");
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /** Matches a given spherical distribution with another containing more
|
|---|
| 63 | * points.
|
|---|
| 64 | *
|
|---|
| 65 | * This is a helper to determine points where to best insert saturation
|
|---|
| 66 | * hydrogens.
|
|---|
| 67 | *
|
|---|
| 68 | * \param _polygon current occupied positions
|
|---|
| 69 | * \param _newpolygon ideal distribution to match best with current occupied
|
|---|
| 70 | * positions
|
|---|
| 71 | * \return remaining vacant positions relative to \a _polygon
|
|---|
| 72 | */
|
|---|
| 73 | static Polygon_t matchSphericalPointDistributions(
|
|---|
| 74 | const WeightedPolygon_t &_polygon,
|
|---|
| 75 | Polygon_t &_newpolygon
|
|---|
| 76 | );
|
|---|
| 77 |
|
|---|
| 78 | //!> default radius of the spherical distribution
|
|---|
| 79 | const double Bondlength;
|
|---|
| 80 | //!> precalculated value for root of 3
|
|---|
| 81 | static const double SQRT_3;
|
|---|
| 82 | //!> threshold for L1 error below which matching is immediately acceptable
|
|---|
| 83 | static const double L1THRESHOLD;
|
|---|
| 84 | //!> threshold for L2 error below which matching is acceptable
|
|---|
| 85 | static const double L2THRESHOLD;
|
|---|
| 86 |
|
|---|
| 87 | //!> typedef for a full rotation specification consisting of axis and angle.
|
|---|
| 88 | typedef std::pair<Vector, double> Rotation_t;
|
|---|
| 89 |
|
|---|
| 90 | //!> typedef for a list of indices (of points in a polygon)
|
|---|
| 91 | typedef std::list<unsigned int> IndexList_t;
|
|---|
| 92 | //!> typedef enumerating possibly multiple points accumulated as one point
|
|---|
| 93 | typedef std::list< IndexList_t > IndexTupleList_t;
|
|---|
| 94 | //!> typedef for a vector of indices
|
|---|
| 95 | typedef std::vector<unsigned int> IndexArray_t;
|
|---|
| 96 | //!> typedef for a Vector of positions
|
|---|
| 97 | typedef std::vector<Vector> VectorArray_t;
|
|---|
| 98 | //!> typedef for a Vector of positions with weights
|
|---|
| 99 | typedef std::vector< std::pair<Vector, int> > WeightedVectorArray_t;
|
|---|
| 100 | //!> typedef for a vector of degrees (or integral weights)
|
|---|
| 101 | typedef std::vector<unsigned int> WeightsArray_t;
|
|---|
| 102 |
|
|---|
| 103 | //!> amplitude up to which deviations in checks of rotations are tolerated
|
|---|
| 104 | static const double warn_amplitude;
|
|---|
| 105 |
|
|---|
| 106 | struct PolygonWithIndices
|
|---|
| 107 | {
|
|---|
| 108 | //!> array with points
|
|---|
| 109 | VectorArray_t polygon;
|
|---|
| 110 | //!> list with indices for the above points, defining subset
|
|---|
| 111 | IndexList_t indices;
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | private:
|
|---|
| 115 | //!> grant unit tests access to private parts
|
|---|
| 116 | friend class SphericalPointDistributionTest;
|
|---|
| 117 |
|
|---|
| 118 | static std::pair<double, double> calculateErrorOfMatching(
|
|---|
| 119 | const VectorArray_t &_old,
|
|---|
| 120 | const VectorArray_t &_new,
|
|---|
| 121 | const IndexTupleList_t &_Matching);
|
|---|
| 122 |
|
|---|
| 123 | static Polygon_t removeMatchingPoints(
|
|---|
| 124 | const PolygonWithIndices &_points);
|
|---|
| 125 |
|
|---|
| 126 | struct MatchingControlStructure {
|
|---|
| 127 | bool foundflag;
|
|---|
| 128 | double bestL2;
|
|---|
| 129 | IndexTupleList_t bestmatching;
|
|---|
| 130 | VectorArray_t oldpoints;
|
|---|
| 131 | VectorArray_t newpoints;
|
|---|
| 132 | WeightsArray_t weights;
|
|---|
| 133 | };
|
|---|
| 134 |
|
|---|
| 135 | static void recurseMatchings(
|
|---|
| 136 | MatchingControlStructure &_MCS,
|
|---|
| 137 | IndexTupleList_t &_matching,
|
|---|
| 138 | IndexList_t _indices,
|
|---|
| 139 | WeightsArray_t &_remainingweights,
|
|---|
| 140 | WeightsArray_t::iterator _remainiter,
|
|---|
| 141 | const unsigned int _matchingsize
|
|---|
| 142 | );
|
|---|
| 143 |
|
|---|
| 144 | static IndexList_t findBestMatching(
|
|---|
| 145 | const WeightedPolygon_t &_polygon,
|
|---|
| 146 | Polygon_t &_newpolygon
|
|---|
| 147 | );
|
|---|
| 148 |
|
|---|
| 149 | static IndexList_t joinPoints(
|
|---|
| 150 | Polygon_t &_newpolygon,
|
|---|
| 151 | const VectorArray_t &_newpoints,
|
|---|
| 152 | const IndexTupleList_t &_bestmatching
|
|---|
| 153 | );
|
|---|
| 154 |
|
|---|
| 155 | static Rotation_t findPlaneAligningRotation(
|
|---|
| 156 | const PolygonWithIndices &_referencepositions,
|
|---|
| 157 | const PolygonWithIndices &_currentpositions
|
|---|
| 158 | );
|
|---|
| 159 |
|
|---|
| 160 | static Rotation_t findPointAligningRotation(
|
|---|
| 161 | const PolygonWithIndices &remainingold,
|
|---|
| 162 | const PolygonWithIndices &remainingnew);
|
|---|
| 163 |
|
|---|
| 164 | };
|
|---|
| 165 |
|
|---|
| 166 | // declare specializations
|
|---|
| 167 |
|
|---|
| 168 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>() const;
|
|---|
| 169 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>() const;
|
|---|
| 170 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>() const;
|
|---|
| 171 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>() const;
|
|---|
| 172 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>() const;
|
|---|
| 173 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>() const;
|
|---|
| 174 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>() const;
|
|---|
| 175 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>() const;
|
|---|
| 176 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>() const;
|
|---|
| 177 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>() const;
|
|---|
| 178 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>() const;
|
|---|
| 179 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>() const;
|
|---|
| 180 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>() const;
|
|---|
| 181 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>() const;
|
|---|
| 182 |
|
|---|
| 183 | #endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
|
|---|