Skip to content

Commit d36273d

Browse files
committed
update channel models
1 parent adfb0b1 commit d36273d

File tree

5 files changed

+97
-103
lines changed

5 files changed

+97
-103
lines changed

brainpy/_src/dyn/channels/Ca.py

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
from typing import Union, Callable
99

10-
import jax.numpy as jnp
11-
1210
import brainpy.math as bm
1311
from brainpy._src.dyn.base import Channel
1412
from brainpy._src.initialize import OneInit, Initializer, parameter, variable
@@ -23,7 +21,7 @@
2321
'CalciumDetailed',
2422
'CalciumFirstOrder',
2523

26-
'ICa_p2q_ss', 'ICa_p2q_markov',
24+
'_ICa_p2q_ss', '_ICa_p2q_markov',
2725

2826
'ICaN_IS2008',
2927

@@ -141,12 +139,12 @@ def reset_state(self, V, C_Ca=None, E_Ca=None, batch_size=None):
141139

142140
def update(self, tdi, V):
143141
for node in self.nodes(level=1, include_self=False).unique().subset(Channel).values():
144-
node.update(tdi, V, self.C, self.E)
142+
node.update(tdi, V, self.C.value, self.E.value)
145143
self.C.value = self.integral(self.C.value, tdi['t'], V, tdi['dt'])
146-
self.E.value = self._reversal_potential(self.C)
144+
self.E.value = self._reversal_potential(self.C.value)
147145

148146
def _reversal_potential(self, C):
149-
return self._constant * jnp.log(self.C0 / C)
147+
return self._constant * bm.log(self.C0 / C)
150148

151149

152150
class CalciumDetailed(CalciumDyna):
@@ -292,7 +290,7 @@ def __init__(
292290

293291
def derivative(self, C, t, V):
294292
ICa = self.current(V, C, self.E)
295-
drive = jnp.maximum(- ICa / (2 * self.F * self.d), 0.)
293+
drive = bm.maximum(- ICa / (2 * self.F * self.d), 0.)
296294
return drive + (self.C_rest - C) / self.tau
297295

298296

@@ -335,14 +333,14 @@ def __init__(
335333

336334
def derivative(self, C, t, V):
337335
ICa = self.current(V, C, self.E)
338-
drive = jnp.maximum(- self.alpha * ICa, 0.)
336+
drive = bm.maximum(- self.alpha * ICa, 0.)
339337
return drive - self.beta * C
340338

341339

342340
# -------------------------
343341

344342

345-
class ICa_p2q_ss(CalciumChannel):
343+
class _ICa_p2q_ss(CalciumChannel):
346344
r"""The calcium current model of :math:`p^2q` current which described with steady-state format.
347345
348346
The dynamics of this generalized calcium current model is given by:
@@ -386,19 +384,19 @@ def __init__(
386384
mode: bm.Mode = None,
387385
name: str = None
388386
):
389-
super(ICa_p2q_ss, self).__init__(size,
390-
keep_size=keep_size,
391-
name=name,
392-
mode=mode, )
387+
super(_ICa_p2q_ss, self).__init__(size,
388+
keep_size=keep_size,
389+
name=name,
390+
mode=mode, )
393391

394392
# parameters
395393
self.phi_p = parameter(phi_p, self.varshape, allow_none=False)
396394
self.phi_q = parameter(phi_q, self.varshape, allow_none=False)
397395
self.g_max = parameter(g_max, self.varshape, allow_none=False)
398396

399397
# variables
400-
self.p = variable(jnp.zeros, self.mode, self.varshape)
401-
self.q = variable(jnp.zeros, self.mode, self.varshape)
398+
self.p = variable(bm.zeros, self.mode, self.varshape)
399+
self.q = variable(bm.zeros, self.mode, self.varshape)
402400

403401
# functions
404402
self.integral = odeint(JointEq([self.dp, self.dq]), method=method)
@@ -435,7 +433,7 @@ def f_q_tau(self, V):
435433
raise NotImplementedError
436434

437435

438-
class ICa_p2q_markov(CalciumChannel):
436+
class _ICa_p2q_markov(CalciumChannel):
439437
r"""The calcium current model of :math:`p^2q` current which described with first-order Markov chain.
440438
441439
The dynamics of this generalized calcium current model is given by:
@@ -479,19 +477,19 @@ def __init__(
479477
name: str = None,
480478
mode: bm.Mode = None,
481479
):
482-
super(ICa_p2q_markov, self).__init__(size,
483-
keep_size=keep_size,
484-
name=name,
485-
mode=mode)
480+
super(_ICa_p2q_markov, self).__init__(size,
481+
keep_size=keep_size,
482+
name=name,
483+
mode=mode)
486484

487485
# parameters
488486
self.phi_p = parameter(phi_p, self.varshape, allow_none=False)
489487
self.phi_q = parameter(phi_q, self.varshape, allow_none=False)
490488
self.g_max = parameter(g_max, self.varshape, allow_none=False)
491489

492490
# variables
493-
self.p = variable(jnp.zeros, self.mode, self.varshape)
494-
self.q = variable(jnp.zeros, self.mode, self.varshape)
491+
self.p = variable(bm.zeros, self.mode, self.varshape)
492+
self.q = variable(bm.zeros, self.mode, self.varshape)
495493

496494
# functions
497495
self.integral = odeint(JointEq([self.dp, self.dq]), method=method)
@@ -592,31 +590,31 @@ def __init__(
592590
self.phi = parameter(phi, self.varshape, allow_none=False)
593591

594592
# variables
595-
self.p = variable(jnp.zeros, self.mode, self.varshape)
593+
self.p = variable(bm.zeros, self.mode, self.varshape)
596594

597595
# function
598596
self.integral = odeint(self.derivative, method=method)
599597

600598
def derivative(self, p, t, V):
601-
phi_p = 1.0 / (1 + jnp.exp(-(V + 43.) / 5.2))
602-
p_inf = 2.7 / (jnp.exp(-(V + 55.) / 15.) + jnp.exp((V + 55.) / 15.)) + 1.6
599+
phi_p = 1.0 / (1 + bm.exp(-(V + 43.) / 5.2))
600+
p_inf = 2.7 / (bm.exp(-(V + 55.) / 15.) + bm.exp((V + 55.) / 15.)) + 1.6
603601
return self.phi * (phi_p - p) / p_inf
604602

605603
def update(self, tdi, V, C_Ca, E_Ca):
606-
self.p.value = self.integral(self.p, tdi['t'], V, tdi['dt'])
604+
self.p.value = self.integral(self.p.value, tdi['t'], V, tdi['dt'])
607605

608606
def current(self, V, C_Ca, E_Ca):
609607
M = C_Ca / (C_Ca + 0.2)
610608
g = self.g_max * M * self.p
611609
return g * (self.E - V)
612610

613611
def reset_state(self, V, C_Ca, E_Ca, batch_size=None):
614-
self.p.value = 1.0 / (1 + jnp.exp(-(V + 43.) / 5.2))
612+
self.p.value = 1.0 / (1 + bm.exp(-(V + 43.) / 5.2))
615613
if batch_size is not None:
616614
assert self.p.shape[0] == batch_size
617615

618616

619-
class ICaT_HM1992(ICa_p2q_ss):
617+
class ICaT_HM1992(_ICa_p2q_ss):
620618
r"""The low-threshold T-type calcium current model proposed by (Huguenard & McCormick, 1992) [1]_.
621619
622620
The dynamics of the low-threshold T-type calcium current model [1]_ is given by:
@@ -697,22 +695,22 @@ def __init__(
697695
self.V_sh = parameter(V_sh, self.varshape, allow_none=False)
698696

699697
def f_p_inf(self, V):
700-
return 1. / (1 + jnp.exp(-(V + 59. - self.V_sh) / 6.2))
698+
return 1. / (1 + bm.exp(-(V + 59. - self.V_sh) / 6.2))
701699

702700
def f_p_tau(self, V):
703-
return 1. / (jnp.exp(-(V + 132. - self.V_sh) / 16.7) +
704-
jnp.exp((V + 16.8 - self.V_sh) / 18.2)) + 0.612
701+
return 1. / (bm.exp(-(V + 132. - self.V_sh) / 16.7) +
702+
bm.exp((V + 16.8 - self.V_sh) / 18.2)) + 0.612
705703

706704
def f_q_inf(self, V):
707-
return 1. / (1. + jnp.exp((V + 83. - self.V_sh) / 4.0))
705+
return 1. / (1. + bm.exp((V + 83. - self.V_sh) / 4.0))
708706

709707
def f_q_tau(self, V):
710-
return jnp.where(V >= (-80. + self.V_sh),
711-
jnp.exp(-(V + 22. - self.V_sh) / 10.5) + 28.,
712-
jnp.exp((V + 467. - self.V_sh) / 66.6))
708+
return bm.where(V >= (-80. + self.V_sh),
709+
bm.exp(-(V + 22. - self.V_sh) / 10.5) + 28.,
710+
bm.exp((V + 467. - self.V_sh) / 66.6))
713711

714712

715-
class ICaT_HP1992(ICa_p2q_ss):
713+
class ICaT_HP1992(_ICa_p2q_ss):
716714
r"""The low-threshold T-type calcium current model for thalamic
717715
reticular nucleus proposed by (Huguenard & Prince, 1992) [1]_.
718716
@@ -795,21 +793,21 @@ def __init__(
795793
self.V_sh = parameter(V_sh, self.varshape, allow_none=False)
796794

797795
def f_p_inf(self, V):
798-
return 1. / (1. + jnp.exp(-(V + 52. - self.V_sh) / 7.4))
796+
return 1. / (1. + bm.exp(-(V + 52. - self.V_sh) / 7.4))
799797

800798
def f_p_tau(self, V):
801-
return 3. + 1. / (jnp.exp((V + 27. - self.V_sh) / 10.) +
802-
jnp.exp(-(V + 102. - self.V_sh) / 15.))
799+
return 3. + 1. / (bm.exp((V + 27. - self.V_sh) / 10.) +
800+
bm.exp(-(V + 102. - self.V_sh) / 15.))
803801

804802
def f_q_inf(self, V):
805-
return 1. / (1. + jnp.exp((V + 80. - self.V_sh) / 5.))
803+
return 1. / (1. + bm.exp((V + 80. - self.V_sh) / 5.))
806804

807805
def f_q_tau(self, V):
808-
return 85. + 1. / (jnp.exp((V + 48. - self.V_sh) / 4.) +
809-
jnp.exp(-(V + 407. - self.V_sh) / 50.))
806+
return 85. + 1. / (bm.exp((V + 48. - self.V_sh) / 4.) +
807+
bm.exp(-(V + 407. - self.V_sh) / 50.))
810808

811809

812-
class ICaHT_HM1992(ICa_p2q_ss):
810+
class ICaHT_HM1992(_ICa_p2q_ss):
813811
r"""The high-threshold T-type calcium current model proposed by (Huguenard & McCormick, 1992) [1]_.
814812
815813
The high-threshold T-type calcium current model is adopted from [1]_.
@@ -886,29 +884,29 @@ def __init__(
886884
self.V_sh = parameter(V_sh, self.varshape, allow_none=False)
887885

888886
# variables
889-
self.p = variable(jnp.zeros, self.mode, self.varshape)
890-
self.q = variable(jnp.zeros, self.mode, self.varshape)
887+
self.p = variable(bm.zeros, self.mode, self.varshape)
888+
self.q = variable(bm.zeros, self.mode, self.varshape)
891889

892890
# function
893891
self.integral = odeint(JointEq([self.dp, self.dq]), method=method)
894892

895893
def f_p_inf(self, V):
896-
return 1. / (1. + jnp.exp(-(V + 59. - self.V_sh) / 6.2))
894+
return 1. / (1. + bm.exp(-(V + 59. - self.V_sh) / 6.2))
897895

898896
def f_p_tau(self, V):
899-
return 1. / (jnp.exp(-(V + 132. - self.V_sh) / 16.7) +
900-
jnp.exp((V + 16.8 - self.V_sh) / 18.2)) + 0.612
897+
return 1. / (bm.exp(-(V + 132. - self.V_sh) / 16.7) +
898+
bm.exp((V + 16.8 - self.V_sh) / 18.2)) + 0.612
901899

902900
def f_q_inf(self, V):
903-
return 1. / (1. + jnp.exp((V + 83. - self.V_sh) / 4.))
901+
return 1. / (1. + bm.exp((V + 83. - self.V_sh) / 4.))
904902

905903
def f_q_tau(self, V):
906-
return jnp.where(V >= (-80. + self.V_sh),
907-
jnp.exp(-(V + 22. - self.V_sh) / 10.5) + 28.,
908-
jnp.exp((V + 467. - self.V_sh) / 66.6))
904+
return bm.where(V >= (-80. + self.V_sh),
905+
bm.exp(-(V + 22. - self.V_sh) / 10.5) + 28.,
906+
bm.exp((V + 467. - self.V_sh) / 66.6))
909907

910908

911-
class ICaHT_Re1993(ICa_p2q_markov):
909+
class ICaHT_Re1993(_ICa_p2q_markov):
912910
r"""The high-threshold T-type calcium current model proposed by (Reuveni, et al., 1993) [1]_.
913911
914912
HVA Calcium current was described for neocortical neurons by Sayer et al. (1990).
@@ -994,19 +992,19 @@ def __init__(
994992

995993
def f_p_alpha(self, V):
996994
temp = -27 - V + self.V_sh
997-
return 0.055 * temp / (jnp.exp(temp / 3.8) - 1)
995+
return 0.055 * temp / (bm.exp(temp / 3.8) - 1)
998996

999997
def f_p_beta(self, V):
1000-
return 0.94 * jnp.exp((-75. - V + self.V_sh) / 17.)
998+
return 0.94 * bm.exp((-75. - V + self.V_sh) / 17.)
1001999

10021000
def f_q_alpha(self, V):
1003-
return 0.000457 * jnp.exp((-13. - V + self.V_sh) / 50.)
1001+
return 0.000457 * bm.exp((-13. - V + self.V_sh) / 50.)
10041002

10051003
def f_q_beta(self, V):
1006-
return 0.0065 / (jnp.exp((-15. - V + self.V_sh) / 28.) + 1.)
1004+
return 0.0065 / (bm.exp((-15. - V + self.V_sh) / 28.) + 1.)
10071005

10081006

1009-
class ICaL_IS2008(ICa_p2q_ss):
1007+
class ICaL_IS2008(_ICa_p2q_ss):
10101008
r"""The L-type calcium channel model proposed by (Inoue & Strowbridge, 2008) [1]_.
10111009
10121010
The L-type calcium channel model is adopted from (Inoue, et, al., 2008) [1]_.
@@ -1080,15 +1078,15 @@ def __init__(
10801078
self.V_sh = parameter(V_sh, self.varshape, allow_none=False)
10811079

10821080
def f_p_inf(self, V):
1083-
return 1. / (1 + jnp.exp(-(V + 10. - self.V_sh) / 4.))
1081+
return 1. / (1 + bm.exp(-(V + 10. - self.V_sh) / 4.))
10841082

10851083
def f_p_tau(self, V):
1086-
return 0.4 + .7 / (jnp.exp(-(V + 5. - self.V_sh) / 15.) +
1087-
jnp.exp((V + 5. - self.V_sh) / 15.))
1084+
return 0.4 + .7 / (bm.exp(-(V + 5. - self.V_sh) / 15.) +
1085+
bm.exp((V + 5. - self.V_sh) / 15.))
10881086

10891087
def f_q_inf(self, V):
1090-
return 1. / (1. + jnp.exp((V + 25. - self.V_sh) / 2.))
1088+
return 1. / (1. + bm.exp((V + 25. - self.V_sh) / 2.))
10911089

10921090
def f_q_tau(self, V):
1093-
return 300. + 100. / (jnp.exp((V + 40 - self.V_sh) / 9.5) +
1094-
jnp.exp(-(V + 40 - self.V_sh) / 9.5))
1091+
return 300. + 100. / (bm.exp((V + 40 - self.V_sh) / 9.5) +
1092+
bm.exp(-(V + 40 - self.V_sh) / 9.5))

0 commit comments

Comments
 (0)