/* * SphericalPointDistribution.hpp * * Created on: May 29, 2014 * Author: heber */ #ifndef SPHERICALPOINTDISTRIBUTION_HPP_ #define SPHERICALPOINTDISTRIBUTION_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/Assert.hpp" #include #include #include #include #include #include "LinearAlgebra/Vector.hpp" class SphericalPointDistributionTest; /** contains getters for the VSEPR model for specific number of electrons. * * This struct contains specialized functions returning a list of Vectors * (points in space) to match the VSEPR model for the given number of electrons. * * This is implemented via template specialization of the function get(). * * These specializations are taken from the python script \b CreateVspeShapes.py * by Christian Neuen, 07th May 2009. */ struct SphericalPointDistribution { /** Cstor for SphericalPointDistribution, allows setting radius of sphere * * \param _BondLength desired radius of sphere */ SphericalPointDistribution(const double _Bondlength = 1.) : Bondlength(_Bondlength) {} //!> typedef for the list of points typedef std::list Polygon_t; //!> typedef for the list of points with integral weights typedef std::list > WeightedPolygon_t; //!> typedef for a sorted list of indices typedef std::set IndexSet_t; //!> typedef for the adjacency list of a polygon typedef std::map adjacency_t; /** General getter function for the distribution of points on the surface. * * \warn this function needs to be specialized! * * \return Polygon_t with points on the surface centered at (0,0,0) */ template Polygon_t get() const { ASSERT(0, "SphericalPointDistribution::get() - not specialized for "+toString(N)+"."); return Polygon_t(); } template adjacency_t getConnections() { ASSERT(0, "SphericalPointDistribution::getConnections() - not specialized for "+toString(N)+"."); return Polygon_t(); } /** Initializes the polygon with the given \a _NumberOfPoints. * * \param _NumberOfPoints number of points */ Polygon_t getSimplePolygon(const int _NumberOfPoints) const; /** Returns vacant spots to fill to get a complete spherical point distribution from * given points \a _polygon, containing then \a _N in total. * * This is a helper to determine points where to best insert saturation * hydrogens. * * \param _polygon already filled places to match * \param _N desired total number fo points */ Polygon_t getRemainingPoints(const WeightedPolygon_t &_polygon, const int _N); //!> default radius of the spherical distribution const double Bondlength; //!> precalculated value for root of 3 static const double SQRT_3; //!> threshold for L1 error below which matching is immediately acceptable static const double L1THRESHOLD; //!> threshold for L2 error below which matching is acceptable static const double L2THRESHOLD; //!> typedef for a full rotation specification consisting of axis and angle. typedef std::pair Rotation_t; //!> typedef for a list of indices (of points in a polygon) typedef std::list IndexList_t; //!> typedef enumerating possibly multiple points accumulated as one point typedef std::list< IndexList_t > IndexTupleList_t; //!> typedef for a vector of indices typedef std::vector IndexArray_t; //!> typedef for a Vector of positions typedef std::vector VectorArray_t; //!> typedef for a Vector of positions with weights typedef std::vector< std::pair > WeightedVectorArray_t; //!> typedef for a vector of degrees (or integral weights) typedef std::vector WeightsArray_t; //!> amplitude up to which deviations in checks of rotations are tolerated static const double warn_amplitude; struct PolygonWithIndices { //!> array with points VectorArray_t polygon; //!> list with indices for the above points, defining subset IndexList_t indices; }; static Vector calculateCenterOfMinimumDistance( const SphericalPointDistribution::VectorArray_t &_positions, const SphericalPointDistribution::IndexList_t &_indices); private: //!> points for the ideal distribution Polygon_t points; //!> connection information between these ideal points adjacency_t adjacency; /** Initialize inner status (points and adjacency) to desired number of * points. * * \param _N number of points */ void initSelf(const int _N); private: //!> grant unit tests access to private parts friend class SphericalPointDistributionTest; static std::pair calculateErrorOfMatching( const VectorArray_t &_old, const VectorArray_t &_new, const IndexTupleList_t &_Matching); static Polygon_t removeMatchingPoints( const PolygonWithIndices &_points); struct MatchingControlStructure { MatchingControlStructure( const adjacency_t &_adjacency, const VectorArray_t &_oldpoints, const VectorArray_t &_newpoints, const WeightsArray_t &_weights ); bool foundflag; double bestL2; const adjacency_t &adjacency; const VectorArray_t oldpoints; const VectorArray_t newpoints; const WeightsArray_t weights; IndexTupleList_t bestmatching; }; static void recurseMatchings( MatchingControlStructure &_MCS, IndexTupleList_t &_matching, IndexList_t _indices, WeightsArray_t &_remainingweights, WeightsArray_t::iterator _remainiter, const unsigned int _matchingsize ); IndexList_t findBestMatching(const WeightedPolygon_t &_polygon); static IndexList_t joinPoints( Polygon_t &_newpolygon, const VectorArray_t &_newpoints, const IndexTupleList_t &_bestmatching ); static Rotation_t findPlaneAligningRotation( const PolygonWithIndices &_referencepositions, const PolygonWithIndices &_currentpositions ); static Rotation_t findPointAligningRotation( const PolygonWithIndices &remainingold, const PolygonWithIndices &remainingnew); }; // declare specializations template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<0>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<1>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<2>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<3>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<4>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<5>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<6>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<7>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<8>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<9>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<10>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<11>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<12>() const; template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>() const; template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<0>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<1>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<2>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<3>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<4>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<5>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<6>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<7>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<8>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<9>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<10>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<11>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<12>(); template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<14>(); #endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */