Index: src/FunctionApproximation/Extractors.cpp
===================================================================
--- src/FunctionApproximation/Extractors.cpp	(revision 060e1edada88a5af82c8bf5d9876db51fcac57a7)
+++ src/FunctionApproximation/Extractors.cpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -308,4 +308,8 @@
   /// we first have to count same elements, then get different targets
   /// for each and then associated them in correct order back again.
+
+  // 0. if no elements given, we return empty arguments
+  if (elements.empty())
+    return FunctionModel::arguments_t();
 
   // 1. we have to place each charge into a map as unique chargeiter, i.e. map
@@ -416,4 +420,6 @@
 {
   // get last element from charges
+  ASSERT( !elements.empty(),
+      "Extractors::_detail::pickLastElementAsTarget() - no elements given to pick targets for.");
   const Fragment::charge_t charge = elements.back();
   elements.pop_back();
Index: src/Potentials/Makefile.am
===================================================================
--- src/Potentials/Makefile.am	(revision 060e1edada88a5af82c8bf5d9876db51fcac57a7)
+++ src/Potentials/Makefile.am	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -8,4 +8,5 @@
   Potentials/PotentialRegistry.cpp \
   Potentials/SerializablePotential.cpp \
+  Potentials/Specifics/ConstantPotential.cpp \
   Potentials/Specifics/ManyBodyPotential_Tersoff.cpp \
   Potentials/Specifics/PairPotential_Angle.cpp \
@@ -30,4 +31,5 @@
 # add here headers for real potentials (i.e. the PotentialFactory should instantiate)  
 SPECIFICPOTENTIALSHEADER = \
+  Potentials/Specifics/ConstantPotential.hpp \
   Potentials/Specifics/ManyBodyPotential_Tersoff.hpp \
   Potentials/Specifics/PairPotential_Angle.hpp \
Index: src/Potentials/PotentialFactory.cpp
===================================================================
--- src/Potentials/PotentialFactory.cpp	(revision 060e1edada88a5af82c8bf5d9876db51fcac57a7)
+++ src/Potentials/PotentialFactory.cpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -103,4 +103,6 @@
       "PotentialFactory::createInstance() - cannot find potential of name "+potentialtype);
   switch (NameToType[potentialtype]) {
+  case constant:
+      return new ConstantPotential(types);
   case tersoff:
       return new ManyBodyPotential_Tersoff(types);
Index: src/Potentials/Specifics/ConstantPotential.cpp
===================================================================
--- src/Potentials/Specifics/ConstantPotential.cpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
+++ src/Potentials/Specifics/ConstantPotential.cpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -0,0 +1,177 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+/*
+ * ConstantPotential.cpp
+ *
+ *  Created on: May 09, 2013
+ *      Author: heber
+ */
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "ConstantPotential.hpp"
+
+#include <boost/assign/list_of.hpp> // for 'map_list_of()'
+#include <boost/bind.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <cmath>
+#include <string>
+
+#include "CodePatterns/Assert.hpp"
+
+#include "FunctionApproximation/Extractors.hpp"
+#include "FunctionApproximation/TrainingData.hpp"
+#include "Potentials/helpers.hpp"
+#include "Potentials/ParticleTypeCheckers.hpp"
+
+class Fragment;
+
+// static definitions
+const ConstantPotential::ParameterNames_t
+ConstantPotential::ParameterNames =
+      boost::assign::list_of<std::string>
+      ("energy_offset") //
+    ;
+const std::string ConstantPotential::potential_token("constant");
+
+ConstantPotential::ConstantPotential(
+    const ParticleTypes_t &_ParticleTypes
+    ) :
+  EmpiricalPotential(_ParticleTypes),
+  params(parameters_t(MAXPARAMS, 0.))
+{
+  // have some decent defaults for parameter_derivative checking
+  params[energy_offset] = 0.1;
+}
+
+ConstantPotential::ConstantPotential(
+    const ParticleTypes_t &_ParticleTypes,
+    const double _energy_offset) :
+  EmpiricalPotential(_ParticleTypes),
+  params(parameters_t(MAXPARAMS, 0.))
+{
+  params[energy_offset] = _energy_offset;
+}
+
+void ConstantPotential::setParameters(const parameters_t &_params)
+{
+  const size_t paramsDim = _params.size();
+  ASSERT( paramsDim <= getParameterDimension(),
+      "ConstantPotential::setParameters() - we need not more than "
+      +toString(getParameterDimension())+" parameters.");
+  for(size_t i=0;i<paramsDim;++i)
+    params[i] = _params[i];
+
+#ifndef NDEBUG
+  parameters_t check_params(getParameters());
+  check_params.resize(paramsDim); // truncate to same size
+  ASSERT( check_params == _params,
+      "ConstantPotential::setParameters() - failed, mismatch in to be set "
+      +toString(_params)+" and set "+toString(check_params)+" params.");
+#endif
+}
+
+ConstantPotential::results_t
+ConstantPotential::operator()(
+    const arguments_t &arguments
+    ) const
+{
+  ASSERT( arguments.size() == 0,
+      "ConstantPotential::operator() - requires no argument.");
+  ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
+      arguments, getParticleTypes()),
+      "ConstantPotential::operator() - types don't match with ones in arguments.");
+  const result_t result = params[energy_offset];
+  return std::vector<result_t>(1, result);
+}
+
+ConstantPotential::derivative_components_t
+ConstantPotential::derivative(
+    const arguments_t &arguments
+    ) const
+{
+  ASSERT( arguments.size() == 0,
+      "ConstantPotential::operator() - requires no argument.");
+  ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
+      arguments, getParticleTypes()),
+      "ConstantPotential::operator() - types don't match with ones in arguments.");
+  derivative_components_t result(1, 0.);
+  return result;
+}
+
+ConstantPotential::results_t
+ConstantPotential::parameter_derivative(
+    const arguments_t &arguments,
+    const size_t index
+    ) const
+{
+  ASSERT( arguments.size() == 0,
+      "ConstantPotential::parameter_derivative() - requires no argument.");
+  ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
+      arguments, getParticleTypes()),
+      "ConstantPotential::operator() - types don't match with ones in arguments.");
+  switch (index) {
+    case energy_offset:
+    {
+      // Maple result: 1
+      const result_t result = +1.;
+      return std::vector<result_t>(1, result);
+      break;
+    }
+    default:
+      break;
+  }
+  return std::vector<result_t>(1, 0.);
+}
+
+FunctionModel::extractor_t
+ConstantPotential::getFragmentSpecificExtractor() const
+{
+  Fragment::charges_t charges;
+  charges.resize(getParticleTypes().size());
+  std::transform(getParticleTypes().begin(), getParticleTypes().end(),
+      charges.begin(), boost::lambda::_1);
+  FunctionModel::extractor_t returnfunction =
+      boost::bind(&Extractors::gatherDistancesFromFragment,
+          boost::bind(&Fragment::getPositions, _1),
+          boost::bind(&Fragment::getCharges, _1),
+          charges,
+          _2);
+  return returnfunction;
+}
+
+void
+ConstantPotential::setParametersToRandomInitialValues(
+    const TrainingData &data)
+{
+  params[ConstantPotential::energy_offset] =
+      data.getTrainingOutputAverage()[0];// -1.;
+}
+
Index: src/Potentials/Specifics/ConstantPotential.hpp
===================================================================
--- src/Potentials/Specifics/ConstantPotential.hpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
+++ src/Potentials/Specifics/ConstantPotential.hpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -0,0 +1,168 @@
+/*
+ * ConstantPotential.hpp
+ *
+ *  Created on: May 09, 2013
+ *      Author: heber
+ */
+
+#ifndef CONSTANTPOTENTIAL_HPP_
+#define CONSTANTPOTENTIAL_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <limits>
+
+#include "Potentials/EmpiricalPotential.hpp"
+
+class TrainingData;
+
+/** This is the implementation of a constant potential to adapt to any offset
+ * in the potential energy.
+ *
+ * This evaluates \f$ k \f$.
+ *
+ */
+class ConstantPotential :
+  public EmpiricalPotential
+{
+  //!> grant unit test access to internal parts
+  friend class ConstantPotentialTest;
+  // some repeated typedefs to avoid ambiguities
+  typedef FunctionModel::arguments_t arguments_t;
+  typedef FunctionModel::result_t result_t;
+  typedef FunctionModel::results_t results_t;
+  typedef EmpiricalPotential::derivative_components_t derivative_components_t;
+  typedef FunctionModel::parameters_t parameters_t;
+public:
+  ConstantPotential(const ParticleTypes_t &_ParticleTypes);
+  ConstantPotential(
+      const ParticleTypes_t &_ParticleTypes,
+      const double _energy_offset);
+  virtual ~ConstantPotential() {}
+
+  /** Setter for parameters as required by FunctionModel interface.
+   *
+   * \param _params given set of parameters
+   */
+  void setParameters(const parameters_t &_params);
+
+  /** Getter for parameters as required by FunctionModel interface.
+   *
+   * \return set of parameters
+   */
+  parameters_t getParameters() const
+  {
+    return params;
+  }
+
+  /** Sets the parameter randomly within the sensible range of each parameter.
+   *
+   * \param data container with training data for guesstimating range
+   */
+  void setParametersToRandomInitialValues(const TrainingData &data);
+
+  /** Getter for the number of parameters of this model function.
+   *
+   * \return number of parameters
+   */
+  size_t getParameterDimension() const
+  {
+    return 1;
+  }
+
+  /** Evaluates the harmonic potential function for the given arguments.
+   *
+   * @param arguments single distance
+   * @return value of the potential function
+   */
+  results_t operator()(const arguments_t &arguments) const;
+
+  /** Evaluates the derivative of the potential function.
+   *
+   * @param arguments single distance
+   * @return vector with derivative with respect to the input degrees of freedom
+   */
+  derivative_components_t derivative(const arguments_t &arguments) const;
+
+  /** Evaluates the derivative of the function with the given \a arguments
+   * with respect to a specific parameter indicated by \a index.
+   *
+   * \param arguments set of arguments as input variables to the function
+   * \param index derivative of which parameter
+   * \return result vector containing the derivative with respect to the given
+   *         input
+   */
+  results_t parameter_derivative(const arguments_t &arguments, const size_t index) const;
+
+  /** Return the token name of this specific potential.
+   *
+   * \return token name of the potential
+   */
+  const std::string& getToken() const
+  { return potential_token; }
+
+  /** Returns a vector of parameter names.
+   *
+   * This is required from the specific implementation
+   *
+   * \return vector of strings containing parameter names
+   */
+  const ParameterNames_t& getParameterNames() const
+  { return ParameterNames; }
+
+  /** States whether lower and upper boundaries should be used to constraint
+   * the parameter search for this function model.
+   *
+   * \return true - constraints should be used, false - else
+   */
+  bool isBoxConstraint() const {
+    return true;
+  }
+
+  /** Returns a vector which are the lower boundaries for each parameter_t
+   * of this FunctionModel.
+   *
+   * \return vector of parameter_t resembling lowest allowed values
+   */
+  parameters_t getLowerBoxConstraints() const {
+    parameters_t lowerbound(getParameterDimension(), -std::numeric_limits<double>::max());
+    return lowerbound;
+  }
+
+  /** Returns a vector which are the upper boundaries for each parameter_t
+   * of this FunctionModel.
+   *
+   * \return vector of parameter_t resembling highest allowed values
+   */
+  parameters_t getUpperBoxConstraints() const {
+    return parameters_t(getParameterDimension(), std::numeric_limits<double>::max());
+  }
+
+  /** Returns a bound function to be used with TrainingData, extracting distances
+   * from a Fragment.
+   *
+   * \return bound function extracting distances from a fragment
+   */
+  FunctionModel::extractor_t getFragmentSpecificExtractor() const;
+
+  enum parameter_enum_t {
+    energy_offset=0,
+    MAXPARAMS
+  };
+
+private:
+  //!> parameter vector with parameters as in enum parameter_enum_t
+  parameters_t params;
+
+  //!> static definitions of the parameter name for this potential
+  static const ParameterNames_t ParameterNames;
+
+  //!> static token of this potential type
+  static const std::string potential_token;
+};
+
+#endif /* CONSTANTPOTENTIAL_HPP_ */
Index: src/Potentials/Specifics/PotentialTypes.def
===================================================================
--- src/Potentials/Specifics/PotentialTypes.def	(revision 060e1edada88a5af82c8bf5d9876db51fcac57a7)
+++ src/Potentials/Specifics/PotentialTypes.def	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -1,4 +1,4 @@
 //!> preprocessor sequence of all known potential types. Just add new parser here
-#define POTENTIALSEQUENCE (tersoff)(morse)(harmonic)(harmonic_angle)(saturation)
+#define POTENTIALSEQUENCE (constant)(tersoff)(morse)(harmonic)(harmonic_angle)(saturation)
 //!> Number of enumerations calculate automatically
 #define PotentialTypes_END BOOST_PP_SEQ_SIZE(POTENTIALSEQUENCE)
Index: src/Potentials/Specifics/unittests/ConstantPotentialUnitTest.cpp
===================================================================
--- src/Potentials/Specifics/unittests/ConstantPotentialUnitTest.cpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
+++ src/Potentials/Specifics/unittests/ConstantPotentialUnitTest.cpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -0,0 +1,121 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2013 Frederik Heber. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation, either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * ConstantPotentialUnitTest.cpp
+ *
+ *  Created on: May 09, 2013
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+using namespace std;
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include "ConstantPotentialUnitTest.hpp"
+
+#include <boost/assign.hpp>
+
+#include "CodePatterns/Assert.hpp"
+
+#include "FunctionApproximation/FunctionArgument.hpp"
+#include "Potentials/Specifics/ConstantPotential.hpp"
+#include "Potentials/helpers.hpp"
+
+using namespace boost::assign;
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( ConstantPotentialTest );
+
+const double offset = 0.1;
+
+void ConstantPotentialTest::setUp()
+{
+  // failing asserts should be thrown
+  ASSERT_DO(Assert::Throw);
+}
+
+
+void ConstantPotentialTest::tearDown()
+{
+}
+
+/** UnitTest for operator()
+ */
+void ConstantPotentialTest::operatorTest()
+{
+  ConstantPotential::ParticleTypes_t types;
+  ConstantPotential constant(types, offset);
+  CPPUNIT_ASSERT(
+      Helpers::isEqual(
+          offset,
+          constant( FunctionModel::arguments_t() )[0]
+      )
+  );
+}
+
+/** UnitTest for derivative()
+ */
+void ConstantPotentialTest::derivativeTest()
+{
+  ConstantPotential::ParticleTypes_t types;
+  ConstantPotential constant(types, offset);
+  CPPUNIT_ASSERT(
+      Helpers::isEqual(
+          0.,
+          constant.derivative(
+              FunctionModel::arguments_t()
+          )[0]
+      )
+  );
+}
+
+
+/** UnitTest for parameter_derivative()
+ */
+void ConstantPotentialTest::parameter_derivativeTest()
+{
+  ConstantPotential::ParticleTypes_t types;
+  ConstantPotential constant(types, offset);
+  CPPUNIT_ASSERT(
+      Helpers::isEqual(
+          1.,
+          constant.parameter_derivative(
+              FunctionModel::arguments_t(),
+              0
+          )[0]
+      )
+  );
+}
Index: src/Potentials/Specifics/unittests/ConstantPotentialUnitTest.hpp
===================================================================
--- src/Potentials/Specifics/unittests/ConstantPotentialUnitTest.hpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
+++ src/Potentials/Specifics/unittests/ConstantPotentialUnitTest.hpp	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -0,0 +1,39 @@
+/*
+ * ConstantPotentialUnitTest.hpp
+ *
+ *  Created on: Oct 04, 2012
+ *      Author: heber
+ */
+
+#ifndef CONSTANTPOTENTIALUNITTEST_HPP_
+#define CONSTANTPOTENTIALUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+/********************************************** Test classes **************************************/
+
+class ConstantPotentialTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( ConstantPotentialTest) ;
+    CPPUNIT_TEST ( operatorTest );
+    CPPUNIT_TEST ( derivativeTest );
+    CPPUNIT_TEST ( parameter_derivativeTest );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+      void setUp();
+      void tearDown();
+      void operatorTest();
+      void derivativeTest();
+      void parameter_derivativeTest();
+
+private:
+};
+
+#endif /* CONSTANTPOTENTIALUNITTEST_HPP_ */
Index: src/Potentials/Specifics/unittests/Makefile.am
===================================================================
--- src/Potentials/Specifics/unittests/Makefile.am	(revision 060e1edada88a5af82c8bf5d9876db51fcac57a7)
+++ src/Potentials/Specifics/unittests/Makefile.am	(revision 8203ce8c8111c1436927aeed91f2ccf0f8098b1e)
@@ -3,4 +3,5 @@
 
 POTENTIALSSPECIFICSTESTSSOURCES = \
+	../Potentials/Specifics/unittests/ConstantPotentialUnitTest.cpp \
 	../Potentials/Specifics/unittests/ManyBodyPotential_TersoffUnitTest.cpp \
 	../Potentials/Specifics/unittests/PairPotential_AngleUnitTest.cpp \
@@ -9,4 +10,5 @@
 
 POTENTIALSSPECIFICSTESTSHEADERS = \
+	../Potentials/Specifics/unittests/ConstantPotentialUnitTest.hpp \
 	../Potentials/Specifics/unittests/ManyBodyPotential_TersoffUnitTest.hpp \
 	../Potentials/Specifics/unittests/PairPotential_AngleUnitTest.hpp \
@@ -15,4 +17,5 @@
 
 POTENTIALSSPECIFICSTESTS = \
+	ConstantPotentialUnitTest \
 	ManyBodyPotential_TersoffUnitTest \
 	PairPotential_AngleUnitTest \
@@ -33,4 +36,9 @@
 	$(BOOST_SERIALIZATION_LDFLAGS) $(BOOST_SERIALIZATION_LIBS) \
 	$(BOOST_LIB)
+
+ConstantPotentialUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+	../Potentials/Specifics/unittests/ConstantPotentialUnitTest.cpp \
+	../Potentials/Specifics/unittests/ConstantPotentialUnitTest.hpp
+ConstantPotentialUnitTest_LDADD = ${POTENTIALSSPECIFICSLIBS}
 
 ManyBodyPotential_TersoffUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
