/* * SaturationDistanceMaximizer.hpp * * Created on: Jul 27, 2014 * Author: heber */ #ifndef SATURATIONDISTANCEMAXIMIZER_HPP_ #define SATURATIONDISTANCEMAXIMIZER_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "SaturatedBond.hpp" class SaturationDistanceMaximizerTest; /** This class encapsulates the minimizing/maximization performed to find the * best angles alpha for a vector of SaturatedBonds. */ class SaturationDistanceMaximizer { public: struct Advocate; //!> typedef for a vector of SaturatedBonds typedef std::vector PositionContainers_t; //!> typedef for the positions per saturated bond typedef std::vector< SaturatedBond::positions_t > position_bins_t; SaturationDistanceMaximizer(PositionContainers_t &_PositionContainers) : PositionContainers(_PositionContainers) {} ~SaturationDistanceMaximizer() {} /** Maximizes the distances between the saturation hydrogens for a number of * SaturedBonds. * * We maximize the function \f$ \sum_{i make advocate friend friend struct Advocate; //!> make unit tests friend friend class SaturationDistanceMaximizerTest; /** Evaluates the penalty function over the current positions. * * \return \f$ \sum_{i calculatePenalityGradient() const; /** Getter for the alphas of each SaturatedBond. * * \return vector with all alphas */ std::vector getAlphas() const; /** Helper function to set the angles alpha of each SaturatedBond from the * components of a gsl_vector \a *x. * * \param x components containing alpha per bond */ void setAlphas(const gsl_vector *x); /** Getter for the advocate to be handed over to other functions or classes. * * \return ptr to advocate */ Advocate* getAdvocate(); public: /** This class is friend and may call penalty functions. * * This class is private and only SaturationDistanceMaximizer is its friend. * Hence, it has total control of who may call its function by instantiating * this advocate object abd handing it to someone else (e.g. a function). * */ class Advocate { private: friend class SaturationDistanceMaximizer; Advocate( SaturationDistanceMaximizer &_maximizer) : maximizer(_maximizer) {} public: double calculatePenality() const { return maximizer.calculatePenality(); } /** Evaluates the gradient with respect to the angles (i.e. per bin only!) * * \return tuple with amount of change per bin */ std::vector calculatePenalityGradient() const { return maximizer.calculatePenalityGradient(); } /** Helper function to set the angles alpha of each SaturatedBond from the * components of a gsl_vector \a *x. * * \param x components containing alpha per bond */ void setAlphas(const gsl_vector *x) { maximizer.setAlphas(x); } private: //!> internal instance for functionc alls SaturationDistanceMaximizer &maximizer; }; private: //!> Vectors with all SaturatedBonds belonging to the central atom to saturate PositionContainers_t &PositionContainers; }; #endif /* SATURATIONDISTANCEMAXIMIZER_HPP_ */