// Created by libAntimony v2.13.0
function ap(ao, ai, bo, bi, ka, kb)
  (ao*bi - bo*ai)/(ka*kb*((1 + ai/ka + bi/kb)*(ao/ka + bo/kb) + (1 + ao/ka + bo/kb)*(ai/ka + bi/kb)));
end

function g(xi, xo)
  xi*xo*ln(xi/xo)/(xi - xo);
end


model *whitcomb04()

  // Compartments and Species:
  compartment plasma, cell, lumen;
  species $bb in plasma, $cb in plasma, $nb in plasma, bi in cell, ci in cell;
  species ni in cell, bl in lumen, $cl in lumen;

  // Assignment Rules:
  cl := 160 - bl;
  eb := (r*temp/f)*ln(bi/bl);
  enbc := (r*temp/f)*ln(bi^2*ni/(bb^2*nb));
  ec := (r*temp/f)*ln(ci/cl);
  ena := (r*temp/f)*ln(nb/ni);
  kccf := g(ci, cl)*gcftr*g_cl;
  kbcf := g(bi, bl)*gcftr*g_bi;
  knbc := gnbc;
  v := (knbc*enbc + kbcf*eb + kccf*ec + gk*ek + gnaleak*ena)/(knbc + kbcf + kccf + gk);
  jnbc := knbc*(v - enbc);
  jbcftr := kbcf*(v - eb);
  jccftr := kccf*(v - ec);
  japl := ap(bl, bi, cl, ci, kbi, kcl)*gapl;
  japbl := ap(bb, bi, cb, ci, kbi, kcl)*gapbl;
  jlum := (-(jccftr + jbcftr)*vr + jac*(1 + rat))/ionstr;
  jnak := gnak*(v - epump)*(ni/np0)^3;
  jnaleak := gnaleak*(v - ena);

  // Reactions:
  nbc: 2 $bb + $nb -> 2 bi + ni; cell*zeta*japl;
  bcftr: bl -> bi; cell*zeta*jbcftr;
  ccftr: $cl -> ci; cell*zeta*jccftr;
  apl: bl + ci -> bi + $cl; cell*zeta*japl;
  apbl: $bb + ci -> bi + $cb; cell*zeta*japbl;
  nak: ni -> $nb; cell*zeta*jnak;
  naleak: ni -> $nb; cell*zeta*jnaleak;
  buffering:  -> bi; cell*zeta*buf*(bi0 - bi);
  bac:  -> bl; lumen*zeta*jac*rat;
  cac:  -> $cl; lumen*zeta*jac;
  outflow: bl -> ; lumen*zeta*jlum*bl;

  // Events:
  _E0: at time >= ton: gcftr = gcftron;
  _E1: at time >= toff: gcftr = gcftrbase;

  // Species initializations:
  bb = 22;
  cb = 130;
  nb = 140;
  bi = 15;
  ci = 60;
  ni = 14;
  bl = 32;

  // Compartment initializations:
  plasma = 1;
  cell = 1;
  lumen = cell/vr;

  // Variable initializations:
  vr = 10;
  vr has dimensionless;
  ton = 60;
  ton has second;
  gcftr = gcftrbase;
  gcftr has L_per_volt_per_sec_per_m2;
  gcftron = 1;
  gcftron has L_per_volt_per_sec_per_m2;
  toff = 360;
  toff has second;
  gcftrbase = 7e-05;
  gcftrbase has L_per_volt_per_sec_per_m2;
  g_bi = 0.2;
  g_bi has dimensionless;
  g_cl = 1;
  g_cl has dimensionless;
  zeta = 50;
  zeta has m2_per_L;
  kbi = 1;
  kbi has mM;
  kcl = 10;
  kcl has mM;
  gnbc = 2;
  gnbc has mmol_per_volt_per_sec_per_m2;
  gapl = 0.25;
  gapl has mmol_per_volt_per_sec_per_m2;
  gapbl = 0.005;
  gapbl has mmol_per_volt_per_sec_per_m2;
  bi0 = 15;
  bi0 has mM;
  buf = 0.1;
  buf has L_per_sec_per_m2;
  ek = -0.085;
  ek has volt;
  gk = 1;
  gk has mmol_per_volt_per_sec_per_m2;
  r = 8.31451;
  r has J_per_mol_per_K;
  f = 96485;
  f has C_per_mol;
  temp = 310;
  temp has kelvin;
  ionstr = 160;
  ionstr has mM;
  gnak = 3.125;
  gnak has mmol_per_volt_per_sec_per_m2;
  np0 = 25;
  np0 has mM;
  epump = -0.2;
  epump has volt;
  gnaleak = 0.4;
  gnaleak has mmol_per_volt_per_sec_per_m2;
  jac = 0.025;
  jac has mmol_per_sec_per_m2;
  rat = 0.25;
  rat has dimensionless;
  eb has volt;
  enbc has volt;
  ec has volt;
  ena has volt;
  kccf has mmol_per_volt_per_sec_per_m2;
  kbcf has mmol_per_volt_per_sec_per_m2;
  knbc has mmol_per_volt_per_sec_per_m2;
  v has volt;
  jnbc has mmol_per_sec_per_m2;
  jbcftr has mmol_per_sec_per_m2;
  jccftr has mmol_per_sec_per_m2;
  japl has mmol_per_sec_per_m2;
  japbl has mmol_per_sec_per_m2;
  jlum has L_per_sec_per_m2;
  jnak has mmol_per_sec_per_m2;
  jnaleak has mmol_per_sec_per_m2;

  // Other declarations:
  var gcftr, eb, enbc, ec, ena, kccf, kbcf, knbc, v, jnbc, jbcftr, jccftr;
  var japl, japbl, jlum, jnak, jnaleak;
  const plasma, cell, lumen, vr, ton, gcftron, toff, gcftrbase, g_bi, g_cl;
  const zeta, kbi, kcl, gnbc, gapl, gapbl, bi0, buf, ek, gk, r, f, temp, ionstr;
  const gnak, np0, epump, gnaleak, jac, rat;

  // Unit definitions:
  unit substance = 1e-3 mole;
  unit mM = 1e-3 mole / litre;
  unit mmol_per_volt_per_sec_per_m2 = 1e-3 mole / (volt * second * metre^2);
  unit L_per_volt_per_sec_per_m2 = litre / (volt * second * metre^2);
  unit mmol_per_sec_per_m2 = 1e-3 mole / (second * metre^2);
  unit m2_per_L = metre^2 / litre;
  unit L_per_sec_per_m2 = litre / (second * metre^2);
  unit J_per_mol_per_K = joule / (mole * kelvin);
  unit C_per_mol = coulomb / mole;

  // Display Names:
  substance is "mmol";
  mmol_per_volt_per_sec_per_m2 is "mmol per volt per sec per m^2";
  L_per_volt_per_sec_per_m2 is "L per volt per sec per m^2";
  mmol_per_sec_per_m2 is "mmol per sec per m^2";
  m2_per_L is "m^2 per L";
  L_per_sec_per_m2 is "L per sec per m^2";
  J_per_mol_per_K is "J per mol per K";
  C_per_mol is "C per mol";
  bb is "HCO3-";
  cb is "CL-";
  nb is "Na+";
  bi is "HCO3-";
  ci is "CL-";
  ni is "Na+";
  bl is "HCO3-";
  cl is "CL-";
  r is "gas constant";
  f is "Faraday constant";

  // SBO terms:
  plasma.sboTerm = 290
  cell.sboTerm = 290
  lumen.sboTerm = 290
  vr.sboTerm = 196
  bb.sboTerm = 327
  cb.sboTerm = 327
  nb.sboTerm = 327
  bi.sboTerm = 327
  ci.sboTerm = 327
  ni.sboTerm = 327
  bl.sboTerm = 327
  cl.sboTerm = 327
  ton.sboTerm = 345
  gcftr.sboTerm = 196
  gcftron.sboTerm = 196
  toff.sboTerm = 345
  gcftrbase.sboTerm = 196
  g_bi.sboTerm = 9
  g_cl.sboTerm = 9
  zeta.sboTerm = 9
  kbi.sboTerm = 9
  kcl.sboTerm = 9
  gnbc.sboTerm = 257
  gapl.sboTerm = 257
  gapbl.sboTerm = 257
  bi0.sboTerm = 196
  buf.sboTerm = 196
  ek.sboTerm = 196
  gk.sboTerm = 196
  r.sboTerm = 567
  f.sboTerm = 568
  temp.sboTerm = 2
  ionstr.sboTerm = 196
  gnak.sboTerm = 9
  np0.sboTerm = 2
  epump.sboTerm = 9
  gnaleak.sboTerm = 9
  jac.sboTerm = 2
  rat.sboTerm = 2
  nbc.sboTerm = 185
  bcftr.sboTerm = 185
  ccftr.sboTerm = 185
  apl.sboTerm = 185
  apbl.sboTerm = 185
  nak.sboTerm = 185
  naleak.sboTerm = 185
  buffering.sboTerm = 176
  bac.sboTerm = 185
  cac.sboTerm = 185
  outflow.sboTerm = 185

  // CV terms:
  bb identity "http://identifiers.org/chebi/CHEBI:17544"
  cb identity "http://identifiers.org/chebi/CHEBI:17996"
  nb identity "http://identifiers.org/chebi/CHEBI:29101"
  bi identity "http://identifiers.org/chebi/CHEBI:17544"
  ci identity "http://identifiers.org/chebi/CHEBI:17996"
  ni identity "http://identifiers.org/chebi/CHEBI:29101"
  bl identity "http://identifiers.org/chebi/CHEBI:17544"
  cl identity "http://identifiers.org/chebi/CHEBI:17996"
end

whitcomb04 is "Whitcomb2004_Bicarbonate_Pancreas"

whitcomb04 model_entity_is "http://identifiers.org/biomodels.db/MODEL1104180000"
whitcomb04 model_entity_is "http://identifiers.org/biomodels.db/BIOMD0000000327"
whitcomb04 description "http://identifiers.org/pubmed/15257112"
whitcomb04 taxon "http://identifiers.org/taxonomy/9606",
                 "http://identifiers.org/bto/BTO:0002362"
whitcomb04 hypernym "http://identifiers.org/go/GO:0030157"
