Skip to main content

Moorlight

A small Coot 0.9-style model-building viewer that runs in the browser, with real-space refinement built on TorchRef restraints and Claude built in. Made for TorchRef (difference) refinement results.

pip install moorlight                 # pulls in TorchRef, gemmi, torch (CPU is fine)
moorlight path/to/torchref/run/     # refined.pdb + refined.mtz, or D.pdb + L_refined.pdb + difference_data.mtz
moorlight model.pdb maps.mtz lig.cif  # or individual files
moorlight dark.pdb dark.mtz:dark light.mtz:light   # file.mtz:label names the maps

What it does

  • Maps. It recognises TorchRef columns automatically:

    • FWT/PHWT and DELFWT/PHDELWT from single-dataset refinement
    • WDF, DF and DFc with PHIC_dark, mDFop-DFc/PHIC_diff, and the extrapolated maps (with PHIC_light) from difference refinement
    • phenix 2FOFCWT/FOFCWT, Fo-Fo (FoFo/PHFc from phenix.fobs_minus_fobs_map) and polder/omit maps
    • other F/PHI column pairs, or CCP4 maps

    load_mtz takes a label (map name), explicit columns (F,PHI[,kind[,name]]) and a d_min to compare data sets at matched resolution. Maps can be renamed (rename_map).

    Maps are drawn as Coot-style chicken wire within a 10 Å radius of the centre. The scroll wheel changes the level of the map marked ●.

  • Real-space refinement. Choose a zone, the residue ±1 (R), a sphere (Shift-R), or a new alternative conformer. Each refinement builds TorchRef restraints (bonds, angles, torsions, planes, chirals; ligand CIFs included) for the moving residues plus a fixed shell around them. These are minimised against the refinement map (the one marked R) with live updates in the view. Drag an atom to pull it; Enter accepts, Esc rejects. Fixed atoms never move.

  • Difference target. Set the refinement target to difference (or map + difference). Moving atoms are then fitted so that the model's light-minus-dark density matches a difference map (WDF by default), with a fitted scale. The dark reference is D.pdb for TorchRef difference refinement, otherwise the residue's other alternative conformers, otherwise the starting coordinates. The banner shows the live difference CC.

  • Repulsion. Non-bonded repulsion is off by default, so you can pull atoms on top of each other. Tick atoms repel to switch it on.

  • Building. Alternative conformers, rotamers ranked by density, mutate, pepflip, adding residues at either terminus, renumbering, deleting, waters (W, or Find water sites), ions, ligands from a CIF that contains coordinates, occupancy/B, undo/redo, save.

  • Peaks tab. Lists the strongest ± difference peaks with their nearest atom, after symmetry mapping. Click a peak to go there. Each peak carries its rank among all peaks of that sign in the cell ("15th of 560 above 3.5σ").

  • Tours. A tour is a list of stops, each a saved view (centre, rotation, zoom, slab, visible molecules and maps with their levels, labels and distances) plus a short text. Claude builds one with tour_add and tour_save. You can step through it with ◀ ▶ in the Display tab, and share it as a JSON file: tour_load opens the models and maps it needs. Single views can be saved with save_view / restore_view.

  • Claude tab. A chat running headless Claude Code with every viewer command as a tool. Each message carries your current view (visible maps and levels, centre, selected atoms), so "this map" means what you're looking at. Claude can take screenshots of the view. The shell box lets it run commands such as TorchRef refinements; it's off by default.

Press ? in the viewer for keys and mouse controls.

Using it from any Claude Code session (MCP)

The viewer writes its address to ~/.moorlight/server.json. To attach the tools to any Claude Code session:

claude mcp add moorlight -- python -m moorlight.mcp

Claude can then call state, screenshot, goto, set_map, peaks, map_correlation, refine, add_altconf and the other commands directly.

Driving it from a shell or an already-running agent session

MCP servers cannot be added to a Claude Code session that is already running. The same commands are available from the shell:

moorlight cmd --list                                   # every command with its parameters
moorlight cmd state compact=true
moorlight cmd solo mol=2
moorlight cmd frame_atoms atoms='["A/381 SG", "B/901 C1"]'
moorlight cmd density_profile a="A/381 SG" b="B/901 C1" maps=3,4
moorlight cmd screenshot width=800

Values are read as JSON when possible (numbers, true, lists), otherwise as strings, and the result is printed as JSON. The viewer is found through --url, $MOORLIGHT_URL or ~/.moorlight/server.json, and you get an error if that file points at a viewer that is no longer running. moorlight --no-browser prints Moorlight ready: <url> once the port is open.

Underneath is a small HTTP API:

endpoint
GET /api/commands all commands, with descriptions and parameter types
POST /api/cmd {"cmd": "goto", "args": {"chain": "A", "resseq": 85}} → {"ok": true, "result": ...} or {"ok": false, "error": ...}
GET /api/state everything the browser needs to draw (models, maps, view, tour)

Atom specs. Commands that take atoms accept A/85 CA, A/85 LYS CA:B (altloc B), 2#A/85 SG (molecule 2), A/85 (residue centroid) or {"chain": "A", "resseq": 85, "atom": "CA"}.

Commands for presenting and measuring:

  • Display: set_molecule (visible, colour, style, hydrogens), solo. The panel checkboxes use the same commands, so state reports what you see.
  • Framing: goto (residue), goto_atom, frame_atoms (fits the atoms and lays the first pair horizontally in the screen plane), and set_center on an atom or the midpoint of several.
  • Measuring:
    • distance, across molecules; without altlocs, every conformer pair.
    • density_profile along a line, with the lowest value relative to the ends.
    • density_at_point.
    • density_at_atoms, with maps=[...] independent of visibility.
  • Annotation: label_atoms, show_distance, clear_annotations. Labels and distances are drawn into screenshots.
  • Screenshots: screenshot waits until the view has settled and its map contours are computed. It takes width, crop and path.

Claude skill: guided result tours

moorlight --install-skill copies the bundled moorlight-result-tour skill to ~/.claude/skills (or give a directory). It tells Claude how to walk you through results (difference maps, moving residues, waters): plan the stops from the analysis, show one map at a time, frame each target with goto (residue plus ~5 Å context, depth slab), back every statement with density_at_atoms numbers and stop after each stop. The built-in chat uses the same rules.

goto takes radius (Å of context around the residue, default 5; 0 = only centre) and slab (depth half-thickness in Å).

Notes / limits (v0.1)

  • Real-space refinement uses trilinear interpolation of the map and a simple non-bonded repulsion. Ramachandran restraints are not used yet.
  • Hydrogens are left out of refinement and follow their parent atom afterwards.
  • Ligands need coordinates in the CIF (from acedrg, grade or eLBOW). There's no RDKit conformer generation yet.
  • Rotamers come from the Penultimate library (modal χ values), ranked by mean density at the side-chain atoms.

Metadata

Release files for moorlight 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moorlight 0.2.1
File Size Uploaded Provenance Actions
moorlight-0.2.1.tar.gz 92.1 kB Without provenance Details for moorlight-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for moorlight 0.2.1
File Interpreter ABI Platform Actions
moorlight-0.2.1-py3-none-any.whl Python 3 none any Details for moorlight-0.2.1-py3-none-any.whl

Total release size: 187.4 kB

Release files / moorlight-0.2.1.tar.gz

Download URL moorlight-0.2.1.tar.gz
Size 92.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b461323481036aa6795deb076b23f6ea5b3e17576e6d1e55031db3bfe97f3b1d
BLAKE2b-256 checksum
How to use checksums
8dcd0fc5ee98c79a1375bfe55451cdc1adf7cc0df766b946d18fbac9539bf434
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / moorlight-0.2.1-py3-none-any.whl

Download URL moorlight-0.2.1-py3-none-any.whl
Size 95.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e0edf99914ad3f007320669efe9f451682be8d3e59694ed7eed2836fbd028bc
BLAKE2b-256 checksum
How to use checksums
ee05edb2234eb1d24f036bcd9d445ad938850b60866d41d201a3f74fe9c571ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for moorlight 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page