Index: configure.ac
===================================================================
--- configure.ac	(revision fe0355ee3fec7d6cbe3e4b2fdc1797b211092dff)
+++ configure.ac	(revision f06d528db608aa670621118d65d43dc67a5b5fd2)
@@ -247,4 +247,26 @@
 
 
+# Check for Levenberg-Marquardt implementation
+enable_levmar=no
+AX_LAPACK([enable_levmar=yes],[enable_levmar=no])
+AC_MSG_CHECKING(whether to compile in Levenberg-Marquardt)
+AS_IF([test x"$enable_levmar" = x"yes"],[
+	AC_ARG_WITH(
+		[levmar],
+		[AS_HELP_STRING([--with-levmar], [give path to LevMar package])],
+		[have_levmar_path=$withval],
+		[enable_levmar=no])
+		],[enable_levmar=no])
+AC_MSG_RESULT($enable_levmar)
+AS_IF([test x"$enable_levmar" = x"yes"],[
+	LEVMAR_CPPFLAGS="-I${have_levmar_path}/include"
+	LEVMAR_LDFLAGS="-L${have_levmar_path}/lib"
+	LEVMAR_LIBS="-llevmar"
+	AC_SUBST(LEVMAR_CPPFLAGS)
+	AC_SUBST(LEVMAR_LDFLAGS)
+	AC_SUBST(LEVMAR_LIBS)
+	])
+AM_CONDITIONAL([CONDLEVMAR], [test x"$enable_levmar" = x"yes"])
+
 # Checks for header files.
 AC_HEADER_STDC
Index: m4/ax_blas.m4
===================================================================
--- m4/ax_blas.m4	(revision f06d528db608aa670621118d65d43dc67a5b5fd2)
+++ m4/ax_blas.m4	(revision f06d528db608aa670621118d65d43dc67a5b5fd2)
@@ -0,0 +1,238 @@
+# ===========================================================================
+#          http://www.gnu.org/software/autoconf-archive/ax_blas.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_BLAS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+#   This macro looks for a library that implements the BLAS linear-algebra
+#   interface (see http://www.netlib.org/blas/). On success, it sets the
+#   BLAS_LIBS output variable to hold the requisite library linkages.
+#
+#   To link with BLAS, you should link with:
+#
+#     $BLAS_LIBS $LIBS $FLIBS
+#
+#   in that order. FLIBS is the output variable of the
+#   AC_F77_LIBRARY_LDFLAGS macro (called if necessary by AX_BLAS), and is
+#   sometimes necessary in order to link with F77 libraries. Users will also
+#   need to use AC_F77_DUMMY_MAIN (see the autoconf manual), for the same
+#   reason.
+#
+#   Many libraries are searched for, from ATLAS to CXML to ESSL. The user
+#   may also use --with-blas=<lib> in order to use some specific BLAS
+#   library <lib>. In order to link successfully, however, be aware that you
+#   will probably need to use the same Fortran compiler (which can be set
+#   via the F77 env. var.) as was used to compile the BLAS library.
+#
+#   ACTION-IF-FOUND is a list of shell commands to run if a BLAS library is
+#   found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it is
+#   not found. If ACTION-IF-FOUND is not specified, the default action will
+#   define HAVE_BLAS.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
+#
+#   This program 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 3 of the License, or (at your
+#   option) any later version.
+#
+#   This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#   As a special exception, the respective Autoconf Macro's copyright owner
+#   gives unlimited permission to copy, distribute and modify the configure
+#   scripts that are the output of Autoconf when processing the Macro. You
+#   need not follow the terms of the GNU General Public License when using
+#   or distributing such scripts, even though portions of the text of the
+#   Macro appear in them. The GNU General Public License (GPL) does govern
+#   all other use of the material that constitutes the Autoconf Macro.
+#
+#   This special exception to the GPL applies to versions of the Autoconf
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.
+
+#serial 14
+
+AU_ALIAS([ACX_BLAS], [AX_BLAS])
+AC_DEFUN([AX_BLAS], [
+AC_PREREQ(2.50)
+AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
+AC_REQUIRE([AC_CANONICAL_HOST])
+ax_blas_ok=no
+
+AC_ARG_WITH(blas,
+	[AS_HELP_STRING([--with-blas=<lib>], [use BLAS library <lib>])])
+case $with_blas in
+	yes | "") ;;
+	no) ax_blas_ok=disable ;;
+	-* | */* | *.a | *.so | *.so.* | *.o) BLAS_LIBS="$with_blas" ;;
+	*) BLAS_LIBS="-l$with_blas" ;;
+esac
+
+# Get fortran linker names of BLAS functions to check for.
+AC_F77_FUNC(sgemm)
+AC_F77_FUNC(dgemm)
+
+ax_blas_save_LIBS="$LIBS"
+LIBS="$LIBS $FLIBS"
+
+# First, check BLAS_LIBS environment variable
+if test $ax_blas_ok = no; then
+if test "x$BLAS_LIBS" != x; then
+	save_LIBS="$LIBS"; LIBS="$BLAS_LIBS $LIBS"
+	AC_MSG_CHECKING([for $sgemm in $BLAS_LIBS])
+	AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes], [BLAS_LIBS=""])
+	AC_MSG_RESULT($ax_blas_ok)
+	LIBS="$save_LIBS"
+fi
+fi
+
+# BLAS linked to by default?  (happens on some supercomputers)
+if test $ax_blas_ok = no; then
+	save_LIBS="$LIBS"; LIBS="$LIBS"
+	AC_MSG_CHECKING([if $sgemm is being linked in already])
+	AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes])
+	AC_MSG_RESULT($ax_blas_ok)
+	LIBS="$save_LIBS"
+fi
+
+# BLAS in OpenBLAS library? (http://xianyi.github.com/OpenBLAS/)
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(openblas, $sgemm, [ax_blas_ok=yes
+			                BLAS_LIBS="-lopenblas"])
+fi
+
+# BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(atlas, ATL_xerbla,
+		[AC_CHECK_LIB(f77blas, $sgemm,
+		[AC_CHECK_LIB(cblas, cblas_dgemm,
+			[ax_blas_ok=yes
+			 BLAS_LIBS="-lcblas -lf77blas -latlas"],
+			[], [-lf77blas -latlas])],
+			[], [-latlas])])
+fi
+
+# BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(blas, $sgemm,
+		[AC_CHECK_LIB(dgemm, $dgemm,
+		[AC_CHECK_LIB(sgemm, $sgemm,
+			[ax_blas_ok=yes; BLAS_LIBS="-lsgemm -ldgemm -lblas"],
+			[], [-lblas])],
+			[], [-lblas])])
+fi
+
+# BLAS in Intel MKL library?
+if test $ax_blas_ok = no; then
+	# MKL for gfortran
+	if test x"$ac_cv_fc_compiler_gnu" = xyes; then
+		# 64 bit
+		if test $host_cpu = x86_64; then
+			AC_CHECK_LIB(mkl_gf_lp64, $sgemm,
+			[ax_blas_ok=yes;BLAS_LIBS="-lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread"],,
+			[-lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread])
+		# 32 bit
+		elif test $host_cpu = i686; then
+			AC_CHECK_LIB(mkl_gf, $sgemm,
+				[ax_blas_ok=yes;BLAS_LIBS="-lmkl_gf -lmkl_sequential -lmkl_core -lpthread"],,
+				[-lmkl_gf -lmkl_sequential -lmkl_core -lpthread])
+		fi
+	# MKL for other compilers (Intel, PGI, ...?)
+	else
+		# 64-bit
+		if test $host_cpu = x86_64; then
+			AC_CHECK_LIB(mkl_intel_lp64, $sgemm,
+				[ax_blas_ok=yes;BLAS_LIBS="-lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread"],,
+				[-lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread])
+		# 32-bit
+		elif test $host_cpu = i686; then
+			AC_CHECK_LIB(mkl_intel, $sgemm,
+				[ax_blas_ok=yes;BLAS_LIBS="-lmkl_intel -lmkl_sequential -lmkl_core -lpthread"],,
+				[-lmkl_intel -lmkl_sequential -lmkl_core -lpthread])
+		fi
+	fi
+fi
+# Old versions of MKL
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(mkl, $sgemm, [ax_blas_ok=yes;BLAS_LIBS="-lmkl -lguide -lpthread"],,[-lguide -lpthread])
+fi
+
+# BLAS in Apple vecLib library?
+if test $ax_blas_ok = no; then
+	save_LIBS="$LIBS"; LIBS="-framework vecLib $LIBS"
+	AC_MSG_CHECKING([for $sgemm in -framework vecLib])
+	AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes;BLAS_LIBS="-framework vecLib"])
+	AC_MSG_RESULT($ax_blas_ok)
+	LIBS="$save_LIBS"
+fi
+
+# BLAS in Alpha CXML library?
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(cxml, $sgemm, [ax_blas_ok=yes;BLAS_LIBS="-lcxml"])
+fi
+
+# BLAS in Alpha DXML library? (now called CXML, see above)
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(dxml, $sgemm, [ax_blas_ok=yes;BLAS_LIBS="-ldxml"])
+fi
+
+# BLAS in Sun Performance library?
+if test $ax_blas_ok = no; then
+	if test "x$GCC" != xyes; then # only works with Sun CC
+		AC_CHECK_LIB(sunmath, acosp,
+			[AC_CHECK_LIB(sunperf, $sgemm,
+				[BLAS_LIBS="-xlic_lib=sunperf -lsunmath"
+                                 ax_blas_ok=yes],[],[-lsunmath])])
+	fi
+fi
+
+# BLAS in SCSL library?  (SGI/Cray Scientific Library)
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(scs, $sgemm, [ax_blas_ok=yes; BLAS_LIBS="-lscs"])
+fi
+
+# BLAS in SGIMATH library?
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(complib.sgimath, $sgemm,
+		     [ax_blas_ok=yes; BLAS_LIBS="-lcomplib.sgimath"])
+fi
+
+# BLAS in IBM ESSL library? (requires generic BLAS lib, too)
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(blas, $sgemm,
+		[AC_CHECK_LIB(essl, $sgemm,
+			[ax_blas_ok=yes; BLAS_LIBS="-lessl -lblas"],
+			[], [-lblas $FLIBS])])
+fi
+
+# Generic BLAS library?
+if test $ax_blas_ok = no; then
+	AC_CHECK_LIB(blas, $sgemm, [ax_blas_ok=yes; BLAS_LIBS="-lblas"])
+fi
+
+AC_SUBST(BLAS_LIBS)
+
+LIBS="$ax_blas_save_LIBS"
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test x"$ax_blas_ok" = xyes; then
+        ifelse([$1],,AC_DEFINE(HAVE_BLAS,1,[Define if you have a BLAS library.]),[$1])
+        :
+else
+        ax_blas_ok=no
+        $2
+fi
+])dnl AX_BLAS
Index: m4/ax_lapack.m4
===================================================================
--- m4/ax_lapack.m4	(revision f06d528db608aa670621118d65d43dc67a5b5fd2)
+++ m4/ax_lapack.m4	(revision f06d528db608aa670621118d65d43dc67a5b5fd2)
@@ -0,0 +1,131 @@
+# ===========================================================================
+#         http://www.gnu.org/software/autoconf-archive/ax_lapack.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_LAPACK([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+#   This macro looks for a library that implements the LAPACK linear-algebra
+#   interface (see http://www.netlib.org/lapack/). On success, it sets the
+#   LAPACK_LIBS output variable to hold the requisite library linkages.
+#
+#   To link with LAPACK, you should link with:
+#
+#     $LAPACK_LIBS $BLAS_LIBS $LIBS $FLIBS
+#
+#   in that order. BLAS_LIBS is the output variable of the AX_BLAS macro,
+#   called automatically. FLIBS is the output variable of the
+#   AC_F77_LIBRARY_LDFLAGS macro (called if necessary by AX_BLAS), and is
+#   sometimes necessary in order to link with F77 libraries. Users will also
+#   need to use AC_F77_DUMMY_MAIN (see the autoconf manual), for the same
+#   reason.
+#
+#   The user may also use --with-lapack=<lib> in order to use some specific
+#   LAPACK library <lib>. In order to link successfully, however, be aware
+#   that you will probably need to use the same Fortran compiler (which can
+#   be set via the F77 env. var.) as was used to compile the LAPACK and BLAS
+#   libraries.
+#
+#   ACTION-IF-FOUND is a list of shell commands to run if a LAPACK library
+#   is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
+#   is not found. If ACTION-IF-FOUND is not specified, the default action
+#   will define HAVE_LAPACK.
+#
+# LICENSE
+#
+#   Copyright (c) 2009 Steven G. Johnson <stevenj@alum.mit.edu>
+#
+#   This program 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 3 of the License, or (at your
+#   option) any later version.
+#
+#   This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#   As a special exception, the respective Autoconf Macro's copyright owner
+#   gives unlimited permission to copy, distribute and modify the configure
+#   scripts that are the output of Autoconf when processing the Macro. You
+#   need not follow the terms of the GNU General Public License when using
+#   or distributing such scripts, even though portions of the text of the
+#   Macro appear in them. The GNU General Public License (GPL) does govern
+#   all other use of the material that constitutes the Autoconf Macro.
+#
+#   This special exception to the GPL applies to versions of the Autoconf
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.
+
+#serial 7
+
+AU_ALIAS([ACX_LAPACK], [AX_LAPACK])
+AC_DEFUN([AX_LAPACK], [
+AC_REQUIRE([AX_BLAS])
+ax_lapack_ok=no
+
+AC_ARG_WITH(lapack,
+        [AS_HELP_STRING([--with-lapack=<lib>], [use LAPACK library <lib>])])
+case $with_lapack in
+        yes | "") ;;
+        no) ax_lapack_ok=disable ;;
+        -* | */* | *.a | *.so | *.so.* | *.o) LAPACK_LIBS="$with_lapack" ;;
+        *) LAPACK_LIBS="-l$with_lapack" ;;
+esac
+
+# Get fortran linker name of LAPACK function to check for.
+AC_F77_FUNC(cheev)
+
+# We cannot use LAPACK if BLAS is not found
+if test "x$ax_blas_ok" != xyes; then
+        ax_lapack_ok=noblas
+        LAPACK_LIBS=""
+fi
+
+# First, check LAPACK_LIBS environment variable
+if test "x$LAPACK_LIBS" != x; then
+        save_LIBS="$LIBS"; LIBS="$LAPACK_LIBS $BLAS_LIBS $LIBS $FLIBS"
+        AC_MSG_CHECKING([for $cheev in $LAPACK_LIBS])
+        AC_TRY_LINK_FUNC($cheev, [ax_lapack_ok=yes], [LAPACK_LIBS=""])
+        AC_MSG_RESULT($ax_lapack_ok)
+        LIBS="$save_LIBS"
+        if test $ax_lapack_ok = no; then
+                LAPACK_LIBS=""
+        fi
+fi
+
+# LAPACK linked to by default?  (is sometimes included in BLAS lib)
+if test $ax_lapack_ok = no; then
+        save_LIBS="$LIBS"; LIBS="$LIBS $BLAS_LIBS $FLIBS"
+        AC_CHECK_FUNC($cheev, [ax_lapack_ok=yes])
+        LIBS="$save_LIBS"
+fi
+
+# Generic LAPACK library?
+for lapack in lapack lapack_rs6k; do
+        if test $ax_lapack_ok = no; then
+                save_LIBS="$LIBS"; LIBS="$BLAS_LIBS $LIBS"
+                AC_CHECK_LIB($lapack, $cheev,
+                    [ax_lapack_ok=yes; LAPACK_LIBS="-l$lapack"], [], [$FLIBS])
+                LIBS="$save_LIBS"
+        fi
+done
+
+AC_SUBST(LAPACK_LIBS)
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test x"$ax_lapack_ok" = xyes; then
+        ifelse([$1],,AC_DEFINE(HAVE_LAPACK,1,[Define if you have LAPACK library.]),[$1])
+        :
+else
+        ax_lapack_ok=no
+        $2
+fi
+])dnl AX_LAPACK
Index: src/LevMartester.cpp
===================================================================
--- src/LevMartester.cpp	(revision f06d528db608aa670621118d65d43dc67a5b5fd2)
+++ src/LevMartester.cpp	(revision f06d528db608aa670621118d65d43dc67a5b5fd2)
@@ -0,0 +1,241 @@
+/*
+ * 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/>. 
+ */
+
+/*
+ * LevMartester.cpp
+ *
+ *  Created on: Sep 27, 2012
+ *      Author: heber
+ */
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/program_options.hpp>
+
+#include <fstream>
+#include <iostream>
+#include <iterator>
+#include <vector>
+
+#include <levmar.h>
+
+#include "CodePatterns/Assert.hpp"
+#include "CodePatterns/Log.hpp"
+
+#include "LinearAlgebra/Vector.hpp"
+
+#include "Fragmentation/Homology/HomologyContainer.hpp"
+#include "Fragmentation/SetValues/Fragment.hpp"
+
+namespace po = boost::program_options;
+
+HomologyGraph getFirstGraphWithTwoCarbons(const HomologyContainer &homologies)
+{
+  FragmentNode SaturatedCarbon(6,4); // carbon has atomic number 6 and should have 4 bonds for C2H6
+  for (HomologyContainer::container_t::const_iterator iter =
+      homologies.begin(); iter != homologies.end(); ++iter) {
+    if (iter->first.hasNode(SaturatedCarbon,2))
+      return iter->first;
+  }
+  return HomologyGraph();
+}
+
+/* Meyer's (reformulated) problem, minimum at (2.48, 6.18, 3.45) */
+void meyer(double *p, double *x, int m, int n, void *data)
+{
+register int i;
+double ui;
+
+        for(i=0; i<n; ++i){
+                ui=0.45+0.05*i;
+                x[i]=p[0]*exp(10.0*p[1]/(ui+p[2]) - 13.0);
+        }
+}
+
+void jacmeyer(double *p, double *jac, int m, int n, void *data)
+{
+register int i, j;
+double ui, tmp;
+
+  for(i=j=0; i<n; ++i){
+          ui=0.45+0.05*i;
+          tmp=exp(10.0*p[1]/(ui+p[2]) - 13.0);
+
+          jac[j++]=tmp;
+          jac[j++]=10.0*p[0]*tmp/(ui+p[2]);
+          jac[j++]=-10.0*p[0]*p[1]*tmp/((ui+p[2])*(ui+p[2]));
+  }
+}
+
+
+int main(int argc, char **argv)
+{
+  std::cout << "Hello to the World from LevMar!" << std::endl;
+
+  // load homology file
+  po::options_description desc("Allowed options");
+  desc.add_options()
+      ("help", "produce help message")
+      ("homology-file", po::value< boost::filesystem::path >(), "homology file to parse")
+  ;
+
+  po::variables_map vm;
+  po::store(po::parse_command_line(argc, argv, desc), vm);
+  po::notify(vm);
+
+  if (vm.count("help")) {
+      std::cout << desc << "\n";
+      return 1;
+  }
+
+  boost::filesystem::path homology_file;
+  if (vm.count("homology-file")) {
+    homology_file = vm["homology-file"].as<boost::filesystem::path>();
+    LOG(1, "INFO: Parsing " << homology_file.string() << ".");
+  } else {
+    LOG(0, "homology-file level was not set.");
+  }
+  HomologyContainer homologies;
+  if (boost::filesystem::exists(homology_file)) {
+    std::ifstream returnstream(homology_file.string().c_str());
+    if (returnstream.good()) {
+      boost::archive::text_iarchive ia(returnstream);
+      ia >> homologies;
+    } else {
+      ELOG(2, "Failed to parse from " << homology_file.string() << ".");
+    }
+    returnstream.close();
+  } else {
+    ELOG(0, homology_file << " does not exist.");
+  }
+
+  // first we try to look into the HomologyContainer
+  LOG(1, "INFO: Listing all present homologies ...");
+  for (HomologyContainer::container_t::const_iterator iter =
+      homologies.begin(); iter != homologies.end(); ++iter) {
+    LOG(1, "INFO: graph " << iter->first << " has Fragment "
+        << iter->second.first << " and associated energy " << iter->second.second << ".");
+  }
+
+  // then we ought to pick the right HomologyGraph ...
+  const HomologyGraph graph = getFirstGraphWithTwoCarbons(homologies);
+  LOG(1, "First representative graph containing two saturated carbons is " << graph << ".");
+
+  // Afterwards we go through all of this type and gather the distance and the energy value
+  typedef std::vector< std::pair<double, double> > DistanceEnergyVector_t;
+  DistanceEnergyVector_t DistanceEnergyVector;
+  std::pair<HomologyContainer::const_iterator, HomologyContainer::const_iterator> range =
+      homologies.getHomologousGraphs(graph);
+  for (HomologyContainer::const_iterator iter = range.first; iter != range.second; ++iter) {
+    // get distance out of Fragment
+    const Fragment &fragment = iter->second.first;
+    const Fragment::charges_t charges = fragment.getCharges();
+    const Fragment::positions_t positions = fragment.getPositions();
+    std::vector< Vector > DistanceVectors;
+    for (Fragment::charges_t::const_iterator chargeiter = charges.begin();
+        chargeiter != charges.end(); ++chargeiter) {
+      if (*chargeiter == 6) {
+        Fragment::positions_t::const_iterator positer = positions.begin();
+        const size_t steps = std::distance(charges.begin(), chargeiter);
+        std::advance(positer, steps);
+        DistanceVectors.push_back(Vector((*positer)[0], (*positer)[1], (*positer)[2]));
+      }
+    }
+    ASSERT( DistanceVectors.size() == (size_t)2,
+        "main() - found not exactly two carbon atoms in fragment.");
+    const double distance = DistanceVectors[0].distance(DistanceVectors[1]);
+    const double energy = iter->second.second;
+    DistanceEnergyVector.push_back( std::make_pair(distance, energy) );
+  }
+  LOG(1, "INFO: I gathered the following " << DistanceEnergyVector.size() << " data pairs: ");
+  for (DistanceEnergyVector_t::const_iterator dataiter = DistanceEnergyVector.begin();
+      dataiter != DistanceEnergyVector.end(); ++dataiter) {
+    LOG(1, "INFO: " << dataiter->first << " with energy " << dataiter->second);
+  }
+  // NOTICE that distance are in bohrradi as they come from MPQC!
+
+  // let levmar optimize
+  register int i, j;
+  int ret;
+  double p[5], // 5 is max(2, 3, 5)
+             x[16]; // 16 is max(2, 3, 5, 6, 16)
+  int m, n;
+  double opts[LM_OPTS_SZ], info[LM_INFO_SZ];
+
+  opts[0]=LM_INIT_MU; opts[1]=1E-15; opts[2]=1E-15; opts[3]=1E-20;
+  opts[4]= LM_DIFF_DELTA; // relevant only if the Jacobian is approximated using finite differences; specifies forward differencing
+  //opts[4]=-LM_DIFF_DELTA; // specifies central differencing to approximate Jacobian; more accurate but more expensive to compute!
+
+  m=3; n=16;
+  p[0]=8.85; p[1]=4.0; p[2]=2.5;
+  x[0]=34.780;        x[1]=28.610; x[2]=23.650; x[3]=19.630;
+  x[4]=16.370;        x[5]=13.720; x[6]=11.540; x[7]=9.744;
+  x[8]=8.261; x[9]=7.030; x[10]=6.005; x[11]=5.147;
+  x[12]=4.427;        x[13]=3.820; x[14]=3.307; x[15]=2.872;
+  ret=dlevmar_der(meyer, jacmeyer, p, x, m, n, 1000, opts, info, NULL, NULL, NULL); // with analytic Jacobian
+
+ { double *work, *covar;
+  work=(double *)malloc((LM_DIF_WORKSZ(m, n)+m*m)*sizeof(double));
+  if(!work){
+      fprintf(stderr, "memory allocation request failed in main()\n");
+    exit(1);
+  }
+  covar=work+LM_DIF_WORKSZ(m, n);
+
+  ret=dlevmar_dif(meyer, p, x, m, n, 1000, opts, info, work, covar, NULL); // no Jacobian, caller allocates work memory, covariance estimated
+
+  printf("Covariance of the fit:\n");
+  for(i=0; i<m; ++i){
+    for(j=0; j<m; ++j)
+      printf("%g ", covar[i*m+j]);
+    printf("\n");
+  }
+  printf("\n");
+
+  free(work);
+ }
+
+//  {
+//   double err[16];
+//   dlevmar_chkjac(meyer, jacmeyer, p, m, n, NULL, err);
+//   for(i=0; i<n; ++i) printf("gradient %d, err %g\n", i, err[i]);
+//  }
+
+  printf("Levenberg-Marquardt returned %d in %g iter, reason %g\nSolution: ", ret, info[5], info[6]);
+  for(i=0; i<m; ++i)
+    printf("%.7g ", p[i]);
+  printf("\n\nMinimization info:\n");
+  for(i=0; i<LM_INFO_SZ; ++i)
+    printf("%g ", info[i]);
+  printf("\n");
+
+  return 0;
+}
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision fe0355ee3fec7d6cbe3e4b2fdc1797b211092dff)
+++ src/Makefile.am	(revision f06d528db608aa670621118d65d43dc67a5b5fd2)
@@ -475,4 +475,23 @@
 endif
 
+if CONDLEVMAR
+bin_PROGRAMS += LevMartester
+LevMartester_SOURCES = LevMartester.cpp
+LevMartester_CPPFLAGS = $(AM_CPPFLAGS) $(LEVMAR_CPPFLAGS)
+LevMartester_LDFLAGS = $(AM_LDFLAGS) $(BOOST_SERIALIZATION_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LDFLAGS) $(BOOST_FILESYSTEM_LDFLAGS) $(BOOST_SYSTEM_LDFLAGS) ${CodePatterns_LDFLAGS} $(LEVMAR_LDFLAGS)
+LevMartester_LDADD = \
+	libMolecuilderFragmentation.la \
+	libMolecuilderFragmentation_getFromKeysetStub.la \
+	libMolecuilderFragmentationSetValues.la \
+	$(top_builddir)/LinearAlgebra/src/LinearAlgebra/libLinearAlgebra.la \
+	$(BOOST_SERIALIZATION_LIBS) \
+	$(BOOST_PROGRAM_OPTIONS_LIBS) \
+	$(BOOST_FILESYSTEM_LIBS) \
+	$(BOOST_SYSTEM_LIBS) \
+	${CodePatterns_LIBS} \
+	$(LEVMAR_LIBS) \
+	$(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS)
+endif
+
 unity_SOURCES = unity.cpp
 unity_CPPFLAGS = $(AM_CPPFLAGS) 
