Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/openfe/protocols/openmm_septop/equil_septop_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
openfe.protocols.openmm_septop.SepTopProtocol
"""

from typing import Optional
import copy
import warnings
from typing import Any, Optional

import numpy as np
from gufe.settings import (
Expand All @@ -21,7 +23,7 @@
)
from gufe.settings.typing import PicosecondQuantity
from openff.units import unit as offunit
from pydantic import Field, field_validator
from pydantic import Field, field_validator, model_validator

from openfe.protocols.openmm_afe.equil_afe_settings import (
AlchemicalSettings,
Expand Down Expand Up @@ -371,6 +373,35 @@ def must_be_positive(cls, v):
"""
Settings for the Boresch restraint applied to ligand B in the complex.
"""

@model_validator(mode="before")
@classmethod
def allow_legacy_complex_restraint_settings(cls, data: Any) -> Any:
"""
Allow settings with ``complex_restraint_settings`` (pre openfe v1.13)
to be loaded by converting it to ``complex_restraint_settings_A``
and ``complex_restraint_settings_B``.
"""
if (
isinstance(data, dict)
and "complex_restraint_settings" in data
and "complex_restraint_settings_A" not in data
and "complex_restraint_settings_B" not in data
):
Comment thread
atravitz marked this conversation as resolved.
Resolved
wmsg = (
"Loading SepTop settings from `openfe<=1.12` "
"which uses ``complex_restraint_settings``. "
"The values of ``complex_restraint_settings`` have been copied over to "
"``complex_restraint_settings_A`` and ``complex_restraint_settings_B``. "
"This will no longer be supported in openfe v1.14."
)
warnings.warn(wmsg, FutureWarning, stacklevel=2)
data = dict(data)
legacy = data.pop("complex_restraint_settings")
data["complex_restraint_settings_A"] = copy.deepcopy(legacy)
data["complex_restraint_settings_B"] = copy.deepcopy(legacy)
return data

analysis_settings: MultiStateAnalysisSettings = Field(
default_factory=MultiStateAnalysisSettings
)
Expand Down
27 changes: 27 additions & 0 deletions src/openfe/tests/protocols/openmm_septop/test_septop_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
SepTopProtocol,
)
from openfe.protocols.openmm_septop.equil_septop_settings import SepTopSettings
from openfe.protocols.restraint_utils.settings import BoreschRestraintSettings


@pytest.fixture()
Expand Down Expand Up @@ -137,3 +138,29 @@ def test_adaptive_settings_with_protein_membrane(a2a_protein_membrane_component,
assert isinstance(settings, SepTopSettings)
# Barostat should have been updated
assert settings.complex_integrator_settings.barostat == "MonteCarloMembraneBarostat"


def test_legacy_complex_restraint_settings(default_settings):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also make sense to just have a test somewhere that tries to load some legacy serialilzed Protocol?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that could be useful, but maybe not blocking for this PR?

@IAlibay IAlibay Oct 7, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since opening this PR, our aim has changed from "concretely being able to support previous versions" to "just a shim to reduce the amount of work for this release". In that case, my view has changed to the following: adding the regression check isn't worth the time (edit: for a shim) - we can revisit this after the release if our strategy changes.

# Settings created before per-ligand complex restraints were introduced (openfe v1.13)
# used a single `complex_restraint_settings` field
legacy = dict(default_settings)
legacy.pop("complex_restraint_settings_A")
legacy.pop("complex_restraint_settings_B")
legacy["complex_restraint_settings"] = BoreschRestraintSettings(host_selection="name CA")

with pytest.warns(FutureWarning, match="complex_restraint_settings"):
settings = SepTopSettings(**legacy)

assert settings.complex_restraint_settings_A.host_selection == "name CA"
assert settings.complex_restraint_settings_B.host_selection == "name CA"
# A and B must not share the same object
assert settings.complex_restraint_settings_A is not settings.complex_restraint_settings_B


def test_legacy_complex_restraint_settings_mixed(default_settings):
# Mixing the legacy field with the new ones is not allowed
mixed = dict(default_settings)
mixed["complex_restraint_settings"] = BoreschRestraintSettings()

with pytest.raises(ValueError, match="complex_restraint_settings"):
SepTopSettings(**mixed)
Loading