From 58ce1a4fb4c831d3939ea12b970af0687c21202f Mon Sep 17 00:00:00 2001 From: Josh Horton Date: Thu, 12 Dec 2024 16:03:42 +0000 Subject: [PATCH 1/4] make sure the cofactor is in the transformation --- .../tests/commands/test_plan_rbfe_network.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/openfecli/tests/commands/test_plan_rbfe_network.py b/openfecli/tests/commands/test_plan_rbfe_network.py index 2fc4a9947..f05b6d047 100644 --- a/openfecli/tests/commands/test_plan_rbfe_network.py +++ b/openfecli/tests/commands/test_plan_rbfe_network.py @@ -2,7 +2,6 @@ import pytest from importlib import resources -import os import shutil from click.testing import CliRunner @@ -10,6 +9,9 @@ plan_rbfe_network, plan_rbfe_network_main, ) +from gufe import AlchemicalNetwork +from gufe.tokenization import JSON_HANDLER +import json @pytest.fixture(scope='session') @@ -148,6 +150,17 @@ def test_plan_rbfe_network_cofactors(eg5_files): print(result.output) assert result.exit_code == 0 + # make sure the cofactor is in the transformations + network = AlchemicalNetwork.from_dict( + json.load(open("alchemicalNetwork/alchemicalNetwork.json"), cls=JSON_HANDLER.decoder) + ) + for edge in network.edges: + if "protein" in edge.stateA.components: + assert "cofactor1" in edge.stateA.components + assert "cofactor1" in edge.stateB.components + else: + assert "cofactor1" not in edge.stateA.components + assert "cofactor1" not in edge.stateB.components @pytest.fixture From d8fc66eecb5fcf4dba6c5d0c690663bf99fe4ee2 Mon Sep 17 00:00:00 2001 From: Josh Horton Date: Thu, 12 Dec 2024 16:25:15 +0000 Subject: [PATCH 2/4] fix cofactor name --- .../chemicalsystem_generator/easy_chemicalsystem_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py b/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py index 2b5907dc8..36c03b15a 100644 --- a/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py +++ b/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py @@ -112,7 +112,7 @@ def __call__( RFEComponentLabels.PROTEIN: self.protein, } for i, c in enumerate(self.cofactors): - components.update({f'{RFEComponentLabels.COFACTOR}{i+1}': c}) + components.update({f'{RFEComponentLabels.COFACTOR.value}{i+1}': c}) if self.solvent is not None: components.update({RFEComponentLabels.SOLVENT: self.solvent}) chem_sys = ChemicalSystem( From fe198adfc16c83f4fdab8577eca6178e6a0cb26f Mon Sep 17 00:00:00 2001 From: Josh Horton Date: Tue, 7 Jan 2025 10:11:19 +0000 Subject: [PATCH 3/4] use value in enum, add cofactor chemical system generator test --- .../easy_chemicalsystem_generator.py | 12 ++++++------ .../component_checks.py | 4 ++++ .../test_easy_chemicalsystem_generator.py | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py b/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py index 36c03b15a..829a41b4f 100644 --- a/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py +++ b/openfe/setup/chemicalsystem_generator/easy_chemicalsystem_generator.py @@ -90,7 +90,7 @@ def __call__( if self.do_vacuum: chem_sys = ChemicalSystem( - components={RFEComponentLabels.LIGAND: component}, + components={RFEComponentLabels.LIGAND.value: component}, name=component.name + "_vacuum", ) yield chem_sys @@ -98,8 +98,8 @@ def __call__( if self.solvent is not None: chem_sys = ChemicalSystem( components={ - RFEComponentLabels.LIGAND: component, - RFEComponentLabels.SOLVENT: self.solvent, + RFEComponentLabels.LIGAND.value: component, + RFEComponentLabels.SOLVENT.value: self.solvent, }, name=component.name + "_solvent", ) @@ -108,13 +108,13 @@ def __call__( components: dict[str, Component] if self.protein is not None: components = { - RFEComponentLabels.LIGAND: component, - RFEComponentLabels.PROTEIN: self.protein, + RFEComponentLabels.LIGAND.value: component, + RFEComponentLabels.PROTEIN.value: self.protein, } for i, c in enumerate(self.cofactors): components.update({f'{RFEComponentLabels.COFACTOR.value}{i+1}': c}) if self.solvent is not None: - components.update({RFEComponentLabels.SOLVENT: self.solvent}) + components.update({RFEComponentLabels.SOLVENT.value: self.solvent}) chem_sys = ChemicalSystem( components=components, name=component.name + "_complex" ) diff --git a/openfe/tests/setup/chemicalsystem_generator/component_checks.py b/openfe/tests/setup/chemicalsystem_generator/component_checks.py index cfea082ce..6b703a346 100644 --- a/openfe/tests/setup/chemicalsystem_generator/component_checks.py +++ b/openfe/tests/setup/chemicalsystem_generator/component_checks.py @@ -14,3 +14,7 @@ def solventC_in_chem_sys(chemical_system: ChemicalSystem) -> bool: def proteinC_in_chem_sys(chemical_system: ChemicalSystem) -> bool: return RFEComponentLabels.PROTEIN in chemical_system.components + +def cofactorC_in_chem_sys(chemical_system: ChemicalSystem) -> bool: + # cofactors are numbered from 1 + return f"{RFEComponentLabels.COFACTOR.value}1" in chemical_system.components diff --git a/openfe/tests/setup/chemicalsystem_generator/test_easy_chemicalsystem_generator.py b/openfe/tests/setup/chemicalsystem_generator/test_easy_chemicalsystem_generator.py index bf706923f..29dc074a9 100644 --- a/openfe/tests/setup/chemicalsystem_generator/test_easy_chemicalsystem_generator.py +++ b/openfe/tests/setup/chemicalsystem_generator/test_easy_chemicalsystem_generator.py @@ -11,7 +11,7 @@ from ...conftest import T4_protein_component from gufe import SolventComponent -from .component_checks import proteinC_in_chem_sys, solventC_in_chem_sys, ligandC_in_chem_sys +from .component_checks import proteinC_in_chem_sys, solventC_in_chem_sys, ligandC_in_chem_sys, cofactorC_in_chem_sys def test_easy_chemical_system_generator_init(T4_protein_component): @@ -55,7 +55,6 @@ def test_build_solvent_chemical_system(ethane): def test_build_protein_chemical_system(ethane, T4_protein_component): - # TODO: cofactors with eg5 system chem_sys_generator = EasyChemicalSystemGenerator( protein=T4_protein_component, ) @@ -66,6 +65,21 @@ def test_build_protein_chemical_system(ethane, T4_protein_component): assert proteinC_in_chem_sys(chem_sys) assert not solventC_in_chem_sys(chem_sys) assert ligandC_in_chem_sys(chem_sys) + assert not cofactorC_in_chem_sys(chem_sys) + +def test_build_cofactor_chemical_system(eg5_cofactor, eg5_ligands, eg5_protein): + chem_sys_generator = EasyChemicalSystemGenerator( + cofactors=[eg5_cofactor], protein=eg5_protein + ) + chem_sys = next(chem_sys_generator(eg5_ligands[0])) + + assert chem_sys is not None + assert isinstance(chem_sys, ChemicalSystem) + assert proteinC_in_chem_sys(chem_sys) + assert not solventC_in_chem_sys(chem_sys) + assert ligandC_in_chem_sys(chem_sys) + assert cofactorC_in_chem_sys(chem_sys) + def test_build_hydr_scenario_chemical_systems(ethane): @@ -91,7 +105,6 @@ def test_build_binding_scenario_chemical_systems(ethane, T4_protein_component): assert len(chem_syss) == 2 assert all([isinstance(chem_sys, ChemicalSystem) for chem_sys in chem_syss]) - print(chem_syss) assert [proteinC_in_chem_sys(chem_sys) for chem_sys in chem_syss] == [False, True] assert [solventC_in_chem_sys(chem_sys) for chem_sys in chem_syss] == [True, True] assert [ligandC_in_chem_sys(chem_sys) for chem_sys in chem_syss] == [True, True] From 653a752487db09105cba234798a42fc2959e2a4d Mon Sep 17 00:00:00 2001 From: Josh Horton Date: Tue, 7 Jan 2025 10:32:43 +0000 Subject: [PATCH 4/4] remove print from test --- openfecli/tests/commands/test_plan_rbfe_network.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openfecli/tests/commands/test_plan_rbfe_network.py b/openfecli/tests/commands/test_plan_rbfe_network.py index b3d9ae495..25b703811 100644 --- a/openfecli/tests/commands/test_plan_rbfe_network.py +++ b/openfecli/tests/commands/test_plan_rbfe_network.py @@ -147,8 +147,6 @@ def test_plan_rbfe_network_cofactors(eg5_files): with runner.isolated_filesystem(): result = runner.invoke(plan_rbfe_network, args) - print(result.output) - assert result.exit_code == 0 # make sure the cofactor is in the transformations network = AlchemicalNetwork.from_dict(