From f6432deaa2e8a3526322ad484bf693a5f38e4d09 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 12:23:10 +0000 Subject: [PATCH 1/5] Rotate the reciprocal lattice points --- diffsims/generators/diffraction_generator.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/diffsims/generators/diffraction_generator.py b/diffsims/generators/diffraction_generator.py index 34e8976a..54830f37 100644 --- a/diffsims/generators/diffraction_generator.py +++ b/diffsims/generators/diffraction_generator.py @@ -22,6 +22,7 @@ import numpy as np from math import pi +from transforms3d.euler import euler2mat from diffsims.sims.diffraction_simulation import DiffractionSimulation from diffsims.sims.diffraction_simulation import ProfileSimulation @@ -82,6 +83,7 @@ def __init__(self, def calculate_ed_data(self, structure, + rotation, reciprocal_radius, with_direct_beam=True): """Calculates the Electron Diffraction data for a structure. @@ -92,6 +94,8 @@ def calculate_ed_data(self, 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). + rotation : tuple + Euler angles, in degrees, in the rzxz convention reciprocal_radius : float The maximum radius of the sphere of reciprocal space to sample, in reciprocal angstroms. @@ -118,6 +122,10 @@ def calculate_ed_data(self, spot_indicies, cartesian_coordinates, spot_distances = get_points_in_sphere( recip_latt, reciprocal_radius) + ai,aj,ak = np.deg2rad(rotation[0]),np.deg2rad(rotation[1]),np.deg2rad(rotation[2]) + R = euler2mat(ai,aj,ak,axes='rzxz') + cartesian_coordinates = np.matmul(R,cartesian_coordinates.T).T + # Identify points intersecting the Ewald sphere within maximum # excitation error and store the magnitude of their excitation error. r_sphere = 1 / wavelength From 28a5f088d2b99b32eca1f69e8bde1bf051960926 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 12:30:33 +0000 Subject: [PATCH 2/5] make rotation a kwargs --- diffsims/generators/diffraction_generator.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/diffsims/generators/diffraction_generator.py b/diffsims/generators/diffraction_generator.py index 54830f37..69d0a10c 100644 --- a/diffsims/generators/diffraction_generator.py +++ b/diffsims/generators/diffraction_generator.py @@ -83,8 +83,8 @@ def __init__(self, def calculate_ed_data(self, structure, - rotation, reciprocal_radius, + rotation=(0,0,0), with_direct_beam=True): """Calculates the Electron Diffraction data for a structure. @@ -94,11 +94,12 @@ def calculate_ed_data(self, 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). - rotation : tuple - Euler angles, in degrees, in the rzxz convention reciprocal_radius : float The maximum radius of the sphere of reciprocal space to sample, in reciprocal angstroms. + rotation : tuple + Euler angles, in degrees, in the rzxz convention. Default is (0,0,0) + which aligns 'z' with the electron beam with_direct_beam : bool If True, the direct beam is included in the simulated diffraction pattern. If False, it is not. From 02c0c3a13d606bcc303e7fcb57b383f0d6dfbb50 Mon Sep 17 00:00:00 2001 From: pc494 Date: Wed, 29 Jan 2020 12:34:57 +0000 Subject: [PATCH 3/5] Adjust library generator for new rotation style --- diffsims/generators/library_generator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/diffsims/generators/library_generator.py b/diffsims/generators/library_generator.py index d1f8d696..797ea92e 100644 --- a/diffsims/generators/library_generator.py +++ b/diffsims/generators/library_generator.py @@ -101,8 +101,7 @@ def get_diffraction_library(self, intensities = np.empty(num_orientations, dtype='object') # Iterate through orientations of each phase. for i, orientation in enumerate(tqdm(orientations, leave=False)): - matrix = euler2mat(*np.deg2rad(orientation), 'rzxz') - simulation = simulate_rotated_structure(diffractor, structure, matrix, reciprocal_radius, with_direct_beam) + simulation = diffractor.calculate_ed_data(structure,reciprocal_radius,rotation=orientation,with_direct_beam=with_direct_beam) # Calibrate simulation simulation.calibration = calibration From 62ce60a8dffde6dfca4bd2c2d01e44598857137a Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 30 Jan 2020 17:35:34 +0000 Subject: [PATCH 4/5] Delete simulate_rotate_structure --- diffsims/utils/sim_utils.py | 40 ------------------------------------- 1 file changed, 40 deletions(-) diff --git a/diffsims/utils/sim_utils.py b/diffsims/utils/sim_utils.py index b0bc7fd9..b7c16c34 100644 --- a/diffsims/utils/sim_utils.py +++ b/diffsims/utils/sim_utils.py @@ -346,46 +346,6 @@ def simulate_kinematic_scattering(atomic_coordinates, return intensity - -def simulate_rotated_structure(diffraction_generator, structure, rotation_matrix, reciprocal_radius, with_direct_beam): - """Calculate electron diffraction data for a structure after rotating it. - - Parameters - ---------- - diffraction_generator : DiffractionGenerator - Diffraction generator used to simulate diffraction patterns - structure : diffpy.structure.Structure - Structure object to simulate - rotation_matrix : ndarray - 3x3 matrix describing the base rotation to apply to the structure, applied on the left of the vector - reciprocal_radius : float - The maximum g-vector magnitude to be included in the simulations. - with_direct_beam : bool - Include the direct beam peak - - Returns - ------- - simulation : DiffractionSimulation - The simulation data generated from the given structure and rotation. - """ - # Convert left multiply (input) to right multiply (diffpy) - stdbase = structure.lattice.stdbase - stdbase_inverse = np.linalg.inv(stdbase) - rotation_matrix_diffpy = stdbase_inverse @ rotation_matrix @ stdbase - - lattice_rotated = diffpy.structure.lattice.Lattice( - *structure.lattice.abcABG(), - baserot=rotation_matrix_diffpy) - # Don't change the original - structure_rotated = diffpy.structure.Structure(structure) - structure_rotated.placeInLattice(lattice_rotated) - - return diffraction_generator.calculate_ed_data( - structure_rotated, - reciprocal_radius, - with_direct_beam) - - def get_points_in_sphere(reciprocal_lattice, reciprocal_radius): """Finds all reciprocal lattice points inside a given reciprocal sphere. Utilised within the DiffractionGenerator. From b58055978fb215942ab33b6f2f5566dc3a09d5a4 Mon Sep 17 00:00:00 2001 From: pc494 Date: Thu, 30 Jan 2020 17:53:09 +0000 Subject: [PATCH 5/5] Remove an import of a deleted function --- diffsims/generators/library_generator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/diffsims/generators/library_generator.py b/diffsims/generators/library_generator.py index 797ea92e..aac52f8f 100644 --- a/diffsims/generators/library_generator.py +++ b/diffsims/generators/library_generator.py @@ -30,7 +30,6 @@ from diffsims.libraries.vector_library import DiffractionVectorLibrary from diffsims.utils.sim_utils import get_points_in_sphere -from diffsims.utils.sim_utils import simulate_rotated_structure from diffsims.utils.vector_utils import get_angle_cartesian_vec