.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/analytical/scattering.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_analytical_scattering.py: Scattering Example: Percus Yevick Structure Factor and Phase Function ===================================================================== Example of Percus Yevick structure factor computation for a polydisperse mixture and corresponding phase function calculation. .. GENERATED FROM PYTHON SOURCE LINES 9-66 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from PackLab import analytical, samplers, scattering from PackLab.units import ureg sampler = samplers.NormalRadiusSampler( mean=100 * ureg.nanometer, standard_deviation=10 * ureg.nanometer, bins=10 ) particle_radii, number_fractions = sampler.to_bins() py_domain = analytical.PercusYevickDomain( size=100 * ureg.micrometer, radii=particle_radii, volume_fraction=0.24, number_fractions=number_fractions, ) py_domain.print_bins() distances = np.linspace( py_domain.radii.min() * 2, py_domain.radii.max() * 10, 400, ) solver = analytical.PercusYevickSolver( densities=py_domain.particle_densities_per_radius, radii=py_domain.radii, wavenumber="auto", ) py_result = solver.compute(distances=distances) fig, ax = plt.subplots(1, 1, figsize=(12, 8)) K = len(particle_radii) for i in range(K): for j in range(K): _ = ax.plot( py_result.distances.to("micrometer"), py_result.g[i, j], linewidth=1.5, label=f"{i}-{j}", ) ax.set_xlabel("r") ax.set_ylabel(r"$g_{ij}(r)$") ax.set_title("Partial pair correlation: RSA vs Percus Yevick") _ = ax.legend() plt.show() .. image-sg:: /gallery/analytical/images/sphx_glr_scattering_001.png :alt: Partial pair correlation: RSA vs Percus Yevick :srcset: /gallery/analytical/images/sphx_glr_scattering_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 67-69 Calculate and plot the scattering phase function ------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 69-98 .. code-block:: Python datas = scattering.compute_scattering_amplitudes( wavelength=150 * ureg.nanometer, diameters=py_result.radii, material=1.45, medium=1.0, phi=np.linspace(-np.pi / 2, np.pi / 2, 400) * ureg.radian, polarization=0 * ureg.degree, ) datas.process() phi, theta, phase_function = datas.get_phase_function( densities=py_result.densities, H=py_result.H, wavenumber=py_result.wavenumber, theta_points=150 ) _ = scattering.plottings.plot_phase_function_3d( phi=phi, theta=theta, phase_function=phase_function.to('1 / meter').magnitude, mode="spherical" ) plt.show() .. image-sg:: /gallery/analytical/images/sphx_glr_scattering_002.png :alt: Phase function mapped on sphere (radius proportional to P) :srcset: /gallery/analytical/images/sphx_glr_scattering_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 18.452 seconds) .. _sphx_glr_download_gallery_analytical_scattering.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: scattering.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: scattering.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: scattering.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_