Import mechanism with different default parameters

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
gduffley
Posts: 4
Joined: Thu Feb 04, 2016 8:46 pm

Import mechanism with different default parameters

Post by gduffley »

In Hoc, this syntax allows to import and change a default parameter for a mechanism:

Code: Select all

insert extracellular xraxial=Rpn0
Is there a equivalent syntax in Python?

Thanks,
Gordon
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Import mechanism with different default parameters

Post by ted »

The line of code in your post

Code: Select all

insert extracellular xraxial=Rpn0
will generate an error message unless it is part of a compound statement (one or more statements enclosed within a pair of curly brackets). You'll find a more complete discussion of hoc syntax in the NEURON Book and also in the online Programmer's Reference (see
https://www.neuron.yale.edu/neuron/stat ... yntax.html); for a concise summary and an example of how to analyze a program by doing a code walkthorough, you might want to see these slides https://www.neuron.yale.edu/ftp/neuron/ ... tc2012.pdf
Is there a equivalent syntax in Python?
I don't think that Python tolerates placing more than one statement in a single line.

If you are asking how to refer to hoc keywords etc. from Python, it's likely that you will need to know the answers to many related questions. The bottom line is that anything in hoc can be accessed from Python and vice versa. To learn how, in the Programmer's Reference see https://www.neuron.yale.edu/neuron/stat ... ython.html, especially under the subject headings
Python Accessing HOC
and
HOC accessing Python

Also, on NEURON's Documentation page http://www.neuron.yale.edu/neuron/docs see the subjects
Scripting NEURON with Python
and
Examples of using the Python interpreter to work with hoc/nrniv objects
gduffley
Posts: 4
Joined: Thu Feb 04, 2016 8:46 pm

Re: Import mechanism with different default parameters

Post by gduffley »

Hi Ted,

Thanks for the quick reply. I think my issue is resolved, but let me give the long form of my question for completeness. When parsing through the McIntyre MRG model, I came across this block of code:

Code: Select all

	
for i=0, paranodes1-1 {
		MYSA[i]{
			nseg=1
			diam=fiberD
			L=paralength1
			Ra=rhoa*(1/(paraD1/fiberD)^2)/10000
			cm=2*paraD1/fiberD
			insert pas
			g_pas=0.001*paraD1/fiberD		
			e_pas=-80
			insert extracellular xraxial=Rpn1 xg=mygm/(nl*2) xc=mycm/(nl*2)
			}
I conceptually understood what was going on until the the last line. After importing the mechanism using python, I tried to edit the variables of my section by doing:

Code: Select all


cur_node.insert("extracellular")
cur_node.xraxial = x

but I was thrown a:

Code: Select all

IndexError: missing index
Digging into the extracellular mechanism documentation, I found that the variable xraxial is actually a list of 2 variables, so they can be properly accessed with:

Code: Select all

cur_node.insert("extracellular")
cur_node.xraxial[0] = 5
cur_node.xraxial[1] = 5
My conclusion from all of this is the Hoc syntax actually changed the value of both variables, where in python you need to explicitly set each one individually. I am aware that all of this could be avoided by using the neuron.hoc.HocObject() class, but as a python enthusiast, I wanted to understand the equivalent syntax between the two ways of accessing neuron.

Thanks,
Gordon
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Import mechanism with different default parameters

Post by ted »

gduffley wrote:I tried to edit the variables of my section by doing:

Code: Select all

cur_node.insert("extracellular")
cur_node.xraxial = x
First let me point out that, after a mechanism has been inserted into a section, it is no longer necessary to insert that mechanism again.
My conclusion from all of this is the Hoc syntax actually changed the value of both variables
Actually that's an inference or hypothesis, which is yet to be verified. You have yet to carry out the "critical experiment" (test that can disprove the hypothesis), which is easily done done by taking advantage of the interpreter's "immediate execution" feature.

So, by now having performed that experiment, can you report whether the initial inference fell, or does it still stand?
Post Reply