: BK-type calcium-activated potassium current from Purkinje neuron
: FORREST MD (2014) Simulation of alcohol action upon a detailed Purkinje neuron model and a simpler surrogate model that runs >400 times faster. BMC Neuroscience

NEURON {
       SUFFIX bkpkj
       USEION k READ ek WRITE ik
       USEION ca READ cai
       RANGE gkbar
       GLOBAL minf, mtau, hinf, htau, zinf, ztau
       GLOBAL m_vh, m_k, mtau_y0, mtau_vh1, mtau_vh2, mtau_k1, mtau_k2
       GLOBAL z_coef, ztau
       GLOBAL h_y0, h_vh, h_k, htau_y0, htau_vh1, htau_vh2, htau_k1, htau_k2
}

UNITS {
      (mV) = (millivolt)
      (mA) = (milliamp)
      (mM) = (milli/liter)
}

PARAMETER {
          v            (mV)
          gkbar = .007 (mho/cm2)

          m_vh = -28.9           (mV)
          m_k = 6.2            (mV)
          mtau_y0 = .000505     (s)
          mtau_vh1 = -33.3     (mV)
          mtau_k1 = -10         (mV)
          mtau_vh2 = 86.4       (mV)
          mtau_k2 = 10.1        (mV)

          z_coef = .001        (mM)
          ztau = 1              (ms)

          h_y0 = .085
          h_vh = -32          (mV)
          h_k = 5.8             (mV)
          htau_y0 = .0019      (s)
          htau_vh1 = -54.2       (mV)
          htau_k1 = -12.9       (mV)
          htau_vh2 = 48.5      (mV)
          htau_k2 = 5.2        (mV)

          ek           (mV)
          cai          (mM)
Q10 = 3 (1) 
  Q10TEMP = 22 (degC) 

}

ASSIGNED {
         minf
         mtau          (ms)
         hinf
         htau          (ms)
         zinf

         ik            (mA/cm2)

celsius (degC) 
  qt (1) 
}

STATE {
      m   FROM 0 TO 1
      z   FROM 0 TO 1
      h   FROM 0 TO 1
}

BREAKPOINT {
           SOLVE states METHOD cnexp
           ik = gkbar * m * m * m * z * z * h * (v - ek)
}

DERIVATIVE states {
        rates(v)

        m' = (minf - m) / mtau
        h' = (hinf - h) / htau
        z' = (zinf - z) / ztau
}

PROCEDURE rates(Vm (mV)) {
          LOCAL v
          v = Vm + 5
          minf = 1 / (1 + exp(-(v - (m_vh)) / m_k))
          mtau = ((1e3) * (mtau_y0 + 1/(exp((v+ mtau_vh1)/mtau_k1) + exp((v+mtau_vh2)/mtau_k2)))) / qt
          zinf = 1/(1 + z_coef / cai)
          hinf = h_y0 + (1-h_y0) / (1+exp((v - h_vh)/h_k))
          htau = ((1e3) * (htau_y0 + 1/(exp((v + htau_vh1)/htau_k1)+exp((v+htau_vh2)/htau_k2)))) / qt
}

INITIAL {
        rates(v)
        m = minf
        z = zinf
        h = hinf
: qt = Q10^((celsius-Q10TEMP)/10) 
qt = 1
}