Index: doc/userguide/userguide.xml
===================================================================
--- doc/userguide/userguide.xml	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ doc/userguide/userguide.xml	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -1752,4 +1752,8 @@
             This offset compensates for the interaction energy associated with
             a fragment of order 1, e.g. a single hydrogen atom. Essentially, this captures the atomic energy that is not associated to any bonding interactions.</para>
+            <para>Note that by choosing "set-max-iterations" and "take-best-of"
+            one can force the optimization to try either a single set of random
+            initial parameters very thoroughly or many different sets just for
+            a few iterations. Or any in between.</para>
           </note>
         </section>
@@ -1785,4 +1789,7 @@
           in a text editor at the moment. And perform a fit-compound-potential
           with this file.</para>
+          <para>Here, also "set-max-iterations" and "take-best-of" can be used
+          to mix thorough or shallow search from random initial parameter sets.
+          </para>
         </section>
         <section xml:id="potentials.parse-potential">
Index: src/Actions/PotentialAction/FitCompoundPotentialAction.cpp
===================================================================
--- src/Actions/PotentialAction/FitCompoundPotentialAction.cpp	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ src/Actions/PotentialAction/FitCompoundPotentialAction.cpp	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -96,4 +96,5 @@
       graph,
       params.training_file.get(),
+      params.max_iterations.get(),
       params.threshold.get(),
       params.best_of_howmany.get());
Index: src/Actions/PotentialAction/FitCompoundPotentialAction.def
===================================================================
--- src/Actions/PotentialAction/FitCompoundPotentialAction.def	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ src/Actions/PotentialAction/FitCompoundPotentialAction.def	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -23,14 +23,15 @@
 // ValueStorage by the token "Z" -> first column: int, Z, "Z"
 // "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
-#define paramtypes (boost::filesystem::path)(std::vector<const element *>)(unsigned int)(double)
-#define paramtokens ("training-file")("fragment-charges")("take-best-of")("set-threshold")
-#define paramdescriptions ("optional file to write training data to")("charges specifying the fragment")("take the best among this many approximations")("Require L2 error to be smaller than threshold, overrides number of attempts")
-#define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(PARAM_DEFAULT(3))(PARAM_DEFAULT(1.))
-#define paramreferences (training_file)(fragment)(best_of_howmany)(threshold)
+#define paramtypes (boost::filesystem::path)(std::vector<const element *>)(unsigned int)(double)(unsigned int)
+#define paramtokens ("training-file")("fragment-charges")("take-best-of")("set-threshold")("set-max-iterations")
+#define paramdescriptions ("optional file to write training data to")("charges specifying the fragment")("take the best among this many approximations")("Require L2 error to be smaller than threshold, overrides number of attempts")("sets the maximum number of iterations spent on the optimization of parameters")
+#define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(PARAM_DEFAULT(3))(PARAM_DEFAULT(1.))(PARAM_DEFAULT(100))
+#define paramreferences (training_file)(fragment)(best_of_howmany)(threshold)(max_iterations)
 #define paramvalids \
 (DummyValidator<boost::filesystem::path>()) \
 (STLVectorValidator< std::vector<const element *> >(1,99, ElementValidator())) \
 (PositiveValidator<unsigned int>()) \
-(PositiveValidator<double>())
+(PositiveValidator<double>()) \
+(PositiveValidator<unsigned int>())
 
 #undef statetypes
Index: src/Actions/PotentialAction/FitPotentialAction.cpp
===================================================================
--- src/Actions/PotentialAction/FitPotentialAction.cpp	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ src/Actions/PotentialAction/FitPotentialAction.cpp	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -147,4 +147,5 @@
       graph,
       params.training_file.get(),
+      params.max_iterations.get(),
       params.threshold.get(),
       params.best_of_howmany.get());
Index: src/Actions/PotentialAction/FitPotentialAction.def
===================================================================
--- src/Actions/PotentialAction/FitPotentialAction.def	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ src/Actions/PotentialAction/FitPotentialAction.def	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -23,9 +23,9 @@
 // ValueStorage by the token "Z" -> first column: int, Z, "Z"
 // "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
-#define paramtypes (boost::filesystem::path)(std::string)(std::vector<const element *>)(std::vector<const element *>)(unsigned int)(double)
-#define paramtokens ("training-file")("potential-type")("potential-charges")("fragment-charges")("take-best-of")("set-threshold")
-#define paramdescriptions ("optional file to write training data to")("potential type to fit")("charges specifying the potential")("charges specifying the fragment")("take the best among this many approximations")("Require L2 error to be smaller than threshold, overrides number of attempts")
-#define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(NOPARAM_DEFAULT)(NOPARAM_DEFAULT)(PARAM_DEFAULT(3))(PARAM_DEFAULT(1.))
-#define paramreferences (training_file)(potentialtype)(charges)(fragment)(best_of_howmany)(threshold)
+#define paramtypes (boost::filesystem::path)(std::string)(std::vector<const element *>)(std::vector<const element *>)(unsigned int)(double)(unsigned int)
+#define paramtokens ("training-file")("potential-type")("potential-charges")("fragment-charges")("take-best-of")("set-threshold")("set-max-iterations")
+#define paramdescriptions ("optional file to write training data to")("potential type to fit")("charges specifying the potential")("charges specifying the fragment")("take the best among this many approximations")("Require L2 error to be smaller than threshold, overrides number of attempts")("sets the maximum number of iterations spent on the optimization of parameters")
+#define paramdefaults (PARAM_DEFAULT(""))(NOPARAM_DEFAULT)(NOPARAM_DEFAULT)(NOPARAM_DEFAULT)(PARAM_DEFAULT(3))(PARAM_DEFAULT(1.))(PARAM_DEFAULT(100))
+#define paramreferences (training_file)(potentialtype)(charges)(fragment)(best_of_howmany)(threshold)(max_iterations)
 #define paramvalids \
 (DummyValidator<boost::filesystem::path>()) \
@@ -34,5 +34,6 @@
 (STLVectorValidator< std::vector<const element *> >(1,99, ElementValidator())) \
 (PositiveValidator<unsigned int>()) \
-(PositiveValidator<double>())
+(PositiveValidator<double>()) \
+(PositiveValidator<unsigned int>())
 
 #undef statetypes
Index: src/FunctionApproximation/FunctionApproximation.cpp
===================================================================
--- src/FunctionApproximation/FunctionApproximation.cpp	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ src/FunctionApproximation/FunctionApproximation.cpp	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -57,8 +57,10 @@
     const TrainingData &_data,
     FunctionModel &_model,
-    const double _precision) :
+    const double _precision,
+    const unsigned int _maxiterations) :
     input_dimension(_data.getTrainingInputs().size()),
     output_dimension(_data.getTrainingOutputs().size()),
     precision(_precision),
+    maxiterations(_maxiterations),
     input_data(_data.getTrainingInputs()),
     output_data(_data.getTrainingOutputs()),
@@ -196,10 +198,10 @@
         ret=dlevmar_bc_dif(
             &FunctionApproximation::LevMarCallback,
-            p, x, m, n, lb, ub, NULL, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
+            p, x, m, n, lb, ub, NULL, 100, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
       } else if (mode == ParameterDerivative) {
         ret=dlevmar_bc_der(
             &FunctionApproximation::LevMarCallback,
             &FunctionApproximation::LevMarDerivativeCallback,
-            p, x, m, n, lb, ub, NULL, 1000, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
+            p, x, m, n, lb, ub, NULL, 100, opts, info, work, covar, this); // no Jacobian, caller allocates work memory, covariance estimated
       } else {
         ASSERT(0, "FunctionApproximation::operator() - Unknown jacobian method chosen.");
Index: src/FunctionApproximation/FunctionApproximation.hpp
===================================================================
--- src/FunctionApproximation/FunctionApproximation.hpp	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ src/FunctionApproximation/FunctionApproximation.hpp	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -81,9 +81,11 @@
    * \param _model FunctionModel to use in approximation
    * \param _precision desired precision of fit
+   * \param _maxiterations maximum number of iterations for LevMar's optimization
    */
   FunctionApproximation(
       const TrainingData &_data,
       FunctionModel &_model,
-      const double _precision);
+      const double _precision,
+      const unsigned int _maxiterations);
 
   /** Constructor of the class FunctionApproximation.
@@ -97,9 +99,11 @@
       const size_t &_output_dimension,
       FunctionModel &_model,
-      const double _precision) :
+      const double _precision,
+      const unsigned int _maxiterations) :
     input_dimension(_input_dimension),
     output_dimension(_output_dimension),
-    model(_model),
-    precision(_precision)
+    precision(_precision),
+    maxiterations(_maxiterations),
+    model(_model)
   {}
   /** Destructor for class FunctionApproximation.
@@ -197,4 +201,6 @@
   //!> desired precision given to LevMar
   const double precision;
+  //!> maximum number of iterations for LevMar
+  const unsigned int maxiterations;
 
   //!> current input set of training data
Index: src/Potentials/PotentialTrainer.cpp
===================================================================
--- src/Potentials/PotentialTrainer.cpp	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ src/Potentials/PotentialTrainer.cpp	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -71,4 +71,5 @@
     const HomologyGraph &_graph,
     const boost::filesystem::path &_trainingfile,
+    const unsigned int _maxiterations,
     const double _threshold,
     const unsigned int _best_of_howmany) const
@@ -120,5 +121,5 @@
       ELOG(2, "threshold parameter always overrules max_runs, both are specified.");
     // now perform the function approximation by optimizing the model function
-    FunctionApproximation approximator(data, *model, _threshold);
+    FunctionApproximation approximator(data, *model, _threshold, _maxiterations);
     if (model->isBoxConstraint() && approximator.checkParameterDerivatives()) {
       double l2error = std::numeric_limits<double>::max();
Index: src/Potentials/PotentialTrainer.hpp
===================================================================
--- src/Potentials/PotentialTrainer.hpp	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ src/Potentials/PotentialTrainer.hpp	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -36,4 +36,5 @@
         const HomologyGraph &_graph,
         const boost::filesystem::path &_trainingfile,
+        const unsigned int _maxiterations,
         const double _threshold,
         const unsigned int _best_of_howmany) const;
Index: tests/Python/AllActions/options.dat
===================================================================
--- tests/Python/AllActions/options.dat	(revision b8f2eaf14d7c6a6b31dcd5b85abd1ba743a81e94)
+++ tests/Python/AllActions/options.dat	(revision b40690bfddf335b2e572dfb6c23adfe8588d60ed)
@@ -198,4 +198,5 @@
 session-type	"cli"
 set-boundary-conditions	"Wrap, Wrap, Wrap"
+set-max-iterations	"10"
 set-parser-parameters	"basis = 4-31G"
 set-parser-parameters	"basis = 4-31G;maxiter=499;theory=CLKS;"
