Index: src/Fragmentation/Exporters/SaturationDistanceMaximizer.hpp
===================================================================
--- src/Fragmentation/Exporters/SaturationDistanceMaximizer.hpp	(revision a1d1dd8b043f6987e14d6d37973e71bd8ccad587)
+++ src/Fragmentation/Exporters/SaturationDistanceMaximizer.hpp	(revision a1d1dd8b043f6987e14d6d37973e71bd8ccad587)
@@ -0,0 +1,147 @@
+/*
+ * SaturationDistanceMaximizer.hpp
+ *
+ *  Created on: Jul 27, 2014
+ *      Author: heber
+ */
+
+#ifndef SATURATIONDISTANCEMAXIMIZER_HPP_
+#define SATURATIONDISTANCEMAXIMIZER_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <vector>
+
+#include <gsl/gsl_vector.h>
+
+#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<SaturatedBond::ptr> 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<j} \frac{1}{ \rVert x_i - x_j \lVert^2} \f$.
+   */
+  void operator()();
+
+  /** Requests positions from each SaturatedBond and places it into vector.
+   *
+   * \return vector of tuples of positions
+   */
+  position_bins_t getAllPositionBins() const;
+
+private:
+  //!> 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<j} \frac{1}{ \rVert x_i - x_j \lVert^2} \f$
+   */
+  double calculatePenality() const;
+
+  /** Evaluates the gradient with respect to the angles (i.e. per bin only!)
+   *
+   * \return tuple with amount of change per bin
+   */
+  std::vector<double> calculatePenalityGradient() const;
+
+  /** Getter for the alphas of each SaturatedBond.
+   *
+   * \return vector with all alphas
+   */
+  std::vector<double> 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<double> 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_ */
