.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/materials/crystals/plot_01_bragg_diffraction.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_materials_crystals_plot_01_bragg_diffraction.py: The Braggs' law of X-ray diffraction (1913) =========================================== Laue showed in 1912 that crystals diffract X-rays. William Lawrence Bragg, a research student at Cambridge, read the spots as reflections from planes of atoms: waves reflected by neighbouring planes a distance :math:`d` apart reinforce when their path difference is a whole number of wavelengths, .. math:: n\lambda = 2d\sin\theta (:func:`~engineeringkit.materials.bragg_angle`). With his father's X-ray spectrometer it turned diffraction into a way of measuring crystals. The example builds the powder pattern of BCC iron and FCC copper (:func:`~engineeringkit.materials.diffraction_peaks`), reads the lattice parameter back from a peak, and checks the density it implies. .. GENERATED FROM PYTHON SOURCE LINES 20-32 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.materials import ( atomic_packing_factor, bragg_angle, cubic_lattice_parameter, diffraction_peaks, interplanar_spacing, theoretical_density, ) .. GENERATED FROM PYTHON SOURCE LINES 33-39 One reflection of iron ---------------------- Iron is BCC with :math:`a = 0.2866` nm. With cobalt radiation (:math:`\lambda = 0.1790` nm) the (220) planes, :math:`d = a/\sqrt8`, reflect at :math:`2\theta \approx 124°`. .. GENERATED FROM PYTHON SOURCE LINES 39-46 .. code-block:: Python a_Fe, wavelength = 0.2866e-9, 0.1790e-9 d220 = interplanar_spacing(a_Fe, 2, 2, 0) theta = bragg_angle(d220, wavelength) print(f"d(220) = {d220 * 1e9:.4f} nm, 2 theta = {np.degrees(2 * theta):.2f} deg") assert np.isclose(wavelength, 2 * d220 * np.sin(theta)) .. rst-class:: sphx-glr-script-out .. code-block:: none d(220) = 0.1013 nm, 2 theta = 124.08 deg .. GENERATED FROM PYTHON SOURCE LINES 47-54 Powder patterns and the missing peaks ------------------------------------- In a BCC cell the atom at the body centre scatters exactly out of phase from the (100) planes, so only planes with :math:`h + k + l` even reflect. In FCC the indices must be all odd or all even. The sequence of peaks therefore identifies the structure. .. GENERATED FROM PYTHON SOURCE LINES 54-71 .. code-block:: Python copper_a, Cu_Ka = 0.3615e-9, 0.1542e-9 fe_planes, fe_two_theta = diffraction_peaks(a_Fe, Cu_Ka, "bcc") cu_planes, cu_two_theta = diffraction_peaks(copper_a, Cu_Ka, "fcc") for name, planes in (("iron (BCC)", fe_planes), ("copper (FCC)", cu_planes)): print(name, ["".join(map(str, p)) for p in planes[:5]]) assert fe_planes[0].tolist() == [1, 1, 0] and cu_planes[0].tolist() == [1, 1, 1] fig, axs = plt.subplots(2, 1, figsize=(6.5, 4.2), sharex=True) for ax, planes, angles, name in ((axs[0], fe_planes, fe_two_theta, "iron, BCC"), (axs[1], cu_planes, cu_two_theta, "copper, FCC")): ax.vlines(np.degrees(angles), 0, 1) for p, t in zip(planes, angles): ax.text(np.degrees(t), 1.05, "".join(map(str, p)), ha="center", fontsize=8) ax.set(ylim=(0, 1.3), yticks=[], ylabel=name) axs[1].set_xlabel("2 theta [deg], Cu K-alpha") fig.tight_layout() .. image-sg:: /api/gallery/materials/crystals/images/sphx_glr_plot_01_bragg_diffraction_001.png :alt: plot 01 bragg diffraction :srcset: /api/gallery/materials/crystals/images/sphx_glr_plot_01_bragg_diffraction_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none iron (BCC) ['110', '200', '211', '220', '310'] copper (FCC) ['111', '200', '220', '311', '222'] .. GENERATED FROM PYTHON SOURCE LINES 72-78 From a peak back to the density ------------------------------- Reading the first copper peak back through Bragg's law gives the lattice parameter; four atoms of 63.55 g/mol in that cube give the density, and the hard-sphere radius gives the FCC packing factor of 0.74. .. GENERATED FROM PYTHON SOURCE LINES 78-88 .. code-block:: Python d111 = Cu_Ka / (2 * np.sin(cu_two_theta[0] / 2)) a_measured = d111 * np.sqrt(3) rho = theoretical_density(4, 63.55e-3, a_measured**3) radius = a_measured / (2 * np.sqrt(2)) print(f"a = {a_measured * 1e9:.4f} nm, R = {radius * 1e9:.4f} nm, density {rho:.0f} kg/m^3, APF {atomic_packing_factor('fcc'):.3f}") assert np.isclose(cubic_lattice_parameter(radius, "fcc"), copper_a) assert abs(rho - 8960) / 8960 < 0.01 plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none a = 0.3615 nm, R = 0.1278 nm, density 8935 kg/m^3, APF 0.740 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.056 seconds) .. _sphx_glr_download_api_gallery_materials_crystals_plot_01_bragg_diffraction.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/materials/crystals/plot_01_bragg_diffraction.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_bragg_diffraction.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_bragg_diffraction.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_bragg_diffraction.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_