MatterVis: Crystal Structure Visualization Toolkit
Overview
MatterVis is a Python toolkit for interactive and publication-quality visualization of crystal structures. Built on Dash and Plotly, it provides a browser-based 3D viewer, coordination-topology analysis, ORTEP-style Matplotlib export, and a REST + WebSocket API for agent-driven automation.
Key Features
- Headless CLI — Three subcommands (
render,serve,tui) cover the full workflow: CIF → publication-quality figure, interactive 3D viewer, or terminal-based inspection. Ideal for batch processing, CI pipelines, and remote servers - Browser Viewer — Drag-and-drop CIF upload, interactive 3D display with
Mesh3datoms and bonds, and a fastScatter3dfallback for large cells. The viewer uses the built-in element palette by default - Coordination Topology — Automatic coordination-number detection via the nearest-neighbour gap, continuous shape measure (CShM) classification against 12 ideal polyhedra (CN 4–12), planarity RMS, and prism/antiprism twist analysis
- Publication Export — Vendored ORTEP-style Matplotlib renderer with correct depth ordering, two-colour bonds, smart label placement, and configurable presets
- Multi-Panel Figures —
uniform_viewport(scenes)stamps a shared world-cube on any list of scenes so everybuild_figurecall emits at the same physical length per pixel - Automation API — REST + WebSocket endpoints on the same Flask server; drive the viewer from notebooks, agents, or subprocesses
- Zero Catalog Required — Ships with a bundled DAP-4.cif so
mat-vis serveworks out of the box
Unit Cell — DAP-4 unit cell (flat ORTEP with element colours)
Coordination Shell — A-site coordination with convex hull overlay (CN=9, tricapped trigonal prism)
Three Display Modes — Formula unit, unit cell, and coordination shell side by side
Publication-Quality Export — Colour ORTEP-style Matplotlib renderer with labels
Asymmetric Unit — Diagnostic crystallographic view with atom labels and unit-cell context
Installation
From PyPI (recommended)
pip install matter-vis
From source (development)
git clone https://github.com/SchrodingersCattt/MatterVis.git
cd MatterVis
pip install -e .
All dependencies are declared in pyproject.toml.
requires-python = ">=3.10". The available extras are:
| Extra | Adds |
|---|---|
[test] |
pytest>=8.0, pytest-cov |
[dev] |
[test] + build, ruff |
molcrys_kit is an optional runtime dependency. When available, the per-fragment
A/B/X heuristic uses its classifier; otherwise crystal_viewer uses built-in
element/size heuristics.
Quick Start
CLI — one-liner from CIF to figure
Install MatterVis, then render a crystal structure with a single command:
# PNG with default ball-and-stick style
mat-vis render structure.cif -o figure.png
# PDF, full unit cell, ORTEP hatch shading in greyscale
mat-vis render structure.cif -o figure.pdf \
--view unit_cell --style ortep --ortep-mode ortep_hatch --monochrome
# Interactive HTML for supplementary information
mat-vis render structure.cif -o si_figure.html \
--show-hydrogen --show-labels
# Launch the interactive browser viewer
mat-vis serve --cif structure.cif
See docs/cli.md for the full flag reference and common recipes.
Python API — programmatic control
from crystal_viewer.loader import build_bundle_scene, build_loaded_crystal
from crystal_viewer.renderer import build_figure
from crystal_viewer.scene import scene_style
bundle = build_loaded_crystal(name="DAP-4", cif_path="scripts/data/DAP-4.cif")
scene = build_bundle_scene(bundle, display_mode="unit_cell")
style = scene_style(scene, {"show_unit_cell": True})
fig = build_figure(scene, style)
fig.write_image("dap4.png", width=900, height=720, scale=2)
fig.write_html("dap4.html", include_plotlyjs="cdn")
Command Line Interface
Installing MatterVis also installs the mat-vis command. The CLI is self-documenting;
use --help at any level to see the exact arguments:
mat-vis --help
mat-vis render --help
mat-vis serve --help
mat-vis tui --help
The three subcommands cover:
mat-vis render ...— render atomistic structures and trajectories from CIF, Cube, VASP, XYZ, ASE, and LAMMPS inputs to PNG/PDF/SVG/HTML/GIF/MP4mat-vis serve ...— launch the interactive Dash browser viewer with drag-and-drop CIF upload, topology analysis, and REST + WebSocket APImat-vis tui ...— terminal-based crystal structure viewer for headless servers and SSH sessions
Documentation
| You are… | Start here |
|---|---|
| Using the library | API Reference · CLI Reference |
| AI agent (calling MatterVis) | Caller API Contracts |
| AI agent (modifying code) | AGENTS.md · Developer Notes |
| Topology scores | Scores Reference |
crystal_viewer/ — source code · scripts/ — runnable demo scripts · docs/ — full documentation
License
This project is licensed under the MIT License — see the LICENSE file for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matter_vis-0.0.3.tar.gz.
File metadata
- Download URL: matter_vis-0.0.3.tar.gz
- Upload date:
- Size: 2.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc6501207c2529986a656f782d122866fa99fa41e7209efcd8cead2f58ced802
|
|
| MD5 |
fc477d218961a0f71c86880a7354dd97
|
|
| BLAKE2b-256 |
745984d9b6f64f00007ddf1d2da3a521f49ab13b0a23da20792f199689d5a528
|
File details
Details for the file matter_vis-0.0.3-py3-none-any.whl.
File metadata
- Download URL: matter_vis-0.0.3-py3-none-any.whl
- Upload date:
- Size: 477.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e3632f3bea7695dc91ff381195a8fb758f010d196434919faa818a58a91d7b1
|
|
| MD5 |
745f302deabf46cee3af3452e454bbf2
|
|
| BLAKE2b-256 |
2e9ac62edb0c24447bf31ac05702ace74391d5a5d636ced5689342e730ae5543
|