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

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

megane-0.6.0-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.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (790.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

megane-0.6.0-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.0-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.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: megane-0.6.0.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.0.tar.gz
Algorithm Hash digest
SHA256 a9feb6e803da0f53261cf4e3c8c8f3df0eac25d00051939b4492feb990a30684
MD5 2b7fdcff42bb5e2ff76edb2c5828109d
BLAKE2b-256 4c3185da7ab0460017971018724b174507a2a002a5437eeb8e11677c5028e7aa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15a2c61faba6db1ee683d631eaa175c1822ea666d775c34fe3deffc7bb86ec22
MD5 ab906717804e655d21a3302f89087098
BLAKE2b-256 274f25c70c42e5899ee59b3a1c3370a19e5c87e96b7378a3d206a4b6a24aa257

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bcfeacbb07784e7f07ad353b0a1f9baa82966e064e2bd67a45ab69260f3786bb
MD5 6a846ce4a8e4dba13bdfe294a9ea9b58
BLAKE2b-256 37fea450df8a84c577137d703ed3bb6dc15019ece0f18dd01a585d81b5f42315

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8dfc1415d8c7c80b4ca2a1ef6c10e5d98a13fcb219208381163b80428c5e52ee
MD5 f0e3047f28011ac1f111c8842267d831
BLAKE2b-256 1718a5e682d1337c45f729a588c7b740580305443b6dd8b187549b8ae9db9388

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 92fe64ea7082c8d4eb8e148f2ef6f519292093f9f465a5bc7674ddaf3162f227
MD5 9fc95a3afaf48c6206526ef9264d3ffa
BLAKE2b-256 4205de95f9b05c9271e2b2017634e1df4b79247eeb38a9911a397560b01f41d9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e2cd7e054c91eb6d0a21073c23b444f1104b96f14094ecd3fa3b0b0adcfbf5a8
MD5 c625968078460f30381dc080078cfc38
BLAKE2b-256 7c3ad3c1c538dd18986a5a0354060611c6873e84a00d644158b428c45a6f659c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 84fcbbe9f0eac54c774747d7bdc2debaf79ab1f0c23cf9fb728f00a1b7f44164
MD5 1ec4e37809601ad1e7cf121de8027852
BLAKE2b-256 7f6bbdbfd9fc382982c368fca98b6f29383be9a5d081e900368827f7fc072bc9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc3a6e956c31daab6a684d317e01c088bc53bd613f2bd571504bcfebf92fb3ff
MD5 5dd50ccaee02451549c2cb714e8b3bf9
BLAKE2b-256 c8183886cd0654e3aa8e78c2ae6abe4f4aa4ddf74a6bdfe10acedb5ff25c3e95

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for megane-0.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b532764487c1938236207d716bcf88db75d998b3387fea3c1ded5bb725283776
MD5 cea27991c6e7d1d73e9129dd864aae44
BLAKE2b-256 765ed45ad059aa2133bac3b50d51ae92cd31185beef7819512cf5d94093dffcb

See more details on using hashes here.

Provenance

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