% JYBfig07.ode
% Ref: Wu et al., J Theor B2008;252:711-21

% Initial values of the variables
init v=-74.0, nK=0.288, hK=0.367, mNa=0.041,  hNa=0.844, nIR=0.003, rIR=0.282, ni=0.657

% Values of the model parameters
params cm=1, gnabar=15, gkbar=8, girbar=1.0, gl=0.05, vna=50, vk=-80, vir=-80, vl=-80
params koi=0.081, kio=0.001, f=0.9

% Gating functions
alphaNam(v) = 0.1*(v+40)/( 1 - exp(-0.09*(v+40)))
betaNam(v) =  4*exp(-0.055*(v+70))
mNainf(v) = 1/(1+betaNam(v)/alphaNam(v))
tauNam(v) = 1/(alphaNam(v) + betaNam(v))

alphaNah(v) =  0.07*exp(-0.05*(v+70))
betaNah(v) = 1/( 1 + exp(-0.09*(v+25)) )
hNainf(v) = 1/(1+betaNah(v)/alphaNah(v))
tauNah(v) = 1/(alphaNah(v) + betaNah(v))

alphaKn(v) = 0.01*(v + 60)/(1 - exp(-0.1*(V + 60)))
betaKn(v) = 0.125*exp(-0.0125*(V + 70))
nKinf(v) = 1/(1+betaKn(v)/alphaKn(v))
tauKn(v) = 1/(alphaKn(v) + betaKn(v))

alphaKh(v) = 0.001*exp(-0.04*(v+70))
betaKh(v) = 0.001*exp(-0.0195*(v+40))
hKinf(v) = 1/(1+betaKh(v)/alphaKh(v))
tauKh(v) = 1/(alphaKh(v) + betaKh(v))

alphaIRn(v) = 0.00035*exp(0.07*(v+25))
betaIRn(v) = 0.09/(1+exp(0.11*(v+100)))
nIRinf(v) = 1/(1+betaIRn(v)/alphaIRn(v))
tauIRn(v) = 1/(alphaIRn(v) + betaIRn(v))

alphaIRr(v) = 30/(1+exp(0.04*(v+230)))
betaIRr(v) = 0.15/(1+exp(-0.05*(v+120)))
rIRinf(v) = 1/(1+betaIRr(v)/alphaIRr(v))
tauIRr(v) = 1/(alphaIRr(v) + betaIRr(v))

alpha_n3(v)=-0.021*(v+8.3)/(exp(-(v+8.3)/9.8)-1)
beta_n3(v)=0.0002*exp(-(v+23.6)/20.7)

% Applied current pulse 
param ia1=1.4, t1=30, dt1=530
param ia2=0, t2=0, dt2=0
param ia3=0, t3=0, dt3=0
i(amp,t0,dt)=amp*(heav(t-t0)-heav(t-t0-dt))
ia=i(ia1,t1,dt1)+i(ia2,t2,dt2)+i(ia3,t3,dt3)

% Differential equations
v' =  -(gnabar*mNa^3*hNa*(v-vna) + (1-f)*gkbar*nK^4*hK*(v-vk) + girbar*nIR*rIR*(v-vir) + f*gkbar*(nK^4)*ni*(v-vk) + gl*(v-vl) - ia)/cm
mNa' =  (mNainf(v) - mNa)/tauNam(v)
hNa' =  (hNainf(v) - hNa)/tauNah(v)
nK' =  (nKinf(v) - nK)/tauKn(v)
hK' = (hKinf(v) - hK)/tauKh(v)
nIR' = (nIRinf(v) - nIR)/tauIRn(v)
rIR' = (rIRinf(v) - rIR)/tauIRr(v)
ni' = kio*(1-ni)-koi*nK^4*ni

aux ik=(1-f)*gkbar*(nK^4)*hK*(v-vk)+f*gkbar*(nK^4)*ni*(v-vk)

% Numerical and plotting parameters for xpp
@ xlo=0, xhi=700, ylo=-90, yhi=+60, total=700, dt=0.05, method=Euler
@ bounds=10000

done