megane-viewer 0.1.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/LICENSE +21 -0
- package/README.md +169 -0
- package/dist/widget.js +28456 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hodakamori
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<img src="docs/public/logo.png" alt="" width="32" />
|
|
3
|
+
megane
|
|
4
|
+
</h1>
|
|
5
|
+
|
|
6
|
+
<p align="center">Desktop-grade molecular visualization. Right in your browser.</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://github.com/hodakamori/megane/actions/workflows/ci.yml"><img src="https://github.com/hodakamori/megane/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
|
|
10
|
+
<a href="https://pypi.org/project/megane/"><img src="https://img.shields.io/pypi/v/megane" alt="PyPI" /></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/megane"><img src="https://img.shields.io/npm/v/megane" alt="npm" /></a>
|
|
12
|
+
<a href="https://github.com/hodakamori/megane/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License" /></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://hodakamori.github.io/megane/">Docs</a> ·
|
|
17
|
+
<a href="https://hodakamori.github.io/megane/getting-started">Getting Started</a> ·
|
|
18
|
+
<a href="https://pypi.org/project/megane/">PyPI</a> ·
|
|
19
|
+
<a href="https://www.npmjs.com/package/megane">npm</a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<p align="center">
|
|
23
|
+
<img src="docs/public/screenshots/hero.png" alt="megane screenshot" width="640" />
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Features
|
|
29
|
+
|
|
30
|
+
- **1M+ atoms at 60fps** — Billboard impostor rendering with WebGL handles massive protein complexes in real time
|
|
31
|
+
- **Jupyter, CLI, React** — Use as a Jupyter widget, serve from the command line, or embed the React component in your own app
|
|
32
|
+
- **Rust + WASM** — PDB, GRO, XYZ, MOL, and XTC parsers in Rust, shared between Python (PyO3) and browser (WASM)
|
|
33
|
+
- **Trajectory streaming** — Stream XTC trajectories over WebSocket in real time, scrub through thousands of frames
|
|
34
|
+
- **Atom selection & measurement** — Select 2–4 atoms to measure distances, angles, or dihedral angles
|
|
35
|
+
- **Adaptive rendering** — High-quality InstancedMesh for small systems, auto-switches to Billboard Impostor for large systems
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
### Python
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install megane
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### npm (for React embedding)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install megane
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
### Jupyter Notebook
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import megane
|
|
57
|
+
|
|
58
|
+
viewer = megane.MolecularViewer()
|
|
59
|
+
viewer.load("protein.pdb")
|
|
60
|
+
viewer # display in cell
|
|
61
|
+
|
|
62
|
+
# With trajectory
|
|
63
|
+
viewer.load("protein.pdb", xtc="trajectory.xtc")
|
|
64
|
+
viewer.frame_index = 50
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### CLI
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
megane serve protein.pdb
|
|
71
|
+
megane serve protein.pdb --xtc trajectory.xtc
|
|
72
|
+
megane serve # upload from browser
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### React
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import { MeganeViewer, parseStructureFile } from "megane";
|
|
79
|
+
|
|
80
|
+
function App() {
|
|
81
|
+
const [snapshot, setSnapshot] = useState(null);
|
|
82
|
+
|
|
83
|
+
const handleUpload = async (file: File) => {
|
|
84
|
+
const result = await parseStructureFile(file);
|
|
85
|
+
setSnapshot(result.snapshot);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return <MeganeViewer snapshot={snapshot} mode="local" /* ... */ />;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Supported File Formats
|
|
93
|
+
|
|
94
|
+
| Format | Extension | Description |
|
|
95
|
+
|--------|-----------|-------------|
|
|
96
|
+
| PDB | `.pdb` | Protein Data Bank |
|
|
97
|
+
| GRO | `.gro` | GROMACS structure file |
|
|
98
|
+
| XYZ | `.xyz` | Cartesian coordinate format |
|
|
99
|
+
| MOL/SDF | `.mol`, `.sdf` | MDL Molfile (V2000) |
|
|
100
|
+
| XTC | `.xtc` | GROMACS compressed trajectory |
|
|
101
|
+
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
### Prerequisites
|
|
105
|
+
|
|
106
|
+
- Python 3.10+
|
|
107
|
+
- Node.js 18+
|
|
108
|
+
- Rust (for building the parser)
|
|
109
|
+
- [uv](https://docs.astral.sh/uv/)
|
|
110
|
+
|
|
111
|
+
### Setup
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
git clone https://github.com/hodakamori/megane.git
|
|
115
|
+
cd megane
|
|
116
|
+
|
|
117
|
+
# Python
|
|
118
|
+
uv sync --extra dev
|
|
119
|
+
|
|
120
|
+
# Node.js
|
|
121
|
+
npm install
|
|
122
|
+
npm run build
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Development Mode
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# Terminal 1: Vite dev server
|
|
129
|
+
npm run dev
|
|
130
|
+
|
|
131
|
+
# Terminal 2: Python backend
|
|
132
|
+
uv run megane serve protein.pdb --dev --no-browser
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Tests
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
uv run pytest # Python tests
|
|
139
|
+
npm test # TypeScript unit tests
|
|
140
|
+
cargo test -p megane-core # Rust tests
|
|
141
|
+
make test-all # All tests
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Project Structure
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
src/ TypeScript frontend
|
|
148
|
+
renderer/ Three.js rendering (impostor, mesh, shaders)
|
|
149
|
+
protocol/ Binary protocol decoder + web workers
|
|
150
|
+
parsers/ WASM-based file parsers (PDB, GRO, XYZ, MOL, XTC)
|
|
151
|
+
logic/ Bond / label / vector source logic
|
|
152
|
+
components/ React UI components
|
|
153
|
+
hooks/ Custom React hooks
|
|
154
|
+
stream/ WebSocket client
|
|
155
|
+
crates/ Rust workspace
|
|
156
|
+
megane-core/ Core parsers and bond inference
|
|
157
|
+
megane-python/ PyO3 Python extension
|
|
158
|
+
megane-wasm/ WASM bindings (wasm-bindgen)
|
|
159
|
+
python/megane/ Python backend
|
|
160
|
+
parsers/ PDB / XTC parsers
|
|
161
|
+
protocol.py Binary protocol encoder
|
|
162
|
+
server.py FastAPI WebSocket server
|
|
163
|
+
widget.py anywidget Jupyter widget
|
|
164
|
+
tests/ Tests (Python, TypeScript, E2E)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## License
|
|
168
|
+
|
|
169
|
+
[MIT](LICENSE)
|