[Rdkit-discuss] Iterate through atoms in molecule including hydrogens in Python
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
From: Jeremy M. <je...@gm...> - 2023-10-08 04:34:48
|
In Python, I'd like to iterate through all the atoms in a molecule, including hydrogens, so I can assign an isotope to each atom. I haven't been able to include hydrogens in the iterable of atoms: from rdkit import Chem mol = Chem.MolFromSmiles("CCO") # Example molecule: Ethanol (C2H5OH) # Add explicit hydrogens Chem.AddHs(mol) for atom in mol.GetAtoms(): print(f"Atom Symbol: {atom.GetSymbol()}") Output: Atom Symbol: C Atom Symbol: C Atom Symbol: O Similarly, mol.GetAtomWithIdx() works up to an index of only 3, giving C, C, and O atoms but no hydrogens. Thanks, Jeremy -- ~ -- ~ -- Jeremy Monat, PhD LinkedIn: http://www.linkedin.com/in/jemonat Portfolio: https://bertiewooster.github.io GitHub: https://github.com/bertiewooster |