.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/pdf_demo.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_pdf_demo.py: Pair distribution functions =========================== Calculate the pair distribution function G(r) with :func:`diffuse.pdf`: how a finite Q range adds termination ripples, and how X-rays and neutrons weight the atom pairs differently. To run it yourself, from the repository root:: DIFFUSE_PYTHON_PATH=build/python PYTHONPATH=python python3 python/examples/pdf_demo.py .. GENERATED FROM PYTHON SOURCE LINES 13-21 .. code-block:: Python from pathlib import Path import matplotlib.pyplot as plt import diffuse as dc .. GENERATED FROM PYTHON SOURCE LINES 28-33 Nickel: the effect of a finite Q range -------------------------------------- ``qmax=0`` gives the PDF of an ideal measurement. A real one stops at some Qmax, which adds ripples around each peak; ``qdamp`` describes the instrument resolution, which damps the peaks at large r. .. GENERATED FROM PYTHON SOURCE LINES 33-43 .. code-block:: Python nickel = dc.read_structure(HERE / "nickel.cell") ideal = dc.pdf(nickel, rmax=20, dr=0.01) measured = dc.pdf(nickel, rmax=20, dr=0.01, qmax=20, qdamp=0.04) ax = ideal.plot(label="ideal (no Qmax)") measured.plot(ax=ax, label="Qmax = 20 Å⁻¹, Qdamp = 0.04 Å⁻¹") ax.set_title("Nickel (fcc)") ax.legend() .. image-sg:: /gallery/images/sphx_glr_pdf_demo_001.png :alt: Nickel (fcc) :srcset: /gallery/images/sphx_glr_pdf_demo_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-45 The first peak sits at the nearest-neighbour distance a/√2: .. GENERATED FROM PYTHON SOURCE LINES 45-49 .. code-block:: Python first = ideal.r[(ideal.G * (ideal.r < 3)).argmax()] print(f"first peak at r = {first:.3f} Å, a/√2 = {nickel.a / 2**0.5:.3f} Å") .. rst-class:: sphx-glr-script-out .. code-block:: none first peak at r = 2.490 Å, a/√2 = 2.491 Å .. GENERATED FROM PYTHON SOURCE LINES 50-55 Anatase: X-rays and neutrons ---------------------------- Each atom pair is weighted by the scattering power of its two atoms. Titanium dominates for X-rays; for neutrons its scattering length is negative, so Ti–O peaks point down. .. GENERATED FROM PYTHON SOURCE LINES 55-67 .. code-block:: Python anatase = dc.read_structure(HERE / "anatase.cif") xray = dc.pdf(anatase, rmax=10, dr=0.01, qmax=25, radiation="xray") neutron = dc.pdf(anatase, rmax=10, dr=0.01, qmax=25, radiation="neutron") fig, ax = plt.subplots(figsize=(8, 4.5)) xray.plot(ax=ax, label="X-ray") neutron.plot(ax=ax, label="neutron") ax.set_title("Anatase (TiO₂)") ax.legend() plt.show() .. image-sg:: /gallery/images/sphx_glr_pdf_demo_002.png :alt: Anatase (TiO₂) :srcset: /gallery/images/sphx_glr_pdf_demo_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.212 seconds) .. _sphx_glr_download_gallery_pdf_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pdf_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pdf_demo.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pdf_demo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_