seto77 / ReciPro

The software ReciPro makes various crystallographic calculations, visualizes a crystal structure, simulates a diffraction pattern and high-resolution TEM image, indexes diffraction spots, plots stereographic projection, and so on.
https://seto77.github.io/ReciPro/
Other
117 stars 13 forks source link

Question about fetching diffraction pattern from ReciPro in an automated way #36

Open OverEthanol opened 2 months ago

OverEthanol commented 2 months ago

Hi,

I am working on indexing of spot and Kikuchi patterns in transmission mode in a SEM using the technique called on-axis Transmission Kikuchi Diffraction (TKD). Given the low acceleration voltage in SEM, it is almost crucial that we use electron diffraction pattern simulated via dynamical electron diffraction.

Currently, there exist some Python packages that can perform the spot and Kikuchi patterns separately, however, not all of them have a built-in dynamical electron diffraction simulation. Therefore, I would like to ask, if it is possible that, given a list of crystal orientation defined in Euler angles, to feed the list of orientations into Recipro and obtain the corresponding diffraction pattern at the given acceleration voltage, detector distance, and size of the reciprocal space in an automated way?

Thank you for the help in advance and hope that you can help me out on this ^^

seto77 commented 2 months ago

I'm sorry for not getting back to you sooner.

ReciPro can output a pattern of electron diffraction spots based on a dynamical theory from any Euler angle. Of course, you can freely set the acceleration voltage, camera length, and output resolution.

image

Unfortunately, however, the Kikuchi line simulation only supports kinematical calculations. To treat the Kikuchi line dynamically, it is necessary to accurately treat the inelastic scattering process inside the specimen, which is a bit difficult.

I am currently working on the implementation of EBSD simulations. If that is successful, I will be able to handle TKD simulations soon. Please wait in anticipation.

OverEthanol commented 2 months ago

Thank you very much for the reply Seto san!

Yes I understand that ReciPro can take in a set of Euler angle and output the corresponding diffraction image given the camera length, electron wavelength, etc. However, my question is more on: Is it possible to automate such process?

For example, I wish to input a list of Euler angles, such as:

and save the diffraction image output (e.g. as a 2D gray-scale array with the same pixel grid as our detector grid) by ReciPro:

Do you think such thing is possible? And what could be some potential coding challenge related to it?

Or maybe this approach is inefficient and stupid, and some other approach can be better?

seto77 commented 2 months ago

ReciPro has a simple macro feature that allows you to write loops and conditionals in Python syntax.

image image

For example, the following macro may achieve what you want. (Please select a crystal to be calculated in advance.)

#Open the "Diffraction Simulator"
ReciPro.DifSim.Open()
#Set the wave source.
ReciPro.DifSim.Source_Electron()
#Set the intensity calculation mode.
ReciPro.DifSim.Calc_Dynamical()
#Set the Bloch wave number.
ReciPro.DifSim.NumberOfDiffractedWaves = 100
#Set the image size, resolution, and camera length.
ReciPro.DifSim.ImageWidth = 800
ReciPro.DifSim.ImageHeight = 800
ReciPro.DifSim.ImageResolutionInMM = 0.02
ReciPro.DifSim.CameraLength2 = 60

#Loop the Euler angle "phi" from -180° to 180° in 60° steps.
for phi in range(-180, 180, 60):
        #Loop the Euler angle "theta" from 0° to 180° in 60° steps.
        for theta in range (0, 180, 60):
                #Loop the Euler angle "psi" from -180° to 180° in 60° steps.
                for psi in range(-180, 180, 60):
                        #Set crystal orientation with loop variables phi, theta, and psi.
                        ReciPro.Dir.EulerInDegree(phi, theta, psi)
                        #Loop the "Thickness" from 10 nm to 40 nm in 10 nm steps.
                        for thickness in range (10, 40, 10):
                                ReciPro.DifSim.Thickness = thickness
                                #Set an appropriate file name and save the file in an appropriate location.
                                filename = 'd:/' + str(phi) + '_' + str(theta) + '_' + str(psi) +'_' + str(thickness) + '.png'
                                ReciPro.DifSim.SaveAsPng(filename)
#Reset the Euler angles.
ReciPro.Dir.EulerInDegree(0, 0, 0)

Smaller loop steps may cause an explosion in computation time. Adjust the steps carefully.

At this time, not all functions inside ReciPro can be called from the macro. It is easy to add them, so please do not hesitate to contact me.