pymol-hyperpowers 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pymol_hyperpowers-0.2.0/PKG-INFO +146 -0
- pymol_hyperpowers-0.2.0/README.md +138 -0
- pymol_hyperpowers-0.2.0/pyproject.toml +119 -0
- pymol_hyperpowers-0.2.0/pyproject.toml.orig +90 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/__init__.py +5 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/app.py +129 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/claims.py +571 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/cli.py +306 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/client.py +436 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/plugin.py +2323 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/protocol.py +78 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/registry.py +223 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/selection.py +185 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/__init__.py +1 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/align.py +71 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/escape.py +47 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/geometry.py +40 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/images.py +98 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/io.py +129 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/query.py +165 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/session.py +99 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/tools/view.py +30 -0
- pymol_hyperpowers-0.2.0/src/pymol_hyperpowers/types.py +128 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pymol-hyperpowers
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: MCP server and PyMOL plugin that let agents control any open PyMOL session.
|
|
5
|
+
Requires-Dist: mcp>=2.3,<2.4
|
|
6
|
+
Requires-Python: >=3.12
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
|
|
9
|
+
# pymol-hyperpowers
|
|
10
|
+
|
|
11
|
+
An MCP server and PyMOL plugin that let agents in Claude Code, Codex and Antigravity control any open PyMOL session.
|
|
12
|
+
|
|
13
|
+
Each PyMOL that runs the plugin announces itself under a scientist's name when it starts:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
pymol-hyperpowers: this session is "Franklin" (127.0.0.1:50123)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The window title shows the same name. An agent lists the open sessions (newest first) with `list_sessions` and picks one with `use_session`; the listing also shows which other agent conversations are using each session. With one session open, tools use it without asking, unless another conversation is already using it, in which case the call asks the agent to call `use_session` to share it or to ask you. With several open and none chosen, a tool call fails with the list and asks the agent to choose or to ask you.
|
|
20
|
+
|
|
21
|
+
The package contains no prescriptive science. It gives an agent PyMOL's commands and data, and leaves the science to the agent and to you.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
Requires [uv](https://docs.astral.sh/uv/) and PyMOL 3 (which embeds Python 3.10 or newer).
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
uv tool install pymol-hyperpowers
|
|
29
|
+
pymol-hyperpowers install-plugin
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The first command installs the MCP server and the plugin together. `install-plugin` adds a marked block to `~/.pymolrc.py` that loads the plugin from that installation whenever PyMOL starts; restart PyMOL afterwards. Re-running it rewrites the block in place. `uninstall-plugin` removes the block and leaves the rest of the file alone. Your `~/.pymolrc` is not touched; PyMOL reads every `~/.pymolrc*` file. Both commands take `--pymolrc PATH` to edit another file.
|
|
33
|
+
|
|
34
|
+
To start the plugin in one PyMOL without the rc block, run `pymol -r "$(pymol-hyperpowers plugin-path)"`.
|
|
35
|
+
|
|
36
|
+
### Updating
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
uv tool upgrade pymol-hyperpowers
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This one command updates both halves: PyMOL loads the plugin file inside the installed package, so upgrading the package replaces the plugin too. Then restart PyMOL so it loads the new plugin, and restart your agent sessions so their servers load the new code. `list_sessions` and `pymol-hyperpowers sessions` add a note to any session whose plugin version differs from the server's, saying which of the two to restart.
|
|
43
|
+
|
|
44
|
+
The plugin's path includes the tool's Python version, so reinstalling the tool on another Python moves the file. When the server starts and finds that the block in `~/.pymolrc.py` loads a file that no longer exists, it points the block at its own plugin and says so; restart PyMOL once more to load it. A block that loads a file that still exists, such as a development checkout, is left alone.
|
|
45
|
+
|
|
46
|
+
## Register the server with your agent
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
claude mcp add --scope user pymol -- ~/.local/bin/pymol-hyperpowers
|
|
50
|
+
codex mcp add pymol -- ~/.local/bin/pymol-hyperpowers
|
|
51
|
+
agy mcp add pymol ~/.local/bin/pymol-hyperpowers
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`pymol-hyperpowers sessions` prints the sessions the server can see, newest first, with the conversations using each and their process IDs, for checking from a terminal.
|
|
55
|
+
|
|
56
|
+
### Agents running without prompts
|
|
57
|
+
|
|
58
|
+
`codex exec` and `agy -p` cannot ask you to approve a tool call, so a pymol tool that needs approval fails instead of running. Approve the pymol tools beforehand. This includes `run`, which executes arbitrary Python inside PyMOL with your permissions.
|
|
59
|
+
|
|
60
|
+
- Codex: add `default_tools_approval_mode = "approve"` under `[mcp_servers.pymol]` in `~/.codex/config.toml`, or pass it for one run with `codex exec -c 'mcp_servers.pymol.default_tools_approval_mode="approve"' ...`. To approve only some tools, set `mcp_servers.pymol.tools.<tool>.approval_mode = "approve"` for each.
|
|
61
|
+
- Antigravity: add `"mcp(pymol/*)"` to `permissions.allow` in `~/.gemini/antigravity-cli/settings.json`, and remove any `permissions.ask` rule that matches the pymol tools. An ask rule wins over an allow rule, and `agy -p` cannot answer it. For one run, pass `agy --settings '{"permissions":{"allow":["mcp(pymol/*)"],"ask":[]}}' -p ...`: each list given there replaces the saved one, so the empty `ask` list lifts every saved ask rule for that run, not only the pymol ones.
|
|
62
|
+
|
|
63
|
+
### Coexistence with agentic-pymol
|
|
64
|
+
|
|
65
|
+
The two plugins use different rc files, ports and state directories, so both can run in one PyMOL. They clash only on the MCP server name `pymol`: when switching, remove agentic-pymol's registration first (for example `claude mcp remove pymol`), or register this server under another name, such as `pymol-hp`, while you try it.
|
|
66
|
+
|
|
67
|
+
## Tools
|
|
68
|
+
|
|
69
|
+
| Group | Tools |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Sessions | `list_sessions`, `use_session`, `status` |
|
|
72
|
+
| Commands | `do` (PyMOL command language, one command per line), `run` (Python inside PyMOL) |
|
|
73
|
+
| Query | `iterate`, `alter`, `get_model`, `get_fastastr`, `get_coords`, `get_chains`, `get_names`, `get_object_list`, `count_atoms`, `count_states`, `get_extent`, `select` |
|
|
74
|
+
| Geometry | `get_distance`, `get_angle`, `get_dihedral`, `get_area` |
|
|
75
|
+
| Alignment | `align`, `cealign`, `rms` |
|
|
76
|
+
| View | `get_view`, `set_view` |
|
|
77
|
+
| Files | `fetch`, `load`, `save` |
|
|
78
|
+
| Images | `render` (PNG file), `screenshot` (PNG returned to the agent) |
|
|
79
|
+
|
|
80
|
+
Display work (`show`, `color`, `label`, settings, scenes, movies) goes through `do`. `run` executes arbitrary Python inside PyMOL with your permissions.
|
|
81
|
+
|
|
82
|
+
## PyMOL commands
|
|
83
|
+
|
|
84
|
+
- `mcp_status`: the session name, port, state file and connected clients.
|
|
85
|
+
- `mcp_stop`: stop listening and revoke every agent's access to this PyMOL.
|
|
86
|
+
- `mcp_start`: listen again, under a new name.
|
|
87
|
+
|
|
88
|
+
The plugin listens on 127.0.0.1 only, and every request must carry the session's token, which is stored in a file only your user can read.
|
|
89
|
+
|
|
90
|
+
## Configuration
|
|
91
|
+
|
|
92
|
+
| Variable | Side | Default | Effect |
|
|
93
|
+
|---|---|---|---|
|
|
94
|
+
| `PYMOL_HP_STATE_DIR` | both | `$XDG_STATE_HOME/pymol-hyperpowers` or `~/.local/state/pymol-hyperpowers` | parent of `sessions/` |
|
|
95
|
+
| `PYMOL_HP_AUTOSTART` | plugin | `1` | `0` loads without listening |
|
|
96
|
+
| `PYMOL_HP_MAIN_THREAD_START_TIMEOUT` | plugin | `120` s | how long a `do` or `run` waits for the main thread to start it |
|
|
97
|
+
| `PYMOL_HP_MAX_OUTPUT_CHARS` | plugin | `8000` | output kept from `do` and `run` |
|
|
98
|
+
| `PYMOL_HP_APP_NAP_IDLE_S` | plugin | `900` s | App Nap guard idle release; `0` disables |
|
|
99
|
+
| `PYMOL_HP_TIMEOUT` | server | `60` s | default per-call timeout |
|
|
100
|
+
| `PYMOL_HP_SLOW_TIMEOUT` | server | `600` s | timeout for `do`, `run`, `render`, `save`, `fetch`, `load` and ray-traced screenshots |
|
|
101
|
+
| `PYMOL_HP_MAX_IMAGE_BYTES` | server | `3500000` | largest inline screenshot |
|
|
102
|
+
| `PYMOL_HP_PYMOL` | live tests | `~/Applications/PyMOL.app/Contents/MacOS/MacPyMOL` | PyMOL executable for live tests |
|
|
103
|
+
|
|
104
|
+
## Development
|
|
105
|
+
|
|
106
|
+
To run the server and plugin from a checkout, install it editable and point PyMOL at the checkout:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
uv tool install --editable /path/to/pymol-hyperpowers
|
|
110
|
+
pymol-hyperpowers install-plugin
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Re-run `install-plugin` if the checkout moves. With the editable install, `pymol-hyperpowers --version` keeps reporting the version from install time; the version notes use the version in the checkout.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
uv sync
|
|
117
|
+
uv python install 3.10 # a test compiles and runs plugin.py under PyMOL's Python version
|
|
118
|
+
uv run pytest # unit tests; no PyMOL needed
|
|
119
|
+
uv run pytest -m live # starts headless PyMOLs; set PYMOL_HP_PYMOL if PyMOL is elsewhere
|
|
120
|
+
uv run pytest -m live --run-network # adds a fetch from RCSB
|
|
121
|
+
uv run ruff format src tests && uv run ruff check src tests && uv run mypy
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`pytest -m live` fails when no live test passed, so a run that found no PyMOL does not look like a pass.
|
|
125
|
+
|
|
126
|
+
Bump versions with `vrzn bump patch` (or `minor`, `major`); it keeps `pyproject.toml` and the plugin's `PLUGIN_VERSION` in step. Bump whenever the plugin's behaviour changes: the server compares its `PLUGIN_VERSION` with each session's to tell users which side to restart, and an unbumped change goes unnoticed. Change `PROTOCOL_VERSION` (in both `protocol.py` and `plugin.py`) only when the wire format changes.
|
|
127
|
+
|
|
128
|
+
### Publishing
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
uv run inv publish --dry-run # every step except the upload and the tag
|
|
132
|
+
uv run inv publish # upload to PyPI and tag the commit v<version>
|
|
133
|
+
uv run inv publish --test # upload to TestPyPI instead; no tag
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`publish` runs only on a clean `main` whose version is not yet on the index or tagged, so bump with `vrzn` first. It runs the format, lint, type and unit checks, builds the sdist and wheel into `dist/`, and refuses a wheel whose `plugin.py` carries a different `PLUGIN_VERSION`, since that file is the plugin users get. `uv publish` reads the token from `UV_PUBLISH_TOKEN` or asks for it. The tag stays local; push it with `git push origin v<version>`.
|
|
137
|
+
|
|
138
|
+
### Manual GUI checklist
|
|
139
|
+
|
|
140
|
+
The live tests run headless PyMOL. Check these by hand in the GUI before a release:
|
|
141
|
+
|
|
142
|
+
1. PyMOL started normally after `install-plugin` prints its session name in the console, and the window title shows it.
|
|
143
|
+
2. From an agent, `do` with a window-touching command (for example `viewport 800, 600`) and `screenshot` with `ray=False` both work while the GUI is open.
|
|
144
|
+
3. A ray-traced `render` with PyMOL in the background finishes in roughly the time it takes in the foreground (the App Nap guard).
|
|
145
|
+
4. Two GUI PyMOLs started seconds apart get distinct names, and both appear in `list_sessions`.
|
|
146
|
+
5. In each of Claude Code, Codex and Antigravity, `list_sessions` shows the open PyMOLs.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# pymol-hyperpowers
|
|
2
|
+
|
|
3
|
+
An MCP server and PyMOL plugin that let agents in Claude Code, Codex and Antigravity control any open PyMOL session.
|
|
4
|
+
|
|
5
|
+
Each PyMOL that runs the plugin announces itself under a scientist's name when it starts:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
pymol-hyperpowers: this session is "Franklin" (127.0.0.1:50123)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The window title shows the same name. An agent lists the open sessions (newest first) with `list_sessions` and picks one with `use_session`; the listing also shows which other agent conversations are using each session. With one session open, tools use it without asking, unless another conversation is already using it, in which case the call asks the agent to call `use_session` to share it or to ask you. With several open and none chosen, a tool call fails with the list and asks the agent to choose or to ask you.
|
|
12
|
+
|
|
13
|
+
The package contains no prescriptive science. It gives an agent PyMOL's commands and data, and leaves the science to the agent and to you.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
Requires [uv](https://docs.astral.sh/uv/) and PyMOL 3 (which embeds Python 3.10 or newer).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
uv tool install pymol-hyperpowers
|
|
21
|
+
pymol-hyperpowers install-plugin
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The first command installs the MCP server and the plugin together. `install-plugin` adds a marked block to `~/.pymolrc.py` that loads the plugin from that installation whenever PyMOL starts; restart PyMOL afterwards. Re-running it rewrites the block in place. `uninstall-plugin` removes the block and leaves the rest of the file alone. Your `~/.pymolrc` is not touched; PyMOL reads every `~/.pymolrc*` file. Both commands take `--pymolrc PATH` to edit another file.
|
|
25
|
+
|
|
26
|
+
To start the plugin in one PyMOL without the rc block, run `pymol -r "$(pymol-hyperpowers plugin-path)"`.
|
|
27
|
+
|
|
28
|
+
### Updating
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
uv tool upgrade pymol-hyperpowers
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This one command updates both halves: PyMOL loads the plugin file inside the installed package, so upgrading the package replaces the plugin too. Then restart PyMOL so it loads the new plugin, and restart your agent sessions so their servers load the new code. `list_sessions` and `pymol-hyperpowers sessions` add a note to any session whose plugin version differs from the server's, saying which of the two to restart.
|
|
35
|
+
|
|
36
|
+
The plugin's path includes the tool's Python version, so reinstalling the tool on another Python moves the file. When the server starts and finds that the block in `~/.pymolrc.py` loads a file that no longer exists, it points the block at its own plugin and says so; restart PyMOL once more to load it. A block that loads a file that still exists, such as a development checkout, is left alone.
|
|
37
|
+
|
|
38
|
+
## Register the server with your agent
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
claude mcp add --scope user pymol -- ~/.local/bin/pymol-hyperpowers
|
|
42
|
+
codex mcp add pymol -- ~/.local/bin/pymol-hyperpowers
|
|
43
|
+
agy mcp add pymol ~/.local/bin/pymol-hyperpowers
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`pymol-hyperpowers sessions` prints the sessions the server can see, newest first, with the conversations using each and their process IDs, for checking from a terminal.
|
|
47
|
+
|
|
48
|
+
### Agents running without prompts
|
|
49
|
+
|
|
50
|
+
`codex exec` and `agy -p` cannot ask you to approve a tool call, so a pymol tool that needs approval fails instead of running. Approve the pymol tools beforehand. This includes `run`, which executes arbitrary Python inside PyMOL with your permissions.
|
|
51
|
+
|
|
52
|
+
- Codex: add `default_tools_approval_mode = "approve"` under `[mcp_servers.pymol]` in `~/.codex/config.toml`, or pass it for one run with `codex exec -c 'mcp_servers.pymol.default_tools_approval_mode="approve"' ...`. To approve only some tools, set `mcp_servers.pymol.tools.<tool>.approval_mode = "approve"` for each.
|
|
53
|
+
- Antigravity: add `"mcp(pymol/*)"` to `permissions.allow` in `~/.gemini/antigravity-cli/settings.json`, and remove any `permissions.ask` rule that matches the pymol tools. An ask rule wins over an allow rule, and `agy -p` cannot answer it. For one run, pass `agy --settings '{"permissions":{"allow":["mcp(pymol/*)"],"ask":[]}}' -p ...`: each list given there replaces the saved one, so the empty `ask` list lifts every saved ask rule for that run, not only the pymol ones.
|
|
54
|
+
|
|
55
|
+
### Coexistence with agentic-pymol
|
|
56
|
+
|
|
57
|
+
The two plugins use different rc files, ports and state directories, so both can run in one PyMOL. They clash only on the MCP server name `pymol`: when switching, remove agentic-pymol's registration first (for example `claude mcp remove pymol`), or register this server under another name, such as `pymol-hp`, while you try it.
|
|
58
|
+
|
|
59
|
+
## Tools
|
|
60
|
+
|
|
61
|
+
| Group | Tools |
|
|
62
|
+
|---|---|
|
|
63
|
+
| Sessions | `list_sessions`, `use_session`, `status` |
|
|
64
|
+
| Commands | `do` (PyMOL command language, one command per line), `run` (Python inside PyMOL) |
|
|
65
|
+
| Query | `iterate`, `alter`, `get_model`, `get_fastastr`, `get_coords`, `get_chains`, `get_names`, `get_object_list`, `count_atoms`, `count_states`, `get_extent`, `select` |
|
|
66
|
+
| Geometry | `get_distance`, `get_angle`, `get_dihedral`, `get_area` |
|
|
67
|
+
| Alignment | `align`, `cealign`, `rms` |
|
|
68
|
+
| View | `get_view`, `set_view` |
|
|
69
|
+
| Files | `fetch`, `load`, `save` |
|
|
70
|
+
| Images | `render` (PNG file), `screenshot` (PNG returned to the agent) |
|
|
71
|
+
|
|
72
|
+
Display work (`show`, `color`, `label`, settings, scenes, movies) goes through `do`. `run` executes arbitrary Python inside PyMOL with your permissions.
|
|
73
|
+
|
|
74
|
+
## PyMOL commands
|
|
75
|
+
|
|
76
|
+
- `mcp_status`: the session name, port, state file and connected clients.
|
|
77
|
+
- `mcp_stop`: stop listening and revoke every agent's access to this PyMOL.
|
|
78
|
+
- `mcp_start`: listen again, under a new name.
|
|
79
|
+
|
|
80
|
+
The plugin listens on 127.0.0.1 only, and every request must carry the session's token, which is stored in a file only your user can read.
|
|
81
|
+
|
|
82
|
+
## Configuration
|
|
83
|
+
|
|
84
|
+
| Variable | Side | Default | Effect |
|
|
85
|
+
|---|---|---|---|
|
|
86
|
+
| `PYMOL_HP_STATE_DIR` | both | `$XDG_STATE_HOME/pymol-hyperpowers` or `~/.local/state/pymol-hyperpowers` | parent of `sessions/` |
|
|
87
|
+
| `PYMOL_HP_AUTOSTART` | plugin | `1` | `0` loads without listening |
|
|
88
|
+
| `PYMOL_HP_MAIN_THREAD_START_TIMEOUT` | plugin | `120` s | how long a `do` or `run` waits for the main thread to start it |
|
|
89
|
+
| `PYMOL_HP_MAX_OUTPUT_CHARS` | plugin | `8000` | output kept from `do` and `run` |
|
|
90
|
+
| `PYMOL_HP_APP_NAP_IDLE_S` | plugin | `900` s | App Nap guard idle release; `0` disables |
|
|
91
|
+
| `PYMOL_HP_TIMEOUT` | server | `60` s | default per-call timeout |
|
|
92
|
+
| `PYMOL_HP_SLOW_TIMEOUT` | server | `600` s | timeout for `do`, `run`, `render`, `save`, `fetch`, `load` and ray-traced screenshots |
|
|
93
|
+
| `PYMOL_HP_MAX_IMAGE_BYTES` | server | `3500000` | largest inline screenshot |
|
|
94
|
+
| `PYMOL_HP_PYMOL` | live tests | `~/Applications/PyMOL.app/Contents/MacOS/MacPyMOL` | PyMOL executable for live tests |
|
|
95
|
+
|
|
96
|
+
## Development
|
|
97
|
+
|
|
98
|
+
To run the server and plugin from a checkout, install it editable and point PyMOL at the checkout:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
uv tool install --editable /path/to/pymol-hyperpowers
|
|
102
|
+
pymol-hyperpowers install-plugin
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Re-run `install-plugin` if the checkout moves. With the editable install, `pymol-hyperpowers --version` keeps reporting the version from install time; the version notes use the version in the checkout.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
uv sync
|
|
109
|
+
uv python install 3.10 # a test compiles and runs plugin.py under PyMOL's Python version
|
|
110
|
+
uv run pytest # unit tests; no PyMOL needed
|
|
111
|
+
uv run pytest -m live # starts headless PyMOLs; set PYMOL_HP_PYMOL if PyMOL is elsewhere
|
|
112
|
+
uv run pytest -m live --run-network # adds a fetch from RCSB
|
|
113
|
+
uv run ruff format src tests && uv run ruff check src tests && uv run mypy
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`pytest -m live` fails when no live test passed, so a run that found no PyMOL does not look like a pass.
|
|
117
|
+
|
|
118
|
+
Bump versions with `vrzn bump patch` (or `minor`, `major`); it keeps `pyproject.toml` and the plugin's `PLUGIN_VERSION` in step. Bump whenever the plugin's behaviour changes: the server compares its `PLUGIN_VERSION` with each session's to tell users which side to restart, and an unbumped change goes unnoticed. Change `PROTOCOL_VERSION` (in both `protocol.py` and `plugin.py`) only when the wire format changes.
|
|
119
|
+
|
|
120
|
+
### Publishing
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
uv run inv publish --dry-run # every step except the upload and the tag
|
|
124
|
+
uv run inv publish # upload to PyPI and tag the commit v<version>
|
|
125
|
+
uv run inv publish --test # upload to TestPyPI instead; no tag
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
`publish` runs only on a clean `main` whose version is not yet on the index or tagged, so bump with `vrzn` first. It runs the format, lint, type and unit checks, builds the sdist and wheel into `dist/`, and refuses a wheel whose `plugin.py` carries a different `PLUGIN_VERSION`, since that file is the plugin users get. `uv publish` reads the token from `UV_PUBLISH_TOKEN` or asks for it. The tag stays local; push it with `git push origin v<version>`.
|
|
129
|
+
|
|
130
|
+
### Manual GUI checklist
|
|
131
|
+
|
|
132
|
+
The live tests run headless PyMOL. Check these by hand in the GUI before a release:
|
|
133
|
+
|
|
134
|
+
1. PyMOL started normally after `install-plugin` prints its session name in the console, and the window title shows it.
|
|
135
|
+
2. From an agent, `do` with a window-touching command (for example `viewport 800, 600`) and `screenshot` with `ray=False` both work while the GUI is open.
|
|
136
|
+
3. A ray-traced `render` with PyMOL in the background finishes in roughly the time it takes in the foreground (the App Nap guard).
|
|
137
|
+
4. Two GUI PyMOLs started seconds apart get distinct names, and both appear in `list_sessions`.
|
|
138
|
+
5. In each of Claude Code, Codex and Antigravity, `list_sessions` shows the open PyMOLs.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.13,<0.14"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pymol-hyperpowers"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "MCP server and PyMOL plugin that let agents control any open PyMOL session."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = ["mcp>=2.3,<2.4"]
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
pymol-hyperpowers = "pymol_hyperpowers.cli:main"
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
18
|
+
"invoke>=3.0.3",
|
|
19
|
+
"mypy>=1.15",
|
|
20
|
+
"pytest>=8.3",
|
|
21
|
+
"pytest-timeout>=2.3",
|
|
22
|
+
"ruff>=0.11",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[tool.ruff]
|
|
26
|
+
line-length = 120
|
|
27
|
+
target-version = "py312"
|
|
28
|
+
src = [
|
|
29
|
+
"src",
|
|
30
|
+
"tests",
|
|
31
|
+
]
|
|
32
|
+
extend-exclude = ["docs"]
|
|
33
|
+
|
|
34
|
+
[tool.ruff.per-file-target-version]
|
|
35
|
+
"src/pymol_hyperpowers/plugin.py" = "py310"
|
|
36
|
+
|
|
37
|
+
[tool.ruff.lint]
|
|
38
|
+
select = ["ALL"]
|
|
39
|
+
ignore = [
|
|
40
|
+
"COM812",
|
|
41
|
+
"ISC001",
|
|
42
|
+
"D",
|
|
43
|
+
"FBT",
|
|
44
|
+
"TRY003",
|
|
45
|
+
"EM101",
|
|
46
|
+
"EM102",
|
|
47
|
+
"PLR0913",
|
|
48
|
+
"C901",
|
|
49
|
+
"PLR0911",
|
|
50
|
+
"PLR0912",
|
|
51
|
+
"PLR0915",
|
|
52
|
+
"TC",
|
|
53
|
+
"CPY",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint.per-file-ignores]
|
|
57
|
+
"tests/**" = [
|
|
58
|
+
"S101",
|
|
59
|
+
"S105",
|
|
60
|
+
"S106",
|
|
61
|
+
"S107",
|
|
62
|
+
"S311",
|
|
63
|
+
"S603",
|
|
64
|
+
"S607",
|
|
65
|
+
"S608",
|
|
66
|
+
"PLR2004",
|
|
67
|
+
"ANN",
|
|
68
|
+
"ARG",
|
|
69
|
+
"INP001",
|
|
70
|
+
"SLF001",
|
|
71
|
+
"T201",
|
|
72
|
+
]
|
|
73
|
+
"tests/support/fake_pymol.py" = [
|
|
74
|
+
"A002",
|
|
75
|
+
"PLR0917",
|
|
76
|
+
]
|
|
77
|
+
"src/pymol_hyperpowers/plugin.py" = [
|
|
78
|
+
"S102",
|
|
79
|
+
"S307",
|
|
80
|
+
"BLE001",
|
|
81
|
+
"T201",
|
|
82
|
+
"SLF001",
|
|
83
|
+
"ANN401",
|
|
84
|
+
"PLC0415",
|
|
85
|
+
]
|
|
86
|
+
"src/pymol_hyperpowers/client.py" = ["ANN401"]
|
|
87
|
+
"src/pymol_hyperpowers/tools/*.py" = [
|
|
88
|
+
"A002",
|
|
89
|
+
"PLR0917",
|
|
90
|
+
]
|
|
91
|
+
"src/pymol_hyperpowers/cli.py" = ["T201"]
|
|
92
|
+
"tasks.py" = ["T201"]
|
|
93
|
+
|
|
94
|
+
[tool.mypy]
|
|
95
|
+
strict = true
|
|
96
|
+
python_version = "3.12"
|
|
97
|
+
files = ["src"]
|
|
98
|
+
|
|
99
|
+
[[tool.mypy.overrides]]
|
|
100
|
+
module = [
|
|
101
|
+
"pymol",
|
|
102
|
+
"pymol.*",
|
|
103
|
+
"chempy",
|
|
104
|
+
"chempy.*",
|
|
105
|
+
"numpy",
|
|
106
|
+
"pmg_qt",
|
|
107
|
+
"pmg_qt.*",
|
|
108
|
+
]
|
|
109
|
+
ignore_missing_imports = true
|
|
110
|
+
|
|
111
|
+
[tool.pytest.ini_options]
|
|
112
|
+
testpaths = ["tests"]
|
|
113
|
+
pythonpath = ["tests"]
|
|
114
|
+
addopts = "-ra -m 'not live'"
|
|
115
|
+
timeout = 120
|
|
116
|
+
markers = [
|
|
117
|
+
"live: starts real headless PyMOL processes; deselected unless -m live",
|
|
118
|
+
"network: contacts RCSB; skipped unless --run-network",
|
|
119
|
+
]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.13,<0.14"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pymol-hyperpowers"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "MCP server and PyMOL plugin that let agents control any open PyMOL session."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"mcp>=2.3,<2.4",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
pymol-hyperpowers = "pymol_hyperpowers.cli:main"
|
|
17
|
+
|
|
18
|
+
[dependency-groups]
|
|
19
|
+
dev = [
|
|
20
|
+
"invoke>=3.0.3",
|
|
21
|
+
"mypy>=1.15",
|
|
22
|
+
"pytest>=8.3",
|
|
23
|
+
"pytest-timeout>=2.3",
|
|
24
|
+
"ruff>=0.11",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.ruff]
|
|
28
|
+
line-length = 120
|
|
29
|
+
target-version = "py312"
|
|
30
|
+
src = ["src", "tests"]
|
|
31
|
+
extend-exclude = ["docs"] # the spec and plan are prose; ruff would reformat their code blocks
|
|
32
|
+
|
|
33
|
+
[tool.ruff.per-file-target-version]
|
|
34
|
+
# PyMOL embeds Python 3.10, and the plugin runs inside it.
|
|
35
|
+
"src/pymol_hyperpowers/plugin.py" = "py310"
|
|
36
|
+
|
|
37
|
+
[tool.ruff.lint]
|
|
38
|
+
select = ["ALL"]
|
|
39
|
+
ignore = [
|
|
40
|
+
"COM812", # conflicts with ruff format
|
|
41
|
+
"ISC001", # conflicts with ruff format
|
|
42
|
+
"D", # reST field-list docstrings are checked in review; pydocstyle has no reST convention
|
|
43
|
+
"FBT", # MCP tool signatures take boolean flags by design
|
|
44
|
+
"TRY003",
|
|
45
|
+
"EM101",
|
|
46
|
+
"EM102",
|
|
47
|
+
"PLR0913", # MCP tools mirror PyMOL's argument lists
|
|
48
|
+
"C901",
|
|
49
|
+
"PLR0911",
|
|
50
|
+
"PLR0912",
|
|
51
|
+
"PLR0915",
|
|
52
|
+
"TC", # runtime-vs-typing import placement adds churn without catching bugs here
|
|
53
|
+
"CPY", # copyright headers are not used
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint.per-file-ignores]
|
|
57
|
+
"tests/**" = ["S101", "S105", "S106", "S107", "S311", "S603", "S607", "S608", "PLR2004", "ANN", "ARG", "INP001", "SLF001", "T201"]
|
|
58
|
+
# The fake mirrors PyMOL's parameter names and signatures.
|
|
59
|
+
"tests/support/fake_pymol.py" = ["A002", "PLR0917"]
|
|
60
|
+
# The plugin runs inside PyMOL: it executes agent code by design (exec, eval), prints to PyMOL's
|
|
61
|
+
# console, reaches PyMOL internals (cmd._cmd, cmd._COb), imports PyMOL and optional modules lazily,
|
|
62
|
+
# and must never let one failure stop the listener.
|
|
63
|
+
"src/pymol_hyperpowers/plugin.py" = ["S102", "S307", "BLE001", "T201", "SLF001", "ANN401", "PLC0415"]
|
|
64
|
+
# Values read off the wire are JSON of any shape; the tools convert them.
|
|
65
|
+
"src/pymol_hyperpowers/client.py" = ["ANN401"]
|
|
66
|
+
# Tool parameter names (type, format) are agentic-pymol's public contract, and a tool's
|
|
67
|
+
# parameters become its named arguments, so PyMOL-sized argument lists stay as they are.
|
|
68
|
+
"src/pymol_hyperpowers/tools/*.py" = ["A002", "PLR0917"]
|
|
69
|
+
"src/pymol_hyperpowers/cli.py" = ["T201"]
|
|
70
|
+
"tasks.py" = ["T201"]
|
|
71
|
+
|
|
72
|
+
[tool.mypy]
|
|
73
|
+
strict = true
|
|
74
|
+
python_version = "3.12"
|
|
75
|
+
files = ["src"]
|
|
76
|
+
|
|
77
|
+
[[tool.mypy.overrides]]
|
|
78
|
+
# PyMOL, chempy and numpy exist only inside PyMOL; the plugin imports them lazily.
|
|
79
|
+
module = ["pymol", "pymol.*", "chempy", "chempy.*", "numpy", "pmg_qt", "pmg_qt.*"]
|
|
80
|
+
ignore_missing_imports = true
|
|
81
|
+
|
|
82
|
+
[tool.pytest.ini_options]
|
|
83
|
+
testpaths = ["tests"]
|
|
84
|
+
pythonpath = ["tests"]
|
|
85
|
+
addopts = "-ra -m 'not live'"
|
|
86
|
+
timeout = 120
|
|
87
|
+
markers = [
|
|
88
|
+
"live: starts real headless PyMOL processes; deselected unless -m live",
|
|
89
|
+
"network: contacts RCSB; skipped unless --run-network",
|
|
90
|
+
]
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""The MCP server: its instructions, the tool context, and plugin errors as tool errors."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from mcp.server.mcpserver import Context, MCPServer
|
|
9
|
+
from mcp.server.mcpserver.exceptions import ToolError
|
|
10
|
+
from mcp_types import CallToolResult, InputRequiredResult
|
|
11
|
+
|
|
12
|
+
from pymol_hyperpowers import __version__
|
|
13
|
+
from pymol_hyperpowers.client import ClientPool, PluginError, SessionClient, SessionGoneError, TransportError
|
|
14
|
+
from pymol_hyperpowers.selection import Selection, SelectionError
|
|
15
|
+
from pymol_hyperpowers.tools import align, escape, geometry, images, io, query, session, view
|
|
16
|
+
|
|
17
|
+
INSTRUCTIONS = """\
|
|
18
|
+
pymol-hyperpowers controls the PyMOL sessions open on this computer. Each session runs the \
|
|
19
|
+
pymol-hyperpowers plugin and is named after a scientist, such as Franklin or Pauling.
|
|
20
|
+
|
|
21
|
+
Choosing a session: with one session open, tools use it. With several open, tools ask you to \
|
|
22
|
+
choose: call list_sessions (newest first, with each session's objects and the other conversations \
|
|
23
|
+
using it) and select one with use_session. A session another conversation is using is not \
|
|
24
|
+
selected automatically: call use_session to share it once the user agrees, or pick another \
|
|
25
|
+
session. Ask the user when it is unclear which PyMOL they mean.
|
|
26
|
+
|
|
27
|
+
Choosing a tool: prefer a dedicated tool, which returns typed data. Use do for anything else in \
|
|
28
|
+
PyMOL's command language, including display, colouring, labels, settings, scenes and movies. Use \
|
|
29
|
+
run, which executes arbitrary Python inside PyMOL, only when neither works.
|
|
30
|
+
|
|
31
|
+
Reading results: do stops at the first line PyMOL rejects and names it. Read the warnings do \
|
|
32
|
+
returns: PyMOL reports a selection that matched nothing as a warning, not an error.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def surface_plugin_error(error: PluginError) -> str:
|
|
37
|
+
"""A plugin error as tool-error text: type and message, then PyMOL's output, then the traceback."""
|
|
38
|
+
parts = [f"{error.error_type}: {error.message}"]
|
|
39
|
+
if error.stdout.strip():
|
|
40
|
+
parts.append(f"--- PyMOL output ---\n{error.stdout.rstrip()}")
|
|
41
|
+
if error.traceback_text.strip():
|
|
42
|
+
parts.append(f"--- traceback ---\n{error.traceback_text.rstrip()}")
|
|
43
|
+
return "\n\n".join(parts)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def client_name(context: object) -> str | None:
|
|
47
|
+
"""The MCP client's name (``client_info.name``) from a tool call's context, or None.
|
|
48
|
+
|
|
49
|
+
The SDK passes request context to tools only through a Context parameter, which no tool takes,
|
|
50
|
+
so the server reads it here; any missing piece means unknown.
|
|
51
|
+
"""
|
|
52
|
+
try:
|
|
53
|
+
name = context.session.client_params.client_info.name # type: ignore[attr-defined]
|
|
54
|
+
except Exception: # noqa: BLE001 - no request context, no client params, or another SDK shape
|
|
55
|
+
return None
|
|
56
|
+
return name if isinstance(name, str) and name else None
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class ToolContext:
|
|
60
|
+
"""What every tool works through: the session selection and one client per session."""
|
|
61
|
+
|
|
62
|
+
def __init__(self, selection: Selection | None = None, pool: ClientPool | None = None) -> None:
|
|
63
|
+
self.selection = selection if selection is not None else Selection()
|
|
64
|
+
self.pool = pool if pool is not None else ClientPool()
|
|
65
|
+
|
|
66
|
+
def record_client(self, name: str | None) -> None:
|
|
67
|
+
"""Record the MCP client's name for this server's claims; the first name stays."""
|
|
68
|
+
self.selection.set_client(name)
|
|
69
|
+
|
|
70
|
+
def run[T](self, action: Callable[[SessionClient], T]) -> T:
|
|
71
|
+
"""Run ``action`` against the session this call works with, read once when the call starts.
|
|
72
|
+
|
|
73
|
+
The claim's last activity is refreshed before and after, so a call that hangs shows when it began.
|
|
74
|
+
|
|
75
|
+
:raises ToolError: For every failure, with text the agent can act on.
|
|
76
|
+
"""
|
|
77
|
+
try:
|
|
78
|
+
address = self.selection.resolve()
|
|
79
|
+
except SelectionError as e:
|
|
80
|
+
raise ToolError(str(e)) from e
|
|
81
|
+
client = self.pool.get(address)
|
|
82
|
+
self.selection.touch(address)
|
|
83
|
+
try:
|
|
84
|
+
return action(client)
|
|
85
|
+
except SessionGoneError as e:
|
|
86
|
+
self.pool.discard(address.session_id)
|
|
87
|
+
raise ToolError(self.selection.lost(address, str(e))) from e
|
|
88
|
+
except PluginError as e:
|
|
89
|
+
raise ToolError(surface_plugin_error(e)) from e
|
|
90
|
+
except TransportError as e:
|
|
91
|
+
raise ToolError(str(e)) from e
|
|
92
|
+
finally:
|
|
93
|
+
self.selection.touch(address)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class PymolServer(MCPServer[Any]):
|
|
97
|
+
"""The MCP server, recording the client's name from each tool call before running the tool."""
|
|
98
|
+
|
|
99
|
+
def __init__(self, ctx: ToolContext, *args: Any, **kwargs: Any) -> None: # noqa: ANN401 - MCPServer's own signature
|
|
100
|
+
super().__init__(*args, **kwargs)
|
|
101
|
+
self._ctx = ctx
|
|
102
|
+
|
|
103
|
+
async def call_tool(
|
|
104
|
+
self, name: str, arguments: dict[str, Any], context: Context[Any, Any] | None = None
|
|
105
|
+
) -> CallToolResult | InputRequiredResult:
|
|
106
|
+
"""Record the client's name, then call the tool as ``MCPServer`` does."""
|
|
107
|
+
self._ctx.record_client(client_name(context))
|
|
108
|
+
return await super().call_tool(name, arguments, context)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def build_server(context: ToolContext | None = None) -> MCPServer[Any]:
|
|
112
|
+
"""Register every tool on a new server, not yet running.
|
|
113
|
+
|
|
114
|
+
:param context: Defaults to a new ``ToolContext`` reading the registry this process sees.
|
|
115
|
+
"""
|
|
116
|
+
ctx = context if context is not None else ToolContext()
|
|
117
|
+
server: MCPServer[Any] = PymolServer(ctx, "pymol", instructions=INSTRUCTIONS, version=__version__)
|
|
118
|
+
for register in (
|
|
119
|
+
session.register,
|
|
120
|
+
escape.register,
|
|
121
|
+
query.register,
|
|
122
|
+
geometry.register,
|
|
123
|
+
align.register,
|
|
124
|
+
view.register,
|
|
125
|
+
io.register,
|
|
126
|
+
images.register,
|
|
127
|
+
):
|
|
128
|
+
register(server, ctx)
|
|
129
|
+
return server
|