2
$\begingroup$

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

$\endgroup$
3
$\begingroup$

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']
$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$ – Sören Nov 19 '19 at 23:56
  • $\begingroup$ Sorry for that. I fixed the typo by using your code. But I am glad it works now! $\endgroup$ – Matteo Ferla Nov 20 '19 at 8:45
2
$\begingroup$

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)
$\endgroup$

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.