CXS Class

class CXS(n, L=1.0, dq=1.0, f_probe=None, f_mask=None)

Bases: Module

Base class to compute the coherent X-ray scattering pattern of an object.

Parameters:
  • n (int) – Dimension of reciprocal-space pattern n x n for dq = 1 (default). When dq < 1, the new dimension n will be recomputed and saved as an attribute.

  • L (float) – Length of the real-space simulation box (L x L).

  • dq (float) – Sampling in reciprocal space, i.e. the fraction of \(2 \pi/L\) at which to sample. Default is dq = 1, corresponding to a spacing of \(2 \pi/L\).

  • f_probe (float) – Standard deviation of the Gaussian probe intensity as a fraction of L.

  • f_mask (float) – Radius of center beam stop as a fraction of n.

Variables:
  • cmap (matplotlib.colors.Colormap) – Default colormap for plotting.

  • gmap (matplotlib.colors.Colormap) – cmap with an opacity gradient.

  • q (torch.tensor) – 1-D tensor of reciprocal space coordinates determined by the dimension n and sampling dq.

  • n (int) – Recomputed dimension of reciprocal-space pattern n x n for the input sampling dq.

  • Q (torch.tensor) – 2-D tensor of shape (n x n, 2) containing the reciprocal space coordinate grid.

  • mask (torch.tensor) – Boolean tensor storing the masked detector pixels.

  • probe (torch.nn.Conv2d) – Convolution operator for convolving the reciprocal space pattern with the probe.

center_crop(y, k)

Crop y down to its central k x k pixels.

Parameters:
  • y (torch.tensor) – Tensor to crop.

  • k (int) – Target dimension, k x k.

Returns:

y – Cropped tensor.

Return type:

torch.tensor of shape (...,k,k)

plot_example(ode, y, ntype=None, vmin=None, vmax=None, lmax=None)

Plot images visualizing the scattering conditions of a given example.

Parameters:
  • ode (ode) – ODE object of the system.

  • y (torch.tensor) – Solution of the system to plot.

  • ntype (str) –

    Type of normalization to apply when displaying the image. The options are:

    • none – No normalization

    • sym – Symmetric linear normalization scale

    • unit – Linear normalization between 0 and 1

    • mod – Linear normalization modulo \(2 \pi\)

    • log – Logarithmic normalization scale

    • symlog – Symmetric logarithmic normalization scale

    • None – Linear normalization between the min. and max. values of y

    The default is None.

  • vmin (float, optional) – Minimum normalization value.

  • vmax (float, optional) – Maximum normalization value.

  • lmax (float, optional) – Maximum intensity, proxy for maximum expected event frequency of Poisson process. The default value is None, corresponding to the ideal scattered intensity without Poisson sampling.

Returns:

fig – Figure object.

Return type:

matplotlib.figure

plot_probe(ax, ec='white')

Plot the real and, optionally, reciprocal space views of the probe.

Parameters:

ax (matplotlib.axes) – Axis or list of axis objects on which to display the image(s).

Returns:

sm – List of scalar mappables storing the color scales of the two plots.

Return type:

list

shapes()

Print detector and probe shapes.

class CXSGrid(N, n, L=1.0, dq=1.0, f_probe=None, f_mask=None, f=None, w=None, c=None, k=0)

Bases: CXS

Class to compute the coherent X-ray scattering pattern of an object on a uniform grid.

Parameters:
  • N (int) – Dimension of real-space grid N x N.

  • n (int) – Dimension of reciprocal-space pattern n x n for dq = 1 (default). When dq < 1, the new dimension n will be recomputed and saved as an attribute.

  • L (float) – Length of the real-space simulation box (L x L).

  • dq (float) – Sampling in reciprocal space, i.e. the fraction of \(2 \pi/L\) at which to sample. Default is dq = 1, corresponding to a spacing of \(2 \pi/L\).

  • f_probe (float) – Standard deviation of the Gaussian probe intensity as a fraction of L.

  • f_mask (float) – Radius of center beam stop as a fraction of n.

  • f (str) – Form factor function to use. Current options are phase or none (identity).

  • w (list) – List of relative weights on input channels.

  • c (list) – List of relative weights on non-magnetic and magnetic scattering channels.

Variables:
  • cmap (matplotlib.colors.Colormap) – Default colormap for plotting.

  • gmap (matplotlib.colors.Colormap) – cmap with an opacity gradient.

  • q (torch.tensor) – 1-D tensor of reciprocal space coordinates determined by the dimension n and sampling dq.

  • n (int) – Recomputed dimension of reciprocal-space pattern n x n for the input sampling dq.

  • Q (torch.tensor) – 2-D tensor of shape (n x n, 2) containing the reciprocal space coordinate grid.

  • mask (torch.tensor) – Boolean tensor storing the masked detector pixels.

  • probe (torch.nn.Conv2d) – Convolution operator for convolving the reciprocal space pattern with the probe.

I_xmcd(y)

Magnetic scattering channel intensity.

Parameters:

y (torch.tensor) – Tensor of orientations over the real-space grid.

Returns:

I – Scattered intensity.

Return type:

torch.tensor

I_xnm()

Non-magnetic scattering channel intensity.

Returns:

I – Scattered intensity.

Return type:

torch.tensor

f_none(y)

Identity form factor.

Parameters:

y (torch.tensor) – Tensor of phases at which to evaluate the form factor.

Returns:

f – Form factor evaluated at each point in y.

Return type:

torch.tensor of shape y.shape

f_phase(y)

Orientation-dependent form factor.

Parameters:

y (torch.tensor) – Tensor of phases at which to evaluate the form factor.

Returns:

f – Form factor evaluated at each point in y.

Return type:

torch.tensor of shape y.shape

forward(y)

Compute the total scattered intensity.

Parameters:

y (torch.tensor) – Tensor of orientations over the real-space grid.

Returns:

I – Scattered intensity.

Return type:

torch.tensor

class CXSPoint(R, n, L=1.0, dq=1.0, f_probe=None, f_mask=None, c=None)

Bases: CXS

Class to compute the coherent X-ray scattering pattern of a point cloud of spherical objects.

Parameters:
  • R (int) – Radius of spherical objects.

  • n (int) – Dimension of reciprocal-space pattern n x n for dq = 1 (default). When dq < 1, the new dimension n will be recomputed and saved as an attribute.

  • L (float) – Length of the real-space simulation box (L x L).

  • dq (float) – Sampling in reciprocal space, i.e. the fraction of \(2 \pi/L\) at which to sample. Default is dq = 1, corresponding to a spacing of \(2 \pi/L\).

  • f_probe (float) – Standard deviation of the Gaussian probe intensity as a fraction of L.

  • f_mask (float) – Radius of center beam stop as a fraction of n.

  • c (list) – List of relative weights on non-magnetic and magnetic scattering channels.

Variables:
  • cmap (matplotlib.colors.Colormap) – Default colormap for plotting.

  • gmap (matplotlib.colors.Colormap) – cmap with an opacity gradient.

  • q (torch.tensor) – 1-D tensor of reciprocal space coordinates determined by the dimension n and sampling dq.

  • n (int) – Recomputed dimension of reciprocal-space pattern n x n for the input sampling dq.

  • Q (torch.tensor) – 2-D tensor of shape (n x n, 2) containing the reciprocal space coordinate grid.

  • mask (torch.tensor) – Boolean tensor storing the masked detector pixels.

  • probe (torch.nn.Conv2d) – Convolution operator for convolving the reciprocal space pattern with the probe.

I_xmcd(ys)

Magnetic scattering channel intensity.

Parameters:

ys (List of torch.tensors) – List of tensors giving the orientations as well as the real and imaginary parts of the phase term.

Returns:

I – Scattered intensity.

Return type:

torch.tensor

I_xnm(ys)

Non-magnetic scattering channel intensity.

Parameters:

ys (List of torch.tensors) – List of tensors of the real and imaginary parts of the phase term.

Returns:

I – Scattered intensity.

Return type:

torch.tensor

f_coreshell(q, Rc, Rs, pc, ps, pa)

Normalized form factor of a core-shell particle.

Parameters:
  • q (torch.tensor) – Tensor of reciprocal-space points at which to evaluate the form factor.

  • Rc (float) – Radius of core.

  • Rs (float) – Radius of shell.

  • pc (float) – Scattering length density of core.

  • ps (float) – Scattering length density of shell.

  • pa (float) – Scattering length density of solvent.

Returns:

f – Form factor evaluated at each point in q.

Return type:

torch.tensor of shape q.shape

f_phase(y)

Orientation-dependent form factor.

Parameters:

y (torch.tensor) – Tensor of phases at which to evaluate the form factor.

Returns:

f – Form factor evaluated at each point in y.

Return type:

torch.tensor of shape y.shape

f_sphere(q, R)

Normalized form factor of a sphere.

Parameters:
  • q (torch.tensor) – Tensor of reciprocal-space points at which to evaluate the form factor.

  • R (float) – Radius of sphere.

Returns:

f – Form factor evaluated at each point in q.

Return type:

torch.tensor of shape q.shape

forward(y)

Compute the total scattered intensity.

Parameters:

y (torch.tensor) – Tensor of particle coordinates. The final dimension should correspond to orientations, if applicable.

Returns:

I – Scattered intensity.

Return type:

torch.tensor