From dc63ad8fc7570c3bac362a019db69326f8826707 Mon Sep 17 00:00:00 2001 From: Alyssa Travitz Date: Wed, 6 Nov 2024 11:04:44 -0800 Subject: [PATCH] Revert "rename mappers to mapper to avoid api break" This reverts commit bf82085d7a86be63d2eaca11e105261107229ecc. --- openfe/setup/ligand_network_planning.py | 23 +++++----- openfe/tests/setup/test_network_planning.py | 48 ++++++++++----------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/openfe/setup/ligand_network_planning.py b/openfe/setup/ligand_network_planning.py index 18f7334f7..8835c9735 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 to construct edges, at least 1 required + mapper(s) to use, 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,8 +171,9 @@ def generate_maximal_network( ---------- ligands : Iterable[SmallMoleculeComponent] the ligands to include in the LigandNetwork - mappers : AtomMapper or iterable of AtomMappers - mapper(s) to use to construct edges, at least 1 required + mapper : AtomMapper or Iterable[AtomMapper] + the AtomMapper(s) to use to propose mappings. At least 1 required, + but many can be given. scorer : Scoring function any callable which takes a LigandAtomMapping and returns a float progress : Union[bool, Callable[Iterable], Iterable] @@ -322,8 +323,8 @@ def generate_network_from_names( ---------- ligands : list of SmallMoleculeComponent the small molecules to place into the network - mappers : AtomMapper or iterable of AtomMappers - mapper(s) to use, at least 1 required + mapper: AtomMapper + the atom mapper to use to construct edges 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 @@ -364,8 +365,8 @@ def generate_network_from_indices( ---------- ligands : list of SmallMoleculeComponent the small molecules to place into the network - mappers : AtomMapper or iterable of AtomMappers - mapper(s) to use to construct edges, at least 1 required + mapper: AtomMapper + the atom mapper to use to construct edges 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 @@ -400,8 +401,8 @@ def load_orion_network( ---------- ligands : list of SmallMoleculeComponent the small molecules to place into the network - mappers : AtomMapper or iterable of AtomMappers - mapper(s) to use to construct edges, at least 1 required + mapper: AtomMapper + the atom mapper to use to construct edges network_file : str path to NES network file. @@ -449,8 +450,8 @@ def load_fepplus_network( ---------- ligands : list of SmallMoleculeComponent the small molecules to place into the network - mappers : AtomMapper or iterable of AtomMappers - mapper(s) to use to construct edges, at least 1 required + mapper: AtomMapper + the atom mapper to use to construct edges 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 83bfa0ca0..feb456359 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, - mapper=mapper, scorer=None, + mappers=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, - mapper=lomap_old_mapper, scorer=None, + mappers=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', - mapper=lomap_old_mapper, scorer=None, + mappers=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', - mapper=lomap_old_mapper, scorer=None, + mappers=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, - mapper=lomap_old_mapper, scorer=None, + mappers=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, - mapper=[BadMapper(), lomap_old_mapper], + mappers=[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, - mapper=mappers, + mappers=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'], - mapper=[lomap_old_mapper], + mappers=[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], - mapper=mappers, + mappers=mappers, scorer=scorer, progress=with_progress, ) @@ -247,7 +247,7 @@ def scorer(mapping): network = openfe.ligand_network_planning.generate_minimal_spanning_network( ligands=ligands, - mapper=mappers, + mappers=mappers, scorer=scorer, ) @@ -266,7 +266,7 @@ def scorer(mapping): network = openfe.setup.ligand_network_planning.generate_minimal_spanning_network( ligands=others + [toluene], - mapper=mappers, + mappers=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], - mapper=[lomap_old_mapper], + mappers=[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], - mapper=mappers, + mappers=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], - mapper=[lomap_old_mapper], + mappers=[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, - mapper=lomap_old_mapper, + mappers=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, - mapper=lomap_old_mapper, + mappers=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, - mapper=lomap_old_mapper, + mappers=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, - mapper=lomap_old_mapper, + mappers=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, - mapper=lomap_old_mapper, + mappers=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, - mapper=lomap_old_mapper, + mappers=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()], - mapper=openfe.LomapAtomMapper(), + mappers=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, - mapper=openfe.LomapAtomMapper(), + mappers=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()], - mapper=openfe.LomapAtomMapper(), + mappers=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()], - mapper=openfe.LomapAtomMapper(), + mappers=openfe.LomapAtomMapper(), network_file='bad_edges.edges', )