2017-09-01 280 views
0

我想用InChI作爲輸入,例如從幾個數據庫中檢索ID。如何相互轉換InChI和InChIKey?

InChI=1S/C6H14N2O2/c7-4-2-1-3-5(8)6(9)10/h5H,1-4,7-8H2,(H,9,10)/t5-/m0/s1 

人們可以使用unichembioservices對於這一點,然而,這些功能都需要InChIKey作爲輸入,例如

KDXKERNSBIXSRK-YFKPBYRVSA-N 

是否有可能使用bioservices來互換兩個,如果沒有則可能以某種方式使用unichem功能與InChI而非InChIKey

我想:

from bioservices import * 
u = UniChem() 
u.get_src_compound_ids_from_inchikey('KDXKERNSBIXSRK-YFKPBYRVSA-N') 

工作正常,但是,

u.get_src_compound_ids_from_inchikey('InChI=1S/C6H14N2O2/c7-4-2-1-3-5(8)6(9)10/h5H,1-4,7-8H2,(H,9,10)/t5-/m0/s1') 

不起作用,並返回400

回答

0

不知道如果在bioservices直接可行的,但我們可以做到使用chemspider以下解決方法:

import requests 

host = "http://www.chemspider.com" 
getstring = "/InChI.asmx/InChIToInChIKey?inchi=" 
inchi = 'InChI=1S/C6H14N2O2/c7-4-2-1-3-5(8)6(9)10/h5H,1-4,7-8H2,(H,9,10)/t5-/m0/s1' 

r = requests.get('{}{}{}'.format(host, getstring, inchi)) 
if r.ok: 
    res = str(r.text.replace('<?xml version="1.0" encoding="utf-8"?>\r\n<string xmlns="http://www.chemspider.com/">', '').replace('</string>', '').strip()) 
else: 
    print "provide a valid inchi!" 

這將給所需InChIKey

'KDXKERNSBIXSRK-YFKPBYRVSA-N' 

可以在unichem使用。