Skip to content

API reference

Brillouin-zone paths

SymmetryPoint

Model of a symmetry point at the brillouinzone.

Parameters:

  • point (Tuple[float, ...]) –

    A point in the reciprocal domain.

  • name (str) –

    A label to describe the point.

__init__(point, name)

Initialize a SymmetryPoint.

BlochVectors dataclass

Cartesian Bloch vectors and optional distances along a symmetry path.

values has shape (dimension, n_samples). cumsum contains path distances for ordered paths and is None for unordered Bloch samples.

BrillouinZonePath(a1, *args, **kwargs)

BrillouinZonePath factory.

BrillouinZonePath1D

Bases: BrillouinZonePathBase

BrillouinZonePath1D.

Parameters:

  • a1 (Tuple[float]) –

    Direct lattice vector a1.

  • path (List[SymmetryPoint]) –

    List of symmetry points.

  • n_points (int, default: 50 ) –

    Total number of vectors sampled along the full path. Used when points_per_segment is not set.

  • strategy (str = 'linear', default: 'linear' ) –

    Strategy to interpolate.

  • points_per_segment (int, default: None ) –

    Number of intervals on each segment. Every symmetry point is sampled; the total is one plus this value times the number of segments. This takes precedence over n_points.

betas property

Return beta vector values and cumsum.

b1 property

Return reciprocal lattice vector b1.

__init__(a1, path, n_points=50, strategy='linear', points_per_segment=None)

Initialize a BrillouinZonePath.

BrillouinZonePath2D

Bases: BrillouinZonePathBase

BrillouinZonePath2D.

Parameters:

  • a1 (Tuple[float, float]) –

    Direct lattice vector a1.

  • a2 (Tuple[float, float]) –

    Direct lattice vector a2.

  • path (List[SymmetryPoint]) –

    List of symmetry points.

  • n_points (int, default: 50 ) –

    Total number of vectors sampled along the full path. Used when points_per_segment is not set.

  • strategy (str = 'linear', default: 'linear' ) –

    Strategy to interpolate.

  • points_per_segment (int, default: None ) –

    Number of intervals on each segment. Every symmetry point is sampled; the total is one plus this value times the number of segments. This takes precedence over n_points.

betas property

Return beta vector values and cumsum.

b1 property

Return reciprocal lattice vector b1.

b2 property

Return reciprocal lattice vector b2.

__init__(a1, a2, path, n_points=50, strategy='linear', points_per_segment=None)

Initialize a BrillouinZonePath.

BrillouinZonePath3D

Bases: BrillouinZonePathBase

BrillouinZonePath3D.

Parameters:

  • a1 (Tuple[float, float, float]) –

    Direct lattice vector a1.

  • a2 (Tuple[float, float, float]) –

    Direct lattice vector a2.

  • a3 (Tuple[float, float, float]) –

    Direct lattice vector a3.

  • path (List[SymmetryPoint]) –

    List of symmetry points.

  • n_points (int, default: 50 ) –

    Total number of vectors sampled along the full path. Used when points_per_segment is not set.

  • strategy (str = 'linear', default: 'interpolate' ) –

    Strategy to interpolate.

  • points_per_segment (int, default: None ) –

    Number of intervals on each segment. Every symmetry point is sampled; the total is one plus this value times the number of segments. This takes precedence over n_points.

betas property

Return beta vector values and cumsum.

b1 property

Return reciprocal lattice vector b1.

b2 property

Return reciprocal lattice vector b2.

b3 property

Return reciprocal lattice vector b3.

__init__(a1, a2, a3, path, n_points=50, strategy='interpolate', points_per_segment=None)

Initialize a BrillouinZonePath.

Bulk Bloch samples

BlochPoints

Unordered Bloch-vector samples in a one-, two-, or three-dimensional cell.

Parameters:

  • *lattice_vectors (tuple of float, default: () ) –

    Direct lattice vectors, one per spatial dimension.

  • points ((array - like, shape(n_samples, dimension))) –

    Sampling coordinates. A flat sequence is also accepted in 1D.

  • fractional (bool, default: True ) –

    Express points in reciprocal-lattice coordinates. When false, use Cartesian wave vectors in inverse length units, including 2 pi.

betas property

Return Cartesian samples; unordered points have no path distance.

brillouin_zone_mesh(*lattice_vectors, shape)

Sample one primitive reciprocal cell on a uniform, Gamma-centered mesh.

Parameters:

  • *lattice_vectors (tuple of float, default: () ) –

    Direct lattice vectors.

  • shape (int or tuple of int) –

    Samples per reciprocal direction. One integer applies to every axis.

Returns:

  • BlochPoints –

    Uniformly weighted points covering one reciprocal primitive cell, without duplicated periodic endpoints. grid_shape records the grid dimensions. Samples flatten in C order and always include Gamma. For oblique lattices this cell is not the Wigner-Seitz polyhedron; its points cover the Brillouin zone modulo reciprocal translations.

Pass a BlochPoints batch or reciprocal-cell mesh to Solver in place of a symmetry path. find_band_gaps then uses every supplied sample, and stored modes support field reconstruction. See Brillouin-zone sampling for coordinates, mesh layout, gap convergence, and density-of-states estimates.

Solutions

Solution dataclass

Calculated bands and modes together with their sampling path.

Parameters:

  • path (BrillouinZonePathBase or BlochPoints) –

    Independent snapshot of the path or unordered samples used by the solver.

  • wn ((ndarray, shape(n_k, n_bands))) –

    Unscaled eigen-wavenumbers omega / c, ordered low to high. Lossy materials give complex frequencies, sorted by real part and then imaginary part. With exp(-i omega t), passive loss has Im(wn) < 0.

  • modes (list of numpy.ndarray) –

    Eigenvectors at each sampled wave vector, with one mode per column. Empty when run(store_modes=False) is used.

  • pol (str, default: None ) –

    Polarization label for 1D and 2D solutions. Vectorial 3D solutions have no polarization label.

  • harmonics (tuple of int, default: None ) –

    Retained harmonic counts in each lattice direction.

  • geometry (GeometryBase, default: None ) –

    Material snapshot used for field reconstruction, present when modes were stored. Contains sampled arrays, with no callbacks attached.

wave_vectors property

Return the sampled Cartesian wave vectors, shape (dim, n_k).

path_distance property

Return cumulative wave-vector distance at each sampled path point.

Every solver's run() method returns a Solution containing its path, eigen-wavenumbers, modes, and polarization. Reusing a solver starts a fresh calculation; previously returned results keep their calculated data. solution.path_distance returns the cumulative wave-vector distance at each sample. solution.wave_vectors contains the Cartesian sampling coordinates with shape (dimension, number_of_samples). Both arrays are read-only snapshots. The result owns a copy of the input sampling, including its lattice and any path labels and symmetry points. Later edits to the input do not change existing results or their plots. Consequently, solution.path is path is false. For unordered samples, use solution.wave_vectors; path_distance and plot_bands require an ordered symmetry path.

With modes retained, solution.harmonics stores the expansion counts and solution.geometry stores independent, read-only material arrays without callbacks. Frequency-only runs omit the material snapshot.

Electromagnetic fields

Fields dataclass

Complex fields on the material grid, with vector components last.

E and H have shape (*grid_shape, 3). H is the impedance-scaled magnetic field Z0 H. Eigenmode amplitudes and overall phase are arbitrary; squared magnitudes are not power or energy densities. coordinates contains the Cartesian positions of the samples.

electric_intensity property

Return sum(abs(E)**2) over vector components.

magnetic_intensity property

Return sum(abs(Z0 H)**2) over vector components.

reconstruct_fields(solution, *, sample=0, band=0)

Reconstruct one mode's E and impedance-scaled H on its material grid.

Parameters:

  • solution (Solution) –

    Solver result computed with store_modes=True.

  • sample (int, default: 0 ) –

    Zero-based Bloch-vector sample index.

  • band (int, default: 0 ) –

    Zero-based retained band index.

Returns:

  • Fields –

    Complex Cartesian fields, including the Bloch phase exp(-i beta.r) and using time dependence exp(-i omega t). The periodic Fourier basis is exp(+i G.(r-r_origin)), with r_origin the grid corner. At zero frequency the primary field is reconstructed and its undetermined companion field is set to zero.

plot_field(fields, *, field='E', component='intensity', part='real', ax=None, slice_axis=2, slice_index=None, **kwargs)

Plot a field profile, a 2D map, or a planar slice through a 3D cell.

Parameters:

  • fields (Fields) –

    Output of reconstruct_fields.

  • field ((E, H), default: "E" ) –

    Electric field or impedance-scaled magnetic field.

  • component ((intensity, x, y, z), default: "intensity" ) –

    Squared vector magnitude, or a Cartesian component.

  • part ((real, imag, abs), default: "real" ) –

    Component representation; ignored for intensity maps.

  • ax (Axes, default: None ) –

    Axes to draw on; create axes when omitted.

  • slice_axis (int, default: 2 ) –

    Lattice-grid direction held fixed for a 3D slice.

  • slice_index (int, default: None ) –

    Slice sample index; default to the middle grid sample.

  • **kwargs –

    Styling passed to plot in 1D or pcolormesh in 2D and 3D.

Returns:

  • Axes –

    Axes containing the field profile or map. Maps include a colorbar.

See the field reconstruction guide for spatial conventions, normalization, static modes, and 3D slices.

Plotting

plot_brillouin_zone(path, ax=None, *, inset=False, inset_bounds=(0.65, 0.06, 0.32, 0.32), **kwargs)

Plot the first Brillouin zone and symmetry path in 2D or 3D.

Parameters:

  • path (BrillouinZonePath2D, BrillouinZonePath3D, or BlochPoints) –

    Sampling whose reciprocal lattice vectors define the zone. Unordered Bloch points are shown as a scatter plot without connecting lines.

  • ax (Axes or Axes3D, default: None ) –

    Axes to draw on, or the parent band axes when inset=True. Create suitable axes when omitted.

  • inset (bool, default: False ) –

    Place the zone inside ax with a transparent background. Requires parent axes; 3D paths create a 3D inset inside the 2D band plot.

  • inset_bounds (tuple of float, default: (0.65, 0.06, 0.32, 0.32) ) –

    Inset left, bottom, width, and height as fractions of the parent axes. Used only when inset=True. Rotate returned 3D axes with view_init.

  • **kwargs –

    Polygon style options passed to Matplotlib.

Returns:

  • Axes or Axes3D –

    Axes containing the Brillouin zone, or the newly created inset axes.

plot_bands(solution, n_bands=None, ax=None, *, lattice_constant=None, component='real', **kwargs)

Plot solved bands and any gaps that remain open along the path.

Parameters:

  • solution (Solution or sequence of Solution) –

    Results returned by Solver.run(). Multiple solutions must use the same path; only gaps shared by all supplied solutions are shaded. Unordered Bloch samples have no path distance and cannot be drawn as band paths; use find_band_gaps to analyze their spectra.

  • n_bands (int, default: None ) –

    Number of lowest bands to plot. Plot all bands when omitted.

  • ax (Axes, default: None ) –

    Axes to draw on. Create axes when omitted.

  • lattice_constant (float, default: None ) –

    Reference length a for normalized frequency omega a / (2 pi c). Default to the length of the first direct lattice vector. Supply the conventional period when it differs, such as for an fcc primitive cell.

  • component ((real, imag), default: "real" ) –

    Frequency component to draw. Lossy results have no gap shading.

  • **kwargs –

    Line style options passed to Matplotlib.

Returns:

  • Axes –

    Axes containing the band plot. Use ax.figure to access its figure.

Pass the returned result directly to plot_bands. It retrieves the path from the solution, scales frequencies by |a1|/(2π), and shades gaps common to all supplied solutions along the sampled path. Use lattice_constant=a when the conventional reference period differs from |a1|. Both plotting functions return the Matplotlib axes. Keep both functions separate and pass the same parent axes to put the Brillouin zone inside the band plot:

import matplotlib.pyplot as plt

from morpho import plot_bands, plot_brillouin_zone

solution = solver.run()
_, band_axis = plt.subplots(figsize=(7, 5), tight_layout=True)
plot_bands(solution, ax=band_axis)
zone_axis = plot_brillouin_zone(
    solution.path, ax=band_axis, inset=True, inset_bounds=(0.32, 0.12, 0.30, 0.25)
)

The zone inset has a transparent background, so underlying bands remain visible. Its axes are returned separately for further styling. Omitting inset=True draws a standalone Brillouin zone in the supplied axes. Use inset_bounds=(left, bottom, width, height) to place it in clear space. For 3D zones, rotate the returned axes with zone_axis.view_init(elev=25, azim=-105).

Pass multiple polarizations together with plot_bands((tm_solution, te_solution), ax=band_axis) to shade their shared gaps.

Band gaps

BandGap dataclass

A gap in normalized frequency omega a / (2 pi c).

Parameters:

  • lower (float) –

    Maximum frequency of the lower band over the supplied Bloch samples.

  • upper (float) –

    Minimum frequency of the upper band over the supplied Bloch samples.

gap_to_midgap_ratio property

Return fractional gap width; multiply by 100 for a percentage.

find_band_gaps(solution, n_bands=None, *, lattice_constant=None)

Return real-frequency gaps shared by all supplied solutions.

Parameters:

  • solution (Solution or sequence of Solution) –

    One result, or multiple polarizations using the same path or Bloch points.

  • n_bands (int, default: None ) –

    Use the lowest requested number of bands; default to all stored bands.

  • lattice_constant (float, default: None ) –

    Reference length for omega a / (2 pi c); default to |a1|.

Returns:

  • list of BandGap –

    Gaps between adjacent retained bands, ordered low to high. Each gap has normalized lower and upper edges and a fractional gap_to_midgap_ratio. Results apply only to the supplied samples; meshes give finite-grid estimates, not a proof of a complete gap. Lossy spectra are rejected.

Use the same gap calculation without opening a figure:

from morpho import find_band_gaps

for gap in find_band_gaps((tm_solution, te_solution), n_bands=4):
    print(gap.lower, gap.upper, 100 * gap.gap_to_midgap_ratio)

Edges use omega a / (2 pi c), with a = |a1| unless lattice_constant=a is supplied. Ratios are fractions: 0.314 means 31.4%. Multiple solutions return only their shared gaps. n_bands limits the bands analyzed, so gaps above that limit are not reported. Touching edges and gaps within numerical tolerance are excluded. Results apply only to the sampled path, not the whole Brillouin zone. Complex-frequency spectra are rejected; use the real and imaginary frequency plots to inspect lossy results instead.

Geometry

Geometry(*args, **kwargs)

Geometry factory.

Parameters:

  • args –

    args

  • kwargs –

    kwargs

Returns:

GeometryBase

Bases: ABC

Base Geometry class.

Material callbacks start from a fresh background of one on every access. Without a callback, material arrays can be edited directly and persist.

overwrite(func)

Overwrite decorator.

Parameters:

  • func (Callable) –

    func

Geometry1D

Bases: GeometryBase

Geometry class.

Parameters:

  • a1 (Tuple[float, ...]) –

    Direct a1 vector.

  • n1 (int, default: 64 ) –

    Number of divisions in the a1 vector direction.

  • eps_rf (Optional[Callable], default: None ) –

    Permittivity matrix eps_r if directly supplied.

  • mu_rf (Optional[Callable], default: None ) –

    Permeabillity matrix mu_r if directly supplied.

X property

Return cartesian positions.

eps_r property

Return the relative permittivity profile.

mu_r property

Return the relative permeability profile.

Geometry2D

Bases: GeometryBase

Geometry class.

Parameters:

  • a1 (Tuple[float, ...]) –

    Direct a1 vector.

  • a2 (Optional[Tuple[float, ...]]) –

    Direct a2 vector.

  • n1 (int, default: 64 ) –

    Number of divisions in the a1 vector direction.

  • n2 (int, default: 64 ) –

    Number of divisions in the a2 vector direction.

  • eps_rf (Optional[Callable], default: None ) –

    Permittivity matrix eps_r if directly supplied.

  • mu_rf (Optional[Callable], default: None ) –

    Permeabillity matrix mu_r if directly supplied.

X property

Return cartesian positions.

eps_r property

Return the relative permittivity matrice.

mu_r property

Return the relative permeabillity matrice.

Geometry3D

Bases: GeometryBase

Geometry class.

Parameters:

  • a1 (Tuple[float, float, float]) –

    Direct a1 vector.

  • a2 (Optional[Tuple[float, float, float]]) –

    Direct a2 vector.

  • a3 (Optional[Tuple[float, float, float]]) –

    Direct a3 vector.

  • n1 (int, default: 64 ) –

    Number of divisions in the a1 vector direction.

  • n2 (int, default: 64 ) –

    Number of divisions in the a2 vector direction.

  • n3 (int, default: 64 ) –

    Number of divisions in the a3 vector direction.

  • eps_rf (Optional[Callable], default: None ) –

    Permittivity matrix function eps_rf if directly supplied.

  • mu_rf (Optional[Callable], default: None ) –

    Permeabillity matrix function mu_rf if directly supplied.

X property

Return cartesian positions.

eps_r property

Return the relative permittivity matrice.

mu_r property

Return the relative permeabillity matrice.

Solvers

Solver(geometry, path, *args, **kwargs)

Select a solver from the dimension of a symmetry path or Bloch points.

Solver1D

Implement a 1D PWE Solver.

Parameters:

  • geometry (Geometry) –

    geometry

  • path (BrillouinZonePath or BlochPoints) –

    A symmetry path or arbitrary Bloch-vector batch.

  • P (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector b1.

__init__(geometry, path, P=1, pol='TM')

Initialize the PWE Solver.

run(*, n_bands=None, store_modes=True)

Calculate the lowest n_bands; optionally skip eigenvectors.

By default, return all bands and modes. Lossless materials use a partial eigensolve when n_bands is supplied. General complex eigenproblems compute the full spectrum before selecting bands by real frequency. With store_modes=False, do not compute or retain eigenvectors.

Solver2D

Implement a 2D PWE Solver.

Parameters:

  • geometry (Geometry) –

    geometry

  • path (BrillouinZonePath or BlochPoints) –

    A symmetry path or arbitrary Bloch-vector batch.

  • P (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector b1.

  • Q (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector b2.

__init__(geometry, path, P=1, Q=1, pol='TM')

Initialize the PWE Solver.

run(*, n_bands=None, store_modes=True)

Calculate the lowest n_bands; optionally skip eigenvectors.

By default, return all bands and modes. Lossless materials use a partial eigensolve when n_bands is supplied. General complex eigenproblems compute the full spectrum before selecting bands by real frequency. With store_modes=False, do not compute or retain eigenvectors.

Solver3D

Implement a 3D PWE Solver.

Parameters:

  • geometry (Geometry) –

    geometry

  • path (BrillouinZonePath or BlochPoints) –

    A symmetry path or arbitrary Bloch-vector batch.

  • P (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector b1.

  • Q (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector b2.

  • R (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector b3.

__init__(geometry, path, P=1, Q=1, R=1)

Initialize the PWE Solver.

run(*, n_bands=None, store_modes=True)

Calculate the lowest n_bands; optionally skip eigenvectors.

By default, return all bands and modes. Lossless materials use a partial eigensolve when n_bands is supplied. General complex eigenproblems compute the full spectrum before selecting bands by real frequency. With store_modes=False, do not compute or retain eigenvectors.

solver.run(n_bands=4, store_modes=False) computes only the four lowest bands for real, positive materials and skips eigenvector calculation and storage. solution.modes and solver.modes are empty in this mode. The defaults still calculate all physical bands and retain their modes. n_bands must be a positive integer no greater than the retained physical band count (P, P * Q, or 2 * P * Q * R). For general complex eigenproblems, band selection follows a full eigenvalue solve; frequency-only runs still skip eigenvectors. In 3D the longitudinal null modes are excluded from the returned physical band count.

Solvers reject invalid polarization labels (use exactly "TM" or "TE"), nonpositive or noninteger harmonic counts, and incompatible geometry/path lattices. Each material-grid dimension needs at least 2 * harmonics - 1 samples to represent every Fourier difference used by the convolution matrix. Paths need at least two finite points and, with global sampling, an integer n_points >= 2. Material samples must be finite.

Lossy materials

All dimensions accept frequency-independent, scalar complex eps_r and mu_r. Material samples must be finite and nonzero. Real, positive materials use a Hermitian eigensolver; complex or nonpositive materials use a general eigensolver. Solution.wn contains complex omega / c, ordered by real part and then imaginary part, with the principal square-root convention. For ordinary passive dielectrics, use positive imaginary material parts with exp(-i omega t); negative imaginary frequencies describe temporal decay at real Bloch vectors. This does not solve for complex Bloch vectors at a fixed real frequency. Frequency dispersion, anisotropic tensors, and nonlinear material models are not included. Negative material constants are treated as nondispersive inputs; physical metal models generally require frequency dispersion.

For example, set geometry.eps_r[:] = 4 + 0.2j without a material callback, then call solver.run(). Use plot_bands(solution) for real frequencies or plot_bands(solution, component="imag") for imaginary frequencies. Lossy bands are never shaded as conventional band gaps.

Fourier utilities

harmonic_indices(count)

Return count integer harmonics centered as closely as possible at 0.

For an even count, the integer range is necessarily asymmetric; this convention keeps zero and the negative Nyquist-side harmonic.

convmat(A, P=1, Q=1, R=1)

Return a permittivity/permeability convolution matrix.

Parameters:

  • A (ndarray) –

    A 3D/2D/1D permittivity or permeability matrix.

  • P (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector T1.

  • Q (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector T2.

  • R (int, default: 1 ) –

    Number of terms in the direction of the reciprocal vector T3.