Uploading .swc file through .hoc

Managing anatomically complex model cells with the CellBuilder. Importing morphometric data with NEURON's Import3D tool or Robert Cannon's CVAPP. Where to find detailed morphometric data.
Post Reply
neuron121!
Posts: 8
Joined: Thu Mar 31, 2022 11:00 pm

Uploading .swc file through .hoc

Post by neuron121! »

Hello all,

I have an uploaded neuron in a .swc file, and I'm able to access it through a python file. However, I have all this previous code that runs through NEURON, through a .hoc file. It doesn't read the python file, so I have two options: I can either rewrite all the .hoc code in python, or I can open a .swc file in .hoc code. The latter is much easier, but I can't find the code for it, if anyone has any suggestions. Thank you!
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Uploading .swc file through .hoc

Post by ramcdougal »

Roughly speaking the HOC code would look exactly like the Python, but drop the h. part.

That said, HOC and Python are just two different interfaces to the same simulator. You can mix and match.

e.g. from Python, you can run a HOC script called my_script.hoc via:

Code: Select all

h.load_file("my_script.hoc")
and then if that script defined a HOC function called foo, from Python you could simply invoke e.g.

Code: Select all

h.foo(123)
Alternatively from HOC, you can invoke Python via nrnpython and/or by creating a PythonObject:

Code: Select all

oc>objref pyobj
oc>pyobj = new PythonObject()
oc>nrnpython("import math")
	1 
oc>pyobj.math.cos(3.14)
	-0.99999873 
neuron121!
Posts: 8
Joined: Thu Mar 31, 2022 11:00 pm

Re: Uploading .swc file through .hoc

Post by neuron121! »

Hello,

Thank you for the reply. I think this code is the most helpful to me.

oc>objref pyobj
oc>pyobj = new PythonObject()
oc>nrnpython("import math")
1
oc>pyobj.math.cos(3.14)
-0.99999873

However, when I run it in the neuron executable or in VS code, the third line always comes out as a 0, indicating that "the python object is not supported". Any suggestions?
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Uploading .swc file through .hoc

Post by ted »

If you're already familiar with Python, why not stick with Python?

from neuron import h, gui
# or, if you prefer,
# from neuron import h
# h.load_file('stdgui.hoc')
. . . next execute your python code that reads the swc file . . .
# then execute the legacy hoc file that does whatever useful stuff you need
h.load_file('foo.hoc')
# and continue in Python, referring to hoc-defined variables and functions as
# h.variablename and h.functionname()
Post Reply