5
$\begingroup$

I'm updating a database and trying to move from CAS Registry names to InChIKeys. I have about ~800 compounds to track. Is there a way to do this mappings programatically? I'm looking for a web service or API that already has this implemented, does something like it exist?

$\endgroup$
1

2 Answers 2

8
$\begingroup$

Chemical Identifier Resolver can convert several identifiers and has an API so you can convert with a script.

A Python example for CAS to InChIKey:

from urllib.request import urlopen

def CIRconvert(cas):
    try:
        url = 'http://cactus.nci.nih.gov/chemical/structure/' + cas + '/stdinchikey'
        ans = urlopen(url).read().decode('utf8')
        return ans
    except:
        return cas

casno = ['50-78-2', '69-72-7', '95-1E-6', '108-24-7', '31710-30-2']

for casid in casno:
    print(CIRconvert(casid))

Output:

InChIKey=BSYNRYMUTXBXSQ-UHFFFAOYSA-N
InChIKey=YGSDEFSMJLZEOE-UHFFFAOYSA-N
95-1E-6
InChIKey=WFDIJRYMOXRFFG-UHFFFAOYSA-N
InChIKey=CIPFDHFTBYJKQB-UHFFFAOYSA-N
$\endgroup$
4
  • $\begingroup$ note that your code is syntactically wrong $\endgroup$
    – mykhal
    Commented Jun 8, 2020 at 13:23
  • $\begingroup$ @mykhal Just tested - code and service works. $\endgroup$
    – rapelpy
    Commented Jun 8, 2020 at 15:55
  • $\begingroup$ It really works, sorry for the inconvenience. But I have edited the "buggy code". $\endgroup$
    – mykhal
    Commented Jun 8, 2020 at 16:01
  • $\begingroup$ @mykhal For future reference: code prettify $\endgroup$ Commented Jun 8, 2020 at 16:37
3
$\begingroup$

Chemical Identifier Resolver has a python API also: https://cirpy.readthedocs.io/en/latest/index.html

import cirpy
print(cirpy.resolve('107-13-1', 'stdinchikey'))

Output

InChIKey=NLHHRLWOUZZQLW-UHFFFAOYSA-N
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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