Scripting and command line

Start Proteoscope with the options you need, open structures from a link, and drive it from the browser console, from Python and Jupyter, or from an AI agent.

Command-line options

Flags come first, followed by any structure files or prediction folders to open at startup. Every file and folder you name opens, and the first structure is active.

text
proteoscope [flags] [structure files or prediction folders...]
proteoscope mcp [flags]    an MCP server for AI agents (see AI agents)
proteoscope triage [flags] 
                           rank predictions without a window (see Batch triage)

  --host string       interface to bind (default 127.0.0.1)
  --port int          preferred port; nearby ports are tried if busy (default 8765)
  --no-open           do not open a browser
  --offline           disable remote fetching (cached entries still work)
  --cache-dir path    fetch cache location (default: user cache dir/proteoscope)
  --cache-max-age d   refetch cached downloads older than this (default 720h; 0 keeps them)
  --no-cache          do not read or write the fetch cache
  --dev               serve web/ and data/ from disk for development
  --remote-control    accept commands from scripts on this computer (see Scripting)
  --version           print the version and exit

For example, to open two structure files and a prediction folder:

$ proteoscope structure.cif model.pdb.gz af3_output/my_job/

Local access only

With the default --host 127.0.0.1, the server only answers requests whose Host is the local address, and it always rejects cross-origin API calls. This protects against DNS-rebinding and cross-site requests. A --host such as 0.0.0.0 serves Proteoscope to other machines on your network, so use it only on a network you trust.

A link to Proteoscope's address can tell it what to load. Open one in your browser while Proteoscope is running.

LinkWhat it does
http://127.0.0.1:8765/#fetch=4HHBFetches 4HHB on load
http://127.0.0.1:8765/#fetch=4AKE,1AKE&superposeLoads both structures and superposes the second onto the first
#session=…Opens a whole session carried in the URL; Copy link or the link command makes one. See Share a link.

Use the address and port your Proteoscope printed if it is not 127.0.0.1:8765.

Browser console

In the browser's developer console, proteoscope.run() executes any command you could type in the search box and returns { ok, message, data }. For the commands and the selection language, see Selections and commands.

js
await proteoscope.run('fetch 2HYY');
await proteoscope.run('show sticks byres (within 4.5 of resn STI) and protein');
await proteoscope.run('color salmon resn STI');
const { data } = await proteoscope.run('select within 4 of resn STI');   // residue keys per structure
const png = await proteoscope.snapshot({ scale: 3, transparent: true });  // data URL
const session = await proteoscope.session();                              // the session as JSON

Python and Jupyter

With remote control on, a script on your computer can send commands to the Proteoscope page open in your browser, so you can fetch, superpose, select and render images from a notebook.

  1. Start Proteoscope with --remote-control:
    $ proteoscope --remote-control
  2. Open it in a browser. Commands go to the most recently opened Proteoscope page.
  3. POST each command as JSON to /api/remote/command. The open page runs the command and the reply carries its result.
python
import base64
import requests

def ps(command):
    reply = requests.post("http://127.0.0.1:8765/api/remote/command",
                          json={"command": command}, timeout=180).json()
    if not reply.get("ok"):
        raise RuntimeError(reply.get("message") or reply.get("error"))
    return reply

ps("fetch 4AKE")
ps("add 1AKE")
print(ps("superpose 1AKE onto 4AKE fit /A:1-29+60-121+160-214")["message"])
moved = ps("select deviation > 5 and chain A")["data"]    # residue keys that moved > 5 Å
ps("color deviation")
image = ps("png 2")["data"]["image"]                      # PNG as a data URL

from IPython.display import Image
Image(base64.b64decode(image.split(",", 1)[1]))

The reply is JSON. Its message carries the command's report, such as the superposition result printed above, and data its results, such as residue keys or the image. When a command fails, ok is false, and the ps helper raises an error with the reply's message or error. Over remote control, png, save, link and mvs return data instead of downloading a file, so the image, session, link or MolViewSpec file comes back in the reply. info, interactions <selection>, interface <chain> <chain>, validate, superpose, triage, compound, diagram (SVG and PNG), posecheck, map peaks and help return their results as data too.

Opening files from scripts

POST absolute paths of files or folders to /api/remote/open, and the page opens them as if they had been named on the command line; several prediction folders are ranked together. Because this reads files from your disk, it also needs the token Proteoscope prints when it starts (a new one each run), in the X-Proteoscope-Token header:

python
TOKEN = "..."   # from the "Opening files by path" line Proteoscope printed

reply = requests.post("http://127.0.0.1:8765/api/remote/open",
                      headers={"X-Proteoscope-Token": TOKEN},
                      json={"paths": ["/runs/campaign"]}, timeout=1800).json()
print(reply["message"])                  # "Opened 48 prediction jobs (240 models) ..."
best = ps("triage by ipsae top 5 pair A B")["data"]["rows"]

Files opened this way are served only to the page on this computer, even when --host shares Proteoscope with other machines.

AI agents

proteoscope mcp lets an AI agent such as Claude Code use Proteoscope in the page you see, through the Model Context Protocol:

$ claude mcp add proteoscope --scope user -- /Users/you/.local/bin/proteoscope mcp

See AI agents (MCP) for Claude Desktop, Collomia and other clients, the tools, and troubleshooting.

Remote control safety

Any local program can send commands. While --remote-control is on, any program on your computer can send commands to Proteoscope. Start Proteoscope without the flag when you are not scripting it.