ChemDraw Compound Smart Drawing MCP Tool

ChemDraw Compound Smart Drawing MCP Tool

Enables intelligent identification and validation of compound data from documents and images, then automatically draws compound structures using local ChemDraw software with academic formatting.

Category
Visit Server

README

ChemDraw 化合物智能绘制 MCP 工具

一个集成化的 MCP (Model Context Protocol) 工具,能够从文档中智能识别化合物信息,通过 PubChem 等公开数据库验证和补充化合物数据,利用视觉识别技术解析化合物结构,最终调用本地 ChemDraw 软件绘制化合物结构并输出 ChemDraw 专用格式文件。

✨ 功能特性

  • 文档化合物信息提取 - 支持 Word/PDF/Markdown/TXT 文档,中英文混合识别
  • PubChem 化合物数据查询 - 获取 SMILES、CAS 号、分子量、分子式等完整数据
  • 视觉结构识别 - 从文档图片中识别化合物结构(基于 Imago 引擎)
  • ChemDraw COM 接口调用 - 自动化绘制化合物结构,支持 Clean Up 操作
  • 多格式输出 - CDXML、CDX、PNG (300dpi)、SVG
  • 学术规范设置 - Kekulé 苯环格式、20pt 字体、手性中心标记、统一键长角度

📋 系统要求

  • 操作系统: Windows 10/11
  • Python: 3.8+
  • ChemDraw: 2020/2021/2022(需已注册 COM 对象)
  • 网络: 可访问 PubChem API

🚀 安装

# 克隆仓库
git clone https://github.com/你的用户名/Chemdraw-draw-mcp.git
cd Chemdraw-draw-mcp

# 安装依赖
pip install -r requirements.txt

依赖库

库名 用途
python-docx Word 文档解析
pdfplumber PDF 文档解析
pubchempy PubChem API 调用
pywin32 ChemDraw COM 接口
requests HTTP 请求
pillow 图片处理
opencv-python 视觉识别图片预处理
pytest 测试框架

📖 使用方法

MCP 工具调用

工具名称: draw_compound

参数说明:

参数 类型 必填 默认值 说明
input_type string - 输入类型: document/name/smiles/image
input_value string - 输入值(文档路径/化合物名称/SMILES/图片路径)
formats array ["cdxml", "png"] 输出格式列表
benzene_format string "kekule" 苯环格式: kekule/circle
font_size number 20 字体大小 (pt)
show_stereo boolean true 是否显示手性标记

调用示例:

{
  "input_type": "name",
  "input_value": "Aspirin",
  "formats": ["cdxml", "png", "svg"],
  "benzene_format": "kekule",
  "font_size": 20,
  "show_stereo": true
}

Python API 调用

from src.mcp_server import draw_compound_handler

# 从化合物名称绘制
result = draw_compound_handler({
    "input_type": "name",
    "input_value": "Aspirin",
    "formats": ["cdxml", "png"]
})

# 从SMILES绘制
result = draw_compound_handler({
    "input_type": "smiles",
    "input_value": "CC(=O)OC1=CC=CC=C1C(=O)O"
})

# 从文档批量提取并绘制
result = draw_compound_handler({
    "input_type": "document",
    "input_value": "path/to/compounds.docx"
})

📁 项目结构

Chemdraw-draw-mcp/
├── src/
│   ├── parsers/              # 文档化合物信息提取模块
│   │   ├── word_parser.py
│   │   ├── pdf_parser.py
│   │   ├── markdown_parser.py
│   │   └── compound_identifier.py
│   ├── query/                # PubChem 化合物查询模块
│   │   └── pubchem_client.py
│   ├── visual/               # 视觉结构识别模块
│   │   ├── image_preprocessor.py
│   │   ├── structure_recognizer.py
│   │   ├── imago_recognizer.py
│   │   └── fallback_recognizer.py
│   ├── draw/                 # ChemDraw COM 接口模块
│   │   └── chemdraw_com.py
│   ├── output/               # 格式输出模块
│   │   └── format_exporter.py
│   ├── specs/                # 学术规范设置模块
│   │   └── academic_specs.py
│   └── mcp_server.py         # MCP 服务核心
├── tools/
│   └── draw_compound.json    # MCP 工具定义
├── tests/                    # 测试文件
├── requirements.txt
└── setup.py

🧪 测试

# 运行所有测试
pytest

# 运行特定模块测试
pytest tests/test_parsers.py
pytest tests/test_pubchem.py
pytest tests/test_chemdraw.py

# 运行集成测试
pytest tests/test_integration.py

# 运行性能测试
pytest tests/test_performance.py

📊 处理流程

输入 → 解析/查询 → 获取SMILES → ChemDraw绘制 → 学术规范应用 → 格式导出
  1. 文档输入: 解析 Word/PDF/Markdown → 识别化合物名称
  2. 名称输入: 查询 PubChem → 获取 SMILES
  3. SMILES输入: 直接使用
  4. 图片输入: 视觉识别 → 获取 SMILES
  5. 绘制: 调用 ChemDraw COM → 绘制结构 → Clean Up
  6. 规范: Kekulé 格式 → 20pt 字体 → 手性标记
  7. 输出: CDXML/CDX/PNG/SVG

🔧 MCP 配置

在 TRAE 或 Codex 中配置 MCP 服务:

{
  "mcpServers": {
    "chemdraw-draw": {
      "command": "python",
      "args": ["path/to/Chemdraw-draw-mcp/src/mcp_server.py"],
      "env": {}
    }
  }
}

📝 返回数据格式

{
  "success": true,
  "compounds": [
    {
      "name": "Aspirin",
      "chinese_name": "阿司匹林",
      "smiles": "CC(=O)OC1=CC=CC=C1C(=O)O",
      "cas": "50-78-2",
      "molecular_weight": 180.16,
      "formula": "C9H8O4"
    }
  ],
  "files": [
    "output/compound_1_Aspirin.cdxml",
    "output/compound_1_Aspirin.png"
  ],
  "message": "成功绘制 1 个化合物"
}

⚠️ 注意事项

  • 确保 ChemDraw 已正确安装并注册 COM 对象
  • 首次使用时 ChemDraw 可能会弹出安全提示,请允许程序访问
  • PubChem 查询需要网络连接
  • 输出文件默认保存在 output/ 目录

📄 许可证

MIT License

🤝 贡献

欢迎提交 Issue 和 Pull Request!

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured