pymol
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePyMOL: 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 Category | Examples |
|---|---|
| Setup | Install PyMOL, configure claudemol, verify connection |
| Structure Loading | Load PDB files, fetch from RCSB, open local structures |
| Representations | Cartoon, surface, sticks, spheres, ribbons, lines |
| Coloring | Color by chain, spectrum, B-factor, custom colors |
| Selections | Select residues, chains, ligands, binding sites |
| Camera | Orient view, zoom, rotate, save viewpoints |
| Ray Tracing | High-quality renders, publication figures |
| Export | Save 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.pyManual Setup
手动配置
1. Install claudemol
1. 安装claudemol
bash
pip install claudemolbash
pip install claudemol2. Install PyMOL
2. 安装PyMOL
macOS (Recommended):
bash
brew install pymolWindows/Linux (Headless):
bash
pip install pymol-open-sourceWindows (Licensed PyMOL):
Connect to existing PyMOL installation - see
references/troubleshooting.mdmacOS(推荐方式):
bash
brew install pymolWindows/Linux(无界面模式):
bash
pip install pymol-open-sourceWindows(授权版PyMOL):
连接已安装的PyMOL - 详见
references/troubleshooting.md3. Configure PyMOL
3. 配置PyMOL
bash
claudemol setupThis adds the socket plugin to PyMOL's startup.
bash
claudemol setup此操作会将套接字插件添加到PyMOL的启动项中。
4. Launch and Verify
4. 启动与验证
- Start PyMOL normally
- Check that port 9880 is listening:
bash
lsof -i :9880 # macOS/Linux netstat -an | findstr 9880 # Windows
- 正常启动PyMOL
- 检查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
undefinedpython
undefinedFrom 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')
undefinedcmd.fetch('1ubq')
cmd.fetch('6lu7', type='cif')
undefinedRepresentations
结构展示方式
python
undefinedpython
undefinedShow 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')
undefinedcmd.hide('lines', 'all')
cmd.hide('everything', 'solvent')
undefinedColoring
着色
python
undefinedpython
undefinedColor 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')
undefinedcmd.spectrum('b', 'blue_white_red', 'all')
undefinedSelections
选区
python
undefinedpython
undefinedCreate 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')
undefinedcmd.select('no_water', 'all and not solvent')
undefinedView and Camera
视角与相机控制
python
undefinedpython
undefinedOrient 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')
undefinedcmd.view('view1', 'store')
cmd.view('view1', 'recall')
undefinedRay Tracing and Export
光线追踪与导出
python
undefinedpython
undefinedBasic 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)
undefinedcmd.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)
undefinedVisualization Workflows
可视化工作流
See for complete workflows:
references/visualization.md- Basic protein visualization
- Cartoon with chain coloring
- Surface with transparency
- Ligand binding site
- Domain highlighting
- Publication-quality figures
完整工作流请参考:
references/visualization.md- 基础蛋白质可视化
- 带链着色的卡通模型
- 带透明度的表面模型
- 配体结合位点展示
- 结构域高亮
- 学术发表级图像生成
Command Reference
命令参考
See for complete command documentation:
references/commands.md- All functions
cmd.* - Selection syntax
- Setting parameters
- Color palettes
完整命令文档请参考:
references/commands.md- 所有函数
cmd.* - 选区语法
- 参数设置
- 颜色调色板
Troubleshooting
故障排查
See for platform-specific issues:
references/troubleshooting.md- macOS GLUT errors
- Windows headless mode
- Connection refused errors
- Display problems
平台特定问题请参考:
references/troubleshooting.md- macOS GLUT错误
- Windows无界面模式问题
- 连接被拒绝错误
- 显示问题
Common Issues
常见问题
| Issue | Resolution |
|---|---|
| Connection refused | Ensure PyMOL is running with claudemol plugin loaded |
| Port 9880 in use | Kill 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 tracing | Reduce resolution or simplify scene |
| 问题 | 解决方法 |
|---|---|
| 连接被拒绝 | 确保PyMOL已运行且加载了claudemol插件 |
| 9880端口被占用 | 终止其他占用该端口的进程或修改端口 |
| 无GUI界面(Windows pip安装版) | 使用无界面模式或安装授权版PyMOL |
| macOS缺失GLUT | 使用Homebrew安装而非pip |
| 光线追踪速度慢 | 降低分辨率或简化场景 |
External Resources
外部资源
- PyMOL Documentation: https://pymol.org/dokuwiki/
- PyMOL Wiki: https://pymolwiki.org/
- claudemol GitHub: https://github.com/colorifix/claudemol
- Open-Source PyMOL: https://github.com/schrodinger/pymol-open-source
- PyMOL官方文档:https://pymol.org/dokuwiki/
- PyMOL维基:https://pymolwiki.org/
- claudemol GitHub仓库:https://github.com/colorifix/claudemol
- 开源版PyMOL:https://github.com/schrodinger/pymol-open-source