Getting started

Installation

Install hofmann from PyPI:

pip install hofmann

For ASE interoperability (optional):

pip install "hofmann[ase]"

For pymatgen interoperability (optional):

pip install "hofmann[pymatgen]"

For animation export (optional):

pip install "hofmann[animation]"

For development (tests + docs):

pip install "hofmann[all]"

Requirements

Rendering from an XBS file

The XBS .bs file format describes atoms, species styles, and bond rules in a simple text format (see XBS file format).

from hofmann import StructureScene

scene = StructureScene.from_xbs("ch4.bs")
scene.render_mpl("ch4.svg")
CH4 rendered from an XBS file

The output format is inferred from the file extension: .svg, .pdf, and .png are all supported.

Rendering from ASE

If you have ASE installed, you can build a scene directly from an Atoms object:

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

Both periodic and non-periodic Atoms objects are supported. For periodic systems, fractional coordinates are wrapped into the unit cell automatically. For non-periodic systems (molecules), Cartesian positions are stored directly.

See from_ase() for full details.

Rendering from pymatgen

If you have pymatgen installed, you can build a scene directly from a Structure object:

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")
Diamond-cubic Si rendered from pymatgen

See from_pymatgen() for full details on periodic boundary condition expansion and polyhedra support. Partial-occupancy and solid-solution sites pass through automatically – see Partial and mixed occupancy.