{
  "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# Simulate arbitrary transitions (multi-quantum)\n\n33S (I=5/2) quadrupolar spectrum simulation.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Simulate a triple quantum spectrum.\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 Method1D\n\n# global plot configuration\nmpl.rcParams[\"figure.figsize\"] = [4.5, 3.0]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create a single-site arbitrary spin system.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "site = Site(\n    name=\"27Al\",\n    isotope=\"27Al\",\n    isotropic_chemical_shift=35.7,  # in ppm\n    quadrupolar={\"Cq\": 2.959e6, \"eta\": 0.98},  # Cq is in Hz\n)\nspin_system = SpinSystem(sites=[site])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Selecting the triple-quantum transition\n\nFor spin-site spin-5/2 spin system, there are three triple-quantum transition\n\n- $|1/2\\rangle\\rightarrow|-5/2\\rangle$ ($P=-3, D=6$)\n- $|3/2\\rangle\\rightarrow|-3/2\\rangle$ ($P=-3, D=0$)\n- $|5/2\\rangle\\rightarrow|-1/2\\rangle$ ($P=-3, D=-6$)\n\nTo select one or more triple-quantum transitions, assign the respective value of P and\nD to the `transition_query`.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "method = Method1D(\n    channels=[\"27Al\"],\n    magnetic_flux_density=21.14,  # in T\n    rotor_frequency=1e9,  # in Hz\n    spectral_dimensions=[\n        {\n            \"count\": 1024,\n            \"spectral_width\": 5e3,  # in Hz\n            \"reference_offset\": 2.5e4,  # in Hz\n            \"events\": [\n                {  # symmetric triple quantum transitions\n                    \"transition_query\": {\"P\": [-3], \"D\": [0]}\n                }\n            ],\n        }\n    ],\n)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Create the Simulator object and add the method and the spin system object.\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\nsim.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()"
      ]
    }
  ],
  "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
}