# How to voltage clamp a neuron?

**URL:** <https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407>\
**Category:** Support\
**Created:** [18 June 2021 12:27 UTC](https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407 "2021-06-18T12:27:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![schmitts](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/schmitts/32/191_2.png) [@schmitts](https://brian.discourse.group/u/schmitts)\
**Post date:** [18 June 2021 12:27 UTC](https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407/1 "2021-06-18T12:27:55Z")

</div>

Hi!

I see a voltage-clamp implemented via a large conductance towards the clamp potential in [Example: Fig1 — Brian 2 2.4.2 documentation](https://brian2.readthedocs.io/en/stable/examples/frompapers.Brette_2012.Fig1.html). Is there a more straightforward solution?

Thanks,

Sebastian

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [18 June 2021 12:50 UTC](https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407/2 "2021-06-18T12:50:46Z")

</div>

That depends a bit on the details… The example tries to model a “realistic” voltage clamp in an experiment. Do you simply want to set the voltage to a fixed value for some time? And should it also be at an arbitrary time, or is it rather for modelling e.g. the refractory period?

---

<div class="post-metadata">

**Author:** ![schmitts](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/schmitts/32/191_2.png) [@schmitts](https://brian.discourse.group/u/schmitts)\
**Post date:** [18 June 2021 13:12 UTC](https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407/3 "2021-06-18T13:12:34Z")

</div>

I want to test the implementation of a voltage-dependent plasticity model. E.g, I want to have a defined membrane voltage at the time of an incoming spike. Should I exploit [Refractoriness — Brian 2 2.4.2 documentation](https://brian2.readthedocs.io/en/stable/user/refractoriness.html#defining-model-behaviour-during-refractoriness)?

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [18 June 2021 13:15 UTC](https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407/4 "2021-06-18T13:15:50Z")

</div>

Could you explain more what you mean by “a defined membrane voltage at the time of an incoming spike”? You have access to the membrane potentials of the pre- and post-synaptic cells with `v_pre` and `v_post` in the `on_pre=...` statement that gets triggered by an incoming spike, but I assume this is not enough for you?

---

<div class="post-metadata">

**Author:** ![schmitts](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/schmitts/32/191_2.png) [@schmitts](https://brian.discourse.group/u/schmitts)\
**Post date:** [18 June 2021 13:18 UTC](https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407/5 "2021-06-18T13:18:54Z")

</div>

I want to sweep the membrane potential and check that the plasticity rule does what it’s supposed to do. On second thought it’s [Plotting of arbitrary functions - #2 by mstimberg](https://brian.discourse.group/t/plotting-of-arbitrary-functions/399/2) again, but it’s somehow not so nice that I cannot test against my “full model”. It would be good if I don’t have to replace the neuron dynamics equations.

---

<div class="post-metadata">

**Author:** ![rth](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/rth/32/16_2.png) [@rth](https://brian.discourse.group/u/rth)\
**Post date:** [18 June 2021 13:35 UTC](https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407/6 "2021-06-18T13:35:54Z")

</div>

@schmitts, sorry for jumping into the conversation.

It seems you are trying to debug a part of the model (plasticity model) where voltage is a parameter. If so: segregate the plasticity model, make a postsynaptic equation like `v = stim(t) : 1`, use in plasticity model `v_post`, and create TimeArray `stim` with voltage sweep. If you want the voltage to be a constant: just `v : 1` and `(name of your NeuronGroup).v = (array of voltages to test)`

I’m not sure, I got your question right, but above is my standard way to debug a code in Brian. Hope it helps.

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [18 June 2021 14:08 UTC](https://brian.discourse.group/t/how-to-voltage-clamp-a-neuron/407/7 "2021-06-18T14:08:18Z")

</div>

I agree that changing the definition of `v` as proposed by @rth is probably the cleanest solution. If you prefer to keep your equations unchanged _and_ you don’t care that the membrane potential is doing weird stuff before and after the incoming spike (i.e. you are only looking at your plasticity model), you can also directly assign to `v_post` at the start of your `on_pre` statements. Either based on some parameter that you add to the synapse or neuron equations, or – if you prefer to not change anything in the equations at all – even based on some calculated expression, e.g. something along the lines of `v_post = -100*mV + 100*mV*j/(N_post-1)` to test voltage values from -100mV to 0mV based on the post-synaptic index and the total number of cells.
