Skip to content

Commit

Permalink
print contents of the mod & nml file OpenSourceBrain#2
Browse files Browse the repository at this point in the history
  • Loading branch information
shayanshafquat committed Sep 7, 2022
1 parent aef42e4 commit fe98522
Showing 1 changed file with 322 additions and 7 deletions.
329 changes: 322 additions & 7 deletions parsemod/parse_mod_to_nml.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Import the modules required to generate neuroml file, present in ./parse_mod_file.py"
"Import the modules required to generate neuroml file, present in ./parse_mod_file.py"
]
},
{
Expand All @@ -21,7 +21,32 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Path to locate the MOD files and the path where to generate the nml file"
"Defining a method that helps us visualize the contents of the mod as well as the generated neuroml file"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"def file_content_line_by_line(path_to_file):\n",
" # Using readlines()\n",
" file1 = open(path_to_file, 'r')\n",
" Lines = file1.readlines()\n",
" \n",
" count = 0\n",
" # Strips the newline character\n",
" for line in Lines:\n",
" count += 1\n",
" print(\"{}\".format(line.strip()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Path to locate the MOD files and show how it looks:"
]
},
{
Expand All @@ -30,15 +55,213 @@
"metadata": {},
"outputs": [],
"source": [
"mod_file = \"./test/nat.mod\"\n",
"mod_file = \"./test/nat.mod\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Contents of the mod file"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"COMMENT\n",
"26 Ago 2002 Modification of original channel to allow variable time step and to correct an initialization error.\n",
"Done by Michael Hines([email protected]) and Ruggero Scorcioni([email protected]) at EU Advance Course in Computational Neuroscience. Obidos, Portugal\n",
"\n",
"na.mod\n",
"\n",
"Sodium channel, Hodgkin-Huxley style kinetics.\n",
"\n",
"Kinetics were fit to data from Huguenard et al. (1988) and Hamill et\n",
"al. (1991)\n",
"\n",
"qi is not well constrained by the data, since there are no points\n",
"between -80 and -55. So this was fixed at 5 while the thi1,thi2,Rg,Rd\n",
"were optimized using a simplex least square proc\n",
"\n",
"voltage dependencies are shifted approximately from the best\n",
"fit to give higher threshold\n",
"\n",
"Author: Zach Mainen, Salk Institute, 1994, [email protected]\n",
"\n",
"May 2006: set the tha -28 mV, vshift 0 and thinf -55 mV to comply with measured\n",
"Somatic Na+ kinetics in neocortex. Kole, ANU, 2006\n",
"\n",
"ENDCOMMENT\n",
"\n",
"INDEPENDENT {t FROM 0 TO 1 WITH 1 (ms)}\n",
"\n",
"NEURON {\n",
"SUFFIX nat : renenamed to account for transient behaviour (Armin, Jul 09)\n",
"USEION na READ ena WRITE ina\n",
"RANGE m, h, gna, gbar, vshift, vshift2, timefactor_m, timefactor_h,gbarfactor, ina\n",
"GLOBAL tha, thi1, thi2, qa, qi, qinf, thinf\n",
"RANGE minf, hinf, mtau, htau\n",
"GLOBAL Ra, Rb, Rd, Rg\n",
"GLOBAL q10, temp, tadj, vmin, vmax\n",
"}\n",
"\n",
"PARAMETER {\n",
"gbar = 0 \t(pS/um2)\t: 0.12 mho/cm2\n",
"vshift = 0\t(mV)\t\t: voltage shift\n",
"vshift2 = 0\t(mV)\t\t: voltage shift 2\n",
"\n",
"tha = -28\t(mV)\t\t: v 1/2 for act\t\t(-42)\n",
"qa = 9\t(mV)\t\t\t: act slope\n",
"Ra = 0.182\t(/ms)\t: open (v)\n",
"Rb = 0.124\t(/ms)\t: close (v)\n",
"\n",
"thi1 = -50\t(mV)\t\t: v 1/2 for inact\n",
"thi2 = -75\t(mV)\t\t: v 1/2 for inact\n",
"qi = 5\t(mV)\t \t: inact tau slope\n",
"thinf = -55\t(mV)\t\t: inact inf slope\n",
"qinf = 6.2\t(mV)\t\t: inact inf slope\n",
"Rg = 0.0091\t(/ms)\t: inact (v)\n",
"Rd = 0.024\t(/ms)\t: inact recov (v)\n",
"\n",
"temp = 23\t(degC)\t\t: original temp\n",
"q10 = 2.3\t\t\t: temperature sensitivity\n",
"\n",
"v \t\t(mV)\n",
"dt\t\t(ms)\n",
"celsius\t\t(degC)\n",
"vmin = -120\t(mV)\n",
"vmax = 100\t(mV)\n",
"\n",
"gbarfactor = 1\n",
"timefactor_m = 1\t\t: increase, decrease the speed of the the activation of the channels\n",
"timefactor_h = 1\t\t: increase, decrease the speed of the the activation of the channels\n",
"}\n",
"\n",
"\n",
"UNITS {\n",
"(mA) = (milliamp)\n",
"(mV) = (millivolt)\n",
"(pS) = (picosiemens)\n",
"(um) = (micron)\n",
"}\n",
"\n",
"ASSIGNED {\n",
"ina \t\t(mA/cm2)\n",
"gna\t\t(pS/um2)\n",
"ena\t\t(mV)\n",
"minf \t\thinf\n",
"mtau (ms)\thtau (ms)\n",
"tadj\n",
"}\n",
"\n",
"\n",
"STATE { m h }\n",
"\n",
"INITIAL {\n",
"trates(v-vshift-vshift2)\n",
"m = minf\n",
"h = hinf\n",
"}\n",
"\n",
"BREAKPOINT {\n",
"\n",
"SOLVE states METHOD cnexp\n",
"gna = gbarfactor*tadj*gbar*m*m*m*h\n",
"ina = (1e-4) * gna * (v - ena)\n",
"}\n",
"\n",
"LOCAL mexp, hexp\n",
"\n",
"DERIVATIVE states { :Computes state variables m, h, and n\n",
"trates(v-vshift-vshift2) : at the current v and dt.\n",
"m' = (minf-m)/(timefactor_m*mtau)\n",
"h' = (hinf-h)/(timefactor_h*htau)\n",
"}\n",
"\n",
"PROCEDURE trates(v) {\n",
"\n",
"\n",
"TABLE minf, hinf, mtau, htau\n",
"DEPEND celsius, temp, Ra, Rb, Rd, Rg, tha, thi1, thi2, qa, qi, qinf\n",
"\n",
"FROM vmin TO vmax WITH 199\n",
"\n",
"rates(v): not consistently executed from here if usetable == 1\n",
"\n",
": tinc = -dt * tadj\n",
"\n",
": mexp = 1 - exp(tinc/mtau)\n",
": hexp = 1 - exp(tinc/htau)\n",
"}\n",
"\n",
"\n",
"PROCEDURE rates(vm) {\n",
"LOCAL a, b\n",
"\n",
"a = trap0(vm,tha,Ra,qa)\n",
"b = trap0(-vm,-tha,Rb,qa)\n",
"\n",
"tadj = q10^((celsius - temp)/10)\n",
"\n",
"mtau = 1/tadj/(a+b)\n",
"minf = a/(a+b)\n",
"\n",
":\"h\" inactivation\n",
"\n",
"a = trap0(vm,thi1,Rd,qi)\n",
"b = trap0(-vm,-thi2,Rg,qi)\n",
"htau = 1/tadj/(a+b)\n",
"hinf = 1/(1+exp((vm-thinf)/qinf))\n",
"}\n",
"\n",
"\n",
"FUNCTION trap0(v,th,a,q) {\n",
"if (fabs(v/th) > 1e-6) {\n",
"trap0 = a * (v - th) / (1 - exp(-(v - th)/q))\n",
"} else {\n",
"trap0 = a * q\n",
"}\n",
"}\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
}
],
"source": [
"file_content_line_by_line(mod_file)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Path where the generated the neuroml file should be saved"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"nmlfilepath =\"./test\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Generate the nml file"
"Generate the nml file"
]
},
{
Expand All @@ -49,11 +272,103 @@
"source": [
"generate_neuroml2_for_mod_file(mod_file, nmlfilepath)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Contents of the generated nml file"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"### PARAMETER :\n",
"gbar = 0 (pS/um2) : 0.12 mho/cm2\n",
"vshift = 0 (mV) : voltage shift\n",
"vshift2 = 0 (mV) : voltage shift 2\n",
"tha = -28 (mV) : v 1/2 for act (-42)\n",
"qa = 9 (mV) : act slope\n",
"Ra = 0.182 (/ms) : open (v)\n",
"Rb = 0.124 (/ms) : close (v)\n",
"thi1 = -50 (mV) : v 1/2 for inact\n",
"thi2 = -75 (mV) : v 1/2 for inact\n",
"qi = 5 (mV) : inact tau slope\n",
"thinf = -55 (mV) : inact inf slope\n",
"qinf = 6.2 (mV) : inact inf slope\n",
"Rg = 0.0091 (/ms) : inact (v)\n",
"Rd = 0.024 (/ms) : inact recov (v)\n",
"temp = 23 (degC) : original temp\n",
"q10 = 2.3 : temperature sensitivity\n",
"vmin = -120 (mV)\n",
"vmax = 100 (mV)\n",
"gbarfactor = 1\n",
"timefactor_m = 1 : increase, decrease the speed of the the activation of the channels\n",
"timefactor_h = 1 : increase, decrease the speed of the the activation of the channels\n",
"\n",
"### PROCEDURE trates(v) :\n",
"TABLE minf, hinf, mtau, htau\n",
"DEPEND celsius, temp, Ra, Rb, Rd, Rg, tha, thi1, thi2, qa, qi, qinf\n",
"FROM vmin TO vmax WITH 199\n",
"rates(v): not consistently executed from here if usetable == 1\n",
"\n",
"### PROCEDURE rates(vm) :\n",
"LOCAL a, b\n",
"a = trap0(vm,tha,Ra,qa)\n",
"b = trap0(-vm,-tha,Rb,qa)\n",
"tadj = q10^((celsius - temp)/10)\n",
"mtau = 1/tadj/(a+b)\n",
"minf = a/(a+b)\n",
"a = trap0(vm,thi1,Rd,qi)\n",
"b = trap0(-vm,-thi2,Rg,qi)\n",
"htau = 1/tadj/(a+b)\n",
"hinf = 1/(1+exp((vm-thinf)/qinf))\n",
"### DELETE THE ABOVE TEXTS AFTER ADDING THE GATE INFO\n",
"\n",
"\n",
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n",
"<neuroml xmlns=\"http://www.neuroml.org/schema/neuroml2\"\n",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n",
"xsi:schemaLocation=\"http://www.neuroml.org/schema/neuroml2 https://raw.github.com/NeuroML/NeuroML2/development/Schemas/NeuroML2/NeuroML_v2beta4.xsd\"\n",
"id=\"nat\">\n",
"\n",
"<notes>NeuroML file automatically generated from an NMODL file</notes>\n",
"\n",
"<ionChannel id=\"nat\" conductance=\"10pS\" type=\"ionChannelHH\" species=\"na\">\n",
"\n",
"<notes>NeuroML2 file automatically generated from NMODL file: ./test/nat.mod</notes>\n",
"\n",
"\n",
"<gate id=\"m\" type=\"???\" instances=\"3\">\n",
"\n",
"</gate>\n",
"\n",
"<gate id=\"h\" type=\"???\" instances=\"1\">\n",
"\n",
"</gate>\n",
"\n",
"</ionChannel>\n",
"\n",
"</neuroml>\n"
]
}
],
"source": [
"nml_generated_file_path = mod_file.replace(\".mod\", \".channel.nml\")\n",
"\n",
"file_content_line_by_line(nml_generated_file_path)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.10 64-bit",
"display_name": "Python 3.10.0 ('neuron')",
"language": "python",
"name": "python3"
},
Expand All @@ -67,12 +382,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
"version": "3.10.0"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e"
"hash": "34c99d7b9019ebf7116fb123d3da999cf8f38ee4cc2bded985a8172faaeedfbd"
}
}
},
Expand Down

0 comments on commit fe98522

Please sign in to comment.