From 94eded67eaa697b9d9aec21dd56384d901377b5f Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Thu, 10 Feb 2022 20:19:36 +0100
Subject: [PATCH] Add kwargs to modelling.MinimizeModelEnergy

Add tolerance values that are passed to the according SD/LBFGS minimizers
---
 modelling/pymod/_pipeline.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/modelling/pymod/_pipeline.py b/modelling/pymod/_pipeline.py
index 8b79f214..db7fc2ad 100644
--- a/modelling/pymod/_pipeline.py
+++ b/modelling/pymod/_pipeline.py
@@ -256,7 +256,8 @@ def BuildSidechains(mhandle, merge_distance=4, fragment_db=None,
 
 def MinimizeModelEnergy(mhandle, max_iterations=12, max_iter_sd=20,
                         max_iter_lbfgs=10, use_amber_ff=False,
-                        extra_force_fields=list()):
+                        extra_force_fields=list(),
+                        tolerance_sd=1.0, tolerance_lbfgs=1.0):
     '''Minimize energy of final model using molecular mechanics.
 
     Uses :mod:`ost.mol.mm` to perform energy minimization.
@@ -291,6 +292,14 @@ def MinimizeModelEnergy(mhandle, max_iterations=12, max_iter_sd=20,
     :param max_iter_lbfgs: Max. number of iterations within LBFGS method
     :type max_iter_lbfgs:  :class:`int`
 
+    :param tolerance_sd: Tolerance parameter passed to ApplySD of 
+                         :class:`ost.mol.mm.Simulation` object.
+    :type tolerance_sd: :class:`float`
+
+    :param tolerance_lbfgs: Tolerance parameter passed to ApplyLBFGS of 
+                            :class:`ost.mol.mm.Simulation` object.
+    :type tolerance_lbfgs:  :class:`float`
+
     :param use_amber_ff: if True, use the AMBER force field instead of the def.
                          CHARMM one (see :meth:`BuildFromRawModel`).
     :type use_amber_ff:  :class:`bool`
@@ -335,8 +344,8 @@ def MinimizeModelEnergy(mhandle, max_iterations=12, max_iter_sd=20,
         ost.LogInfo("Perform energy minimization "
                     "(iteration %d, energy: %g)" % (i+1, cur_energy))
         try:
-            sim.ApplySD(tolerance = 1.0, max_iterations = max_iter_sd)
-            sim.ApplyLBFGS(tolerance = 1.0, max_iterations = max_iter_lbfgs)
+            sim.ApplySD(tolerance = tolerance_sd, max_iterations = max_iter_sd)
+            sim.ApplyLBFGS(tolerance = tolerance_lbfgs, max_iterations = max_iter_lbfgs)
             sim.UpdatePositions()
         except Exception as ex:
             # ABORT ON FAIL
-- 
GitLab