I'm using python to import hoc commands from a hoc file
h('xopen("CA1PyrCmHSpikeErrorAHPDepth.hoc")')
However, before instantiating a cell from the template within the hoc file, I want to change some of the variables inside that hoc file.
Here's the code I'm using to instantiate a new cell from the template.
h('cell = new celltemplate(econ)')
I tried h('variableval=10'), and this doesn't seem to access the variable inside the template. So how do I do so?
Thanks for this wonderful community!
Changing hoc variables after xopen but before instantiation
Moderator: hines
-
- Posts: 267
- Joined: Fri Nov 28, 2008 3:38 pm
- Location: Yale School of Public Health
Re: Changing hoc variables after xopen but before instantiat
One solution is to declare a top-level variable that is used for initialization and set that.
For example, consider example.hoc's use of initvalue:
Here's a Python routine that creates two Example instances, both of which have independent "value" variables, but both of which are initially set to a default value specified in the Python:
As an aside, note that you don't need to write a string to access HOC functions and variables; they're accessible directly as members of the h module.
For example, consider example.hoc's use of initvalue:
Code: Select all
// default value for creating new Example objects
initvalue = 17
begintemplate Example
public value, print_value
external initvalue
proc print_value() {
printf("value = %g\n", value)
}
proc init() {
value = initvalue
}
endtemplate Example
Code: Select all
from neuron import h, gui
# load the template
h.load_file('example.hoc')
# change the default value (was 17)
h.initvalue = 32
obj = h.Example()
# show the default value (32)
obj.print_value()
# change the value and re-show
obj.value = 5.15
obj.print_value()
#
# or to give the object a direct HOC name
#
h('objref cell')
h.cell = h.Example()
# prints the (Python-specified as above) default value of 32
h.cell.print_value()
-
- Site Admin
- Posts: 6305
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Changing hoc variables after xopen but before instantiat
Parameters can also be passed at the time of instance creation.I believe you can also write templates using numarg so that 0 or more parameters can be passed.
Code: Select all
begintemplate Example
public print_value
proc print_value() {
printf("value = %g\n", value)
}
proc init() {
value = $1
}
endtemplate Example
objref elist
elist = new List()
for i=0,3 elist.append(new Example(i*i))
for i=0,elist.count()-1 {
print "item ", i
elist.o(i).print_value
}
Re: Changing hoc variables after xopen but before instantiat
Thank you ramcdougal, it works perfectly!
ted: good to see alternative ways of doing it!
ted: good to see alternative ways of doing it!