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.2.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.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (790.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

megane-0.6.2-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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (790.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

megane-0.6.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (784.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

megane-0.6.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (792.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

megane-0.6.2-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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (792.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

megane-0.6.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (786.8 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: megane-0.6.2.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.2.tar.gz
Algorithm Hash digest
SHA256 35c94ee8d55f9a65630313e1cba989b9d8c47b522c6526248c109218a634abb3
MD5 da3ec07fc58b19b0c6e32f2315b106db
BLAKE2b-256 f4abc4a7d08a7d8bedad7a11ec090fe35f37895313ed5f9224f0460d28992ed8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 00ea55036402050ef1571752bf2ba32e16b949750eb82dcd77a88e4af923210b
MD5 579068ed2533775bde013ec1a1d2f3c0
BLAKE2b-256 09cc3f5e7bc4469f2133628bd1155e565e26027332601ff9c55d688ea1d64d8d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 06a69e1461292e018f7d191a080025487af62f863bc515df5fea931f14b0b9e2
MD5 ba89bbf584044469f96ec7444c3b3020
BLAKE2b-256 116b2ee41b892b41658cc62333f24b7106c04ff7616aa10fd8ed536e6c504ef2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc6bbcb3e065cbf0d8f2c1915bebce6f8fa41918c9076b17ad7c99f10bff1114
MD5 b3dbec04f6baa596d536fec64a894ac5
BLAKE2b-256 97e39ca854cbc0263169d696b06207b4489820bf7d39e40d90f008b929fa8d28

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cb19bb2eb154d2bdfc6321de8f139fa414b9b61761e793d7382ad2ae6fd37f07
MD5 53843c0ebd2e21861395113c971fe331
BLAKE2b-256 f380ac644bc363d4ed1bcaba6d84709dade6132dcbd178ef8a2c65e4d7e40f71

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 40db31a10cb94c3a8ead6ca6e19343f59ffc5660933bcb08361709a6b35ec0be
MD5 2551fa7bf030692737573dfdd35ba3ff
BLAKE2b-256 b96e2636e0d5106f1f2e09f07ef56a6d6ab4f88e5dc17419676eeefedcbbfc19

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8f618e46f9feb2d63f49ce0ad46334d25da51845ba371ebccf7d55fd5d31ead9
MD5 d08770030c3c3628b181f9c359b7f8bc
BLAKE2b-256 3ffac7636c0ce05d5a802c59a80932b095936f35c3dc097791fc4fd5c0db9213

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4a25afd419e79b23d06f3f7a4dffcb986dc3c228ca2b1a374da07b1b3dd3e7b8
MD5 6c28ef337bed73720588d28430c06888
BLAKE2b-256 3e395742861a48cac17d25a76f93c7db436010ee0534dbbb998a5fdbbf6df4d2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5d9e6246de277d1ab6dd47548413cf166335f53097d0594096285418ecfbc8e3
MD5 ef14e0016b3cb1021b3bdba197930e9b
BLAKE2b-256 e22740ea84107f8454759a888ed0197bf6d75c31432585f319003eff90e230d1

See more details on using hashes here.

Provenance

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