Quickstart¶
Defining a unit cell¶
A UnitCell is built from the standard
crystallographic cell parameters — edge lengths a, b, c and angles
alpha, beta, gamma — plus an optional list of basis sites:
from unitcell import UnitCell
# A simple cubic cell with one site at the origin
cell = UnitCell(a=1.0, b=1.0, c=1.0, alpha=90, beta=90, gamma=90)
# A cell with more than one site in the basis, each tagged with an id
cell = UnitCell(
a=1.0, b=1.0, c=1.0, alpha=90, beta=90, gamma=90,
sites=[("A", 0.0, 0.0, 0.0), ("B", 0.5, 0.5, 0.5)],
)
Getting site coordinates¶
get_point(u, v, w, n) returns the real-space (x, y, z) coordinates of
lattice site n in unit cell (u, v, w):
x, y, z = cell.get_point(0, 0, 0, n=0)
get_site(u, v, w, n) also returns the site id:
site_id, x, y, z = cell.get_site(0, 0, 0, n=0)
Iterating over a lattice¶
iter_points/iter_sites walk every site in an n1 x n2 x n3 block of unit
cells:
for x, y, z in cell.iter_points(4, 4, 4):
...
for site_id, x, y, z in cell.iter_sites(4, 4, 4):
...
Rotating and re-parameterizing a cell¶
The underlying PrimitiveCell tracks
rotations so that they survive later changes to the cell parameters:
cell.zrotate(45) # rotate 45 degrees around z
cell.a = 2.0 # basis vectors are rebuilt, the rotation is replayed
Crystallographic directions and planes¶
normal = cell.get_normal(1, 1, 1) # unit vector normal to the (111) plane
spacing = cell.get_planedist(1, 1, 1) # spacing between (111) planes
The seven lattice systems¶
unitcell ships shortcuts for all seven 3D lattice systems, all subclasses
of UnitCell and importable directly from the top-level package: Triclinic,
Monoclinic, Orthorhombic, Tetragonal, Trigonal (alias Rhombohedral),
Hexagonal, and Cubic.
from unitcell import Cubic
cell = Cubic(a=1.0)
Centering¶
Monoclinic, Orthorhombic, Tetragonal and Cubic accept a
lattice_type argument for non-primitive centerings: 'S' (base-centered,
on the ab plane), 'B' (body-centered) or 'F' (face-centered), each
only valid on the systems it applies to (e.g. 'F' is not valid on
Tetragonal). Any sites passed in are repeated at each centering offset,
so a multi-atom basis is replicated at every lattice point:
from unitcell import Orthorhombic, Cubic
base_centered = Orthorhombic(a=1.0, b=2.0, c=3.0, lattice_type='S')
body_centered = Cubic(a=1.0, lattice_type='B')
BCC and FCC are Cubic subclasses that pass lattice_type='B' and
lattice_type='F' as their defaults, respectively:
from unitcell import FCC
# Diamond: FCC with a two-atom basis, expands to 8 sites per cell
diamond = FCC(a=3.57, sites=[('C', 0, 0, 0), ('C', 0.25, 0.25, 0.25)])
See the API Reference for the full set of classes and methods.