diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index 69099423e..a2b39cab0 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -21,8 +21,12 @@ organisation on `GitHub `__. * Fix ``delta`` parameter in soft-core Coulomb potential. +* When possible, use the ``SOMD2`` logger for dynamics warnings. + * Fix recursion bug in :func:`sire.base.wrap()` function. +* Fix :meth:`Dynamics.get_rest2_scale()` method. + `2025.3.0 `__ - November 2025 --------------------------------------------------------------------------------------------- diff --git a/src/sire/mol/_dynamics.py b/src/sire/mol/_dynamics.py index c82bd6465..3e6e2dfb0 100644 --- a/src/sire/mol/_dynamics.py +++ b/src/sire/mol/_dynamics.py @@ -304,6 +304,14 @@ def __init__(self, mols=None, map=None, **kwargs): else: self._pressure = None + # Try importing the SOMD2 logger. + try: + from somd2 import _logger as somd2_logger + + self._somd2_logger = somd2_logger + except: + self._somd2_logger = None + def is_null(self): return self._sire_mols is None @@ -754,6 +762,15 @@ def integrator(self): else: return self._omm_mols.getIntegrator() + def get_rest2_scale(self): + """ + Return the current REST2 scaling factor. + """ + if self.is_null(): + return None + else: + return self._omm_mols.get_rest2_scale() + def info(self): if self.is_null(): return None @@ -953,14 +970,19 @@ def _rebuild_and_minimise(self): from ..utils import Console - Console.warning( + msg = ( "Something went wrong when running dynamics. The system will be " "minimised, and then dynamics will be attempted again. If an " "error still occurs, then it is likely that the step size is too " "large, the molecules are over-constrained, or there is something " - "more fundemental going wrong..." + "more fundamental going wrong..." ) + if self._somd2_logger is not None: + self._somd2_logger.warning(msg) + else: + Console.warning(msg) + # rebuild the molecules from ..convert import to @@ -1909,16 +1931,8 @@ def get_rest2_scale(self): """ Return the current REST2 scaling factor. """ - if self.is_null(): - return None return self._d.get_rest2_scale() - def set_rest2_scale(self, rest2_scale: float): - """ - Set the current REST2 scaling factor. - """ - self._d.set_rest2_scale(rest2_scale=rest2_scale) - def ensemble(self): """ Return the ensemble in which the simulation is being performed