Using RDKit (2020.09.5) I would like to assign InChi to molecules expressed as SMILES and fail to replicate this GitHub gist for initial training written about 2 years ago (RDKit 2019.03.2). I would like to know if the required instruction changed, or if I miss importing/adjusting a relevant function/parameter then causing the errors.

To quote the relevant code there:

# Load RDKit modules
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import Draw

# Construct a molecular object from a SMILES string
m1 = Chem.MolFromSmiles('COC(=O)C1CN1C(=O)OCC2=CC=CC=C2')

# Calculate InChI

# Calculate InChIKey

However, neither the anticipated InChi ('InChI=1S/C12H13NO4/c1-16-11(14)10-7-13(10)12(15)17-8-9-5-3-2-4-6-9/h2-6,10H,7-8H2,1H3') nor the hash, i.e. InChiKey 'GTZJUBQWCWZING-UHFFFAOYSA-N' are accessible for me.

Instead, the Jupyter notebook mentions the following errors:

AttributeError                            Traceback (most recent call last)
<ipython-input-9-71f9b591b71d> in <module>
      9 # Calculate InChI
---> 10 Chem.MolToInchi(m1)
     12 # Calculate InChIKey

AttributeError: module 'rdkit.Chem' has no attribute 'MolToInchi'

Following the recommendation in RDKit's manual here, I thought the substitution of Chem.MolToInchi(m1) by Chem.inchi.MolToInchi(m1) would remove the road block. Contrary to anticipation, however, this doesn't work either:

AttributeError                            Traceback (most recent call last)
<ipython-input-10-cddee16a293d> in <module>
      9 # Calculate InChI
     10 # Chem.MolToInchi(m1)
---> 11 Chem.inchi.MolToInchi(m1)
     13 # Calculate InChIKey

AttributeError: module 'rdkit.Chem.inchi' has no attribute 'MolToInchi'
  • $\begingroup$ +10 nice first question Buttonwood! Hopefully after you wrote all those excellent answers here, someone will be able to return the favor and answer yours! $\endgroup$ Sep 10, 2021 at 14:00
  • $\begingroup$ Its presumably an issue of your Jupyter environment. From a fresh install of rdkit 2021.03, I was able to execute the original code from the terminal. You may try to check the version being used within Jupyter import rdkit; print(rdkit.__version__) $\endgroup$
    – Tyberius
    Sep 10, 2021 at 14:19
  • $\begingroup$ @Tyberius As stated above, 202009.5-1 (or 2020.09.5 by import rdkit; help(rdkit); G) is the currently latest available version packaged for Debian 12/bookworm (testing). Yet I read your comment as invite to install rdkit in miniconda. Weekend, here I am ... $\endgroup$
    – Buttonwood
    Sep 10, 2021 at 16:35
  • 1
    $\begingroup$ Downgrading to 2020.09.5 and running in Jupyter still worked for me, though I'm using an Ubuntu20.04 machine. For checking the version, I was more curious if the intended version wasn't matching the one being used by Jupyter for some reason. $\endgroup$
    – Tyberius
    Sep 10, 2021 at 16:46

1 Answer 1


Following @Tyberius suggest, I departed from using Jupyter notebook in favor of the CLI. In contrast of the GitHub gist,* the following script is to report InChi and InChiKey about pyridine:

#!/bin/usr/env python3

import rdkit
from rdkit import Chem

molecule = Chem.MolFromSmiles('n1ccccc1')

inchi = str(Chem.MolToInchi(molecule))
inchikey = str(Chem.MolToInchiKey(molecule))


to yield the strings


These match the output provided e.g., by the ChemDraw JS Sample Page.

Notes taken en route to this result:

  • Following the instructions by RDKit, a separate second Python interpreter was set up based on Miniconda. While substantially smaller than a full Anaconda ecosystem, past the creation of a virtual environment by

    conda create -c conda-forge -n my-rdkit-env rdkit

    the installation requires about $\pu{1.5 GB}$ free space to include larger dependencies like matplotlib, or pandas.

  • As of writing, this offers Python 3.9.7 and rdkit 2021.03.5 when working from the terminal. The version of the later may be checked by either print(rdkit.__version__), or import rdkit; help(rdkit); G. For a reason beyond the scope of this question, Jupyter still was loading the elder version of rdkit provided by the hosting OS, 2020.09.5.

  • *) RDKit 2019.03.2 the GitHub gist mentioned seems to be fine with the aziridine defined by the SMILES string COC(=O)C1CN1C(=O)OCC2=CC=CC=C2. The present version of RDKit however recognizes the ambiguity present and prepends a note in the pattern of:

    [hh:mm:ss] WARNING: Omitted undefined stereo

    In line with this, the Inchi -> structure conversion provided by the PubChem Sketcher draws a structure formula lacking wedges as if there were no (R)/(S) configuration.

  • 1
    $\begingroup$ +1 Great work figuring this out on your own and then sharing it with this whole community in case future users may find it useful! $\endgroup$ Sep 12, 2021 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.