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

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, and XTC parsers shared between Python (PyO3) and browser (WASM) — parse once, run anywhere.
  • Visual Pipeline Editor — Build visualization workflows by wiring nodes. 8 node types (load, bond, filter, modify, labels, polyhedra, viewport) with 6 typed data channels (particle, bond, cell, label, mesh, trajectory) flowing through color-coded edges.
  • 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 Extension

The secret: PDB, GRO, XYZ, MOL, and XTC 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.

8 node types across 5 categories: load data, add bonds, filter atoms by query, modify scale and opacity per-group, generate labels, render coordination polyhedra, and display in a 3D viewport.

6 typed data channels — particle, bond, cell, label, mesh, trajectory — 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.MolecularViewer()
viewer.load("protein.pdb")
viewer  # display in cell

# With trajectory
viewer.load("protein.pdb", xtc="trajectory.xtc")
viewer.frame_index = 50

CLI

megane serve protein.pdb
megane serve protein.pdb --xtc trajectory.xtc
megane serve  # upload from 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

Development

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Rust (for building the parser)
  • uv

Setup

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

# Python
uv sync --extra dev

# Node.js
npm install
npm run build

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, XTC)
  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
  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.3.0.tar.gz (383.2 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.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (655.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

megane-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (653.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

megane-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (654.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

megane-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (653.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

megane-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (657.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

megane-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (656.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

megane-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (657.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

megane-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (656.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

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

File metadata

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

File hashes

Hashes for megane-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e876b2202c17416e33e86f411f1071bcadfc4d4b19e8609cc27243261d2dc298
MD5 9f8e4aa4697f576a0cbdd7519eb5ddff
BLAKE2b-256 20bd431f1ef437adb36981d5186de58efc4d620d4022ebc3965702f4ca13f579

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 980fc0082c4afd0c08b1557da88f5e90d9c6c3e879884391ab1afe585bf8c4e2
MD5 b6656e4be28356f4707ca9c3fd94a247
BLAKE2b-256 8490173932280c754f18c66017e24ef571b86bf8384849e2664ef9a1c16e6834

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 34ede43832b10f8ed681ebfc2a85ce9ed79b65d94783e1860f93436f75f2c6ea
MD5 7b982631970ef4e0ddbdbd59b74f28ea
BLAKE2b-256 a69f383e4a679915471758fc06cb1fee7c09db99ee9f8b94beb65a53f1404a27

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 efed7081b182544cba8f2dae4b9a5850ba4d5524c746cce7631ea852bee30274
MD5 5912704ae68c1c32b2fc48593026eca3
BLAKE2b-256 01fcbd0a78303bb3146c86784ff9504cb22d52efe5c1d61250e65fc479f2cf7b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f503da14fd4072618a74fa82fa2b189cc4cbec7a71cd669f46530a15e170ea53
MD5 30fe7caf61395486390cad71c6e8e2ea
BLAKE2b-256 8ee7a3f1da4190874254a5ef0ba138980f2939437a4c069e04a9f2cca6aae22a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75084e377bf8e7930c1651ee690a0ae6a10dfbd9a90b224f1c26a152177f44ce
MD5 d77f153b390a3a058abcc524d125ce7c
BLAKE2b-256 79bdcc3c34f484745112455fa5374eef3d3b998d52b5df522888326fc775ff3d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f09fd6e639037a96ee85cb38148ec27c31bb27d823031abe3329e83efdac85e0
MD5 dde795296c96be697110620e2a21ce6b
BLAKE2b-256 1108d8f0a47e48a4348727a7cecf23fc00bfcb78ed0274449b0185713af06439

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d521c210e8d1a201c35dbd660019dbbae72578468fca16b2cf686a2191908c0b
MD5 2bc1e83b3af5a2e001776b9ba6432031
BLAKE2b-256 d0452de11390e569e8d72a026255ebbdaadef114bef2f7e5e26c59be7c37f519

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8d8303df5fa831aec5ff80583ceb805843bbfc096395d83bc39ffd4f2eae1a30
MD5 0191d7e346cd6d12ebad3384762d482f
BLAKE2b-256 d98d31be77b9d9866bd273d85b3f82cc27a9c80a283151011ba5bf31d92bd041

See more details on using hashes here.

Provenance

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