{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from IPython.display import Math, display\n",
    "import numpy as np\n",
    "import sympy as sp\n",
    "from scipy import constants as const\n",
    "\n",
    "#add relative path to backend\n",
    "import sys\n",
    "sys.path.append('../../clean_diag/backend')\n",
    "\n",
    "import trap_units as si\n",
    "from twod_trap import PancakeTrap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "initial_power = 49 * si.uW \n",
    "\n",
    "trap: PancakeTrap = PancakeTrap(\n",
    "    power=0,  # Set pancake laser power to 0, no 2D trap\n",
    "    grad_z= 0 * si.G / si.cm,\n",
    "    grad_r=0,\n",
    "    power_tweezer= initial_power,\n",
    "    waist_tweezer=1 * si.um,\n",
    "\n",
    "    m= 161 * const.value(\"atomic mass constant\"),\n",
    "    mu_b= 9.93 * const.value(\"Bohr magneton\" ),\n",
    "    a=184.4*(4 * np.pi * const.epsilon_0 * const.value(\"Bohr radius\")**3)/(2 * const.epsilon_0 * const.c),\n",
    "\n",
    "    wvl = 1064 * si.nm,\n",
    ")\n",
    "axial_width = trap.get_tweezer_rayleigh()\n",
    "zr = float(trap.subs(trap.get_tweezer_rayleigh()))\n",
    "\n",
    "x, y, z = trap.x, trap.y, trap.z"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Gradient to cancel gravity:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.847 G/cm\n"
     ]
    }
   ],
   "source": [
    "grav_grad = float(trap.subs(trap.m*const.g/trap.mu_b) /si.G*si.cm)\n",
    "print(f\"{grav_grad:.3f} G/cm\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Find waist for target aspect ration (1064nm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle W_{t}\\left(\\frac{\\omega_{t r}}{\\omega_{t ax}} = 9\\right) = 2.16\\mathrm{\\mu m}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "eta_target = 9\n",
    "\n",
    "waist = trap.subs(\n",
    "    sp.solve(\n",
    "        trap.get_omega_r_tweezer() / trap.get_omega_ax_tweezer() - eta_target,\n",
    "        trap.waist_tweezer,\n",
    "    )[0]\n",
    ").evalf()\n",
    "\n",
    "_aspect_ratio_latex = sp.latex(trap.omega_r_tweezer / trap.omega_ax_tweezer)\n",
    "display(\n",
    "    Math(\n",
    "        f\"{sp.latex(trap.waist_tweezer)}\\\\left({_aspect_ratio_latex} = {eta_target}\\\\right)\"\n",
    "        f\" = {waist/si.um:.2f}\\\\mathrm{{\\\\mu m}}\"\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# For 532nm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "trap[trap.wvl] = 532*si.nm\n",
    "trap[trap.a] = 180* (4 * np.pi * const.epsilon_0 * const.value(\"Bohr radius\")**3)/(2 * const.epsilon_0 * const.c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle W_{t}\\left(\\frac{\\omega_{t r}}{\\omega_{t ax}} = 9\\right) = 1.08\\mathrm{\\mu m}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "eta_target = 9\n",
    "\n",
    "waist = trap.subs(\n",
    "    sp.solve(\n",
    "        trap.get_omega_r_tweezer() / trap.get_omega_ax_tweezer() - eta_target,\n",
    "        trap.waist_tweezer,\n",
    "    )[0]\n",
    ").evalf()\n",
    "\n",
    "_aspect_ratio_latex = sp.latex(trap.omega_r_tweezer / trap.omega_ax_tweezer)\n",
    "display(\n",
    "    Math(\n",
    "        f\"{sp.latex(trap.waist_tweezer)}\\\\left({_aspect_ratio_latex} = {eta_target}\\\\right)\"\n",
    "        f\" = {waist/si.um:.2f}\\\\mathrm{{\\\\mu m}}\"\n",
    "    )\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Ploting for different target aspect ratios"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33192 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "wvls = np.array([532, 1064]) * si.nm\n",
    "waists = np.linspace(0.5,4) * si.um\n",
    "\n",
    "for i, wvl in enumerate(wvls):\n",
    "    eta = np.sqrt(2)*np.pi * waists/wvl\n",
    "    plt.plot(waists/si.um,eta,label=f\"{wvl/si.nm}nm\")\n",
    "\n",
    "plt.ylabel(\"eta\")\n",
    "plt.xlabel(\"waist [um]\")\n",
    "plt.grid()\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
