marimol
Fast, reactive, and beautiful 3D molecular and crystal visualizer for marimo notebooks.
marimol provides a clean, responsive, and interactive 3D WebGL molecular viewer built with Three.js and anywidget. It is designed from the ground up for marimo notebooks, enabling two-way reactivity: clicking atoms or playing through trajectories in the 3D viewport immediately updates downstream reactive notebook cells in real time.
Supports visualization of ASE, Pymatgen, mol-cspy, and native Python dictionaries with zero configuration.
For a more in depth documentation which includes interactive examples see: marimol.naujordep.com.
✨ Features
- ⚛️ Multi-format Support: Native visualizer functions for ASE (
ase.Atoms), Pymatgen (pymatgen.core.Structure/Molecule), mol-cspy (cspy.Crystal/cspy.Molecule), and standard Python dictionaries. - ⚡ Two-Way marimo Reactivity: Downstream cells automatically re-run when you click atoms (
viewer.selected_atoms) or scrub frames (viewer.current_frame). - 🎬 Trajectory Playback: Smooth multi-frame animations with play/pause, step forward/backward, configurable FPS, and an interactive frame scrubber slider.
- 📐 Measurement Tool: Built-in interactive ruler for measuring interatomic distances ($\text{Å}$), bond angles ($^\circ$), and dihedral / torsion angles ($^\circ$).
- 🧭 Coordinate Axis Snapping: Interactive XYZ triad in the corner—click X, Y, or Z to instantly align the camera along Cartesian axes.
- 🧊 Crystallography & Periodic Boundaries: Unit cell bounding boxes, crystallographic lattice vector indicators ($a, b, c$), and automatic molecule unwrapping across periodic boundary conditions (
unwrap_molecules=True). - 🎨 Visual Styles & Cel Shading: Ball-and-stick, Van der Waals (VDW), wireframe, stylized cartoon silhouette outlines (
draw_outlines=True), atom element/index labels (draw_labels=True), depth fog, and custom styles. - 📊 Metadata Drawer: Instant inspection of unit cell parameters ($a, b, c, \alpha, \beta, \gamma$), volume, density, and custom calculation results.
- 📸 Image Capture & Video Recording (added in v0.2.0): High-resolution PNG screenshots (S) and WebM/MP4 animation recordings (R) of trajectories or auto-spin loops directly to your downloads.
- ❓ Interactive Help & Controls Overlay (added in v0.2.0): Built-in cheatsheet of all keyboard and mouse interactions (toggle with H or the ? button).
- 🚀 High-Density Scalability & Battery Efficiency (added in v0.3.3): Shared singleton WebGL architecture completely eliminates browser WebGL context limits (no more crashed "sad face" canvases when opening dozens of viewers). Features automated viewport hibernation (
IntersectionObserver) and demand-driven rendering to keep idle GPU and CPU usage at ~0%.
📦 Installation
Install marimol via pip:
pip install marimol
To install with support for scientific packages (ASE, Pymatgen, and mol-cspy):
# Install all optional dependencies
pip install "marimol[external]"
# Or install individual libraries as needed
pip install "marimol[ase]"
pip install "marimol[pymatgen]"
pip install "marimol[cspy]"
🚀 Quick Start
1. Visualizing with ASE
import marimo as mo
from ase.build import molecule
from marimol import view_ase
# Visualize a molecule
mol = molecule("CH4")
view_ase(mol)
2. Visualizing with Pymatgen
from pymatgen.core import Lattice, Structure
from marimol import view_pymatgen
# Visualize a periodic crystal structure
lattice = Lattice.cubic(4.2)
structure = Structure(lattice, ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
view_pymatgen(structure, show_axes=True, draw_outlines=True)
3. Visualizing with mol-cspy
from cspy import Molecule
from marimol import view_cspy
mol = Molecule.load("aspirin.xyz")
view_cspy(mol, style="ball-and-stick")
4. Native Python Dictionary / Trajectory
from marimol import view_structure
# Single structure or list of frames for trajectories
data = {
"positions": [[0.0, 0.0, 0.0], [1.1, 0.0, 0.0]],
"species": ["C", "O"],
"bonds": [{"source": 0, "target": 1}],
# Optional 3D vector arrows (origin, end/direction, length, styling) *(added in v0.3.0)*
"vectors": [
{"origin": 0, "direction": [0.0, 0.0, 1.0], "length": 1.5, "color": "yellow", "outline": True},
],
}
view_structure(data)
🔄 Two-Way Reactivity in marimo
Because marimol widgets connect directly to marimo's reactive dataflow graph, you can access and respond to user interactions in downstream notebook cells:
# Cell 1: Render the viewer and assign to a variable
viewer = view_ase(mol)
viewer
# Cell 2: Automatically updates whenever the user selects atoms in the 3D viewer!
selected_indices = viewer.selected_atoms
f"Selected {len(selected_indices)} atom(s): {selected_indices}"
# Cell 3: Access current frame during trajectory playback
current_step = viewer.current_frame
f"Currently viewing trajectory frame: {current_step}"
🎮 Viewer Controls & Shortcuts
| Action | Control |
|---|---|
| Rotate | Left-click + Drag |
| Pan | Right-click + Drag |
| Zoom | Scroll wheel / Pinch trackpad |
| Select / Inspect Atom | Click atom (displays index, species, coords in info panel) |
| Multi-select Atoms | Shift + Click atoms |
| Clear Selection | Click on background canvas |
| Snap View to Axis | Click X, Y, or Z on the bottom-left coordinate triad |
| Measurement Tool | Click the Ruler icon (top-right), then pick 2 (dist), 3 (angle), or 4 (dihedral) atoms |
| Extra Data Drawer | Click the List icon (top-right) to expand the metadata drawer |
| Capture Screenshot | Click the Camera icon or press S (when recording_tools=True) (added in v0.2.0) |
| Record Animation | Click the Video icon or press R (when recording_tools=True) (added in v0.2.0) |
| Help & Shortcuts | Press H or click the ? icon to open the controls overlay (added in v0.2.0) |
| Close Help | Press Esc or click outside the modal (added in v0.2.0) |
⚙️ Configuration & Parameters
All viewer functions (view_structure, view_ase, view_pymatgen, view_cspy) accept the following arguments:
| Parameter | Type | Default | Description |
|---|---|---|---|
data / atoms / structure |
dict | list[dict] |
Required | Structure dictionary, list of dictionaries, or external library structure object. |
config |
dict | str | PathLike |
None |
Configuration dictionary, TOML string, or path to a .toml file. Explicit arguments will overwrite config settings. (added in v0.2.0) |
style |
str | dict |
"ball-and-stick" |
Representation style: "ball-and-stick", "vdw", "wireframe", or custom dict. |
background_color |
str |
"white" |
Viewport background color (e.g. "white", "black", "#1e1e1e", "transparent"). |
show_axes |
bool |
False |
Display interactive XYZ coordinate triad in the bottom-left corner. |
projection |
str |
"orthographic" |
Camera projection: "orthographic" (parallel projection) or "perspective". |
width |
str |
"100%" |
CSS width of the viewer container (e.g. "100%", "600px"). |
height |
str |
"400px" |
CSS height of the viewer container (e.g. "400px", "500px"). |
viewer_outline |
bool | str |
False |
Draw border around the viewport. True for subtle border or CSS border string. |
fog |
bool |
False |
Distance fog effect for depth cueing in large lattices. |
fog_strength |
float |
0.5 |
Strength of the fog effect ($0.0$ to $1.0$). |
clip_distance |
float |
0.0 |
Near camera clipping plane distance in Å. If 0.0 (default), near clipping is disabled. If positive, clips atoms closer to the camera than this distance. (added in v0.3.0) |
draw_outlines |
bool |
False |
Stylized cartoon / cel-shaded silhouette outlines around atoms and bonds. |
draw_labels |
bool |
False |
Element and index labels on atoms with 3D occlusion testing. |
measuring_tool |
bool |
False |
Enable ruler button in the top-right toolbar for distance and angle measurements. |
unwrap_molecules |
bool |
False |
Unwrap molecules split across periodic unit cell boundary conditions. |
structure_transparency |
float |
0.0 |
Transparency level for atoms and bonds ($0.0$ opaque to $1.0$ fully transparent), useful for viewing internal vectors. (added in v0.3.0) |
vector_width |
float |
0.08 |
Shaft radius / width for 3D vector arrows. (added in v0.3.0) |
vector_outline |
bool | str |
False |
Whether to draw outlines around 3D vector arrows (or outline color string). (added in v0.3.0) |
vector_color |
str |
"red" |
Default color name or hex code for 3D vector arrows. (added in v0.3.0) |
spin |
bool |
False |
Continuous automatic 3D rotation of the structure. |
spin_axis |
tuple[float, float, float] |
(0.0, 1.0, 0.0) |
Cartesian 3D axis vector around which the structure rotates during spin. |
spin_speed |
float |
2.0 |
Angular rotation speed for auto-spin (positive for CW, negative for CCW). |
multi_traj |
bool |
True |
Trajectory media playback controls (play/pause) for multi-frame data. |
traj_fps |
float |
10.0 |
Playback speed in frames per second for trajectory animations. |
trajectory_slider |
bool |
False |
Scrubbable timeline slider in the trajectory control bar. |
compute_extra_data |
bool |
False |
Automatically compute density, volume, lattice lengths & angles, atom count, and MW for the metadata drawer. |
extra_data |
Callable[[T], dict] |
None |
Custom callable accepting the structure/object and returning a dictionary of metadata for the extra data drawer (only available in view_ase, view_pymatgen, view_cspy). (added in v0.3.0) |
show_help |
bool |
True |
Show the help button and enable the H interactive controls overlay. (added in v0.2.0) |
recording_tools |
bool |
False |
Show screenshot (PNG) and video recording (WebM/MP4) buttons in the viewer toolbar. (added in v0.2.0) |
dpi |
int |
200 |
Resolution in dots per inch (DPI) for exported screenshots and video recordings. (added in v0.2.0) |
record_include_bgd |
bool |
False |
Include the background color in exported screenshots and video recordings (default is False for transparent backgrounds). (added in v0.2.0) |
record_include_ui |
bool |
False |
Include all viewer UI elements (playback controls, info panel, measurements, labels) in exported screenshots and video recordings. (added in v0.2.0) |
Configuration Presets (TOML / Dict) (added in v0.2.0)
You can maintain reusable visual presets across your notebooks using TOML strings, .toml files, or dictionaries:
toml_config = """
style = "ball-and-stick"
background_color = "#0f172a"
show_axes = true
spin = true
spin_speed = 1.5
measuring_tool = true
recording_tools = true
record_include_bgd = true
"""
# Explicit arguments take precedence and overwrite config values
view_structure(data, config=toml_config, background_color="#1e293b")
Custom Style Configuration
Pass a custom dictionary to style:
custom_style = {
"bond_radius": 0.12, # Cylinder radius for bonds in Å (0.0 hides bonds)
"atomic_radius_scaler": 0.8, # Scale factor multiplied by atomic/VdW radii
"hydrogen_atom_radius": 0.2, # Fixed radius override for hydrogen atoms
"fixed_atomic_radius": None, # Fixed radius override for all non-H atoms
"use_vdw_radii": False, # True for Van der Waals radii; False for covalent
}
view_structure(data, style=custom_style)
🚀 Interactive Examples
Interactive marimo example notebooks demonstrating molecules, trajectories, crystals, and presets are provided in the examples/ directory:
# Launch interactive marimo editor for all examples
uv run just examples
# Or edit a specific example notebook
uv run marimo edit examples/01_interactive_molecule_viewer.py
| Notebook | Description |
|---|---|
01_interactive_molecule_viewer.py |
Molecule visualization with UI controls (styles, themes, outlines, auto-spin) and two-way reactivity. |
02_trajectory_and_animation.py |
Multi-frame vibrational trajectory with media controls, scrubbable timeline, and video recording. |
03_crystal_structures_and_extra_data.py |
Periodic crystal lattices with unit cell wireframes, depth fog, and automated crystallographic metrics. |
04_toml_presets_and_themes.py |
Reusable visual presets loaded from TOML via config with parameter overrides. (added in v0.2.0) |
05_cspy_crystal_generation_and_custom_extra_data.py |
Crystal structure generation across space groups with custom extra_data callable. (added in v0.3.0) |
06_vector_data_and_arrows.py |
3D vector arrows for molecular dipole moments, vibrational forces, magnetic spins, and transparency. (added in v0.3.0) |
📝 Documentation
To run the interactive marimo documentation app locally:
uv run just docs-edit
Contributing
Contributions to marimol are very welcome! Whether you are reporting issues, adding support for new computational chemistry packages, improving WebGL performance, or enhancing documentation, here is how to get started:
1. Fork and clone the repository
- Fork the marimol repository to your own GitHub account by clicking the Fork button on GitHub.
- Clone your personal fork locally and switch to the
devbranch:
git clone https://github.com/<your-username>/marimol.git
cd marimol
git checkout dev
2. Set up the development environment & pre-commit hooks
We use uv for fast, reproducible dependency management and just for task automation. Install dependencies with all optional extras and dev tools:
# Install dependencies with all optional extras and dev tools
uv sync --all-extras
To keep code formatting and linting consistent across the codebase, pre-commit hooks must be installed:
# Install Git hook shims via just or prek
uv run just install-hooks
Once installed, automated checks (such as Ruff formatting and linting, trailing whitespace trimming, and YAML validation) will run automatically before every commit.
3. Code style and formatting
This project uses Ruff for linting and formatting. You can run checks manually at any time:
# Run linter
uv run just lint
# Format code
uv run just format
4. Running tests
Execute the test suite using pytest:
uv run just test
5. Previewing documentation & examples
To launch and edit the interactive documentation notebook locally:
uv run just docs-edit
To launch and browse the interactive example notebooks:
uv run just examples
To test exporting the documentation to HTML:
uv run just docs-build
6. Submitting a Pull Request
- Make sure your local
devbranch is up to date:git checkout dev git pull origin dev
- Create a feature branch branching off
dev:git checkout -b feature/my-new-feature
- Make your changes and commit them:
git commit -m "feat: add support for XYZ"
- Run checks to verify code formatting and tests:
uv run just check
- Push to your fork:
git push origin feature/my-new-feature
- Open a Pull Request from your feature branch to the
devbranch of Parzival1918/marimol.
📄 License
Distributed under the MIT License.
Metadata
Release files for marimol 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| marimol-0.3.3.tar.gz | 45.2 kB | With provenance | Details for marimol-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| marimol-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for marimol-0.3.3-py3-none-any.whl |
Total release size: 91.3 kB
Release files / marimol-0.3.3.tar.gz
| Download URL | marimol-0.3.3.tar.gz |
|---|---|
| Size | 45.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4a1de5162360a6308ebc642dbd69204e15de53b550904b4b3cdf155448ce95b
|
|
BLAKE2b-256 checksum How to use checksums |
07f6d2b234f241f72d6da68c4997e3f59123a893b19481e7ace1f1286fe401b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logRelease files / marimol-0.3.3-py3-none-any.whl
| Download URL | marimol-0.3.3-py3-none-any.whl |
|---|---|
| Size | 46.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c448fa8093eaa8dcf37b2bbde8b0423539d771a83394e25e26cf09d6b9356b66
|
|
BLAKE2b-256 checksum How to use checksums |
3dcf6ad8b84d70e708b16059c28f830d1b66251c7178e601fc9ad7d477d7d322
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logSecurity for marimol 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for marimol-0.3.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.