Chemistry Query Agent v1.4.0
Overview
Full-stack chemistry toolkit combining PubChem data retrieval with RDKit molecule processing, visualization, analysis, retrosynthesis, and synthesis planning. All outputs are structured JSON for easy downstream chaining. Generates PNG/SVG images on demand.
Key capabilities:
- - PubChem compound lookup (info, structure, synthesis refs, similarity search)
- RDKit molecular properties (MW, logP, TPSA, HBD/HBA, rotatable bonds, aromatic rings)
- 2D molecule visualization (PNG/SVG)
- BRICS retrosynthesis with recursive depth control
- Multi-step synthesis route planning
- Forward reaction simulation with SMARTS templates
- Morgan fingerprints and similarity/substructure search
- 21 named reaction templates (Suzuki, Heck, Grignard, Wittig, Diels-Alder, etc.)
Quick Start
CODEBLOCK0
Scripts
scripts/query_pubchem.py
PubChem REST API queries with automatic name→CID resolution and timeout handling.
CODEBLOCK1
- - info: Formula, MW, IUPAC name, InChIKey (JSON)
- structure: SMILES, InChI, image URL, or full JSON
- synthesis: Synonyms/references for a compound
- similar: Similar compounds by 2D fingerprint (top 20)
scripts/rdkit_mol.py
RDKit cheminformatics engine. Resolves names via PubChem automatically.
CODEBLOCK2
| Action | Description | Key Args |
|---|
| props | MW, logP, TPSA, HBD, HBA, rotB, aromRings | INLINECODE2 |
| draw |
2D PNG/SVG (300×300) |
--smiles --output file.png --format png\|svg |
| retro | BRICS recursive retrosynthesis |
--target <SMILES\|name> --depth N |
| plan | Multi-step retro route |
--target <SMILES\|name> --steps N |
| react | Forward reaction via SMARTS |
--reactants "smi1 smi2" --smarts "<SMARTS>" |
| fingerprint | Morgan fingerprint bitvector |
--smiles --radius 2 |
| similarity | Tanimoto similarity scoring |
--query_smiles --target_smiles "smi1,smi2" |
| substruct | Substructure matching |
--query_smiles --target_smiles "smi1,smi2" |
| xyz | 3D coordinates (MMFF optimized) |
--smiles |
scripts/chain_entry.py
Standard agent chain interface. Accepts
{"smiles": "...", "context": "..."} or
{"name": "...", "context": "..."}. Returns unified JSON with props, visualization, and retrosynthesis.
CODEBLOCK3
Output schema:
CODEBLOCK4
scripts/templates.json
21 named reaction templates with SMARTS, expected yields, conditions, and references. Includes: Suzuki, Heck, Buchwald-Hartwig, Grignard, Wittig, Diels-Alder, Click, Sonogashira, Negishi, and more.
Chaining
- 1. Name → Full Profile:
chain_entry.py with {"name": "ibuprofen"} → props + draw + retro - Chemistry → Pharmacology: Output feeds directly into INLINECODE17
- Retro + Viz: Get precursors, then draw each one
- Suzuki Test: INLINECODE18
Tested With
All features verified end-to-end with RDKit 2024.03+:
| Molecule | SMILES | Tests Passed |
|---|
| Caffeine | INLINECODE19 | info, structure, props, draw, retro, plan, chain |
| Aspirin |
CC(=O)Oc1ccccc1C(=O)O | info, structure, props, draw, retro, plan, chain |
| Sotorasib | PubChem name lookup | info, structure, props, draw, retro, chain |
| Ibuprofen | PubChem name lookup | info, structure, props, chain |
| Invalid SMILES |
XXXINVALID | Graceful JSON error |
| Empty input |
{} | Graceful JSON error |
Resources
- -
references/api_endpoints.md — PubChem API endpoint reference and rate limits - INLINECODE24 — Legacy reaction module
- INLINECODE25 ,
scripts/pubmed_search.py, scripts/admet_predict.py — Additional query modules
Changelog
v1.4.0 (2026-02-14)
- - Fixed PubChem SMILES/InChI endpoint (property/CanonicalSMILES/TXT)
- Fixed chainentry.py HTML entity corruption
- Fixed bricsretro to handle BRICSDecompose string output correctly
- Added request timeouts (15s) to all PubChem calls
- Graceful error handling for invalid SMILES and empty input
- Updated chain output version and schema
- Comprehensive end-to-end testing
v1.3.0
- - RDKit props NoneType fixes, invalid SMILES graceful errors
- React fix: ReactionFromSmarts import
- Name resolution via PubChem for all RDKit actions
v1.2.0
- - BRICS retrosynthesis + 21 reaction templates library
- Multi-step synthesis planning
化学查询智能体 v1.4.0
概述
全栈化学工具包,结合PubChem数据检索与RDKit分子处理、可视化、分析、逆合成及合成规划。所有输出均为结构化JSON格式,便于下游链式调用。可按需生成PNG/SVG图像。
核心能力:
- - PubChem化合物查询(信息、结构、合成参考文献、相似性搜索)
- RDKit分子属性(分子量、logP、TPSA、氢键供体/受体数、可旋转键数、芳香环数)
- 二维分子可视化(PNG/SVG)
- BRICS逆合成与递归深度控制
- 多步合成路线规划
- 基于SMARTS模板的正向反应模拟
- Morgan指纹与相似性/子结构搜索
- 21种命名反应模板(Suzuki、Heck、Grignard、Wittig、Diels-Alder等)
快速开始
bash
PubChem化合物信息
exec python scripts/query_pubchem.py --compound aspirin --type info
从SMILES计算分子属性
exec python scripts/rdkit_mol.py --smiles CC(=O)Oc1ccccc1C(=O)O --action props
逆合成
exec python scripts/rdkit_mol.py --target CC(=O)Oc1ccccc1C(=O)O --action retro --depth 2
完整链式调用(名称 → 属性 + 绘图 + 逆合成)
exec python scripts/chain_entry.py --input-json {name: caffeine, context: user}
脚本
scripts/query_pubchem.py
PubChem REST API查询,支持自动名称→CID解析和超时处理。
--compound <名称|CID> --type [--format smiles|inchi|image|json] [--threshold 80]
- - info: 分子式、分子量、IUPAC名称、InChIKey(JSON格式)
- structure: SMILES、InChI、图像URL或完整JSON
- synthesis: 化合物的同义词/参考文献
- similar: 基于二维指纹的相似化合物(前20个)
scripts/rdkit_mol.py
RDKit化学信息学引擎。自动通过PubChem解析化合物名称。
--smiles --action
| 操作 | 描述 | 关键参数 |
|---|
| props | 分子量、logP、TPSA、氢键供体数、氢键受体数、可旋转键数、芳香环数 | --smiles |
| draw |
二维PNG/SVG图像(300×300) | --smiles --output file.png --format png\|svg |
| retro | BRICS递归逆合成 | --target
--depth N |
| plan | 多步逆合成路线 | --target --steps N |
| react | 基于SMARTS的正向反应 | --reactants smi1 smi2 --smarts |
| fingerprint | Morgan指纹位向量 | --smiles --radius 2 |
| similarity | Tanimoto相似度评分 | --querysmiles --targetsmiles smi1,smi2 |
| substruct | 子结构匹配 | --querysmiles --targetsmiles smi1,smi2 |
| xyz | 三维坐标(MMFF优化) | --smiles |
scripts/chain_entry.py
标准智能体链式调用接口。接受{smiles: ..., context: ...}或{name: ..., context: ...}格式输入。返回包含属性、可视化和逆合成的统一JSON。
bash
python scripts/chain_entry.py --input-json {name: sotorasib, context: user}
输出模式:
json
{
agent: chemistry-query,
version: 1.4.0,
smiles: <规范SMILES>,
status: success|error,
report: {props: {...}, draw: {...}, retro: {...}},
risks: [],
viz: [path/to/image.png],
recommend_next: [pharmacology, toxicology],
confidence: 0.95,
warnings: [],
timestamp: ISO8601
}
scripts/templates.json
21种命名反应模板,包含SMARTS、预期产率、反应条件和参考文献。包括:Suzuki、Heck、Buchwald-Hartwig、Grignard、Wittig、Diels-Alder、点击化学、Sonogashira、Negishi等。
链式调用
- 1. 名称 → 完整档案: chainentry.py 使用 {name: ibuprofen} → 属性 + 绘图 + 逆合成
- 化学 → 药理学: 输出直接输入到 pharma-pharmacology-agent
- 逆合成 + 可视化: 获取前体,然后绘制每个前体
- Suzuki测试: --action react --reactants c1ccccc1Br c1ccccc1B(O)O --smarts [c:1][Br:2].[c:3]B(O)O>>[c:1][c:3]
测试验证
所有功能已使用RDKit 2024.03+进行端到端验证:
| 分子 | SMILES | 通过测试 |
|---|
| 咖啡因 | CN1C=NC2=C1C(=O)N(C(=O)N2C)C | 信息、结构、属性、绘图、逆合成、规划、链式调用 |
| 阿司匹林 |
CC(=O)Oc1ccccc1C(=O)O | 信息、结构、属性、绘图、逆合成、规划、链式调用 |
| 索托拉西布 | PubChem名称查询 | 信息、结构、属性、绘图、逆合成、链式调用 |
| 布洛芬 | PubChem名称查询 | 信息、结构、属性、链式调用 |
| 无效SMILES | XXXINVALID | 优雅的JSON错误处理 |
| 空输入 | {} | 优雅的JSON错误处理 |
资源
- - references/apiendpoints.md — PubChem API端点参考和速率限制
- scripts/rdkitreaction.py — 遗留反应模块
- scripts/chemblquery.py、scripts/pubmedsearch.py、scripts/admet_predict.py — 其他查询模块
更新日志
v1.4.0(2026-02-14)
- - 修复PubChem SMILES/InChI端点(property/CanonicalSMILES/TXT)
- 修复chainentry.py中的HTML实体损坏问题
- 修复bricsretro以正确处理BRICSDecompose字符串输出
- 为所有PubChem调用添加请求超时(15秒)
- 对无效SMILES和空输入进行优雅的错误处理
- 更新链式调用输出版本和模式
- 全面的端到端测试
v1.3.0
- - RDKit属性NoneType修复,无效SMILES优雅错误处理
- 反应修复:ReactionFromSmarts导入
- 通过PubChem为所有RDKit操作添加名称解析
v1.2.0
- - BRICS逆合成 + 21种反应模板库
- 多步合成规划