From bf82085d7a86be63d2eaca11e105261107229ecc Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Wed, 6 Nov 2024 10:59:28 -0800 Subject: [PATCH] rename mappers to mapper to avoid api break --- openfe/setup/ligand_network_planning.py | 23 +++++----- openfe/tests/setup/test_network_planning.py | 48 ++++++++++----------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/openfe/setup/ligand_network_planning.py b/openfe/setup/ligand_network_planning.py index 8835c9735..18f7334f7 100644 --- a/openfe/setup/ligand_network_planning.py +++ b/openfe/setup/ligand_network_planning.py @@ -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. @@ -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] @@ -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 @@ -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 @@ -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. @@ -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. diff --git a/openfe/tests/setup/test_network_planning.py b/openfe/tests/setup/test_network_planning.py index feb456359..83bfa0ca0 100644 --- a/openfe/tests/setup/test_network_planning.py +++ b/openfe/tests/setup/test_network_planning.py @@ -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) @@ -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) @@ -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, ) @@ -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, ) @@ -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, ) @@ -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) @@ -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) @@ -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 ) @@ -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, ) @@ -247,7 +247,7 @@ def scorer(mapping): network = openfe.ligand_network_planning.generate_minimal_spanning_network( ligands=ligands, - mappers=mappers, + mapper=mappers, scorer=scorer, ) @@ -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 @@ -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 ) @@ -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 ) @@ -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 ) @@ -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) @@ -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, ) @@ -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, ) @@ -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) @@ -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, ) @@ -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, ) @@ -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, ) @@ -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, ) @@ -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', ) @@ -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', )