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/PHWTandDELFWT/PHDELWTfrom single-dataset refinementWDF,DFandDFcwithPHIC_dark,mDFop-DFc/PHIC_diff, and the extrapolated maps (withPHIC_light) from difference refinement- phenix
2FOFCWT/FOFCWT, Fo-Fo (FoFo/PHFcfromphenix.fobs_minus_fobs_map) and polder/omit maps - other
F/PHIcolumn pairs, or CCP4 maps
load_mtztakes alabel(map name), explicitcolumns(F,PHI[,kind[,name]]) and ad_minto 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 ●. Each map has a level slider (log scale up to the map's strongest value, as in shared pages), the level in σ and on the map's own scale. A map whose column labels do not say what it is (e.g.
FDDCAT) is classified from its values when it is first computed: difference maps have noise below −2.5 σ, density maps almost none. -
Map slices. Maps as: Slice draws the map on a plane instead of mesh contours, as in shared pages: green +, red − (the map colour for density), brighter towards 3 × level, contour lines at 1, 2, 4 … × level. The live plane faces you through the centre and follows the view; Fix plane locks it to the molecule, Depth moves it along its normal, Thickness shows the strongest value within the slab, Through selected atoms lays it through the labelled atoms.
-
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_addandtour_save. You can step through it with ◀ ▶ in the Display tab, and share it as a JSON file:tour_loadopens the models and maps it needs. Single views can be saved withsave_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, sostatereports what you see. - Framing:
goto(residue),goto_atom,frame_atoms(fits the atoms and lays the first pair horizontally in the screen plane), andset_centeron an atom or the midpoint of several. - Measuring:
distance, across molecules; without altlocs, every conformer pair.density_profilealong a line, with the lowest value relative to the ends.density_at_point.density_at_atoms, withmaps=[...]independent of visibility.
- Annotation:
label_atoms,show_distance,clear_annotations. Labels and distances are drawn into screenshots. - Slices:
slice(styleslice/mesh,atoms=[...]for a plane through atoms,fix,depth,thickness,map_id) returns where the plane is and its strongest positive and negative values with the nearest atoms. Saved views and tour stops keep the slice. - Screenshots:
screenshotwaits until the view has settled and its map contours are computed. It takeswidth,cropandpath.
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 Å).
Shareable pages (no server)
moorlight-share (or moorlight share) writes one self-contained HTML viewer page. It runs on a phone, as a
claude.ai artifact, or as a file opened locally. The page holds the models, their symmetry neighbours, the maps on
their own grids, and preset slice planes. The browser contours the maps itself (mesh, or an Olex2-style slice).
The page fetches nothing: three.js 0.170.0 (MIT, vendored in moorlight/web/vendor) is written into it and it uses
system fonts. A --standalone page can be sent by e-mail or messenger or deposited with a paper and opens offline in
any current browser with WebGL 2 (on an iPhone, open a link rather than a file preview). Its "About this file" section
lists the input files with SHA-256 checksums, the Moorlight version and commit, and the build time.
moorlight-share model.pdb maps.mtz --title "Ligand site" --center A/401 --plane "Ring=A/401 C1, A/401 C2, A/401 C3" -o page.html
moorlight-share /path/to/refinement_folder --title "Dark vs light" --center RET -o page.html # TorchRef layouts
moorlight-share 3hs4 --center ZN --plane "Zn site=ZN" -o page.html --standalone # PDB-REDO entry
moorlight-share again page.spec.json --plane "Second=A/85; copies=-1,1" # same page, more
One command builds the page in a few seconds and prints what it shows (maps, the strongest difference features
near the centre, each plane with the features in it). Atom specs also take residue names (RET, ZN C1). Plane
options: copies, toward, perpendicular-to, thickness, center, offset, axis. The bundled
moorlight-share skill, installed with moorlight --install-skill, has the agent workflow.
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.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| moorlight-0.3.0.tar.gz | 358.6 kB | Without provenance | Details for moorlight-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| moorlight-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for moorlight-0.3.0-py3-none-any.whl |
Total release size: 723.3 kB
Release files / moorlight-0.3.0.tar.gz
| Download URL | moorlight-0.3.0.tar.gz |
|---|---|
| Size | 358.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9cbcf841af797290d11ce86ea42c419bd194a8707c0f91586e43c10459eea69
|
|
BLAKE2b-256 checksum How to use checksums |
1932d485f3a70ebbe4004f1a45b527fa01932a2fd0ef233634a5111f750aecd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Release files / moorlight-0.3.0-py3-none-any.whl
| Download URL | moorlight-0.3.0-py3-none-any.whl |
|---|---|
| Size | 364.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a8ebcba68ee651a6589d88ee44d3cccaf162829b7651c08e211d613b76a165d
|
|
BLAKE2b-256 checksum How to use checksums |
c42cd97a278d9bf80a6c8e7d01e2f47fa5e920eb04cd358d2d7d2811c16a4553
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.12
|
Security for moorlight 0.3.0
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.