PAOFLOW.gen.fermi_plotter#

fermi-plotter — interactive 3-D Fermi-surface viewer for PAOFLOW BXSF output.

Reads a Fermi-surface BXSF file written by PAOFLOW (FermiSurf_{ispin}.bxsf, produced by PAOFLOW.writers.write2bxsf.write2bxsf()) and renders the Fermi sheets as interactive iso-surfaces with Mayavi. The surfaces are extracted with marching cubes, folded into the first Brillouin zone and coloured by the Fermi velocity \(|\nabla_{\mathbf k} E|\). The Mayavi window supports rotation, zoom and pan out of the box.

This module backs the fermi-plotter console script (see [project.scripts] in pyproject.toml).

Usage examples#

Composite image (all bands crossing the Fermi window):

fermi-plotter FermiSurf_0.bxsf

A single band (by its BXSF band label):

fermi-plotter FermiSurf_0.bxsf --band 58

A subset of bands, upsampled 2x for smoother sheets, saved to PNG:

fermi-plotter FermiSurf_0.bxsf --band 57,58 --interp 2 --save fermi.png

A 2x2x2 block of reciprocal cells with a Gamma point at the centre:

fermi-plotter FermiSurf_0.bxsf --supercell 2 --center

The raw reciprocal parallelepiped instead of the true zone:

fermi-plotter FermiSurf_0.bxsf --bz cell

The SKEAF magnetic-field axis and its slice plane, using the same field selector and angles as PAOFLOW.PAOFLOW.pyskeaf():

fermi-plotter FermiSurf_0.bxsf --b-field non_principal --azimuthal 30 \
    --polar 45 --field-plane --field-label --opacity 0.6

A field rotation, drawn as start/end arrows joined by the swept arc:

fermi-plotter FermiSurf_0.bxsf --b-field rotation --azimuthal 0,90 \
    --polar 45,45 --num-angles 7

Only one spin channel is handled per run; point the tool at the desired FermiSurf_{ispin}.bxsf file directly.

Requires the fermisurface extra (pip install "PAOFLOW[fermisurface]" or pip install mayavi scikit-image).

Classes#

FermiSurfData

Parsed contents of a (possibly multi-band) PAOFLOW BXSF file.

FieldSpec

Magnetic-field geometry to overlay, in SKEAF conventions.

Functions#

read_fermi_bxsf(path)

Read a PAOFLOW Fermi-surface BXSF file (single or multi-band).

fft_upsample(grid, factor)

Fourier zero-padding upsampling of a periodic energy grid.

fermi_velocity_field(energy, recip)

Return the Fermi-velocity magnitude |grad_k E| on the grid.

reciprocal_neighbours(recip[, order])

Reciprocal-lattice vectors around the origin, excluding \(\Gamma\).

reduce_basis(basis[, iterations])

Greedily shorten a lattice basis without changing the lattice.

brillouin_zone(recip[, max_order])

Build the first Brillouin zone of an arbitrary reciprocal lattice.

bz_edges(verts, faces)

Return the unique polyhedron edges as (p0, p1) endpoint pairs.

bz_planes(verts, faces)

Outward half-space description of the Brillouin zone.

select_near_bz(cart, faces, scalars, normals, offsets)

Drop triangles that lie wholly outside the Brillouin zone.

clip_to_planes(tri, values, normals, offsets)

Clip triangles to the convex region k @ normals[i] <= offsets[i].

fold_into_bz(cart, faces, scalars, recip, normals, offsets)

Gather the periodic images of a sheet that reach into the first BZ.

central_replica(ncell)

Return the index of the replica closest to the centre of the block.

supercell_translations(recip[, ncell, center])

Cartesian offsets replicating the reciprocal cell over an ncell block.

tile_mesh(cart, faces, scalars, translations)

Replicate a triangular mesh by a set of translations.

resolve_field_angles(recip, hvd[, theta, phi])

Resolve a SKEAF hvd selector to (theta, phi) in radians.

field_direction(theta, phi)

Cartesian unit vector of the field axis for angles in radians.

field_sweep_arc(theta0, phi0, theta1, phi1, num)

Unit vectors traced by a SKEAF rotation sweep.

plane_basis(normal)

Return two orthonormal vectors spanning the plane normal to normal.

plot_fermi_surface(data, band_labels[, interp, ...])

Render the selected Fermi sheets with Mayavi.

main([argv])

Console-script entry point for fermi-plotter.

Module Contents#

class PAOFLOW.gen.fermi_plotter.FermiSurfData[source]#

Parsed contents of a (possibly multi-band) PAOFLOW BXSF file.

Variables:
  • fermi_energy (float) – Fermi energy in eV, as written in the BEGIN_INFO block.

  • dims (tuple[int, int, int]) – Grid dimensions (Nx, Ny, Nz) as stored in the file. PAOFLOW writes the periodic wrap-around grid, so Nx = nk1 + 1 etc.

  • recip (np.ndarray, shape (3, 3)) – Reciprocal-lattice (spanning) vectors as stored in the file; row i is the i-th vector (units of \(2\pi/a_{\rm lat}\)).

  • bands (dict[int, np.ndarray]) – Mapping of BXSF band label -> energy grid of shape dims (eV).

fermi_energy: float[source]#
dims: tuple[int, int, int][source]#
recip: numpy.ndarray[source]#
bands: dict[int, numpy.ndarray][source]#
PAOFLOW.gen.fermi_plotter.read_fermi_bxsf(path)[source]#

Read a PAOFLOW Fermi-surface BXSF file (single or multi-band).

Unlike PAOFLOW.pyskeaf.io_bxsf.read_bxsf (which targets single-band, non-periodic SKEAF grids), this reader accepts the multi-band, periodic-wrapped grid that write2bxsf emits.

Parameters:

path (str or Path) – Path to the .bxsf file.

Returns:

Parsed Fermi energy, grid dimensions, reciprocal vectors and per-band energy grids.

Return type:

FermiSurfData

PAOFLOW.gen.fermi_plotter.fft_upsample(grid, factor)[source]#

Fourier zero-padding upsampling of a periodic energy grid.

The PAOFLOW grid is periodic with a duplicated endpoint plane in each direction. This routine strips the wrap plane, upsamples the base (period) grid by factor via Fourier zero-padding (exact for periodic band energies), and re-appends the wrap plane so the result stays closed for marching cubes.

Parameters:
  • grid (np.ndarray, shape (Nx, Ny, Nz)) – Wrap-closed energy grid (N_i = n_i + 1).

  • factor (int) – Integer upsampling factor (>= 1). 1 returns the input.

Returns:

Upsampled, wrap-closed grid of shape (factor*n_x + 1, factor*n_y + 1, factor*n_z + 1) along axes with n_i > 1 (axes of length 1 are left unchanged).

Return type:

np.ndarray

PAOFLOW.gen.fermi_plotter.fermi_velocity_field(energy, recip)[source]#

Return the Fermi-velocity magnitude |grad_k E| on the grid.

Parameters:
  • energy (np.ndarray, shape (Nx, Ny, Nz)) – Wrap-closed energy grid (eV).

  • recip (np.ndarray, shape (3, 3)) – Reciprocal spanning vectors (rows).

Returns:

|grad_k E| at every grid node (eV per reciprocal-length unit).

Return type:

np.ndarray, shape (Nx, Ny, Nz)

PAOFLOW.gen.fermi_plotter.reciprocal_neighbours(recip, order=2)[source]#

Reciprocal-lattice vectors around the origin, excluding \(\Gamma\).

Parameters:
  • recip (np.ndarray, shape (3, 3)) – Reciprocal spanning vectors (rows).

  • order (int, optional) – Largest |n_i| in \(\mathbf G = n_1\mathbf b_1 + n_2\mathbf b_2 + n_3\mathbf b_3\) (default 2).

Returns:

Cartesian neighbour vectors.

Return type:

np.ndarray, shape ((2*order+1)**3 - 1, 3)

PAOFLOW.gen.fermi_plotter.reduce_basis(basis, iterations=50)[source]#

Greedily shorten a lattice basis without changing the lattice.

Parameters:
  • basis (np.ndarray, shape (3, 3)) – Spanning vectors (rows).

  • iterations (int, optional) – Maximum reduction sweeps (default 50).

Returns:

A near-Minkowski-reduced basis of the same lattice.

Return type:

np.ndarray, shape (3, 3)

Notes

Only integer multiples of one row are subtracted from another and rows are permuted, both unimodular operations, so the lattice — and hence its Wigner-Seitz cell — is unchanged. Reduction matters because the number of neighbour shells needed to close the Brillouin zone depends on how skewed the basis is, not on the lattice itself.

PAOFLOW.gen.fermi_plotter.brillouin_zone(recip, max_order=4)[source]#

Build the first Brillouin zone of an arbitrary reciprocal lattice.

Parameters:
  • recip (np.ndarray, shape (3, 3)) – Reciprocal spanning vectors (rows).

  • max_order (int, optional) – Largest neighbour shell tried before giving up (default 4).

Returns:

  • vertices (np.ndarray, shape (nv, 3)) – BZ corners, centred on \(\Gamma\).

  • faces (list[np.ndarray]) – One array of vertex indices per facet, ordered cyclically.

Raises:

RuntimeError – If no neighbour shell up to max_order reproduces the primitive cell volume.

Notes

The first BZ is the Wigner-Seitz cell of the reciprocal lattice: the set of k closer to \(\Gamma\) than to any other reciprocal-lattice point. It is obtained here as the Voronoi region of the origin, which makes the construction purely geometric and therefore identical for every Bravais lattice — no per-crystal-system tabulation is involved.

The basis is reduced first (see reduce_basis()) and the neighbour shell is then grown until the polyhedron volume matches \(|\det(\mathbf b)|\). Because the Wigner-Seitz cell tiles space, that equality is a sufficient check that no bounding plane was missed.

PAOFLOW.gen.fermi_plotter.bz_edges(verts, faces)[source]#

Return the unique polyhedron edges as (p0, p1) endpoint pairs.

PAOFLOW.gen.fermi_plotter.bz_planes(verts, faces)[source]#

Outward half-space description of the Brillouin zone.

Parameters:
Returns:

  • normals (np.ndarray, shape (nf, 3)) – Outward unit normals.

  • offsets (np.ndarray, shape (nf,)) – Plane distances from \(\Gamma\), so the zone interior is k @ normals[i] <= offsets[i] for every facet.

PAOFLOW.gen.fermi_plotter.select_near_bz(cart, faces, scalars, normals, offsets, tol=1e-09)[source]#

Drop triangles that lie wholly outside the Brillouin zone.

Parameters:
  • cart (np.ndarray, shape (nv, 3)) – Vertex positions.

  • faces (np.ndarray, shape (nf, 3)) – Triangle vertex indices.

  • scalars (np.ndarray, shape (nv,)) – Per-vertex scalars.

  • normals (np.ndarray) – Half-space description from bz_planes().

  • offsets (np.ndarray) – Half-space description from bz_planes().

  • tol (float, optional) – Slack on the outside test, in reciprocal-length units.

Returns:

(vertices, faces, scalars) keeping only triangles that touch the zone. Vertices are unshared (three per surviving triangle).

Return type:

tuple of np.ndarray

Notes

This is the trivial-reject half of the clip: a triangle whose three corners all violate the same facet plane cannot intersect the zone. Triangles straddling a face are kept whole here and cut exactly later by the renderer, so no geometry is lost.

PAOFLOW.gen.fermi_plotter.clip_to_planes(tri, values, normals, offsets)[source]#

Clip triangles to the convex region k @ normals[i] <= offsets[i].

Parameters:
  • tri (np.ndarray, shape (nf, 3, 3)) – Triangle corner positions.

  • values (np.ndarray, shape (nf, 3)) – Per-corner scalars, interpolated linearly onto any new corner.

  • normals (np.ndarray, shape (np, 3)) – Outward unit normals of the bounding half-spaces.

  • offsets (np.ndarray, shape (np,)) – Plane distances from the origin.

Returns:

Clipped (tri, values). Triangles crossing a plane are cut and re-triangulated, so the trimmed surface follows the boundary exactly instead of overhanging it.

Return type:

tuple of np.ndarray

PAOFLOW.gen.fermi_plotter.fold_into_bz(cart, faces, scalars, recip, normals, offsets)[source]#

Gather the periodic images of a sheet that reach into the first BZ.

Parameters:
  • cart (np.ndarray, shape (nv, 3)) – Vertex positions, spanning the reciprocal parallelepiped.

  • faces (np.ndarray, shape (nf, 3)) – Triangle vertex indices.

  • scalars (np.ndarray, shape (nv,)) – Per-vertex scalars.

  • recip (np.ndarray, shape (3, 3)) – Reciprocal spanning vectors (rows).

  • normals (np.ndarray) – Half-space description from bz_planes().

  • offsets (np.ndarray) – Half-space description from bz_planes().

Returns:

(vertices, faces, scalars) of the sheet trimmed to the zone. Vertices are unshared (three per triangle).

Return type:

tuple of np.ndarray

Notes

The iso-surface is periodic, so every part of the zone is covered by some lattice translation of the parallelepiped. All 27 translations of the reduced basis are laid down, trivially rejected against the zone, and then clipped exactly. Because the Wigner-Seitz cell and the primitive cell have equal volume, the result holds about one cell’s worth of triangles.

PAOFLOW.gen.fermi_plotter.central_replica(ncell)[source]#

Return the index of the replica closest to the centre of the block.

PAOFLOW.gen.fermi_plotter.supercell_translations(recip, ncell=(1, 1, 1), center=False)[source]#

Cartesian offsets replicating the reciprocal cell over an ncell block.

Parameters:
  • recip (np.ndarray, shape (3, 3)) – Reciprocal spanning vectors (rows).

  • ncell (tuple[int, int, int], optional) – Number of repetitions along each reciprocal vector (default no replication). Replicas grow in the +b_i directions, so element 0 is always the original cell.

  • center (bool, optional) – Shift the block so the origin of the central replica sits at the Cartesian origin.

Returns:

Translation \(i\mathbf b_0 + j\mathbf b_1 + k\mathbf b_2\) for each replica, in C order over (i, j, k).

Return type:

np.ndarray, shape (nx*ny*nz, 3)

Notes

The centring shift is an integer combination of reciprocal vectors, so the Cartesian origin always lands on a \(\Gamma\) point and no vertex needs to be wrapped (wrapping fractional coordinates into \([-1/2, 1/2)\) would tear every triangle crossing a cell face). A single cell has no interior replica, so center is then a no-op.

PAOFLOW.gen.fermi_plotter.tile_mesh(cart, faces, scalars, translations)[source]#

Replicate a triangular mesh by a set of translations.

Parameters:
  • cart (np.ndarray, shape (nv, 3)) – Vertex positions.

  • faces (np.ndarray, shape (nf, 3)) – Triangle vertex indices.

  • scalars (np.ndarray, shape (nv,)) – Per-vertex scalars (the Fermi speed used for colouring).

  • translations (np.ndarray, shape (nc, 3)) – Offsets from supercell_translations().

Returns:

Concatenated (vertices, faces, scalars) for all replicas, so the whole block can be drawn as a single Mayavi actor.

Return type:

tuple of np.ndarray

Notes

The BXSF grid carries the periodic wrap plane, so the iso-surface is continuous across cell faces and plain translation tiles it seamlessly — no second marching-cubes pass is needed.

class PAOFLOW.gen.fermi_plotter.FieldSpec[source]#

Magnetic-field geometry to overlay, in SKEAF conventions.

Variables:
  • hvd (str) – SKEAF field selector: 'a', 'b', 'c' align with reciprocal vector 0, 1, 2; 'n' uses theta/phi; 'r' sweeps from (theta, phi) to (theta_end, phi_end).

  • phi (theta,) – Azimuth and polar angle in radians (theta is PAOFLOW’s azimuthal, phi its polar).

  • phi_end (theta_end,) – Sweep endpoint in radians; used only for hvd='r'.

  • num_angles (int) – Number of orientations in the sweep.

  • show_plane (bool) – Draw a translucent plane normal to the field, i.e. the plane SKEAF slices the Fermi surface with.

  • show_label (bool) – Annotate the arrow with its angles.

hvd: str = 'n'[source]#
theta: float = 0.0[source]#
phi: float = 0.0[source]#
theta_end: float = 0.0[source]#
phi_end: float = 0.0[source]#
num_angles: int = 1[source]#
show_plane: bool = False[source]#
show_label: bool = False[source]#
PAOFLOW.gen.fermi_plotter.resolve_field_angles(recip, hvd, theta=0.0, phi=0.0)[source]#

Resolve a SKEAF hvd selector to (theta, phi) in radians.

Delegates to PAOFLOW.pyskeaf.geometry.set_field_angle() so the arrow can never drift from the geometry SKEAF actually uses. Only the direction of recip matters, so its scaling (BXSF stores \(2\pi/a\) units, pyskeaf documents |AA|-1) is irrelevant.

PAOFLOW.gen.fermi_plotter.field_direction(theta, phi)[source]#

Cartesian unit vector of the field axis for angles in radians.

Notes

Inverts the SKEAF convention theta = atan2(v_y, v_x), phi = arccos(v_z / |v|):

\[\hat{\mathbf H} = (\sin\phi\cos\theta,\; \sin\phi\sin\theta,\; \cos\phi)\]
PAOFLOW.gen.fermi_plotter.field_sweep_arc(theta0, phi0, theta1, phi1, num)[source]#

Unit vectors traced by a SKEAF rotation sweep.

Parameters:
  • theta0 (float) – Sweep endpoints in radians.

  • phi0 (float) – Sweep endpoints in radians.

  • theta1 (float) – Sweep endpoints in radians.

  • phi1 (float) – Sweep endpoints in radians.

  • num (int) – Number of orientations (clamped to at least 2).

Returns:

Field directions at each step of the sweep.

Return type:

np.ndarray, shape (num, 3)

Notes

theta and phi are stepped independently and linearly, matching PAOFLOW.pyskeaf.runner.run_angle_sweep(); the path is therefore not a great circle unless the endpoints happen to lie on one.

PAOFLOW.gen.fermi_plotter.plane_basis(normal)[source]#

Return two orthonormal vectors spanning the plane normal to normal.

PAOFLOW.gen.fermi_plotter.plot_fermi_surface(data, band_labels, interp=1, fermi_shift=0.0, cmap='jet', opacity=1.0, bz='ws', supercell=(1, 1, 1), center=False, field=None, figsize=(900, 700), save=None)[source]#

Render the selected Fermi sheets with Mayavi.

Parameters:
  • data (FermiSurfData) – Parsed BXSF contents.

  • band_labels (list[int]) – BXSF band labels to render. A single element gives a one-band image; multiple elements give the composite image.

  • interp (int, optional) – Integer Fourier upsampling factor for smoother sheets (default 1).

  • fermi_shift (float, optional) – Energy offset (eV) added to the Fermi level defining the iso-surface.

  • cmap (str, optional) – Mayavi/VTK colormap name for the velocity colouring.

  • opacity (float, optional) – Surface opacity in [0, 1].

  • bz ({'ws', 'cell', 'none'}, optional) – Zone drawn and used to place the sheets. 'ws' (default) folds the sheets into the true first Brillouin zone and outlines that polyhedron; 'cell' keeps the raw reciprocal parallelepiped; 'none' draws no outline (sheets stay in the parallelepiped).

  • supercell (tuple[int, int, int], optional) – Number of cell repetitions along each reciprocal vector (default (1, 1, 1)). The sheets are replicated by translation.

  • center (bool, optional) – Put the central replica’s origin (a \(\Gamma\) point) at the Cartesian origin. No-op for a single cell, and redundant with bz='ws', whose zone is centred on \(\Gamma\) already.

  • field (FieldSpec, optional) – SKEAF magnetic-field geometry to overlay. None draws nothing.

  • figsize (tuple[int, int], optional) – Render window size in pixels.

  • save (str, optional) – If given, render and save a PNG to this path instead of opening an interactive window. (VTK on macOS has no OSMesa off-screen backend, so this still renders through a normal on-screen window.)

PAOFLOW.gen.fermi_plotter.main(argv=None)[source]#

Console-script entry point for fermi-plotter.