ABSTRACT (original article): To exploit the information contained in 2D X-ray diffractograms fully, quantitatively, automatically, and with high throughput, e.g. for analyzing video sequences from in-situ experiments, we can train deep learning NNs (neural networks) with simulated diffractograms. Realistic models of materials microstructures require ‘‘ground truth’’ training datasets of high cardinality. To produce these, we developed a ‘‘kinematic diffraction simulator’’, implemented in the Wolfram Language and executed within a high-performance computing environment. The simulator can rapidly generate Fraunhofer diffractograms for diverse crystal- and microstructure models over a significant multi-dimensional space of parameters. We conclude that simulated diffractograms can enable suitable training of deep-learning NNs– in spite of not including some ‘‘real-world’’ features that occur in experimental diffractograms– and that high-performance computing achieves training data generation rates that support modeling of microstructures with a realistically large number of parameters. CITATION (original article): Mehdi, R., Chawla, R., Barcelos, E. I., Willard, M. A., French, R. H., & Ernst, F. (2025). 2D-diffractogram analysis: Kinematic-diffraction simulator for neural-network training-data generation. In Computational Materials Science (Vol. 252, p. 113777). Elsevier BV. DOI: https://doi.org/10.1016/j.commatsci.2025.113777​
​GitHub
Settings

X-Ray Diffractometry

X-Ray Atom Form Factors

Different atoms diffract X-rays with different efficacy or “diffraction amplitude.” Moreover, the diffraction amplitude depends on the angle into which diffraction is being considered. The amplitude falls off with increasing angle because portions of the wave diffracted from different regions around the exact atom position interfere destructively. The smaller the atom, the more quickly is the fall-off.
The dependency of the diffraction amplitude on the atomic number and the diffraction angle is generally known and tabulated in the form of 4 superimposed Gauß distributions plus one constant. The data are contained in the next section.

Form Factor Data

https://bit.ly/3X2X1I1
lXFFData=
;

X-Ray Form Factor

The length
gNM
of the diffraction vector g is expected in
-1
nm
.
Call rXFF like this:
rXFF[lXFFData["Cu"],||g||]
.
In[]:=
rXFF[lc9_,gNM_]:=Module{ff,gAng,i},​​gAng=
gNM
10
;​​ff=0;​​Fori=0,i<4,i++,​​ff+=lc92i+1Exp-lc92i+2
2
gAng
4π
;​​ff+=lc99;​​Return[ff]

Example


Form Intensity Factor for Cubic Systems


Debye–Waller Factors

Atoms in crystals are not at rest. They oscillate about equilibrium positions. The frequency and amplitude of the oscillation depends on the mass
m
of the atom, the bonding forces from its environment, and the absolute temperature
T
. Generally, the oscillation magnitude and frequency will be anisotropic, i.e. vary with crystallographic direction.
Compared to a hypothetical diffraction pattern obtained with atoms at rest, the disorder that an X-ray photon gets to see (as a “frozen phonon” snapshot) owing to the oscillation of atoms in real crystals leads to an attenuation of diffracted-beam intensities and a diffuse background. The effect is more pronounced for larger diffraction angles / smaller plane spacings because the attenuation of a diffracted beam with increasing deviation (“excitation error”) from the diffraction condition is more pronounced the higher the order of the diffracted beam. The higher the order, i.e. the smaller the plane spacing, the smaller will be the “allowable” deviation from the exact diffraction (Bragg) condition.
The amplitude (not: intensity) of the diffracted beam is weakened by a factor
Exp[-M]<1
, known as the Debye–Waller Factor. Generally, this factor can be generally introduced by replacing the atom-form factor
f[q]
by
0
f
[q]Exp[-M]
, where
0
f
[q]
is the atom-form factor absent vibration. The attenuation factor is known as the Debye–Waller factor. It has the form
Exp[-M]
, where
M=
1
2
2
(2πg)

2
u
g
=2
2
2
π
2
Sin[θ]
λ

2
u
g
=:B
2
Sin[θ]
λ
. (Your
2π
-s may vary. The form after the first equation sign is based on defining the wave number of the primary wave as
k
0
=
1
λ
, not
2π
λ
. The former is popular in crystallography, the latter is popular in solid-state physics.)
g
is the norm (with dimension of reciprocal length) of the diffraction vector
g
.

2
u
g

is the mean square of the displacement
u
g
in the direction of
g
. Under the simplifying assumption of isotropic oscillation, only
1
3
of the oscillation amplitude is (on the average) out of plane. Then,
M=
2
3
2
π
2
g

2
u

.
B
is known as temperature factor or Debye Parameter and – sometimes – get this – also as the Debye–Waller Factor.
Since
u
depends not only on the mass, but also on the bonding environment of the atom, there is no general, unique way to assign Debye–Waller factors to each atom species.
A further simplifying assumption is that the oscillation is harmonic, meaning that there is a linear force law and the potential energy of the oscillating atom depends in a parabolic way on the distance from the oscillation center. (If this were actually true, there would be no thermal expansion.) At low temperature, i.e. when
T<
θ
D
, where
θ
D
is the Debye temperature, part of the atom oscillators may be frozen. At
T>
θ
D
, all atoms oscillate.
The total energy
E
of a harmonic oscillator equals the maximum potential energy,
E=
D
2
2
u
0
, where
D
is the spring constant (bonding force). By the law of equi-partition, the total energy also equals
3
2
k
B
T
, where
k
B
is the Boltzmann Constant. So, the magnitude
u
0
(maximum absolute amplitude) of the oscillation will be proportional to
E
=
3
2
k
B
T
∝
T
. For a sinusoidal oscillation
u[t]=
u
0
Sin[ωt]
, the mean square amplitude is

2
u
=
2
u
0
2
. So,

2
u
∝T
.
Further, the total energy
E
of a harmonic oscillator is proportional to the mass
m
. For a fixed total energy, therefore,
2
u
0
∝
1
m
. Thus,
M=
2
3
2
π
2
g

2
u

can be written as
M=β
T
m
·
2
g
, where β is a parameter that represents the level of (harmonic) bonding forces acting on the considered atom in its specific position within the crystal structure. Evaluating values for the Debye–Waller Factor of the same atom species bonded to different bonding partners in different coordination may provide data for the variation of bonding forces.

Debye–Waller Factor Data


Debye–Waller Factor


Primary Beam

Primary beam wavelength, in units of nm.
In[]:=
rLambda=0.0178331;

Wave Number and Wave Vector

Wave number in units of
-1
nm
.
No factor 2π (we use the definition that is popular in crystallography). The wave vector is aligned with the z-axis of the coordinate system.
In[]:=
rK0=
1
rLambda
;​​lK0={0,0,rK0};

Polychromaticity

Assumption: Primary photon energy follows normal distribution.
Photons:p==
e
c
=hk,sok==
e
hc
.
Normal distribution of energy implies normal distribution of wave number.

Standard Deviation of Wave Number Distribution


Diffraction Geometry

Detector Size – Maximum Angle

Maximum scattering angle captured by the pattern.
In[]:=
rAngMax=0.6Degree;

Excitation Error

This section is currently not actively being used.
Angle between vector
{
v
1
,
v
2
,
v
3
} and [001]: ArcCos[]
In[]:=
rBAng[g_List,a0_,λ_]:=ArcSin
λ
2a0
Plus@@
2
#
&/@g

In[]:=
Plot{2.5PDF[NormalDistribution[],x],
2
Sinc[x]
},{x,-10,10},PlotRange->Full

Diffracted Intensity

Reflection

For the given primary wave vector lK0 and a given plane normal or diffraction vector lS with some length and some orientation, calculate the outgoing wave vector lK, the angle r2Theta it makes with lK0, the excitation error, the x-y coordinates of the q-vector in the x-y-plane, and the intensity factor rFI. To do this, the function evaluates the distance of the rotated hkl plane normal from the Ewald sphere. From the distance, the intensity factor rFF related to the atom-form factor and the intensity factor rFI related to the non-monochromaticity (wavelength spread) is obtained via function rFE. Further, the coordinates of the corresponding q in the diffraction plane are calculated for later use.
In[]:=
aDiff[aGI_,lK0_]:=Module{lK,rEE,r2Theta,lXY,rFI},​​lK=lK0+aGI["lGhklR"];​​r2Theta=VectorAngle[lK,lK0];​​rEE=Abs[Norm[lK]-Norm[lK0]];​​lXY=
1
Cos[r2Theta]
{aGI["lGhklR"]〚1〛,aGI["lGhklR"]〚2〛};​​rFI=rFE[rEE]aGI["rFI"];​​Return[<|"lK"->lK,"lXY"->lXY,"rFI"->rFI|>]
Phases and Structures
◼
Unit Cells
From an abstract point of view, a crystal is a periodic repetition of a fixed “motif” in space. The motif can be a single atom or a group of atoms. Important is that this motif is attached to every lattice point in the same way – in the same relative position to the lattice point (not necessarily on the lattice point) and in the same orientation. Owing to translation symmetry, the crystal structure is fully defined by specifying one repeat unit, which is called a unit cell. As mentioned, there are many possible valid choices for the crystal lattice and, correspondingly, for the unit cell. A valid specification must include the fundamental translations
g
i
that span the unit cell, the locations of the lattice points that the cell includes (e.g. 4 lattice points in the case of an FCC lattice), and information on the basis to be attached to every lattice point. (Mathematically, the crystal structure corresponds to a convolution of the lattice with the basis). Specifications of the bases must include the type of each constituent atom and its location relative to the lattice point.
◼
Diffracted Beams – or Reflections
The following theory is detailed at https://bit.ly/EMSE-228 (Case VPN!), specifically https://bit.ly/3IDHN8.
When the Bragg Condition is fulfilled, sets of (equally spaced) lattice planes can reflect the primary beam like semi-permeable mirrors. Each set of lattice planes in the crystal lattice is designated by a vector normal to the planes. By definition, the length of the normal vector is chosen to be the inverse of the respective lattice plane spacing. The entirety of all such-defined plane normals forms a lattice! This is the lattice of plane normals,
p
L
. It is generally different from the “ordinary” lattice that describes translation symmetry and crystallographic directions, which we will, for distinction, from now on call the lattice of directions,
L
d
.
◼
  • Choice 1: The smallest unit cell that exhibits the full point symmetry of the crystal structure. To exhibit that symmetry, it may be necessary that the unit cell includes several lattice points.
  • ◼
  • Choice 2: A “primitive” unit cell: a cell with the smallest possible volume. Cap this implies that a primitive of unit cell includes only one lattice point.
  • ◼
    Unit-Cell Diffracted-Beam Amplitude – “Structure Factor”

    Structure Factor – Implementation

    ◼
  • The same list of index sets that was input as “lHKLs”.
  • ◼
  • The real value of the X-ray form factor as "rFF."
  • ◼
  • The complex-valued structure factor as "cSF," which includes the form factor and the Debye-Waller Factors as factors.
  • Microstructure

    Random Orientations

    Random Unit Vector

    Imagine a uniform random distribution of points over the surface of the earth, idealized as a sphere. Their longitudes ϕ will be equally distributed. However, the latitudes will not be equally distributed. They will be distributed proportionally to Cos[θ]. Based on this insight, the following function produces randomly oriented unit vectors with uniform distribution.

    Random Orientation

    Cartesian frames with uniformly distributed random orientations can be produced by generating two independent random unit vectors and taking cross products thereof.

    Grain Size Distribution

    A better model, which e.g. fits empirically to grain sizes in sand, is a Weibull distribution.
    Define grain-size-related intensity factor.
    Show typical values.
    Diffraction Simulation

    Graphics

    Pixel Resolution

    To place the origin on a pixel and facilitate inversion symmetry, the dimension of the field of view is an odd number. Beam convergence is modeled by convoluting with a Gauß matrix. However, this operation shrinks the pixel dimensions of the resulting pattern by the mask dimension mDim. Therefore, we first determine mDim, then choose a correspondingly larger iDim, so that the author resulting image is the desired dimension.

    Field of View

    Assign pixel to a vector q.

    CITE THIS NOTEBOOK

    2D-diffractogram analysis: Kinematic-diffraction simulator for neural-network training-data generation​
    by Redad Mehdi, Rounak Chawla, Erika I. Barcelos, Matthew A. Willard, Roger H. French & Frank Ernst
    Wolfram Community, STAFF PICKS, March 5, 2025
    ​https://community.wolfram.com/groups/-/m/t/3412145