Questions on Linear Circuit Builder

Anything that doesn't fit elsewhere.
Post Reply
ChrisR

Questions on Linear Circuit Builder

Post by ChrisR »

Hi All!

I have two questions:

Is it possible to combine a hoc neuron model with a linear circuit from the Linear Circuit Builder to create a hoc file that can be run by a script?
I don't see how .ses and the normal hoc configuration plays together.

How can I play a current from an external file into a current source in the Linear Circuit Builder? Does this work with "External Stim Pattern" or do I have to use the "Play" option from the "Vector" menu. I tried both but
1. I couldn't load the external file. How does it have to be formatted?
2. The variables like LinearCircuit[0].I1 or Vector[149] corresponding to the current source were not recognized by "Play".

Thanks a lot!
Chris
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Questions on Linear Circuit Builder

Post by ted »

ChrisR wrote:I don't see how .ses and the normal hoc configuration plays together.
ses files are merely machine-written hoc code. hoc and ses files play together extremely well. It is even possible to edit ses files, e.g. if you want to change the name of a variable that is plotted in a graph, or to steal code from ses files that you can then reuse in your own hoc programs (for an example see
How to use hoc to plot a variable vs. time
https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=552).
Is it possible to combine a hoc neuron model with a linear circuit from the Linear Circuit Builder to create a hoc file that can be run by a script?
Absolutely. Start NEURON and make sure that an instance of your model cell exists. Start the Linear Circuit Builder, and every time you spawn one of those "cell thingies" on its canvas you are actually getting a tool that allows you to attach an electrode to any section of any cell that existed before you started the Linear Circuit Builder. When you're finished setting up
your circuit, use the Print & File Window Manager to save the Linear Circuit Builder, and any graphs or other GUI tools that you created with it, to a ses file. Then you can reuse it in the future by writing an init.hoc file that contains the following:

Code: Select all

load_file("celldef.hoc") // hoc (or ses) file that specifies properties your model cell(s)
load_file("circuit.ses") // ses file saved from your Linear Circuit Builder and its associated GUI tools
For some practice, try this exercise
Introduction to the Linear Circuit Builder
http://www.neuron.yale.edu/course/lincir1/lincir1.html
How can I play a current from an external file into a current source in the Linear Circuit Builder? Does this work with "External Stim Pattern"
Yep. On the LCB's Simulate page, click on the Source f(t) button and select the name of the current souce. This brings up a parameter panel called something like "f(t) for I1 of Lin...bla..." Click on the "External Stim Pattern" button and the parameter panel disappers.

Next click on the Source f(t) button again, and select the name of the current souce. This time you get a panel with a message that says something like "External Stim Pattern ... should play into the alias LinearCircuit[0].I1"

So create a pair of vectors called tvec and ivec. Fill ivec with the series of current values, and tvec with the corresponding time values. Then execute
ivec.play(&LinearCircuit[0].i, tvec)
and every time you run a simulation, the current source will deliver the desired current waveform.

You should be able to accomplish same results with the GUI's Vector/Play tool, but setting up "vector play" with hoc is such a convenient idiom that you'll learn it by heart if you just write the code a few times.
I couldn't load the external file. How does it have to be formatted?
Here's how to discover for yourself:
Run neurondemo
Select the hh model.
Run a simulation.
Use the v graph's "Pick vector" to select the displayed waveform (click on the graph's menu box, then select "Pick vector" from the dropdown menu, and finally click on the voltage trace).
Then click on NEURON Main Menu / Vector / Save to File
Finalliy, examine the file with any text editor (not MSWord or WordPad or any WYSIWYG program).

BTW the Vector class has very convenient methods for reading data from files.
cengique
Posts: 7
Joined: Thu Jun 09, 2011 7:22 pm

Re: Questions on Linear Circuit Builder

Post by cengique »

Hello,

I have been trying to use the LinerCircuit to simulate electrode capacitance (Ce) and series resistance (Re) properties, but I'm having problems. I am not sure if this is the most direct way of doing this, but I built the simple circuit below that is attached to a single compartmental soma model with only passive properties (E=-88 mV, g_leak=3.2 nS):
Image
Re=28 MOhm and Ce=0.1 pF. The voltage clamp stays at -70 mV for 10 ms and then jumps to -90 mV for 100 ms. I can estimate the leak current to be 57 pA at the -70 mV holding potential, and I can verify this when I plot soma.i.pas(0.5). However, when I plot the LinerCircuit[0].VC_I, I get about 27 pF current. This doesn't make any sense, as if the VC current is different, it must be larger than the leak at the soma.

Is there anything obviously wrong with this picture? Do you have an explanation why I see a smaller clamp current than the somatic leak?

Thanks..
-Cengiz

ModelView output below (removed duplicates and VC parameters show up as 0, but I can see the correct values from within LinearCircuit)

Code: Select all

1 sections; 1 segments

* 1 real cells
    * root soma
        1 sections; 1 segments
        * 1 distinct values of nseg
            Longest dx is 10000 at soma with nseg=1
            nseg consistent under assumption of dx=10000 and nseg=2*int(L/dx/2)+1
            Greatest dlambda is 0.00224411 at soma with nseg=1
        * 3 inserted mechanisms
            Ra = 35.4
            cm = 1.8e-05
            * pas
                g_pas = 3.2e-09
                e_pas = -88
        ModelViewParmSubset[0] (1 sections)
        * soma {
                Ra = 35.4
                cm = 1.8e-05
                g_pas = 3.2e-09
                e_pas = -88
            }
        * 2 Point Processes
            * 1 VClamp
                dur[0] = 0
                dur[1] = 0
                dur[2] = 0
                amp[0] = 0
                amp[1] = 0
                amp[2] = 0
                gain = 100000
                rstim = 1
                tau1 = 0.001
                tau2 = 0
                e0 = -34.3137
                vo0 = 3.43137e+06
                vi0 = -70
                fac = 0
            1 PointProcessMark
0 artificial cells
0 NetCon objects
1 LinearMechanism objects

* Density Mechanisms
    * Mechanisms in use
        Ra
        capacitance
        pas
    * Homogeneous Parameters
        Ra = 35.4
        cm = 1.8e-05
        g_pas = 3.2e-09
        e_pas = -88
    Heterogeneous Parameters
    Global parameters for density mechanisms
    KSChan definitions for density mechanisms
    * Mechanisms in use
        Ra
        capacitance
        pas
    * Homogeneous Parameters
        Ra = 35.4
        cm = 1.8e-05
        g_pas = 3.2e-09
        e_pas = -88
    Heterogeneous Parameters
    Global parameters for density mechanisms
    KSChan definitions for density mechanisms
* 2 point processes (0 can receive events) of 2 base classes
    * 2 Point Processes
        * 1 VClamp
            dur[0] = 0
            dur[1] = 0
            dur[2] = 0
            amp[0] = 0
            amp[1] = 0
            amp[2] = 0
            gain = 100000
            rstim = 1
            tau1 = 0.001
            tau2 = 0
            e0 = -34.3137
            vo0 = 3.43137e+06
            vi0 = -70
            fac = 0
        1 PointProcessMark
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Questions on Linear Circuit Builder

Post by ted »

It's good to see someone using the Linear Circuit Builder.

Comments on the equivalent circuit for an electrode:
1. Ce will have no effect on membrane potential when the junction of Ce and Re is driven by a voltage source. Also, if you are using step commands, the effect of Ce on clamp current will vanish within one integration step.
2. It would be better to attach Ce to the other end of Re.
3. Better yet, split Re into two pieces and attach Ce to their junction (a T circuit representation of an electrode's distributed resistance and capacitance).

Regarding the discrepancy between i_pas and the current delivered by the clamp--
pas is a density mechanism, and density mechanism currents and conductances are in mA/cm2 and S/cm2. The clamp's current, however, is in nA, and your g_leak is in nS. What is the surface area of your single compartment model?
cengique
Posts: 7
Joined: Thu Jun 09, 2011 7:22 pm

Re: Questions on Linear Circuit Builder

Post by cengique »

ted wrote:It's good to see someone using the Linear Circuit Builder.
Great! So, I'm not totally on the wrong track. And I really appreciate the quick reply! :)
ted wrote:Comments on the equivalent circuit for an electrode:
1. Ce will have no effect on membrane potential when the junction of Ce and Re is driven by a voltage source. Also, if you are using step commands, the effect of Ce on clamp current will vanish within one integration step.
2. It would be better to attach Ce to the other end of Re.
3. Better yet, split Re into two pieces and attach Ce to their junction (a T circuit representation of an electrode's distributed resistance and capacitance).
This is a good point. I didn't think like this before, but you are right, the capacitive current disappears after one integration step. However, this matches the response we get from real recordings, so it never bothered me. I will keep your suggestions in mind, though.
ted wrote: Regarding the discrepancy between i_pas and the current delivered by the clamp--
pas is a density mechanism, and density mechanism currents and conductances are in mA/cm2 and S/cm2. The clamp's current, however, is in nA, and your g_leak is in nS. What is the surface area of your single compartment model?
Ah, a few things.
1. After writing this post, I realized I really chose stupid values for the size parameters; i.e., my soma's area was normalized to 1 cm^2 by being 1 cm long. So I initially thought that could have resulted in an additional series resistance artifact. So now my passive parameters are consistent with the 5 um radius cells I am considering:

Code: Select all

soma {
	nseg = 1
	diam = 5 // [um], adjusted to make area 314 um^2
	L = 10 // [um] 
}
soma insert pas 
soma.cm = 5.72 // [uF/cm^2]
soma.g_pas = 1e-3 // [S/cm^2]
soma.e_pas = -88
From these, my soma's area is 3.14e-6 cm^2.
2. I didn't realize i_pas was in mA/cm^2. I knew it was in a different unit, but didn't consider it would also be scaled with the area. So now I scale i_pas to be in nA and can plot it together with VC_I (left) and also show passive vs capacitive currents at soma (unscaled, right):
Image Image
However, there is still a discrepancy between VC_I and i_pas after it is properly scaled. There still may be a mistake because it looks awfully similar to what I had initially. I hope you can spot it.
cengique
Posts: 7
Joined: Thu Jun 09, 2011 7:22 pm

Found it!

Post by cengique »

It was only one more thing to fix: I had radius instead of diameter in the soma diam parameter. :( Correcting it to 2*5 um = 10 um gave me matching VC_I and soma.i_pas! Thanks again, Ted.
-Cengiz
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Questions on Linear Circuit Builder

Post by ted »

Making mistakes is easy. The hard part is finding one's own mistake and fixing it. Thanks for following up with the diagnosis and fix.

By the way, if soma is the default section and nseg is 1, you can use hoc's area() function in your graph--plot 0.01*area(0.5)*i_pas(0.5) and you won't have to bother with calculating L*diam. Read about area in the Programmer's Reference.
cengique
Posts: 7
Joined: Thu Jun 09, 2011 7:22 pm

Re: Questions on Linear Circuit Builder

Post by cengique »

ted wrote:Making mistakes is easy. The hard part is finding one's own mistake and fixing it. Thanks for following up with the diagnosis and fix.
Sure :)
ted wrote:By the way, if soma is the default section and nseg is 1, you can use hoc's area() function in your graph--plot 0.01*area(0.5)*i_pas(0.5) and you won't have to bother with calculating L*diam. Read about area in the Programmer's Reference.
Great, that works, too!

Now this circuit works for me, but I observed something strange with the plots. LinearCircuit graphs and regular Neuron graphs seem to have a .0125 ms (dt/2 for me) difference between them. The LC graphs are correct, while other graphs start from x[0]=0.0125, and therefore everything is right shifted. My dt=0.025 ms. This is not a problem for me, as I am using the LC graphs and saving the data from there.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Questions on Linear Circuit Builder

Post by ted »

cengique wrote:LinearCircuit graphs and regular Neuron graphs seem to have a .0125 ms (dt/2 for me) difference between them. The LC graphs are correct, while other graphs start from x[0]=0.0125, and therefore everything is right shifted. My dt=0.025 ms.
If you have the NEURON Book, please read chapter 7, and in particular 7.4 Incorporationg Graphs and new objects into the plotting system. NEURON has four graphLists that control the updating of objects that have been appended to these lists. graphList[0], which is used for voltages, is updated at t, but graphList[1] and [2] are updated at t-0.5*dt and t+0.5*dt. This offset is used "to provide second-order correct plots of ionic currents and state variables, respectively, when the Crank-Nicholson method has been selected through the variable secondorder=2. The offset is meaningless when the default first-order method is used (secondorder=1) because first-order accuracy holds at all instants in the interval [t-0.5*dt, t+0.5*dt]. When the variable time step methods are chose, all variables are computed at the same t so the offset is 0 and the [1] and [2] graphList lists are identical to graphList[0]."

So, as is sometimes said, this is "a feature, not a bug." But in this case, it really is. A feature, that is.

If you don't like the offset, just plot everything in a Voltage axis plot (or append the Graph to graphList[0]). If you're using the NEURON Main Menu to spawn graphs, just use the graph's "Delete" menu item to get rid of the v(.5) that comes up automatically with Voltage axis graphs.
Post Reply