Lab 5 Python 3 Code and Figures
December 3, 2023
[29]: import numpy as np
import matplotlib.pyplot as plt
A = np.loadtxt("Pt 1 (A).txt")
B = np.loadtxt("Pt 1 (B).txt")
C = np.loadtxt("Pt 1 (C).txt")
D = np.loadtxt("Pt 1 (D).txt")
E = np.loadtxt("Pt 1 (E).txt")
F = np.loadtxt("Pt 1 (F).txt")
WA = A[:,0]
AA = A[:,1]
WB = B[:,0]
AB = B[:,1]
WC = C[:,0]
AC = C[:,1]
WD = D[:,0]
AD = D[:,1]
WE = E[:,0]
AE = E[:,1]
WF = F[:,0]
AF = F[:,1]
ax = plt.axes()
ax.plot(WA, AA, color = "black", label = "Solution A")
ax.plot(WB, AB, color = "orange", label = "Solution B")
ax.plot(WC, AC, color = "purple", label = "Solution C")
ax.plot(WD, AD, color = "pink", label = "Solution D")
ax.plot(WE, AE, color = "green", label = "Solution E")
ax.plot(WF, AF, color = "blue", label = "Solution F")
fs = 10
plt.xlabel("Wavelength [nm]", {"fontsize": fs})
1
plt.ylabel("Intensity [arb.]", {"fontsize": fs})
plt.title("Figure 1. Absorbance spectra of Cy7 Solutions", {"fontsize": fs});
ax.legend();
[30]: import numpy as np
import matplotlib.pyplot as plt
B = np.loadtxt("Pt 1 (B).txt")
WB = B[:,0]
AB = B[:,1]
MB = np.max(np.array([B[:,1]]))
print("The peak absorbance of Solution B was " + str(MB) + ".")
ax = plt.axes()
ax.plot(WB, AB, color = "orange", label = "Solution B")
ax.plot(B[450, 0], MB, "o", color = "red", label = "Peak Absorbance")
fs = 10
plt.xlabel("Wavelength [nm]", {"fontsize": fs})
plt.ylabel("Intensity [arb.]", {"fontsize": fs})
2
plt.title("Absorbance spectrum of Solution B", {"fontsize": fs});
ax.legend();
ext = 240000 # Liters per mol per centimeter
def Beers(A, ext):
return A / (1 * ext)
ConB = Beers(MB, ext)
print("The concentration of Cy7 in Solution B was " + str(ConB) + " M.")
The peak absorbance of Solution B was 1.027.
The concentration of Cy7 in Solution B was 4.279166666666666e-06 M.
[31]: import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
B = np.loadtxt("Pt 1 (B).txt")
C = np.loadtxt("Pt 1 (C).txt")
3
D = np.loadtxt("Pt 1 (D).txt")
E = np.loadtxt("Pt 1 (E).txt")
F = np.loadtxt("Pt 1 (F).txt")
MB = np.max(np.array([B[:,1]]))
MC = np.max(np.array([C[:,1]]))
MD = np.max(np.array([D[:,1]]))
ME = np.max(np.array([E[:,1]]))
MF = np.max(np.array([F[:,1]]))
ext = 240000 # Liters per mol per centimeter
def Beers(A, ext):
return (A / (1 * ext)) * (10 ** 6)
CyB = Beers(MB, ext)
CyC = Beers(MC, ext)
CyD = Beers(MD, ext)
CyE = Beers(ME, ext)
CyF = Beers(MF, ext)
TB = 0 # TCEP concentration in Solution B in micromolars
TC = 0.5 # TCEP concentration in Solution C in micromolars
TD = 1.5 # TCEP concentration in Solution D in micromolars
TE = 5 # TCEP concentration in Solution E in micromolars
TF = 15 # TCEP concentration in Solution F in micromolars
Cy = np.array([CyB, CyC, CyD, CyE, CyF])
T = np.array([TB, TC, TD, TE, TF])
def decay(x, a, b, c, d):
return (a / ((b * x) + c)) + d
pars, cov = curve_fit(f = decay, xdata = T, ydata = Cy, p0 = [1, 1, 1, 1],␣
↪bounds = (-np.inf, np.inf))
ax = plt.axes()
ax.plot(TB, CyB, "o", color = "orange", label = "Solution B")
ax.plot(TC, CyC, "o", color = "purple", label = "Solution C")
ax.plot(TD, CyD, "o", color = "pink", label = "Solution D")
ax.plot(TE, CyE, "o", color = "green", label = "Solution E")
ax.plot(TF, CyF, "o", color = "blue", label = "Solution F")
ax.plot(T, decay(T, *pars), color = "red", label = "Curve Fit")
fs = 10
plt.xlabel("TCEP Concentration [$\mu$M]", {"fontsize": fs})
plt.ylabel("Cy7 Concentration [$\mu$M]", {"fontsize": fs})
plt.title("Figure 2. Titration of Cy7 and TCEP", {"fontsize": fs});
4
ax.legend();
[32]: import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
C = np.loadtxt("Pt 2 (C2).txt")
tC = C[:,0]
AC = C[:,1]
tC_fit = tC[5:29]
AC_fit = AC[5:29]
def decay(t, a, k, c):
return (a * np.exp(-k * t)) + c
pars, cov = curve_fit(f = decay, xdata = tC_fit, ydata = AC_fit, p0 = [1, 0,␣
↪0], bounds = (-np.inf, np.inf))
k1 = pars[2]
5
print("The reaction constant of the reaction is {} Hz.".format(k1))
fs = 10
ax = plt.axes()
ax.plot(tC, AC, color = "purple", label = "Solution C")
ax.plot(C[5, 0], C[5,1], "o", color = "red")
ax.plot(C[28, 0], C[28,1], "o", color = "red")
ax.plot(tC_fit, decay(tC_fit, *pars), color = "red", label = "Curve Fit")
plt.xlabel("Time [s]", {"fontsize": fs})
plt.ylabel("Intensity [arb.]", {"fontsize": fs})
plt.title("Figure 3. Absorbance decay of Solution C excited with UV light",␣
↪{"fontsize": fs});
ax.legend();
The reaction constant of the reaction is 0.47210753170888037 Hz.
[33]: import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
6
D = np.loadtxt("Pt 2 (D2).txt")
tD = D[:,0]
AD = D[:,1]
tD_fit = tD[31:59]
AD_fit = AD[31:59]
def decay(t, a, k, c):
return (a * np.exp(-k * t)) + c
pars, cov = curve_fit(f = decay, xdata = tD_fit, ydata = AD_fit, p0 = [1, 0,␣
↪0], bounds = (-np.inf, np.inf))
k2 = pars[2]
print("The reaction constant of the reaction is {} Hz.".format(k2))
fs = 10
ax = plt.axes()
ax.plot(tD, AD, color = "pink", label = "Solution D")
ax.plot(D[31, 0], D[31,1], "o", color = "red")
ax.plot(D[58, 0], D[58,1], "o", color = "red")
ax.plot(tD_fit, decay(tD_fit, *pars), color = "red", label = "Curve Fit")
plt.xlabel("Time [s]", {"fontsize": fs})
plt.ylabel("Intensity [arb.]", {"fontsize": fs})
plt.title("Figure 4. Absorbance decay of Solution D excited with UV light",␣
↪{"fontsize": fs});
ax.legend();
The reaction constant of the reaction is 0.5003146463754398 Hz.
7
[35]: import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
E = np.loadtxt("Pt 2 (E2).txt")
tE = E[:,0]
AE = E[:,1]
tE_fit = tE[7:71]
AE_fit = AE[7:71]
def decay(t, a, k, c):
return (a * np.exp(-k * t)) + c
pars, cov = curve_fit(f = decay, xdata = tE_fit, ydata = AE_fit, p0 = [1, 0,␣
↪0], bounds = (-np.inf, np.inf))
k3 = pars[2]
print("The reaction constant of the reaction is {} Hz.".format(k3))
8
fs = 10
ax = plt.axes()
ax.plot(tE, AE, color = "green", label = "Solution E")
ax.plot(E[7, 0], E[7,1], "o", color = "red")
ax.plot(E[71, 0], E[71,1], "o", color = "red")
ax.plot(tE_fit, decay(tE_fit, *pars), color = "red", label = "Curve Fit")
plt.xlabel("Wavelength [nm]", {"fontsize": fs})
plt.ylabel("Intensity [arb.]", {"fontsize": fs})
plt.title("Figure 5. Absorbance decay of Solution E excited with UV light",␣
↪{"fontsize": fs});
ax.legend();
The reaction constant of the reaction is 0.5019103984079036 Hz.
[36]: import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
F = np.loadtxt("Pt 2 (F2).txt")
9
tF = F[:,0]
AF = F[:,1]
tF_fit = tF[10:60]
AF_fit = AF[10:60]
def decay(t, a, k, c):
return (a * np.exp(-k * t)) + c
pars, cov = curve_fit(f = decay, xdata = tF_fit, ydata = AF_fit, p0 = [1, 0,␣
↪0], bounds = (-np.inf, np.inf))
k4 = pars[2]
print("The reaction constant of the reaction is {} Hz.".format(k4))
fs = 10
ax = plt.axes()
ax.plot(tF, AF, color = "blue", label = "Solution F")
ax.plot(F[10, 0], F[10,1], "o", color = "red")
ax.plot(F[60, 0], F[60,1], "o", color = "red")
ax.plot(tF_fit, decay(tF_fit, *pars), color = "red", label = "Curve Fit")
plt.xlabel("Wavelength [nm]", {"fontsize": fs})
plt.ylabel("Intensity [arb.]", {"fontsize": fs})
plt.title("Figure 6. Absorbance decay of Solution F excited with UV light",␣
↪{"fontsize": fs});
ax.legend();
The reaction constant of the reaction is 0.5111944497701563 Hz.
10
[37]: import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
T = np.array([1 / TC, 1 / TD, 1 / TE, 1 / TF])
k = np.array([1 / k1, 1 / k2, 1 / k3, 1 / k4])
def line(x, m, b):
return (m * x) + b
pars, cov = curve_fit(f = line, xdata = T, ydata = k, p0 = [0, 0], bounds =␣
↪(-np.inf, np.inf))
ax = plt.axes()
ax.plot(1 / TC, 1 / k1, "o", color = "purple", label = "Solution C")
ax.plot(1 / TD, 1 / k2, "o", color = "pink", label = "Solution D")
ax.plot(1 / TE, 1 / k3, "o", color = "green", label = "Solution E")
ax.plot(1 / TF, 1 / k4, "o", color = "blue", label = "Solution F")
ax.plot(T, line(T, *pars), color = "red", label = "Curve Fit")
fs = 10
11
plt.xlabel("Inverse of TCEP Concentration [1/$\mu$M]", {"fontsize": fs})
plt.ylabel("Inverse of Reaction Constant [s]", {"fontsize": fs})
plt.title("Figure 7. Lineweaver-Burk plot for solutions C, D, E, and F",␣
↪{"fontsize": fs});
ax.legend();
[ ]:
12