MasterPatternSimulator#

class de_ebsd.sim.MasterPatternSimulator(crystal, microscope, npx=150, dmin=0.1, bethe=None, monte_carlo=None, backend='bloch_prism')[source]#

Bases: object

Simulate an EBSD master pattern for one crystal and beam energy.

Parameters:
crystal

The crystal structure.

microscope

Beam energy and sample geometry.

npx

Half-width of the square Lambert grid; the master pattern maps have shape (2 npx + 1, 2 npx + 1) per hemisphere.

dmin

Smallest interplanar spacing (nm) still included as a reflection. Lowering it adds beams and raises accuracy and cost.

bethe

Bethe-potential truncation thresholds.

monte_carlo

Energy/depth statistics for the depth integration (required by the the Bloch-wave backends; when omitted, a native Monte Carlo is run).

backend

"bloch_prism" (default), "bloch", or any MasterPatternBackend instance. Both named backends solve the same Bloch-wave model. "bloch" is the float64 reference, one direction at a time; "bloch_prism" batches it on the GPU and reproduces it (r = 1.0000 against the EMsoft master of Si at npx = 500), so it is the default.

Methods

compute

Compute the master pattern on the Lambert grid.

dynamical_matrix

The Bloch dynamical matrix (with Bethe corrections) for one beam.

refine

A new simulator with updated parameters, reusing valid caches.

reflections

The reflection list; with k, classified strong/weak for that beam.

show_setup

Interactive geometry widget for this simulation's setup.

structure_factors

U_g with absorption for all reflections down to dmin (cached).

Attributes

energy_kev

compute(device=None, dtype=torch.float32, chunk_size=262144, mc_electrons=200000, symmetry=True, energy_resolved=False, progress=None)[source]#

Compute the master pattern on the Lambert grid.

Parameters:
device

Torch device (e.g. "cuda"); default: torch’s current default.

dtype

Floating point type for the direction batch (FP32 recommended).

chunk_size

Number of beam directions per batch, bounding peak memory.

mc_electrons

Electron count for the native Monte Carlo depth profile built when the backend needs one and no monte_carlo was supplied. Ignored if a depth profile is provided or the backend does not use one.

symmetry

Fold the beam directions onto the point-group fundamental sector so each symmetry-distinct direction is computed once (exact; ~15x fewer evaluations for cubic). Disable to evaluate every grid point.

energy_resolved

Compute one Lambert map per Monte Carlo energy bin (structure factors and depth profile per energy), giving an (nE, 2, n, n) master. Requires a depth-integrating backend; ignored otherwise. Default is a single map at the beam energy.

progress

Called as progress(done, total) after each batch of beam directions, counting batches over all energies, so a caller can show how far a long simulation has got. At the default chunk_size a master of any usual size is one batch per energy, so a single-energy compute reports only its end. The Monte Carlo, the symmetry fold and the first energy all run before the first call. It is called on the calling thread, inside the loop, so it should be quick and never block; an exception raised in it stops the simulation.

dynamical_matrix(k)[source]#

The Bloch dynamical matrix (with Bethe corrections) for one beam.

refine(**changes)[source]#

A new simulator with updated parameters, reusing valid caches.

Accepted keys: npx, dmin, bethe, backend, monte_carlo, microscope, crystal. Example:

better = sim.refine(npx=300, dmin=0.05)

Structure factors are carried over when the crystal, energy, and dmin are unchanged (raising npx or adjusting Bethe thresholds is free).

reflections(k=None)[source]#

The reflection list; with k, classified strong/weak for that beam.

k is a beam direction in the Cartesian crystal frame (any length; it is normalized). For cubic crystals Cartesian components coincide with lattice directions.

show_setup(detector=None)[source]#

Interactive geometry widget for this simulation’s setup.

structure_factors()[source]#

U_g with absorption for all reflections down to dmin (cached).