pymol-mcp
Headless PyMOL for molecular visualization, GROMACS/LAMMPS MD trajectories, and clathrate-hydrate cage analysis: H-bond networks, F3/F4 order parameters, and TRACE cage perception + occupancy.
README
<p align="center"><img src="./cover.png" width="100%" /></p>
<h1 align="center">pymol-mcp</h1> <p align="center"> <em>Headless PyMOL as an MCP server — drive molecular visualization, GROMACS/LAMMPS trajectories, and clathrate-hydrate cage science from your LLM.</em> </p> <p align="center"> <a href="#demo">Demo</a> · <a href="#quick-start">Quick Start</a> · <a href="#highlights">Highlights</a> · <a href="#features">Features</a> · <a href="#tool-catalog">Tools</a> · <a href="#domain-clathrate-hydrate-science">Cage Science</a> · <a href="./README-Ko-KR.md">한국어</a> </p> <p align="center"> <img src="https://img.shields.io/badge/license-MIT-blue" /> <img src="https://img.shields.io/badge/python-3.11%2B-green" /> <img src="https://img.shields.io/badge/PyMOL-open--source%203.x-1e40af" /> <img src="https://img.shields.io/badge/MCP-FastMCP%203-blueviolet" /> <img src="https://img.shields.io/badge/tests-passing-brightgreen" /> </p>
[!NOTE] An MCP server that embeds PyMOL in-process, headless — no GUI, no socket plugin, no manual setup. It exposes 30+ typed tools, returns rendered images inline so the model can see what it draws, loads GROMACS/LAMMPS trajectories, and ships a clathrate-hydrate analysis toolkit (H-bond networks, F3/F4 order parameters) with numerically validated science.
Demo
<p align="center"><img src="./assets/pymol-mcp-demo.gif" width="100%" /></p> <p align="center"><em>Ask in plain language → the model calls typed tools → headless PyMOL renders it. (<a href="./assets/pymol-mcp-demo.mp4">full-quality MP4</a>)</em></p>
Highlights
| Runtime | Embedded, headless pymol2 — no GUI, no plugin, no socket |
| Tools | 30+ typed tools with real, structured return values |
| Vision | ray-traced PNG returned inline so the model sees what it draws |
| MD trajectories | GROMACS .xtc/.trr + LAMMPS dump (MDAnalysis bridge) |
| Domain science | cage perception (TRACE), occupancy, H-bonds, F3/F4 — validated |
| Robustness | worker-thread session, stdout-safe transport, pytest suite |
| Safety | arbitrary-code passthrough off by default |
Features
- Embedded & headless — one long-lived PyMOL instance on a dedicated worker thread; nothing to click, works in CI.
- The model can see —
render_imageray-traces and returns a PNG as MCP image content. - MD-native — load GROMACS
.gro+.xtc, or bridge LAMMPS/NetCDF/… through MDAnalysis with in-memory coordinate injection. - Clathrate-hydrate toolkit — H-bond networks and F3/F4 order parameters ported from a validated Rust engine, all in nm with correct triclinic PBC.
- Typed, safe tools — every argument is schema-validated; the arbitrary-code passthrough is opt-in (
PYMOL_MCP_ALLOW_CODE_EXEC=1). - Protocol-hardened — PyMOL's chatty stdout is permanently redirected so it can never corrupt the JSON-RPC stream (with a subprocess test that proves it).
Quick Start
[!IMPORTANT] PyMOL open-source is a conda package, and the server must run in a Python that can
import pymol2. Install into that interpreter — do not useuvx/fastmcp install(they build isolated envs without PyMOL).
# 1. Create the environment (or reuse one that already has pymol-open-source)
conda env create -f env.yml # env named `pymol-mcp`
conda activate pymol-mcp
# 2. Install this package (with the optional MD bridge + dev tools)
pip install -e ".[md,dev]"
# 3. Verify
pytest -q
It's a standard MCP server over stdio, so it works with any MCP-capable client (Claude Code / Desktop,
Codex CLI, Gemini CLI, Cline, Continue, …). Point the command at the absolute conda interpreter so it
can import pymol2.
Most clients use an mcpServers block (Claude Code / Desktop, Gemini CLI, Cline, Continue, …):
{
"mcpServers": {
"pymol": {
"command": "/absolute/path/to/conda/envs/pymol-mcp/bin/python",
"args": ["-m", "pymol_mcp"]
}
}
}
<details> <summary><b>Codex CLI</b> — <code>~/.codex/config.toml</code></summary>
[mcp_servers.pymol]
command = "/absolute/path/to/conda/envs/pymol-mcp/bin/python"
args = ["-m", "pymol_mcp"]
</details>
Prefer not to hardcode a path? Use "command": "conda", "args": ["run", "-n", "pymol-mcp", "python", "-m", "pymol_mcp"] instead (requires conda on the client's PATH). See llms-install.md for a full from-scratch setup.
To enable the opt-in scripting tools, add "env": {"PYMOL_MCP_ALLOW_CODE_EXEC": "1"} to the server entry.
Then ask your agent things like:
Load ./hydrate.gro, color water by F4 order parameter, and render it.
Load md.gro + traj.xtc, show CO2 guests as spheres, render frame 50.
What's the mean H-bond coordination of the water in this structure?
Tool Catalog
| Group | Tools |
|---|---|
| Session / IO | load_structure · fetch_pdb · list_objects · get_object_info · reset_session |
| Selection | select · get_selection_info |
| Representation | show · hide · color · spectrum · set_background |
| View / Render | orient · zoom · turn · render_image → 🖼️ inline PNG |
| Measurement | measure_distance · measure_angle · measure_dihedral · align · save_file |
| Trajectory / MD | load_trajectory (GROMACS/DCD) · load_trajectory_mda (LAMMPS/NetCDF via MDAnalysis) |
| Clathrate domain | identify_cages (TRACE) · cage_occupancy · mark_cages · hbond_network · order_parameter (F3 / F4) |
| Scripting (opt-in) | run_pml · run_python |
Domain: clathrate-hydrate science
Ported from a validated Rust reference implementation and re-checked against ground truth. All analysis runs in
nanometres with a correct fractional-coordinate minimum-image convention (orthorhombic and triclinic),
a signed atan2 dihedral for F4, and a periodic-image KDTree for neighbour search.
identify_cages— full TRACE cage perception: ring finding → geometric validation → constraint-propagation assembly → Euler (SEC) validation → face-count typing (5¹², 5¹²6², 5¹²6⁴, …) and an sI/sII/sH structure call.cage_occupancy— assign guest molecules (CO₂/CH₄) to cages and report per-type occupancy (θ_S, θ_L).mark_cages— drop a colored sphere at each cage centre sorender_imagecan show the cage lattice.order_parameter— F4 (torsional) and F3 (three-body angular). F4 ≈ 0.7–0.95 → hydrate, ≈ 0 → liquid, ≈ −0.4 → ice Ih.hbond_network— water H-bond graph (O–O ≤ 0.36 nm and a donor H–O···O angle < 35°) with coordination stats.
<p align="center"><img src="./assets/cages_demo.png" width="66%" /><br/><em>Detected sII cages drawn as wireframe polyhedra: 5¹² dodecahedra (cyan) around a 5¹²6⁴ cage (red), sharing faces.</em></p>
[!TIP] Validated against ground truth: on a structure II reference,
identify_cagesfinds exactly **128 × 5¹²
- 64 × 5¹²6⁴** cages (the textbook 2:1 sII lattice), and on structure I exactly 16 × 5¹² + 48 × 5¹²6²; F4 over the first ten waters reproduces the reference value 0.926698 exactly, F3 = 0.0028 (hydrate-like ≤ 0.04), and the H-bond network is a perfect tetrahedral (mean coordination 4.00) framework.
How it works
MCP client (Claude · Codex · Gemini …)
│ stdio JSON-RPC
▼
┌───────────────────────────────────────────────┐
│ pymol-mcp (FastMCP, conda env with pymol2) │
│ • permanent stdout redirect (protocol-safe) │
│ • ONE worker thread owns + drives pymol2 │
│ • typed @mcp.tool functions │
└───────────────────────────────────────────────┘
│ cmd.* (headless) │ numpy / scipy (nm)
▼ ▼
PyMOL 3.x ── ray → PNG analysis/ (hbond, F3/F4)
coords via iterate_state
Requirements
| Dependency | Required | Purpose |
|---|---|---|
| Python 3.11+ (conda) | Yes | Runtime that can import pymol2 |
pymol-open-source 3.x |
Yes | The visualization engine (conda) |
fastmcp 3.x, numpy, scipy |
Yes | MCP server + analysis |
MDAnalysis |
No (extra md) |
LAMMPS / NetCDF / xtc bridge (GPL-2.0+) |
ffmpeg |
No | Movie export (future) |
Contributing
Issues and PRs welcome — see CONTRIBUTING.md.
License
MIT. The optional md extra pulls MDAnalysis (GPL-2.0-or-later), imported lazily; the core
package stays MIT.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。