# ProteinView Terminal molecular structure viewer — load, rotate, and explore proteins, nucleic acids, and small molecules from PDB/CIF files right in your terminal. No browser, no GUI, no runtime dependencies. ## Features - **3-tier render modes** — Braille, HD, and FullHD (Sixel/Kitty) with automatic SSH detection - **PNG-compressed Kitty protocol** — ~10-20x smaller than raw RGBA, making FullHD viable over SSH - **Cartoon ribbon visualization** — Lambert-shaded ribbons with depth fog for helices, sheets, and coils - **RNA/DNA support** — backbone, wireframe, and cartoon modes with base-type coloring - **Small molecule rendering** — ligands as ball-and-stick, ions as spheres - **Interface analysis** — inter-chain contacts, binding pockets, and interaction visualization (H-bonds, salt bridges, hydrophobic contacts) - **7 color schemes** — structure, chain, element (CPK), B-factor, rainbow, pLDDT (AlphaFold) - **Interactive controls** — vim-style rotation, zoom, pan with auto-rotation - **PDB & mmCIF** — both formats supported, with RCSB PDB fetch (`--fetch`) - **Headless FullHD export** — render a pixel-perfect PNG for agents and scripts without starting a nested TUI - **Single static binary** — zero runtime dependencies ## Render Modes Three rendering tiers to match your terminal and connection: | Mode | Key | Quality | SSH Performance | |------|-----|---------|-----------------| | **Braille** | default | Text-based, monochrome per cell | Excellent | | **HD** | `m` | Shaded braille with lighting + depth fog | Excellent | | **FullHD** | `M` | Sixel/Kitty pixel graphics | Good (PNG compressed) | `--hd` is SSH-aware: defaults to HD over SSH, FullHD locally. Use `--fullhd` to force pixel graphics. ## Visualization Modes | Mode | Description | |------|-------------| | **Cartoon** | Smooth ribbon rendering — helices, beta-sheets, and coils with Lambert shading. Default. | | **Wireframe** | All-atom bonds including inter-residue peptide and phosphodiester linkages. | | **Backbone** | CA trace (proteins) / C4' trace (nucleic acids) with spheres and thick connecting lines. | ## Interface Analysis & Interactions Press `f` to toggle interface mode — highlights contact residues across chain boundaries with a detailed sidebar. Press `I` to overlay interaction lines: | Color | Interaction | Distance | |-------|-------------|----------| | Cyan | Hydrogen bond | ≤ 3.5 Å | | Red | Salt bridge | ≤ 4.0 Å | | Yellow | Hydrophobic contact | ≤ 4.5 Å | | Gray | Other | ≤ 4.5 Å | ## Nucleic Acids Full support for DNA and RNA structures — backbone traces, wireframe bonds, and cartoon ribbons with nucleotide base-type coloring (A=red, U/T=blue, G=green, C=yellow). ## AlphaFold & pLDDT Automatically detects AlphaFold structures and offers pLDDT confidence coloring (blue = high confidence to orange/yellow = low confidence). Cycle through color schemes with `c`. ## Installation Requires [Rust 1.85+](https://www.rust-lang.org/tools/install). If you don't have Rust, install it with: ```bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` Then install proteinview: ```bash git clone https://github.com/001TMF/ProteinView.git cd ProteinView # Basic install cargo install --path . # With RCSB PDB fetch support cargo install --path . --features fetch # Update an existing installation cargo install --path . --force ``` ## Quick Start ```bash # View a local PDB file proteinview examples/1AOI.pdb # HD mode (fast text-based shading) proteinview examples/4HHB.pdb --hd # FullHD pixel mode (Kitty/Sixel terminals) proteinview examples/4HHB.pdb --fullhd # Headless FullHD pixel snapshot (no alternate screen or terminal probing) proteinview examples/4HHB.pdb --snapshot 4HHB.png # Fetch from RCSB and export a 1200x800 FullHD frame for inline display proteinview --fetch 1UBQ --snapshot 1UBQ.png \ --snapshot-width 1200 --snapshot-height 800 # Fetch from RCSB PDB proteinview --fetch 1UBQ # Choose color scheme and visualization proteinview examples/1UBQ.pdb --color rainbow --mode wireframe # FullHD biological interface view focused on chain A proteinview examples/4HHB.pdb --snapshot interface.png \ --snapshot-interface-chain A --snapshot-interactions # Hide ligands and ions in a snapshot proteinview examples/4HHB.pdb --snapshot polymer-only.png \ --snapshot-hide-ligands # Color exact residues (blank insertion code A:42 and insertion-coded A:42[A]) proteinview examples/4HHB.pdb --snapshot selected.png \ --residue-color A:42=FF0000 \ --residue-color 'A:42[A]=00FFFF' ``` `--snapshot` always uses the software pixel renderer behind **FullHD** and writes a PNG before any raw-mode, alternate-screen, or graphics-protocol setup. It is therefore safe to call from another terminal application. This is distinct from **HD**, which is the shaded text-cell renderer. Snapshot dimensions default to 1920×1080 and are capped at 4096 pixels per side and 8,388,608 total pixels. Snapshots can also focus one chain's interface, overlay classified inter-chain interaction lines, retain or hide ligands, and use any regular ProteinView color or visualization mode. These controls make the headless renderer suitable for iterative, conversational analysis in an agent chat. Interface highlighting uses its own green/orange focus/partner palette rather than a regular color scheme. Exact residue colors identify polymer residues by case-sensitive chain ID, signed sequence number, and optional insertion code. Omitting the insertion code selects only the blank code, not every residue with that number. Overrides use strict uppercase `RRGGBB` and take precedence over regular, element, pLDDT, and interface colors. ## Headless Panel Server (NDJSON) For a live agent-owned panel, start the persistent headless server with one private PNG path: ```bash proteinview examples/1UBQ.pdb --panel-server \ --output /tmp/proteinview-live.png \ --panel-width 960 --panel-height 540 ``` The server renders the initial frame, then writes a `ready` JSON object to stdout. It accepts one NDJSON command per stdin line, for example `{"id":1,"command":"rotate","axis":"y","delta":0.1}` or `{"id":2,"command":"resize","width":1200,"height":800}`. Successful state changes atomically replace the same PNG before their response is emitted. Responses include the request ID, monotonic revision, camera and presentation state, and exact frame path and dimensions. Use `get_state` without rendering or `shutdown` to acknowledge and exit. Diagnostics remain on stderr, and the server never emits terminal graphics escapes. Protocol requests and responses are each capped at 64 KiB; display-only structure names are sanitized and bounded, while structures whose required chain metadata cannot fit are rejected before the initial frame is rendered. An agent can replace all exact residue colors atomically with: ```json {"id":3,"command":"set_residue_colors","residues":[{"chain":"A","residue_number":42,"color":"FF0000"},{"chain":"B","residue_number":101,"insertion_code":"A","color":"00FFFF"}]} ``` An empty `residues` array clears the overrides. Invalid or duplicate targets leave the prior frame, state, and revision unchanged. See [panel-server.md](panel-server.md) for the full command reference. ## CLI Options ``` Usage: proteinview [OPTIONS] [FILE] Arguments: [FILE] Path to PDB, mmCIF, or XYZ file Options: --hd Use HD rendering (HalfBlock over SSH, FullHD locally) --fullhd, --pixel Force full pixel graphics (Sixel/Kitty/iTerm2) regardless of SSH --render Render mode: braille, halfblock (or hd), fullhd (or pixel) --color Color scheme: structure, element, chain, plddt, bfactor, rainbow [default: structure] --residue-color Override one exact polymer residue color: CHAIN:RES[ICODE]=RRGGBB --mode Visualization mode: cartoon, backbone, wireframe [default: cartoon] --fetch Fetch structure from RCSB PDB by ID --panel-server Run the persistent headless panel server over NDJSON stdin/stdout --output PNG path atomically replaced by the panel server --panel-width Initial panel framebuffer width in pixels [default: 960] --panel-height Initial panel framebuffer height in pixels [default: 540] --snapshot Render one FullHD pixel frame to a PNG and exit without starting the TUI --snapshot-width Snapshot width in pixels [default: 1920] --snapshot-height Snapshot height in pixels [default: 1080] --snapshot-interface-chain Highlight the interface for this focus-chain ID in a snapshot --snapshot-interactions Overlay classified interface interaction lines in a snapshot --snapshot-hide-ligands Hide ligands and ions in a snapshot --log Write debug log to file (e.g. --log debug.log) --threads Number of render threads [default: 4] -h, --help Print help -V, --version Print version ``` ## Keybindings | Key | Action | |-----|--------| | `h`/`l` | Rotate Y | | `j`/`k` | Rotate X | | `u`/`i` | Roll | | `+`/`-` | Zoom | | `w`/`a`/`s`/`d` | Pan | | `r` | Reset view | | `c` | Cycle color scheme | | `v` | Cycle viz mode | | `m` | Braille / HD | | `M` | HD / FullHD | | `f` | Interface analysis | | `I` | Interface interactions | | `g` | Toggle ligands | | `[`/`]` | Prev/next chain | | `Space` | Auto-rotate | | `?` | Help | | `q` | Quit | ## Color Schemes | Scheme | Description | |--------|-------------| | **Structure** | Helix (red), sheet (yellow), coil (green). Default. | | **Chain** | Distinct color per chain. | | **Element** | CPK coloring (C, N, O, S, P, metals). | | **B-factor** | Blue (rigid) to red (flexible). | | **Rainbow** | N-terminus (blue) to C-terminus (red). | | **pLDDT** | AlphaFold confidence (blue=high, orange=low). | ## Terminal Support | Terminal | Braille | HD | FullHD | |----------|---------|-----|--------| | Any Unicode terminal | Yes | Yes | -- | | Kitty | Yes | Yes | Yes (PNG) | | WezTerm | Yes | Yes | Yes (Sixel) | | iTerm2 | Yes | Yes | Yes | | foot | Yes | Yes | Yes (Sixel) | | tmux/screen | Yes | Yes | -- | ## Building ```bash cargo build --release # With RCSB fetch support cargo build --release --features fetch ``` ## License [MIT](LICENSE)