-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from openforcefield/issue-188
Added validation guardrail for AlchemicalNetworks with self-Transformations
- Loading branch information
Showing
5 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pytest | ||
|
||
from openfe_benchmarks import tyk2 | ||
from gufe import ChemicalSystem, Transformation, AlchemicalNetwork | ||
from gufe.tests.test_protocol import DummyProtocol, BrokenProtocol | ||
|
||
from alchemiscale import validators | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def network_self_transformation(): | ||
tyk2s = tyk2.get_system() | ||
ligand = tyk2s.ligand_components[0] | ||
|
||
cs = ChemicalSystem( | ||
components={"ligand": ligand, "solvent": tyk2s.solvent_component}, | ||
name=f"{ligand.name}_water", | ||
) | ||
|
||
tf = Transformation( | ||
stateA=cs, | ||
stateB=cs, | ||
protocol=DummyProtocol(settings=DummyProtocol.default_settings()), | ||
name=f"{ligand.name}->{ligand.name}_water", | ||
) | ||
|
||
return AlchemicalNetwork(edges=[tf], name="self_transformation") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def network_nonself_transformation(): | ||
tyk2s = tyk2.get_system() | ||
ligand = tyk2s.ligand_components[0] | ||
ligand2 = tyk2s.ligand_components[1] | ||
|
||
cs = ChemicalSystem( | ||
components={"ligand": ligand, "solvent": tyk2s.solvent_component}, | ||
name=f"{ligand.name}_water", | ||
) | ||
|
||
cs2 = ChemicalSystem( | ||
components={"ligand": ligand2, "solvent": tyk2s.solvent_component}, | ||
name=f"{ligand2.name}_water", | ||
) | ||
|
||
tf = Transformation( | ||
stateA=cs, | ||
stateB=cs2, | ||
protocol=DummyProtocol(settings=DummyProtocol.default_settings()), | ||
name=f"{ligand.name}->{ligand2.name}_water", | ||
) | ||
|
||
return AlchemicalNetwork(edges=[tf], name="nonself_transformation") | ||
|
||
|
||
def test_validate_network_nonself( | ||
network_self_transformation, network_nonself_transformation | ||
): | ||
with pytest.raises(ValueError, match="uses the same `ChemicalSystem`"): | ||
validators.validate_network_nonself(network_self_transformation) | ||
|
||
out = validators.validate_network_nonself(network_nonself_transformation) | ||
|
||
assert out is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
:mod:`alchemiscale.validators` --- validation guardrails for user input | ||
======================================================================= | ||
""" | ||
|
||
from gufe import AlchemicalNetwork, Transformation | ||
|
||
|
||
def validate_network_nonself(network: AlchemicalNetwork): | ||
"""Check that the given AlchemicalNetwork features no Transformations with | ||
the same ChemicalSystem for its two states. | ||
A ``ValueError`` is raised if a `Transformation` is detected. | ||
""" | ||
for transformation in network.edges: | ||
if transformation.stateA == transformation.stateB: | ||
raise ValueError( | ||
f"`Transformation` '{transformation.key}' uses the same `ChemicalSystem` '{transformation.stateA.key}' for both states; " | ||
"this is currently not supported in `alchemiscale`" | ||
) |