Hello1 I was trying to use rdkit pack to finish the work of displaying the molecular's atom numbers in Jupyter Notebook ,"import IPython.core.interactiveshell" and "import InteractiveShell" ,and "from rdkit.Chem.Draw import DrawingOptions" packs,then I was using "DrawingOptions.includeAtomNumbers=True" to work it ,but the result didn't display the atoms index at all . I don't konw what 's the reason lead to the atoms number didn't showed. So I want to please you to give an answer fittable. Thanks a lot!
rdkit: How to show molecular's atoms number
6k views Asked by jFang At
3
There are 3 answers
0
On
There are three ways to show atom numbers in the molecule.
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
def show_atom_number(mol, label):
for atom in mol.GetAtoms():
atom.SetProp(label, str(atom.GetIdx()+1))
return mol
1. In place of the atoms
mol = Chem.MolFromSmiles('c1ccccc(C(N)=O)1')
show_atom_number(mol, 'atomLabel')
2. Along with the atoms
mol = Chem.MolFromSmiles('c1ccccc(C(N)=O)1')
show_atom_number(mol, 'molAtomMapNumber')
3. On top of the atoms
mol = Chem.MolFromSmiles('c1ccccc(C(N)=O)1')
show_atom_number(mol, 'atomNote')
If you want to change the numbers to display, change the part str(atom.GetIdx()+1)
as per your requirements. Checkout my blog post on the same for more detailed explanation here
0
On
In version 2020.03.2.0 you could try
from rdkit.Chem.Draw import rdMolDraw2D
from rdkit import Chem
mol = Chem.MolFromSmiles('c1ccccc1O')
d = rdMolDraw2D.MolDraw2DCairo(250, 200)
d.drawOptions().addAtomIndices = True
d.DrawMolecule(mol)
d.FinishDrawing()
with open('atom_annotation_1.png', 'wb') as f:
f.write(d.GetDrawingText())
This works for me in a Jupyter Notebook:
Update
As of version
2020.03.1
this did not work anymore.But you can annotate atoms directly.