From bb1ee1705b9f79ad9c25ca5dbc2a4fedd3d4ec62 Mon Sep 17 00:00:00 2001 From: Katharina Buchthal Date: Wed, 14 Jan 2026 09:06:20 +0100 Subject: [PATCH 1/2] removed next() usage --- kinfraglib/utils.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/kinfraglib/utils.py b/kinfraglib/utils.py index c4668893..c492182a 100644 --- a/kinfraglib/utils.py +++ b/kinfraglib/utils.py @@ -1328,16 +1328,20 @@ def construct_ligand(fragment_ids, bond_ids, fragment_library): ed_combo = Chem.EditableMol(combo) replaced_dummies = [] - atoms = combo.GetAtoms() - for bond in bond_ids: - dummy_1 = next( - atom for atom in combo.GetAtoms() if atom.GetProp("fragment_atom_id") == bond[0] - ) - dummy_2 = next( - atom for atom in combo.GetAtoms() if atom.GetProp("fragment_atom_id") == bond[1] - ) + # should be a one element lists + dummy_1_candidates = [atom for atom in combo.GetAtoms() if atom.GetProp("fragment_atom_id") == bond[0]] + dummy_2_candidates = [atom for atom in combo.GetAtoms() if atom.GetProp("fragment_atom_id") == bond[1]] + + if len(dummy_1_candidates) == 0 or len(dummy_2_candidates) == 0: + raise RuntimeError(f'Dummy atoms for bond {bond} not found') + elif len(dummy_1_candidates) > 1 or len(dummy_2_candidates) > 1: + raise RuntimeError(f'This should not happen: Dummy atoms found for bond {bond} are unambigious') + + dummy_1 = dummy_1_candidates[0] + dummy_2 = dummy_2_candidates[1] + atom_1 = dummy_1.GetNeighbors()[0] atom_2 = dummy_2.GetNeighbors()[0] From 06d35cd9557e28cfa1f02e38c0ec538e99fc58eb Mon Sep 17 00:00:00 2001 From: Katharina Buchthal Date: Mon, 26 Jan 2026 17:23:27 +0100 Subject: [PATCH 2/2] bug fix --- kinfraglib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kinfraglib/utils.py b/kinfraglib/utils.py index c492182a..86d9c18e 100644 --- a/kinfraglib/utils.py +++ b/kinfraglib/utils.py @@ -1340,7 +1340,7 @@ def construct_ligand(fragment_ids, bond_ids, fragment_library): raise RuntimeError(f'This should not happen: Dummy atoms found for bond {bond} are unambigious') dummy_1 = dummy_1_candidates[0] - dummy_2 = dummy_2_candidates[1] + dummy_2 = dummy_2_candidates[0] atom_1 = dummy_1.GetNeighbors()[0] atom_2 = dummy_2.GetNeighbors()[0]