bcdi.simulation: calculation of the diffraction intensity based on FFT or kinematical sum

simulation_utils

In Bragg geometry, calculation of the diffraction intensity based on FFT or kinematical sum. It can include a displacement field, noise, detector gaps etc… See Carnis et al. Scientific Reports 9, 17357 (2019) https://doi.org/10.1038/s41598-019-53774-2

In forward CDI geometry, calculation of the Bragg peak positions in 3D for a mesocrystal, knowing the unit cell and unit cell parameter. It can be used to fit experimental data.

API Reference

Functions related to the calculation of crystalline lattices.

bcdi.simulation.simulation_utils.angle_vectors(ref_vector, test_vector, basis_vectors=(numpy.array, numpy.array, numpy.array))

Calculate the angle between two vectors expressed in a defined basis.

It uses the Gram matrix.

Parameters:
  • ref_vector – reference vector

  • test_vector – vector for which the angle relative to the reference vector should be calculated

  • basis_vectors – tuple of the three components of the basis vectors expressed in the orthonormal basis. The convention used for the orthonormal basis is ([1, 0, 0], [0, 1, 0], [0, 0, 1]).

Returns:

the angle in degrees

bcdi.simulation.simulation_utils.assign_peakshape(array_shape, lattice_list, peak_shape, pivot)

Assign the 3D peak_shape to lattice points.

Parameters:
  • array_shape – shape of the output array

  • lattice_list – list of points in pixels [[z1,y1,x1],[z2,y2,x2],…]

  • peak_shape – the 3D kernel to apply at each lattice point

  • pivot – position of the center of reciprocal space in pixels

Returns:

a 3D array featuring the peak shape at each lattice point

bcdi.simulation.simulation_utils.bcc_lattice(q_values, unitcell_param, pivot, euler_angles=(0, 0, 0), offset_indices=False, verbose=False)

Calculate Bragg peaks positions using experimental parameters for a BCC unit cell.

Parameters:
  • q_values – tuple of 1D arrays (qx, qz, qy), q_values range where to look for Bragg peaks

  • unitcell_param – the unit cell parameter of the BCC lattice in nm

  • pivot – tuple, the pivot point position in pixels for the rotation

  • euler_angles – tuple of angles for rotating the unit cell around (qx, qz, qy)

  • offset_indices – if True, return the non rotated lattice with the origin of indices corresponding to the length of padded q values

  • verbose – True to have printed comments

Returns:

offsets after padding, the list of Bragg peaks positions in pixels, and the corresponding list of hlk.

bcdi.simulation.simulation_utils.bct_lattice(q_values, unitcell_param, pivot, euler_angles=(0, 0, 0), offset_indices=False, verbose=False)

Calculate Bragg peaks positions for a BCT unit cell.

The long axis is by default along qz (vertical up).

Parameters:
  • q_values – tuple of 1D arrays (qx, qz, qy), q_values range where to look for Bragg peaks

  • unitcell_param – tuple, the unit cell parameters of the BCT lattice in nm (square side, long axis)

  • pivot – tuple, the pivot point position in pixels for the rotation

  • euler_angles – tuple of angles for rotating the unit cell around (qx, qz, qy)

  • offset_indices – if True, return the non rotated lattice with the origin of indices corresponding to the length of padded q values

  • verbose – True to have printed comments

Returns:

offsets after padding, the list of Bragg peaks positions in pixels, and the corresponding list of hlk.

bcdi.simulation.simulation_utils.cubic_lattice(q_values, unitcell_param, pivot, euler_angles=(0, 0, 0), offset_indices=False, verbose=False)

Calculate Bragg peaks positions for a simple cubic unit cell.

Parameters:
  • q_values – tuple of 1D arrays (qx, qz, qy), q_values range where to look for Bragg peaks

  • unitcell_param – the unit cell parameter of the simple cubic lattice in nm

  • pivot – tuple, the pivot point position in pixels for the rotation

  • euler_angles – tuple of angles for rotating the unit cell around (qx, qz, qy)

  • offset_indices – if True, return the non rotated lattice with the origin of indices corresponding to the length of padded q values

  • verbose – True to have printed comments

Returns:

offsets after padding, the list of Bragg peaks positions in pixels, and the corresponding list of hlk.

bcdi.simulation.simulation_utils.fcc_lattice(q_values, unitcell_param, pivot, euler_angles=(0, 0, 0), offset_indices=False, verbose=False)

Calculate Bragg peaks positions for a FCC unit cell.

Parameters:
  • q_values – tuple of 1D arrays (qx, qz, qy), q_values range where to look for Bragg peaks

  • unitcell_param – the unit cell parameter of the FCC lattice in nm

  • pivot – tuple, the pivot point position in pixels for the rotation

  • euler_angles – tuple of angles for rotating the unit cell around (qx, qz, qy)

  • offset_indices – if True, return the non rotated lattice with the origin of indices corresponding to the length of padded q values

  • verbose – True to have printed comments

Returns:

offsets after padding, the list of Bragg peaks positions in pixels, and the corresponding list of hlk.

bcdi.simulation.simulation_utils.gap_detector(data, mask, start_pixel, width_gap)

Reproduce a detector gap in reciprocal space data and mask.

Parameters:
  • data – the 3D reciprocal space data

  • mask – the corresponding 3D mask

  • start_pixel – pixel number where the gap starts

  • width_gap – width of the gap in pixels

Returns:

data and mask array with a gap

bcdi.simulation.simulation_utils.lattice(energy, sdd, direct_beam, detector, unitcell, unitcell_param, euler_angles=(0, 0, 0), offset_indices=False)

Calculate the position of the Bragg peaks positions for a particular unit cell.

Parameters:
  • energy – X-ray energy in eV

  • sdd – sample to detector distance in m

  • direct_beam – direct beam position on the detector in pixels (vertical, horizontal)

  • detector – the detector object: Class experiment_utils.Detector()

  • unitcell – ‘cubic’, ‘bcc’, ‘fcc’, ‘bct’

  • unitcell_param – number or tuple for unit cell parameters

  • euler_angles – tuple of angles for rotating the unit cell around (qx, qz, qy)

  • offset_indices – if True, return the non rotated lattice with the origin of indices corresponding to the length of padded q values

Returns:

pivot position, q values, a list of pixels positions for each Bragg peak, Miller indices.

bcdi.simulation.simulation_utils.reciprocal_lattice(alpha, beta, gamma, a1, a2, a3, input_lattice='direct', verbose=False)

Calculate the reciprocal lattice given the direct space lattice parameters.

It assumes the most general triclinic lattice.

Parameters:
  • alpha – in degrees, angle between a2 and a3

  • beta – in degrees, angle between a1 and a3

  • gamma – in degrees, angle between a1 and a2

  • a1 – length of the first direct lattice basis vector in nm

  • a2 – length of the second direct lattice basis vector in nm

  • a3 – length of the third direct lattice basis vector in nm

  • input_lattice – ‘direct’ or ‘reciprocal’, used to define the unit for the volume of the unit cell

  • verbose – True to print comments

Returns:

the triclinic reciprocal lattice componenets (alpha_r, beta_r, gamma_r, b1, b2, b3)

bcdi.simulation.simulation_utils.rotate_lattice(lattice_list, peaks_list, original_shape, pad_offset, pivot, euler_angles=(0, 0, 0))

Rotate a lattice.

It rotates lattice points given Euler angles, the pivot position and an eventual offset of the origin.

Parameters:
  • lattice_list – list of Bragg peaks positions in pixels to be rotated [[z1,y1,x1],[z2,y2,x2],…]

  • peaks_list – corresponding list of [[h1,l1,k1],[h2,l2,k2]…]

  • original_shape – shape of q values before padding

  • pad_offset – index shift of the origin for the padded q values

  • pivot – tuple, the pivot point position in pixels for the rotation

  • euler_angles – tuple of angles for rotating the unit cell around (qx, qz, qy)

Returns:

list of Bragg peaks positions fitting into the range, and the corresponding list of hlk

bcdi.simulation.simulation_utils.triclinic_to_basis(alpha, beta, gamma, a1, a2, a3)

Change basis for the most general triclinic lattice.

It calculate the basis vector components in the orthonormal basis [[1, 0, 0], [0, 1, 0], [0, 0, 1]].

Parameters:
  • alpha – in degrees, angle between a2 and a3

  • beta – in degrees, angle between a1 and a3

  • gamma – in degrees, angle between a1 and a2

  • a1 – length of the first basis vector

  • a2 – length of the second basis vector

  • a3 – length of the third basis vector

Returns:

the basis vector components expressed in the orthonormal basis as (v1, v2, v3)

supportMaker

This module provides tools to create a simple support using polygons. It is possible to define distances in pixels or nanometers.

API Reference

Make a 3D polygon.

bcdi.simulation.supportMaker.AddPolyCen(array, center, planes)

Make the polygon.

Parameters:
  • array – input array

  • center – origin of polygon

  • planes – array of planes

bcdi.simulation.supportMaker.MakePoly(dims, planes)

Make a polygon.

Parameters:
  • dims – dimensions of array in pixels

  • planes – array of planes

bcdi.simulation.supportMaker.MakePolyCen(dims, center, planes)

Make the polygon.

Parameters:
  • array – input array

  • center – origin of polygon

  • planes – array of planes

bcdi.simulation.supportMaker.generatePlanesCuboid(x, y, z)

Make a cuboid of size x,y,z.

bcdi.simulation.supportMaker.generatePlanesPrism(x, y)

Make a Prism of thickness x, y is somewhat arbitrary.

bcdi.simulation.supportMaker.generatePlanesTetrahedra(x)

Make a tetrahedra of dimension x.

bcdi.simulation.supportMaker.make_poly(dims, planes)

Make a polygon.

Parameters:
  • dims – dimensions of array in pixels

  • planes – array of planes

bcdi.simulation.supportMaker.rot_planes(planes, rot)

Rotate planes with some rotation matrix.

something is wrong here if I import this it doesnt work

class bcdi.simulation.supportMaker.supportMaker(rawdata, wavelength=None, detector_distance=None, detector_pixel_size=None, ang_step=None, braggAng=None, planes=None, planesDist=None, voxel_size=None)

A masking class for support creation.

Parameters:
  • rawdata – raw experimental data

  • wavelength – x-ray wavelength

  • detector_distance – sample to detector (m)

  • detector_pixel_size – detector pixel size - 2D (m)

  • ang_step – angular step (degrees)

  • braggAng – bragg angle (degrees)

  • planes – array of planes np.array([x,y,z])

  • planesDist – array of plane distance to origin (m)

  • voxel_size – set the voxel size to some arbitrary size, np.array([x,y,z]) (m)

calc_voxel_size(wavelength=None, detDist=None, pixel_size=None, ang_step=None, braggAng=None)

Calculate the voxel size.

get_planes()

Return planes array.

get_planesDist()

Return planes distance from origin.

get_support()

Return the generated support.

set_planes(planes_list, plane_distance_origin_list)

Set the planes.

set_support(rawdata)

Set the support to match rawdata dimensions.

set_voxel_size(voxel_size)

Set the voxel size.