Index: src/Potentials/Specifics/FourBodyPotential_Improper.cpp
===================================================================
--- src/Potentials/Specifics/FourBodyPotential_Improper.cpp	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
+++ src/Potentials/Specifics/FourBodyPotential_Improper.cpp	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
@@ -0,0 +1,89 @@
+/*
+ * 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/>.
+ */
+
+/*
+ * FourBodyPotential_Improper.cpp
+ *
+ *  Created on: Jul 10, 2013
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "FourBodyPotential_Improper.hpp"
+
+#include <boost/assign/list_of.hpp> // for 'map_list_of()'
+
+// static definitions
+const FourBodyPotential_Improper::ParameterNames_t
+FourBodyPotential_Improper::ParameterNames =
+      boost::assign::list_of<std::string>
+      ("spring_constant")
+      ("equilibrium_distance")
+    ;
+const std::string FourBodyPotential_Improper::improper_token("improper");
+
+
+FourBodyPotential_Improper::FourBodyPotential_Improper() :
+    FourBodyPotential_Torsion()
+{}
+
+FourBodyPotential_Improper::FourBodyPotential_Improper(
+    const ParticleTypes_t &_ParticleTypes) :
+    FourBodyPotential_Torsion(_ParticleTypes)
+{}
+
+FourBodyPotential_Improper::FourBodyPotential_Improper(
+    const ParticleTypes_t &_ParticleTypes,
+    const double _spring_constant,
+    const double _equilibrium_distance) :
+    FourBodyPotential_Torsion(
+        _ParticleTypes,
+        _spring_constant,
+        _equilibrium_distance)
+{}
+
+FourBodyPotential_Improper::result_t
+FourBodyPotential_Improper::function_theta(
+    const double &r_ij,
+    const double &r_ik,
+    const double &r_il,
+    const double &r_jk,
+    const double &r_jl,
+    const double &r_kl
+  ) const
+{
+  // just relay call to torsion's theta function with some flipped arguments
+  return FourBodyPotential_Torsion::function_theta(
+      r_jk,
+      r_ik,
+      r_kl,
+      r_ij,
+      r_jl,
+      r_il
+      );
+}
Index: src/Potentials/Specifics/FourBodyPotential_Improper.hpp
===================================================================
--- src/Potentials/Specifics/FourBodyPotential_Improper.hpp	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
+++ src/Potentials/Specifics/FourBodyPotential_Improper.hpp	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
@@ -0,0 +1,84 @@
+/*
+ * FourBodyPotential_Improper.hpp
+ *
+ *  Created on: Jul 10, 2013
+ *      Author: heber
+ */
+
+#ifndef FOURBODYPOTENTIAL_IMPROPER_HPP_
+#define FOURBODYPOTENTIAL_IMPROPER_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "FourBodyPotential_Torsion.hpp"
+
+class FourBodyPotential_ImproperTest;
+class PotentialFactory;
+
+/** The improper potential is identical to the torsion potential with exception
+ * of the way the angle is calculated.
+ *
+ * Hence, we only need to override function_theta().
+ *
+ */
+class FourBodyPotential_Improper : public FourBodyPotential_Torsion
+{
+  //!> grant unit test access to internal parts
+  friend class FourBodyPotential_ImproperTest;
+  //!> grant PotentialFactory access to default cstor
+  friend class PotentialFactory;
+  // some repeated typedefs to avoid ambiguities
+  typedef FunctionModel::result_t result_t;
+  typedef FunctionModel::results_t results_t;
+private:
+  /** Private default constructor.
+   *
+   * This prevents creation of potential without set ParticleTypes_t.
+   *
+   * \note PotentialFactory may use this default cstor
+   *
+   */
+  FourBodyPotential_Improper();
+
+public:
+  FourBodyPotential_Improper(const ParticleTypes_t &_ParticleTypes);
+  FourBodyPotential_Improper(
+      const ParticleTypes_t &_ParticleTypes,
+      const double _spring_constant,
+      const double _equilibrium_distance);
+  virtual ~FourBodyPotential_Improper() {}
+
+private:
+  /** Function to obtain angle between planes from distances.
+   *
+   */
+  result_t function_theta(
+      const double &r_ij,
+      const double &r_ik,
+      const double &r_il,
+      const double &r_jk,
+      const double &r_jl,
+      const double &r_kl
+    ) const;
+
+  /** Return the token name of this specific potential.
+   *
+   *  We need to override the function in order to use a different static variable.
+   *
+   * \return token name of the potential
+   */
+  const std::string& getToken() const
+  { return improper_token; }
+
+private:
+  //!> static definitions of the parameter name for this potential
+  static const ParameterNames_t ParameterNames;
+
+  //!> static token of this potential type
+  static const std::string improper_token;
+};
+
+#endif /* FOURBODYPOTENTIAL_IMPROPER_HPP_ */
Index: src/Potentials/Specifics/PotentialTypes.def
===================================================================
--- src/Potentials/Specifics/PotentialTypes.def	(revision a74a9626b6ee2a91ad83f23859d11cf48766d51b)
+++ src/Potentials/Specifics/PotentialTypes.def	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
@@ -1,4 +1,4 @@
 //!> preprocessor sequence of all known potential types. Just add new parser here
-#define POTENTIALSEQUENCE (constant)(tersoff)(morse)(harmonic)(harmonic_angle)(lennardjones)(torsion)
+#define POTENTIALSEQUENCE (constant)(tersoff)(morse)(harmonic)(harmonic_angle)(lennardjones)(torsion)(improper)
 //!> Number of enumerations calculate automatically
 #define PotentialTypes_END BOOST_PP_SEQ_SIZE(POTENTIALSEQUENCE)
Index: src/Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.cpp
===================================================================
--- src/Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.cpp	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
+++ src/Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.cpp	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
@@ -0,0 +1,183 @@
+/*
+ * 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/>.
+ */
+
+/*
+ * FourBodyPotential_ImproperUnitTest.cpp
+ *
+ *  Created on: Jul 10, 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 "FourBodyPotential_ImproperUnitTest.hpp"
+
+#include <boost/assign.hpp>
+
+#include "CodePatterns/Assert.hpp"
+
+#include "FunctionApproximation/FunctionArgument.hpp"
+#include "Potentials/Specifics/FourBodyPotential_Improper.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( FourBodyPotential_ImproperTest );
+
+const double spring_constant = .5;
+
+void FourBodyPotential_ImproperTest::setUp()
+{
+  // failing asserts should be thrown
+  ASSERT_DO(Assert::Throw);
+
+  // create three distances to have the desired angle
+  typedef std::vector<double> angles_t;
+  angles_t angles;
+  angles += -0.5, -.4, -.3, -.2, -.1, 0., .1, .2, .3, .4, .5;
+  FunctionModel::arguments_t tempvector(6);
+  tempvector[3] = argument_t( std::make_pair(0,1), std::make_pair(0,1), 1.);
+  tempvector[1] = argument_t( std::make_pair(0,2), std::make_pair(0,1), 1.);
+  tempvector[5] = argument_t( std::make_pair(0,3), std::make_pair(0,0), 0.);
+  tempvector[0] = argument_t( std::make_pair(1,2), std::make_pair(1,1), 1.);
+  tempvector[4] = argument_t( std::make_pair(1,3), std::make_pair(0,1), 1.);
+  tempvector[2] = argument_t( std::make_pair(2,3), std::make_pair(0,1), 1.);
+  // we have two equilateral triangles (length 1)
+  // height is then \sqrt(2*(1+1)-1)*.5=sqrt(3)*.5
+  // then angle in triangle of both heights and connecting line is
+  // (h_1^2+h_2^2 - x^2) / (2*h_1*h_2) = cos(theta). Solving this equation
+  // for the unknown distance x is what we need
+  // 3/4+3/4-x/(2*sqrt(3)*.5*sqrt(3)*.5)
+  // x = sqrt(h_1^2+h_2^2 - cos(theta) * (2*h_1*h_2))
+  for (angles_t::const_iterator iter = angles.begin(); iter != angles.end(); ++iter) {
+    tempvector[5].distance = sqrt(.75+.75 - (*iter)*(1.5));
+    input += tempvector;
+  }
+  output +=
+      spring_constant*0.25,
+      spring_constant*0.16,
+      spring_constant*0.09,
+      spring_constant*0.04,
+      spring_constant*0.01,
+      spring_constant*0.,
+      spring_constant*0.01,
+      spring_constant*0.04,
+      spring_constant*0.09,
+      spring_constant*0.16,
+      spring_constant*0.25;
+
+  CPPUNIT_ASSERT_EQUAL( input.size(), output.size() );
+}
+
+
+void FourBodyPotential_ImproperTest::tearDown()
+{
+}
+
+/** UnitTest for operator()
+ */
+void FourBodyPotential_ImproperTest::operatorTest()
+{
+  FourBodyPotential_Improper::ParticleTypes_t types =
+      boost::assign::list_of<FourBodyPotential_Improper::ParticleType_t>
+        (0)(1)(1)(0)
+      ;
+  FourBodyPotential_Improper angle(types, spring_constant,0.);
+  for (size_t index = 0; index < input.size(); ++index) {
+    const FourBodyPotential_Improper::results_t result =
+        angle( input[index] );
+    CPPUNIT_ASSERT(
+        Helpers::isEqual(
+            output[index],
+            result[0]
+        )
+    );
+  }
+}
+
+/** UnitTest for derivative()
+ */
+void FourBodyPotential_ImproperTest::derivativeTest()
+{
+  FourBodyPotential_Improper::ParticleTypes_t types =
+      boost::assign::list_of<FourBodyPotential_Improper::ParticleType_t>
+        (0)(1)(1)(0)
+      ;
+  FourBodyPotential_Improper angle(types, spring_constant,0.);
+  CPPUNIT_ASSERT(
+      Helpers::isEqual(
+          0.,
+          angle.derivative(
+              input[5]
+          )[0],
+          10.
+      )
+  );
+}
+
+
+/** UnitTest for parameter_derivative()
+ */
+void FourBodyPotential_ImproperTest::parameter_derivativeTest()
+{
+  FourBodyPotential_Improper::ParticleTypes_t types =
+      boost::assign::list_of<FourBodyPotential_Improper::ParticleType_t>
+        (0)(1)(1)(0)
+      ;
+  FourBodyPotential_Improper angle(types, spring_constant,0.);
+  CPPUNIT_ASSERT(
+      Helpers::isEqual(
+          0.,
+          angle.parameter_derivative(
+              input[5],
+              0
+          )[0],
+          10.
+      )
+  );
+  CPPUNIT_ASSERT(
+      Helpers::isEqual(
+          0.,
+          angle.parameter_derivative(
+              input[5],
+              1
+          )[0],
+          10.
+      )
+  );
+}
Index: src/Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.hpp
===================================================================
--- src/Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.hpp	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
+++ src/Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.hpp	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
@@ -0,0 +1,46 @@
+/*
+ * FourBodyPotential_ImproperUnitTest.hpp
+ *
+ *  Created on: Jul 10, 2013
+ *      Author: heber
+ */
+
+#ifndef FOURBODYPOTENTIAL_IMPROPERUNITTEST_HPP_
+#define FOURBODYPOTENTIAL_IMPROPERUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "FunctionApproximation/FunctionModel.hpp"
+
+class FourBodyPotential_Improper;
+
+/********************************************** Test classes **************************************/
+
+class FourBodyPotential_ImproperTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( FourBodyPotential_ImproperTest) ;
+    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:
+      typedef std::vector<double> data_t;
+      std::vector<FunctionModel::arguments_t> input;
+      data_t output;
+};
+
+#endif /* FOURBODYPOTENTIAL_IMPROPERUNITTEST_HPP_ */
Index: src/Potentials/Specifics/unittests/Makefile.am
===================================================================
--- src/Potentials/Specifics/unittests/Makefile.am	(revision a74a9626b6ee2a91ad83f23859d11cf48766d51b)
+++ src/Potentials/Specifics/unittests/Makefile.am	(revision 791a1267512a1feef8dcf3d7a6835d27341ed0ef)
@@ -4,4 +4,5 @@
 POTENTIALSSPECIFICSTESTSSOURCES = \
 	../Potentials/Specifics/unittests/ConstantPotentialUnitTest.cpp \
+	../Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.cpp \
 	../Potentials/Specifics/unittests/FourBodyPotential_TorsionUnitTest.cpp \
 	../Potentials/Specifics/unittests/ManyBodyPotential_TersoffUnitTest.cpp \
@@ -13,4 +14,5 @@
 POTENTIALSSPECIFICSTESTSHEADERS = \
 	../Potentials/Specifics/unittests/ConstantPotentialUnitTest.hpp \
+	../Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.hpp \
 	../Potentials/Specifics/unittests/FourBodyPotential_TorsionUnitTest.hpp \
 	../Potentials/Specifics/unittests/ManyBodyPotential_TersoffUnitTest.hpp \
@@ -22,4 +24,5 @@
 POTENTIALSSPECIFICSTESTS = \
 	ConstantPotentialUnitTest \
+	FourBodyPotential_ImproperUnitTest \
 	FourBodyPotential_TorsionUnitTest \
 	ManyBodyPotential_TersoffUnitTest \
@@ -47,4 +50,9 @@
 	../Potentials/Specifics/unittests/ConstantPotentialUnitTest.hpp
 ConstantPotentialUnitTest_LDADD = ${POTENTIALSSPECIFICSLIBS}
+
+FourBodyPotential_ImproperUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+	../Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.cpp \
+	../Potentials/Specifics/unittests/FourBodyPotential_ImproperUnitTest.hpp
+FourBodyPotential_ImproperUnitTest_LDADD = ${POTENTIALSSPECIFICSLIBS}
 
 FourBodyPotential_TorsionUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
