/* * 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)+"."); } template adjacency_t getConnections() { ASSERT(0, "SphericalPointDistribution::getConnections() - not specialized for "+toString(N)+"."); } /** Matches a given spherical distribution with another containing more * points. * * This is a helper to determine points where to best insert saturation * hydrogens. * * \param _polygon current occupied positions * \param _newpolygon ideal distribution to match best with current occupied * positions * \return remaining vacant positions relative to \a _polygon */ static Polygon_t matchSphericalPointDistributions( const WeightedPolygon_t &_polygon, Polygon_t &_newpolygon ); //!> 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: //!> 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 { bool foundflag; double bestL2; IndexTupleList_t bestmatching; VectorArray_t oldpoints; VectorArray_t newpoints; WeightsArray_t weights; }; static void recurseMatchings( MatchingControlStructure &_MCS, IndexTupleList_t &_matching, IndexList_t _indices, WeightsArray_t &_remainingweights, WeightsArray_t::iterator _remainiter, const unsigned int _matchingsize ); static IndexList_t findBestMatching( const WeightedPolygon_t &_polygon, Polygon_t &_newpolygon ); 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_ */