Skip to content

Commit

Permalink
Merge pull request #178 from openforcefield/fix-177
Browse files Browse the repository at this point in the history
Fix 177
  • Loading branch information
j-wags authored Jun 5, 2024
2 parents 610a6fb + 2103e14 commit 642d420
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 10 additions & 0 deletions openff/fragmenter/_tests/test_fragmenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,16 @@ def test_add_substituent():
assert fragment.to_smiles(mapped=False, explicit_hydrogens=False) == "CCCCCC"


def test_issue_177():
"""
There was an where the path search gets tripped up when there are two paths
of equal length leading to a 3-membered ring. This test ensures Fragmenter
runs on a minimal reproducing example of this problem.
More info at https://github.com/openforcefield/openff-fragmenter/issues/177
"""
WBOFragmenter().fragment(Molecule.from_smiles("C1CC1[C@H]2C[C@H]3C[C@H]3C2"))


@pytest.mark.parametrize("input_smiles, n_output", [("CCCCCCC", 4)])
def test_pfizer_fragmenter(input_smiles, n_output):
result = PfizerFragmenter().fragment(Molecule.from_smiles(input_smiles))
Expand Down
19 changes: 11 additions & 8 deletions openff/fragmenter/fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,20 +1246,23 @@ def _select_neighbour_by_path_length(

target_indices = [get_atom_index(molecule, atom) for atom in target_bond]

path_lengths_1, path_lengths_2 = zip(
*(
(
networkx.shortest_path_length(
nx_molecule, target_index, neighbour_index
path_lengths = list(
zip(
*(
(
networkx.shortest_path_length(
nx_molecule, target_index, neighbour_index
)
for target_index in target_indices
)
for target_index in target_indices
for atom_index, neighbour_index in atoms_to_add
)
for atom_index, neighbour_index in atoms_to_add
)
)

if len(path_lengths_1) == 0 and len(path_lengths_2) == 0:
if len(path_lengths) == 0:
return None
path_lengths_1, path_lengths_2 = path_lengths

reverse = False

Expand Down

0 comments on commit 642d420

Please sign in to comment.