{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### We can match the tweezer depths for a given difference in waist, but need to apply an offset to the power to be in the no-crossover regime. Here I want to find what the best value for that offset is."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from helpers_merging import *\n",
    "\n",
    "initial_power = 50* si.uW\n",
    "initial_waist = 1.1*si.uW\n",
    "initial_distance = 3*si.um\n",
    "\n",
    "trap: DoubleTweezer = DoubleTweezer(\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_tweezer1 = initial_power,     #stationary\n",
    "    power_tweezer2 = initial_power,     #transfer tweezer\n",
    "    waist_tweezer1 = initial_waist,     #stationary\n",
    "    waist_tweezer2 = initial_waist*1.075,     #transfer tweezer\n",
    "    distance_tweezers = initial_distance,\n",
    "\n",
    "    a=180*(4 * np.pi * const.epsilon_0 * const.value(\"Bohr radius\")**3)/(2 * const.epsilon_0 * const.c),\n",
    "    wvl = 532 * si.nm,\n",
    "\n",
    "    g = 0,\n",
    ")\n",
    "\n",
    "x, y, z = trap.x, trap.y, trap.z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 51584 characters]",
      "text/plain": [
       "<Figure size 500x500 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "left_cutoff = -0.5*initial_distance-3*np.max([float(trap.subs(trap.waist_tweezer1)),float(trap.subs(trap.waist_tweezer2))])\n",
    "right_cutoff = 0.5*initial_distance+3*np.max([float(trap.subs(trap.waist_tweezer1)),float(trap.subs(trap.waist_tweezer2))])\n",
    "\n",
    "trap[trap.distance_tweezers] = 0.55*initial_distance\n",
    "trap[trap.power_tweezer2] = initial_power*2.5\n",
    "trap[trap.waist_tweezer2] = initial_waist*1.5\n",
    "plot_solutions(trap,4,left_cutoff,right_cutoff,display_plot=-1,state_mult=40,n_pot_steps=1000,plot=True,ret_results=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_deltaE(power_tweezer1, power_tweezer2, waist_tweezer1, waist_tweezer2,\n",
    "               n_levels=10,n_pot_steps=2000, initial_distance=4*si.um, plot=True):\n",
    "    \"\"\"\n",
    "    Returns the minimal energy gap and occupation numbers of the groundstate when the two tweezers merge.\n",
    "    \"\"\"\n",
    "    trap[trap.power_tweezer1] = power_tweezer1\n",
    "    trap[trap.power_tweezer2] = power_tweezer2\n",
    "    trap[trap.waist_tweezer1] = waist_tweezer1\n",
    "    trap[trap.waist_tweezer2] = waist_tweezer2\n",
    "\n",
    "    distances = np.linspace(initial_distance,0*si.um,500) #always has to have smallest distance at last index\n",
    "    energies, states, potentials = loop_distances(trap, distances,n_levels=n_levels,n_pot_steps=n_pot_steps)\n",
    "\n",
    "    new_energies, new_states, new_potentials, index_top, index, swap_index = swapped_loop_distance(distances, energies, states, potentials)\n",
    "    energies_left, energies_right, states_left, states_right = find_ass_tweezer(new_energies,new_states, return_deltaE=False)\n",
    "\n",
    "    if len(index)!=0:\n",
    "        deltaE_min = 0\n",
    "        print(\"crossover\")\n",
    "    else:\n",
    "        deltaE_min = np.inf\n",
    "        for i in range(energies_left.shape[1]):\n",
    "            for j in range(energies_right.shape[1]):\n",
    "                row_diff = np.nanmin(np.abs(energies_left[:,i] - energies_right[:,j]))\n",
    "                if row_diff<deltaE_min:\n",
    "                    deltaE_min = row_diff\n",
    "                    i_min, j_min = i,j\n",
    "        print(f\"closest approach between states: left:{i_min}, right:{j_min}\")\n",
    "\n",
    "    if plot:\n",
    "        # Create the figure with two subplots (1 row, 2 columns)\n",
    "        fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))\n",
    "\n",
    "        # Plot the full range on ax1\n",
    "        \"\"\"\n",
    "        ax1.plot(distances/si.um, energies_left[:, 0], color=\"red\", label=\"GS left tweezer\")\n",
    "        ax1.plot(distances/si.um, energies_right[:, 0], color=\"blue\", label=\"GS right tweezer\")\n",
    "        ax1.plot(distances/si.um, energies_left[:, 1:], color=\"red\", linestyle=\"dotted\", label=\"left tweezer\")\n",
    "        ax1.plot(distances/si.um, energies_right[:, 1:], color=\"blue\", linestyle=\"dotted\", label=\"right tweezer\")\"\"\"\n",
    "        ax1.plot(distances/si.um, energies_left[:], color=\"red\", label=\"left tweezer\")\n",
    "        ax1.plot(distances/si.um, energies_right[:], color=\"blue\", label=\"right tweezer\")\n",
    "\n",
    "        for i, ind in enumerate(index):\n",
    "            ax1.axvline(distances[ind]/si.um, color=\"k\", alpha=0.7, label=\"energy crossings\")\n",
    "\n",
    "        ax1.set_xlabel(\"Tweezer distance [um]\")\n",
    "        ax1.set_ylabel(\"Eigenenergy [a.u.]\")\n",
    "        ax1.set_title(fr\"$p_l={float(trap.subs(trap.power_tweezer1))/si.uW:.1f}$ uW, $p_r={float(trap.subs(trap.power_tweezer2))/si.uW:.1f}$ uW, $w_l={float(trap.subs(trap.waist_tweezer1))/si.um:.3f}$ um, $w_r={float(trap.subs(trap.waist_tweezer2))/si.um:.3f}$ um\")\n",
    "        ax1.grid()\n",
    "\n",
    "        # Plot the zoomed-in range (1 to 1.5 µm) on ax2\n",
    "        \"\"\"\n",
    "        ax2.plot(distances/si.um, energies_left[:, 0], color=\"red\", label=\"GS left tweezer\")\n",
    "        ax2.plot(distances/si.um, energies_right[:, 0], color=\"blue\", label=\"GS right tweezer\")\n",
    "        ax2.plot(distances/si.um, energies_left[:, 1:], color=\"red\", linestyle=\"dotted\", label=\"left tweezer\")\n",
    "        ax2.plot(distances/si.um, energies_right[:, 1:], color=\"blue\", linestyle=\"dotted\", label=\"right tweezer\")\"\"\"\n",
    "        ax2.plot(distances/si.um, energies_left[:], color=\"red\", label=\"left tweezer\")\n",
    "        ax2.plot(distances/si.um, energies_right[:], color=\"blue\", label=\"right tweezer\")\n",
    "\n",
    "        for i, ind in enumerate(index):\n",
    "            ax2.axvline(distances[ind]/si.um, color=\"k\", alpha=0.7, label=\"energy crossings\")\n",
    "\n",
    "        ax2.set_xlabel(\"Tweezer distance [um]\")\n",
    "        ax2.set_ylabel(\"Eigenenergy [a.u.]\")\n",
    "        ax2.set_title(\"Zoomed-in Region\")\n",
    "        ax2.set_xlim(0.7, 1)  # Zooming in on the region between 1.0 and 1.5 µm\n",
    "        ax2.set_ylim(-7e-28,-5e-28)\n",
    "        ax2.grid()\n",
    "\n",
    "        # Remove duplicates in the legend (labels that appear in both subplots)\n",
    "        handles, labels = ax1.get_legend_handles_labels()\n",
    "        unique_labels = dict(zip(labels, handles))  # Remove duplicates\n",
    "        ax1.legend(unique_labels.values(), unique_labels.keys())\n",
    "\n",
    "        # Show the plots\n",
    "        plt.tight_layout()\n",
    "        plt.show()\n",
    "\n",
    "    return deltaE_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "crossover\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 70756 characters]",
      "text/plain": [
       "<Figure size 800x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "initial_power = 500*si.uW\n",
    "initial_waist = 0.75*si.um\n",
    "initial_distance = 2*si.um\n",
    "\n",
    "factor_waist2 = 1.025\n",
    "\n",
    "trap[trap.power_tweezer1] = initial_power\n",
    "trap[trap.waist_tweezer1] = initial_waist\n",
    "trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "omega_r2 = sp.sqrt(2*trap.power_tweezer2*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer2**2\n",
    "\n",
    "#offset required for 1 level spacing of the left tweezer\n",
    "power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "#factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "power2_factor = factor_waist2**2 - 0.42*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "deltaEs = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10)\n",
    "\n",
    "print(deltaEs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:4, right:4\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 91632 characters]",
      "text/plain": [
       "<Figure size 800x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.1070827342779715e-32\n"
     ]
    }
   ],
   "source": [
    "factor_waist2 = 1.0\n",
    "\n",
    "trap[trap.power_tweezer1] = initial_power\n",
    "trap[trap.waist_tweezer1] = initial_waist\n",
    "trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "omega_r2 = sp.sqrt(2*trap.power_tweezer2*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer2**2\n",
    "\n",
    "#offset required for 1 level spacing of the left tweezer\n",
    "power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "#factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "power2_factor = factor_waist2**2 - 0.02*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "deltaEs = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10)\n",
    "\n",
    "print(deltaEs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:4, right:4\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 93788 characters]",
      "text/plain": [
       "<Figure size 800x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.818007561261679e-31\n"
     ]
    }
   ],
   "source": [
    "factor_waist2 = 1.0\n",
    "\n",
    "trap[trap.power_tweezer1] = initial_power\n",
    "trap[trap.waist_tweezer1] = initial_waist\n",
    "trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "omega_r2 = sp.sqrt(2*trap.power_tweezer2*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer2**2\n",
    "\n",
    "#offset required for 1 level spacing of the left tweezer\n",
    "power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "#factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "power2_factor = factor_waist2**2 - 0.3*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "deltaEs = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10)\n",
    "\n",
    "print(deltaEs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:1, right:0\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 95644 characters]",
      "text/plain": [
       "<Figure size 800x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.9577544578567123e-32\n"
     ]
    }
   ],
   "source": [
    "factor_waist2 = 1.1\n",
    "\n",
    "trap[trap.power_tweezer1] = initial_power\n",
    "trap[trap.waist_tweezer1] = initial_waist\n",
    "trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "omega_r2 = sp.sqrt(2*trap.power_tweezer2*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer2**2\n",
    "\n",
    "#offset required for 1 level spacing of the left tweezer\n",
    "power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "#factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "power2_factor = factor_waist2**2 - 0.5*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "deltaEs = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10)\n",
    "\n",
    "print(deltaEs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:1, right:0\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 94664 characters]",
      "text/plain": [
       "<Figure size 800x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.2369169874679794e-31\n"
     ]
    }
   ],
   "source": [
    "factor_waist2 = 1.\n",
    "\n",
    "trap[trap.power_tweezer1] = initial_power\n",
    "trap[trap.waist_tweezer1] = initial_waist\n",
    "trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "omega_r2 = sp.sqrt(2*trap.power_tweezer2*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer2**2\n",
    "\n",
    "#offset required for 1 level spacing of the left tweezer\n",
    "power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "#factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "power2_factor = factor_waist2**2 - 0.5*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "deltaEs = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10)\n",
    "\n",
    "print(deltaEs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Analyse how minimal energy difference behaves with fraction of level spacing:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:1, right:0\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 94664 characters]",
      "text/plain": [
       "<Figure size 800x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.2369169874680354e-31\n"
     ]
    }
   ],
   "source": [
    "initial_power = 50* si.uW\n",
    "initial_waist = 1.1*si.uW\n",
    "initial_distance = 3*si.um\n",
    "\n",
    "factor_waist2 = 1.\n",
    "\n",
    "trap[trap.power_tweezer1] = initial_power\n",
    "trap[trap.waist_tweezer1] = initial_waist\n",
    "trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "\n",
    "#offset required for 1 level spacing of the left tweezer\n",
    "power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "#factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "power2_factor = factor_waist2**2 - 0.5*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "deltaEs = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10)\n",
    "\n",
    "print(deltaEs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n"
     ]
    }
   ],
   "source": [
    "level_spacings = np.linspace(0,1,20)\n",
    "relative_waists = np.linspace(1,1.1,4)\n",
    "delta_E = np.full((len(level_spacings),len(relative_waists)),np.nan)\n",
    "\n",
    "for i, space_fac in enumerate(level_spacings):\n",
    "    for j, factor_waist2 in enumerate(relative_waists):\n",
    "\n",
    "        trap[trap.power_tweezer1] = initial_power\n",
    "        trap[trap.waist_tweezer1] = initial_waist\n",
    "        trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "        omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "\n",
    "        #offset required for 1 level spacing of the left tweezer\n",
    "        power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "        #factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "        power2_factor = factor_waist2**2 - space_fac*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "        delta_E[i,j] = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10,plot=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 79924 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for j, factor_waist2 in enumerate(relative_waists):\n",
    "    plt.plot(level_spacings, delta_E[:,j],label=f\"waist ratio: {factor_waist2:.3f}\")\n",
    "\n",
    "plt.axhline(float(trap.subs(const.hbar*omega_r1))*0.1,color=\"k\",label=\"10% of level spacing\")\n",
    "    \n",
    "plt.xlabel(\"power offset as fraction of level spacing\")\n",
    "plt.ylabel(\"minimum energy gap\")\n",
    "plt.title(f\"tweezer1: p0={initial_power/si.uW:.2f}uW, w0={initial_waist/si.um:.2f}um\")\n",
    "#plt.yscale(\"log\")\n",
    "plt.legend()\n",
    "plt.grid()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Try at different power and waist:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:1, right:0\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 74524 characters]",
      "text/plain": [
       "<Figure size 800x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.071882919254056e-31\n"
     ]
    }
   ],
   "source": [
    "initial_power = 100* si.uW\n",
    "initial_waist = 1.1*si.uW\n",
    "\n",
    "factor_waist2 = 1.\n",
    "\n",
    "trap[trap.power_tweezer1] = initial_power\n",
    "trap[trap.waist_tweezer1] = initial_waist\n",
    "trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "\n",
    "#offset required for 1 level spacing of the left tweezer\n",
    "power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "#factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "power2_factor = factor_waist2**2 - 0.5*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "deltaEs = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10)\n",
    "\n",
    "print(deltaEs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\naeve\\AppData\\Local\\Temp\\ipykernel_21460\\1111512266.py:24: RuntimeWarning: All-NaN slice encountered\n",
      "  row_diff = np.nanmin(np.abs(energies_left[:,i] - energies_right[:,j]))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n"
     ]
    }
   ],
   "source": [
    "level_spacings = np.linspace(0,1,20)\n",
    "relative_waists = np.linspace(1,1.1,4)\n",
    "delta_E = np.full((len(level_spacings),len(relative_waists)),np.nan)\n",
    "\n",
    "for i, space_fac in enumerate(level_spacings):\n",
    "    for j, factor_waist2 in enumerate(relative_waists):\n",
    "\n",
    "        trap[trap.power_tweezer1] = initial_power\n",
    "        trap[trap.waist_tweezer1] = initial_waist\n",
    "        trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "        omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "\n",
    "        #offset required for 1 level spacing of the left tweezer\n",
    "        power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "        #factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "        power2_factor = factor_waist2**2 - space_fac*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "        delta_E[i,j] = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10,plot=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 67912 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for j, factor_waist2 in enumerate(relative_waists):\n",
    "    plt.plot(level_spacings, delta_E[:,j],label=f\"waist ratio: {factor_waist2:.3f}\")\n",
    "\n",
    "plt.axhline(float(trap.subs(const.hbar*omega_r1))*0.1,color=\"k\",label=\"10% of level spacing\")\n",
    "    \n",
    "plt.xlabel(\"power offset as fraction of level spacing\")\n",
    "plt.ylabel(\"minimum energy gap\")\n",
    "plt.title(f\"tweezer1: p0={initial_power/si.uW:.2f}uW, w0={initial_waist/si.um:.2f}um\")\n",
    "#plt.yscale(\"log\")\n",
    "plt.legend()\n",
    "plt.grid()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We see that the energy gap is larger for larger powers. This is expected, since a higher depth also means higher level spacing."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:1, right:0\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 78348 characters]",
      "text/plain": [
       "<Figure size 800x400 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8.084158826331112e-32\n"
     ]
    }
   ],
   "source": [
    "initial_power = 50* si.uW\n",
    "initial_waist = 2.2*si.uW\n",
    "initial_distance = 5*si.um\n",
    "\n",
    "factor_waist2 = 1.\n",
    "\n",
    "trap[trap.power_tweezer1] = initial_power\n",
    "trap[trap.waist_tweezer1] = initial_waist\n",
    "trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "\n",
    "#offset required for 1 level spacing of the left tweezer\n",
    "power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "#factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "power2_factor = factor_waist2**2 - 0.5*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "deltaEs = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10)\n",
    "\n",
    "print(deltaEs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:0, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\naeve\\AppData\\Local\\Temp\\ipykernel_21460\\1111512266.py:24: RuntimeWarning: All-NaN slice encountered\n",
      "  row_diff = np.nanmin(np.abs(energies_left[:,i] - energies_right[:,j]))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "crossover\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:4, right:4\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n"
     ]
    }
   ],
   "source": [
    "level_spacings = np.linspace(0,1,20)\n",
    "relative_waists = np.linspace(1,1.1,4)\n",
    "delta_E = np.full((len(level_spacings),len(relative_waists)),np.nan)\n",
    "\n",
    "for i, space_fac in enumerate(level_spacings):\n",
    "    for j, factor_waist2 in enumerate(relative_waists):\n",
    "\n",
    "        trap[trap.power_tweezer1] = initial_power\n",
    "        trap[trap.waist_tweezer1] = initial_waist\n",
    "        trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "        omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "\n",
    "        #offset required for 1 level spacing of the left tweezer\n",
    "        power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "        #factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "        power2_factor = factor_waist2**2 - space_fac*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "        delta_E[i,j] = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10,plot=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 78144 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for j, factor_waist2 in enumerate(relative_waists):\n",
    "    plt.plot(level_spacings, delta_E[:,j],label=f\"waist ratio: {factor_waist2:.3f}\")\n",
    "\n",
    "plt.axhline(float(trap.subs(const.hbar*omega_r1))*0.1,color=\"k\",label=\"10% of level spacing\")\n",
    "    \n",
    "plt.xlabel(\"power offset as fraction of level spacing\")\n",
    "plt.ylabel(\"minimum energy gap\")\n",
    "plt.title(f\"tweezer1: p0={initial_power/si.uW:.2f}uW, w0={initial_waist/si.um:.2f}um\")\n",
    "#plt.yscale(\"log\")\n",
    "plt.legend()\n",
    "plt.grid()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Larger waists decrease the depth and also the energy gap.\n",
    "\n",
    "## Let's calculate this for more combinations of power and waist:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\naeve\\AppData\\Local\\Temp\\ipykernel_21460\\1111512266.py:24: RuntimeWarning: All-NaN slice encountered\n",
      "  row_diff = np.nanmin(np.abs(energies_left[:,i] - energies_right[:,j]))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:0, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n"
     ]
    }
   ],
   "source": [
    "initial_powers = np.linspace(50,1000,10)*si.uW\n",
    "initial_waists = np.linspace(0.7,2.2,10)*si.um\n",
    "delta_E = np.full((len(initial_powers),len(initial_waists)),np.nan)\n",
    "\n",
    "for i, pow in enumerate(initial_powers):\n",
    "    for j, wai in enumerate(initial_waists):\n",
    "\n",
    "        space_fac = 0.42\n",
    "        factor_waist2 = 1\n",
    "\n",
    "        initial_power = pow\n",
    "        initial_waist = wai\n",
    "        initial_distance = 5*si.um\n",
    "\n",
    "        trap[trap.power_tweezer1] = initial_power\n",
    "        trap[trap.waist_tweezer1] = initial_waist\n",
    "        trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "        omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "\n",
    "        #offset required for 1 level spacing of the left tweezer\n",
    "        power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "        #factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "        power2_factor = factor_waist2**2 - space_fac*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "        delta_E[i,j] = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10,plot=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 26440 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(delta_E,extent=[np.min(initial_waists)/si.uW,np.max(initial_waists)/si.uW,np.min(initial_powers)/si.um,np.max(initial_powers)/si.um],origin=\"lower\",aspect=\"auto\")\n",
    "plt.colorbar()\n",
    "plt.ylabel(\"Power (uW)\")\n",
    "plt.xlabel(\"Waist (um)\")\n",
    "plt.title(\"Energy Difference\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\naeve\\AppData\\Local\\Temp\\ipykernel_21460\\382801629.py:24: RuntimeWarning: All-NaN slice encountered\n",
      "  row_diff = np.nanmin(np.abs(energies_left[:,i] - energies_right[:,j]))\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "closest approach between states: left:1, right:0\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n",
      "crossover\n"
     ]
    }
   ],
   "source": [
    "initial_powers = np.linspace(50,1000,10)*si.uW\n",
    "initial_waists = np.linspace(0.7,2.2,10)*si.um\n",
    "delta_E = np.full((len(initial_powers),len(initial_waists)),np.nan)\n",
    "\n",
    "for i, pow in enumerate(initial_powers):\n",
    "    for j, wai in enumerate(initial_waists):\n",
    "\n",
    "        space_fac = 0.42\n",
    "        factor_waist2 = 1.05\n",
    "\n",
    "        initial_power = pow\n",
    "        initial_waist = wai\n",
    "        initial_distance = 5*si.um\n",
    "\n",
    "        trap[trap.power_tweezer1] = initial_power\n",
    "        trap[trap.waist_tweezer1] = initial_waist\n",
    "        trap[trap.waist_tweezer2] = initial_waist*factor_waist2\n",
    "\n",
    "        omega_r1 = sp.sqrt(2*trap.power_tweezer1*trap.a/sp.pi/trap.m)*2/trap.waist_tweezer1**2\n",
    "\n",
    "        #offset required for 1 level spacing of the left tweezer\n",
    "        power2_offset = sp.pi*trap.waist_tweezer2**2*const.hbar*omega_r1/2/trap.a\n",
    "\n",
    "        #factor to match trap depth and offset by half(or another fraction of) the level spacing\n",
    "        power2_factor = factor_waist2**2 - space_fac*float(trap.subs(power2_offset))/initial_power\n",
    "\n",
    "        delta_E[i,j] = get_deltaE(initial_power,initial_power*power2_factor,initial_waist,initial_waist*factor_waist2,n_levels=10,plot=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 24160 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(delta_E,extent=[np.min(initial_waists)/si.uW,np.max(initial_waists)/si.uW,np.min(initial_powers)/si.um,np.max(initial_powers)/si.um],origin=\"lower\",aspect=\"auto\")\n",
    "plt.colorbar()\n",
    "plt.ylabel(\"Power (uW)\")\n",
    "plt.xlabel(\"Waist (um)\")\n",
    "plt.title(\"Energy Difference\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
