Skip to main content

A fast, beautiful molecular viewer

Project description

megane

Spectacles for atomistic data.

1M+ atoms at 60fps. Visual pipelines. Jupyter, browser, React, VSCode.

CI PyPI npm License Python Docs codecov

Docs · Getting Started · PyPI · npm

megane screenshot


Features

  • 1M+ Atoms at 60fps — Billboard impostor rendering scales from small molecules to massive complexes in real time. InstancedMesh for small systems auto-switches to GPU-accelerated billboard impostors for large systems. Stream XTC trajectories over WebSocket.
  • Runs Everywhere — Jupyter widget, CLI server, React component, and VSCode extension. Rust-based PDB, GRO, XYZ, MOL, CIF, XTC, LAMMPS, and ASE .traj parsers shared between Python (PyO3) and browser (WASM) — parse once, run anywhere.
  • Visual Pipeline Editor — Build visualization workflows by wiring nodes or let the AI generator build them from natural language. 11 node types with 7 typed data channels flowing through color-coded edges. Load multiple structures with layer-based rendering to compare systems side by side.
  • Embed & Integrate — Control the viewer from Plotly via ipywidgets events. Embed in MDX / Next.js docs. React to frame_change, selection_change, and measurement events. Use the framework-agnostic renderer from Vue, Svelte, or vanilla JS.

Scale

megane renders over 1 million atoms at 60fps in the browser. Small systems get high-quality InstancedMesh spheres and cylinders; large systems automatically switch to GPU-accelerated billboard impostors. No desktop app, no plugin — just a browser tab.

Trajectory streaming works over WebSocket via a binary protocol. Load an XTC file and scrub through thousands of frames in real time, without reading everything into memory.

Anywhere

One codebase, every environment.

Environment How Install
Jupyter anywidget inline viewer pip install megane
Browser megane serve local server pip install megane
React <MeganeViewer /> component npm install megane-viewer
VSCode Custom editor for .pdb, .gro, .xyz, .mol, .sdf, .cif Extension

The secret: PDB, GRO, XYZ, MOL, CIF, XTC, LAMMPS, and ASE .traj parsers are written in Rust and compiled to both PyO3 (Python) and WASM (browser). Parse once, run anywhere.

Visual Pipelines

Wire nodes to build visualization workflows — no code required.

11 node types across 5 categories: load data (structure, trajectory, streaming, vector), process (filter, modify), overlay (bonds, labels, polyhedra, vectors), and display in a 3D viewport.

7 typed data channels — particle, bond, cell, label, mesh, trajectory, vector — flow through color-coded edges. Only matching types can connect.

Pipelines serialize to JSON, so you can save, share, and version-control your visualization recipes.

Integrate

megane is not a walled garden. It fits into your existing workflow.

Plotly — Click a point on a Plotly FigureWidget to jump to a trajectory frame. Use megane's on_event("frame_change") callback to update Plotly markers in sync.

MDX / Next.js — Drop <MeganeViewer /> or <Viewport /> into your .mdx documentation. WASM parsing works out of the box with a one-line webpack config.

ipywidgets — React to frame_change, selection_change, and measurement events. Compose megane with any widget in the Jupyter ecosystem.

Framework-agnosticMoleculeRenderer is a plain Three.js class. Mount it in Vue, Svelte, or a vanilla <div>.

Installation

Python

pip install megane

npm (for React embedding)

npm install megane-viewer

Quick Start

Jupyter Notebook

from megane import Pipeline, LoadStructure, AddBonds, Viewport, MolecularViewer

# Build a pipeline
pipe = Pipeline()
s = pipe.add_node(LoadStructure("protein.pdb"))
bonds = pipe.add_node(AddBonds(source="distance"))
v = pipe.add_node(Viewport())
pipe.add_edge(s.out.particle, bonds.inp.particle)
pipe.add_edge(s.out.particle, v.inp.particle)
pipe.add_edge(bonds.out.bond, v.inp.bond)

# Display in notebook
viewer = MolecularViewer()
viewer.set_pipeline(pipe)
viewer

CLI (Docker)

docker build -t megane .
docker run --rm -p 8080:8080 megane

Open http://localhost:8080 in your browser.

To view your own files, mount them into the container:

docker run --rm -p 8080:8080 -v ./mydata:/data megane \
  megane serve /data/protein.pdb --port 8080 --no-browser

React

import { MeganeViewer, parseStructureFile } from "megane-viewer";

function App() {
  const [snapshot, setSnapshot] = useState(null);

  const handleUpload = async (file: File) => {
    const result = await parseStructureFile(file);
    setSnapshot(result.snapshot);
  };

  return <MeganeViewer snapshot={snapshot} mode="local" /* ... */ />;
}

Supported File Formats

Format Extension Description
PDB .pdb Protein Data Bank
GRO .gro GROMACS structure file
XYZ .xyz Cartesian coordinate format
MOL/SDF .mol, .sdf MDL Molfile (V2000)
XTC .xtc GROMACS compressed trajectory
CIF .cif Crystallographic Information File
LAMMPS data .data, .lammps LAMMPS data file
ASE .traj .traj ASE trajectory (ULM binary format)
LAMMPS dump .lammpstrj LAMMPS dump trajectory

Development

Prerequisites

  • Python 3.10+
  • Node.js 22+
  • Rust (for building the parser)
  • wasm-pack (for building WASM bindings)
  • uv

Setup

git clone https://github.com/hodakamori/megane.git
cd megane

# Install wasm-pack (if not already installed)
cargo install wasm-pack

# Python
uv sync --extra dev

# Node.js
npm install
npm run build

Running megane serve

After setup, build and install the package, then start the server:

maturin develop --release
megane serve protein.pdb

Development Mode

# Terminal 1: Vite dev server
npm run dev

# Terminal 2: Python backend
uv run megane serve protein.pdb --dev --no-browser

Tests

uv run pytest              # Python tests
npm test                   # TypeScript unit tests
cargo test -p megane-core  # Rust tests
make test-all              # All tests

Project Structure

src/                     TypeScript frontend
  renderer/              Three.js rendering (impostor, mesh, shaders)
  protocol/              Binary protocol decoder + web workers
  parsers/               WASM-based file parsers (PDB, GRO, XYZ, MOL, CIF, XTC, LAMMPS, .traj)
  logic/                 Bond / label / vector source logic
  components/            React UI components
  hooks/                 Custom React hooks
  stream/                WebSocket client
crates/                  Rust workspace
  megane-core/           Core parsers and bond inference
  megane-python/         PyO3 Python extension
  megane-wasm/           WASM bindings (wasm-bindgen)
python/megane/           Python backend
  parsers/               PDB / XTC parsers
  pipeline.py            Pipeline builder (NetworkX-style DAG)
  protocol.py            Binary protocol encoder
  server.py              FastAPI WebSocket server
  widget.py              anywidget Jupyter widget
tests/                   Tests (Python, TypeScript, E2E)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

megane-0.5.0.tar.gz (455.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

megane-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (742.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

megane-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (738.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

megane-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (742.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

megane-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (739.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

megane-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (744.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

megane-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (741.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

megane-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (744.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

megane-0.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (741.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

Details for the file megane-0.5.0.tar.gz.

File metadata

  • Download URL: megane-0.5.0.tar.gz
  • Upload date:
  • Size: 455.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for megane-0.5.0.tar.gz
Algorithm Hash digest
SHA256 4838d53f448d34dee01030da442877a9a0f79f7d1ca9a653034196fc6fec391d
MD5 49f0e85b1f7827ada281d40463a7b015
BLAKE2b-256 9bf63d64c8ddc6b559ccf9430e7fdfe0c65f29e0591b38a8066bd696ab24e6e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0.tar.gz:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megane-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for megane-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42caa5924a4a36742bb5d0ba0623c4b6f28f6eac4742131efe581a472f307f00
MD5 1b8bf30eb71630db40941cebd7704c7b
BLAKE2b-256 6a21b0696bebc3f50f149ffbe736897bbe9812b0be39783eceed106e86c45021

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megane-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for megane-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8f68c85dcf0c0af346399602825914094338db6c2f431578c91f19dd146384fc
MD5 ca5a2c418f602842e96252139c5aa8f5
BLAKE2b-256 675eeeebb194be6f07e80856f51165fd23d60bee02284ca0bb48a60b4bd3d306

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megane-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for megane-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ddfd298c8ee92033b24fe402d4a65deb401c399ad449858ed3358a2a2ccb2088
MD5 a8514d972adb650fdb94d856a8858e68
BLAKE2b-256 3f4515ecd5f756e5f741fa51faebc94946cb4104b82682587df8c471297722a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megane-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for megane-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2e1db4af4d52c055f56747d72daa0cd78e7976a2c82b17287b7514822429f1f3
MD5 bbe128d3878210051048161ddbb76ce3
BLAKE2b-256 a979e291d0e0eccde2f9f6a2364457ae96b23734c0c14cc4f84223c2fa170a83

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megane-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for megane-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4bf2f753a1da7e87acc9c1617121679e7d46530a6b3be7bd6bb5908a32e6a34f
MD5 cf1cf3fd19c9b2f007be1ec0feff854e
BLAKE2b-256 d0ed2cf77409ff556b8647c0d607c0c3ef260c1cdd59162b0bb213862da3a5e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megane-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for megane-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 53dacda5d7a42735a9054919e6b83b81c965644b853af7a14d036c3081a48c1b
MD5 7e6b334c381127ce5c8b20e099c0f197
BLAKE2b-256 8e166d4667f54d0ad80955202cfc6597b0ce788133d8daf459fce1a7aa9bfa96

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megane-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for megane-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9542545dab042896347953715cb6b51bb6a3f19b6b60d5541e6ebc9dfaf91d9e
MD5 64aeda061e43c880b2f9548cca3f176c
BLAKE2b-256 7a2923eaf857e4871ba227d034e476e123413260460178dbc7da3a350363ea45

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megane-0.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for megane-0.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7c81852c20407a9f084ca61fb94dc7fa1c11cca11b79a820d9ff34483c485409
MD5 84c47d113a69cd3130ecacc6c260fc53
BLAKE2b-256 943262ddd8f7925c60e3ae07cf98cbbb8c8fa1d58714903d894df2c908b38c2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish-pypi.yml on hodakamori/megane

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page