Electron diffraction pattern simulation.
pyxem.generators.diffraction_generator.
DiffractionGenerator
(accelerating_voltage, max_excitation_error, debye_waller_factors=None, scattering_params='lobato')[source]¶Bases: object
Computes electron diffraction patterns for a crystal structure.
Calculate reciprocal lattice of structure. Find all reciprocal points within the limiting sphere given by \(\frac{2}{\lambda}\).
For each reciprocal point \(\mathbf{g_{hkl}}\) corresponding to lattice plane \((hkl)\), compute the Bragg condition \(\sin(\theta) = \frac{\lambda}{2d_{hkl}}\)
The intensity of each reflection is then given in the kinematic approximation as the modulus square of the structure factor. \(I_{hkl} = F_{hkl}F_{hkl}^*\)
accelerating_voltage (float) – The accelerating voltage of the microscope in kV.
max_excitation_error (float) – The maximum extent of the relrods in reciprocal angstroms. Typically equal to 1/{specimen thickness}.
debye_waller_factors (dict of str : float) – Maps element names to their temperature-dependent Debye-Waller factors.
calculate_ed_data
(structure, reciprocal_radius, with_direct_beam=True)[source]¶Calculates the Electron Diffraction data for a structure.
structure (Structure) – The structure for which to derive the diffraction pattern. Note that the structure must be rotated to the appropriate orientation and that testing is conducted on unit cells (rather than supercells).
reciprocal_radius (float) – The maximum radius of the sphere of reciprocal space to sample, in reciprocal angstroms.
with_direct_beam (bool) – If True, the direct beam is included in the simulated diffraction pattern. If False, it is not.
The data associated with this structure and diffraction setup.
pyxem.DiffractionSimulation
calculate_profile_data
(structure, reciprocal_radius=1.0, magnitude_tolerance=1e-05, minimum_intensity=0.001)[source]¶Calculates a one dimensional diffraction profile for a structure.
structure (Structure) – The structure for which to calculate the diffraction profile.
reciprocal_radius (float) – The maximum radius of the sphere of reciprocal space to sample, in reciprocal angstroms.
magnitude_tolerance (float) – The minimum difference between diffraction magnitudes in reciprocal angstroms for two peaks to be consdiered different.
minimum_intensity (float) – The minimum intensity required for a diffraction peak to be considered real. Deals with numerical precision issues.
The diffraction profile corresponding to this structure and experimental conditions.
pyxem.ProfileSimulation
Generating DisplacementGradientMaps from diffraction vectors
pyxem.generators.displacement_gradient_tensor_generator.
get_DisplacementGradientMap
(strained_vectors, unstrained_vectors)[source]¶Calculates the displacement gradient tensor at each navigation position in a map by comparing vectors to determine the 2 x 2 matrix, \(\mathbf(L)\), that maps unstrained vectors, Vu, to strained vectors, Vs, using the np.lingalg.inv() function to find L that satisfies \(Vs = \mathbf(L) Vu\).
The transformation is returned as a 3 x 3 displacement gradient tensor.
strained_vectors (hyperspy.Signal2D) – Signal2D with a 2 x 2 array at each navigation position containing the Cartesian components of two strained basis vectors, V and U, defined as row vectors.
unstrained_vectors (numpy.array) – A 2 x 2 array containing the Cartesian components of two unstrained basis vectors, V and U, defined as row vectors.
D – The 3 x 3 displacement gradient tensor (measured in reciprocal space) at every navigation position.
pyxem.generators.displacement_gradient_tensor_generator.
get_single_DisplacementGradientTensor
(Vs, Vu=None)[source]¶Calculates the displacement gradient tensor from a pairs of vectors by determining the 2 x 2 matrix, \(\mathbf(L)\), that maps unstrained vectors, Vu, onto strained vectors, Vs, using the np.lingalg.inv() function to find \(\mathbf(L)\) that satisfies \(Vs = \mathbf(L) Vu\).
The transformation is returned as a 3 x 3 displacement gradient tensor.
Vs (numpy.array) – A 2 x 2 array containing the Cartesian components of two strained basis vectors, V and U, defined as row vectors.
Vu (numpy.array) – A 2 x 2 array containing the Cartesian components of two unstrained basis vectors, V and U, defined as row vectors.
D – A 3 x 3 displacement gradient tensor (measured in reciprocal space).
numpy.array
See also
Indexation generator and associated tools.
pyxem.generators.indexation_generator.
IndexationGenerator
(signal, diffraction_library)[source]¶Bases: object
Generates an indexer for data using a number of methods.
signal (ElectronDiffraction) – The signal of electron diffraction patterns to be indexed.
diffraction_library (DiffractionLibrary) – The library of simulated diffraction patterns for indexation.
correlate
(n_largest=5, mask=None, inplane_rotations=array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359]), max_peaks=100, *args, **kwargs)[source]¶Correlates the library of simulated diffraction patterns with the electron diffraction signal.
n_largest (int) – The n orientations with the highest correlation values are returned.
mask (Array) – Array with the same size as signal (in navigation) True False
inplane_rotations (ndarray) – Array of inplane rotation angles in degrees. Defaults to 0-360 degrees at 1 degree resolution.
max_peaks (int) – Maximum number of peaks to consider when comparing a template to the diffraction pattern. The strongest peaks are kept.
*args (arguments) – Arguments passed to map().
**kwargs (arguments) – Keyword arguments passed map().
matching_results – Navigation axes of the electron diffraction signal containing correlation results for each diffraction pattern, in the form [Library Number , [z, x, z], Correlation Score]
pyxem.generators.indexation_generator.
ProfileIndexationGenerator
(magnitudes, simulation, mapping=True)[source]¶Bases: object
Generates an indexer for data using a number of methods.
profile (ElectronDiffractionProfile) – The signal of diffraction profiles to be indexed.
library (ProfileSimulation) – The simulated profile data.
index_peaks
(tolerance=0.1, *args, **kwargs)[source]¶Assigns hkl indices to peaks in the diffraction profile.
tolerance (float) – The n orientations with the highest correlation values are returned.
keys (list) – If more than one phase present in library it is recommended that these are submitted. This allows a mapping from the number to the phase. For example, keys = [‘si’,’ga’] will have an output with 0 for ‘si’ and 1 for ‘ga’.
*args (arguments) – Arguments passed to the map() function.
**kwargs (arguments) – Keyword arguments passed to the map() function.
matching_results
ProfileIndexation
pyxem.generators.indexation_generator.
VectorIndexationGenerator
(vectors, vector_library)[source]¶Bases: object
Generates an indexer for DiffractionVectors using a number of methods.
vectors
¶DiffractionVectors to be indexed.
vector_library
¶Library of theoretical diffraction vector magnitudes and inter-vector angles for indexation.
vectors (DiffractionVectors) – DiffractionVectors to be indexed.
vector_library (DiffractionVectorLibrary) – Library of theoretical diffraction vector magnitudes and inter-vector angles for indexation.
index_vectors
(mag_tol, angle_tol, index_error_tol, n_peaks_to_index, n_best, *args, **kwargs)[source]¶Assigns hkl indices to diffraction vectors.
mag_tol (float) – The maximum absolute error in diffraction vector magnitude, in units of reciprocal Angstroms, allowed for indexation.
angle_tol (float) – The maximum absolute error in inter-vector angle, in units of degrees, allowed for indexation.
index_error_tol (float) – Max allowed error in peak indexation for classifying it as indexed, calculated as \(|hkl_calculated - round(hkl_calculated)|\).
n_peaks_to_index (int) – The maximum number of peak to index.
n_best (int) – The maximum number of good solutions to be retained.
*args (arguments) – Arguments passed to the map() function.
**kwargs (arguments) – Keyword arguments passed to the map() function.
indexation_results – Navigation axes of the diffraction vectors signal containing vector indexation results for each probe position.
Diffraction pattern library generator and associated tools.
pyxem.generators.library_generator.
DiffractionLibraryGenerator
(electron_diffraction_calculator)[source]¶Bases: object
Computes a library of electron diffraction patterns for specified atomic structures and orientations.
get_diffraction_library
(structure_library, calibration, reciprocal_radius, half_shape, with_direct_beam=True)[source]¶Calculates a dictionary of diffraction data for a library of crystal structures and orientations.
Each structure in the structure library is rotated to each associated orientation and the diffraction pattern is calculated each time.
Angles must be in the Euler representation (Z,X,Z) and in degrees
structure_library (pyxem:StructureLibrary Object) – Dictionary of structures and associated orientations for which electron diffraction is to be simulated.
calibration (float) – The calibration of experimental data to be correlated with the library, in reciprocal Angstroms per pixel.
reciprocal_radius (float) – The maximum g-vector magnitude to be included in the simulations.
half_shape (tuple) – The half shape of the target patterns, for 144x144 use (72,72) etc
with_direct_beam (bool) – Include the direct beam in the library.
diffraction_library – Mapping of crystal structure and orientation to diffraction data objects.
DiffractionLibrary
pyxem.generators.library_generator.
VectorLibraryGenerator
(structure_library)[source]¶Bases: object
Computes a library of diffraction vectors and pairwise inter-vector angles for a specified StructureLibrary.
get_vector_library
(reciprocal_radius)[source]¶Calculates a library of diffraction vectors and pairwise inter-vector angles for a library of crystal structures.
reciprocal_radius (float) – The maximum g-vector magnitude to be included in the library.
vector_library – Mapping of phase identifier to phase information in dictionary format.
DiffractionVectorLibrary
pyxem.generators.structure_library_generator.
StructureLibraryGenerator
(phases)[source]¶Bases: object
Generates a structure library for the given phases
phases (list) – Array of three-component phase descriptions, where the phase description is [<phase name> : string, <structure> : diffpy.structure.Structure, <crystal system> : string], and crystal system is one of ‘cubic’, ‘hexagonal’, ‘orthorombic’, ‘tetragonal’, ‘trigonal’, ‘monoclinic’.
phase_names
¶List of phase names.
list of string
structures
¶List of structures.
list of diffpy.structure.Structure
systems
¶List of crystal systems.
list of string
Examples
>>> gen = StructureLibraryGenerator([
... ('ZB', structure_zb, 'cubic'),
... ('WZ', structure_wz, 'hexagonal')])
get_orientations_from_list
(orientations)[source]¶Create a structure library from a list of rotations.
orientations (list) – A list over identifiers of lists of euler angles (as tuples) in the rzxz convention and in degrees.
structure_library – Structure library for the given phase names, structures and orientations.
get_orientations_from_stereographic_triangle
(inplane_rotations, resolution)[source]¶Create a structure library from the stereographic triangles of the given crystal systems.
structure_library – Structure library for the given phase names, structures and crystal system.
Generating subpixel resolution on diffraction vectors.
pyxem.generators.subpixelrefinement_generator.
SubpixelrefinementGenerator
(dp, vectors)[source]¶Bases: object
Generates subpixel refinement of DiffractionVectors.
dp (ElectronDiffraction) – The electron diffraction patterns to be refined
vectors (DiffractionVectors | ndarray) – Vectors (in calibrated units) to the locations of the spots to be refined. If given as DiffractionVectors, it must have the same navigation shape as the electron diffraction patterns. If an ndarray, the same set of vectors is mapped over all electron diffraction patterns.
References
[1] Pekin et al. Ultramicroscopy 176 (2017) 170-176
center_of_mass_method
(square_size)[source]¶Find the subpixel refinement of a peak by assuming it lies at the center of intensity.
square_size (int) – Length (in pixels) of one side of a square the contains the peak to be refined.
vector_out – DiffractionVectors containing the refined vectors in calibrated units with the same navigation shape as the diffraction patterns.
conventional_xc
(square_size, disc_radius, upsample_factor)[source]¶Refines the peaks using (phase) cross correlation.
vector_out – DiffractionVectors containing the refined vectors in calibrated units with the same navigation shape as the diffraction patterns.
local_gaussian_method
(square_size)[source]¶Refinement based on the mathematics of a local maxima on a continious region, using the (discrete) maxima pixel as a starting point. See Notes.
square_size (int) – Length (in pixels) of one side of a square the contains the peak to be refined.
vector_out – DiffractionVectors containing the refined vectors in calibrated units with the same navigation shape as the diffraction patterns.
Notes
This method works by first locating the maximum intenisty value within teh square. The four adjacent pixels are then considered and used to form two independant quadratic equations. Solving these gives the x_center and y_center coordinates, which are then returned.
VDF generator and associated tools.
pyxem.generators.vdf_generator.
VDFGenerator
(signal, vectors=None, *args, **kwargs)[source]¶Bases: object
Generates a VDF images for a specified signal and set of aperture positions.
signal (ElectronDiffraction) – The signal of electron diffraction patterns to be indexed.
vectors (DiffractionVectors(optional)) – The vector positions, in calibrated units, at which to position integration windows for VDF formation.
get_concentric_vdf_images
(k_min, k_max, k_steps, normalize=False)[source]¶Obtain the intensity scattered at each navigation position in an ElectronDiffraction Signal by summation over a series of concentric in annuli between a specified inner and outer radius in a number of steps.
vdfs – VDFImage object containing virtual dark field images for all steps within the annulus.
get_vector_vdf_images
(radius, normalize=False)[source]¶Obtain the intensity scattered to each diffraction vector at each navigation position in an ElectronDiffraction Signal by summation in a circular window of specified radius.
radius (float) – Radius of the integration window in reciprocal angstroms.
normalize (boolean) – If True each VDF image is normalized so that the maximum intensity in each VDF is 1.
vdfs – VDFImage object containing virtual dark field images for all unique vectors.