-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNernst_Basic.py
87 lines (69 loc) · 2.1 KB
/
Nernst_Basic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import numpy as np
# Global Constants
Faraday = 96485
R = 8.314
class Nernst():
def temp(self):
"""
:args: none
:return: Temperature in Kelvins
"""
C = float(input("Temperature in Celsius"))
K = C + 273.15
return K
def valence(self):
"""
:args: none
:return: valence shell of ionic species
"""
v = int(input("Valence"))
return v
def innerConcentration(self):
"""
:args: none
:return: Concentration of ion species inside cellular membrane, in millimolars
"""
inner = float(input("Inner Concentration (mM)"))
return inner
def outerConcentration(self):
"""
:args: none
:return: Concentration of ion species outside of cellular membrane, in millimolars
"""
outer = float(input("Outer Concentration (mM)"))
return outer
def equilibrium(self, T, z, Xi, Xo):
"""
:param T: Temperature in Kelvins
:param z: Valence of ionic species
:param Xi: Inner membrane concentration
:param Xo: Outer membrane concentration
:return: Membrane potential for single species
"""
GasIons = (R*T)/(z*Faraday)
Concentrations = np.log(Xo/Xi)
membranePotential = GasIons*Concentrations
return membranePotential
def viz(self, volts):
"""
:param volts: Volage in mV
:return: none
"""
plt.scatter([0,1], [0, volts])
plt.plot([0,1], [0, volts])
plt.ylim(-100,100)
plt.xlim(0,2)
plt.xticks(np.arange(0, 2, 1.0))
plt.title("Membrane Potential Single Ion Species")
plt.xlabel("Time")
plt.ylabel("Voltage (mV")
plt.show()
if __name__ == "__main__":
Nernst = Nernst()
temperature = Nernst.temp()
charge = Nernst.valence()
inner = Nernst.innerConcentration()
outer = Nernst.outerConcentration()
membrane = Nernst.equilibrium(temperature, charge, inner, outer)
print("Result: " + str(membrane))
Nernst.viz(membrane*1000)