Re: [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-09 23:56:31
|
Thanks, Diogo and Fio. That solved that problem. Jeremy On Sun, Oct 8, 2023 at 1:23 AM Diogo Martins <dio...@gm...> wrote: > Hi Jeremy, > > Chem.AddHs returns a new molecule, you could reassign the variable: > > mol = Chem.AddHs(mol) > > Best regards, > Diogo > > On Sat, Oct 7, 2023 at 9:36 PM Jeremy Monat <je...@gm...> wrote: > >> 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 >> _______________________________________________ >> Rdkit-discuss mailing list >> Rdk...@li... >> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >> > _______________________________________________ > Rdkit-discuss mailing list > Rdk...@li... > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss > |