.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/1D_simulation(macro_amorphous)/plot_5_czjzek_distribution.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_examples_1D_simulation(macro_amorphous)_plot_5_czjzek_distribution.py: Czjzek distribution (Shielding and Quadrupolar) =============================================== In this example, we illustrate the simulation of spectrum originating from a Czjzek distribution of traceless symmetric tensors. We show two cases, the Czjzek distribution of the shielding and quadrupolar tensor parameters, respectively. .. GENERATED FROM PYTHON SOURCE LINES 11-12 Import the required modules. .. GENERATED FROM PYTHON SOURCE LINES 12-22 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from mrsimulator import Simulator from mrsimulator.method.lib import BlochDecaySpectrum, BlochDecayCTSpectrum from mrsimulator.models import CzjzekDistribution from mrsimulator.utils.collection import single_site_system_generator from mrsimulator.method import SpectralDimension .. GENERATED FROM PYTHON SOURCE LINES 24-32 Symmetric shielding tensor -------------------------- Create the Czjzek distribution '''''''''''''''''''''''''''''' First, create a distribution of the zeta and eta parameters of the shielding tensors using the :ref:`czjzek_distribution` model as follows. .. GENERATED FROM PYTHON SOURCE LINES 32-39 .. code-block:: Python # The range of zeta and eta coordinates over which the distribution is sampled. z_range = np.arange(100) - 50 # in ppm e_range = np.arange(21) / 20 z_dist, e_dist = np.meshgrid(z_range, e_range) _, _, amp = CzjzekDistribution(sigma=3.1415).pdf(pos=[z_range, e_range]) .. GENERATED FROM PYTHON SOURCE LINES 40-47 Here ``z_range`` and ``e_range`` are the coordinates along the :math:`\zeta` and :math:`\eta` dimensions that form a two-dimensional :math:`\zeta`-:math:`\eta` grid. The argument `sigma` of the CzjzekDistribution class is the standard deviation of the second-rank tensor parameters used in generating the distribution, and `pos` hold the one-dimensional arrays of :math:`\zeta` and :math:`\eta` coordinates, respectively. The following is the contour plot of the Czjzek distribution. .. GENERATED FROM PYTHON SOURCE LINES 47-54 .. code-block:: Python plt.figure(figsize=(4.25, 3.0)) plt.contourf(z_dist, e_dist, amp, levels=10) plt.xlabel(r"$\zeta$ / ppm") plt.ylabel(r"$\eta$") plt.tight_layout() plt.show() .. image-sg:: /examples/1D_simulation(macro_amorphous)/images/sphx_glr_plot_5_czjzek_distribution_001.png :alt: plot 5 czjzek distribution :srcset: /examples/1D_simulation(macro_amorphous)/images/sphx_glr_plot_5_czjzek_distribution_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 55-61 Simulate the spectrum ''''''''''''''''''''' To quickly generate single-site spin systems from the above :math:`\zeta` and :math:`\eta` parameters, use the :func:`~mrsimulator.utils.collection.single_site_system_generator` utility function. .. GENERATED FROM PYTHON SOURCE LINES 61-70 .. code-block:: Python systems = single_site_system_generator( isotope="13C", shielding_symmetric={"zeta": z_dist, "eta": e_dist}, abundance=amp ) method = BlochDecaySpectrum( channels=["13C"], rotor_frequency=0, # in Hz rotor_angle=0, # in rads ) .. GENERATED FROM PYTHON SOURCE LINES 71-73 Here, the variable ``systems`` hold an array of single-site spin systems. Next, create a simulator object and add the above system and a method. .. GENERATED FROM PYTHON SOURCE LINES 73-76 .. code-block:: Python sim = Simulator(spin_systems=systems, methods=[method]) sim.run() .. GENERATED FROM PYTHON SOURCE LINES 77-79 The following is the static spectrum arising from a Czjzek distribution of the second-rank traceless shielding tensors. .. GENERATED FROM PYTHON SOURCE LINES 79-85 .. code-block:: Python plt.figure(figsize=(4.25, 3.0)) ax = plt.subplot(projection="csdm") ax.plot(sim.methods[0].simulation.real, color="black", linewidth=1) plt.tight_layout() plt.show() .. image-sg:: /examples/1D_simulation(macro_amorphous)/images/sphx_glr_plot_5_czjzek_distribution_002.png :alt: plot 5 czjzek distribution :srcset: /examples/1D_simulation(macro_amorphous)/images/sphx_glr_plot_5_czjzek_distribution_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-94 Quadrupolar tensor ------------------ Create the Czjzek distribution '''''''''''''''''''''''''''''' Similarly, you may also create a Czjzek distribution of the electric field gradient (EFG) tensor parameters. .. GENERATED FROM PYTHON SOURCE LINES 94-109 .. code-block:: Python # The range of Cq and eta coordinates over which the distribution is sampled. cq_range = np.arange(100) * 0.6 - 30 # in MHz e_range = np.arange(21) / 20 cq_dist, e_dist = np.meshgrid(cq_range, e_range) _, _, amp = CzjzekDistribution(sigma=2.3).pdf(pos=[cq_range, e_range]) # The following is the contour plot of the Czjzek distribution. plt.figure(figsize=(4.25, 3.0)) plt.contourf(cq_dist, e_dist, amp, levels=10) plt.xlabel(r"Cq / MHz") plt.ylabel(r"$\eta$") plt.tight_layout() plt.show() .. image-sg:: /examples/1D_simulation(macro_amorphous)/images/sphx_glr_plot_5_czjzek_distribution_003.png :alt: plot 5 czjzek distribution :srcset: /examples/1D_simulation(macro_amorphous)/images/sphx_glr_plot_5_czjzek_distribution_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 110-114 Simulate the spectrum ''''''''''''''''''''' Create the spin systems and method .. GENERATED FROM PYTHON SOURCE LINES 114-126 .. code-block:: Python systems = single_site_system_generator( isotope="71Ga", quadrupolar={"Cq": cq_dist * 1e6, "eta": e_dist}, abundance=amp ) method = BlochDecayCTSpectrum( channels=["71Ga"], magnetic_flux_density=4.8, # in T rotor_frequency=0, # in Hz rotor_angle=0, # in rads spectral_dimensions=[SpectralDimension(count=2048, spectral_width=1.2e6)], ) .. GENERATED FROM PYTHON SOURCE LINES 127-128 Create a simulator object and add the above system. .. GENERATED FROM PYTHON SOURCE LINES 128-131 .. code-block:: Python sim = Simulator(spin_systems=systems, methods=[method]) sim.run() .. GENERATED FROM PYTHON SOURCE LINES 132-134 The following is the static spectrum arising from a Czjzek distribution of the second-rank traceless EFG tensors. .. GENERATED FROM PYTHON SOURCE LINES 134-140 .. code-block:: Python plt.figure(figsize=(4.25, 3.0)) ax = plt.subplot(projection="csdm") ax.plot(sim.methods[0].simulation.real, color="black", linewidth=1) ax.invert_xaxis() plt.tight_layout() plt.show() .. image-sg:: /examples/1D_simulation(macro_amorphous)/images/sphx_glr_plot_5_czjzek_distribution_004.png :alt: plot 5 czjzek distribution :srcset: /examples/1D_simulation(macro_amorphous)/images/sphx_glr_plot_5_czjzek_distribution_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.799 seconds) .. _sphx_glr_download_examples_1D_simulation(macro_amorphous)_plot_5_czjzek_distribution.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_5_czjzek_distribution.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_5_czjzek_distribution.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_