Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/instamatic-tem-emulator/simulation/crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import numpy as np
from diffpy import structure as diffpy
from diffsims.crystallography._diffracting_vector import DiffractingVector
from diffsims.generators.simulation_generator import Simulation2D, SimulationGenerator
from orix.crystal_map import Phase
from orix.quaternion import Rotation
Expand Down Expand Up @@ -65,11 +64,6 @@ def __init__(
lattice=self.lattice,
)
self.phase = Phase(space_group=space_group, structure=self.structure)
# self.recip = DiffractingVector.from_min_dspacing(
# self.phase,
# min_dspacing=1,
# include_zero_vector=False,
# ) raises exception to use ReciprocalLatticeVector instead - version 0.7.0 issue?
self.recip = Vector3D.from_min_dspacing(
self.phase,
min_dspacing=1,
Expand Down Expand Up @@ -161,7 +155,7 @@ def reciprocal_space_lattice(self, d_min: float) -> np.ndarray:
vecs = self.lattice.reciprocal().cartesian(hkls)
return vecs

def diffraction_pattern_mask(
def diffraction_pattern(
self,
shape: tuple[int, int],
d_min: float,
Expand Down Expand Up @@ -201,10 +195,27 @@ def diffraction_pattern_mask(
max_excitation_error = excitation_error

rotation = Rotation.from_matrix(rotation_matrix)
from diffsims.generators.simulation_generator import (
Vector3d,
get_intersection_with_ewalds_sphere,
)
try:
from diffsims.generators.simulation_generator import (
Vector3d,
get_intersection_with_ewalds_sphere,
)
except ImportError:
sim = gen.calculate_diffraction2d(
phase=self.phase,
rotation=rotation,
reciprocal_radius=1 / d_min,
with_direct_beam=False,
max_excitation_error=max_excitation_error,
)
pattern = sim.get_diffraction_pattern(
shape=shape,
sigma=1,
calibration=1 / d_min / (shape[0] / 2),
)
return pattern * intensity_scale

# code below only works with https://github.com/pyxem/diffsims/pull/232
optical_axis = rotation * Vector3d.zvector()

# Calculate the reciprocal lattice vectors that intersect the Ewald sphere.
Expand Down
2 changes: 1 addition & 1 deletion src/instamatic-tem-emulator/simulation/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def get_diffraction_pattern(
# Crystal is completely on the grid
continue

reflections += self.crystals[sample.crystal_index].diffraction_pattern_mask(
reflections += self.crystals[sample.crystal_index].diffraction_pattern(
shape,
d_min=d_min,
rotation_matrix=self.rotation_matrix @ sample.rotation_matrix,
Expand Down