+{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[{"file_id":"1kTrDRr1Logxh8_dirw7fxJkfeOXs_WWW","timestamp":1644613029419}]},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["###**Model calculation: Rabi oscillations and quantum beats**\n","\n","\n","\n","> This code can be used to reproduce the data plotted in Figures 10 and 11 of Schultz et al., Coherence in chemistry: foundations and frontiers. *Chem. Revs.* (submitted)\n","\n","To begin, press the play button beside each cell (proceed sequentially through the cells). *Note: run either the \"site 1\" or \"eigenstate 1\" initial state cells and compare the calculated time evolution.*"],"metadata":{"id":"H2WPl-rvZSYR"}},{"cell_type":"code","source":["#@title Import libraries, prep plot settings\n","\n","import matplotlib.pyplot as plt\n","import numpy as np\n","from math import *\n","import cmath\n","from scipy import linalg\n","from IPython.display import set_matplotlib_formats\n","set_matplotlib_formats('svg')\n","\n","hbar = 1\n","\n","i_ = complex(0, 1)\n","\n","SMALL_SIZE = 18\n","MEDIUM_SIZE = 20\n","BIGGER_SIZE = 22\n","\n","plt.rc('font', size=SMALL_SIZE) # controls default text sizes\n","plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title\n","plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels\n","plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels\n","plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels\n","plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize\n","plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title"],"metadata":{"id":"Cv5auRqrYQme","cellView":"form"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["#@title Tunable parameters\n","\n","n = 1000 # number of points\n","tmax = 8 # max time value\n","E1 = 10\n","E2 = 10\n","V = 0.05*E1"],"metadata":{"id":"bSUnrx6SE5rl","executionInfo":{"status":"ok","timestamp":1692631157079,"user_tz":240,"elapsed":167,"user":{"displayName":"Quantum Coherence","userId":"04118399231983577771"}}},"execution_count":2,"outputs":[]},{"cell_type":"code","source":["#@title Set up arrays\n","\n","dt = tmax/n # timestep\n","t = np.arange(0,tmax,dt) # time vector\n","\n","H = np.array([[E1, V], [V, E2]], dtype='complex')\n","\n","eigval, eigvec = linalg.eigh(H)"],"metadata":{"id":"_mn6Z6jdY_zE","cellView":"form","executionInfo":{"status":"ok","timestamp":1692631158422,"user_tz":240,"elapsed":149,"user":{"displayName":"Quantum Coherence","userId":"04118399231983577771"}}},"execution_count":3,"outputs":[]},{"cell_type":"code","source":["#@title Initial state = site 1, projection to sites\n","\n","rho = np.array([[1, 0], [0, 0]], dtype='complex')\n","rho_eig = eigvec @ rho @ np.conjugate(eigvec.transpose())\n","\n","Proj1 = np.array([[1, 0], [0, 0]], dtype='complex')\n","Proj2 = np.array([[0, 0], [0, 1]], dtype='complex')\n","Proj1_eig = eigvec @ Proj1 @ np.conjugate(eigvec.transpose())\n","Proj2_eig = eigvec @ Proj2 @ np.conjugate(eigvec.transpose())"],"metadata":{"id":"P4v02bBtstsy","cellView":"form","executionInfo":{"status":"ok","timestamp":1692631161331,"user_tz":240,"elapsed":197,"user":{"displayName":"Quantum Coherence","userId":"04118399231983577771"}}},"execution_count":4,"outputs":[]},{"cell_type":"code","source":["#@title Initial state = eigenstate 1, projection to sites\n","\n","rho_eig = np.array([[1, 0], [0, 0]], dtype='complex')\n","\n","Proj1 = np.array([[1, 0], [0, 0]], dtype='complex')\n","Proj2 = np.array([[0, 0], [0, 1]], dtype='complex')\n","Proj1_eig = eigvec @ Proj1 @ np.conjugate(eigvec.transpose())\n","Proj2_eig = eigvec @ Proj2 @ np.conjugate(eigvec.transpose())"],"metadata":{"cellView":"form","id":"dp8TC20_szLz"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["#@title Calculate UNITARY time-evolution of density matrix\n","\n","def U(tn):\n"," return linalg.expm(-i_*np.diag(eigval)*tn)\n","\n","def Udag(tn):\n"," return np.transpose(np.conjugate(linalg.expm(-i_*np.diag(eigval)*tn)))\n","\n","P1 = np.zeros((n,))\n","P2 = np.zeros((n,))\n","rho_store = []\n","test = np.zeros((n,))\n","\n","for i in range(n):\n"," rho_time = U(t[i]) @ rho_eig.copy() @ Udag(t[i]) # Propagate the density matrix\n"," P1[i] = np.real(np.trace(rho_time @ Proj1_eig)) # Calculate the observable at time t\n"," P2[i] = np.real(np.trace(rho_time @ Proj2_eig)) # Calculate the observable at time t\n"," rho_store.append(rho_time)\n","\n","fig = plt.figure(figsize=(9,6))\n","ax = fig.add_subplot(1, 1, 1)\n","ax.plot(t,np.real(P1), 'r-', linewidth=1)\n","ax.plot(t,np.real(P2), 'r--', linewidth=3)\n","ax.xaxis.set_ticks([0])\n","ax.yaxis.set_ticks([0,1])\n","plt.xlabel(\"Time (arb. units)\")\n","plt.ylabel(\"Population\")\n","plt.legend(['$\\phi_1$', '$\\phi_2$'])\n","fig.tight_layout()\n","plt.savefig(\"output.svg\")"],"metadata":{"id":"LM5_ZsZnat77","cellView":"form"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["#@title Calculate beats for driven 3LS\n","\n","H3LS = np.array([[0, 0, 0], [0, E1, V], [0, V, E2]], dtype='complex')\n","eigval, eigvec = linalg.eigh(H3LS)\n","\n","total_signal = 2*np.cos((eigval[2]+eigval[1])*t)*np.cos(abs(eigval[2]-eigval[1])*t)\n","average_signal = 2*np.cos((eigval[2]+eigval[1])*t)\n","beat_signal = 2*np.cos(abs(eigval[2]-eigval[1])*t)\n","\n","\n","fig = plt.figure(figsize=(8,5))\n","ax = fig.add_subplot(1, 1, 1)\n","ax.plot(t,average_signal, 'b--', label =\"average\", linewidth=0.5)\n","ax.plot(t,beat_signal, 'r', label =\"beat\", linewidth=4)\n","ax.plot(t,total_signal, 'k', label =\"detected\", linewidth=2)\n","ax.xaxis.set_ticks([0])\n","ax.yaxis.set_ticks([])\n","plt.xlabel(\"Time (arb. units)\")\n","plt.ylabel(\"I(t) (arb. units)\")\n","plt.legend(['total', 'mean', 'beat'],loc =\"right\")\n","fig.tight_layout()\n","plt.savefig(\"output.svg\")"],"metadata":{"id":"jlftZRbX2nVW","cellView":"form"},"execution_count":null,"outputs":[]}]}
0 commit comments