Skip to main content

MatterVis: Crystal Structure Visualization Toolkit

License: MIT Python Version PyPI CI

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 Mesh3d atoms and bonds, and a fast Scatter3d fallback 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 Figuresuniform_viewport(scenes) stamps a shared world-cube on any list of scenes so every build_figure call 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 serve works 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 ... — generate static figures (PNG/PDF/SVG/HTML) from CIF files, with full control over camera, style, colour, and display mode
  • mat-vis serve ... — launch the interactive Dash browser viewer with drag-and-drop CIF upload, topology analysis, and REST + WebSocket API
  • mat-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

matter_vis-0.0.2.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matter_vis-0.0.2-py3-none-any.whl (473.2 kB view details)

Uploaded Python 3

File details

Details for the file matter_vis-0.0.2.tar.gz.

File metadata

  • Download URL: matter_vis-0.0.2.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.6

File hashes

Hashes for matter_vis-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0c0a45dba5c64655c89d72b4cd42339f8b00d49666e4198d6b6bf3ec8cb17072
MD5 255697c3deb7985eabac5b27e520dd59
BLAKE2b-256 70fe630d513dd9422787d688599e819b44e7837ed4f40a3f2fdddb49f0425905

See more details on using hashes here.

File details

Details for the file matter_vis-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: matter_vis-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 473.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.6

File hashes

Hashes for matter_vis-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f4edf8129112254c89dc5840e48ec70f305c9e87d34914191ec91690c608e3af
MD5 e8f9f2a4c52dcea1aa42ea73640757d9
BLAKE2b-256 8c7b36973c4914de02a17214d324b8012496f50279d3a37fa519db26aa79d91d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

This release

0.0.2 This release

2 files

0.0.1

2 files

0.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page