{
  "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# Itraconazole, 13C (I=1/2) PASS\n\n13C (I=1/2) 2D Phase-adjusted spinning sideband (PASS)\nsimulation.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The following is a simulation of a 2D PASS spectrum of itraconazole, a triazole\ncontaining drug prescribed for the prevention and treatment of fungal infection.\nThe 2D PASS spectrum is a correlation of finite speed MAS to an infinite speed MAS\nspectrum. The parameters for the simulation are obtained from Dey `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\nimport mrsimulator.signal_processing as sp\nimport mrsimulator.signal_processing.apodization as apo\nfrom mrsimulator import Simulator\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": [
        "There are 41 $^{13}\\text{C}$ single-site spin systems partially describing the\nNMR parameters of itraconazole. We will import the directly import the spin systems\nto the Simulator object using the `load_spin_systems` method.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "sim = Simulator()\n\nfilename = \"https://sandbox.zenodo.org/record/687656/files/itraconazole_13C.mrsys\"\nsim.load_spin_systems(filename)"
      ]
    },
    {
      "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 PASS spectrum.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "PASS = SSB2D(\n    channels=[\"13C\"],\n    magnetic_flux_density=11.74,\n    rotor_frequency=2000,\n    spectral_dimensions=[\n        {\n            \"count\": 20 * 4,\n            \"spectral_width\": 2000 * 20,  # value in Hz\n            \"label\": \"Anisotropic dimension\",\n        },\n        {\n            \"count\": 1024,\n            \"spectral_width\": 3e4,  # value in Hz\n            \"reference_offset\": 1.1e4,  # value in Hz\n            \"label\": \"Isotropic dimension\",\n        },\n    ],\n)\nsim.methods = [PASS]  # 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 = 20\n\n# run the simulation.\nsim.run()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Apply post-simulation processing. Here, we apply a Lorentzian line broadening to the\nisotropic dimension.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "data = sim.methods[0].simulation\nprocessor = sp.SignalProcessor(\n    operations=[\n        sp.IFFT(dim_index=0),\n        apo.Exponential(FWHM=\"100 Hz\", dim_index=0),\n        sp.FFT(dim_index=0),\n    ]\n)\nprocessed_data = processor.apply_operations(data=data).real\nprocessed_data /= processed_data.max()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The plot of the simulation.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "ax = plt.subplot(projection=\"csdm\")\ncb = ax.imshow(processed_data, aspect=\"auto\", cmap=\"gist_ncar_r\", vmax=0.5)\nplt.colorbar(cb)\nax.invert_xaxis()\nax.invert_yaxis()\nplt.tight_layout()\nplt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        ".. [#f1] Dey, K .K, Gayen, S., Ghosh, M., Investigation of the Detailed Internal\n      Structure and Dynamics of Itraconazole by Solid-State NMR Measurements,\n      ACS Omega (2019) **4**, 21627.\n      `DOI:10.1021/acsomega.9b03558 <https://doi.org/10.1021/acsomega.9b03558>`_\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
}