pyextal.potentialMap.synthesis

Fourier synthesis of potential and charge-density maps.

Both kinds of map are sampled on grids that are uniform in fractional (direct-lattice) coordinates, so a map is exactly a discrete Fourier transform on its grid points:

map[n] = sum_g F(g) exp(-2 pi i g . r_n),   r_n = sum_i n_i axes[i]

The structure factors are scattered into an array at their (folded) integer frequencies and transformed with one FFT. That is exact at the grid points for any grid size and costs O(N log N) whatever the number of beams; the old per-beam loop cost O(N_grid * N_beams). A 2D section whose axes are not integer lattice vectors has non-integer frequencies and falls back to a direct sum, which is still separable along the two axes.

Units follow the original potential_mapping code: a potential map is the electron structure factor times U2V (volts), a charge map is the X-ray structure factor (pyextal.callBloch.e2Xray) over the cell volume (electrons / Angstrom^3).

Attributes

Classes

MapResult

A refined map, its reference and their difference.

Functions

U2V(kv)

Factor from the structure factor U_g to the potential V_g in volts.

_fft_synthesis(F, freq, shape)

sum_g F_g exp(-2 pi i freq_g . n / shape) on every grid point n.

_direct_2d(F, gy, gx, shape)

Separable direct sum for non-integer frequencies on an (ny, nx) grid.

_xray(beams, F, to_xray)

X-ray structure factor of each beam from its electron one.

_coefficients(ctx, layer, beams, kind, model_sf, ...)

Refined and reference Fourier coefficients, and the beams' sources.

_finish(ctx, maps, beams, F, F_ref, source, kind, ...)

section_shape(metric, x_vector, y_vector, sampling)

(ny, nx) of a 2D section: sampling columns, rows by true length.

project_2d(ctx, x_vector, y_vector[, layer, beams, ...])

Refined, reference and difference map on the section spanned by two axes.

hkl_sphere(gstar[, g_max, hkl_range])

All non-zero hkl in a box, optionally cut to |g| <= g_max.

synthesize_3d(ctx[, layer, sampling, hkl_range, ...])

Refined, reference and difference map over the unit cell.

fourier_synthesis(getSF, order, sampling)

3D map from a structure-factor function, normalised by the cell volume.

Module Contents

pyextal.potentialMap.synthesis.KINDS = ('potential', 'charge')
pyextal.potentialMap.synthesis.U2V(kv)

Factor from the structure factor U_g to the potential V_g in volts.

Parameters:

kv (float) – Accelerating voltage in volts.

class pyextal.potentialMap.synthesis.MapResult

A refined map, its reference and their difference.

Variables:
  • refined (np.ndarray) – Map from the refined structure factors.

  • reference (np.ndarray) – Map from the reference (.dat/IAM) ones.

  • diff (np.ndarray) – refined - reference.

  • hkl (np.ndarray) – (n, 3) the beams summed.

  • sf_reference (sf_refined,) – (n,) complex coefficient of each beam, in the map’s units before the volume/voltage factor.

  • source (np.ndarray) – (n,) where each refined coefficient came from: ‘refined’, ‘friedel’ or ‘model’ (see LayerSF.resolve).

  • kind (str) – ‘potential’ or ‘charge’.

  • layer (int) – The run layer the refined map is from.

  • axes (np.ndarray) – (ndim, 3) one grid step along each array axis, in fractional direct-lattice coordinates.

  • lattice (np.ndarray) – (3, 3) Cartesian lattice vectors (rows).

  • settings (dict) – The arguments the map was made with.

refined: numpy.ndarray
reference: numpy.ndarray
diff: numpy.ndarray
hkl: numpy.ndarray
sf_refined: numpy.ndarray
sf_reference: numpy.ndarray
source: numpy.ndarray
kind: str
layer: int
axes: numpy.ndarray
lattice: numpy.ndarray
settings: dict
property ndim
property steps

(ndim, 3) Cartesian grid step along each array axis, Angstrom.

cartesian_grid()

Cartesian position of every grid point, shape map.shape + (3,).

pyextal.potentialMap.synthesis._fft_synthesis(F, freq, shape)

sum_g F_g exp(-2 pi i freq_g . n / shape) on every grid point n.

pyextal.potentialMap.synthesis._direct_2d(F, gy, gx, shape)

Separable direct sum for non-integer frequencies on an (ny, nx) grid.

pyextal.potentialMap.synthesis._xray(beams, F, to_xray)

X-ray structure factor of each beam from its electron one.

pyextal.potentialMap.synthesis._coefficients(ctx, layer, beams, kind, model_sf, to_xray, reference_iam)

Refined and reference Fourier coefficients, and the beams’ sources.

pyextal.potentialMap.synthesis._finish(ctx, maps, beams, F, F_ref, source, kind, layer, axes, kv, settings)
pyextal.potentialMap.synthesis.section_shape(metric, x_vector, y_vector, sampling)

(ny, nx) of a 2D section: sampling columns, rows by true length.

Parameters:
  • metric (np.ndarray) – (3, 3) direct metric tensor.

  • x_vector (array-like) – Section axes, direct-lattice indices.

  • y_vector (array-like) – Section axes, direct-lattice indices.

  • sampling (int or tuple) – Columns, or an explicit (ny, nx).

pyextal.potentialMap.synthesis.project_2d(ctx, x_vector, y_vector, layer=0, beams=None, sampling=256, kind='potential', kv=None, model_sf=None, to_xray=None, reference_iam=False)

Refined, reference and difference map on the section spanned by two axes.

The grid point at row i, column j sits at i/ny * y_vector + j/nx * x_vector. Only g . x_vector and g . y_vector enter the phase, so with the zero-order Laue zone beams this is the projected map down the zone axis.

Parameters:
  • ctx (MapContext) – From setup.

  • x_vector (array-like) – Section axes in direct-lattice indices, e.g. [-1, 1, 0] and [0, 0, 1] for the [110] zone.

  • y_vector (array-like) – Section axes in direct-lattice indices, e.g. [-1, 1, 0] and [0, 0, 1] for the [110] zone.

  • layer (int or LayerSF) – Run layer to map.

  • beams (array-like, optional) – (n, 3) beams to sum. Defaults to the .dat’s beams.

  • sampling (int or tuple) – Columns (rows follow the true axis lengths), or an explicit (ny, nx).

  • kind (str) – ‘potential’ (volts) or ‘charge’ (e / Angstrom^3).

  • kv (float, optional) – Voltage in volts for the potential; defaults to the .dat’s.

  • model_sf (np.ndarray or callable, optional) – lookupSF-format values for beams the run did not refine, or a function of the beams.

  • to_xray (callable, optional) – Electron-to-X-ray conversion with the signature of pyextal.callBloch.e2Xray (the default).

  • reference_iam (bool) – Reference from the IAM even where the .dat sets a structure factor.

Returns:

MapResult

pyextal.potentialMap.synthesis.hkl_sphere(gstar, g_max=None, hkl_range=None)

All non-zero hkl in a box, optionally cut to |g| <= g_max.

Parameters:
  • gstar (np.ndarray) – (3, 3) reciprocal metric tensor, Angstrom^-2.

  • g_max (float, optional) – Largest |g| in 1/Angstrom.

  • hkl_range (tuple, optional) – (p0, p1, p2), the box |h| <= p0 etc. Defaults to the smallest box that holds the g_max sphere.

Returns:

(n, 3) int.

Return type:

np.ndarray

pyextal.potentialMap.synthesis.synthesize_3d(ctx, layer=0, sampling=(64, 64, 64), hkl_range=None, g_max=None, beams=None, kind='potential', kv=None, model_sf=None, to_xray=None, reference_iam=False)

Refined, reference and difference map over the unit cell.

The grid is sampling points along a, b and c; point (i, j, k) sits at fractional coordinates (i/N0, j/N1, k/N2).

Parameters:
  • ctx (MapContext) – From setup.

  • layer (int or LayerSF) – Run layer to map.

  • sampling (tuple) – (N0, N1, N2).

  • hkl_range (tuple, optional) – (p0, p1, p2) box of beams to sum.

  • g_max (float, optional) – Keep beams with |g| <= g_max (1/Angstrom, through the reciprocal metric, so right for any cell).

  • beams (array-like, optional) – Explicit (n, 3) beams instead of the two above.

  • kind – As in project_2d.

  • kv – As in project_2d.

  • model_sf – As in project_2d.

  • to_xray – As in project_2d.

  • reference_iam – As in project_2d.

Returns:

MapResult

pyextal.potentialMap.synthesis.fourier_synthesis(getSF, order, sampling)

3D map from a structure-factor function, normalised by the cell volume.

The engine behind the old pyextal.densityMap.fourierSynthesis: sums getSF(hkl)[0] + 1j*getSF(hkl)[1] over |h|,|k|,|l| <= order (excluding 000) on a ``sampling``^3 fractional grid.

Parameters:
  • getSF (callable) – (h, k, l) -> sequence whose first two entries are the real and imaginary structure factor.

  • order (int) – Largest index.

  • sampling (int) – Grid points per axis.

Returns:

Real (sampling, sampling, sampling) map.

Return type:

np.ndarray