{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# This cell is added by sphinx-gallery\n\n%matplotlib inline\n\nimport mrsimulator\nprint(f'You are using mrsimulator v{mrsimulator.__version__}')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Non-coincidental Quad and CSA, 17O (I=5/2)\n\n17O (I=5/2) quadrupolar static spectrum simulation.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The following example illustrates the simulation of NMR spectra arising from\nnon-coincidental quadrupolar and shielding tensors. The tensor parameter values for\nthe simulation are obtained from Yamada `et. al.` [#f1]_, for the\n$^{17}\\text{O}$ site in benzanilide.\n\n<div class=\"alert alert-danger\"><h4>Warning</h4><p>The Euler angles representation using by Yamada `et. al` is different from the\n    representation used in mrsimulator. The resulting simulation might not resemble\n    the published spectrum.</p></div>\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib as mpl\nimport matplotlib.pyplot as plt\nfrom mrsimulator import Simulator, SpinSystem, Site\nfrom mrsimulator.methods import BlochDecayCentralTransitionSpectrum\nimport numpy as np\n\n# global plot configuration\nmpl.rcParams[\"figure.figsize\"] = [4.5, 3.0]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Step 1:** Create the spin system.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "site = Site(\n    isotope=\"17O\",\n    isotropic_chemical_shift=320,  # in ppm\n    shielding_symmetric={\"zeta\": 376.667, \"eta\": 0.345},\n    quadrupolar={\n        \"Cq\": 8.97e6,  # in Hz\n        \"eta\": 0.15,\n        \"alpha\": 5 * np.pi / 180,\n        \"beta\": np.pi / 2,\n        \"gamma\": 70 * np.pi / 180,\n    },\n)\nspin_system = SpinSystem(sites=[site])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Step 2:** Create a central transition selective Bloch decay spectrum method.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "method = BlochDecayCentralTransitionSpectrum(\n    channels=[\"17O\"],\n    magnetic_flux_density=11.74,  # in T\n    rotor_frequency=0,  # in Hz\n    spectral_dimensions=[\n        {\n            \"count\": 1024,\n            \"spectral_width\": 1e5,  # in Hz\n            \"reference_offset\": 22500,  # in Hz\n            \"label\": r\"$^{17}$O resonances\",\n        }\n    ],\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Step 3:** Create the Simulator object and add method and spin system objects.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "sim = Simulator()\nsim.spin_systems = [spin_system]  # add the spin system\nsim.methods = [method]  # add the method\n\n# Since the spin system have non-zero Euler angles, set the integration_volume to\n# hemisphere.\nsim.config.integration_volume = \"hemisphere\""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Step 4:** Simulate the spectrum.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "sim.run()\n\n# The plot of the simulation before signal processing.\nax = plt.subplot(projection=\"csdm\")\nax.plot(sim.methods[0].simulation.real, color=\"black\", linewidth=1)\nax.invert_xaxis()\nplt.tight_layout()\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. [#f1] Yamada, K., Dong, S., Wu, G., Solid-State 17O NMR Investigation of the\n      Carbonyl Oxygen Electric-Field-Gradient Tensor and Chemical Shielding Tensor in\n      Amides, J. Am. Chem. Soc. 2000, **122**, 11602-11609.\n      `DOI: 10.1021/ja0008315 <https://doi.org/10.1021/ja0008315>`_\n\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}