Mining Code from Channel Builder
Mining Code from Channel Builder
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
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
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Mining Code from Channel Builder
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.
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
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.
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.
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Mining Code from Channel Builder
I would have expected either of these to work if A is indeed a density mechanism. If you just executeBBAmp 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.
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?
Test by executingtyping 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.
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
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
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
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.
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.
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Mining Code from Channel Builder
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. Thenreturns the hh mechanism's gnabar at the internal node closest to 0.1.
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).
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
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)
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
Code: Select all
for seg in soma:
seg.hh.gnabar = 0.11
Code: Select all
for seg in soma:
seg.hh.gnabar = seg.x
Code: Select all
soma for (x, 0) gnabar_hh(x) = x
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
Thank you very much for your help. After a little more tweaking I have been able to get the results I wanted.
-YMP
-YMP
Re: Mining Code from Channel Builder
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!
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Mining Code from Channel Builder
When you ran mknrndll (or was it nrnivmodl?), did any error messages appear?I think there may be some problems or bugs of my .mod document.
Re: Mining Code from Channel Builder
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
-
- Site Admin
- Posts: 6384
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Mining Code from Channel Builder
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.
Reason: as a general rule, forums do not allow a user to open duplicate posts on the same question.