# Beeler-Reuter Mammalian Ventricular Model 1977
#
# In contrast to the earlier Purkinje fibre ionic current models ofD. Noble
# (1962)andR.E. McAllister, D. Noble and R.W. Tsien (1975), the G.W. Beeler and
# H. Reuter 1977 model was developed to describe the mammalian ventricular action
# potential. Not all the ionic currents of the Purkinje fibre model are present
# in ventricular tissue; therefore, this model is simpler than the MNT model.
# The total ionic flux is divided into only four discrete, individual ionic
# currents (seebelow). The main additional feature of the Beeler-Reuter ionic
# current model is a representation of the intracellular calcium ion
# concentration.
#
# The complete original paper reference is cited below:
#
# Reconstruction of the action potential of ventricular myocardial fibres,
# Beeler, G.W. and Reuter, H. 1977Journal of Physiology, 268, 177-210.PubMed ID:
# 874889
#
# The membrane physically contains the currents as indicated by the blue arrows
# in. The currents act independently and are not connected to each other. Several
# of the channels encapsulateandcontain further components which represent
# activation and inactivation gates. The addition of an encapsulation
# relationship informs modellers and processing software that the gates are
# important parts of the current model. It also prevents any other components
# that aren't also encapsulated by the parent component from connecting to its
# gates, effectively hiding them from the rest of the model.
#
# The breakdown of the model into components and the definition of encapsulation
# and containment relationships between them is somewhat arbitrary. When
# considering how a model should be broken into components, modellers are
# encouraged to consider which parts of a model might be re-used and how the
# physiological elements of the system being modelled are naturally bounded.
# Containment relationships should be used to provide simple rendering
# information for processing software (ideally, this will correspond to the
# layout of the physical system), and encapsulation should be used to group sets
# of components into sub-models.
#

# gotran file generated by cellml2gotran from beeler_reuter_1977.cellml

parameters("Sodium current",
           g_Na = ScalarParam(4e-2, unit="mS*mm**-2"),
           E_Na = ScalarParam(50, unit="mV"),
           g_Nac = ScalarParam(3e-5, unit="mS*mm**-2"))

states("Sodium current", "Sodium current m gate",
       m = 0.011)

states("Sodium current", "Sodium current h gate",
       h = 0.988)

states("Sodium current", "Sodium current j gate",
       j = 0.975)

states("Slow inward current",
       Cai = ScalarParam(1e-4, unit="nmole*mm**-3"))

parameters("Slow inward current",
           g_s = ScalarParam(9e-4, unit="mS*mm**-2"))

states("Slow inward current", "Slow inward current d gate",
       d = 0.003)

states("Slow inward current", "Slow inward current f gate",
       f = 0.994)

states("Time dependent outward current", "Time dependent outward current x1 gate",
       x1 = 0.0001)

parameters("Stimulus protocol",
           IstimStart = ScalarParam(1, unit="ms"),
           IstimEnd = ScalarParam(50000, unit="ms"),
           IstimAmplitude = ScalarParam(0.5, unit="uA*mm**-2"),
           IstimPeriod = ScalarParam(1000, unit="ms"),
           IstimPulseDuration = ScalarParam(2, unit="ms"))

states("Membrane",
       V = ScalarParam(-84.624, unit="mV"))

parameters("Membrane",
           C = ScalarParam(0.01, unit="uF*mm**-2"))

component("Sodium current")
i_Na = (g_Na*m**3*h*j + g_Nac)*(V - E_Na)

component("Sodium current", "Sodium current m gate")
alpha_m = -1*(V + 47)/(exp(-0.1*(V + 47)) - 1)
beta_m = 40*exp(-0.056*(V + 72))
dm_dt = alpha_m*(1 - m) - beta_m*m

component("Sodium current", "Sodium current h gate")
alpha_h = 0.126*exp(-0.25*(V + 77))
beta_h = 1.7/(exp(-0.082*(V + 22.5)) + 1)
dh_dt = alpha_h*(1 - h) - beta_h*h

component("Sodium current", "Sodium current j gate")
alpha_j = 0.055*exp(-0.25*(V + 78))/(exp(-0.2*(V + 78)) + 1)
beta_j = 0.3/(exp(-0.1*(V + 32)) + 1)
dj_dt = alpha_j*(1 - j) - beta_j*j

component("Slow inward current")
E_s = -82.3 - 13.0287*log(Cai*0.001)
i_s = g_s*d*f*(V - E_s)
dCai_dt = -0.01*i_s/1 + 0.07*(0.0001 - Cai)

component("Slow inward current", "Slow inward current d gate")
alpha_d = 0.095*exp(-(V - 5)/100)/(1 + exp(-(V - 5)/13.89))
beta_d = 0.07*exp(-(V + 44)/59)/(1 + exp((V + 44)/20))
dd_dt = alpha_d*(1 - d) - beta_d*d

component("Slow inward current", "Slow inward current f gate")
alpha_f = 0.012*exp(-(V + 28)/125)/(1 + exp((V + 28)/6.67))
beta_f = 0.0065*exp(-(V + 30)/50)/(1 + exp(-(V + 30)/5))
df_dt = alpha_f*(1 - f) - beta_f*f

component("Time dependent outward current")
i_x1 = x1*8e-3*(exp(0.04*(V + 77)) - 1)/exp(0.04*(V + 35))

component("Time dependent outward current", "Time dependent outward current x1 gate")
alpha_x1 = 5e-4*exp((V + 50)/12.1)/(1 + exp((V + 50)/17.5))
beta_x1 = 0.0013*exp(-(V + 20)/16.67)/(1 + exp(-(V + 20)/25))
dx1_dt = alpha_x1*(1 - x1) - beta_x1*x1

component("Time independent outward current")
i_K1 = 0.0035*(4*(exp(0.04*(V + 85)) - 1)/(exp(0.08*(V + 53)) + exp(0.04*(V + 53))) + 0.2*(V + 23)/(1 - exp(-0.04*(V + 23))))

component("Stimulus protocol")
Istim = Conditional(And(Ge(time, IstimStart), Le(time, IstimStart+IstimPulseDuration)), IstimAmplitude, 0)

component("Membrane")
dV_dt = (Istim - (i_Na + i_s + i_x1 + i_K1))/C
