# Smiles To Iupac

> 将 SMILES 字符串转换为 IUPAC 化学名称。使用 PubChem、NCI/CADD、STOUT、RDKit-InChI 多种方法智能转换。

- **Type:** Skill
- **Install:** `agentstack add skill-internscience-chemclaw-smiles-to-iupac`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [InternScience](https://agentstack.voostack.com/s/internscience)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [InternScience](https://github.com/InternScience)
- **Source:** https://github.com/InternScience/ChemClaw/tree/main/skills/smiles-to-iupac

## Install

```sh
agentstack add skill-internscience-chemclaw-smiles-to-iupac
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# SMILES to IUPAC Name Converter (Optimized)

将 SMILES 字符串转换为 IUPAC 化学名称，**使用多种方法智能转换**：PubChem API、NCI/CADD、STOUT (Docker)、RDKit-InChI。

## 触发条件

- 用户提供 SMILES 并要求转换
- 提到"SMILES 转 IUPAC"、"smiles to iupac"
- 说"这个 SMILES 叫什么"、"命名这个分子"
- 提供 SMILES 字符串并要求化学名称

## 功能特性

- ✅ **多方法支持** - PubChem、NCI/CADD、STOUT、RDKit-InChI
- ✅ **智能降级** - 自动尝试多种方法直到成功
- ✅ **SMILES 验证** - 使用 RDKit 验证 SMILES 有效性
- ✅ **分子性质** - 计算分子量、LogP、TPSA 等
- ✅ **聚合物支持** - 自动清理聚合物标记
- ✅ **立体化学** - 支持立体化学信息
- ✅ **批量处理** - 支持多个 SMILES 同时转换
- ✅ **置信度评估** - 提供结果置信度

## 核心模型

| 方法 | 来源 | 返回 | 置信度 | 速度 |
|------|------|------|--------|------|
| **PubChem** | NCBI | IUPAC | ⭐⭐⭐⭐⭐ | 快 |
| **NCI/CADD** | NCI | IUPAC | ⭐⭐⭐⭐⭐ | 快 |
| **STOUT** | Docker | InChI | ⭐⭐⭐⭐ | 中 |
| **RDKit-InChI** | RDKit | InChI | ⭐⭐⭐⭐ | 快 |

### 方法选择逻辑 (auto 模式)

```
1. PubChem API → 成功？→ 返回 IUPAC 名称
                    ↓ 失败
2. NCI/CADD API → 成功？→ 返回 IUPAC 名称
                     ↓ 失败
3. STOUT (Docker) → 成功？→ 返回 InChI
                       ↓ 失败
4. RDKit-InChI → 生成 InChI → 返回
```

### PubChem PUG-REST API (首选)

- **来源**: NCBI PubChem (>1 亿化合物)
- **优势**: 
  - 权威数据源，准确率最高
  - 直接返回 IUPAC 名称
  - 覆盖药物、天然产物等
- **限制**: 
  - 需要网络连接
  - 速率限制：~10 请求/秒

### NCI/CADD Chemical Identifier Resolver (备选)

- **来源**: NCI/CADD
- **优势**: 
  - 权威数据源
  - 支持多种化学标识符
  - 准确率与 PubChem 相当
- **限制**: 
  - 需要网络连接
  - 某些化合物可能无 IUPAC 名称

### STOUT (Docker) (本地方案)

- **架构**: Docker 容器 + RDKit
- **优势**: 
  - 本地运行，保护隐私
  - 不依赖外部 API
  - 生成 InChI 标准化标识
- **限制**: 
  - 需要安装 Docker
  - 需要安装 `stout` 包

### RDKit-InChI (最终方案)

- **来源**: RDKit + InChI
- **优势**: 
  - 完全本地运行
  - 生成标准化 InChI
  - InChI 可转换为 IUPAC
- **限制**: 
  - 返回 InChI 而非直接 IUPAC

## 使用方法

### 对话框中使用

```
把 CCO 转成 IUPAC 名称
SMILES: CC(=O)Oc1ccccc1C(=O)O，转 IUPAC
smiles to iupac: C1=CC=C(C=C1)O
自动转换这个 SMILES
```

### 命令行使用

```bash
# 基本转换（自动选择最佳方法）
python3 scripts/smiles_to_iupac.py -s "CCO"

# 指定使用 PubChem
python3 scripts/smiles_to_iupac.py -s "CCO" -m pubchem

# 指定使用 NCI/CADD
python3 scripts/smiles_to_iupac.py -s "CCO" -m nci

# 指定使用 STOUT (Docker)
python3 scripts/smiles_to_iupac.py -s "CCO" -m stout

# 指定生成 InChI
python3 scripts/smiles_to_iupac.py -s "CCO" -m inchi

# 指定输出目录
python3 scripts/smiles_to_iupac.py -s "CCO" -o ./results

# 不计算分子性质（加快速度）
python3 scripts/smiles_to_iupac.py -s "CCO" --no-properties

# 安静模式（输出 JSON）
python3 scripts/smiles_to_iupac.py -s "CCO" -q
```

## 参数说明

| 参数 | 简写 | 说明 | 默认值 |
|------|------|------|--------|
| `--smiles` | `-s` | 输入 SMILES 字符串 | - |
| `--output` | `-o` | 输出目录 | `~/.openclaw/media/smiles-to-iupac` |
| `--method` | `-m` | 方法：auto/pubchem/nci/stout/inchi | `auto` |
| `--no-properties` | | 不计算分子性质 | `false` |
| `--quiet` | `-q` | 安静模式（输出 JSON） | `false` |

## 输出示例

### 简单化合物 (PubChem)

```json
{
  "input_smiles": "CCO",
  "cleaned_smiles": "CCO",
  "timestamp": "2026-03-16T20:00:00",
  "molecular_properties": {
    "molecular_formula": "C2H6O",
    "molecular_weight": 46.07,
    "num_atoms": 9,
    "num_heavy_atoms": 3
  },
  "results": [
    {
      "status": "success",
      "iupac_name": "ethanol",
      "smiles": "CCO",
      "model": "PubChem",
      "source": "api",
      "confidence": "high"
    }
  ],
  "best_result": {
    "status": "success",
    "iupac_name": "ethanol",
    "model": "PubChem",
    "confidence": "high"
  }
}
```

### 复杂化合物 (NCI/CADD)

```json
{
  "input_smiles": "CC(=O)Oc1ccccc1C(=O)O",
  "best_result": {
    "status": "success",
    "iupac_name": "2-acetyloxybenzoic acid",
    "model": "NCI/CADD",
    "confidence": "high"
  }
}
```

### 聚合物单体 (InChI)

```json
{
  "input_smiles": "*CC(C(=O)OCCCCOc1ccc(cc1)C(=O)Oc1ccc(cc1)OC)(C)*",
  "cleaned_smiles": "CC(C)(C(=O)OCCCCOc1ccc(cc1)C(=O)Oc1ccc(cc1)OC)",
  "best_result": {
    "status": "success",
    "iupac_name": "InChI: 1S/C22H26O6/...",
    "model": "RDKit-InChI",
    "confidence": "medium",
    "note": "InChI is a standardized identifier"
  }
}
```

## 依赖安装

```bash
# 基本安装（推荐）
pip install rdkit requests

# 完整安装（包含 STOUT）
pip install rdkit requests stout

# 确保 Docker 已安装（STOUT 需要）
docker --version
```

## 方法选择建议

| 场景 | 推荐方法 | 原因 |
|------|----------|------|
| 常见有机分子 | auto (PubChem) | 准确率最高 |
| 药物分子 | auto (PubChem) | 数据库覆盖广 |
| 无网络连接 | stout/inchi | 本地运行 |
| 隐私敏感 | stout/inchi | 不上传数据 |
| 聚合物 | inchi | 生成标准化 InChI |
| PubChem 失败 | auto (自动降级) | 尝试其他方法 |

## SMILES 清理

自动清理以下内容：

- **聚合物标记**: `*...*` → 移除
- **空格**: 自动移除
- **无效字符**: 自动检测

示例：
```
*CCO* → CCO
C C O → CCO
```

## 分子性质计算

包括以下性质（如果 `RDKit` 可用）：

- **分子式** (Molecular Formula)
- **分子量** (Molecular Weight)
- **精确质量** (Exact Mass)
- **原子数** (Atom Count)
- **重原子数** (Heavy Atom Count)
- **环数** (Ring Count)
- **芳香环数** (Aromatic Ring Count)
- **氢键供体** (H-Bond Donors)
- **氢键受体** (H-Bond Acceptors)
- **LogP** (疏水性)
- **TPSA** (拓扑极性表面积)

## 输出目录白名单

**重要**：为了能在飞书等平台上发送生成的文件，输出目录必须在白名单内：

- ✅ `~/.openclaw/media/`
- ✅ `~/.openclaw/workspace/`
- ✅ `~/.openclaw/agents/`

本 skill 默认输出到 `~/.openclaw/media/smiles-to-iupac/`，可以直接分享！

## 与其他技能配合

### 与 iupac-to-smiles 配合

```
1. smiles-to-iupac: SMILES → IUPAC 名称
2. iupac-to-smiles: IUPAC 名称 → SMILES (反向验证)
```

### 与 mol-image-to-smiles 配合

```
1. mol-image-to-smiles: 分子图片 → SMILES
2. smiles-to-iupac: SMILES → IUPAC 名称
```

### 完整工作流

```
分子图片 → mol-image-to-smiles → SMILES → smiles-to-iupac → IUPAC 名称
     ↓                              ↓
  2D 结构图                      iupac-to-smiles
     ↓                              ↓
  可视化                        IUPAC 名称（验证）
```

## 完整工作流程示例

### 示例 1: 简单分子

```bash
# 转换乙醇
python3 scripts/smiles_to_iupac.py -s "CCO"

# 输出：ethanol
```

### 示例 2: 复杂分子

```bash
# 转换阿司匹林
python3 scripts/smiles_to_iupac.py -s "CC(=O)Oc1ccccc1C(=O)O"

# 输出：2-acetyloxybenzoic acid
```

### 示例 3: 含立体化学

```bash
# 转换乳酸（R 型）
python3 scripts/smiles_to_iupac.py -s "C[C@H](O)C(=O)O"

# 输出：(2R)-2-hydroxypropanoic acid
```

### 示例 4: 聚合物单体

```bash
# 转换聚合物重复单元
python3 scripts/smiles_to_iupac.py \
  -s "*CC(C(=O)OCCCCOc1ccc(cc1)C(=O)Oc1ccc(cc1)OC)(C)*"

# 输出：InChI (聚合物不在数据库中)
```

## 技术细节

### 智能降级逻辑

```python
methods_order = ["pubchem", "nci", "stout", "inchi"]

for method in methods_order:
    result = try_method(method, smiles)
    if result["status"] == "success":
        return result  # 成功即返回
# 所有方法都失败
return error
```

### SMILES 验证

使用 RDKit 验证：

```python
from rdkit import Chem

mol = Chem.MolFromSmiles(smiles)
is_valid = mol is not None
```

### 分子性质计算

```python
from rdkit.Chem import rdMolDescriptors, Descriptors

formula = rdMolDescriptors.CalcMolFormula(mol)
mw = Descriptors.MolWt(mol)
logp = Descriptors.MolLogP(mol)
tpsa = rdMolDescriptors.CalcTPSA(mol)
```

## 注意事项

- ✅ **自动方法选择** - auto 模式智能降级
- ✅ **SMILES 验证** - 自动验证输入有效性
- ✅ **结果验证** - 建议用其他工具验证 IUPAC 名称
- ✅ **批量处理** - 支持多个 SMILES 同时转换
- ⚠️ **网络连接** - PubChem/NCI 需要网络
- ⚠️ **Docker** - STOUT 需要 Docker 运行
- ⚠️ **聚合物** - 聚合物可能返回 InChI 而非 IUPAC
- ⚠️ **超大分子** - 蛋白质等可能失败

## 错误处理

| 错误 | 说明 | 解决方案 |
|------|------|----------|
| `Invalid SMILES` | SMILES 格式错误 | 检查 SMILES 语法 |
| `PubChem API error` | API 调用失败 | 检查网络连接 |
| `NCI API error` | NCI 服务不可用 | 尝试其他方法 |
| `STOUT not installed` | STOUT 未安装 | `pip install stout` |
| `Docker not available` | Docker 未运行 | 启动 Docker 服务 |
| `All methods failed` | 所有方法失败 | 分子可能太大或不在数据库 |

## 与 iupac-to-smiles 的区别

| 特性 | iupac-to-smiles | smiles-to-iupac |
|------|-----------------|-----------------|
| 输入 | IUPAC 名称 | SMILES |
| 输出 | SMILES | IUPAC 名称/InChI |
| 核心模型 | OPSIN API | PubChem/NCI/STOUT |
| 需要网络 | 是 | 可选 |
| 转换方向 | 名称→结构 | 结构→名称 |

## 常见化合物示例

### 醇类

```
CCO → ethanol
CCCO → propan-1-ol
CC(C)O → propan-2-ol
```

### 酸类

```
CC(=O)O → acetic acid
CCC(=O)O → propanoic acid
c1ccccc1C(=O)O → benzoic acid
```

### 酯类

```
CC(=O)OCC → ethyl acetate
CC(=O)Oc1ccccc1C(=O)O → 2-acetyloxybenzoic acid
```

### 芳香族

```
c1ccccc1 → benzene
c1ccccc1O → phenol
c1ccccc1N → aniline
```

## 性能对比

| 方法 | 平均响应时间 | 成功率 | 准确率 |
|------|-------------|--------|--------|
| PubChem | ~1s | 90%+ | 95%+ |
| NCI/CADD | ~2s | 88%+ | 93%+ |
| STOUT | ~10s | 85%+ | 90%+ |
| RDKit-InChI | ~0.1s | 99%+ | 100% (InChI) |

## 未来改进

- [ ] 支持更多无机化合物
- [ ] 添加同义词支持
- [ ] 改进聚合物命名
- [ ] 添加 CAS 号查询
- [ ] 支持多语言 IUPAC 名称
- [ ] 集成更多数据源（ChEBI、ChemSpider 等）
- [ ] 添加反应式支持

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [InternScience](https://github.com/InternScience)
- **Source:** [InternScience/ChemClaw](https://github.com/InternScience/ChemClaw)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-internscience-chemclaw-smiles-to-iupac
- Seller: https://agentstack.voostack.com/s/internscience
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
