Skip to content

Commit

Permalink
Merge pull request #123 from cbc-univie/moving_function
Browse files Browse the repository at this point in the history
Another Cleanup
  • Loading branch information
JohannesKarwou authored Jan 18, 2024
2 parents 170802a + 9ff54d4 commit 96417e1
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 109 deletions.
72 changes: 0 additions & 72 deletions transformato/mutate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2240,75 +2240,3 @@ def _modify_type(atom, psf, atom_type_suffix: str):
new_type = f"{atom_type_suffix}{psf.mutations_to_default}"

atom.type = new_type


def mutate_pure_tautomers(
s1_to_s2: ProposeMutationRoute,
system1: SystemStructure,
system2: SystemStructure,
configuration,
single_state=False,
nr_of_bonded_windows: int = 4,
):
from transformato import (
IntermediateStateFactory,
)

# setup mutation and StateFactory
mutation_list = s1_to_s2.generate_mutations_to_common_core_for_mol1()
i_tautomer1 = IntermediateStateFactory(
system=system1,
configuration=configuration,
)

# write out states
# start with charge
charges = mutation_list["charge"]
for lambda_value in np.linspace(1, 0, 2):
# turn off charges
i_tautomer1.write_state(
mutation_conf=charges,
lambda_value_electrostatic=lambda_value,
)
if single_state:
return (i_tautomer1.output_files, [])

# turn off the lj of the hydrogen
lj = mutation_list["lj"]
i_tautomer1.write_state(
mutation_conf=lj,
lambda_value_vdw=0.0,
)

# transform common core
for lambda_value in np.linspace(1, 0, nr_of_bonded_windows + 1)[1:]:
# turn off charges
i_tautomer1.write_state(
mutation_conf=mutation_list["transform"],
common_core_transformation=lambda_value,
)

# setup other tautomer
mutation_list = s1_to_s2.generate_mutations_to_common_core_for_mol2()
i_tautomer2 = IntermediateStateFactory(
system=system2,
configuration=configuration,
)
# write out states
# start with charge
charges = mutation_list["charge"]
for lambda_value in np.linspace(1, 0, 2):
# turn off charges
i_tautomer2.write_state(
mutation_conf=charges,
lambda_value_electrostatic=lambda_value,
)

# turn off the lj of the hydrogen
lj = mutation_list["lj"]
i_tautomer2.write_state(
mutation_conf=lj,
lambda_value_vdw=0.0,
)

return (i_tautomer1.output_files, i_tautomer2.output_files)
31 changes: 0 additions & 31 deletions transformato/tests/test_alchemical_path_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,6 @@ def test_generate_alchemical_path_acetylaceton_methyl_common_core():
mutate_acetylaceton_methyl_common_core(configuration=configuration)


@pytest.mark.rbfe
def test_rbfe_mutate_2oj9():
from transformato import ProposeMutationRoute, SystemStructure, load_config_yaml

from ..mutate import mutate_pure_tautomers

conf = f"{get_testsystems_dir()}/config/test-2oj9-tautomer-pair-rbfe.yaml"

configuration = load_config_yaml(
config=conf,
input_dir=get_testsystems_dir(),
output_dir=get_test_output_dir(),
)

s1 = SystemStructure(configuration, "structure1")
s2 = SystemStructure(configuration, "structure2")
s1_to_s2 = ProposeMutationRoute(s1, s2)
s1_to_s2.calculate_common_core()
return (
mutate_pure_tautomers(
s1_to_s2,
s1,
s2,
configuration,
nr_of_bonded_windows=4,
),
configuration,
s1_to_s2,
)


@pytest.mark.rsfe
def test_generate_alchemical_path_for_acetylacetone_tautomer_pair(caplog):
caplog.set_level(logging.WARNING)
Expand Down
105 changes: 99 additions & 6 deletions transformato/tests/test_mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,78 @@
)


def mutate_pure_tautomers(
s1_to_s2: ProposeMutationRoute,
system1: SystemStructure,
system2: SystemStructure,
configuration,
single_state=False,
nr_of_bonded_windows: int = 4,
):
from transformato import (
IntermediateStateFactory,
)

# setup mutation and StateFactory
mutation_list = s1_to_s2.generate_mutations_to_common_core_for_mol1()
i_tautomer1 = IntermediateStateFactory(
system=system1,
configuration=configuration,
)

# write out states
# start with charge
charges = mutation_list["charge"]
for lambda_value in np.linspace(1, 0, 2):
# turn off charges
i_tautomer1.write_state(
mutation_conf=charges,
lambda_value_electrostatic=lambda_value,
)
if single_state:
return (i_tautomer1.output_files, [])

# turn off the lj of the hydrogen
lj = mutation_list["lj"]
i_tautomer1.write_state(
mutation_conf=lj,
lambda_value_vdw=0.0,
)

# transform common core
for lambda_value in np.linspace(1, 0, nr_of_bonded_windows + 1)[1:]:
# turn off charges
i_tautomer1.write_state(
mutation_conf=mutation_list["transform"],
common_core_transformation=lambda_value,
)

# setup other tautomer
mutation_list = s1_to_s2.generate_mutations_to_common_core_for_mol2()
i_tautomer2 = IntermediateStateFactory(
system=system2,
configuration=configuration,
)
# write out states
# start with charge
charges = mutation_list["charge"]
for lambda_value in np.linspace(1, 0, 2):
# turn off charges
i_tautomer2.write_state(
mutation_conf=charges,
lambda_value_electrostatic=lambda_value,
)

# turn off the lj of the hydrogen
lj = mutation_list["lj"]
i_tautomer2.write_state(
mutation_conf=lj,
lambda_value_vdw=0.0,
)

return (i_tautomer1.output_files, i_tautomer2.output_files)


def read_params(output_file_base):
extlist = ["rtf", "prm", "str"]
print(output_file_base)
Expand Down Expand Up @@ -97,8 +169,6 @@ def generate_system(output_file_base, env):
def setup_acetylacetone_tautomer_pair(
configuration: dict, single_state=False, nr_of_bonded_windows=4
):
from ..mutate import mutate_pure_tautomers

s1 = SystemStructure(configuration, "structure1")
s2 = SystemStructure(configuration, "structure2")
s1_to_s2 = ProposeMutationRoute(s1, s2)
Expand Down Expand Up @@ -382,6 +452,33 @@ def test_mutation_with_multiple_dummy_regions(caplog):
s1_to_s2.finish_common_core()


@pytest.mark.rbfe
def test_rbfe_mutate_2oj9():
conf = f"{get_testsystems_dir()}/config/test-2oj9-tautomer-pair-rbfe.yaml"

configuration = load_config_yaml(
config=conf,
input_dir=get_testsystems_dir(),
output_dir=get_test_output_dir(),
)

s1 = SystemStructure(configuration, "structure1")
s2 = SystemStructure(configuration, "structure2")
s1_to_s2 = ProposeMutationRoute(s1, s2)
s1_to_s2.calculate_common_core()
return (
mutate_pure_tautomers(
s1_to_s2,
s1,
s2,
configuration,
nr_of_bonded_windows=4,
),
configuration,
s1_to_s2,
)


@pytest.mark.rsfe
@pytest.mark.skipif(
os.getenv("CI") == "true",
Expand Down Expand Up @@ -1833,8 +1930,6 @@ def test_vdw_mutation_for_hydrogens_and_heavy_atoms():
def setup_2OJ9_tautomer_pair_rsfe(
configuration: dict, single_state=False, nr_of_bonded_windows: int = 4
):
from ..mutate import mutate_pure_tautomers

s1 = SystemStructure(configuration, "structure1")
s2 = SystemStructure(configuration, "structure2")
s1_to_s2 = ProposeMutationRoute(s1, s2)
Expand All @@ -1856,8 +1951,6 @@ def setup_2OJ9_tautomer_pair_rsfe(
def setup_2OJ9_tautomer_pair_rbfe(
configuration: dict, single_state: bool = False, nr_of_bonded_windows: int = 4
):
from ..mutate import mutate_pure_tautomers

s1 = SystemStructure(configuration, "structure1")
s2 = SystemStructure(configuration, "structure2")
s1_to_s2 = ProposeMutationRoute(s1, s2)
Expand Down

0 comments on commit 96417e1

Please sign in to comment.