Repository navigation
MolToSmiles fails with rootedAtAtom for disconnected molecules (need for smiles augmentation) #44
Description
Activity
I'm facing the same error for issue #113 in PR #115 , and the below might the reason
Description:
When performing SMILES augmentation using RDKit’sChem.MolToSmileswith therootedAtAtomargument, the function raises aRuntimeError: Range Error idxfor molecules containing disconnected fragments (e.g.,[F-].[Na+]).Steps to Reproduce:
from rdkit import Chem mol = Chem.MolFromSmiles("[F-].[Na+]") Chem.MolToSmiles(mol, rootedAtAtom=1, doRandom=True)
Observed Behavior:
Exception has occurred: RuntimeError Range Error idx Violation occurred on line 209 in file Code\GraphMol\ROMol.cpp Failed Expression: 1 < 1 RDKIT: 2024.09.6 BOOST: 1_85Cause:
RDKit’srootedAtAtomassumes the atom index belongs to a single connected component. For disconnected molecules (multiple fragments), this internal assumption fails and results in an out-of-bounds fragment index.To elaborate,
MolToSmiles’rootedAtAtomparameter expects the index of atom in a connected fragment — but the molecule[F-].[Na+]is two disconnected fragments. When you passrootedAtAtom=1(sodium atom), RDKit internally tries to traverse a single fragment, but the fragment index calculation fails due to it being a disconnected molecule.@sfluegel05, Please let me know if you have any suggestions for augmenting this type of smiles which are present in our processed dataset.
- changed the title
[-]MolToSmiles() gives RuntimeError for some molecules[/-][+]MolToSmiles fails with rootedAtAtom for disconnected molecules (need for smiles augmentation)[/+]on Aug 10, 2025 - addedhelp wantedExtra attention is neededExtra attention is needed
on Aug 10, 2025 - changed the title
[-]MolToSmiles fails with rootedAtAtom for disconnected molecules (need for smiles augmentation)[/-][+]`MolToSmiles` fails with `rootedAtAtom` for disconnected molecules (need for smiles augmentation)[/+]on Aug 10, 2025 - addedquestionFurther information is requestedFurther information is requested
on Aug 10, 2025 you are right. For some reason the
rootedAtAtomargument does not accept the atom id, but only takes the first fragment into account. I guess we should treat each fragment separately as well and then recombine them afterwardsmol = Chem.MolFromSmiles("[F-].[Na+]") fragments = Chem.GetMolFrags(mol, asMols=True) for i, fragment in enumerate(fragments): print(f"Fragment {i}: {Chem.MolToSmiles(fragment)}") # randomize SMILES for this fragment # stitch together fragment-SMILES (in random order)- added a commit that references this issue
on Aug 22, 2025 - linked a pull request that will close this issueData Augmentation : SMILES #115
on Aug 22, 2025
rdkit MolToSmiles() gives RuntimeError for some molecules (Eg: "[Cl-].[H]N+([H])[H]" ), with configuration of rootedAtAtom>0.