diff --git a/rmgpy/molecule/molecule.py b/rmgpy/molecule/molecule.py index a5d54a11d3..1d4f4752e4 100644 --- a/rmgpy/molecule/molecule.py +++ b/rmgpy/molecule/molecule.py @@ -2681,13 +2681,21 @@ def get_smallest_set_of_smallest_rings(self, symmetrized=False): return_mapping=False, save_order=True, ignore_bond_orders=True) - + rdkit_mol.UpdatePropertyCache(strict=False) + ranks = list(Chem.CanonicalRankAtoms(rdkit_mol, breakTies=True)) + rank_to_idx = {rank: idx for idx, rank in enumerate(ranks)} + new_order = [rank_to_idx[i] for i in range(rdkit_mol.GetNumAtoms())] + canonical_mol = Chem.RenumberAtoms(rdkit_mol, new_order) if symmetrized: - ring_info = Chem.GetSymmSSSR(rdkit_mol) + ring_info = Chem.GetSymmSSSR(canonical_mol) else: - ring_info = Chem.GetSSSR(rdkit_mol) + ring_info = Chem.GetSSSR(canonical_mol) + for ring in ring_info: - atom_ring = [self.atoms[idx] for idx in ring] + # Map the new canonical indices back to the original RMG atom indices + original_idx_ring = [new_order[idx] for idx in ring] + atom_ring = [self.atoms[idx] for idx in original_idx_ring] + sorted_ring = self.sort_cyclic_vertices(atom_ring) sssr.append(sorted_ring) if symmetrized: diff --git a/test/rmgpy/molecule/moleculeTest.py b/test/rmgpy/molecule/moleculeTest.py index 43c4b4e33a..2c3896148d 100644 --- a/test/rmgpy/molecule/moleculeTest.py +++ b/test/rmgpy/molecule/moleculeTest.py @@ -3172,8 +3172,8 @@ def test_get_all_polycyclic_vertices(self): """) polycyclic_vertices = mol.get_all_polycyclic_vertices() assert len(polycyclic_vertices) == 2 - assert mol.atoms[0] is mol.get_all_polycyclic_vertices()[0] - assert mol.atoms[1] is mol.get_all_polycyclic_vertices()[1] + assert mol.atoms[0] is mol.get_all_polycyclic_vertices()[1] + assert mol.atoms[1] is mol.get_all_polycyclic_vertices()[0] # Spirocyclic molecule mol = Molecule().from_adjacency_list("""