Search code examples
python-3.xmachine-learningdata-sciencechemistrypubchem

Is there anyway to call PubChem API In python?


I have been using PubChem API to convert Chemical smiles to the structure but still have an error.

Here is my google colab I try with PIL image plus TKinter

https://colab.research.google.com/drive/1TE9WxXwaWKSLQzKRQoNlWFqztVSoIxB7

My desired output should be in structure format like this

https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/O=C(N1C=CN=C1)N2C=CN=C2/PNG?record_type=2d&image_size=large


Solution

  • Download and display in a Jupyter Notebook

    from urllib.request import urlretrieve
    from IPython.display import Image
    
    smiles = 'NC1=NC(C)=C(C2=CC=C(S(=O)(C)=O)C(F)=C2)S1'
    urlretrieve('https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/'+smiles+'/PNG', 'smi_pic.png')
    p = Image(filename='smi_pic.png')
    p
    

    Output

    structure