diff --git a/doc/source/changelog.rst b/doc/source/changelog.rst index 1897e07de..bc9f117c1 100644 --- a/doc/source/changelog.rst +++ b/doc/source/changelog.rst @@ -21,6 +21,8 @@ organisation on `GitHub `__. * Fix ``delta`` parameter in soft-core Coulomb potential. +* When possible, use the ``SOMD2`` logger for dynamics warnings. + `2025.3.0 `__ - November 2025 --------------------------------------------------------------------------------------------- diff --git a/src/sire/mol/_dynamics.py b/src/sire/mol/_dynamics.py index c82bd6465..e8171ddbf 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 @@ -953,14 +961,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