abtem.multislice#

Module for running the multislice algorithm.

Module Contents#

Classes#

FourierMultislice

Multislice algorithm computed fast in Fourier space.

FresnelPropagator

The Fresnel propagator is used for propagating wave functions using the near-field approximation (Fresnel diffraction).

MultisliceTransform

Transformation applying the multislice algorithm to wave functions, producing new wave functions or measurements.

RealSpaceMultislice

Multislice algorithm computed in real-space.

Functions#

allocate_measurement

Allocate a measurement matching the given wave functions and detector.

allocate_multislice_measurements

Allocate the multislice measurements that would be produced by detecting the given set of wave functions with the given set of detectors.

conventional_multislice_step

Calculate one step of the multislice algorithm for the given batch of wave functions through a given potential slice.

is_waves_base_measurements_or_list

lookahead

Generator that yields (current, next) items from an iterable. The last item is yielded as (last, None).

multislice_and_detect

Calculate the full multislice algorithm for the given batch of wave functions through a given potential, detecting at each of the exit planes specified in the potential.

transition_potential_multislice_and_detect

Calculate the full multislice algorithm for the given batch of wave functions through a given potential, detecting at each of the exit planes specified in the potential.

API#

class abtem.multislice.FourierMultislice[source]#

Multislice algorithm computed fast in Fourier space.

Parameters:
  • order (int, optional) – Propagator order, one of 1, 2, or ‘exact’ (default ‘exact’)

  • expansion_scope (str) – Specified for compatibility. Must be “propagator” (default “propagator”)

  • conjugate (bool, optional) – If True, use the conjugate of the transmission function (default is False)

  • transpose (bool, optional) – If True, reverse the order of propagation and transmission (default is False)

conjugate: bool#

False

expansion_scope: Literal[propagator]#

‘propagator’

order: Literal[1, 2, exact]#

‘exact’

transpose: bool#

False

class abtem.multislice.FresnelPropagator[source]#

The Fresnel propagator is used for propagating wave functions using the near-field approximation (Fresnel diffraction).

Initialization

get_array(...) ndarray[source]#

Get the Fresnel propagator as an array for the given wave functions and thickness.

Parameters:
  • waves (Waves) – The wave functions to propagate.

  • thickness (float) – Distance in free space to propagate [Å].

Returns:

array – The Fresnel propagator as an array.

Return type:

ndarray

propagate(...) Waves[source]#

Propagate wave functions through free space.

Parameters:
  • waves (Waves) – The wave functions to propagate.

  • thickness (float) – Distance in free space to propagate.

  • in_place (bool) – If True, the waves are overwritten.

Returns:

propagated_wave_functions – Propagated wave functions.

Return type:

Waves

class abtem.multislice.MultisliceTransform(...)[source]#

Bases: abtem.transform.WavesTransform[abtem.measurements.BaseMeasurements]

Transformation applying the multislice algorithm to wave functions, producing new wave functions or measurements.

Parameters:
  • potential (BasePotential) – A potential as BasePotential object.

  • detectors ((list of) BaseDetector, optional) – A detector or a list of detectors defining how the wave functions should be converted to measurements after running the multislice algorithm.

  • multislice_func (callable, optional) – The multislice function defining the multislice algorithm used (default is multislice_and_detect()).

  • **multislice_func_kwargs – Additional keyword arguments passed to the multislice function.

Initialization

apply(...) Waves | BaseMeasurements | list[Waves | BaseMeasurements][source]#

Run the multislice algorithm on the given wave functions. An output is returned for each detector.

Parameters:
  • waves (Waves) – The wave functions to run the multislice algorithm on.

  • max_batch (int or str, optional) – The maximum batch size to use for the multislice algorithm. If ‘auto’ the batch size is chosen automatically based on the available memory.

Returns:

waves – The wave functions after running the multislice algorithm.

Return type:

tuple of Waves and BaseMeasurements

property detectors: list[BaseDetector]#

List of detectors defining how the wave functions should be converted to measurements.

property ensemble_axes_metadata#
property ensemble_shape#
property multislice_func: Callable#

The multislice function defining the multislice algorithm used.

property potential: BasePotential#

Electrostatic potential for each multislice slice.

class abtem.multislice.RealSpaceMultislice[source]#

Multislice algorithm computed in real-space.

Parameters:
  • order (int, optional) – Propagator and/or transmission operator order (default 1)

  • expansion_scope (str) – If “propagator” (default) only the propagator operator is expanded to order If “full” both the propagator and transmission operators are expanded to order

  • derivative_accuracy (int, optional) – Finite-difference accuracy for Laplace operator (default 6)

  • max_terms (int, optional) – Max terms in exponent Taylor series expansion (default 80)

derivative_accuracy: int#

6

expansion_scope: Literal[propagator, full]#

‘propagator’

max_terms: int#

80

order: int#

1

abtem.multislice.allocate_measurement(...) BaseMeasurements | Waves[source]#

Allocate a measurement matching the given wave functions and detector.

Parameters:
  • waves (BaseWaves) – The wave functions to derive the allocated measurement from.

  • detector (BaseDetector) – The detector to derive the allocated measurement from.

  • extra_ensemble_axes_shape (tuple of int, optional) – The shape of additional ensemble axes not in the waves.

  • extra_ensemble_axes_metadata (list of AxisMetadata) – The axes metadata of additional ensemble axes not in the waves.

Returns:

allocated_measurement – The allocated measurement

Return type:

BaseMeasurements or Waves

abtem.multislice.allocate_multislice_measurements(...) list[BaseMeasurements | Waves][source]#

Allocate the multislice measurements that would be produced by detecting the given set of wave functions with the given set of detectors.

Parameters:
  • waves (Waves) – The waves to derive the allocated measurement from.

  • detectors (list of BaseDetector) – The detectors to derive the allocated measurement from.

  • extra_ensemble_axes_shape (tuple of int, optional) – The shape of additional ensemble axes not in the waves.

  • extra_ensemble_axes_metadata (list of AxisMetadata) – The axes metadata of additional ensemble axes not in the waves.

Returns:

allocated_measurements – List of allocated to measurements.

Return type:

list

abtem.multislice.conventional_multislice_step(...) Waves[source]#

Calculate one step of the multislice algorithm for the given batch of wave functions through a given potential slice.

Parameters:
  • waves (Waves) – A batch of wave functions as a Waves object.

  • potential_slice (PotentialArray or TransmissionFunction) – A potential slice as a PotentialArray or TransmissionFunction.

  • propagator (FresnelPropagator, optional) – A Fresnel propagator type matching the wave functions. The main reason for using this argument is to reuse a previously calculated propagator. If not provided a new propagator is created.

  • antialias_aperture (AntialiasAperture, optional) – An antialias aperture type matching the wave functions. The main reason for using this argument is to reuse a previously calculated antialias aperture. If not provided a new antialias aperture is created.

  • conjugate (bool, optional) – If True, use the conjugate of the transmission function (default is False).

  • transpose (bool, optional) – If True, reverse the order of propagation and transmission (default is False).

Returns:

forward_stepped_waves – Wave functions propagated and transmitted through the potential slice.

Return type:

Waves

abtem.multislice.is_waves_base_measurements_or_list(...) TypeGuard[Waves | BaseMeasurements | list[Waves | BaseMeasurements]][source]#
abtem.multislice.lookahead(...)[source]#

Generator that yields (current, next) items from an iterable. The last item is yielded as (last, None).

abtem.multislice.multislice_and_detect(...) BaseMeasurements | Waves | list[BaseMeasurements | Waves][source]#

Calculate the full multislice algorithm for the given batch of wave functions through a given potential, detecting at each of the exit planes specified in the potential.

The potential is consumed in chunks of contiguous slices. For an unbuilt Potential, each chunk is eagerly computed into memory, the wave functions are propagated through those slices, and the chunk is discarded before the next one is built. This keeps peak memory bounded — previously, build() placed the entire slice dimension into a single dask chunk, so the full potential had to fit in memory (or VRAM) at once.

On GPU, where dask uses a synchronous scheduler and the full dask chunk is materialized at once, this chunking is critical for simulations whose potential exceeds available VRAM.

When the potential is already a pre-built PotentialArray (eager or dask-backed), the chunks are views into the existing array and the memory savings only apply if an unbuilt Potential is passed instead.

Parameters:
  • waves (Waves) – A batch of wave functions as a Waves object.

  • potential (BasePotential) – A potential as BasePotential object. Pass an unbuilt Potential to benefit from memory-bounded slice chunking. A pre-built PotentialArray is also supported but its full data is already in memory, so chunking only controls iteration grouping.

  • detectors ((list of) BaseDetector, optional) – A detector or a list of detectors defining how the wave functions should be converted to measurements after running the multislice algorithm.

  • algorithm (FourierMultislice or RealSpaceMultislice, optional) – Algorithm used for multislice operator (default is FourierMultislice()).

  • return_backscattered (bool, optional) – If algorithm.expansion_scope=”full” and return_backscatter is True, then the backscattered components are also returned. Requires potential exit_planes.

  • pbar (bool, optional) – If True, display a progress bar.

  • potential_chunk_size (int or str, optional) – Number of potential slices to eagerly build and hold in memory at once during propagation. "auto" (default) selects based on the configured memory budget (dask.chunk-size / dask.chunk-size-gpu). Can also be set globally via the potential.slice-chunk-size configuration key.

abtem.multislice.transition_potential_multislice_and_detect(...) list[BaseMeasurements | Waves] | BaseMeasurements | Waves[source]#

Calculate the full multislice algorithm for the given batch of wave functions through a given potential, detecting at each of the exit planes specified in the potential.

Parameters:
  • waves (Waves) – A batch of wave functions as a Waves object.

  • potential (BasePotential) – A potential as BasePotential object.

  • detectors ((list of) BaseDetector, optional) – A detector or a list of detectors defining how the wave functions should be converted to measurements after running the multislice algorithm.

  • algorithm (FourierMultislice or RealSpaceMultislice, optional) – Algorithm used for multislice operator (default is FourierMultislice())

Returns:

measurements – Exit waves or detected measurements or lists of measurements.

Return type:

Waves or tuple of BaseMeasurements