安装pubchempy
Pypi
pip install pubchempy
或conda
conda install -c mcs07 pubchempy
或本地安装,下载源码
tar -xzvf PubChemPy-1.0.4.tar.gz
cd PubChemPy-1.0.4
python setup.py install
import pubchempy as pcp
import re
def get_substructure_cas(smiles):
"""
Get CAS number of smiles
"""
cas_rns = []
results = pcp.get_synonyms(smiles, 'smiles', searchtype='substructure')
for result in results:
for syn in result.get('Synonym', []):
match = re.match('(\d{2,7}-\d\d-\d)', syn)
if match:
cas_rns.append(match.group(1))
return cas_rns
测试
smiles = 'B1(OC2CC3CC(C3(C)C)C2(O1)C)C(CCC(CC(=O)OC(C)(C)C)O[Si](C)(C)C(C)(C)C)Cl'
get_substructure_cas(smiles)
['1681053-96-2']