Skip to content

Instantly share code, notes, and snippets.

@kaizu
Last active April 28, 2017 08:41
Show Gist options
  • Save kaizu/20f59b672ebb5c7dd04f671991a4f8ad to your computer and use it in GitHub Desktop.
Save kaizu/20f59b672ebb5c7dd04f671991a4f8ad to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from IPython.display import display, Math, Latex"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from ecell4 import *\n",
"from ecell4.extra import latex\n",
"from ecell4.util.decorator_base import just_parse"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"with reaction_rules():\n",
" A + B == C | (1.0, 2.0)\n",
"\n",
"m = get_model()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\begin{eqnarray}\n",
"\\frac{\\mathrm{d} \\left[A\\right]}{\\mathrm{d} t} &=& -v_{1}+v_{2},\\\\\n",
"\\frac{\\mathrm{d} \\left[B\\right]}{\\mathrm{d} t} &=& -v_{1}+v_{2},\\\\\n",
"\\frac{\\mathrm{d} \\left[C\\right]}{\\mathrm{d} t} &=& v_{1}-v_{2},\\\\\n",
"v_{1} &=& k_{1}\\left[A\\right]\\left[B\\right],\\\\\n",
"v_{2} &=& k_{2}\\left[C\\right],\\\\\n",
"k_{1} &=& 1.0,\\\\\n",
"k_{2} &=& 2.0\n",
"\\end{eqnarray}\n"
]
}
],
"source": [
"print(latex.equations(m))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\\begin{eqnarray}\n",
"\\frac{\\mathrm{d} \\left[A\\right]}{\\mathrm{d} t} &=& -v_{1}+v_{2},\\\\\n",
"\\frac{\\mathrm{d} \\left[B\\right]}{\\mathrm{d} t} &=& -v_{1}+v_{2},\\\\\n",
"\\frac{\\mathrm{d} \\left[C\\right]}{\\mathrm{d} t} &=& v_{1}-v_{2},\\\\\n",
"v_{1} &=& k_{1}\\left[A\\right]\\left[B\\right],\\\\\n",
"v_{2} &=& k_{2}\\left[C\\right],\\\\\n",
"k_{1} &=& 1.0,\\\\\n",
"k_{2} &=& 2.0\n",
"\\end{eqnarray}"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"latex.display_equations(m)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"with reaction_rules():\n",
" A + 2 * B > 3 * C | 1.0\n",
" C > 2 * A + B | 2.0\n",
"\n",
"m = get_model()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"A+2*B>3*C|1\n",
"C>2*A+B|2\n"
]
}
],
"source": [
"show(m)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\\begin{eqnarray}\n",
"\\frac{\\mathrm{d} \\left[A\\right]}{\\mathrm{d} t} &=& -v_{1}+2 v_{2},\\\\\n",
"\\frac{\\mathrm{d} \\left[B\\right]}{\\mathrm{d} t} &=& -2 v_{1}+v_{2},\\\\\n",
"\\frac{\\mathrm{d} \\left[C\\right]}{\\mathrm{d} t} &=& 3 v_{1}-v_{2},\\\\\n",
"v_{1} &=& \\left[A\\right]\\left[B\\right],\\\\\n",
"v_{2} &=& 2\\left[C\\right]\n",
"\\end{eqnarray}"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"latex.display_equations(m, constants=False)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"with reaction_rules():\n",
" S > P | 1.0 * E * S / (10.0 + S)\n",
" # S > P | ((1.0 * E * S / (10.0 + S)) ** (20.0 + P))\n",
" # S > P | E ** (S + 10) ** 5\n",
"\n",
"m = get_model()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"S+E>P+E|((1.0*E*S)/(10.0+S))\n"
]
}
],
"source": [
"show(m)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\\begin{eqnarray}\n",
"\\frac{\\mathrm{d} \\left[P\\right]}{\\mathrm{d} t} &=& \\frac{k_{1}\\left[E\\right]\\left[S\\right]}{k_{2}+\\left[S\\right]},\\\\\n",
"\\frac{\\mathrm{d} \\left[S\\right]}{\\mathrm{d} t} &=& -\\frac{k_{1}\\left[E\\right]\\left[S\\right]}{k_{2}+\\left[S\\right]},\\\\\n",
"k_{1} &=& 1.0,\\\\\n",
"k_{2} &=& 10.0\n",
"\\end{eqnarray}"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"latex.display_equations(m, inline=True, constants=True)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"a, b, c = 0.2, 0.2, 5.7\n",
"\n",
"with reaction_rules():\n",
" ~x > x | (-y - z)\n",
" ~y > y | (x + a * y)\n",
" ~z > z | (b + z * (x - c))\n",
"\n",
"m = get_model()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\\begin{eqnarray}\n",
"\\frac{\\mathrm{d} \\left[x\\right]}{\\mathrm{d} t} &=& \\left(-\\left[y\\right]-\\left[z\\right]\\right),\\\\\n",
"\\frac{\\mathrm{d} \\left[y\\right]}{\\mathrm{d} t} &=& \\left(\\left[x\\right]+k_{1}\\left[y\\right]\\right),\\\\\n",
"\\frac{\\mathrm{d} \\left[z\\right]}{\\mathrm{d} t} &=& \\left(k_{2}+\\left[z\\right]\\left(\\left[x\\right]-k_{3}\\right)\\right),\\\\\n",
"k_{1} &=& 0.2,\\\\\n",
"k_{2} &=& 0.2,\\\\\n",
"k_{3} &=& 5.7\n",
"\\end{eqnarray}"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"latex.display_equations(m, inline=True)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"del m"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"Q10 = 3.0\n",
"GNa = 120.0 # mS/cm^2\n",
"GK = 36.0 # mS/cm^2\n",
"gL = 0.3 # mS/cm^2\n",
"EL = -64.387 # mV\n",
"ENa = 40.0 # mV\n",
"EK = -87.0 # mV\n",
"Cm = 1.0 # uF/cm^2\n",
"\n",
"T = 6.3 # degrees C\n",
"Iext = 10.0 # nA\n",
"\n",
"with reaction_rules():\n",
" Q = Q10 ** ((T - 6.3) / 10)\n",
"\n",
" alpha_m = -0.1 * (Vm + 50) / (exp(-(Vm + 50) / 10) - 1)\n",
" beta_m = 4 * exp(-(Vm + 75) / 18)\n",
" ~m > m | Q * (alpha_m * (1 - m) - beta_m * m)\n",
"\n",
" alpha_h = 0.07 * exp(-(Vm + 75) / 20)\n",
" beta_h = 1.0 / (exp(-(Vm + 45) / 10) + 1)\n",
" ~h > h | Q * (alpha_h * (1 - h) - beta_h * h)\n",
"\n",
" alpha_n = -0.01 * (Vm + 65) / (exp(-(Vm + 65) / 10) - 1)\n",
" beta_n = 0.125 * exp(-(Vm + 75) / 80)\n",
" ~n > n | Q * (alpha_n * (1 - n) - beta_n * n)\n",
"\n",
" gNa = (m ** 3) * h * GNa\n",
" INa = gNa * (Vm - ENa)\n",
" gK = (n ** 4) * GK\n",
" IK = gK * (Vm - EK)\n",
" IL = gL * (Vm - EL)\n",
" ~Vm > Vm | (Iext - (IL + INa + IK)) / Cm\n",
"\n",
"m = get_model()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"\\begin{eqnarray}\n",
"\\frac{\\mathrm{d} \\left[Vm\\right]}{\\mathrm{d} t} &=& \\frac{k_{30}-\\left(k_{31}\\left(\\left[Vm\\right]-k_{32}\\right)+{\\left[m\\right]}^{k_{33}}\\left[h\\right]k_{34}\\left(\\left[Vm\\right]-k_{35}\\right)+{\\left[n\\right]}^{k_{36}}k_{37}\\left(\\left[Vm\\right]-k_{38}\\right)\\right)}{k_{39}},\\\\\n",
"\\frac{\\mathrm{d} \\left[h\\right]}{\\mathrm{d} t} &=& k_{11}\\left(k_{12}{\\exp} \\left(\\frac{-\\left(\\left[Vm\\right]+k_{13}\\right)}{k_{14}}\\right)\\left(k_{15}-\\left[h\\right]\\right)-\\frac{k_{16}}{{\\exp} \\left(\\frac{-\\left(\\left[Vm\\right]+k_{17}\\right)}{k_{18}}\\right)+k_{19}}\\left[h\\right]\\right),\\\\\n",
"\\frac{\\mathrm{d} \\left[m\\right]}{\\mathrm{d} t} &=& k_{1}\\left(\\frac{k_{2}\\left(\\left[Vm\\right]+k_{3}\\right)}{{\\exp} \\left(\\frac{-\\left(\\left[Vm\\right]+k_{4}\\right)}{k_{5}}\\right)-k_{6}}\\left(k_{7}-\\left[m\\right]\\right)-k_{8}{\\exp} \\left(\\frac{-\\left(\\left[Vm\\right]+k_{9}\\right)}{k_{10}}\\right)\\left[m\\right]\\right),\\\\\n",
"\\frac{\\mathrm{d} \\left[n\\right]}{\\mathrm{d} t} &=& k_{20}\\left(\\frac{k_{21}\\left(\\left[Vm\\right]+k_{22}\\right)}{{\\exp} \\left(\\frac{-\\left(\\left[Vm\\right]+k_{23}\\right)}{k_{24}}\\right)-k_{25}}\\left(k_{26}-\\left[n\\right]\\right)-k_{27}{\\exp} \\left(\\frac{-\\left(\\left[Vm\\right]+k_{28}\\right)}{k_{29}}\\right)\\left[n\\right]\\right),\\\\\n",
"k_{1} &=& 1.0,\\\\\n",
"k_{2} &=& -0.1,\\\\\n",
"k_{3} &=& 50,\\\\\n",
"k_{4} &=& 50,\\\\\n",
"k_{5} &=& 10,\\\\\n",
"k_{6} &=& 1,\\\\\n",
"k_{7} &=& 1,\\\\\n",
"k_{8} &=& 4,\\\\\n",
"k_{9} &=& 75,\\\\\n",
"k_{10} &=& 18,\\\\\n",
"k_{11} &=& 1.0,\\\\\n",
"k_{12} &=& 0.07,\\\\\n",
"k_{13} &=& 75,\\\\\n",
"k_{14} &=& 20,\\\\\n",
"k_{15} &=& 1,\\\\\n",
"k_{16} &=& 1.0,\\\\\n",
"k_{17} &=& 45,\\\\\n",
"k_{18} &=& 10,\\\\\n",
"k_{19} &=& 1,\\\\\n",
"k_{20} &=& 1.0,\\\\\n",
"k_{21} &=& -0.01,\\\\\n",
"k_{22} &=& 65,\\\\\n",
"k_{23} &=& 65,\\\\\n",
"k_{24} &=& 10,\\\\\n",
"k_{25} &=& 1,\\\\\n",
"k_{26} &=& 1,\\\\\n",
"k_{27} &=& 0.125,\\\\\n",
"k_{28} &=& 75,\\\\\n",
"k_{29} &=& 80,\\\\\n",
"k_{30} &=& 10.0,\\\\\n",
"k_{31} &=& 0.3,\\\\\n",
"k_{32} &=& -64.387,\\\\\n",
"k_{33} &=& 3,\\\\\n",
"k_{34} &=& 120.0,\\\\\n",
"k_{35} &=& 40.0,\\\\\n",
"k_{36} &=& 4,\\\\\n",
"k_{37} &=& 36.0,\\\\\n",
"k_{38} &=& -87.0,\\\\\n",
"k_{39} &=& 1.0\n",
"\\end{eqnarray}"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"latex.display_equations(m, inline=True, constants=True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment