A modern Python reimagining of the XBS ball-and-stick crystal structure viewer
Project description
hofmann
A modern Python reimagining of Methfessel's XBS ball-and-stick viewer (1995), named after August Wilhelm von Hofmann who built the first ball-and-stick molecular models in 1865.
hofmann renders crystal and molecular structures as depth-sorted ball-and-stick images with static, publication-quality vector output (SVG, PDF) via matplotlib.
Features
- Static publication-quality output (SVG, PDF, PNG) via matplotlib
- XBS
.bsand.mv(trajectory) file formats - Optional pymatgen
Structureinteroperability - Periodic boundary conditions with automatic image expansion
- Coordination polyhedra with configurable shading and slab clipping
- Unit cell wireframe rendering
- Interactive viewer with mouse rotation, zoom, and keyboard controls
- Orthographic and perspective projection
Installation
pip install hofmann
For pymatgen interoperability:
pip install "hofmann[pymatgen]"
Requirements
- Python 3.11+
- numpy >= 1.24
- matplotlib >= 3.7
- scipy >= 1.10
- pymatgen >= 2024.1.1 (optional)
Quick start
From an XBS file
from hofmann import StructureScene
scene = StructureScene.from_xbs("structure.bs")
scene.render_mpl("output.svg")
From a pymatgen Structure
from pymatgen.core import Lattice, Structure
from hofmann import StructureScene, BondSpec
lattice = Lattice.cubic(5.43)
structure = Structure(
lattice, ["Si"] * 8,
[[0.0, 0.0, 0.0], [0.5, 0.5, 0.0],
[0.5, 0.0, 0.5], [0.0, 0.5, 0.5],
[0.25, 0.25, 0.25], [0.75, 0.75, 0.25],
[0.75, 0.25, 0.75], [0.25, 0.75, 0.75]],
)
bonds = [BondSpec(species=("Si", "Si"), max_length=2.8)]
scene = StructureScene.from_pymatgen(structure, bonds, pbc=True)
scene.render_mpl("si.pdf")
Controlling the view
scene.view.look_along([1, 1, 0]) # View along [110]
scene.view.zoom = 1.5 # Zoom in
scene.view.perspective = 0.3 # Mild perspective
scene.render_mpl("rotated.svg")
Interactive viewer
view, style = scene.render_mpl_interactive()
# Reuse the adjusted view for static output:
scene.view = view
scene.render_mpl("final.svg", style=style)
Documentation
Full documentation is available at hofmann.readthedocs.io, covering:
- Getting started -- installation and first renders
- Scenes and structures -- scenes, frames, bonds, polyhedra
- Rendering -- views, render styles, unit cells, axes
- Colouring -- per-atom data colouring, custom functions, multiple layers
- Interactive viewer -- mouse and keyboard controls
- XBS file format --
.bsand.mvformat reference - API reference -- full autodoc API
Citing hofmann
If you use hofmann in published work, please cite it:
B. J. Morgan, hofmann, https://github.com/bjmorgan/hofmann
A machine-readable citation is available in CITATION.cff.
Licence
MIT. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
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 hofmann-0.7.0.tar.gz.
File metadata
- Download URL: hofmann-0.7.0.tar.gz
- Upload date:
- Size: 106.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9c40a191ed79129b992b955a129e9d48f60681ee39dededb6142fa8ead1c9ba
|
|
| MD5 |
a1946b4f62e7a638219432f2700928a6
|
|
| BLAKE2b-256 |
fc6664ac39b49649e4ec8fd17876c012a4181354f98fe112fda5910e0865da8b
|
Provenance
The following attestation bundles were made for hofmann-0.7.0.tar.gz:
Publisher:
publish.yml on bjmorgan/hofmann
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hofmann-0.7.0.tar.gz -
Subject digest:
f9c40a191ed79129b992b955a129e9d48f60681ee39dededb6142fa8ead1c9ba - Sigstore transparency entry: 963003571
- Sigstore integration time:
-
Permalink:
bjmorgan/hofmann@175d9b7411011e8c43837740f43970b876018d8d -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/bjmorgan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@175d9b7411011e8c43837740f43970b876018d8d -
Trigger Event:
release
-
Statement type:
File details
Details for the file hofmann-0.7.0-py3-none-any.whl.
File metadata
- Download URL: hofmann-0.7.0-py3-none-any.whl
- Upload date:
- Size: 70.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dac6d5fb9116232ea48985bea2675f691c50fec433c4f4b5bdee9657d8fb0ce8
|
|
| MD5 |
d8386ae3deef074b2216f459dd6c8328
|
|
| BLAKE2b-256 |
a4e4c9bcb778793a759bf188c0d0639b88d28b67d1c6c4ccd79e3f1b6a339204
|
Provenance
The following attestation bundles were made for hofmann-0.7.0-py3-none-any.whl:
Publisher:
publish.yml on bjmorgan/hofmann
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hofmann-0.7.0-py3-none-any.whl -
Subject digest:
dac6d5fb9116232ea48985bea2675f691c50fec433c4f4b5bdee9657d8fb0ce8 - Sigstore transparency entry: 963003628
- Sigstore integration time:
-
Permalink:
bjmorgan/hofmann@175d9b7411011e8c43837740f43970b876018d8d -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/bjmorgan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@175d9b7411011e8c43837740f43970b876018d8d -
Trigger Event:
release
-
Statement type: