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

import megane

viewer = megane.view("protein.pdb")
viewer  # displays in notebook

With a trajectory:

viewer = megane.view_traj("protein.pdb", xtc="trajectory.xtc")
viewer.frame_index = 50  # jump to frame 50

For advanced usage (filtering, multi-layer rendering, custom pipelines), see the Pipeline API.

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/lib";

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

Structure formats (LoadStructure node)

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)
LAMMPS data .data, .lammps LAMMPS data file
CIF .cif Crystallographic Information File

Trajectory formats (LoadTrajectory node)

Format Extension Description
XTC .xtc GROMACS compressed trajectory
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.6.1.tar.gz (462.3 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.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (790.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

megane-0.6.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (784.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

megane-0.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (790.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

megane-0.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (784.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

megane-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (792.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

megane-0.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (786.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

megane-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (792.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

megane-0.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (786.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for megane-0.6.1.tar.gz
Algorithm Hash digest
SHA256 0e810b2d58a683cfffd9cc820675d1af5b20c1f12d8f98a87ec22e1e8a17c995
MD5 4303c11e99d55c9ffae4067db42e19c2
BLAKE2b-256 82d1a9e3014f3af58912401cbb78270c5093032dd524a8a0052f5b1487f060d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1.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.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for megane-0.6.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97d102cdd63e16fe094c3ae65f31d053063a8b9bbc6c5f0cd9a213b4e791174d
MD5 1bec7b40059a48c5954016f0c1699422
BLAKE2b-256 fe85e6b2fca66b0089acdcbc74e1b49781fbf573f585fc3c3d8317128f65c635

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1-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.6.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for megane-0.6.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1dab8d902da226b99005f0ba1d6085d0a1ecd22280ab875862b559931b831d94
MD5 cb179678f9498d419ac0aa455beda0c3
BLAKE2b-256 863e570079a1b796f52da140588fa26cbb1b9fb103e47a8ae6a85c0e418780e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1-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.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for megane-0.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a59ee4b17cbb097063d51c3987d2e35c4053f7c722350d6d06df04abf40a59cc
MD5 546ec24e640a0b8314895308f5cda91b
BLAKE2b-256 6af854a18678ea8b3df070c2c98db1a6347f93c2d2e9ab8b1017ab4ae586602d

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1-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.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for megane-0.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 39169d4ccf9d197e8bc6bf916a9594581a242325d3f42d87fc02e0f71cf62834
MD5 56d937f924cabe4f9493a25e45679a13
BLAKE2b-256 d48fea8158aa1d420be0c6c47db9a736859e87a8d8c588cbb6a17e18fe820e25

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1-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.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for megane-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 763ba011bfd79896a7243852e38cb38b4d335f206d4b7fbdd552977a427fe530
MD5 5b2e4e93abcb2c3b5921c55382c13033
BLAKE2b-256 2aded970e81f78aca87edd990d9f7f1abac437a806e5eb5f103ac41a7d263660

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1-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.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for megane-0.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3c1280e8472255394379afa8e203b1c49cdcc3542556b2148a9404527d70b035
MD5 05dc7660b64148bfcd5b6610f1c22e00
BLAKE2b-256 0f0202c28b0efffa78433c9d7f09a8685a2ecd935dcfa3e12fb0506ee0980a34

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1-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.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for megane-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3edf4ce2a48efe39895d8a06a0d61e530928c6eaa138572589895c452f55a8ca
MD5 d84c6f1e6c34b128563585003dd59fae
BLAKE2b-256 056ca389705847b6899ba9a13f454b4aeb31639689d5032d30e34482b462fe29

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1-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.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for megane-0.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 935d1ca1c1352b7fcbc69aa14f9dc134974450c11af01d4f3ca2b2a1629db226
MD5 9c276cc16ce3bb5e3de652792a3daa01
BLAKE2b-256 e50cb83944dbb3052c78cd76e02ab33fa2f63f97edcee32de03ce77a57026643

See more details on using hashes here.

Provenance

The following attestation bundles were made for megane-0.6.1-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