Page 1 of 1
Monitoring injected current in a segment
Posted: Tue May 05, 2015 8:05 am
by dilawar
In my nrnpython model, I am dealing with an issue. Response of my cell is independent of current I inject into `soma`. To check what is really going on, I want to monitor injected current into soma.
Code: Select all
def addStim(section):
"""Setup the stimulus"""
global _args, _records
# _records is a dictionary.
print("[INFO] Adding a pulsegen at %s" % section.hname())
stim = h.IClamp(0.5, sec=section)
stim.amp = 10000.0
stim.delay = 1.0
stim.dur = 1e3*_args.sim_time ## Some float
_records['stim'] = h.Vector()
_records['stim'].record(stim(1)._ref_i)
return True
I'd like to monitor two things:
- 1. How much current is sent from IClamp to soma
2. And what is being recieved by soma.
I tried setting up plots for this, but I am getting the following error:
Code: Select all
File "/data/dilawars/Work/BhallaLab/benchmarks/swc_models/loader_neuron.py", line 215, in addStim
_records['stim'].record(stim(1)._ref_i)
SystemError: NULL result without error in PyObject_Call
Re: Monitoring inject current in a segment
Posted: Tue May 05, 2015 1:30 pm
by ted
This code looks like a case of too clever by half.
Try getting something to work outside of a procedure.
Re: Monitoring injected current in a segment
Posted: Wed May 06, 2015 2:58 am
by dilawar
If I run `nrnpython` in python-debugger, I get the expected response. I'll try to cook up a minimal example and report it.
Re: Monitoring injected current in a segment
Posted: Wed May 06, 2015 3:16 am
by dilawar
Unfortunately the script I have do things which are bit involved:
1. It reads a given SWC file and loads it into NEURON.
2. It builds the topology of network (using python-networkx).
3. It inserts the channels into cell according to a given distribution.
4. It stimulate the cell for a second and plot the results in nrn.eps file.
between step 3 and step 4, I inject some current into soma (see function `addStim` in script `loader_neuron.py`, line number 192 onwards).
The neuron fires an action potential, no matter what value of current I inject into it. I suspect that stimulus is not working. Surprisingly, if I drop into Ipython shell during the execution (uncomment line no 205, and 205; when dropped into shell, type `exit` to return to normal execution), I see that changing properties of `IClamp` now changing the behavior of cell response: multiple fires for a small injected current, delayed stimulus causing delayed firing.
All files are kept at the following folder at github. They are many of them, running `test_nrn.sh` should reproduce the bug if any. The neuron I am using is compiled from source code.
https://github.com/BhallaLab/benchmarks ... models/bug
VERSION INFO ETC:
Code: Select all
NEURON -- VERSION 7.4 (1316:353c7c3ecd8d) 2015-04-03
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits
Code: Select all
Linux chamcham 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:53:56 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Re: Monitoring injected current in a segment
Posted: Wed May 06, 2015 10:01 pm
by ted
When adding a "new" feature to an existing, complex code base fails to work properly, it is often helpful to make a toy program that is much simpler and use that as a test case for adding the "new" feature. Suggest you make a toy program in which a single compartment model with nothing but the hh mechanism is driven by an IClamp, and use that as a testbed for whatever code you want to use to record and/or plot the current delivered by the IClamp. Once you get that to work, steal what code you need from it and reuse that in your more complex program.
Re: Monitoring injected current in a segment
Posted: Thu May 07, 2015 2:30 am
by dilawar
Dear Ted,
I'll create a toy example. Meanwhile, replacing following lines,
Code: Select all
stim = h.IClamp(0.5, sec=section)
stim.amp = 0.1
stim.dur = float(1e3*_args.sim_time)
with following lines did the trick.
Code: Select all
h('access %s' % section.hname())
h('objectvar stim')
h('stim = new IClamp(0.5)')
h('stim.amp = 0.1')
h('stim.dur = %s' % (1e3*_args.sim_time))
Re: Monitoring injected current in a segment
Posted: Thu Sep 17, 2015 9:38 am
by hines
Returning to the first post, there are at least three problems. Two are yours and one is mine.
My problem is that executing
stim(1)
is not generating a reasonable error message. I.e. internally NULL is being returned and i failed to do a
PyErr_SetString(PyExc_TypeError, "object is not callable");
I have pushed the fix:
http://www.neuron.yale.edu/hg/neuron/nr ... 218828d639
Anyway, stim is not a callable object so stim(1) is an error. I'm not sure what you meant by the '1' as the stim is located at section(0.5).
The remaining problem is that everytime you call addStim it will destroy the previous stim in _records['stim'] . ie. your dictionary never has
more than one element and that element has the key of 'stim'.
Thus
Code: Select all
for i in range(3):
addStim(s)
print _records
gives:
Code: Select all
[INFO] Adding a pulsegen at __nrnsec_0x10fc370
[INFO] Adding a pulsegen at __nrnsec_0x10fc370
[INFO] Adding a pulsegen at __nrnsec_0x10fc370
{'stim': <hoc.HocObject object at 0x7f3d79361c00>}
perhaps you meant to write
_records[stim] = h.Vector()
in which case you could have multple stim instances and
Code: Select all
for key, val in _records:
print key.hname(), val.hname()
gives
Code: Select all
IClamp[0] Vector[0]
IClamp[1] Vector[1]
IClamp[2] Vector[2]