Skip to content

API Reference

unitcell.PrimitiveCell

A periodic primitive lattice defined by the standard crystallographic cell parameters: edge lengths a, b, c and angles alpha (between b and c), beta (between a and c), gamma (between a and b).

From these six parameters PrimitiveCell builds the real-space basis vectors a1, a2, a3 — oriented so that a1 lies along x and a2 lies in the xy plane — and their corresponding reciprocal-lattice vectors b1, b2, b3.

PrimitiveCell(a=1., b=1., c=1., alpha=90., beta=90., gamma=90., name='')

Attributes

Name Description
name Optional label for the cell.
a, b, c Edge lengths. Settable; assigning recomputes the basis and reciprocal vectors.
alpha, beta, gamma Angles between the edges, in degrees. Settable, with the same recompute behavior.
al, bet, gam alpha, beta, gamma converted to radians.
a1, a2, a3 Real-space basis vectors, as Vec3.
b1, b2, b3 Reciprocal-lattice vectors, as Vec3.

Methods

Method Description
get_vector(u, v, w) Real-space position of lattice site (u, v, w) as a Vec3.
get_point(u, v, w) Same, as an (x, y, z) tuple.
get_pos(u, v, w) Alias for get_vector.
iter_vectors(xr, yr, zr) Iterate over lattice points in a range, yielding Vec3s.
iter_points(xr, yr, zr) Same, yielding (x, y, z) tuples.
get_basis() Return (a1, a2, a3).
get_reciprocals() Return (b1, b2, b3).
get_normal(h, k, l) Unit vector normal to the (h k l) plane.
get_planedist(h, k, l) Spacing between adjacent (h k l) planes.
xrotate(theta), yrotate(theta), zrotate(theta) Rotate the whole cell by theta degrees around x/y/z. Rotations are recorded and replayed whenever the cell parameters change.
update_reciprocals() Recompute b1, b2, b3 from the current a1, a2, a3. Call after modifying the basis vectors directly.
reset_history() Clear the recorded rotation history (does not change the current orientation).

unitcell.UnitCell

Subclass of PrimitiveCell that adds a basis of sites to the primitive lattice.

UnitCell(a=1., b=1., c=1., alpha=90., beta=90., gamma=90.,
         sites=[('X', 0, 0, 0)], name='')

sites is a list of (id, u, v, w) tuples giving each basis site's label and fractional coordinates within the cell.

Properties

Name Description
siteids Set of the unique site ids defined in the basis.
nsites Number of sites defined in the basis.

Methods

Method Description
get_vector(u, v, w, n=0) Position of basis site n in cell (u, v, w), as a Vec3.
get_point(u, v, w, n=0) Same, as an (x, y, z) tuple.
get_site(u, v, w, n=0) Returns (id, x, y, z) for basis site n in cell (u, v, w).
get_siteid(s) Id of basis site s.
iter_points(n1, n2, n3) Iterate over every site's (x, y, z) in an n1 x n2 x n3 block of cells.
iter_sites(n1, n2, n3) Same, yielding (id, x, y, z).

Lattice system shortcuts

Convenience subclasses of UnitCell, one for each of the seven 3D lattice systems, each fixing the relationships between edge lengths and angles:

Class Signature Fixed relations
Triclinic Triclinic(a, b, c, alpha, beta, gamma, sites=None) None; all six parameters are independent.
Monoclinic Monoclinic(a, b, c, beta, sites=None, lattice_type='P') alpha = gamma = 90° (unique axis b).
Orthorhombic Orthorhombic(a, b, c, sites=None, lattice_type='P') All angles 90°.
Tetragonal Tetragonal(a, c, sites=None, lattice_type='P') b = a, all angles 90°.
Trigonal (alias Rhombohedral) Trigonal(a, alpha, sites=None) b = c = a, beta = gamma = alpha (rhombohedral axes).
Hexagonal Hexagonal(a, c, sites=None) b = a, alpha = beta = 90°, gamma = 120°.
Cubic Cubic(a, sites=None, lattice_type='P') b = c = a, all angles 90°.

Centering

Monoclinic, Orthorhombic, Tetragonal and Cubic accept a lattice_type keyword selecting a non-primitive centering. Each site given (or the default ('X', 0, 0, 0)) is repeated at every offset for the requested centering:

Symbol Centering Offsets added Allowed on
'P' Primitive (default) none all four
'S' Base-centered, on the ab plane (1/2,1/2,0) Monoclinic, Orthorhombic
'B' Body-centered (1/2,1/2,1/2) Orthorhombic, Tetragonal, Cubic
'F' Face-centered (1/2,1/2,0), (1/2,0,1/2), (0,1/2,1/2) Orthorhombic, Cubic

Passing a lattice_type not listed as allowed for that class raises ValueError. For example:

Orthorhombic(1, 2, 3, lattice_type='F')
Cubic(1, lattice_type='B')

BCC and FCC are further subclasses of Cubic that pass lattice_type='B' and lattice_type='F' as their defaults, respectively (still overridable via the lattice_type argument). For example, the diamond structure (FCC with a two-atom basis) is:

diamond = FCC(a, sites=[('C', 0, 0, 0), ('C', 0.25, 0.25, 0.25)])

which expands to the 8 sites of the conventional diamond cubic cell.

Class Signature Fixed relations
BCC BCC(a, sites=None, lattice_type='B') Cubic; each site repeated at (0,0,0) and (1/2,1/2,1/2).
FCC FCC(a, sites=None, lattice_type='F') Cubic; each site repeated at (0,0,0) and the three face centers.

Tetragona is kept as a deprecated alias of Tetragonal for backwards compatibility.

unitcell.geometry

Thin wrapper around vec3 for 3D vector operations, re-exporting Vec3, toVec3, dist, dist2, scalar, vprod, triple, angle, getangle, xrotate, yrotate, zrotate, xmirror, ymirror, zmirror, translate, invert, rescale, plus:

  • unit_vector(v) — the unit Vec3 parallel to v.