projects / TEM diffraction calculator

TEM diffraction calculator

◆ completed 2020 python, pymatgen, numpy visit site ↗ github ↗
simulated diffraction pattern

pymatgen’s TEM module simulates selected-area electron diffraction. Give it a crystal structure and a beam direction, and it returns the spot pattern a microscopist would see, with interplanar spacings, structure factors, and hkl labels.

Background

Selected-area electron diffraction is the standard way to identify a crystal structure inside a transmission electron microscope. A parallel electron beam passes through a thin crystal, the periodic lattice scatters it, and the back focal plane of the objective lens shows a pattern of sharp spots. Each spot comes from a family of lattice planes satisfying Bragg’s law, which reads

nλ=2dsinθn\lambda = 2d\sin\theta

where λ\lambda is the electron wavelength, dd is the interplanar spacing, θ\theta is the scattering half-angle, and nn is the diffraction order. At a typical operating voltage of 200 kV the relativistically corrected electron wavelength is about 2.5 pm, two orders of magnitude smaller than typical interplanar spacings. Bragg angles are therefore tiny, and the Ewald sphere, whose radius is the reciprocal of the wavelength, is nearly flat on the scale of the reciprocal lattice. A whole plane of reciprocal-lattice points diffracts at once, which is why a single orientation yields dozens of spots. When the beam runs along a zone axis [uvw][uvw], the visible reflections (hkl)(hkl) obey the zone-axis rule hu+kv+lw=0hu + kv + lw = 0, and the brightness of each spot follows from the structure factor, written as

Fhkl=jfje2πi(hxj+kyj+lzj)F_{hkl} = \sum_j f_j \, e^{2\pi i (h x_j + k y_j + l z_j)}

where the sum runs over the atoms in the unit cell, fjf_j is the electron scattering factor of atom jj, and (xj,yj,zj)(x_j, y_j, z_j) are its fractional coordinates. When the phase factors cancel, the structure factor vanishes and the reflection is systematically absent, so the pattern of missing spots encodes the symmetry of the crystal. The calculator implements this kinematical picture. It enumerates the reciprocal-lattice points allowed by the zone-axis rule, computes their spacings and structure factors, and projects them onto the detector plane.

Implementation

Getting it merged involved refactoring the interplanar-spacing code onto pymatgen’s lattice utilities, so spacings come from the general lattice method instead of per-crystal-system formulas, vectorizing pattern generation with NumPy in place of nested Python loops, correcting structure factors against standard crystallography tables, and fixing a bug that blanked the (110) family of beam directions. The refactor also swapped the tabular output to pandas DataFrames and reduced each diffraction spot to a lightweight named tuple.

Validation

Before merge I validated the calculator against 600+ diffraction patterns with randomized beam directions on Materials Project iron-oxide structures, prompted by a reviewer’s request to test beyond high-symmetry orientations. All directions produced valid patterns, including the degenerate near-linear ones that certain beam directions are expected to give. Results were also checked against published reference patterns.

Research use

The research project behind the module also ran it at scale, generating 1,770 simulated patterns of X-Fe-O structures and clustering them with t-SNE on CNN-extracted features, where the substituent element left a visible fingerprint but space-group symmetry did not separate.

Outcome

The module ships in pymatgen’s diffraction package, and I am listed as a project developer on the pymatgen team page. The pattern above is its output for silicon down the [110] zone axis.