-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathel_ph.lua
More file actions
168 lines (127 loc) · 3.37 KB
/
Copy pathel_ph.lua
File metadata and controls
168 lines (127 loc) · 3.37 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
-- Electrophysiology and common stuff for nerve models --
module(..., package.seeall);
-- useful constants
R = 8314.4 -- Universal gaz constant, mJ / mole*K
F = 96485.34 -- Faraday constant Coulomb / mole
-- Diffusion coefficients in aqueous solutions --
-- [cm^2/s]
-- (Hille, B., Ionic Channels of Excitable Membranes)
Daq = {K = 1.96e-5, Na = 1.33e-5, H = 9.31e-5, Ca = 0.79e-5}
local gauss_mem = {}
setmetatable(gauss_mem, {__mode = "v"}) -- make gauss_mem weak
function gaussian(t,p)
--local key = t..'-'..p.t..'-'..p.w..'-'..p.a
--if gauss_mem[key] then
-- return gauss_mem[key]
--else
local x,g,z
z = 10
if (t - p.t) * (t - p.t) < z * p.w then
g = (t - p.t)^2
g = -.5*g / p.w
x = p.a * math.exp(g)
else x = 0 end
gauss_mem[key] = x
return x
--end
end
-- Some biophysics --
function NaKpump_flux(Ki, Ko, Nai, Nao, p)
-- mmole
-- NOTE: should return fluxes in --------
-- cm^2 s
-- version 1.0 -- no optimization
local jna, jk
local Km_na = p.a_na + p.b_na * Ki
local Km_k = p.a_k + p.b_k * Nao
local mm_na = 1 / (1 + Km_na/Nai)^3
local mm_k = 1 / (1 + Km_k/Ko)^2
jna = p.jnamax*mm_na*mm_k --+ arg.p.jrest
jk = -jna / 1.5
return {jna, jk}
end
-- Basic circuits --
function i2flux(I)
return I/(1e3*F)
end
function flux2i(flux)
return flux*1e3*F
end
function reciprocal(x) return 1/x end
function rsumr(values)
-- reciprocal of the summed reciprocals --
local res = 0
for i,g in ipairs(values) do
--for i = 1,#values do
res = res + 1/g
end
return 1/res
end
function sum(values)
local res = 0
for _,v in ipairs(values) do res = res+v end
return res
end
function series_resistances(rrr)
return sum(rrr)
end
function series_conductances(ggg)
return rsumr(ggg)
end
function parallel_resistances(rrr)
return rsumr(rrr)
end
function parallel_conductances(ggg)
return sum(ggg)
end
-- Electrochemistry functions --
function nernst(ci, co, T, z)
if not z then z = 1 end -- default charge
return R*T*math.log(co / ci)/(z*F)
end
-- GHK current equation --
function ghk(ci, co, V, T, z)
if not z then z = 1 end -- default charge
local x = V*F*z / (R*T)
if math.abs(V) < 1e-7 then
return (ci - co)*R*T/z
else
local y = math.exp(x)
return x*F*(co-ci*y)/(1 - y)
end
end
local ghk_mem = {}
setmetatable(ghk_mem, {__mode = "v"}) -- make ghk_mem weak
function make_subkey(vector)
local key = "-"
for i,val in ipairs(vector) do
key = key..'val'..'-'
end
return key
end
function ghk_rate_const(p,V)
local x = V + p[1]
local rc = (p[2]*x + p[3]) / (1 + p[4]*math.exp(x/p[5]))
return rc
end
function myelin_area(D, L)
--return math.pi*(D+d)*(L + .5*(D-d))
--return math.pi*(D*L + .5*(D^2 - d^2))
return math.pi*D*L
end
function ring_area(D, d)
return .25*math.pi*(D^2 - d^2)
end
function periaxonal_conductance(rho, d, h, l)
return ring_area(d + 2*h, d)/ (rho*l)
end
function myelin_conductance(gs, D, d, L, N)
-- two membranes per lamella
--return .5 * math.pi * gs * L * D / N
return myelin_area(D, L)*gs/(2*N)
end
function myelin_capacitance(cs, D, d,L, N)
-- two membranes per lamella
--return .5 * math.pi * cs * L * D / N
return cs *myelin_area(D, L) /(2*N)
end