megane-viewer 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,9 @@
11
11
  <a href="https://pypi.org/project/megane/"><img src="https://img.shields.io/pypi/v/megane" alt="PyPI" /></a>
12
12
  <a href="https://www.npmjs.com/package/megane-viewer"><img src="https://img.shields.io/npm/v/megane-viewer" alt="npm" /></a>
13
13
  <a href="https://github.com/hodakamori/megane/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" /></a>
14
+ <a href="https://pypi.org/project/megane/"><img src="https://img.shields.io/pypi/pyversions/megane" alt="Python" /></a>
15
+ <a href="https://hodakamori.github.io/megane/"><img src="https://img.shields.io/badge/docs-online-blue" alt="Docs" /></a>
16
+ <a href="https://codecov.io/gh/hodakamori/megane"><img src="https://codecov.io/gh/hodakamori/megane/graph/badge.svg" alt="codecov" /></a>
14
17
  </p>
15
18
 
16
19
  <p align="center">
@@ -29,8 +32,8 @@
29
32
  ## Features
30
33
 
31
34
  - **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.
32
- - **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.
33
- - **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.
35
+ - **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.
36
+ - **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.
34
37
  - **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.
35
38
 
36
39
  ### Scale
@@ -48,17 +51,17 @@ One codebase, every environment.
48
51
  | **Jupyter** | anywidget inline viewer | `pip install megane` |
49
52
  | **Browser** | `megane serve` local server | `pip install megane` |
50
53
  | **React** | `<MeganeViewer />` component | `npm install megane-viewer` |
51
- | **VSCode** | Custom editor for .pdb, .gro, .xyz | Extension |
54
+ | **VSCode** | Custom editor for .pdb, .gro, .xyz, .mol, .sdf, .cif | Extension |
52
55
 
53
- 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.
56
+ 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.
54
57
 
55
58
  ### Visual Pipelines
56
59
 
57
60
  Wire nodes to build visualization workflows — no code required.
58
61
 
59
- **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.
62
+ **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.
60
63
 
61
- **6 typed data channels** — particle, bond, cell, label, mesh, trajectory — flow through color-coded edges. Only matching types can connect.
64
+ **7 typed data channels** — particle, bond, cell, label, mesh, trajectory, vector — flow through color-coded edges. Only matching types can connect.
62
65
 
63
66
  Pipelines serialize to JSON, so you can save, share, and version-control your visualization recipes.
64
67
 
@@ -93,23 +96,37 @@ npm install megane-viewer
93
96
  ### Jupyter Notebook
94
97
 
95
98
  ```python
96
- import megane
99
+ from megane import Pipeline, LoadStructure, AddBonds, Viewport, MolecularViewer
100
+
101
+ # Build a pipeline
102
+ pipe = Pipeline()
103
+ s = pipe.add_node(LoadStructure("protein.pdb"))
104
+ bonds = pipe.add_node(AddBonds(source="distance"))
105
+ v = pipe.add_node(Viewport())
106
+ pipe.add_edge(s.out.particle, bonds.inp.particle)
107
+ pipe.add_edge(s.out.particle, v.inp.particle)
108
+ pipe.add_edge(bonds.out.bond, v.inp.bond)
109
+
110
+ # Display in notebook
111
+ viewer = MolecularViewer()
112
+ viewer.set_pipeline(pipe)
113
+ viewer
114
+ ```
97
115
 
98
- viewer = megane.MolecularViewer()
99
- viewer.load("protein.pdb")
100
- viewer # display in cell
116
+ ### CLI (Docker)
101
117
 
102
- # With trajectory
103
- viewer.load("protein.pdb", xtc="trajectory.xtc")
104
- viewer.frame_index = 50
118
+ ```bash
119
+ docker build -t megane .
120
+ docker run --rm -p 8080:8080 megane
105
121
  ```
106
122
 
107
- ### CLI
123
+ Open http://localhost:8080 in your browser.
124
+
125
+ To view your own files, mount them into the container:
108
126
 
109
127
  ```bash
110
- megane serve protein.pdb
111
- megane serve protein.pdb --xtc trajectory.xtc
112
- megane serve # upload from browser
128
+ docker run --rm -p 8080:8080 -v ./mydata:/data megane \
129
+ megane serve /data/protein.pdb --port 8080 --no-browser
113
130
  ```
114
131
 
115
132
  ### React
@@ -138,14 +155,19 @@ function App() {
138
155
  | XYZ | `.xyz` | Cartesian coordinate format |
139
156
  | MOL/SDF | `.mol`, `.sdf` | MDL Molfile (V2000) |
140
157
  | XTC | `.xtc` | GROMACS compressed trajectory |
158
+ | CIF | `.cif` | Crystallographic Information File |
159
+ | LAMMPS data | `.data`, `.lammps` | LAMMPS data file |
160
+ | ASE .traj | `.traj` | ASE trajectory (ULM binary format) |
161
+ | LAMMPS dump | `.lammpstrj` | LAMMPS dump trajectory |
141
162
 
142
163
  ## Development
143
164
 
144
165
  ### Prerequisites
145
166
 
146
167
  - Python 3.10+
147
- - Node.js 18+
168
+ - Node.js 22+
148
169
  - Rust (for building the parser)
170
+ - [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) (for building WASM bindings)
149
171
  - [uv](https://docs.astral.sh/uv/)
150
172
 
151
173
  ### Setup
@@ -154,6 +176,9 @@ function App() {
154
176
  git clone https://github.com/hodakamori/megane.git
155
177
  cd megane
156
178
 
179
+ # Install wasm-pack (if not already installed)
180
+ cargo install wasm-pack
181
+
157
182
  # Python
158
183
  uv sync --extra dev
159
184
 
@@ -162,6 +187,15 @@ npm install
162
187
  npm run build
163
188
  ```
164
189
 
190
+ ### Running `megane serve`
191
+
192
+ After setup, build and install the package, then start the server:
193
+
194
+ ```bash
195
+ maturin develop --release
196
+ megane serve protein.pdb
197
+ ```
198
+
165
199
  ### Development Mode
166
200
 
167
201
  ```bash
@@ -187,7 +221,7 @@ make test-all # All tests
187
221
  src/ TypeScript frontend
188
222
  renderer/ Three.js rendering (impostor, mesh, shaders)
189
223
  protocol/ Binary protocol decoder + web workers
190
- parsers/ WASM-based file parsers (PDB, GRO, XYZ, MOL, XTC)
224
+ parsers/ WASM-based file parsers (PDB, GRO, XYZ, MOL, CIF, XTC, LAMMPS, .traj)
191
225
  logic/ Bond / label / vector source logic
192
226
  components/ React UI components
193
227
  hooks/ Custom React hooks
@@ -198,6 +232,7 @@ crates/ Rust workspace
198
232
  megane-wasm/ WASM bindings (wasm-bindgen)
199
233
  python/megane/ Python backend
200
234
  parsers/ PDB / XTC parsers
235
+ pipeline.py Pipeline builder (NetworkX-style DAG)
201
236
  protocol.py Binary protocol encoder
202
237
  server.py FastAPI WebSocket server
203
238
  widget.py anywidget Jupyter widget