python + neuron - neuralensembleneuralensemble.org/media/slides/codejam2_hines_nrnpython.pdfabout...
TRANSCRIPT
![Page 1: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/1.jpg)
Python + NEURON
![Page 2: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/2.jpg)
Python + NEURON>>> hoc.execute(’hoc statement’)oc> nrnpython("python statement")
![Page 3: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/3.jpg)
Python + NEURON>>> hoc.execute(’hoc statement’)oc> nrnpython("python statement")
Native Hoc/Python interaction
![Page 4: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/4.jpg)
Python + NEURON>>> hoc.execute(’hoc statement’)oc> nrnpython("python statement")
Installation
Native Hoc/Python interaction
![Page 5: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/5.jpg)
Python + NEURON>>> hoc.execute(’hoc statement’)oc> nrnpython("python statement")
Numpy
Installation
Native Hoc/Python interaction
![Page 6: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/6.jpg)
Installation
![Page 7: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/7.jpg)
Installation >>> import neuron
![Page 8: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/8.jpg)
InstallationLinux
Mac
MSWin
x86_64i686
10.410.5OS X
>>> import neuron
![Page 9: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/9.jpg)
InstallationLinux
Mac
MSWin
x86_64i686
10.410.5OS X
2.42.5
2.3Python
>>> import neuron
![Page 10: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/10.jpg)
InstallationLinux
Mac
MSWin
x86_64i686
10.410.5OS X
NEURONPythonLaunch
2.42.5
2.3Python
>>> import neuron
![Page 11: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/11.jpg)
InstallationLinux
Mac
MSWin
x86_64i686
CygwinMinGW
10.410.5OS X
NEURONPythonLaunch
2.42.5
2.3Python
>>> import neuron
![Page 12: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/12.jpg)
InstallationLinux
Mac
MSWin
x86_64i686
CygwinMinGW
10.410.5OS X
NumPyNEURONPythonLaunch
2.42.5
2.3Python
>>> import neuron
![Page 13: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/13.jpg)
a = numpy.arange(0,10.0,0.00001)
b = numpy.array(a)0.02v = neuron.Vector(a)a = numpy.array(v)
sec
21.243.7
![Page 14: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/14.jpg)
a = numpy.arange(0,10.0,0.00001)
b = numpy.array(a)0.02v = neuron.Vector(a)a = numpy.array(v)
b = numpy.array(a)0.01v = neuron.Vector(a)0.14b = v.to_python(numpy.zeros(v.size()))0.07
sec
21.243.7
![Page 15: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/15.jpg)
a = numpy.arange(0,10.0,0.00001)
b = numpy.array(a)0.02v = neuron.Vector(a)a = numpy.array(v)
b = numpy.array(a)0.01v = neuron.Vector(a)0.14b = v.to_python(numpy.zeros(v.size()))0.07
a = range(0, 1000000)
b = numpy.array(a)0.16v = neuron.Vector(a)0.06b = v.to_python()0.04
sec
21.243.7
![Page 16: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/16.jpg)
nrniv −python
Python using Hoc
![Page 17: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/17.jpg)
nrniv −pythonimport neuronh = neuron.hprint h
TopLevelHocInterpreter
Python using Hoc
![Page 18: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/18.jpg)
nrniv −pythonimport neuronh = neuron.hprint h
TopLevelHocInterpreterh(’’’ a=5 objref vec vec = new Vector() strdef s s = "string" func f() { return $1 * $1 }’’’)
Python using Hoc
![Page 19: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/19.jpg)
print h.a, h.vec, h.s, h.f(3)5.0 Vector[0] string 9.0
Python using Hoc
![Page 20: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/20.jpg)
print h.a, h.vec, h.s, h.f(3)5.0 Vector[0] string 9.0
s = h.sh.s = ’hello’print s, h.s
string hello
Python using Hoc
![Page 21: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/21.jpg)
print h.a, h.vec, h.s, h.f(3)5.0 Vector[0] string 9.0
s = h.sh.s = ’hello’print s, h.s
string hellof = h.fprint f, f(5)
f() 25.0
Python using Hoc
![Page 22: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/22.jpg)
print h.a, h.vec, h.s, h.f(3)5.0 Vector[0] string 9.0
h.vec.resize(4)h.vec.indgen().add(10).printf()
10 11 12 134.0
Python using Hoc
![Page 23: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/23.jpg)
print h.a, h.vec, h.s, h.f(3)5.0 Vector[0] string 9.0
h.vec.resize(4)h.vec.indgen().add(10).printf()
10 11 12 134.0
vx = h.vec.xprint h.vec, vx, vx[2]
Vector[0] Vector[0].x[?] 12.0
Python using Hoc
![Page 24: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/24.jpg)
import neuronh = neuron.hfrom nrn import *
Python using Hoc
![Page 25: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/25.jpg)
import neuronh = neuron.hfrom nrn import *
soma = Section()soma.L = 10soma(0.5).diam = 10soma.insert(’hh’)
Python using Hoc
![Page 26: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/26.jpg)
import neuronh = neuron.hfrom nrn import *
soma = Section()soma.L = 10soma(0.5).diam = 10soma.insert(’hh’)
stim = neuron.IClamp(soma, 0.5)# Thanks Andrew.stim.delay = 1stim.dur = 0.2stim.amp = 0.5
Python using Hoc
![Page 27: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/27.jpg)
v = neuron.Vector()soma.push()v.record(h.ref(soma(0.5).v))h.pop_section()
Python using Hoc
![Page 28: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/28.jpg)
v = neuron.Vector()soma.push()v.record(h.ref(soma(0.5).v))h.pop_section()
h.load_file(’stdrun.hoc’)h.run()v.printf()
Python using Hoc
![Page 29: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/29.jpg)
weight snapshot file
Hoc using Python
Mitral−Granule reciprocal synapse
src tar w
No way to efficiently derive the MGRS from the src, tar.
![Page 30: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/30.jpg)
Hoc using Python
p = new PythonObject()
map = p.newmap(−1,0) "newmap = lambda key, value : {key:value}")nrnpython(\
objref p, map
![Page 31: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/31.jpg)
for <lines in file> { map.update(p.newmap(gid, w))}
Hoc using Python
p = new PythonObject()
map = p.newmap(−1,0) "newmap = lambda key, value : {key:value}")nrnpython(\
objref p, map
![Page 32: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/32.jpg)
for <lines in file> { map.update(p.newmap(gid, w))}
Hoc using Python
for <all MGRS> {
} w = map._[gid]
p = new PythonObject()
map = p.newmap(−1,0) "newmap = lambda key, value : {key:value}")nrnpython(\
objref p, map
![Page 33: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/33.jpg)
About Topology Subsets Geometry Biophysics Management Continuous Create
d
Cell Type Export Import Hints
Import from top level of interpreter.
This works only if there is one cell in the interpreter.
Or import from NeuroML (Level 2) file.
From top level, imports: Topology, 3-D info.
From NeuroML file: Topology, 3-D info, Subsets, Biophysics.
Don’t forget to specify compartmentalization in Geometry.
Import
Turn off indexed name display.Don’t draw short sections as circles.
CellBuild[0]
./pyr.xmlFile format: MorphML
-------------------------------ZoomTranslate Rotate (about axis in plane)Rotate 45deg about y axisRotated (vs Raw view)Show PointsShow Diam
View all types
View typeSelect point
Select id 0
-------------------------------
Edit
Export
MorphML filter facts
Import3d_GUI[0]
![Page 34: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/34.jpg)
About Topology Subsets Geometry Biophysics Management Continuous Create
d
Cell Type Export Import Hints
Import from top level of interpreter.
This works only if there is one cell in the interpreter.
Or import from NeuroML (Level 2) file.
From top level, imports: Topology, 3-D info.
From NeuroML file: Topology, 3-D info, Subsets, Biophysics.
Don’t forget to specify compartmentalization in Geometry.
Import
Turn off indexed name display.Don’t draw short sections as circles.
CellBuild[0]
./pyr.xmlFile format: MorphML
-------------------------------ZoomTranslate Rotate (about axis in plane)Rotate 45deg about y axisRotated (vs Raw view)Show PointsShow Diam
View all types
View typeSelect point
Select id 0
-------------------------------
Edit
Export
MorphML filter facts
Import3d_GUI[0]
![Page 35: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/35.jpg)
import3d/read_morphml.hoc
begintemplate Import3d_MorphMLpublic parsed
![Page 36: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/36.jpg)
import3d/read_morphml.hoc
begintemplate Import3d_MorphMLpublic parsed
proc input() {
p.rdxml.__setattr__("i3d", this) sprint(tstr, "rdxml.rdxml(’%s’)", $s1) nrnpython(tstr) p.rdxml.__setattr__("i3d", nil)}
nrnpython("import rdxml") p = new PythonObject()
![Page 37: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/37.jpg)
import3d/read_morphml.hoc
begintemplate Import3d_MorphMLpublic parsed
proc parsed() { ...
proc input() {
p.rdxml.__setattr__("i3d", this) sprint(tstr, "rdxml.rdxml(’%s’)", $s1) nrnpython(tstr) p.rdxml.__setattr__("i3d", nil)}
nrnpython("import rdxml") p = new PythonObject()
![Page 38: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/38.jpg)
import xmli3d = 1
def rdxml(fname) : xml.sax.parse(fname, MyContentHandler())
python/rdxml.py
![Page 39: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/39.jpg)
import xmli3d = 1
def rdxml(fname) : xml.sax.parse(fname, MyContentHandler())
class MyContentHandler(xml.sax.ContentHandler):
def endDocument(self): i3d.parsed(self)
class Point Cable CableGroup BioParm BioMech
python/rdxml.py
![Page 40: Python + NEURON - NeuralEnsembleneuralensemble.org/media/slides/CodeJam2_Hines_nrnpython.pdfAbout Topology Subsets Geometry Biophysics Management Continuous Create d Cell Type Export](https://reader030.vdocuments.mx/reader030/viewer/2022041016/5ec83095b760b4675617bbd1/html5/thumbnails/40.jpg)
proc parsed() { ... cables = $o1.cables_ points = $o1.points_ cableid2index = $o1.cableid2index_ for i=0, cables.__len__() − 1 { cab = cables._[i] sec = new Import3d_Section(cab.first_, cab.pcnt_) if (cab.parent_cable_id_ >= 0) { ip = $o1.cableid2index_[cab.parent_cable_id_]
import3d/read_morphml.hoc