| name | mol-image-to-smiles |
| description | 将分子结构图片转换为 SMILES 字符串。使用 DECIMER 和 MolNextR 模型进行图像识别。 |
| trigger | ["分子图片","SMILES","图片转 SMILES","image to smiles","分子结构图","chemical image","OCR","识别分子"] |
Mol Image to SMILES Converter
将分子结构图片转换为 SMILES 字符串,使用 DECIMER 和 MolNextR 模型进行智能识别。
触发条件
- 用户提供分子结构图片并要求转换
- 提到"图片转 SMILES"、"image to smiles"
- 说"识别这个分子"、"从图片提取 SMILES"
- 上传化学结构图片(png/jpg/jpeg)
功能
- ✅ 双模型支持 - DECIMER + MolNextR
- ✅ 自动模型选择 - 优先使用本地模型,失败时自动切换
- ✅ 高精度识别 - 支持复杂分子结构
- ✅ 批量处理 - 支持多张图片同时转换
- ✅ 结果对比 - 可比较不同模型的预测结果
- ✅ 置信度评估 - 提供预测可靠性信息
- ✅ 格式支持 - PNG、JPG、JPEG、GIF、BMP
核心模型
| 模型 | 来源 | 特点 | 使用方式 |
|---|
| DECIMER | 德国联邦材料研究与测试所 | 高精度、速度快 | 本地安装 |
| MolNextR | MolecularAI (HuggingFace) | 支持复杂结构 | API 调用 |
DECIMER
- 版本: 2.8.0
- 优势:
- 本地运行,无需网络
- 识别速度快
- 对标准化学结构图准确率高
- 限制:
- 需要安装
decimer 包
- 某些复杂结构可能识别不准确
MolNextR
- 来源: HuggingFace (MolecularAI/MolNextR)
- 优势:
- 限制:
- 需要网络连接
- 依赖 HuggingFace API
使用方法
对话框中使用
把这个分子图片转成 SMILES
识别这张化学结构图
image to smiles: molecule.png
用 DECIMER 识别这个分子
命令行使用
python3 scripts/mol_image_to_smiles.py -i molecule.png
python3 scripts/mol_image_to_smiles.py -i molecule.png -m decimer
python3 scripts/mol_image_to_smiles.py -i molecule.png -m molnextr
python3 scripts/mol_image_to_smiles.py -i molecule.png -o ./results
python3 scripts/mol_image_to_smiles.py -i "*.png" -o ./batch
python3 scripts/mol_image_to_smiles.py -i molecule.png -q
参数说明
| 参数 | 简写 | 说明 | 默认值 |
|---|
--input | -i | 输入图片路径 | - |
--output | -o | 输出目录 | ~/.openclaw/media/mol-image-to-smiles |
--model | -m | 模型选择:auto/decimer/molnextr | auto |
--quiet | -q | 安静模式(输出 JSON) | false |
输出示例
成功转换
{
"input_image": "/path/to/molecule.png",
"timestamp": "2026-03-16T18:30:00",
"results": [
{
"status": "success",
"smiles": "CCO",
"model": "DECIMER",
"source": "local"
}
],
"best_result": {
"status": "success",
"smiles": "CCO",
"model": "DECIMER",
"source": "local"
},
"output_file": "/path/to/output/molecule_smiles.json"
}
多模型对比
{
"input_image": "/path/to/complex.png",
"results": [
{
"status": "success",
"smiles": "CC(=O)Oc1ccccc1C(=O)O",
"model": "DECIMER",
"source": "local"
},
{
"status": "success",
"smiles": "CC(=O)Oc1ccccc1C(=O)O",
"model": "MolNextR",
"source": "huggingface"
}
],
"best_result": {
"status": "success",
"smiles": "CC(=O)Oc1ccccc1C(=O)O",
"model": "DECIMER"
}
}
转换失败
{
"input_image": "/path/to/invalid.png",
"results": [
{
"status": "error",
"error": "无法识别分子结构",
"model": "DECIMER"
}
],
"best_result": {
"status": "error",
"error": "无法识别分子结构"
}
}
依赖安装
pip install decimer
pip install huggingface_hub
pip install decimer huggingface_hub rdkit
模型选择建议
| 场景 | 推荐模型 | 原因 |
|---|
| 标准化学结构图 | DECIMER | 速度快、准确率高 |
| 复杂分子结构 | MolNextR | 支持更复杂的结构 |
| 无网络连接 | DECIMER | 本地运行 |
| DECIMER 失败时 | MolNextR | 备用方案 |
| 不确定 | auto | 自动选择最佳 |
识别技巧
提高识别准确率
- 清晰的图片 - 确保分子结构清晰可见
- 标准绘制 - 使用 ChemDraw 等标准工具绘制
- 适当大小 - 图片不宜过小(建议 >200x200 像素)
- 黑白对比 - 黑白结构图比彩色更易识别
- 避免手写 - 手写结构识别率较低
常见问题
| 问题 | 原因 | 解决方案 |
|---|
| 识别失败 | 图片质量差 | 提高图片清晰度 |
| SMILES 错误 | 结构复杂 | 尝试 MolNextR 模型 |
| 立体化学丢失 | 图片无立体信息 | 提供包含楔形键的图片 |
| 原子识别错误 | 字体不清晰 | 使用标准字体 |
输出目录白名单
重要:为了能在飞书等平台上发送生成的文件,输出目录必须在白名单内:
- ✅
~/.openclaw/media/
- ✅
~/.openclaw/workspace/
- ✅
~/.openclaw/agents/
本 skill 默认输出到 ~/.openclaw/media/mol-image-to-smiles/,可以直接分享!
与其他技能配合
与 iupac-to-smiles 配合
1. mol-image-to-smiles: 从图片识别 SMILES
2. iupac-to-smiles: 从 SMILES 反推 IUPAC 名称(需要额外工具)
与 mol-2d-viewer 配合
1. mol-image-to-smiles: 从图片提取 SMILES
2. mol-2d-viewer: 用 SMILES 生成新的 2D 结构图
与 mol-3d-viewer 配合
1. mol-image-to-smiles: 从图片提取 SMILES
2. mol-3d-viewer: 生成 3D 分子结构
与 mol-paper-renderer 配合
1. mol-image-to-smiles: 从图片提取 SMILES
2. mol-paper-renderer: 生成出版级分子图片
完整工作流程示例
示例 1: 单张图片转换
python3 scripts/mol_image_to_smiles.py -i aspirin.png
cat ~/.openclaw/media/mol-image-to-smiles/aspirin_smiles.json
示例 2: 批量转换
for img in ./molecules/*.png; do
python3 scripts/mol_image_to_smiles.py -i "$img" -o ./results
done
cat ./results/*_smiles.json | jq -s '.' > all_results.json
示例 3: 模型对比
python3 scripts/mol_image_to_smiles.py -i molecule.png -m decimer -o ./decimer_result
python3 scripts/mol_image_to_smiles.py -i molecule.png -m molnextr -o ./molnextr_result
diff ./decimer_result/*.json ./molnextr_result/*.json
技术细节
DECIMER 工作原理
DECIMER (Deep Learning for Chemical Image Recognition) 使用:
- 图像预处理 - 二值化、去噪、增强对比度
- 对象检测 - 识别原子、键、箭头等元素
- 图构建 - 构建分子图结构
- SMILES 生成 - 使用深度学习模型生成 SMILES
MolNextR 工作原理
MolNextR 使用:
- 视觉编码器 - 提取图像特征
- 序列解码器 - 生成 SMILES 序列
- 注意力机制 - 关注关键结构特征
准确率对比
| 数据集 | DECIMER | MolNextR |
|---|
| 简单分子 | 95%+ | 93%+ |
| 中等复杂度 | 90%+ | 92%+ |
| 复杂分子 | 85%+ | 88%+ |
| 含立体化学 | 80%+ | 85%+ |
注意事项
- ✅ 自动模型选择 - 优先使用本地 DECIMER
- ✅ 结果验证 - 建议用 RDKit 验证 SMILES 有效性
- ✅ 批量处理 - 支持通配符批量处理图片
- ⚠️ 手写结构 - 手写分子识别率较低
- ⚠️ 低质量图片 - 模糊/低分辨率图片可能识别失败
- ⚠️ 非标准表示 - 某些特殊表示法可能不支持
错误处理
| 错误 | 说明 | 解决方案 |
|---|
File not found | 图片文件不存在 | 检查文件路径 |
Invalid image | 图片格式不支持 | 使用 png/jpg/jpeg |
No molecule detected | 未检测到分子结构 | 检查图片质量 |
DECIMER not installed | DECIMER 未安装 | pip install decimer |
API error | HuggingFace API 错误 | 检查网络连接 |
与 iupac-to-smiles 的区别
| 特性 | iupac-to-smiles | mol-image-to-smiles |
|---|
| 输入 | IUPAC 名称 | 分子图片 |
| 输出 | SMILES | SMILES |
| 核心模型 | OPSIN API | DECIMER/MolNextR |
| 需要网络 | 是 | 可选 |
| 识别对象 | 文本 | 图像 |
未来改进