<jupyter_start><jupyter_text>Forward potential sweep The prelab for E5 presents a crude cyclic voltammogram model of redox species in a stagnant electrolyte system. Code block 1 calculates current versus potential response based off this model for a positive potential sweep. This generates an interactive plot window. Running code block 2 will overlay new plots to the interactive window under code block 1. Running code block 1 will reset the interactive window.In the prelab you will examine the effect of changing scan rate 'v' and initial scan potential 'Einitial' by overlaying different plots.<jupyter_code>'''Code block 1'''

# constants
R = 8.314        # gas constant in J/mol*K
T = 298          # temperature in K
n = 1            # number of electrons transferred per rxn
F = 96485        # electronic charge in C/mol
A = 1            # area in cm^2
D = 1e-5         # diffusion constant in cm^2/s
ctotal = 1e-6    # total concentration in mol/cm^3
E0 = 0           # standard reduction potential in V
Einit = E0 - 0.2 # initial potential in V
v = 1            # sweep rate in V/s

# this creates a time array from 0.01 to 0.6 at 0.01 intervals
t = np.arange(0.01, 0.6, 0.01)

# Cell potential as a function of time (equation 7 in the prelab)
Ecell = Einit+v*t

# concentration of reduced species intinitely far away from electrode and at the electrode (equations 4-5 in prelab)
c_red_inf = ctotal/ (1+exp((Einit-E0) / (R*T/n/F)))
c_red_zero = ctotal/ (1+exp((Ecell-E0) / (R*T/n/F)))

# Change in concentration of the reduced species from infinity to the electrode (equation 3 in the prelab)
Deltac = c_red_inf - c_red_zero

# depletion layer thickness (equation 6 in the prelab)
delta = sqrt(4*D*t)

# current during forward sweep (equation 1 in the prelab)
i_f = n*F*A*D*Deltac/delta

# plot current vs cell potential

# plt.plot(Ecell, i_f, label = 'Forward $v$ = '+str(v)+' V/s; $E_{init}$ = '+str(Einit)+' V')
# plt.xlabel('Potential / V')
# plt.ylabel('Current / A')
# plt.ticklabel_format(axis="both", style="sci", scilimits=(-2,3))
# plt.legend()


'''Code block 2'''

# constants
R = 8.314        # gas constant in J/mol*K
T = 298          # temperature in K
n = 1            # number of electrons transferred per rxn
F = 96485        # electronic charge in C/mol
A = 1            # area in cm^2
D = 1e-5         # diffusion constant in cm^2/s
ctotal = 1e-6    # total concentration in mol/cm^3
E0 = 0           # standard reduction potential in V
Einit = E0 - 0.30 # initial potential in V
v = 1            # sweep rate in V/s

# this creates a time array from 0.01 to 0.6 at 0.01 intervals
t = np.arange(0.01, 0.6, 0.01)

# Cell potential as a function of time (equation 7 in the prelab)
Ecell = Einit + v*t

# concentration of reduced species intinitely far away from electrode and at the electrode (equations 4-5 in prelab)
c_red_inf = ctotal/ (1+exp((Einit-E0) / (R*T/n/F)))
c_red_zero = ctotal/ (1+exp((Ecell-E0) / (R*T/n/F)))

# Change in concentration of the reduced species from infinity to the electrode (equation 3 in the prelab)
Deltac = c_red_inf - c_red_zero

# depletion layer thickness (equation 6 in the prelab)
delta = sqrt(4*D*t)

# current during forward sweep (equation 1 in the prelab)
i_f = n*F*A*D*Deltac/delta

# plot current vs cell potential
# plt.plot(Ecell, i_f, label = 'Forward $v$ = '+str(v)+' V/s; $E_{init}$ = '+str(Einit)+' V')
# plt.xlabel('Potential / V')
# plt.ylabel('Current / A')
# plt.ticklabel_format(axis="both", style="sci", scilimits=(-2,3))
# plt.legend()
# plt.savefig('forward-scans')<jupyter_output><empty_output><jupyter_text>Full cyclic voltammogramCode blocks 3 and 4 calculates a full cyclic voltammogram based off the crude model. Code block 3 demonstrates a case where the reverse faradaic reaction cannot occur while code block 4 shows a case where it is included<jupyter_code>'''Code block 3 with no reaction'''

# constants
R=8.314        # gas constant in J/mol*K
T=298          # temperature in K
n=1            # number of electrons transferred per rxn
F=96485        # electronic charge in C/mol
A=1            # area in cm^2
D=1e-5         # diffusion constant in cm^2/s
ctotal=1e-6    # total concentration in mol/cm^3   
E0=0           # standard potential in V
Einit=-0.2  # initial potential in V
v=1            # sweep rate in V/s


'''forward scan (same as code block 1-2)'''
# this creates a time array from 0.01 to 0.6 at 0.01 intervals
t = np.arange(0.01, 0.6, 0.01)

# Cell potential as a function of time (equation 7 in the prelab)
Ecell = Einit+v*t

# concentration of reduced species intinitely far away from electrode and at the electrode (equations 4-5 in prelab)
c_red_inf=ctotal/(1+exp((Einit-E0)/(R*T/n/F)))
c_red_zero=ctotal/(1+exp((Ecell-E0)/(R*T/n/F)))

# Change in concentration of the reduced species from infinity to the electrode (equation 3 in the prelab)
Deltac=c_red_inf-c_red_zero

# depletion layer thickness (equation 6 in the prelab)
delta=sqrt(4*D*t)

# current during forward sweep (equation 1 in the prelab)
i_f=n*F*A*D*Deltac/delta


'''reverse scan'''
# the end potential of the forward scan and the start potential of the reverse scan 
Ereturn=0.4

# time array of the reverse scan
t_r = np.arange(0.61, 1.4, 0.01)

# cell potential as a function of time in the reverse scan 
Ecell_r=Ereturn-v*(t_r-0.6)

# concentration of reduced species intinitely far away from electrode and at the electrode during the reverse scan
c_red_inf=ctotal/(1+exp((Einit-E0)/(R*T/n/F)))
c_red_zero=ctotal/(1+exp((Ereturn-E0)/(R*T/n/F)))

# Change in concentration of the reduced species from infinity to the electrode 
Deltac=c_red_inf-c_red_zero

# depletion layer thickness during reverse scan
delta_r=sqrt(4*D*t_r)

# current during reverse sweep no reaction
i_r_nr=n*F*A*D*Deltac/delta_r

# plot current vs cell potential
# plt.close()
# plt.plot(Ecell, i_f, label = 'forward v = '+str(v)+' V/s; Einit ='+str(Einit)+' V')
# plt.plot(Ecell_r, i_r_nr, label = 'no reverse reaction')
# plt.xlabel('Potential / V')
# plt.ylabel('Current / A')
# plt.ticklabel_format(axis="both", style="sci", scilimits=(-2,3))
# plt.legend()
# # plt.savefig('nonfaradaic-reverse')


'''Code block 4 with back reaction'''

'''reverse scan'''
# the end potential of the forward scan and the start potential of the reverse scan 
Ereturn=0.4

# time array of the reverse scan
t_r = np.arange(0.61, 1.4, 0.01)

# cell potential as a function of time in the reverse scan 
Ecell_r=Ereturn-v*(t_r-0.6)

# concentration of reduced species intinitely far away from electrode and at the electrode during the reverse scan
c_red_inf=ctotal/(1+exp((Ereturn-E0)/(R*T/n/F)))
c_red_zero=ctotal/(1+exp((Ecell_r-E0)/(R*T/n/F)))

# Change in concentration of the reduced species from infinity to the electrode 
Deltac=c_red_inf-c_red_zero

# depletion layer thickness during reverse scan
delta=sqrt(4*D*(t_r-0.6))

# current during reverse sweep no reaction
i_r_r=i_r_nr+n*F*A*D*Deltac/delta

# plot current vs cell potential
plt.plot(Ecell, i_f, label = 'forward v = '+str(v)+' V/s; Einit ='+str(Einit)+' V')
plt.plot(Ecell_r, i_r_r, label = 'with reverse reaction')
plt.xlabel('Potential / V')
plt.ylabel('Current / A')
plt.ticklabel_format(axis="both", style="sci", scilimits=(-2,3))
plt.legend()
# plt.savefig('faradaic-reverse')
Ecell1 = np.concatenate((Ecell, Ecell_r))
iw = np.concatenate((i_f, i_r_r))
print(Ecell, iw)
data = pd.DataFrame(columns=['Ecell', 'iw', 't'])
data['Ecell'] = Ecell1
data['iw'] = iw
data['t'] = Ecell1 / v

# Store parameters
params = pd.DataFrame({'parameter': ['scan_rate'],
                       'value': [v]})
fake_CV = experiment(data, params)
fake_CV.to_excel()<jupyter_output>[-0.19 -0.18 -0.17 -0.16 -0.15 -0.14 -0.13 -0.12 -0.11 -0.1  -0.09 -0.08
 -0.07 -0.06 -0.05 -0.04 -0.03 -0.02 -0.01  0.    0.01  0.02  0.03  0.04
  0.05  0.06  0.07  0.08  0.09  0.1   0.11  0.12  0.13  0.14  0.15  0.16
  0.17  0.18  0.19  0.2   0.21  0.22  0.23  0.24  0.25  0.26  0.27  0.28
  0.29  0.3   0.31  0.32  0.33  0.34  0.35  0.36  0.37  0.38  0.39] [ 3.00708093e-07  5.26356174e-07  8.07616190e-07  1.18193597e-06
  1.69323018e-06  2.40084988e-06  3.38746315e-06  4.76886431e-06
  6.70674729e-06  9.42489802e-06  1.32283109e-05  1.85226191e-05
  2.58269987e-05  3.57664814e-05  4.90199459e-05  6.61932514e-05
  8.75974837e-05  1.12961476e-04  1.41198902e-04  1.70421690e-04
  1.98322133e-04  2.22803911e-04  2.42528172e-04  2.57099449e-04
  2.66888900e-04  2.72693997e-04  2.75430212e-04  2.75939332e-04
  2.74907945e-04  2.72855986e-04  2.70158288e-04  2.67075919e-04
  2.63786060e-04  2.60406380e-04  2.57013396e-04  2.53655677e-04
  2.50363070e-04  2.47153022e-04  2.44034862e-04  2.410[...]
{'fraction_non_alphanumeric': 0.12511510128913444, 'fraction_numerical': 0.09530386740331492, 'mean_word_length': 3.4673521850899744, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '562243', 'license': 'MIT', 'n_tokens_mistral': 3722, 'n_tokens_neox': 3272, 'n_words': 1018, 'path': 'Exercise-Notebooks/E5-Prelab.ipynb', 'repo_name': 'edward-mu/CHEM274', 'size': '8688'}