# What are open source options to simulate kinematical electron diffraction patterns?

I tried using the python package diffsims. I get an image, but not a diffraction pattern I was expecting.

from matplotlib.colors import Normalize
import numpy as np
import matplotlib.pyplot as plt
import diffsims
import diffpy
import difflib
from diffpy import structure
from diffsims import generators

x='Si_mp_149_computed.cif'   #this file was generated using pymatgen, https://materialsproject.org/materials/mp-149/#
Beam=generators.diffraction_generator.DiffractionGenerator(accelerating_voltage=300)  #Instantiated an object in class Diffraction Generator
debye_waller_factors={})
dp= diffraction_pattern.get_diffraction_pattern(size=512, sigma=2)

plt.imshow(dp)
plt.show()

log_dp=np.log(dp)
plt.imshow(log_dp)
plt.show()


• Welcome to the site! I don't know much about simulating diffraction, but there may be some details about your example calculation that would help other users debug it. Do you have a reference diffraction pattern (experimental or simulated) to compare against? How did you choose the parameters for each function, e.g accelerating_voltage, max_excitation_error. Do you set the parameters for the plot anywhere else (or is there anything in this image outside the ~210-300)? Is the plot shown the log plot or just the returned values?
– Tyberius
Jun 5, 2021 at 18:28
• "not a diffraction pattern I was expecting": you mean the format (e.g. 2D heatmap while you wanted 1D plots) or the actual results of the computation?
– Hebo
Jun 7, 2021 at 7:40
• I was expecting spots around the central beam. I tried to display the image in both log scale and linear scale. Log scale should make it visually easy to see spots from the diffracted beams. This question would be relevant for someone who uses diffsims from the pyxem library, which is one of the python libraries for electron microscopy.
– Anya
Jun 16, 2021 at 18:18
• @Hebo does Anya's response help you to answer the question at all? Jun 28, 2021 at 2:48
• @NikeDattani Sadly not, I have too little experience with simulating diffraction patterns to go beyond easier format-related questions.
– Hebo
Jul 6, 2021 at 14:24

I tried to answer the question in the github issue github.com/pyxem/diffsims/issues/176

The reason it doesn't work is that the calibration parameter of the diffraction pattern is not set. A diffraction pattern in diffsims is represented by a list of (x, y) coordinates in projected reciprocal space, and an associated intensities I. Together they represent diffraction spots, and the main purpose of diffsims is to calculate I in these patterns depending on the microscope conditions (like sample orientation, acceleration voltage, ...) and create libraries of these simulated patterns for template matching (comparing to experimental data). A diffraction pattern can exist "etherially" in reciprocal space coordinates, but to convert them to an image one needs to know the size of a pixel in reciprocal space units. By default, this value is 1 (see https://github.com/pyxem/diffsims/blob/3c2540e520f7c8a6a60d24ec9b88844c4d2c8f83/diffsims/sims/diffraction_simulation.py#L50), meaning that 1 pixel will correspond to 1 angstrom^-1. You are thus creating a diffraction pattern image where all the diffraction spots are all blurred together in the center. In a sense, you just needs to "magnify" the diffraction pattern by setting a different calibration. Before the line

dp= diffraction_pattern.get_diffraction_pattern(size=512, sigma=2)


diffraction_pattern.calibration = #some other value representing the number of angstrom^-1 / pixel