diff --git a/src/somd2/config/_config.py b/src/somd2/config/_config.py index 181a051..dc3d370 100644 --- a/src/somd2/config/_config.py +++ b/src/somd2/config/_config.py @@ -127,6 +127,7 @@ def __init__( somd1_compatibility=False, pert_file=None, save_energy_components=False, + timeout="300s", ): """ Constructor. @@ -301,6 +302,9 @@ def __init__( save_energy_components: bool Whether to save the energy contribution for each force when checkpointing. This is useful when debugging crashes. + + timeout: str + Timeout for the minimiser. """ # Setup logger before doing anything else @@ -350,6 +354,7 @@ def __init__( self.somd1_compatibility = somd1_compatibility self.pert_file = pert_file self.save_energy_components = save_energy_components + self.timeout = timeout self.write_config = write_config @@ -1267,6 +1272,29 @@ def save_energy_components(self, save_energy_components): raise ValueError("'save_energy_components' must be of type 'bool'") self._save_energy_components = save_energy_components + @property + def timeout(self): + return self._timeout + + @timeout.setter + def timeout(self, timeout): + if not isinstance(timeout, str): + raise TypeError("'timeout' must be of type 'str'") + + from sire.units import second + + try: + t = _sr.u(timeout) + except: + raise ValueError( + f"Unable to parse 'timeout' as a Sire GeneralUnit: {timeout}" + ) + + if t.value() != 0 and not t.has_same_units(second): + raise ValueError("'timeout' units are invalid.") + + self._timeout = t + @property def output_directory(self): return self._output_directory diff --git a/src/somd2/runner/_dynamics.py b/src/somd2/runner/_dynamics.py index b2a7afb..bb82464 100644 --- a/src/somd2/runner/_dynamics.py +++ b/src/somd2/runner/_dynamics.py @@ -256,7 +256,7 @@ def _minimisation( shift_delta=self._config.shift_delta, map=self._config._extra_args, ) - m.run() + m.run(timeout=self._config.timeout) self._system = m.commit() except: raise @@ -280,7 +280,7 @@ def _minimisation( shift_delta=self._config.shift_delta, map=self._config._extra_args, ) - m.run() + m.run(timeout=self._config.timeout) self._system = m.commit() except: raise