From fd9206bd7edbc4b8e778ea9ca6e50e99b3375c9a Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Mon, 20 Apr 2015 13:18:52 +0200
Subject: [PATCH] allow to generate simulation without attaching an integrator
 to the settings object.

In many cases the user might only want to minimize a structure,
an integrator is therefore useless. To make OpenMM happy, a
dummy integrator (Verlet integrator with timestep 1fs) is
attached to the settings object and simulation in these cases.
---
 modules/mol/mm/src/simulation.cc        | 9 ++++++---
 modules/mol/mm/tests/test_simulation.cc | 3 ---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/modules/mol/mm/src/simulation.cc b/modules/mol/mm/src/simulation.cc
index 4e0fcece9..7f10f6c39 100644
--- a/modules/mol/mm/src/simulation.cc
+++ b/modules/mol/mm/src/simulation.cc
@@ -253,10 +253,13 @@ void Simulation::Init(const TopologyPtr top,
 
 
   top_ = top;
-  integrator_ = settings->integrator;
-  if(!integrator_){
-    throw ost::Error("Settings must have a valid integrator attached to set up a simulation!");
+
+  if(!settings->integrator){
+    //user did not specify an integrator, so let's just use a standard integrator
+    settings->integrator = IntegratorPtr(new OpenMM::VerletIntegrator(0.001));
   }
+  integrator_ = settings->integrator;
+
   system_ = SystemCreator::Create(top_,settings,system_force_mapper_); 
 
   //setting up the context, which combines the system with an integrator
diff --git a/modules/mol/mm/tests/test_simulation.cc b/modules/mol/mm/tests/test_simulation.cc
index f5da8757e..f0e362e4b 100644
--- a/modules/mol/mm/tests/test_simulation.cc
+++ b/modules/mol/mm/tests/test_simulation.cc
@@ -42,9 +42,6 @@ BOOST_AUTO_TEST_CASE(test_simulation_basics){
   top->AddHarmonicPositionRestraint(1,geom::Vec3(0.0,0.0,0.0),10.0);
   top->AddHarmonicDistanceRestraint(1,2,10.0,10.0);
 
-  //try to set up simulation without an integrator
-  BOOST_CHECK_THROW(Simulation sim(test_ent,settings),ost::Error);
-
   settings->integrator = IntegratorPtr(new OpenMM::VerletIntegrator(0.002));
 
   Simulation sim(top, test_ent, settings);
-- 
GitLab