Skip to main content

A modern Python reimagining of the XBS ball-and-stick crystal structure viewer

Project description

hofmann

CI Documentation PyPI

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, producing publication-quality static output (SVG, PDF, PNG) and trajectory animations (GIF, MP4) via matplotlib.

LLZO garnet with ZrO6 polyhedra rendered with hofmann

Features

  • Static publication-quality output (SVG, PDF, PNG) via matplotlib
  • Trajectory animations (GIF, MP4) with per-frame colouring
  • XBS .bs and .mv (trajectory) file formats
  • Optional ASE Atoms and pymatgen Structure interoperability
  • 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 ASE interoperability:

pip install "hofmann[ase]"

For pymatgen interoperability:

pip install "hofmann[pymatgen]"

For animation export (GIF/MP4):

pip install "hofmann[animation]"

Requirements

  • Python 3.11+
  • numpy >= 1.24
  • matplotlib >= 3.7
  • scipy >= 1.10
  • ase >= 3.22 (optional)
  • pymatgen >= 2024.1.1 (optional)
  • imageio >= 2.30 (optional, for GIF animation export)
  • imageio-ffmpeg >= 0.5 (optional, for MP4 animation export)

Quick start

From an XBS file

from hofmann import StructureScene

scene = StructureScene.from_xbs("structure.bs")
scene.render_mpl("output.svg")

From ASE Atoms

from ase.build import bulk
from hofmann import StructureScene, BondSpec

atoms = bulk("Si", "diamond", a=5.43)
bonds = [BondSpec(species=("Si", "Si"), max_length=2.8)]
scene = StructureScene.from_ase(atoms, bonds)
scene.render_mpl("si.pdf")

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)
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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hofmann-0.18.0.tar.gz (104.1 kB view details)

Uploaded Source

Built Distribution

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

hofmann-0.18.0-py3-none-any.whl (117.8 kB view details)

Uploaded Python 3

File details

Details for the file hofmann-0.18.0.tar.gz.

File metadata

  • Download URL: hofmann-0.18.0.tar.gz
  • Upload date:
  • Size: 104.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hofmann-0.18.0.tar.gz
Algorithm Hash digest
SHA256 dfaf5a27c88cb753ad8980c5630e821a8e435c6d8e1bb01adb790e709ddb150b
MD5 12487ecf3993a8e05ac29606d4bb4142
BLAKE2b-256 fdf3e93fe35357dd9a1b34b6298ab0263ed16402242000e4fc9a9174f1927f88

See more details on using hashes here.

Provenance

The following attestation bundles were made for hofmann-0.18.0.tar.gz:

Publisher: publish.yml on bjmorgan/hofmann

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hofmann-0.18.0-py3-none-any.whl.

File metadata

  • Download URL: hofmann-0.18.0-py3-none-any.whl
  • Upload date:
  • Size: 117.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hofmann-0.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1e3aaac175fb48f680eadf138628b51ace6a2a5594984bf0e1f59cb81f47710
MD5 7e17e4ead69f8951c55efdfb0a244a0b
BLAKE2b-256 5c1f1df2080d0f519570c4b05060bdfb120813e19750e2ccc9f220d191121248

See more details on using hashes here.

Provenance

The following attestation bundles were made for hofmann-0.18.0-py3-none-any.whl:

Publisher: publish.yml on bjmorgan/hofmann

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page