Skip to content

Commit

Permalink
rename mappers to mapper to avoid api break
Browse files Browse the repository at this point in the history
  • Loading branch information
atravitz committed Nov 6, 2024
1 parent db7927e commit bf82085
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 36 deletions.
23 changes: 11 additions & 12 deletions openfe/setup/ligand_network_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def generate_radial_network(
the ligands to arrange around the central ligand. If the central ligand
is present it will be ignored (i.e. avoiding a self edge)
mappers : AtomMapper or iterable of AtomMappers
mapper(s) to use, at least 1 required
mapper(s) to use to construct edges, at least 1 required
central_ligand : SmallMoleculeComponent or str or int
the ligand to use as the hub/central ligand.
If this is a string, this should match to one and only one ligand name.
Expand Down Expand Up @@ -171,9 +171,8 @@ def generate_maximal_network(
----------
ligands : Iterable[SmallMoleculeComponent]
the ligands to include in the LigandNetwork
mapper : AtomMapper or Iterable[AtomMapper]
the AtomMapper(s) to use to propose mappings. At least 1 required,
but many can be given.
mappers : AtomMapper or iterable of AtomMappers
mapper(s) to use to construct edges, at least 1 required
scorer : Scoring function
any callable which takes a LigandAtomMapping and returns a float
progress : Union[bool, Callable[Iterable], Iterable]
Expand Down Expand Up @@ -323,8 +322,8 @@ def generate_network_from_names(
----------
ligands : list of SmallMoleculeComponent
the small molecules to place into the network
mapper: AtomMapper
the atom mapper to use to construct edges
mappers : AtomMapper or iterable of AtomMappers
mapper(s) to use, at least 1 required
names : list of tuples of names
the edges to form where the values refer to names of the small molecules,
eg `[('benzene', 'toluene'), ...]` will create an edge between the
Expand Down Expand Up @@ -365,8 +364,8 @@ def generate_network_from_indices(
----------
ligands : list of SmallMoleculeComponent
the small molecules to place into the network
mapper: AtomMapper
the atom mapper to use to construct edges
mappers : AtomMapper or iterable of AtomMappers
mapper(s) to use to construct edges, at least 1 required
indices : list of tuples of indices
the edges to form where the values refer to names of the small molecules,
eg `[(3, 4), ...]` will create an edge between the 3rd and 4th molecules
Expand Down Expand Up @@ -401,8 +400,8 @@ def load_orion_network(
----------
ligands : list of SmallMoleculeComponent
the small molecules to place into the network
mapper: AtomMapper
the atom mapper to use to construct edges
mappers : AtomMapper or iterable of AtomMappers
mapper(s) to use to construct edges, at least 1 required
network_file : str
path to NES network file.
Expand Down Expand Up @@ -450,8 +449,8 @@ def load_fepplus_network(
----------
ligands : list of SmallMoleculeComponent
the small molecules to place into the network
mapper: AtomMapper
the atom mapper to use to construct edges
mappers : AtomMapper or iterable of AtomMappers
mapper(s) to use to construct edges, at least 1 required
network_file : str
path to edges network file.
Expand Down
48 changes: 24 additions & 24 deletions openfe/tests/setup/test_network_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_radial_network(

network = openfe.setup.ligand_network_planning.generate_radial_network(
ligands=others, central_ligand=toluene,
mappers=mapper, scorer=None,
mapper=mapper, scorer=None,
)
# couple sanity checks
assert len(network.nodes) == len(atom_mapping_basic_test_files)
Expand All @@ -84,7 +84,7 @@ def test_radial_network_int_str(atom_mapping_basic_test_files, toluene_vs_others

network = openfe.setup.ligand_network_planning.generate_radial_network(
ligands=ligands, central_ligand=central_ligand_arg,
mappers=lomap_old_mapper, scorer=None,
mapper=lomap_old_mapper, scorer=None,
)
assert len(network.nodes) == len(ligands)
assert len(network.edges) == len(others)
Expand All @@ -104,7 +104,7 @@ def test_radial_network_bad_str(toluene_vs_others, lomap_old_mapper):
with pytest.raises(ValueError, match='No ligand called'):
network = openfe.setup.ligand_network_planning.generate_radial_network(
ligands=ligands, central_ligand='unobtainium',
mappers=lomap_old_mapper, scorer=None,
mapper=lomap_old_mapper, scorer=None,
)


Expand All @@ -116,7 +116,7 @@ def test_radial_network_multiple_str(toluene_vs_others, lomap_old_mapper):
with pytest.raises(ValueError, match='Multiple ligands called'):
network = openfe.setup.ligand_network_planning.generate_radial_network(
ligands=ligands, central_ligand='toluene',
mappers=lomap_old_mapper, scorer=None,
mapper=lomap_old_mapper, scorer=None,
)


Expand All @@ -128,7 +128,7 @@ def test_radial_network_index_error(toluene_vs_others, lomap_old_mapper):
with pytest.raises(ValueError, match='out of bounds'):
network = openfe.setup.ligand_network_planning.generate_radial_network(
ligands=ligands, central_ligand=2077,
mappers=lomap_old_mapper, scorer=None,
mapper=lomap_old_mapper, scorer=None,
)


Expand All @@ -141,7 +141,7 @@ def scorer(mapping):
network = openfe.setup.ligand_network_planning.generate_radial_network(
ligands=others,
central_ligand=toluene,
mappers=[BadMapper(), lomap_old_mapper],
mapper=[BadMapper(), lomap_old_mapper],
scorer=scorer
)
assert len(network.edges) == len(others)
Expand All @@ -163,7 +163,7 @@ def test_radial_network_multiple_mappers_no_scorer(toluene_vs_others,
network = openfe.setup.ligand_network_planning.generate_radial_network(
ligands=others,
central_ligand=toluene,
mappers=mappers,
mapper=mappers,
)
assert len(network.edges) == len(others)

Expand All @@ -178,7 +178,7 @@ def test_radial_network_failure(atom_mapping_basic_test_files, lomap_old_mapper)
network = openfe.setup.ligand_network_planning.generate_radial_network(
ligands=[nigel],
central_ligand=atom_mapping_basic_test_files['toluene'],
mappers=[lomap_old_mapper],
mapper=[lomap_old_mapper],
scorer=None
)

Expand Down Expand Up @@ -206,7 +206,7 @@ def scoring_func(mapping):

network = openfe.setup.ligand_network_planning.generate_maximal_network(
ligands=others + [toluene],
mappers=mappers,
mapper=mappers,
scorer=scorer,
progress=with_progress,
)
Expand Down Expand Up @@ -247,7 +247,7 @@ def scorer(mapping):

network = openfe.ligand_network_planning.generate_minimal_spanning_network(
ligands=ligands,
mappers=mappers,
mapper=mappers,
scorer=scorer,
)

Expand All @@ -266,7 +266,7 @@ def scorer(mapping):

network = openfe.setup.ligand_network_planning.generate_minimal_spanning_network(
ligands=others + [toluene],
mappers=mappers,
mapper=mappers,
scorer=scorer
)
return network
Expand Down Expand Up @@ -322,7 +322,7 @@ def scorer(mapping):
with pytest.raises(RuntimeError, match="Unable to create edges"):
network = openfe.setup.ligand_network_planning.generate_minimal_spanning_network(
ligands=others + [toluene, nimrod],
mappers=[lomap_old_mapper],
mapper=[lomap_old_mapper],
scorer=scorer
)

Expand All @@ -338,7 +338,7 @@ def scorer(mapping):

network = openfe.setup.ligand_network_planning.generate_minimal_redundant_network(
ligands=others + [toluene],
mappers=mappers,
mapper=mappers,
scorer=scorer,
mst_num=2
)
Expand Down Expand Up @@ -424,7 +424,7 @@ def scorer(mapping):
with pytest.raises(RuntimeError, match="Unable to create edges"):
network = openfe.setup.ligand_network_planning.generate_minimal_redundant_network(
ligands=others + [toluene, nimrod],
mappers=[lomap_old_mapper],
mapper=[lomap_old_mapper],
scorer=scorer
)

Expand All @@ -440,7 +440,7 @@ def test_network_from_names(atom_mapping_basic_test_files, lomap_old_mapper):
network = openfe.setup.ligand_network_planning.generate_network_from_names(
ligands=ligs,
names=requested,
mappers=lomap_old_mapper,
mapper=lomap_old_mapper,
)

assert len(network.nodes) == len(ligs)
Expand All @@ -464,7 +464,7 @@ def test_network_from_names_bad_name(
_ = openfe.setup.ligand_network_planning.generate_network_from_names(
ligands=ligs,
names=requested,
mappers=lomap_old_mapper,
mapper=lomap_old_mapper,
)


Expand All @@ -483,7 +483,7 @@ def test_network_from_names_duplicate_name(
_ = openfe.setup.ligand_network_planning.generate_network_from_names(
ligands=ligs,
names=requested,
mappers=lomap_old_mapper,
mapper=lomap_old_mapper,
)


Expand All @@ -497,7 +497,7 @@ def test_network_from_indices(
network = openfe.setup.ligand_network_planning.generate_network_from_indices(
ligands=ligs,
indices=requested,
mappers=lomap_old_mapper,
mapper=lomap_old_mapper,
)

assert len(network.nodes) == len(ligs)
Expand All @@ -522,7 +522,7 @@ def test_network_from_indices_indexerror(
network = openfe.setup.ligand_network_planning.generate_network_from_indices(
ligands=ligs,
indices=requested,
mappers=lomap_old_mapper,
mapper=lomap_old_mapper,
)


Expand All @@ -536,7 +536,7 @@ def test_network_from_indices_disconnected_warning(
_ = openfe.setup.ligand_network_planning.generate_network_from_indices(
ligands=ligs,
indices=requested,
mappers=lomap_old_mapper,
mapper=lomap_old_mapper,
)


Expand All @@ -553,7 +553,7 @@ def test_network_from_external(file_fixture, loader, request,

network = loader(
ligands=[l for l in benzene_modifications.values()],
mappers=openfe.LomapAtomMapper(),
mapper=openfe.LomapAtomMapper(),
network_file=network_file,
)

Expand Down Expand Up @@ -589,7 +589,7 @@ def test_network_from_external_unknown_edge(file_fixture, loader, request,
with pytest.raises(KeyError, match="Invalid name"):
network = loader(
ligands=ligs,
mappers=openfe.LomapAtomMapper(),
mapper=openfe.LomapAtomMapper(),
network_file=network_file,
)

Expand All @@ -614,7 +614,7 @@ def test_bad_orion_network(benzene_modifications, tmpdir):
with pytest.raises(KeyError, match="line does not match"):
network = openfe.setup.ligand_network_planning.load_orion_network(
ligands=[l for l in benzene_modifications.values()],
mappers=openfe.LomapAtomMapper(),
mapper=openfe.LomapAtomMapper(),
network_file='bad_orion_net.dat',
)

Expand All @@ -637,6 +637,6 @@ def test_bad_edges_network(benzene_modifications, tmpdir):
with pytest.raises(KeyError, match="line does not match"):
network = openfe.setup.ligand_network_planning.load_fepplus_network(
ligands=[l for l in benzene_modifications.values()],
mappers=openfe.LomapAtomMapper(),
mapper=openfe.LomapAtomMapper(),
network_file='bad_edges.edges',
)

0 comments on commit bf82085

Please sign in to comment.