pymol

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PyMOL: Molecular Visualization via claudemol

PyMOL:通过claudemol实现分子可视化

Summary

概述

This skill enables Claude Code to control PyMOL molecular visualization software through the claudemol socket interface. It supports:
  • Setup: Cross-platform installation of claudemol and PyMOL
  • Visualization: Rendering proteins, small molecules, and complexes
  • Publication figures: Ray-traced high-resolution images
  • Interactive control: Send PyMOL commands programmatically
本技能允许Claude Code通过claudemol套接字接口控制PyMOL分子可视化软件,支持:
  • 配置:跨平台安装claudemol和PyMOL
  • 可视化:渲染蛋白质、小分子和复合物
  • 学术发表用图像:光线追踪生成高分辨率图像
  • 交互式控制:以编程方式发送PyMOL命令

Applicable Scenarios

适用场景

Task CategoryExamples
SetupInstall PyMOL, configure claudemol, verify connection
Structure LoadingLoad PDB files, fetch from RCSB, open local structures
RepresentationsCartoon, surface, sticks, spheres, ribbons, lines
ColoringColor by chain, spectrum, B-factor, custom colors
SelectionsSelect residues, chains, ligands, binding sites
CameraOrient view, zoom, rotate, save viewpoints
Ray TracingHigh-quality renders, publication figures
ExportSave images (PNG), sessions (PSE), movies
任务类别示例
配置安装PyMOL、配置claudemol、验证连接
结构加载加载PDB文件、从RCSB获取结构、打开本地结构
结构展示方式卡通模型、表面模型、棍状模型、球状模型、带状模型、线状模型
着色按链着色、光谱着色、B因子着色、自定义颜色
选区选择残基、链、配体、结合位点
视角控制调整视角、缩放、旋转、保存视角
光线追踪高质量渲染、学术发表用图像
导出保存图像(PNG)、会话(PSE)、动画

Setup Instructions

配置指南

Quick Setup (All Platforms)

快速配置(全平台)

Run the automated setup script:
bash
python /path/to/skills/pymol/scripts/setup_pymol.py
运行自动化配置脚本:
bash
python /path/to/skills/pymol/scripts/setup_pymol.py

Manual Setup

手动配置

1. Install claudemol

1. 安装claudemol

bash
pip install claudemol
bash
pip install claudemol

2. Install PyMOL

2. 安装PyMOL

macOS (Recommended):
bash
brew install pymol
Windows/Linux (Headless):
bash
pip install pymol-open-source
Windows (Licensed PyMOL): Connect to existing PyMOL installation - see
references/troubleshooting.md
macOS(推荐方式):
bash
brew install pymol
Windows/Linux(无界面模式):
bash
pip install pymol-open-source
Windows(授权版PyMOL): 连接已安装的PyMOL - 详见
references/troubleshooting.md

3. Configure PyMOL

3. 配置PyMOL

bash
claudemol setup
This adds the socket plugin to PyMOL's startup.
bash
claudemol setup
此操作会将套接字插件添加到PyMOL的启动项中。

4. Launch and Verify

4. 启动与验证

  1. Start PyMOL normally
  2. Check that port 9880 is listening:
    bash
    lsof -i :9880  # macOS/Linux
    netstat -an | findstr 9880  # Windows
  1. 正常启动PyMOL
  2. 检查9880端口是否处于监听状态:
    bash
    lsof -i :9880  # macOS/Linux
    netstat -an | findstr 9880  # Windows

Socket Communication

套接字通信

claudemol communicates with PyMOL via a TCP socket on port 9880.
claudemol通过9880端口的TCP套接字与PyMOL通信。

Basic Pattern

基础模式

python
import socket
import json

def send_pymol_command(code: str, host: str = 'localhost', port: int = 9880) -> dict:
    """Send a command to PyMOL via claudemol socket."""
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(30)
    try:
        sock.connect((host, port))
        message = json.dumps({"code": code})
        sock.sendall(message.encode('utf-8'))
        response = sock.recv(65536)
        return json.loads(response.decode('utf-8'))
    finally:
        sock.close()
python
import socket
import json

def send_pymol_command(code: str, host: str = 'localhost', port: int = 9880) -> dict:
    """Send a command to PyMOL via claudemol socket."""
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(30)
    try:
        sock.connect((host, port))
        message = json.dumps({"code": code})
        sock.sendall(message.encode('utf-8'))
        response = sock.recv(65536)
        return json.loads(response.decode('utf-8'))
    finally:
        sock.close()

Multi-Command Example

多命令示例

python
commands = """
cmd.load('1ubq.pdb')
cmd.show('cartoon')
cmd.color('cyan', 'all')
cmd.orient()
"""
result = send_pymol_command(commands)
python
commands = """
cmd.load('1ubq.pdb')
cmd.show('cartoon')
cmd.color('cyan', 'all')
cmd.orient()
"""
result = send_pymol_command(commands)

Quick Reference

快速参考

Loading Structures

加载结构

python
undefined
python
undefined

From local file

从本地文件加载

cmd.load('/path/to/structure.pdb') cmd.load('/path/to/structure.cif')
cmd.load('/path/to/structure.pdb') cmd.load('/path/to/structure.cif')

From RCSB PDB

从RCSB PDB数据库获取

cmd.fetch('1ubq') cmd.fetch('6lu7', type='cif')
undefined
cmd.fetch('1ubq') cmd.fetch('6lu7', type='cif')
undefined

Representations

结构展示方式

python
undefined
python
undefined

Show representations

展示模型

cmd.show('cartoon', 'all') cmd.show('surface', 'chain A') cmd.show('sticks', 'resn LIG') cmd.show('spheres', 'name CA')
cmd.show('cartoon', 'all') cmd.show('surface', 'chain A') cmd.show('sticks', 'resn LIG') cmd.show('spheres', 'name CA')

Hide representations

隐藏模型

cmd.hide('lines', 'all') cmd.hide('everything', 'solvent')
undefined
cmd.hide('lines', 'all') cmd.hide('everything', 'solvent')
undefined

Coloring

着色

python
undefined
python
undefined

Color by chain (automatic colors)

按链自动着色

cmd.util.cbc()
cmd.util.cbc()

Spectrum coloring (rainbow N to C)

光谱着色(从N端到C端彩虹色)

cmd.spectrum('count', 'rainbow', 'all')
cmd.spectrum('count', 'rainbow', 'all')

Specific colors

指定颜色

cmd.color('red', 'chain A') cmd.color('blue', 'resn LIG') cmd.color('green', 'resi 50-100')
cmd.color('red', 'chain A') cmd.color('blue', 'resn LIG') cmd.color('green', 'resi 50-100')

B-factor coloring

基于B因子着色

cmd.spectrum('b', 'blue_white_red', 'all')
undefined
cmd.spectrum('b', 'blue_white_red', 'all')
undefined

Selections

选区

python
undefined
python
undefined

Create named selections

创建命名选区

cmd.select('binding_site', 'byres resn LIG around 5') cmd.select('active_site', 'resi 145+41+166 and chain A') cmd.select('interface', 'chain A within 4 of chain B')
cmd.select('binding_site', 'byres resn LIG around 5') cmd.select('active_site', 'resi 145+41+166 and chain A') cmd.select('interface', 'chain A within 4 of chain B')

Selection algebra

选区运算

cmd.select('no_water', 'all and not solvent')
undefined
cmd.select('no_water', 'all and not solvent')
undefined

View and Camera

视角与相机控制

python
undefined
python
undefined

Orient and zoom

调整方向与缩放

cmd.orient() cmd.zoom('all') cmd.zoom('chain A', buffer=5) cmd.center('resn LIG')
cmd.orient() cmd.zoom('all') cmd.zoom('chain A', buffer=5) cmd.center('resn LIG')

Set specific view

设置特定视角

cmd.set_view([...]) # 18-element matrix
cmd.set_view([...]) # 18元素矩阵

Store and recall views

保存与调用视角

cmd.view('view1', 'store') cmd.view('view1', 'recall')
undefined
cmd.view('view1', 'store') cmd.view('view1', 'recall')
undefined

Ray Tracing and Export

光线追踪与导出

python
undefined
python
undefined

Basic ray trace

基础光线追踪

cmd.ray(1920, 1080) cmd.png('/path/to/output.png')
cmd.ray(1920, 1080) cmd.png('/path/to/output.png')

Publication quality

学术发表级质量

cmd.set('ray_trace_mode', 1) cmd.set('ray_shadows', 'on') cmd.set('antialias', 2) cmd.ray(2400, 2400) cmd.png('/path/to/figure.png', dpi=300)
undefined
cmd.set('ray_trace_mode', 1) cmd.set('ray_shadows', 'on') cmd.set('antialias', 2) cmd.ray(2400, 2400) cmd.png('/path/to/figure.png', dpi=300)
undefined

Visualization Workflows

可视化工作流

See
references/visualization.md
for complete workflows:
  • Basic protein visualization
  • Cartoon with chain coloring
  • Surface with transparency
  • Ligand binding site
  • Domain highlighting
  • Publication-quality figures
完整工作流请参考
references/visualization.md
  • 基础蛋白质可视化
  • 带链着色的卡通模型
  • 带透明度的表面模型
  • 配体结合位点展示
  • 结构域高亮
  • 学术发表级图像生成

Command Reference

命令参考

See
references/commands.md
for complete command documentation:
  • All
    cmd.*
    functions
  • Selection syntax
  • Setting parameters
  • Color palettes
完整命令文档请参考
references/commands.md
  • 所有
    cmd.*
    函数
  • 选区语法
  • 参数设置
  • 颜色调色板

Troubleshooting

故障排查

See
references/troubleshooting.md
for platform-specific issues:
  • macOS GLUT errors
  • Windows headless mode
  • Connection refused errors
  • Display problems
平台特定问题请参考
references/troubleshooting.md
  • macOS GLUT错误
  • Windows无界面模式问题
  • 连接被拒绝错误
  • 显示问题

Common Issues

常见问题

IssueResolution
Connection refusedEnsure PyMOL is running with claudemol plugin loaded
Port 9880 in useKill other processes or change port
No GUI (Windows pip)Use headless mode or licensed PyMOL
GLUT missing (macOS)Install via Homebrew instead of pip
Slow ray tracingReduce resolution or simplify scene
问题解决方法
连接被拒绝确保PyMOL已运行且加载了claudemol插件
9880端口被占用终止其他占用该端口的进程或修改端口
无GUI界面(Windows pip安装版)使用无界面模式或安装授权版PyMOL
macOS缺失GLUT使用Homebrew安装而非pip
光线追踪速度慢降低分辨率或简化场景

External Resources

外部资源