Assigning values to a mechanism over all sections in anatomically detailed model

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

Moderator: hines

Post Reply
aliaped
Posts: 7
Joined: Sun Aug 09, 2020 12:10 pm

Assigning values to a mechanism over all sections in anatomically detailed model

Post by aliaped »

Hi there,

First off, thank you for taking the time to look into my question.

I am new to scripting in python, but have been working with .hoc and neuron for the last year or so.

I am trying to do something in python that seems elementary, and can be done in the .hoc interpreter with one line of code. I want to set the value of eh (reversal potential for h_ion) across all sections in a preexisting .ses file (containing both a rig and a cell builder) to -38 mV. I have loaded the file into my jupyter notebook and can interact with it using point processes just fine, but cannot figure out how to modify this density mechanism. All the required .mod files have been loaded as well.

In hoc, this could be done with:

Code: Select all

forsec all{eh = -38}
I have tried to do this in python in two ways:

1. Using the dictionary function of section.psection():

Code: Select all

for sec in h.all:
    sec.psection()['ions']['h']['eh']=-38
and just incase it is a dict vs list thing, as eh is a list, I also tried:

Code: Select all

for sec in h.all:
    sec.psection()['ions']['h']['eh'][0]=-38
It seems the dictionary returned this way is a copy, rather than a pointer? I looked at the psection() class in the python source code, and I do understand why this didn't work.

Then I tried:

2. Iterating through all the sections as such, which returns the class nrn.Mechanism, which I cannot figure out how to modify.

Code: Select all

for sec in h.all:
    for seg in sec.allseg():
        for mech in seg:
            ##{some mysterious statement that will allow me to modify the contents of mech}
            
I can't seem to find the doc for nrn.Mechanism, only h.MechanismType or h.MechanismStandard. Clearly I am doing this wrong. What am I missing?

Let me know if you need to see the actual .ses file to answer this question.

Many thanks again.
ted
Site Admin
Posts: 5887
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Assigning values to a mechanism over all sections in anatomically detailed model

Post by ted »

It's pretty straightforward in Python too. Try to think about the problem as being "how to iterate over all sections." This is easiest with the idiom

Code: Select all

for sec in h.allsec():
  one_or_more_statements
Example: suppose you have just created a bunch of sections and you need to insert hh into all of them.

Code: Select all

for sec in h.allsec():
  sec.insert('hh')
does the job.

Now suppose you want to change ena in all sections from its default 50 mV to 35 mV (as if your squid is hanging out near the mouth of a river, where nao will be somewhat lower than normal).

Code: Select all

for sec in h.allsec():
  sec.ena=35
Finally, you want to verify that ena is now 35 mV in all segments of all sections.

Code: Select all

for sec in h.allsec():
  for seg in sec:
    print("%s %f %f" % (sec.name(), seg.x, seg.ena))
ted
Site Admin
Posts: 5887
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Assigning values to a mechanism over all sections in anatomically detailed model

Post by ted »

Comments:
1. Iteration over all sections is required because ena is a range variable, not a global variable.
2. Iteration over all segments is not required because the syntax
sectionname.rangevarname = somevalue
assigns the value "somevalue" to the range variable in all segments of the referenced section--for example
dend.ena = 25
changes ena in all segments that belong to dend.
If you only want to affect the value of a range variable in a particular segment, then specify a range argument that is contained in that segment, e.g.
dend.ena(0.5) = 25
will set ena to 25 mV only in the segment of dend that contains the location 0.5.
aliaped
Posts: 7
Joined: Sun Aug 09, 2020 12:10 pm

Re: Assigning values to a mechanism over all sections in anatomically detailed model

Post by aliaped »

Hi Ted, much appreciated!
Post Reply