// HACK: remove not-visited bonds
if visited_bonds: // probably we dont want to delete all
new_mol = Chem.RWMol(new_mol)
all_bonds = set(range(new_mol.GetNumBonds()))
visited_bonds = set(visited_bonds)
for bid in sorted(all_bonds.difference(visited_bonds), reverse=True):
bond = new_mol.GetBondWithIdx(bid)
a1 = bond.GetBeginAtom()
After Change
visited_bonds = set(visited_bonds)
for a1_ix, a2_ix in product(range(new_mol.GetNumAtoms()), repeat=2):
bond = new_mol.GetBondBetweenAtoms(a1_ix, a2_ix)
if bond is None or (a1_ix, a2_ix) in visited_bonds or (a1_ix, a2_ix) in visited_bonds:
continue
a1 = new_mol.GetAtomWithIdx(a1_ix)
a2 = new_mol.GetAtomWithIdx(a2_ix)
a1_num = a1.GetPDBResidueInfo().GetResidueNumber()
a2_num = a2.GetPDBResidueInfo().GetResidueNumber()