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.4.0.tar.gz (451.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.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (735.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

megane-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (732.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

megane-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (735.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

megane-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (732.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

megane-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (738.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

megane-0.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (734.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

megane-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (738.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

megane-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (734.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: megane-0.4.0.tar.gz
  • Upload date:
  • Size: 451.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.4.0.tar.gz
Algorithm Hash digest
SHA256 4616a98f9fa16d57648596dfbd389c433eef0bc8b3ce2fde147c432d26b7a215
MD5 d0bbfa132c79d03bf601d7dda00b9c07
BLAKE2b-256 8bff8ef9648d8bcee3226549feeaefdac12728f037549c5ae622d614563ef59c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f6c67bb76af2c045fcd34f047b1a82424cad994d935d23fe9df8e4ab983a9752
MD5 1538fe057d3281e960277b3cc9b4c8fb
BLAKE2b-256 ef9810fbcb130a1f11af7acfcb0beb88c304131b88473616a95731883b4f2cf3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 662ea0965c760556344a287b41b4b66aaef71551c56db37bdcdf4178c29f6f32
MD5 331b5fa5e420ca652dadd96694d5b40a
BLAKE2b-256 c57ecf03b992e92b6895b1bc3ddd8ee1f87d95b0aae1988045fd1fca9efa7c9d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b88c6026b88f9dd426e86eda5a83f2ee46fc0821feba271360adcde07f5d8c3
MD5 be34b9232bee479638e571c5c116a41f
BLAKE2b-256 9bdcc9595b31001425fd51be9de3f010e779ae94f7c922055f28402f69ff1616

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6decb43729ffa9ddc61ab27ea88b6b0ddf59032ced9687c8d65f3202a8f65c2f
MD5 9538e6af383b0e4baad332ae9ac66fc4
BLAKE2b-256 aeaee0adb0724334ce66e04844f54b9bab10f9c3d41225d3c9a6eabaaaac9470

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 692e74c9d0ffdbe2804d792592190f46cc6323a474b3c1890725de99b4cef349
MD5 65b566fa5480e309b91b21e73ba7f641
BLAKE2b-256 a60bf767e0901309f651a00f6041f60ec2494abb3f1e77083640b12deb64c435

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5d6ac337b40fdcc14ae4194827c590fd13edd8e3dedd82026c6cb1bff1d6c6d6
MD5 931606a7d0a18046078549259db0415e
BLAKE2b-256 dc86fd66b3a030dfaf40c3ada7763808e31e103261aac1d9a7512f3fa15d1771

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d01761d65a1eaf3d1e8fb738e2a74f1f4b7f5b0bee6397d44759dedbb62d956c
MD5 12bc6db1ab71ecf11333657b6b2f1f04
BLAKE2b-256 056b7e5aed41e6cf478083547b5c698692f65ef7c3ed36b1e78291102771169b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 038715511e8d2b87e5dcb8dd51a26bbbc408f506e0060c91f891f949d167ac41
MD5 5d69eb6c058f33b041c3c4c2fd3c3c6d
BLAKE2b-256 9523b4b2f5a44d1219b56d29a9c875b8cc3086ec29c890ed4f026aa993be347d

See more details on using hashes here.

Provenance

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