<p>Yes, RDKit can be used, however, if you installed it with <code>conda</code> it will not work out of the box for inChi key fetching. You can either spend some time installing the missing bit or use something else. It is not like Mol2 support in RDKit, which shouldn't be used, it is just not worth the bother.</p>

<p>I would suggest <a href="https://pubchemdocs.ncbi.nlm.nih.gov/pug-rest" rel="nofollow noreferrer">PubChem's RESTFul API</a>.</p>

<p>Say </p>

<pre><code> import requests
 ethanol = 'LFQSCWFLJHTTHZ-UHFFFAOYSA-N'
 r = requests.get(f'https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/inchikey/{ethanol}/property/CanonicalSMILES/JSON').json()
 smiles = r['PropertyTable']['Properties'][0]['CanonicalSMILES']
</code></pre>

CC BY-SA 4.0
2019-11-19T23:56:51.790Z
Hey, thanks for the answer. Though I get {'Fault': {'Code': 'PUGREST.BadRequest',
  'Message': 'Missing structure string',
  'Details': ["An argument for 'inchi' must be provided in the URL path or POST data"]}} when I run your code.
Soerendip
CC BY-SA 4.0
2019-11-20T08:45:10.283Z
Sorry for that. I fixed the typo by using your code. But I am glad it works now!
Matteo Ferla
CC BY-SA 4.0
2019-11-17T09:11:44.730Z
2019-11-20T08:42:32.597Z
2019-11-20T08:42:32.597Z
Matteo Ferla
<p>Slightly modified Matteos answer:</p>

<pre><code>import requests
def get_smiles_from_inchikey(inchikey):
    r = requests.get(f'https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/inchikey/{inchikey}/property/CanonicalSMILES/JSON').json()
    return r['PropertyTable']['Properties'][0]['CanonicalSMILES']

inchikey = 'SGNXVBOIDPPRJJ-UHFFFAOYSA-N'
get_smiles_from_inchikey(inchikey)
</code></pre>

CC BY-SA 4.0
2019-11-20T00:14:46.267Z
2019-11-20T00:14:46.267Z
Soerendip
<p>I am looking for a python package that can convert InChi keys (e.g.SGNXVBOIDPPRJJ-UHFFFAOYSA-N) to molecular structure or SMILES strings. Can I do that with RDKit? </p>

<p>The key comes from: <a href="https://www.metabolomicsworkbench.org/databases/refmet/refmet_latest.txt" rel="nofollow noreferrer">https://www.metabolomicsworkbench.org/databases/refmet/refmet_latest.txt</a></p>

<structural-biology>
Is there a Python package to convert InChi to molecular structures?
# Is there a Python package to convert InChi to molecular structures?

(Asked by: username_0 on 2019-11-09)

I am looking for a python package that can convert InChi keys (e.g.SGNXVBOIDPPRJJ-UHFFFAOYSA-N) to molecular structure or SMILES strings. Can I do that with RDKit?

The key comes from: <https://www.metabolomicsworkbench.org/databases/refmet/refmet_latest.txt>

**Tags:** structural-biology

---

## 2 answers

### Answer by username_1 on 2019-11-17. Score: 3 | Accepted answer

Yes, RDKit can be used, however, if you installed it with conda it will not work out of the box for inChi key fetching. You can either spend some time installing the missing bit or use something else. It is not like Mol2 support in RDKit, which shouldn't be used, it is just not worth the bother.
I would suggest PubChem's RESTFul API.
Say 
 import requests
 ethanol = 'LFQSCWFLJHTTHZ-UHFFFAOYSA-N'
 r = requests.get(f'https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/inchikey/{ethanol}/property/CanonicalSMILES/JSON').json()
 smiles = r['PropertyTable']['Properties'][0]['CanonicalSMILES']

> **Comments:**
> **username_0**: Hey, thanks for the answer. Though I get {'Fault': {'Code': 'PUGREST.BadRequest',   'Message': 'Missing structure string',   'Details': ["An argument for 'inchi' must be provided in the URL path or POST data"]}} when I run your code.  
> **username_1**: Sorry for that. I fixed the typo by using your code. But I am glad it works now!  

---

### Answer by username_0 on 2019-11-20. Score: 2

Slightly modified Matteos answer:
import requests
def get_smiles_from_inchikey(inchikey):
    r = requests.get(f'https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/inchikey/{inchikey}/property/CanonicalSMILES/JSON').json()
    return r['PropertyTable']['Properties'][0]['CanonicalSMILES']

inchikey = 'SGNXVBOIDPPRJJ-UHFFFAOYSA-N'
get_smiles_from_inchikey(inchikey)


---

