{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ff0fc2d9-b53e-4d29-883b-6d6303d76eb2",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Activity 5: Multiple scattering in the forward scattering regime"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f10b898-4fc8-40fd-a477-05e736a5a255",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "In photoelectron diffraction, it is well known that for high photoelectron kinetic energy (typically > 900 eV), the scattering factor is strongly peaked in the forward direction. It means that photoelectrons are almost not deviated after a scattering event.\n",
    "\n",
    "Peaks of intentisity are then usually observed for dense atomic directions of the sample. This is the **forward scattering approximation**.\n",
    "\n",
    "For such high kinetic energy, multiple scattering is needed to accurately describe the measured intensity, but the matrix inversion algorithm cannot be used since the memory needed for storing the matrix itself would be generally too large. The matrix will contain\n",
    "$(N \\times (L_{max}+1)^2)^2$ elements of complex type with double precision (64 bits) where $N$ is the number of atoms and $L_{max}$ is the number of spherical harmonics used to expand the electron wave around each atomic center. As the kinetic energy increases, the mean free path (MFP) of the photoelectron is larger and the number of atoms in the cluster has to be greater. Lmax also increases with the kinetic energy."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc78443a-1d06-408a-91eb-33a56fe25ba3",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "::::{tab-set}\n",
    "\n",
    ":::{tab-item} <i class=\"fa-solid fa-circle-question\"></i> Quiz\n",
    "Try to evaluate how much memory you would need for this matrix for a hemispherical cluster of copper 15 angströms thick (1 MFP) for $L_{max} = 25$ ?\n",
    ":::\n",
    "\n",
    "::::"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e6f5b739-bcbf-4a2f-9c51-5e409079392a",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "hide-cell"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "606 atoms, 2.685 TB\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# lattice constant of fcc copper\n",
    "a = 3.6\n",
    "# radius of the cluster\n",
    "r = 15\n",
    "# volume of the cluster\n",
    "V = .5 * (4/3) * np.pi * r**3\n",
    "# volume of the cell\n",
    "v = a**3\n",
    "# number of atoms in the unit cell\n",
    "n = 4\n",
    "# number of atoms in the cluster\n",
    "N = int(V/v * n)\n",
    "\n",
    "Lmax = 25\n",
    "M = (N * (Lmax+1)**2 )**2 * 2 * 64 / 8\n",
    "print(f\"{N:d} atoms, {M/1e12:.3f} TB\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f53ecd7a-9202-40ec-a472-c5a2146587c9",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "This is too much memory. We will use another algorithm available in MsSpec: The *Rehr-Albers series expansion*. We already used that algorithm in activity 3 for the single scattering approach. But this time, we will explore a bit more the effect of the scattering order > 1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7e215cd-3468-4316-901d-27731ec3e61d",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "## PED of the 1T-TiSe<sub>2</sub> surface"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed46b9b8-cd37-4531-9686-5c1d804e868e",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "Let us try to model the Ti2p XPD pattern of the transition metal dichalcogenide 1T-TiSe<sub>2</sub>.\n",
    "\n",
    ":::{seealso}\n",
    "based on this paper from M.V. Kuznetsov *et al.*\n",
    "[Surf. Sci. **606** p1760–70 (2012)](https://doi.org/10.1016/j.susc.2012.06.008)\n",
    ":::\n",
    "\n",
    "### Creating the TiSe{sub}`2` cluster\n",
    "\n",
    "Start by creating a small cluster of 1T-TiSe<sub>2</sub> using the `mx2` function of `ase.build` and the `hemispherical_cluster` function of `msspec.utils`."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "65562913-1336-476c-8dd7-0ade7a8a1b8b",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    ":::{figure-md} TiSe2-fig\n",
    "<img src=\"TiSe2_cell.jpg\" alt=\"TiSe2\" width=\"300px\" align=\"center\">\n",
    "\n",
    "Structure of 1T-TiSe<sub>2</sub> ($a_0=b_0=3.535$ Å, $c_0=6.004$ Å, $d=3.450$ Å, $D=2.554$ Å)\n",
    ":::"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "849041c9-513f-4593-a4dd-fb3a495094fa",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "::::{tab-set}\n",
    "\n",
    ":::{tab-item} <i class=\"fa-solid fa-circle-question\"></i> Quiz\n",
    "Complete the code snipet provided below to create a small TiSe{sub}`2` cluster with Ti emitter in the 2{sup}`nd` plane:\n",
    "\n",
    "```{literalinclude} TiSe2_1_tofill.py\n",
    ":start-at: from\n",
    ":end-before: Create a calculator\n",
    ":lineno-match:\n",
    "```\n",
    "\n",
    ":::\n",
    "\n",
    "::::"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b65b569e-242b-4fe9-9c87-ea90d80d9b44",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "hide-cell"
    ]
   },
   "outputs": [],
   "source": [
    "from ase.build import mx2\n",
    "from ase.visualize import view\n",
    "from msspec.calculator import MSSPEC\n",
    "from msspec.utils import hemispherical_cluster, get_atom_index\n",
    "\n",
    "# Some usefull constants (a, c, d, D) for defining the structure\n",
    "a=3.535;c=6.004;d=3.450;D=2.554\n",
    "\n",
    "# Create the TiSe2 trilayer\n",
    "# use ase help for this function\n",
    "TiSe2 = mx2(formula='TiSe2', kind='1T', a=a, thickness=d, size=(1, 1, 1), vacuum=None)\n",
    "\n",
    "# The preious cell is 2D, let's define the c-axis to take into account \n",
    "# the Van der Waals gap between trilayers\n",
    "TiSe2.cell[2] = [0, 0, c]\n",
    "\n",
    "# To be aligned like in the paper\n",
    "TiSe2.rotate(60, 'z', rotate_cell=True)\n",
    "\n",
    "# Since the material is multi-elements, \"tag\" each inequivalent atom \n",
    "# of the unit cell with a number. The \"Ti\" atom is tagged 0 and \"Se\" \n",
    "# atoms are 1 and 2.\n",
    "for i in range(3): \n",
    "    TiSe2[i].tag = i\n",
    "\n",
    "cluster = hemispherical_cluster(TiSe2, emitter_tag=0, emitter_plane=1, planes=5)\n",
    "cluster.emitter = get_atom_index(cluster, 0, 0, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "515064d0-3751-4fae-af0c-c4b15ea221b3",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<html>\n",
       "    <head>\n",
       "        <title>ASE atomic visualization</title>\n",
       "        <link rel=\"stylesheet\" type=\"text/css\"             href=\"https://www.x3dom.org/release/x3dom.css\"></link>\n",
       "        <script type=\"text/javascript\"             src=\"https://www.x3dom.org/release/x3dom.js\"></script>\n",
       "    </head>\n",
       "    <body>\n",
       "        <X3D width=\"400px\"; height=\"300px\";>\n",
       "\n",
       "<!--Inserting Generated X3D Scene-->\n",
       "<scene>\n",
       "  <viewpoint position=\"0 0 28.28\">\n",
       "    <group/>\n",
       "  </viewpoint>\n",
       "  <transform translation=\"-0.8837500000000003 -2.220446049250313e-16 -3.002\">\n",
       "    <group>\n",
       "      <group>\n",
       "        <transform translation=\"0 0 0\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0 0 0\"/>\n",
       "            </appearance>\n",
       "            <lineset vertexCount=\"5\">\n",
       "              <coordinate point=\"0 0 0 1.7675000000000005 3.0613998023779905 0.0 -1.7674999999999996 3.061399802377991 0.0 -3.535 4.440892098500626e-16 0.0 0 0 0\"/>\n",
       "            </lineset>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 0.0 6.004\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0 0 0\"/>\n",
       "            </appearance>\n",
       "            <lineset vertexCount=\"5\">\n",
       "              <coordinate point=\"0 0 0 1.7675000000000005 3.0613998023779905 0.0 -1.7674999999999996 3.061399802377991 0.0 -3.535 4.440892098500626e-16 0.0 0 0 0\"/>\n",
       "            </lineset>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0 0 0\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0 0 0\"/>\n",
       "            </appearance>\n",
       "            <lineset vertexCount=\"5\">\n",
       "              <coordinate point=\"0 0 0 1.7675000000000005 3.0613998023779905 0.0 1.7675000000000005 3.0613998023779905 6.004 0.0 0.0 6.004 0 0 0\"/>\n",
       "            </lineset>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.535 4.440892098500626e-16 0.0\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0 0 0\"/>\n",
       "            </appearance>\n",
       "            <lineset vertexCount=\"5\">\n",
       "              <coordinate point=\"0 0 0 1.7675000000000005 3.0613998023779905 0.0 1.7675000000000005 3.0613998023779905 6.004 0.0 0.0 6.004 0 0 0\"/>\n",
       "            </lineset>\n",
       "          </shape>\n",
       "        </transform>\n",
       "      </group>\n",
       "      <group>\n",
       "        <transform translation=\"1.767499999999984 -7.143266205548649 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-1.7675000000000125 -7.143266205548649 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"3.5349999999999966 -6.122799604755983 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"3.5349999999999966 -4.0818664031706575 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"1.767499999999984 -5.102333003963317 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 -4.0818664031706575 -4.279000000000005\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 -6.122799604755983 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 -4.0818664031706575 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-1.7675000000000125 -5.102333003963317 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.5349999999999966 -6.122799604755983 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.5349999999999966 -4.0818664031706575 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"5.302499999999995 -3.0613998023779914 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"5.302499999999995 -1.0204666007926662 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"3.5349999999999966 -2.040933201585325 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"1.767499999999984 -1.0204666007926662 -4.279000000000005\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"1.767499999999984 -3.0613998023779914 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"1.767499999999984 -1.0204666007926662 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 -2.040933201585325 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-1.7675000000000125 -1.0204666007926662 -4.279000000000005\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-1.7675000000000125 -3.0613998023779914 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-1.7675000000000125 -1.0204666007926662 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.5349999999999966 -2.040933201585325 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-5.302500000000009 -3.0613998023779914 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-5.302500000000009 -1.0204666007926662 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"7.069999999999993 0.0 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"7.069999999999993 2.040933201585325 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"5.302499999999995 1.020466600792666 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"3.5349999999999966 2.040933201585325 -4.279000000000005\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"3.5349999999999966 0.0 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"3.5349999999999966 2.040933201585325 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"1.767499999999984 1.020466600792666 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 0.0 -6.004\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 2.040933201585325 -4.279000000000005\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 0.0 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 2.040933201585325 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-1.7675000000000125 1.020466600792666 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.5349999999999966 2.040933201585325 -4.279000000000005\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.5349999999999966 0.0 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.5349999999999966 2.040933201585325 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-5.302500000000009 1.020466600792666 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-7.070000000000007 0.0 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-7.070000000000007 2.040933201585325 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"5.302499999999995 3.0613998023779985 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"5.302499999999995 5.102333003963331 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"3.5349999999999966 4.0818664031706575 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"1.7674999999999983 3.0613998023779985 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"1.7674999999999983 5.102333003963331 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 4.0818664031706575 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-1.7675000000000125 3.0613998023779985 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-1.7675000000000125 5.102333003963331 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.5349999999999966 4.0818664031706575 -1.7249999999999894\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-5.302500000000009 3.0613998023779985 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-5.302500000000009 5.102333003963331 1.724999999999999\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"1.0 0.631 0.0\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.2\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"3.5349999999999966 6.12279960475599 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"0.0 6.12279960475599 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "        <transform translation=\"-3.5349999999999966 6.12279960475599 4.6629367034256575e-15\">\n",
       "          <shape>\n",
       "            <appearance>\n",
       "              <material diffuseColor=\"0.749 0.761 0.78\"/>\n",
       "            </appearance>\n",
       "            <sphere radius=\"1.6\"/>\n",
       "          </shape>\n",
       "        </transform>\n",
       "      </group>\n",
       "    </group>\n",
       "  </transform>\n",
       "</scene>\n",
       "<!--End of Inserted Scene-->\n",
       "\n",
       "        </X3D>\n",
       "    </body>\n",
       "</html>\n",
       "\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "view(cluster, viewer='x3d')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b029e1b-6871-42ac-9cdd-65c583404e3d",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "### Effect of the scattering order\n",
    "\n",
    "Use the line belows to create a calculator and compute a $\\theta$-$\\phi$ scan of the Ti(2p)\n",
    "\n",
    "```{literalinclude} TiSe2_1_tofill.py\n",
    "    :start-at: Create a\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8169ad09-36b4-4f0a-b737-378e2f78b3df",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "::::{tab-set}\n",
    "\n",
    ":::{tab-item} <i class=\"fa-solid fa-circle-question\"></i> Quiz\n",
    "Compute a scan for an emitter in the first trilayer and in the second trilayer for scattering orders from 1 (single scattering) to 3 in order to complete the figure below.\n",
    "What do you conclude about the value of the `calc.calculation_parameters.scattering_order` ?\n",
    "\n",
    "```{figure-md} results-fig\n",
    "<img src=\"results.jpg\" width=\"400px\" align=\"center\">\n",
    "\n",
    "$\\theta$-$\\phi$ scan of Ti(2p) at 1030 eV kinetic energy for an emitter in the first trilayer (left column) and in the second trilayer (right column). Each row correspond to a growing value for the `calc.calculation_parameters.scattering_order` parameter (from 1 to 5).\n",
    "```\n",
    "\n",
    ":::\n",
    "\n",
    "::::"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4fb402ae-e094-4d6c-833f-5f106fd72035",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": [
     "hide-cell"
    ]
   },
   "source": [
    "```{toggle}\n",
    "\n",
    ":::{figure-md} results-completed-fig\n",
    "<img src=\"results_completed.jpg\" width=\"400px\" align=\"center\">\n",
    "\n",
    "$\\theta$-$\\phi$ scan of Ti(2p) at 1030 eV kinetic energy for an emitter in the first trilayer (left column) and in the second trilayer (right column). Each row correspond to a growing value for the `calc.calculation_parameters.scattering_order` parameter (from 1 to 5).\n",
    ":::\n",
    "\n",
    "The deeper the emitter, the greater the scattering order should be for the intensity to converge.\n",
    "Typically, in the forward scattering regime, the scattering order corresponds to the number of planes above the emitter.\n",
    "\n",
    "```"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}