Page 1 of 1

Mining Code from Channel Builder

Posted: Fri Mar 26, 2010 2:53 pm
by BBAmp
Hello,

I am currently working on translating a NEURON model into Python and I would like to know if there is a way to get Channel Builder info/code from the GUI into something Python can use.

I know how to get the hoc code as well as a text file info of the channel density mechanisms specified by channel builder (properties -> "clone channel type" or "text to stdout") but if I simply load these hoc files (using h.load_file("mechanism.hoc")) and insert the mechanisms into a cell they don't work properly if at all.

Is there a way for Python to somehow communicate with the channel builder or would I have to create my own custom mod files with the information I extract from the GUI?

I don't have much experience with the GUI so I apologize if I have looked over something obvious. I have tried searching the forums but I haven't been able to find anything useful.

Thank you,
-Youngmin Park

Re: Mining Code from Channel Builder

Posted: Sat Mar 27, 2010 7:06 pm
by ted
Suppose you have a Channel Builder that defines the properties of some channel, and has been saved to a ses file (for the sake of this example, let's say the file is called foo.ses, and the channel is called nax). Then all you have to do is load that file by use Python to exercise the hoc statement
load_file("foo.ses")
and you will be able to insert the nax mechanism wherever you want to, just as if it had been defined by a mod file.

Re: Mining Code from Channel Builder

Posted: Sun Mar 28, 2010 8:44 pm
by BBAmp
Thank you for your reply.

I was able to load the ses file but when I tried to insert one of my mechanisms with the command soma.insert('A') it says A is not a density argument name.

I've also tried creating a soma in hoc using h('create soma') and tried h.soma.insert('A') but I got the the same error message.

typing h('insert A') with either hoc or python created somas doesn't produce any errors but I can't tell if it is being inserted properly.

Re: Mining Code from Channel Builder

Posted: Mon Mar 29, 2010 12:30 pm
by ted
BBAmp wrote:I was able to load the ses file but when I tried to insert one of my mechanisms with the command soma.insert('A') it says A is not a density argument name.

I've also tried creating a soma in hoc using h('create soma') and tried h.soma.insert('A') but I got the the same error message.
I would have expected either of these to work if A is indeed a density mechanism. If you just execute
nrngui foo.ses
where foo is the name of the channel builder's session file, what is the first line under the Properties button in the ChannelBuilder? "A Density Mechanism" or something else?
typing h('insert A') with either hoc or python created somas doesn't produce any errors but I can't tell if it is being inserted properly.
Test by executing
h('soma psection()')
You should see, among other stuff, a line that starts
insert A
followed by paired curly brackets that report parameter names and values, for example
{gbar_A=0.001}

What version of NEURON are you running, and under what OS?

Re: Mining Code from Channel Builder

Posted: Fri Apr 02, 2010 6:00 pm
by BBAmp
OS: Linux Mint
Version: NEURON 7.1
Python version: 2.6.2

I double checked the mechanisms and they are indeed density mechanisms.

According to psection the mechanisms were placed properly but I am still not getting the results I am looking for.

I am starting to think I am not using the NetCon command properly. I'll try figuring out if anything else could be wrong on my end and come back here if I run into more problem.

Thank you,
-YMP

Re: Mining Code from Channel Builder

Posted: Sat Apr 03, 2010 1:35 pm
by BBAmp
Hi again,

Is there a way to change the values set by the ses files through python?

For example if I created a denisty mechanism called A where the default gmax is 0.1. I then insert the mechanism into the python defined soma with h('insert A') and verify that it indeed exists in the python soma with h('forall psection()').

I've tried typing soma.gmax_A = 0.2 but I get "AttributeError: 'nrn.Section' object has no attribute 'gmax_A'". I get another attribute error if I try soma.gmax.A = 0.2.

Re: Mining Code from Channel Builder

Posted: Sun Apr 04, 2010 12:50 pm
by ted
One Python syntax for referencing a range variable is
sectionname(rangevalue).mechanismname.rangevariable
sectionname(rangevalue) is a "Segment object".

Something that looks different, but which is really just another case of using a "Segment object", is to iterate a variable (name could be foo or anything else that doesn't conflict with other code in your program) over a section and then use
foo.mechanismname.rangevariable
In this example, foo is also a Segment object.

Specific examples:
Suppose soma contains hh, and soma.nseg is 3. Then

Code: Select all

soma(0.1).hh.gnabar
returns the hh mechanism's gnabar at the internal node closest to 0.1.

Code: Select all

for seg in soma:
  seg.hh.gnabar = 0.11
iterates "seg" over all internal nodes of soma and assigns the value 0.11 to the hh mechanism's gnabar parameter (nothing magical about the name "seg" here--it could just as easily have been "foo", but seg seems more suggestive of its purpose).

Code: Select all

for seg in soma:
  seg.hh.gnabar = seg.x
iterates over all internal nodes of soma, and at each node assigns that node's "range" to the hh mechanism's gnabar parameter at that location, i.e. is equivalent to the hoc

Code: Select all

soma for (x, 0) gnabar_hh(x) = x
You might find some other useful stuff in
Hines, M.L., Davison, A.P. and Muller, E. NEURON and Python. Frontiers in Neuroinformatics 3:, 1, 2009
(available from http://www.neuron.yale.edu/neuron/nrnpubs)

Re: Mining Code from Channel Builder

Posted: Mon Apr 05, 2010 2:05 pm
by BBAmp
Thank you very much for your help. After a little more tweaking I have been able to get the results I wanted.

-YMP