# from Rho and Prescott, PLoS Comput Biol 2012
# to be run in XPP
# 3-D model with slow Na channel inactivation (see Fig 4); noise is also included here

# DIFFERENTIAL EQUATIONS

dv/dt = (Istim+sqrt(Qi)*ni-gna*minf(V)*h*(V-Vna)-gk*w*(V-VK)-gl*(V-Vl))/cap
dw/dt = phi_w*(winf(V)-w)/tauw(V)
dh/dt = (hinf(V)-h)/tauh

# TO IMPLEMENT NOISE
wiener ni
param Qi=1
# noise amplitude is adjusted by varying Qi. Remove noise by setting to 0

# FUNCTIONS AND PARAMETERS

minf(v)=.5*(1+tanh((v-beta_m)/gamma_m))
winf(v)=.5*(1+tanh((v-beta_w)/gamma_w))
hinf(v)= 1/(1+exp(-(v-beta_h)/gamma_h))

tauw(v)=1/cosh((v-beta_w)/(2*gamma_w))


param Istim=0 
param vna=50,vk=-100,vl=-70
param gk=20,gl=2,gna=20
param beta_m=-1.2,gamma_m=15
param beta_w=-13,gamma_w=10
# beta_w = -21 for transient spiking; beta_w = -13 for repetitive spiking
param phi_w=.15
param beta_h=-30,gamma_h=-5,tauh=2000
param cap=2

# INITIAL CONDITIONS
V(0)=-70
w(0)=0.000025
h(0)=1

# ALWAYS USE EULER! - Actually this is only true for noise
@ total=10000,dt=.05,xlo=-100,xhi=60,ylo=-.125,yhi=.6,xp=v,yp=w
@ meth=euler
@ MAXSTOR=1000000,bounds=10000

done