diff --git a/docs/nmodl/transpiler/notebooks/nmodl-python-tutorial.ipynb b/docs/nmodl/transpiler/notebooks/nmodl-python-tutorial.ipynb
index 1b3ecc5548..1bcb764b93 100644
--- a/docs/nmodl/transpiler/notebooks/nmodl-python-tutorial.ipynb
+++ b/docs/nmodl/transpiler/notebooks/nmodl-python-tutorial.ipynb
@@ -152,7 +152,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": null,
"metadata": {},
"outputs": [
{
@@ -164,7 +164,7 @@
}
],
"source": [
- "print(\"%.200s\" % modast) # only first 200 characters"
+ "print(f\"{modast:.200s}\") # only first 200 characters"
]
},
{
@@ -235,7 +235,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": null,
"metadata": {},
"outputs": [
{
@@ -259,32 +259,33 @@
"units = lookup_visitor.lookup(modast, ast.AstNodeType.UNIT)\n",
"\n",
"if odes:\n",
- " print(\"%d differential equation(s) exist : \" % len(odes))\n",
+ " print(f\"{len(odes)} differential equation(s) exist:\")\n",
" for ode in odes:\n",
- " print(\"\\t %s \" % nmodl.to_nmodl(ode))\n",
+ " print(f\"\\t {nmodl.to_nmodl(ode)}\")\n",
"\n",
"if primes:\n",
- " print(\"%d prime variables exist :\" % len(primes), end=\"\")\n",
+ " print(f\"{len(primes)} prime variables exist:\", end=\"\")\n",
" for prime in primes:\n",
- " print(\" %s\" % nmodl.to_nmodl(prime), end=\"\")\n",
+ " print(f\" {nmodl.to_nmodl(prime)}\", end=\"\")\n",
" print()\n",
"\n",
"if range_vars:\n",
- " print(\"%d range variables exist :\" % len(range_vars), end=\"\")\n",
+ " print(f\"{len(range_vars)} range variables exist:\", end=\"\")\n",
" for range_var in range_vars:\n",
- " print(\" %s\" % nmodl.to_nmodl(range_var), end=\"\")\n",
+ " print(f\" {nmodl.to_nmodl(range_var)}\", end=\"\")\n",
" print()\n",
"\n",
"if parameters:\n",
- " print(\"%d parameter variables exist :\" % len(parameters), end=\"\")\n",
- " for range_var in range_vars:\n",
- " print(\" %s\" % nmodl.to_nmodl(range_var), end=\"\")\n",
+ " print(f\"{len(parameters)} parameter variables exist:\", end=\"\")\n",
+ " for parameter in parameters:\n",
+ " print(f\" {nmodl.to_nmodl(parameter)}\", end=\"\")\n",
" print()\n",
"\n",
"if units:\n",
- " print(\"%d units uses :\" % len(units), end=\"\")\n",
+ " print(f\"{len(units)} units uses:\", end=\"\")\n",
" for unit in units:\n",
- " print(\" %s\" % nmodl.to_nmodl(unit), end=\"\")"
+ " print(f\" {nmodl.to_nmodl(unit)}\", end=\"\")\n",
+ " print()"
]
},
{
@@ -747,7 +748,7 @@
},
{
"cell_type": "code",
- "execution_count": 20,
+ "execution_count": null,
"metadata": {},
"outputs": [
{
@@ -782,15 +783,12 @@
"\n",
"ont_statements = lookup_visitor.lookup(modast, ast.AstNodeType.ONTOLOGY_STATEMENT)\n",
"ions = lookup_visitor.lookup(modast, ast.AstNodeType.USEION)\n",
- "\n",
"for statement in ont_statements:\n",
- " print(\n",
- " \" %s (%s)\" % (nmodl.to_nmodl(statement), nmodl.to_nmodl(statement.ontology_id))\n",
- " )\n",
+ " print(f\" {nmodl.to_nmodl(statement)} ({nmodl.to_nmodl(statement.ontology_id)})\")\n",
"\n",
"for ion in ions:\n",
" o_id = nmodl.to_nmodl(ion.ontology_id) if ion.ontology_id else \"\"\n",
- " print(\" %s (%s)\" % (nmodl.to_nmodl(ion), o_id))"
+ " print(f\" {nmodl.to_nmodl(ion)} ({o_id})\")\n"
]
},
{
diff --git a/docs/rxd-tutorials/Changing initial conditions and parameters.ipynb b/docs/rxd-tutorials/Changing initial conditions and parameters.ipynb
index 60624b2f06..3531b5c9bb 100644
--- a/docs/rxd-tutorials/Changing initial conditions and parameters.ipynb
+++ b/docs/rxd-tutorials/Changing initial conditions and parameters.ipynb
@@ -64,7 +64,7 @@
"\n",
"h.load_file(\"stdrun.hoc\")\n",
"\n",
- "soma = h.Section(name=\"soma\")\n",
+ "soma = h.Section(\"soma\")\n",
"cyt = rxd.Region([soma], name=\"cyt\", nrn_region=\"i\")\n",
"u = rxd.Species(cyt, name=\"u\")\n",
"α = rxd.Parameter(cyt, value=0.3 * mM)\n",
diff --git a/docs/rxd-tutorials/Restricting reactions to certain sections.ipynb b/docs/rxd-tutorials/Restricting reactions to certain sections.ipynb
index 99ce764900..7a1a602455 100644
--- a/docs/rxd-tutorials/Restricting reactions to certain sections.ipynb
+++ b/docs/rxd-tutorials/Restricting reactions to certain sections.ipynb
@@ -89,8 +89,8 @@
"metadata": {},
"outputs": [],
"source": [
- "left = h.Section(name=\"left\")\n",
- "right = h.Section(name=\"right\")\n",
+ "left = h.Section(\"left\")\n",
+ "right = h.Section(\"right\")\n",
"\n",
"left.nseg = right.nseg = 101\n",
"left.L = right.L = 101\n",
@@ -271,7 +271,7 @@
"def plot(fig):\n",
" y = protein.nodes.concentration\n",
" x = [h.distance(node, left(0)) for node in protein.nodes]\n",
- " fig.add_trace(go.Scatter(x=x, y=y, name=f\"t = {h.t:g} ms\"))"
+ " fig.add_trace(go.Scatter(x=x, y=y, name=f\"t = {h.t} ms\"))"
]
},
{
diff --git a/docs/rxd-tutorials/basic-initialization.ipynb b/docs/rxd-tutorials/basic-initialization.ipynb
index 8ff3a5ccd5..829476e9af 100644
--- a/docs/rxd-tutorials/basic-initialization.ipynb
+++ b/docs/rxd-tutorials/basic-initialization.ipynb
@@ -44,7 +44,7 @@
"from neuron import h, rxd\n",
"from neuron.units import mV\n",
"\n",
- "soma = h.Section(name=\"soma\")\n",
+ "soma = h.Section(\"soma\")\n",
"cyt = rxd.Region(soma.wholetree(), name=\"cyt\", nrn_region=\"i\")\n",
"\n",
"ca = rxd.Species(cyt, name=\"ca\", charge=2, atolscale=1e-6)\n",
@@ -90,7 +90,7 @@
"from neuron import h, rxd\n",
"from neuron.units import mV\n",
"\n",
- "soma = h.Section(name=\"soma\")\n",
+ "soma = h.Section(\"soma\")\n",
"cyt = rxd.Region(soma.wholetree(), name=\"cyt\")\n",
"\n",
"ca = rxd.Species(cyt, name=\"ca\", charge=2)\n",
@@ -187,7 +187,7 @@
"from neuron import h, rxd\n",
"from neuron.units import mV\n",
"\n",
- "soma = h.Section(name=\"soma\")\n",
+ "soma = h.Section(\"soma\")\n",
"\n",
"cyt = rxd.Region([soma], name=\"cyt\")\n",
"m = rxd.State(cyt, initial=0.47)\n",
diff --git a/docs/rxd-tutorials/calcium waves.ipynb b/docs/rxd-tutorials/calcium waves.ipynb
index 8de5c86478..cba9f564b2 100644
--- a/docs/rxd-tutorials/calcium waves.ipynb
+++ b/docs/rxd-tutorials/calcium waves.ipynb
@@ -87,7 +87,7 @@
"metadata": {},
"outputs": [],
"source": [
- "sec = h.Section(name=\"sec\")\n",
+ "sec = h.Section(\"sec\")\n",
"sec.L = 101\n",
"sec.diam = 1\n",
"sec.nseg = 101"
@@ -181,7 +181,7 @@
"outputs": [],
"source": [
"cyt = rxd.Region(\n",
- " h.allsec(),\n",
+ " [sec],\n",
" nrn_region=\"i\",\n",
" geometry=rxd.FractionalVolume(fc, surface_fraction=1),\n",
" name=\"cyt\",\n",
@@ -211,7 +211,7 @@
"metadata": {},
"outputs": [],
"source": [
- "er = rxd.Region(h.allsec(), geometry=rxd.FractionalVolume(fe), name=\"er\")"
+ "er = rxd.Region([sec], geometry=rxd.FractionalVolume(fe), name=\"er\")"
]
},
{
@@ -228,7 +228,7 @@
"outputs": [],
"source": [
"cyt_er_membrane = rxd.Region(\n",
- " h.allsec(), geometry=rxd.DistributedBoundary(2), name=\"cyt_er_membrane\"\n",
+ " [sec], geometry=rxd.DistributedBoundary(2), name=\"cyt_er_membrane\"\n",
")"
]
},
@@ -273,7 +273,7 @@
"
name
assigns a name to the Species that syncs with the rest of NEURON (NMODL, GUI tools, variables of the form e.g. cai
, etc)\n",
" charge
refers to the charge of the Species; e.g. a calcium ion would have charge 2\n",
" initial
refers to the initial concentration of the Species. If initial
is not specified and the Species has a name and exists on an rxd.Region with nrn_region
set, then NEURON's default initialization rules apply; otherwise the default is 0.\n",
- " atolscale
indicates a tolerance scale factor for variable step integration and is especially important for calcium and other substances with a low concentration\n",
+ " atolscale
indicates a tolerance scale factor for variable step integration and is especially important for calcium and other substances with a low concentration. (For calcium, consider an atolscale around 1e-6.)\n",
""
]
},
diff --git a/docs/rxd-tutorials/circadian.ipynb b/docs/rxd-tutorials/circadian.ipynb
index 9728ef7ce1..ea34060f78 100644
--- a/docs/rxd-tutorials/circadian.ipynb
+++ b/docs/rxd-tutorials/circadian.ipynb
@@ -155,7 +155,7 @@
"metadata": {},
"outputs": [],
"source": [
- "cell = h.Section(name=\"cell\")\n",
+ "cell = h.Section(\"cell\")\n",
"cell.diam = cell.L = 5\n",
"r = rxd.Region([cell], nrn_region=\"i\")"
]
diff --git a/docs/rxd-tutorials/combining currents from mod files with rxd.ipynb b/docs/rxd-tutorials/combining currents from mod files with rxd.ipynb
index 80dfe64a08..84f63b73e2 100644
--- a/docs/rxd-tutorials/combining currents from mod files with rxd.ipynb
+++ b/docs/rxd-tutorials/combining currents from mod files with rxd.ipynb
@@ -95,7 +95,7 @@
"outputs": [],
"source": [
"## define morphology\n",
- "soma = h.Section(name=\"soma\")\n",
+ "soma = h.Section(\"soma\")\n",
"soma.L = soma.diam = 10 * um\n",
"\n",
"## add ion channels (h.hh is built in, so always available)\n",
diff --git a/docs/rxd-tutorials/ip3-demo.ipynb b/docs/rxd-tutorials/ip3-demo.ipynb
index 7c72325829..59d72224cc 100644
--- a/docs/rxd-tutorials/ip3-demo.ipynb
+++ b/docs/rxd-tutorials/ip3-demo.ipynb
@@ -24,7 +24,7 @@
"metadata": {},
"outputs": [],
"source": [
- "dend = h.Section(name=\"dend\")\n",
+ "dend = h.Section(\"dend\")\n",
"dend.L = 100\n",
"dend.nseg = 101"
]
@@ -88,7 +88,7 @@
"while dend(0.7).ip3i < 100 * nM:\n",
" h.fadvance()\n",
"\n",
- "print(\"crossed 100 nM at t = {} ms\".format(h.t))"
+ "print(f\"crossed 100 nM at t = {h.t} ms\")"
]
},
{
@@ -105,8 +105,8 @@
"h.finitialize(-65)\n",
"h.continuerun(1000)\n",
"max_ip3 = max(ip3_vec)\n",
- "print(\"peak ip3 =\", max_ip3)\n",
- "print(\"final ip3 =\", dend(0.7).ip3i)"
+ "print(f\"peak ip3 = {max_ip3}\")\n",
+ "print(f\"final ip3 = {dend(0.7).ip3i}\")"
]
}
],
diff --git a/docs/rxd-tutorials/thresholds.ipynb b/docs/rxd-tutorials/thresholds.ipynb
index cd542fa28a..52a1d02847 100644
--- a/docs/rxd-tutorials/thresholds.ipynb
+++ b/docs/rxd-tutorials/thresholds.ipynb
@@ -29,10 +29,10 @@
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
- "import numpy\n",
+ "import numpy as np\n",
"\n",
- "x = numpy.linspace(-5, 5)\n",
- "y = numpy.tanh(x)\n",
+ "x = np.linspace(-5, 5)\n",
+ "y = np.tanh(x)\n",
"plt.grid()\n",
"plt.plot(x, y)\n",
"plt.xlabel(\"x\")\n",
@@ -78,8 +78,8 @@
"metadata": {},
"outputs": [],
"source": [
- "x = numpy.linspace(0, 4, 1000)\n",
- "y = (1 + numpy.tanh(2 * 10 * (x - 2))) / 2\n",
+ "x = np.linspace(0, 4, 1000)\n",
+ "y = (1 + np.tanh(2 * 10 * (x - 2))) / 2\n",
"plt.grid()\n",
"plt.plot(x, y)\n",
"plt.xlabel(\"x\")\n",
@@ -113,7 +113,7 @@
"\n",
"h.load_file(\"stdrun.hoc\")\n",
"\n",
- "soma = h.Section(name=\"soma\")\n",
+ "soma = h.Section(\"soma\")\n",
"cyt = rxd.Region([soma], name=\"cyt\", nrn_region=\"i\")\n",
"ip3 = rxd.Species(cyt, name=\"ip3\", charge=0, initial=1 * mM)\n",
"k = 2 # degradation rate\n",
diff --git a/docs/tutorials/ball-and-stick-1.ipynb b/docs/tutorials/ball-and-stick-1.ipynb
index 783e469705..3cc71aa7c7 100644
--- a/docs/tutorials/ball-and-stick-1.ipynb
+++ b/docs/tutorials/ball-and-stick-1.ipynb
@@ -138,8 +138,8 @@
"source": [
"class BallAndStick:\n",
" def __init__(self):\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)"
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)"
]
},
{
@@ -218,8 +218,8 @@
"source": [
"class BallAndStick:\n",
" def __init__(self):\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
"\n",
" def __repr__(self):\n",
" return \"BallAndStick\""
@@ -316,11 +316,11 @@
"class BallAndStick:\n",
" def __init__(self, gid):\n",
" self._gid = gid\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
"\n",
" def __repr__(self):\n",
- " return \"BallAndStick[{}]\".format(self._gid)"
+ " return f\"BallAndStick[{self._gid}]\""
]
},
{
@@ -393,12 +393,12 @@
"class BallAndStick:\n",
" def __init__(self, gid):\n",
" self._gid = gid\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
" self.dend.connect(self.soma)\n",
"\n",
" def __repr__(self):\n",
- " return \"BallAndStick[{}]\".format(self._gid)"
+ " return f\"BallAndStick[{self._gid}]\""
]
},
{
@@ -503,15 +503,15 @@
"class BallAndStick:\n",
" def __init__(self, gid):\n",
" self._gid = gid\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
" self.dend.connect(self.soma)\n",
" self.soma.L = self.soma.diam = 12.6157 * µm\n",
" self.dend.L = 200 * µm\n",
" self.dend.diam = 1 * µm\n",
"\n",
" def __repr__(self):\n",
- " return \"BallAndStick[{}]\".format(self._gid)\n",
+ " return f\"BallAndStick[{self._gid}]\"\n",
"\n",
"\n",
"my_cell = BallAndStick(0)"
@@ -673,8 +673,8 @@
"class BallAndStick:\n",
" def __init__(self, gid):\n",
" self._gid = gid\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
" self.dend.connect(self.soma)\n",
" self.all = self.soma.wholetree() # <-- NEW\n",
" self.soma.L = self.soma.diam = 12.6157 * µm\n",
@@ -685,7 +685,7 @@
" sec.cm = 1 # Membrane capacitance in micro Farads / cm^2 # <-- NEW\n",
"\n",
" def __repr__(self):\n",
- " return \"BallAndStick[{}]\".format(self._gid)\n",
+ " return f\"BallAndStick[{self._gid}]\"\n",
"\n",
"\n",
"my_cell = BallAndStick(0)"
@@ -718,8 +718,8 @@
" self._setup_biophysics()\n",
"\n",
" def _setup_morphology(self):\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
" self.all = [self.soma, self.dend]\n",
" self.dend.connect(self.soma)\n",
" self.soma.L = self.soma.diam = 12.6157 * µm\n",
@@ -732,7 +732,7 @@
" sec.cm = 1 # Membrane capacitance in micro Farads / cm^2\n",
"\n",
" def __repr__(self):\n",
- " return \"BallAndStick[{}]\".format(self._gid)\n",
+ " return f\"BallAndStick[{self._gid}]\"\n",
"\n",
"\n",
"my_cell = BallAndStick(0)"
@@ -777,8 +777,8 @@
" for sec in self.all:\n",
" sec.Ra = 100 # Axial resistance in Ohm * cm\n",
" sec.cm = 1 # Membrane capacitance in micro Farads / cm^2\n",
- " self.soma.insert(\"hh\") # <-- NEW\n",
- " for seg in self.soma: # <-- NEW\n",
+ " self.soma.insert(h.hh) # <-- NEW\n",
+ " for seg in self.soma: # <-- NEW\n",
" seg.hh.gnabar = (\n",
" 0.12 # Sodium conductance in S/cm2 # <-- NEW\n",
" )\n",
@@ -791,7 +791,7 @@
" ) # Reversal potential # <-- NEW\n",
"\n",
" def __repr__(self):\n",
- " return \"BallAndStick[{}]\".format(self._gid)\n",
+ " return f\"BallAndStick[{self._gid}]\"\n",
"\n",
"\n",
"my_cell = BallAndStick(0)"
@@ -824,8 +824,8 @@
" self._setup_biophysics()\n",
"\n",
" def _setup_morphology(self):\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
" self.dend.connect(self.soma)\n",
" self.all = self.soma.wholetree()\n",
" self.soma.L = self.soma.diam = 12.6157 * µm\n",
@@ -836,20 +836,20 @@
" for sec in self.all:\n",
" sec.Ra = 100 # Axial resistance in Ohm * cm\n",
" sec.cm = 1 # Membrane capacitance in micro Farads / cm^2\n",
- " self.soma.insert(\"hh\")\n",
+ " self.soma.insert(h.hh)\n",
" for seg in self.soma:\n",
" seg.hh.gnabar = 0.12 # Sodium conductance in S/cm2\n",
" seg.hh.gkbar = 0.036 # Potassium conductance in S/cm2\n",
" seg.hh.gl = 0.0003 # Leak conductance in S/cm2\n",
" seg.hh.el = -54.3 * mV # Reversal potential\n",
" # Insert passive current in the dendrite # <-- NEW\n",
- " self.dend.insert(\"pas\") # <-- NEW\n",
+ " self.dend.insert(h.pas) # <-- NEW\n",
" for seg in self.dend: # <-- NEW\n",
" seg.pas.g = 0.001 # Passive conductance in S/cm2 # <-- NEW\n",
" seg.pas.e = -65 * mV # Leak reversal potential # <-- NEW\n",
"\n",
" def __repr__(self):\n",
- " return \"BallAndStick[{}]\".format(self._gid)\n",
+ " return f\"BallAndStick[{self._gid}]\"\n",
"\n",
"\n",
"my_cell = BallAndStick(0)"
@@ -885,7 +885,7 @@
"outputs": [],
"source": [
"for sec in h.allsec():\n",
- " print(\"%s: %s\" % (sec, \", \".join(sec.psection()[\"density_mechs\"].keys())))"
+ " print(f\"{sec}: {', '.join(sec.psection()['density_mechs'])}\")"
]
},
{
@@ -1244,8 +1244,8 @@
"for amp, color in zip(amps, colors):\n",
" stim.amp = amp\n",
" for my_cell.dend.nseg, width in [(1, 2), (101, 1)]:\n",
- " h.finitialize(-65)\n",
- " h.continuerun(25)\n",
+ " h.finitialize(-65 * mV)\n",
+ " h.continuerun(25 * ms)\n",
" f.line(\n",
" t,\n",
" list(soma_v),\n",
diff --git a/docs/tutorials/ball-and-stick-2.ipynb b/docs/tutorials/ball-and-stick-2.ipynb
index 3c64aa9ea6..a90d8acea2 100644
--- a/docs/tutorials/ball-and-stick-2.ipynb
+++ b/docs/tutorials/ball-and-stick-2.ipynb
@@ -78,7 +78,7 @@
" self._setup_biophysics()\n",
"\n",
" def __repr__(self):\n",
- " return \"{}[{}]\".format(self.name, self._gid)"
+ " return f\"{self.name}[{self._gid}]\""
]
},
{
@@ -98,8 +98,8 @@
" name = \"BallAndStick\"\n",
"\n",
" def _setup_morphology(self):\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
" self.dend.connect(self.soma)\n",
" self.soma.L = self.soma.diam = 12.6157\n",
" self.dend.L = 200\n",
@@ -109,14 +109,14 @@
" for sec in self.all:\n",
" sec.Ra = 100 # Axial resistance in Ohm * cm\n",
" sec.cm = 1 # Membrane capacitance in micro Farads / cm^2\n",
- " self.soma.insert(\"hh\")\n",
+ " self.soma.insert(h.hh)\n",
" for seg in self.soma:\n",
" seg.hh.gnabar = 0.12 # Sodium conductance in S/cm2\n",
" seg.hh.gkbar = 0.036 # Potassium conductance in S/cm2\n",
" seg.hh.gl = 0.0003 # Leak conductance in S/cm2\n",
" seg.hh.el = -54.3 # Reversal potential in mV\n",
" # Insert passive current in the dendrite\n",
- " self.dend.insert(\"pas\")\n",
+ " self.dend.insert(h.pas)\n",
" for seg in self.dend:\n",
" seg.pas.g = 0.001 # Passive conductance in S/cm2\n",
" seg.pas.e = -65 # Leak reversal potential mV"
@@ -161,7 +161,7 @@
" self._set_position(x, y, z) # <-- NEW\n",
"\n",
" def __repr__(self):\n",
- " return \"{}[{}]\".format(self.name, self._gid)\n",
+ " return f\"{self.name}[{self._gid}]\"\n",
"\n",
" # everything below here is NEW\n",
"\n",
@@ -208,8 +208,8 @@
" name = \"BallAndStick\"\n",
"\n",
" def _setup_morphology(self):\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
" self.dend.connect(self.soma)\n",
" self.soma.L = self.soma.diam = 12.6157\n",
" self.dend.L = 200\n",
@@ -219,14 +219,14 @@
" for sec in self.all:\n",
" sec.Ra = 100 # Axial resistance in Ohm * cm\n",
" sec.cm = 1 # Membrane capacitance in micro Farads / cm^2\n",
- " self.soma.insert(\"hh\")\n",
+ " self.soma.insert(h.hh)\n",
" for seg in self.soma:\n",
" seg.hh.gnabar = 0.12 # Sodium conductance in S/cm2\n",
" seg.hh.gkbar = 0.036 # Potassium conductance in S/cm2\n",
" seg.hh.gl = 0.0003 # Leak conductance in S/cm2\n",
" seg.hh.el = -54.3 # Reversal potential in mV\n",
" # Insert passive current in the dendrite\n",
- " self.dend.insert(\"pas\")\n",
+ " self.dend.insert(h.pas)\n",
" for seg in self.dend:\n",
" seg.pas.g = 0.001 # Passive conductance in S/cm2\n",
" seg.pas.e = -65 # Leak reversal potential mV"
@@ -425,7 +425,7 @@
"metadata": {},
"outputs": [],
"source": [
- "print(\"Reversal potential = {} mV\".format(syn_.e))"
+ "print(f\"Reversal potential = {syn_.e} mV\")"
]
},
{
@@ -712,7 +712,7 @@
"outputs": [],
"source": [
"for i, spike_times_vec in enumerate(spike_times):\n",
- " print(\"cell {}: {}\".format(i, list(spike_times_vec)))"
+ " print(f\"cell {i}: {list(spike_times_vec)}\")"
]
},
{
diff --git a/docs/tutorials/ball-and-stick-3.ipynb b/docs/tutorials/ball-and-stick-3.ipynb
index a1971e10f9..b62dc36339 100644
--- a/docs/tutorials/ball-and-stick-3.ipynb
+++ b/docs/tutorials/ball-and-stick-3.ipynb
@@ -81,7 +81,7 @@
" self.soma_v = h.Vector().record(self.soma(0.5)._ref_v)\n",
"\n",
" def __repr__(self):\n",
- " return \"{}[{}]\".format(self.name, self._gid)\n",
+ " return f\"{self.name}[{self._gid}]\"\n",
"\n",
" def _set_position(self, x, y, z):\n",
" for sec in self.all:\n",
@@ -125,8 +125,8 @@
" name = \"BallAndStick\"\n",
"\n",
" def _setup_morphology(self):\n",
- " self.soma = h.Section(name=\"soma\", cell=self)\n",
- " self.dend = h.Section(name=\"dend\", cell=self)\n",
+ " self.soma = h.Section(\"soma\", self)\n",
+ " self.dend = h.Section(\"dend\", self)\n",
" self.dend.connect(self.soma)\n",
" self.soma.L = self.soma.diam = 12.6157\n",
" self.dend.L = 200\n",
@@ -136,14 +136,14 @@
" for sec in self.all:\n",
" sec.Ra = 100 # Axial resistance in Ohm * cm\n",
" sec.cm = 1 # Membrane capacitance in micro Farads / cm^2\n",
- " self.soma.insert(\"hh\")\n",
+ " self.soma.insert(h.hh)\n",
" for seg in self.soma:\n",
" seg.hh.gnabar = 0.12 # Sodium conductance in S/cm2\n",
" seg.hh.gkbar = 0.036 # Potassium conductance in S/cm2\n",
" seg.hh.gl = 0.0003 # Leak conductance in S/cm2\n",
" seg.hh.el = -54.3 # Reversal potential in mV\n",
" # Insert passive current in the dendrite\n",
- " self.dend.insert(\"pas\")\n",
+ " self.dend.insert(h.pas)\n",
" for seg in self.dend:\n",
" seg.pas.g = 0.001 # Passive conductance in S/cm2\n",
" seg.pas.e = -65 # Leak reversal potential mV\n",
@@ -288,7 +288,7 @@
"source": [
"t = h.Vector().record(h._ref_t)\n",
"h.finitialize(-65 * mV)\n",
- "h.continuerun(100)"
+ "h.continuerun(100 * ms)"
]
},
{
@@ -322,7 +322,7 @@
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
- "plt.plot(t, list(ring.cells[0].soma_v))\n",
+ "plt.plot(t, ring.cells[0].soma_v)\n",
"plt.show()"
]
},
diff --git a/docs/tutorials/ball-and-stick-4.ipynb b/docs/tutorials/ball-and-stick-4.ipynb
index 93d0db6069..31e01d7e8c 100644
--- a/docs/tutorials/ball-and-stick-4.ipynb
+++ b/docs/tutorials/ball-and-stick-4.ipynb
@@ -95,7 +95,7 @@
"from neuron import h\n",
"h.nrnmpi_init() # initialize MPI\n",
"pc = h.ParallelContext()\n",
- "print('I am {} of {}'.format(pc.id(), pc.nhost()))\n",
+ "print(f'I am {pc.id()} of {pc.nhost()}')\n",
"h.quit() # necessary to avoid a warning message on parallel exit on some systems"
]
},
@@ -309,11 +309,11 @@
"\n",
"if pc.gid_exists(cell_to_plot):\n",
" plt.figure()\n",
- " plt.title(\"Cell {}\".format(cell_to_plot))\n",
+ " plt.title(f\"Cell {cell_to_plot}\")\n",
" plt.plot(t, pc.gid2cell(cell_to_plot).soma_v)\n",
" plt.xlabel(\"Simulation time [ms]\")\n",
" plt.ylabel(\"Soma voltage [mV]\")\n",
- " plt.savefig(\"test_ring1_{}ranks.svgz\".format(pc.nhost()))\n",
+ " plt.savefig(f\"test_ring1_{pc.nhost()}ranks.svgz\")\n",
"\n",
"pc.barrier()\n",
"pc.done()\n",
diff --git a/docs/tutorials/pythontutorial.ipynb b/docs/tutorials/pythontutorial.ipynb
index c8589f5046..4087ff0bf1 100644
--- a/docs/tutorials/pythontutorial.ipynb
+++ b/docs/tutorials/pythontutorial.ipynb
@@ -59,7 +59,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We can use a string's format method with {} placeholders to substitute calculated values into the output in specific locations; for example:"
+ "Instead of a string literal, we can use an f-string with {} placeholders to indicate variables or calculated values into the output. For example:"
]
},
{
@@ -68,14 +68,14 @@
"metadata": {},
"outputs": [],
"source": [
- "print(\"3 + 4 = {}. Amazing!\".format(3 + 4))"
+ "print(f\"3 + 4 = {3 + 4}. Amazing!\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "Multiple values can be substituted:"
+ "Multiple values can be substituted. Here we use values from variables (see the next section):"
]
},
{
@@ -84,7 +84,9 @@
"metadata": {},
"outputs": [],
"source": [
- "print(\"The length of the {} is {} microns.\".format(\"apical dendrite\", 100))"
+ "section = \"apical dendrite\"\n",
+ "length = 100\n",
+ "print(f\"The length of the {section} is {length} microns.\")"
]
},
{
@@ -522,10 +524,10 @@
"outputs": [],
"source": [
"print(my_list)\n",
- "print(my_list[2:4]) # Includes the range from index 2 to 3\n",
+ "print(my_list[2:4]) # Includes the range from index 2 to 3\n",
"print(my_list[2:-1]) # Includes the range from index 2 to the element before -1\n",
- "print(my_list[:2]) # Includes everything before index 2\n",
- "print(my_list[2:]) # Includes everything from index 2"
+ "print(my_list[:2]) # Includes everything before index 2\n",
+ "print(my_list[2:]) # Includes everything from index 2"
]
},
{
@@ -586,8 +588,8 @@
"list_a = [1, 3, 5, 8, 13]\n",
"list_b = list(list_a)\n",
"list_b.reverse()\n",
- "print(\"list_a = \" + str(list_a))\n",
- "print(\"list_b = \" + str(list_b))"
+ "print(f\"list_a = {list_a}\")\n",
+ "print(f\"list_b = {list_b}\")"
]
},
{
@@ -603,10 +605,10 @@
"metadata": {},
"outputs": [],
"source": [
- "print(\"initial: list_a[0] = %g\" % list_a[0])\n",
+ "print(f\"initial: list_a[0] = {list_a[0]}\")\n",
"foo = list_a\n",
"foo[0] = 42\n",
- "print(\"final: list_a[0] = %g\" % list_a[0])"
+ "print(f\"final: list_a[0] = {list_a[0]}\")"
]
},
{
@@ -860,7 +862,7 @@
"source": [
"cell_parts = [\"soma\", \"axon\", \"dendrites\"]\n",
"for part_num, part in enumerate(cell_parts):\n",
- " print(\"%d %s\" % (part_num, part))"
+ " print(f\"{part_num} {part}\")"
]
},
{
@@ -879,7 +881,7 @@
"cell_parts = [\"soma\", \"axon\", \"dendrites\"]\n",
"diams = [20, 2, 3]\n",
"for diam, part in zip(diams, cell_parts):\n",
- " print(\"%10s %g\" % (part, diam))"
+ " print(f\"{part:<10s} {diam}\")"
]
},
{
@@ -897,8 +899,8 @@
"source": [
"y = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"x = list(range(len(y)))\n",
- "print(\"x = {}\".format(x))\n",
- "print(\"y = {}\".format(y))\n",
+ "print(f\"x = {x}\")\n",
+ "print(f\"y = {y}\")\n",
"print(list(zip(x, y)))"
]
},
@@ -916,7 +918,7 @@
"outputs": [],
"source": [
"for x_val, y_val in zip(x, y):\n",
- " print(\"index {}: {}\".format(x_val, y_val))"
+ " print(f\"index {x_val}: {y_val}\")"
]
},
{
@@ -1045,7 +1047,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "We can use curly braces with keys to indicate dictionary fields when using format. e.g."
+ "If you have a dictionary with many properties whose information you want to print out, you can write the property names inside of regular string (not an f-string) and use the format method. e.g."
]
},
{
@@ -1082,7 +1084,7 @@
"outputs": [],
"source": [
"for k, v in about_me.items():\n",
- " print(\"key = {:10s} val = {}\".format(k, v))"
+ " print(f\"key = {k:10s} val = {v}\")"
]
},
{
@@ -1311,18 +1313,11 @@
" self.email = email\n",
" self.phone = phone\n",
"\n",
- " def print_info(self):\n",
- " \"\"\"Print all of the information of this contact.\"\"\"\n",
- " my_str = \"Contact info:\"\n",
- " if self.first_name:\n",
- " my_str += \" \" + self.first_name\n",
- " if self.last_name:\n",
- " my_str += \" \" + self.last_name\n",
- " if self.email:\n",
- " my_str += \" \" + self.email\n",
- " if self.phone:\n",
- " my_str += \" \" + self.phone\n",
- " print(my_str)"
+ "def print_info(self):\n",
+ " \"\"\"Print all of the information of this contact.\"\"\"\n",
+ " contact_info = [self.first_name, self.last_name, self.email, self.phone]\n",
+ " # when used as here, the filter function removes None values from the list\n",
+ " print(\"Contact info:\", \" \".join(filter(None, contact_info)))"
]
},
{
@@ -1443,9 +1438,9 @@
"metadata": {},
"outputs": [],
"source": [
- "import numpy\n",
+ "import numpy as np\n",
"\n",
- "my_vec = numpy.arange(0, 1, 0.1)\n",
+ "my_vec = np.arange(0, 1, 0.1)\n",
"print(my_vec)"
]
},
@@ -1469,7 +1464,7 @@
"metadata": {},
"outputs": [],
"source": [
- "x = numpy.linspace(0, numpy.pi, 20)"
+ "x = np.linspace(0, np.pi, 20)"
]
},
{
@@ -1494,7 +1489,7 @@
"metadata": {},
"outputs": [],
"source": [
- "y = numpy.sin(x)"
+ "y = np.sin(x)"
]
},
{
@@ -1581,6 +1576,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
+ "For more advanced storage, consider using the `sqlite3` database module, the `json` module for JSON files, or `pandas` for tabular data (CSV, Excel, etc.).\n",
+ "\n",
"The next part of this tutorial introduces basic NEURON commands."
]
},
diff --git a/docs/tutorials/scripting-neuron-basics.ipynb b/docs/tutorials/scripting-neuron-basics.ipynb
index 6bd65e49a3..811182eaac 100644
--- a/docs/tutorials/scripting-neuron-basics.ipynb
+++ b/docs/tutorials/scripting-neuron-basics.ipynb
@@ -161,7 +161,7 @@
"metadata": {},
"outputs": [],
"source": [
- "soma = h.Section(name=\"soma\")"
+ "soma = h.Section(\"soma\")"
]
},
{
@@ -474,7 +474,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "A section's insert method is used to insert density mechanisms (i.e. anything where we don't want to specify every single instance separately). Let's insert Hodgkin-Huxley channels into the soma's membrane. We do this by passing 'hh' as the mechanism type:"
+ "A section's insert method is used to insert density mechanisms (i.e. anything where we don't want to specify every single instance separately). Let's insert Hodgkin-Huxley channels into the soma's membrane. We do this by passing h.hh as the mechanism type:"
]
},
{
@@ -483,7 +483,7 @@
"metadata": {},
"outputs": [],
"source": [
- "soma.insert(\"hh\")"
+ "soma.insert(h.hh)"
]
},
{
@@ -537,8 +537,8 @@
"metadata": {},
"outputs": [],
"source": [
- "print(\"type(soma) = {}\".format(type(soma)))\n",
- "print(\"type(soma(0.5)) = {}\".format(type(soma(0.5))))"
+ "print(f\"type(soma) = {type(soma)}\")\n",
+ "print(f\"type(soma(0.5)) = {type(soma(0.5))}\")"
]
},
{