| [97d6ab] | 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 |  */
 | 
|---|
 | 34 | struct 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;
 | 
|---|
| [260540] | 47 |   //!> typedef for the list of points with integral weights
 | 
|---|
 | 48 |   typedef std::list<std::pair<Vector, int> > WeightedPolygon_t;
 | 
|---|
| [97d6ab] | 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 | 
 | 
|---|
| [0d4daf] | 61 | 
 | 
|---|
| [972412] | 62 |   /** Matches a given spherical distribution with another containing more
 | 
|---|
 | 63 |    * points.
 | 
|---|
 | 64 |    *
 | 
|---|
| [6ef48c] | 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 |    *
 | 
|---|
| [972412] | 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(
 | 
|---|
| [260540] | 81 |       const WeightedPolygon_t &_polygon,
 | 
|---|
| [972412] | 82 |       const Polygon_t &_newpolygon
 | 
|---|
 | 83 |       );
 | 
|---|
 | 84 | 
 | 
|---|
| [97d6ab] | 85 |   //!> default radius of the spherical distribution
 | 
|---|
 | 86 |   const double Bondlength;
 | 
|---|
 | 87 |   //!> precalculated value for root of 3
 | 
|---|
 | 88 |   const double SQRT_3;
 | 
|---|
| [3da643] | 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 | 
 | 
|---|
 | 99 | private:
 | 
|---|
 | 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(
 | 
|---|
| [260540] | 125 |       const WeightedPolygon_t &_polygon,
 | 
|---|
| [3da643] | 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 | 
 | 
|---|
| [97d6ab] | 140 | };
 | 
|---|
 | 141 | 
 | 
|---|
| [0d4daf] | 142 | // declare specializations
 | 
|---|
 | 143 | 
 | 
|---|
 | 144 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>();
 | 
|---|
 | 145 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>();
 | 
|---|
 | 146 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>();
 | 
|---|
 | 147 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>();
 | 
|---|
 | 148 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>();
 | 
|---|
 | 149 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>();
 | 
|---|
 | 150 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>();
 | 
|---|
 | 151 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>();
 | 
|---|
 | 152 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>();
 | 
|---|
 | 153 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>();
 | 
|---|
 | 154 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>();
 | 
|---|
 | 155 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>();
 | 
|---|
 | 156 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>();
 | 
|---|
 | 157 | template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>();
 | 
|---|
| [97d6ab] | 158 | 
 | 
|---|
 | 159 | #endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
 | 
|---|