用于获取不同化学物质基本信息的一个类
该类主要基于http://cactus.nci.nih.gov/chemical网站的,你可以利用已知的信息在该网站查询其他信息,比如你知道一个化合物的cas号,你可以在该网站查询到它的iupac name。
该类中设置了超时时间为10秒,并简单的把一切不正常返回都提示为超时错误(如果需要,必须细致甄别不同类型的错误)。
1 # -*- coding: utf-8 -*- 2 import urllib2 3 import socket 4 5 #-------------------------------------------------------------------------- 6 # 该类建立在http://cactus.nci.nih.gov/chemical的基础上 7 # 提交地址http://cactus.nci.nih.gov/chemical/structure/(提交的参数)/(想得到的参数,即返回的参数) 8 # 如:提交cas号,想得到IUPAC Name,可按照如下方式提交地址 9 # http://cactus.nci.nih.gov/chemical/structure/90-51-7/iupac_name 10 # 11 # 提交的参数 选项 12 # stdinchikey Standard InChIKey 13 # stdinchi Standard InChI 14 # smiles SMILES 15 # ficts FICTS Identifier 16 # ficus FICuS Identifier 17 # uuuuu uuuuu Identifier 18 # hashisy Cactvs HASHISY 19 # sdf SD File 20 # names Names 21 # iupac_name IUPAC Name 22 # cas CAS Registry Number 23 # chemspider_id ChemSpider ID 24 # image GIF Image 25 # twirl TwirlyMol (3D) 26 # mw Molecular Weight 27 # formula Chemical Formula 28 # h_bond_donor_count Number of Hydrogen Bond Donors 29 # h_bond_acceptor_count Number of Hydrogen Bond Acceptors 30 # h_bond_center_count Number of Hydrogen Bond Acceptors and Donors 31 # rule_of_5_violation_count Number of Rule of 5 Violations 32 # rotor_count Number of Freely Rotatable Bonds 33 # effective_rotor_count Number of Effectively Rotatable Bonds 34 # ring_count Number of Rings 35 # ringsys_count Number of Ring Systems 36 #-------------------------------------------------------------------------- 37 38 class chemInfo(): 39 def __init__(self,d1,d2): 40 self.enging='http://cactus.nci.nih.gov/chemical/structure/' 41 self.option=['stdinchikey','stdinchi','smiles','ficts','ficus','uuuuu','hashisy','sdf','names','iupac_name','cas','chemspider_id','image','twirl','mw','formula','h_bond_donor_count','h_bond_acceptor_count','h_bond_center_count','rule_of_5_violation_count','rotor_count','effective_rotor_count','ring_count','ringsys_count'] 42 43 self.d1=str(d1).strip() 44 self.d2=str(d2).strip() 45 46 socket.setdefaulttimeout(10) 47 48 if self.d2 in self.option: 49 try: 50 self.info=urllib2.urlopen(self.enging+self.d1+'/'+self.d2).read() 51 except: 52 self.info="链接超时!" 53 else: 54 self.info='找不到你提供的选项,请查证后在试!' 55 56 57 if __name__=='__main__': 58 59 60 chInfo=chemInfo('50-01-1','smiles') 61 print chInfo.info 62 #print chInfo.info.split('\n')[0]