-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nernst_Together.py
49 lines (43 loc) · 1.62 KB
/
Nernst_Together.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
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Global Constants
Faraday = 96485
R = 8.314
Temp = 310.15
class Nernst():
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):
plt.scatter([0,1,2,3], [0, 0, volts, volts])
plt.plot([0,1,2,3], [0, 0, volts, volts])
plt.ylim(-100,100)
plt.xlim(0,3)
xlabs = np.arange(0, 3, 1.0)
bins = ['','Channel Closed', 'Channel Open','']
plt.xticks(xlabs, bins)
plt.text(2, volts+5, str(round(volts, 2)))
plt.title("Membrane Potential Single Ion Species")
plt.xlabel("Membrane Permeability")
plt.ylabel("Voltage (mV)")
plt.legend(['Sodium', 'Chloride', 'Potassium'])
if __name__ == "__main__":
file = pd.read_csv('C:\\Users\\ajh\\Desktop\\ions.txt',
names=['name', 'charge', 'temperature', 'inner', 'outer'],
dtype={'name':str, 'charge':int, 'temperature':int, 'inner':int, 'outer':float},skiprows=1)
df = pd.DataFrame(file)
Nernst = Nernst()
for index,row in file.iterrows():
potential = Nernst.equilibrium(Temp,row.charge,row.inner,row.outer)
Nernst.viz(potential*1000)
plt.show()