Powder patterns of anatase#

Read a CIF file, let DISCUS build a supercell, calculate X-ray and neutron powder patterns with the Debye equation, and plot them with matplotlib.

The structure is anatase (TiO2), COD entry 1010942 (python/examples/anatase.cif).

To run it yourself, from the repository root:

DIFFUSE_PYTHON_PATH=build/python PYTHONPATH=python python3 python/examples/powder_demo.py
from pathlib import Path

import matplotlib.pyplot as plt

import diffuse as dc

CIF = HERE / "anatase.cif"

Read the structure#

A CIF file holds the asymmetric unit. DISCUS applies the space group (I41/amd) and builds 10 x 10 x 4 unit cells.

crystal = dc.read_structure(CIF, supercell=(10, 10, 4))
print(crystal)
Crystal('anatase.cif', supercell=(10, 10, 4), natoms=4800, lattice=(3.73, 3.73, 9.37, 90, 90, 90))

Calculate powder patterns#

The results are NumPy arrays (q and intensity), so any plotting or analysis library can use them.

xray = dc.powder(crystal, qmin=0.5, qmax=10, dq=0.005, radiation="xray")
neutron = dc.powder(crystal, qmin=0.5, qmax=10, dq=0.005, radiation="neutron")
print(f"{len(xray.q)} points from Q = {xray.q[0]} to {xray.q[-1]} Å⁻¹")
1901 points from Q = 0.5 to 10.0 Å⁻¹

A much smaller crystal of the same structure shows how the crystal size broadens the peaks.

small = dc.read_structure(CIF, supercell=(3, 3, 1))
xray_small = dc.powder(small, qmin=0.5, qmax=10, dq=0.005, radiation="xray")

Plot#

X-rays see mostly titanium; neutrons see oxygen much more strongly, so the relative peak heights change.

fig, (top, bottom) = plt.subplots(2, 1, figsize=(9, 7), sharex=True,
                                  constrained_layout=True)
top.plot(xray.q, xray.intensity / xray.intensity.max(), lw=1, label="X-ray")
top.plot(neutron.q, neutron.intensity / neutron.intensity.max(), lw=1, label="neutron")
top.set_title(f"Anatase, 10×10×4 unit cells ({crystal.natoms} atoms)")
top.set_ylabel("Intensity (normalised)")
top.legend()

for p, label in ((xray, f"{crystal.natoms} atoms"), (xray_small, f"{small.natoms} atoms")):
    bottom.plot(p.q, p.intensity / p.intensity.max(), lw=1, label=label)
bottom.set_title("X-ray: crystal size broadens the peaks")
bottom.set_xlabel(r"$Q$ (Å$^{-1}$)")
bottom.set_ylabel("Intensity (normalised)")
bottom.set_xlim(xray.q[0], xray.q[-1])
bottom.legend()

plt.show()
Anatase, 10×10×4 unit cells (4800 atoms), X-ray: crystal size broadens the peaks

Total running time of the script: (0 minutes 0.199 seconds)

Gallery generated by Sphinx-Gallery