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 with static, publication-quality vector output (SVG, PDF) via matplotlib.

LLZO garnet with ZrO6 polyhedra rendered with hofmann

Features

  • Static publication-quality output (SVG, PDF, PNG) via matplotlib
  • XBS .bs and .mv (trajectory) file formats
  • Optional 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 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"), min_length=0.0,
                  max_length=2.8, radius=0.1, colour=0.5)]
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:

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.1.1.tar.gz (78.2 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.1.1-py3-none-any.whl (52.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hofmann-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d7573ba414917be98b1ebd79475368d8726c623fb701c5f049ceea1b18bfbbc8
MD5 4ff3bfb0bc471c8f4f9c3c753a42cde3
BLAKE2b-256 c22aecc4c91672ce831dd267aa42e8d8c7c097b229f7521e634c6d2e2f452ab9

See more details on using hashes here.

Provenance

The following attestation bundles were made for hofmann-0.1.1.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.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for hofmann-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a331dbbe49935a3e7f92de45e09a000217c8b3108d430af5dc2aa16b21445926
MD5 e180ff30ae71243e9c086ae37e37daa9
BLAKE2b-256 55301e9e9ab2a58793a8d460b3deb14a1878fce8503133b639084e23ba651e3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hofmann-0.1.1-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