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/#
s= structure.loadStructure(x)
Beam=generators.diffraction_generator.DiffractionGenerator(accelerating_voltage=300)  #Instantiated an object in class Diffraction Generator
diffraction_pattern=Beam.calculate_ed_data(structure=s,reciprocal_radius =15, rotation=(0,0,0),with_direct_beam=False,max_excitation_error=0.01, \
dp= diffraction_pattern.get_diffraction_pattern(size=512, sigma=2)



Result from code

  • 1
    $\begingroup$ 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? $\endgroup$
    – Tyberius
    Jun 5 at 18:28
  • $\begingroup$ "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? $\endgroup$
    – Hebo
    Jun 7 at 7:40
  • $\begingroup$ 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. $\endgroup$
    – Anya
    Jun 16 at 18:18
  • $\begingroup$ @Hebo does Anya's response help you to answer the question at all? $\endgroup$ Jun 28 at 2:48
  • $\begingroup$ @NikeDattani Sadly not, I have too little experience with simulating diffraction patterns to go beyond easier format-related questions. $\endgroup$
    – Hebo
    Jul 6 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)

you should add a line

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

Hope this helps.

Also an important note: since diffraction patterns in diffsims are essentially a structured point cloud, an unprocessed pattern is basically a zero image with some bright pixels. When we collect real diffraction patterns in the microscope, spots have a finite size due to imperfect optics, thermal vibrations, finite sample and beam size, dynamic diffraction,... All these effects are not considered in diffsims, it only uses the kinematical approximation. To make the pattern appear more like experimental patterns, the bright pixels are simply blurred with a 2D gaussian. This is not representative of a physical process and just serves as a sanity check when judging the patterns.

  • 1
    $\begingroup$ Welcome to the site and thank you for adding an answer! Do you mind editing this post to include/quote the answer from the link or summarize the main points? Its unlikely, but we want to avoid a case where a link goes dead and an answer disappears. $\endgroup$
    – Tyberius
    Sep 22 at 1:40
  • $\begingroup$ Welcome to the Matter Modeling community! Thank you so much for writing an answer here :) I totally agree with @Tyberius that it would be helpful to answer the question here, since the GitHub was just a link to this question, which I posted myself. The original user that asked the question might not see it on GitHub. I see no harm in having the answer in both places, but if it's only on GitHub than the original asker might not see it. $\endgroup$ Sep 22 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.