IUPAC 名称和 SMILES 互转:工具选择指南#
背景#
拿到 ChemAxon 学术许可证后,发现不包含 Python API,无法直接用脚本批量转换 IUPAC 名称和 SMILES。于是调研了几个免费工具,记录一下实测结果。
工具对比#
性能数据(基于学术文献)#
IUPAC → SMILES 准确率:
| 工具 | 准确率 | 费用 | 说明 |
|---|---|---|---|
| OPSIN | 99.8% | 免费 | 基于规则解析 |
| ChemAxon | 95-98% | 付费 | 需要额外许可证 |
| STOUT V2 | 90-94% | 免费 | AI 模型 |
| CIR | 80-90% | 免费 | 在线服务 |
SMILES → IUPAC:
只有 STOUT 和商业软件支持,OPSIN 和 CIR 都不支持反向转换。
三个免费工具#
1. OPSIN#
准确率最高的方案(99.8%),专门解析标准 IUPAC 名称。
pip install py2opsin
from py2opsin import py2opsin
smiles = py2opsin("propan-2-ol") # CC(C)O
优点:准确率高,离线运行
缺点:不识别俗名(如 "aspirin"),不支持反向转换
2. STOUT V2#
唯一免费的双向转换工具,基于 Transformer AI 模型。
pip install STOUT-pypi
from STOUT import translate_forward, translate_reverse
# SMILES → IUPAC
iupac = translate_forward("CCO") # "ethanol"
# IUPAC → SMILES
smiles = translate_reverse("ethanol") # "CCO"
优点:双向转换,2024 年 12 月最新版
缺点:IUPAC→SMILES 准确率低于 OPSIN(90-94%)
3. CIR#
NIH/NCI 提供的免费在线服务,支持俗名查询。
import urllib.request
url = f"https://cactus.nci.nih.gov/chemical/structure/aspirin/smiles"
smiles = urllib.request.urlopen(url).read().decode().strip()
# CC(=O)Oc1ccccc1C(O)=O
优点:支持俗名("aspirin"、"ibuprofen")
缺点:依赖数据库收录,需要联网
实测对比#
| 化合物 | OPSIN | STOUT | CIR |
|---|---|---|---|
| propan-2-ol | ✅ | ✅ | ✅ |
| (2S)-2-aminopropanoic acid | ✅ | ✅ | ✅ |
| aspirin | ❌ | ❌ | ✅ |
结论:三者互补。
推荐方案#
组合使用#
from py2opsin import py2opsin
from STOUT import translate_reverse
import urllib.request
def iupac_to_smiles(name):
# 1. 先用 OPSIN(最准确)
try:
return py2opsin(name)
except:
pass
# 2. STOUT 备用
try:
return translate_reverse(name)
except:
pass
# 3. CIR 兜底(支持俗名)
try:
url = f"https://cactus.nci.nih.gov/chemical/structure/{name}/smiles"
return urllib.request.urlopen(url, timeout=10).read().decode().strip()
except:
return None
这个组合能覆盖大部分场景,而且完全免费。
快速决策#
- 只需 IUPAC → SMILES → 用 OPSIN
- 需要双向转换 → 用 STOUT
- 处理俗名 → 用 CIR
- 最高成功率 → 三者组合
安装#
conda create -n chemtools python=3.11 -y
conda activate chemtools
pip install py2opsin STOUT-pypi
conda install -c conda-forge rdkit
参考#
- OPSIN: https://github.com/dan2097/opsin
- STOUT: https://github.com/Kohulan/Smiles-TO-iUpac-Translator
- CIR: https://cactus.nci.nih.gov/chemical/structure
总结:对于 IUPAC→SMILES,免费的 OPSIN(99.8%)比付费的 ChemAxon(95-98%)更准确。STOUT 是目前唯一免费的双向转换工具。