Mining Code from Channel Builder

Using the graphical user interface to build and exercise models. Includes customizing the GUI by writing a little bit of hoc or Python
Post Reply
BBAmp
Posts: 12
Joined: Fri Mar 26, 2010 2:36 pm

Mining Code from Channel Builder

Post 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
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mining Code from Channel Builder

Post 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.
BBAmp
Posts: 12
Joined: Fri Mar 26, 2010 2:36 pm

Re: Mining Code from Channel Builder

Post 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.
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mining Code from Channel Builder

Post 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?
BBAmp
Posts: 12
Joined: Fri Mar 26, 2010 2:36 pm

Re: Mining Code from Channel Builder

Post 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
BBAmp
Posts: 12
Joined: Fri Mar 26, 2010 2:36 pm

Re: Mining Code from Channel Builder

Post 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.
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mining Code from Channel Builder

Post 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)
BBAmp
Posts: 12
Joined: Fri Mar 26, 2010 2:36 pm

Re: Mining Code from Channel Builder

Post 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
cassiehu
Posts: 35
Joined: Tue Sep 06, 2022 10:41 am

Re: Mining Code from Channel Builder

Post by cassiehu »

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

-YMP
Hi, I met the totally same problem as yours. And I have compiled the .mod document again, there was still the error that"argument not a density mechanism name". I think there may be some problems or bugs of my .mod document. So I want to ask you that how to solve this question as you said that you have accomplished it.
Looking forward to your reply very much!
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mining Code from Channel Builder

Post by ted »

I think there may be some problems or bugs of my .mod document.
When you ran mknrndll (or was it nrnivmodl?), did any error messages appear?
cassiehu
Posts: 35
Joined: Tue Sep 06, 2022 10:41 am

Re: Mining Code from Channel Builder

Post by cassiehu »

ted wrote: Mon Sep 12, 2022 11:34 am
I think there may be some problems or bugs of my .mod document.
When you ran mknrndll (or was it nrnivmodl?), did any error messages appear?
There was no error however. Also corresponding .c document and .o document were created. I don't know why Python said no argument not a density mechanism name. By the way, if I insert "hh", Python can run successfully. My NEURON version is 8.0.
https://pic.imgdb.cn/item/631ff2cf16f2c2beb122da5d.png
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Mining Code from Channel Builder

Post by ted »

Reply to cassiehu: I see that your posts in this discussion thread are actually about the same problem that you are asking in a separate thread ("Insert an ion channel written in a .mod file"). Further discussion of your problem will continue in that thread. After you have had the opportunity to read this message, all posts in this thread ("Mining Code from Channel Builder") with dates later than Friday, September 9, 2022, will be deleted.

Reason: as a general rule, forums do not allow a user to open duplicate posts on the same question.
Post Reply