.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/fourier_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_fourier_demo.py: Single-crystal diffraction and diffuse scattering ================================================= Calculate intensities on planes in reciprocal space with :func:`diffuse.fourier`, for an ordered crystal (anatase) and for a Cu/Au layer with short-range order, where removing the average structure leaves the diffuse scattering. To run it yourself, from the repository root:: DIFFUSE_PYTHON_PATH=build/python PYTHONPATH=python python3 python/examples/fourier_demo.py .. GENERATED FROM PYTHON SOURCE LINES 14-22 .. code-block:: Python from pathlib import Path import matplotlib.pyplot as plt import diffuse as dc .. GENERATED FROM PYTHON SOURCE LINES 29-34 Bragg peaks of an ordered crystal --------------------------------- The hk0 plane of anatase (I4\ :sub:`1`/amd), 8 x 8 x 4 unit cells. The corners give the plane in reciprocal-lattice units: ``ll`` lower left, ``lr`` lower right, ``ul`` upper left. .. GENERATED FROM PYTHON SOURCE LINES 34-42 .. code-block:: Python anatase = dc.read_structure(HERE / "anatase.cif", supercell=(8, 8, 4)) hk0 = dc.fourier(anatase, ll=(-4, -4, 0), lr=(4, -4, 0), ul=(-4, 4, 0), npoints=(321, 321), radiation="xray") ax = hk0.plot(log=True, cmap="magma") ax.set_title("Anatase, hk0 plane (X-rays, log scale)") ax.set_aspect("equal") .. image-sg:: /gallery/images/sphx_glr_fourier_demo_001.png :alt: Anatase, hk0 plane (X-rays, log scale) :srcset: /gallery/images/sphx_glr_fourier_demo_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 43-46 The result is a NumPy array plus its reciprocal-space coordinates, so you can work with it directly, for example to find the strongest reflection apart from the origin: .. GENERATED FROM PYTHON SOURCE LINES 46-54 .. code-block:: Python import numpy as np hkl = hk0.hkl() # shape (321, 321, 3) away = np.linalg.norm(hkl, axis=-1) > 0.5 # leave out 000 i, j = np.unravel_index(np.where(away, hk0.intensity, 0).argmax(), hk0.intensity.shape) print("strongest reflection:", hkl[i, j].round(3)) .. rst-class:: sphx-glr-script-out .. code-block:: none strongest reflection: [-2. 0. 0.] .. GENERATED FROM PYTHON SOURCE LINES 55-63 Diffuse scattering of a disordered layer ---------------------------------------- A single layer of 50 x 50 cells, occupied by Cu and about 35 % Au. The Au atoms cluster: a neighbour of an Au atom is more likely to be Au than the average composition says (short-range order). The total scattering is dominated by the Bragg peaks of the average structure; ``subtract_average=100`` removes them and leaves the diffuse scattering. Because like atoms cluster, it gathers around the Bragg positions. .. GENERATED FROM PYTHON SOURCE LINES 63-78 .. code-block:: Python layer = dc.read_structure(HERE / "cuau_layer.stru") plane = dict(ll=(0, 0, 0), lr=(3, 0, 0), ul=(0, 3, 0), npoints=(241, 241)) total = dc.fourier(layer, **plane) diffuse = dc.fourier(layer, subtract_average=100, **plane) fig, (left, right) = plt.subplots(1, 2, figsize=(11, 4.6), constrained_layout=True) total.plot(ax=left, log=True, cmap="magma") left.set_title("Total scattering (log scale)") diffuse.plot(ax=right, cmap="magma") right.set_title("Diffuse scattering (average removed)") for ax in (left, right): ax.set_aspect("equal") plt.show() .. image-sg:: /gallery/images/sphx_glr_fourier_demo_002.png :alt: Total scattering (log scale), Diffuse scattering (average removed) :srcset: /gallery/images/sphx_glr_fourier_demo_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.190 seconds) .. _sphx_glr_download_gallery_fourier_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: fourier_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: fourier_demo.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: fourier_demo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_