pymol

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PyMOL

PyMOL

Prerequisites

前提条件

  1. uv
    : Read the
    uv
    skill and follow its Setup instructions to ensure
    uv
    is installed and on PATH.
  2. User Notification: If LICENSE_NOTIFICATION.txt does not already exist in this skill directory then (1) prominently notify the user to check the license at https://www.pymol.org/, then (2) create the file recording the notification text and timestamp.
  1. uv
    :阅读
    uv
    技能文档并遵循其设置说明,确保
    uv
    已安装且在PATH路径中。
  2. 用户通知:若此技能目录中不存在LICENSE_NOTIFICATION.txt文件,则需(1)显著通知用户查看https://www.pymol.org/上的许可证信息,然后(2)创建该文件并记录通知文本及时间戳。

Overview

概述

All PyMOL commands run on the host via
uv
with OSMesa software rendering — no GPU, display, or X server is needed. Structure files must be downloaded to the host before running PyMOL.
Do NOT use when:
  • The user wants to run AlphaFold predictions.
  • The user wants docking or molecular dynamics simulations.
  • The user only has a sequence and no structure file — fetch the structure first. Check if any other installed skills can retrieve structures from the PDB or AlphaFold Database before proceeding.
所有PyMOL命令通过
uv
在主机上运行,使用OSMesa软件渲染——无需GPU、显示器或X服务器。运行PyMOL前需将结构文件下载至主机。
请勿在以下场景使用:
  • 用户需要运行AlphaFold预测。
  • 用户需要进行对接或分子动力学模拟。
  • 用户仅拥有序列而无结构文件——需先获取结构。在继续操作前,检查是否有其他已安装技能可从PDB或AlphaFold Database检索结构。

Setup (Agent Instructions)

设置(Agent操作说明)

Ensure that
uv
is installed on the host system. The PyMOL scripts use PEP 0723 headers to declare their dependencies, and
uv run
will automatically handle installing them (including
pymol-open-source-whl
) when the script is executed.
确保主机系统已安装
uv
。PyMOL脚本使用PEP 0723头声明依赖项,执行脚本时
uv run
会自动处理依赖安装(包括
pymol-open-source-whl
)。

Core Rules

核心规则

  • Output paths must be absolute or relative to the user's project root. Always run PyMOL scripts from the user's project directory.
  • Software rendering only. Use
    cmd.png()
    for output. Never use
    cmd.draw()
    or
    cmd.ray()
    with hardware acceleration — OSMesa does not support it. Set environment variable
    PYOPENGL_PLATFORM=osmesa
    for headless rendering.
  • Always save a
    .pse
    session file
    alongside any PNG output. This lets the user open the session in their local PyMOL for further inspection.
  • Always call
    cmd.quit()
    at the end of every PyMOL script. Omitting it causes the process to stop responding.
  • Init boilerplate is mandatory. Every PyMOL script must begin with the initialization sequence.
    from pymol import cmd
    must come after
    finish_launching()
    , not before.
  • See references/PYMOL_REFERENCE.md for selection syntax, common commands, and gotchas.
  • Pre-Flight File Check: Before writing the PyMOL script or running it, you MUST verify that the requested structure file actually exists on the host machine.
  • Verify Structure Load: After loading a structure with
    cmd.load()
    , always verify it succeeded by checking
    cmd.count_atoms("all")
    . If the result is 0, print an error to stdout and call
    cmd.quit()
    immediately.
  • Notification: If this skill is used, ensure this is mentioned in the output.
  • **输出路径必须为绝对路径或相对于用户项目根目录的路径。**始终从用户项目目录运行PyMOL脚本。
  • **仅使用软件渲染。**使用
    cmd.png()
    生成输出。切勿使用
    cmd.draw()
    或带硬件加速的
    cmd.ray()
    ——OSMesa不支持该功能。设置环境变量
    PYOPENGL_PLATFORM=osmesa
    以实现无界面渲染。
  • 始终保存
    .pse
    会话文件
    ,与PNG输出放在一起。这样用户可在本地PyMOL中打开会话进行进一步检查。
  • 每个PyMOL脚本末尾必须调用
    cmd.quit()
    。省略该命令会导致进程停止响应。
  • **初始化模板是必填项。**每个PyMOL脚本必须以初始化序列开头。
    from pymol import cmd
    必须在
    finish_launching()
    之后导入,而非之前。
  • 有关选择语法、常用命令及注意事项,请参阅references/PYMOL_REFERENCE.md
  • 运行前文件检查:在编写或运行PyMOL脚本前,必须确认请求的结构文件确实存在于主机上。
  • 验证结构加载:使用
    cmd.load()
    加载结构后,务必通过检查
    cmd.count_atoms("all")
    验证加载是否成功。若结果为0,向标准输出打印错误信息并立即调用
    cmd.quit()
  • 通知:若使用此技能,需在输出中提及这一点。

Quick Start

快速开始

  • Ensure structure files are downloaded to a directory in the user's project.
  • Write a PyMOL Python script (e.g.,
    render.py
    ) with the required init boilerplate and PEP 0723 header.
  • Run it via
    uv run
    :
    bash uv run render.py
  • 确保结构文件已下载至用户项目中的某个目录。
  • 编写PyMOL Python脚本(例如
    render.py
    ),包含所需的初始化模板和PEP 0723头。
  • 通过
    uv run
    运行脚本:
    bash uv run render.py

Minimal example script (
render.py
)

最小示例脚本(
render.py

python
undefined
python
undefined

/// script

/// script

requires-python = ">=3.10, <3.13"

requires-python = ">=3.10, <3.13"

dependencies = [

dependencies = [

"pymol-open-source-whl",

"pymol-open-source-whl",

]

]

///

///

import os import sys
import os import sys

Set environment variable for headless rendering

Set environment variable for headless rendering

os.environ["PYOPENGL_PLATFORM"] = "osmesa"
import pymol # pytype: disable=import-error pymol.pymol_argv = ["pymol", "-cq"] pymol.finish_launching()
from pymol import cmd # pytype: disable=import-error
cmd.load("AF-P00520-F1-model_v4.cif", "structure") cmd.show("cartoon") cmd.color("green", "ss h") cmd.color("yellow", "ss s") cmd.color("gray", "ss l+''") cmd.orient() cmd.set("ray_opaque_background", 1) cmd.png("output/render.png", width=1200, height=900, dpi=150) cmd.save("output/session.pse") cmd.quit()
undefined
os.environ["PYOPENGL_PLATFORM"] = "osmesa"
import pymol # pytype: disable=import-error pymol.pymol_argv = ["pymol", "-cq"] pymol.finish_launching()
from pymol import cmd # pytype: disable=import-error
cmd.load("AF-P00520-F1-model_v4.cif", "structure") cmd.show("cartoon") cmd.color("green", "ss h") cmd.color("yellow", "ss s") cmd.color("gray", "ss l+''") cmd.orient() cmd.set("ray_opaque_background", 1) cmd.png("output/render.png", width=1200, height=900, dpi=150) cmd.save("output/session.pse") cmd.quit()
undefined

Common Recipes

常用示例

See references/RECIPES.md for complete, copy-paste ready recipes. Available recipes:
  • Cartoon with secondary structure coloring — basic helix/sheet/loop coloring
  • B-factor (pLDDT) coloring — continuous spectrum coloring by B-factor
  • AlphaFold pLDDT coloring — canonical threshold-based confidence colors
  • Highlight specific residues — show active site or key residues as sticks
  • Surface rendering — transparent surface over cartoon
  • Electrostatic surface rendering — vacuum electrostatics (qualitative)
  • Multi-chain complex colors — automatic per-chain coloring
  • B-factor putty analysis — tube width proportional to flexibility
  • Cavity and pocket visualization — surface cavity detection with ligand focus
  • Multi-structure batch rendering — render a directory of structures
  • Measure distance between residues — CA–CA distance with labels
  • Zoom into binding pocket — simple pocket focus
  • Protein-ligand interaction — ligand isolation, styled rendering, polar contacts
  • Two-structure superposition with RMSD — align/cealign with auto-fallback
  • In silico mutagenesis — mutate residues with the mutagenesis wizard
  • Load and modify an existing session — re-open a
    .pse
    file
完整的可复制示例请参阅references/RECIPES.md。可用示例包括:
  • 二级结构上色卡通图——基础螺旋/片层/环上色
  • B因子(pLDDT)上色——按B因子进行连续光谱上色
  • AlphaFold pLDDT上色——标准阈值置信度颜色
  • 突出特定残基——将活性位点或关键残基显示为棒状
  • 表面渲染——卡通图上叠加透明表面
  • 静电表面渲染——真空静电(定性)
  • 多链复合物上色——自动按链上色
  • B因子putty分析——管宽与灵活性成正比
  • 空腔与口袋可视化——以配体为焦点的表面空腔检测
  • 多结构批量渲染——渲染目录中的所有结构
  • 测量残基间距离——带标签的CA-CA距离
  • 放大结合口袋——简单的口袋聚焦
  • 蛋白质-配体相互作用——配体分离、风格化渲染、极性接触
  • 两结构叠加与RMSD——align/cealign自动回退
  • 虚拟诱变——使用诱变向导突变残基
  • 加载并修改现有会话——重新打开
    .pse
    文件

Interpreting Output

输出解读

  • The
    output/
    directory contains PNG images and a
    .pse
    session file.
  • Any measurements or metrics (distances, RMSD, atom counts) are printed to stdout by the PyMOL script. Report these values to the user.
  • Present PNG images to the user and describe the visualization.
  • Tell the user they can open the
    .pse
    file in their local PyMOL to further explore, rotate, or modify the visualization.
  • If the user wants modifications, load the saved
    .pse
    in a new script and re-run.
  • Large sessions with surfaces can exceed the
    --max_output_mb
    limit (default 500 MB). Increase it with
    --max_output_mb=1000
    if needed.
  • output/
    目录包含PNG图像和
    .pse
    会话文件。
  • 所有测量值或指标(距离、RMSD、原子数)由PyMOL脚本打印至标准输出。需将这些数值告知用户。
  • 向用户展示PNG图像并描述可视化内容。
  • 告知用户可在本地PyMOL中打开
    .pse
    文件,进一步探索、旋转或修改可视化效果。
  • 若用户需要修改,在新脚本中加载保存的
    .pse
    并重新运行。
  • 包含表面的大型会话可能会超出
    --max_output_mb
    限制(默认500 MB)。如有需要,可使用
    --max_output_mb=1000
    提高限制。