## how to add a current clamp in Python?

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

cassiehu
Posts: 24
Joined: Tue Sep 06, 2022 10:41 am

### how to add a current clamp in Python?

I want to put a current clamp of a special form instead of a constant on a neuron. The change of the value of current should be like in the following picture.
https://pic.imgdb.cn/item/638b3d2d16f2c2beb1f72805.png
ted
Posts: 6095
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

### Re: how to add a current clamp in Python?

The Vector class's play() method can be used to force the current delivered by an IClamp to follow an arbitrary waveform. However, if the waveform can be described by a function or algorithm, it might be easier to implement the function or algorithm in NMODL. The resulting point process would also be easier to use, and it would automatically work properly with NEURON's adaptive integrators. I mention this because the waveform in figure you provided looks like it could be described by an algorithm like this:

Code: Select all

Initialization: at t == 0 set current i to 0
During a simulation:
at each time step
if an event with weight w arrives
i = i * exp(-dt/tau)
i = i + w
else
i = i * exp(-dt/tau)
If this is what you have in mind, let me know and I will be glad to implement it for you.
cassiehu
Posts: 24
Joined: Tue Sep 06, 2022 10:41 am

### Re: how to add a current clamp in Python?

Thanks for your reply very much. You are right, the form of the curret trully is regular. We can treat it as an exponential form. Then could you introduce the method of the exponential form current to express it correctly in NEURON+ Python.
cassiehu
Posts: 24
Joined: Tue Sep 06, 2022 10:41 am

### Re: how to add a current clamp in Python?

I noticed that we can write in a mod file, is it right? I am still learning how to describe mechanisms with NMODL.
ted
Posts: 6095
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

### Re: how to add a current clamp in Python?

I am still learning how to describe mechanisms with NMODL.
Then it will save your time and mine if I just implement something that matches your needs. As bad as most user-written hoc or Python code may be, the sad truth is that most user-written NMODL code is even worse because of NMODL's peculiarities and the fact that very few people do enough programming in NMODL to develop any real competence. That may sound harsh, but reality is often harsh.

Here are two key questions.

First, are you sure that ExpSyn wouldn't do what you need? The current generated by an ExpSyn is
i = g * (v - e)
where v is local membrane potential, e is the ExpSyn's reversal potential, and g decays exponentially with time. If (v - e) is large and fluctuations of v are small, the time course of i can approximate a monoexponential decay very closely.

Second, is this thing that you want supposed to represent synaptic current that enters a cell through ion channels in the membrane, or is it supposed to represent a current that is injected into the cell through an electrode? Your answer is important because the sign convention for positive current flow depends on it.
cassiehu
Posts: 24
Joined: Tue Sep 06, 2022 10:41 am

### Re: how to add a current clamp in Python?

OK, I totally understand. For the first question, we are not sure wether "If (v - e) is large and fluctuations of v are small" which means this expression may not be absolutely correct under some circumstances. However, it seems to be appropriate for the form that I need, so I can try it firstly.

For the second question, it should represent a current that is injected into the cell through an electrode because it is an input current stimulus acting on the sensory neuron of C.elegans.

ted
Posts: 6095
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

### Re: how to add a current clamp in Python?

it should represent a current that is injected into the cell through an electrode
So this really is to be similar to an IClamp. The name I chose for this particular mechanism is ExpIClamp because it delivers a current that decays monoexponentially with time. Its source code is in a file called expiclamp.mod.

The source code for ExpIClamp is below. In the NEURON block note that the current generated by an ExpIClamp is declared to be an ELECTRODE_CURRENT. A depolarizing ELECTRODE_CURRENT has positive sign. The alternative would be an "ionic current", which would be declared in a NONSPECIFIC_CURRENT statement if its effect on ionic concentration is to be ignored, or in a USEION statement so that it can affect the concentration of a particular ion.

Code: Select all

COMMENT
An event-driven current source that delivers an electrode current
which decays monoexponentially with time.
Arrival of an event with weight w
instantaneously perturbs the current by w nA.
For example, a single event with weight 0.1
will elicit a single current pulse with peak amplitude 0.1 nA.

Developed by NTC based on ExpSyn.
ENDCOMMENT

NEURON {
POINT_PROCESS ExpIClamp
RANGE tau, i
ELECTRODE_CURRENT i
}

UNITS {
(nA) = (nanoamp)
}

PARAMETER {
tau = 0.1 (ms) <1e-9,1e9>
}

ASSIGNED {
i (nA)
}

STATE {
ii (nA)
}

INITIAL {
ii=0
}

BREAKPOINT {
SOLVE state METHOD cnexp
i = ii
}

DERIVATIVE state {
ii' = -ii/tau
}

ii = ii + weight
}
cassiehu
Posts: 24
Joined: Tue Sep 06, 2022 10:41 am

### Re: how to add a current clamp in Python?

Thank you very much!!!
I have learned your method while I still has a question about NET_RECEIVE module. I have known the information in the following picture from the book <Expanding NEURON’s Repertoire of Mechanisms with NMODL> that for synaptic model building the NET_RECEIVE module can be called by NetCon(). Then in this mod file, what should I write in Python code to give a value to weight. Is h.ExpIClamp.weight=2 a correct expression? Like in simple IClamp.

Secondly, if I want the current to have two decays which is shown in the following picture. What should I write in mod file, because its logic is like:
for t in [0,50ms]:
ii=exp(-t)+weight_1
for t in (50,100ms]:
ii=exp(-t)+weight_2(smaller than weight_1)
https://pic.imgdb.cn/item/63ca1669be43e0d30e46fea7.png
https://pic.imgdb.cn/item/638b3d2d16f2c2beb1f72805.png
https://pic.imgdb.cn/item/63ca169ebe43e0d30e477451.png
ted
Posts: 6095
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

### Re: how to add a current clamp in Python?

in this mod file, what should I write in Python code to give a value to weight
Nothing. Do not change the NMODL code. The weight associated with an event is specified by the weight parameter of the NetCon that (1) detected the presynaptic spike and (2) delivers the event to the synaptic target mechanism. The value of a NetCon's weight parameter can be specified when the NetCon is created, or after the NetCon has been created. In the file initexpiclamp.hoc you will see that the weight was specified after the NetCon was created. The Python syntax for assigning weight to a NetCon is identical. See the documentation of the NetCon class in the Programmer's Reference.
if I want the current to have two decays
then come up with a set of ODEs or a kinetic scheme that will produce such a time course, and I'll show you how to implement those equations properly in NMODL. Do not try to use crude hacks, like logic statements (conditional statements or "if" statements) to switch between one time constant and another--the resulting code will not work properly.
cassiehu
Posts: 24
Joined: Tue Sep 06, 2022 10:41 am

### Re: how to add a current clamp in Python?

and I'll show you how to implement those equations properly in NMODL.
ted
Posts: 6095
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

### Re: how to add a current clamp in Python?

if I want the current to have two decays
then come up with a set of ODEs or a kinetic scheme that will produce such a time course, and I'll show you how to implement those equations properly in NMODL.
cassiehu
Posts: 24
Joined: Tue Sep 06, 2022 10:41 am

### Re: how to add a current clamp in Python?

Hi, sorry that I am not fully understanding.
This is the mod file I tried and you said that do not use "if else" expression, then what should I write?
Plus, this stimuli has nothing to do with the synapse which means it does not have relationship with weight. So I changed a little, the number can just be a constant.

Code: Select all

COMMENT
An event-driven current source that delivers an electrode current which decays monoexponentially with time.
Arrival of an event with weight w instantaneously perturbs the current by w nA.
For example, a single event with weight 0.1 will elicit a single current pulse with peak amplitude 0.1 nA.

Developed by NTC based on ExpSyn.
ENDCOMMENT

NEURON {
POINT_PROCESS ExpIClamp
RANGE tau_1,tau_2, i
ELECTRODE_CURRENT i
}

UNITS {
(nA) = (nanoamp)
}

PARAMETER {
tau_1 = 0.2 (ms) <1e-9,1e9>
tau_2 = 0.1 (ms) <1e-9,1e9>
}

ASSIGNED {
i (nA)
}

STATE {
i_1 (nA)
i_2 (nA)
}

INITIAL {
i_1=0
i_2=0
}

BREAKPOINT {
SOLVE state METHOD cnexp
if (t>=0(ms) && t<200(ms) {
i = i_1 + 30
}    else   {
i=i_2+15
}
}

DERIVATIVE state {
i_1' = -i_1/tau_1
i_2' = -i_2/tau_2
}