Currently, I am using the version 3.last of the Brain Scaffold Builder that utilizes NEURON to simulate realistic neurons (in this case, I am working on a cerebellum scaffold). Ideally, I would like to implement a sinusoidal current clamp so that I can use it as if it were a native tool of NEURON (similar to what is already available with IClamp).
NEURON is implemented through this patch: https://github.com/dbbs-lab/patch.
Based on this topic in the NEURON forum: viewtopic.php?p=14760&hilit=sinusoid#p14760
I'm trying to implement a variant of the IClamp tool in BSB that generates a sinusoidal current pattern:
Code: Select all
NEURON {
POINT_PROCESS sinclamp
RANGE delay, dur, pkamp, freq, phase, bias
ELECTRODE_CURRENT i
}
UNITS {
(nA) = (nanoamp)
}
PARAMETER {
delay=5 (ms)
dur=200 (ms)
pkamp=1 (nA)
freq=1 (Hz)
phase=0 (rad)
bias=0 (nA)
PI=3.14159265358979323846
}
ASSIGNED {
i (nA)
}
BREAKPOINT {
at_time(delay)
at_time(delay + dur)
if (t < delay) {
i=0
}else{
if (t < delay+dur) {
i = pkamp*sin(2*PI*freq*(t-delay)/1000+phase)+bias
}else{
i = 0
}}}
Code: Select all
nrnivmodl
I have modified all the entries in the devices and adapter files with their respective __init__ referencing the new tool.
I have also made the necessary changes for the tool in the interpreter and object files of the path module.
mod in interpreter.py:
Code: Select all
def IClamp(self, x=0.5, sec=None):
sec = sec if sec is not None else self.cas()
clamp = IClamp(self, self.__h.IClamp(x, sec=transform(sec)))
clamp.__ref__(sec)
if hasattr(sec, "__ref__"):
sec.__ref__(clamp)
return clamp
def SinClamp(self, x=0.5, sec=None): # <<<<<<<<<<<<<<<============
sec = sec if sec is not None else self.cas()
clamp = SinClamp(self, self.__h.SinClamp(x, sec=transform(sec)))
clamp.__ref__(sec)
if hasattr(sec, "__ref__"):
sec.__ref__(clamp)
return clamp
def SEClamp(self, sec, x=0.5):
clamp = SEClamp(self, self.__h.SEClamp(transform(sec(x))))
clamp.__ref__(sec)
if hasattr(sec, "__ref__"):
sec.__ref__(clamp)
return clamp
Code: Select all
def iclamp(self, x=0.5, delay=0, duration=100, amplitude=0):
"""
Create a current clamp on the section.
"""
clamp = self._interpreter.IClamp(x=x, sec=self)
clamp.delay = delay
clamp.dur = duration
if _is_sequence(amplitude):
# If its a sequence play it as a vector into the clamp
dt = self._interpreter.dt
t = self._interpreter.Vector([delay + dt * i for i in range(len(amplitude))])
v = self._interpreter.Vector(amplitude, t)
v.play(clamp._ref_amp, t.__neuron__())
clamp.__ref__(v)
clamp.__ref__(t)
else:
clamp.amp = amplitude
return clamp
def sinclamp(self, x=0.5, delay=5, dur=100, pkamp=0, freq=1, phase=0, bias=0.35): # <<<<<<<<<<<<<<<==
"""
Create a sinusoidal current clamp on the section.
"""
clamp = self._interpreter.SinClamp(x=x, sec=self)
clamp.delay = delay
clamp.dur = dur
clamp.pkamp = pkamp
clamp.freq = freq
clamp.phase = phase
clamp.phase = phase
clamp.bias = bias
if _is_sequence(pkamp):
# If its a sequence play it as a vector into the clamp
dt = self._interpreter.dt
t = self._interpreter.Vector([delay + dt * i for i in range(len(pkamp))])
v = self._interpreter.Vector(pkamp, t)
v.play(clamp._ref_amp, t.__neuron__())
clamp.__ref__(v)
clamp.__ref__(t)
else:
clamp.pkamp = pkamp
return clamp
Code: Select all
"devices": {
"sinusoid": {
"io": "input",
"device": "sin_clamp",
"targetting": "cell_type",
"cell_types": [
"stellate_cell"
],
"section_types": [
"soma"
],
"parameters": {
"delay": 5,
"dur": 500,
"pkamp": 0.35,
"freq": 1,
"phase": 0,
"bias": 0.35
}
},
Code: Select all
AttributeError: 'hoc.HocObject' object has no attribute 'SinClamp'
device.implement(target, location)
File "/home/simone/.pyenv/versions/3.9.0/envs/BSB_tool/lib/python3.9/site-packages/bsb/simulators/neuron/devices/sin_clamp.py", line 7, in implement
location.section.sinclamp(**pattern)
File "/home/simone/.pyenv/versions/3.9.0/envs/BSB_tool/lib/python3.9/site-packages/patch/objects.py", line 318, in sinclamp
clamp = self._interpreter.SinClamp(x=x, sec=self)
File "/home/simone/.pyenv/versions/3.9.0/envs/BSB_tool/lib/python3.9/site-packages/patch/interpreter.py", line 239, in SinClamp
clamp = SinClamp(self, self.__h.SinClamp(x, sec=transform(sec)))
AttributeError: 'hoc.HocObject' object has no attribute 'SinClamp'
I know that I may be asking for something quite challenging, and I apologize if I have posted it in the wrong section