Skip to content

Commit

Permalink
draft network from indices/names
Browse files Browse the repository at this point in the history
  • Loading branch information
richardjgowers committed Jul 6, 2023
1 parent 916695f commit cf3ea3a
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions openfe/setup/ligand_network_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,66 @@ def generate_minimal_spanning_network(
+ str(list(missing_nodes)))

return min_network


def generate_network_from_names(
ligands: list[SmallMoleculeComponent],
mapper: AtomMapper,
names: list[tuple[str, str]],
) -> LigandNetwork:
"""Generate a LigandNetwork
Parameters
----------
ligands : list of SmallMoleculeComponent
the small molecules to place into the network
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
molecule with names 'benzene' and 'toluene'
Returns
-------
LigandNetwork
"""
nm2idx = {l.name: i for i, l in enumerate(ligands)}

Check warning on line 210 in openfe/setup/ligand_network_planning.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/ligand_network_planning.py#L210

Added line #L210 was not covered by tests

ids = [(nm2idx[nm1], nm2idx[nm2]) for nm1, nm2 in names]

Check warning on line 212 in openfe/setup/ligand_network_planning.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/ligand_network_planning.py#L212

Added line #L212 was not covered by tests

return generate_network_from_indices(ligands, mapper, ids)

Check warning on line 214 in openfe/setup/ligand_network_planning.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/ligand_network_planning.py#L214

Added line #L214 was not covered by tests


def generate_network_from_indices(
ligands: list[SmallMoleculeComponent],
mapper: Union[AtomMapper, Iterable[AtomMapper]],
indices: list[tuple[int, int]],
) -> LigandNetwork:
"""Generate a LigandNetwork
Parameters
----------
ligands : list of SmallMoleculeComponent
the small molecules to place into the network
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
remembering that Python uses 0-based indexing
Returns
-------
LigandNetwork
"""
edges = []

Check warning on line 239 in openfe/setup/ligand_network_planning.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/ligand_network_planning.py#L239

Added line #L239 was not covered by tests

for i, j in indices:
m1, m2 = ligands[i], ligands[j]

Check warning on line 242 in openfe/setup/ligand_network_planning.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/ligand_network_planning.py#L241-L242

Added lines #L241 - L242 were not covered by tests

mapping = next(mapper.suggest_mappings(m1, m2))

Check warning on line 244 in openfe/setup/ligand_network_planning.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/ligand_network_planning.py#L244

Added line #L244 was not covered by tests

edges.append(mapping)

Check warning on line 246 in openfe/setup/ligand_network_planning.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/ligand_network_planning.py#L246

Added line #L246 was not covered by tests

return LigandNetwork(edges=edges, nodes=ligands)

Check warning on line 248 in openfe/setup/ligand_network_planning.py

View check run for this annotation

Codecov / codecov/patch

openfe/setup/ligand_network_planning.py#L248

Added line #L248 was not covered by tests

0 comments on commit cf3ea3a

Please sign in to comment.