Re: [Rdkit-discuss] how to get indexes and atoms with H from smiles
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
From: Francois B. <ml...@li...> - 2023-05-10 01:42:27
|
Hello, Maybe you can use this: Chem.MolToSmiles(mol, allHsExplicit=True) This will place each heavy atom between '[' and ']' and give you the number of hydrogens for each. It get easier to work with SMILES strings after this (you don't need anymore a full blown SMILES parser). Regards, F. On 09/05/2023 14:55, Haijun Feng wrote: > [1] > > Hi All, > > I am trying to add atom numbers in smiles as belows, > > from rdkit import Chem > mol=Chem.MolFromSmiles('c1ccccc(C(N)=O)1') > for i, atom in enumerate(mol.GetAtoms()): > atom.SetProp('molAtomMapNumber',str(i)) > smi=Chem.MolToSmiles(mol) > print(smi) > > the output is: [cH:0]1[cH:1][cH:2][cH:3][cH:4][c:5]1C:6=[O:8] > > then I want to split the smiles into atoms, I did it like this: > > from rdkit import Chem > mol=Chem.MolFromSmiles('c1ccccc(C(N)=O)1') > for i, atom in enumerate(mol.GetAtoms()): > atom.SetProp('molAtomMapNumber',str(i)) > print(i,atom.GetSymbol()) > > the output is: > > 0 C > 1 C > 2 C > 3 C > 4 C > 5 C > 6 C > 7 N > 8 O > > But what I do want is something like this (with fragments instead of > atoms): > > 0 cH > 1 CH > ... > 7 NH2 > 8 O > > Can anyone help me figure out how to get each atom with H from the > smiles as above. Thanks so much! > > best, > > Hal > > Links: > ------ > [1] https://stackoverflow.com/posts/76197437/timeline > _______________________________________________ > Rdkit-discuss mailing list > Rdk...@li... > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss |