{
  "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# Rb2SO4, 87Rb (I=3/2) QMAT\n\n87Rb (I=3/2) Quadrupolar Magic-angle turning (QMAT)\nsimulation.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The following is a simulation of the QMAT spectrum of $\\text{Rb}_2\\text{SiO}_4$.\nThe 2D QMAT spectrum is a correlation of finite speed MAS to an infinite speed MAS\nspectrum. The parameters for the simulation are obtained from Walder `et. al.` [#f1]_.\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 SSB2D\n\n# global plot configuration\nfont = {\"size\": 9}\nmpl.rc(\"font\", **font)\nmpl.rcParams[\"figure.figsize\"] = [4.5, 3.0]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Generate the site and spin system objects.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "sites = [\n    Site(\n        isotope=\"87Rb\",\n        isotropic_chemical_shift=16,  # in ppm\n        quadrupolar={\"Cq\": 5.3e6, \"eta\": 0.1},  # Cq in Hz\n    ),\n    Site(\n        isotope=\"87Rb\",\n        isotropic_chemical_shift=40,  # in ppm\n        quadrupolar={\"Cq\": 2.6e6, \"eta\": 1.0},  # Cq in Hz\n    ),\n]\nspin_systems = [SpinSystem(sites=[s]) for s in sites]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Use the ``SSB2D`` method to simulate a PASS, MAT, QPASS, QMAT, or any equivalent\nsideband separation spectrum. Here, we use the method to generate a QMAT spectrum.\nThe QMAT method is created from the ``SSB2D`` method in the same as a PASS or MAT\nmethod. The difference is that the observed channel is a half-integer quadrupolar\nspin instead of a spin I=1/2.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "qmat = SSB2D(\n    channels=[\"87Rb\"],\n    magnetic_flux_density=9.4,\n    rotor_frequency=2604,\n    spectral_dimensions=[\n        {\n            \"count\": 32 * 4,\n            \"spectral_width\": 2604 * 32,  # in Hz\n            \"label\": \"Anisotropic dimension\",\n        },\n        {\n            \"count\": 512,\n            \"spectral_width\": 50000,  # in Hz\n            \"label\": \"High speed MAS dimension\",\n        },\n    ],\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create the Simulator object, add the method and spin system objects, and\nrun the simulation.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "sim = Simulator()\nsim.spin_systems = spin_systems  # add the spin systems\nsim.methods = [qmat]  # add the method.\n\n# For 2D spinning sideband simulation, set the number of spinning sidebands in the\n# Simulator.config object to `spectral_width/rotor_frequency` along the sideband\n# dimension.\nsim.config.number_of_sidebands = 32\nsim.run()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The plot of the simulation.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "data = sim.methods[0].simulation\nax = plt.subplot(projection=\"csdm\")\ncb = ax.imshow(data / data.max(), aspect=\"auto\", cmap=\"gist_ncar_r\", vmax=0.15)\nplt.colorbar(cb)\nax.invert_xaxis()\nax.set_ylim(200, -200)\nplt.tight_layout()\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. [#f1] Walder, B. J., Dey, K .K, Kaseman, D. C., Baltisberger, J. H., and Philip J.\n      Grandinetti. Sideband separation experiments in NMR with phase incremented echo\n      train acquisition, J. Chem. Phys. (2013) **138**, 174203.\n      `DOI:10.1063/1.4803142 <https://doi.org/10.1063/1.4803142>`_\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
}