exp2syn without NetCon

NMODL and the Channel Builder.
mattmc88

exp2syn without NetCon

Post by mattmc88 »

I'd like to implement a synaptic conductance on single cell model with control over the rise and decay kinetics, like 'exp2syn' but that I can implement by simply setting a delay, like 'AlphaSynapse' without invoking NetCon.

I imagine I could cut and paste blocks from the two .mod files, and create a new PointProcess .mod file, but this is a bit over my head. Anybody done this, or know how?

Thanks!!

Matt
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: exp2syn without NetCon

Post by ted »

mattmc88 wrote:I'd like to implement a synaptic conductance on single cell model with control over the rise and decay kinetics, like 'exp2syn' but that I can implement by simply setting a delay, like 'AlphaSynapse' without invoking NetCon.
AlphaSynapse won't give you independent control over rise and decay kinetics. Why the aversion to using Exp2Syn?
I imagine I could cut and paste blocks from the two .mod files, and create a new PointProcess .mod file, but this is a bit over my head. Anybody done this, or know how?
You might find it helpful to read the documentation of NMODL in chapter 9 of The NEURON Book, or at least
Hines, M.L. and Carnevale, N.T.
The NEURON simulation environment.
Neural Computation 9:1179-1209, 1997
which is available from a link at http://www.neuron.yale.edu/neuron/nrnpubs
mattmc88

Re: exp2syn without NetCon

Post by mattmc88 »

Hi Ted,

I want to make a modified Exp2Syn because I already have a bunch of code written that implements spatial distributions of synapses (using AlphaSynapses) with different temporal profiles of activation. I'd like to adapt this code to utilize Exp2Syn-type synapses, instead, because I want the control over rise and decay.

As I said before, my only 'aversion' to Exp2Syn is that it is designed for the NetCon framework, so I can't use it with my existing code. I'll take a look at the literature you suggested, and see if I can figure it out.

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

Re: exp2syn without NetCon

Post by ted »

Suggestions for making the transition as painless as possible:

1. As a first step, put the code that creates each instance of an AlphaSynapse into a proc, and segregate it and its supporting code into a hoc file. For example, you could have a file called alphasyn.hoc that contains the following

Code: Select all

objref synlist
synlist = new List()

// 1st arg is location (range) of synapse
// other args specify time constant, peak conductance, reversal potential, and start time

proc makesyn() { localobj tobj
  tobj = new AlphaSynapse($1)
  synlist.append(tobj)
   . . . statements to set time constant, peak conductance, reversal potential, and start time
    of the AlphaSynapse referenced by tobj . . .
}
Then in your main program
load_file("alphasyn.hoc")
and every time you need to attach a new synapse to some section in your model cell
secname makesyn(synloc, tau, gmax, e, onset)
(replace secname, synloc, tau, gmax, e, and onset with desired values).

Verify that this works by comparing results with your original code.
After this is working, you're ready for step 2.

2. Copy alphasyn.hoc to exp2syn.hoc. In exp2syn.hoc, revise proc makesyn() like so

Code: Select all

objref ns, synlist, nclist
ns = new NetStim() // to generate the event(s) that will be delivered by the NetCons
 . . . statements to specify ns's "firing pattern" . . .
synlist = new List()
nclist = new List()

// 1st arg is location (range) of synapse
// other args specify time constants, peak conductance, reversal potential,
// and delay between time of presynaptic event
// and delivery of event to Exp2Syn mechanism

proc makesyn() { localobj tobj, ncobj
  tobj = new Exp2Syn($1)
  synlist.append(tobj)
  ncobj = new NetCon(ns, tobj)
  nclist.append(ncobj)

  tobj.tau1 = $2
  tobj.tau2 = $3
  ncobj.weight = $4 // will be Exp2Syn peak conductance
  tobj.e = $5
  ncobj.delay = $6
}
Also, make the necessary changes in your main program to deal with the 2nd time constant, and change the load_file() statement to
load_file("exp2syn.hoc")
Verify that this works by setting tau1 = tau2 = tau of your original model that used AlphaSynapses, and seeing that it produces the same results as the original.
mattmc88

Re: exp2syn without NetCon

Post by mattmc88 »

Well, I attempted step 1, by creating a file called 'exp2alpha.hoc' consisting of the following:

objref synlist
synlist = new List()

// 1st arg is location (range) of synapse
// other args specify time constant, peak conductance, reversal potential, and start time

proc makesyn() { localobj tobj
tobj = new AlphaSynapse($1)
synlist.append(tobj)

NEURON {
POINT_PROCESS AlphaSynapse
RANGE onset, tau, gmax, e, i
NONSPECIFIC_CURRENT i
}
UNITS {
(nA) = (nanoamp)
(mV) = (millivolt)
(uS) = (microsiemens)
}

PARAMETER {
onset=0 (ms)
tau=.1 (ms) <1e-3,1e6>
gmax=0 (uS) <0,1e9>
e=0 (mV)
}

ASSIGNED { v (mV) i (nA) g (uS)}

BREAKPOINT {
if (gmax) { at_time(onset) }
g = gmax * alpha( (t - onset)/tau )
i = g*(v - e)
}

FUNCTION alpha(x) {
if (x < 0 || x > 10) {
alpha = 0
}else{
alpha = x * exp(1 - x)
}
}

}

______________________________

Neuron gave some errors that came by too fast to read, and then crashed.

Still working on it...
mattmc88

Re: exp2syn without NetCon

Post by mattmc88 »

Ted-

Going back to my original idea, can I make a modified version of 'exp2syn.mod' that doesn't invoke NetCon, but instead has the onset as a parameter? The thing is, I'm not making a network model. I just want to activate exp2syn-type synapses on my single neuron model. I've attempted to do this, creating a file called 'exp2delay.mod' containing the following code:

COMMENT
Two state kinetic scheme synapse described by rise time tau1,
and decay time constant tau2. The peak conductance is gmax.
Decay time MUST be greater than rise time.

The solution of A->G->bath with rate constants 1/tau1 and 1/tau2 is
A = a*exp(-t/tau1) and
G = a*tau2/(tau2-tau1)*(-exp(-t/tau1) + exp(-t/tau2))
where tau1 < tau2

If tau2-tau1 -> 0 then we have a alphasynapse.
and if tau1 -> 0 then we have just single exponential decay.

The factor is evaluated in the
initial block such that an event with gmax 1 generates a
peak conductance of 1.

Because the solution is a sum of exponentials, the
coupled equations can be solved as a pair of independent equations
by the more efficient cnexp method.

ENDCOMMENT

NEURON {
POINT_PROCESS Exp2Delay
RANGE tau1, tau2, gmax, e, i
NONSPECIFIC_CURRENT i

RANGE g

}

UNITS {
(nA) = (nanoamp)
(mV) = (millivolt)
(uS) = (microsiemens)
}

PARAMETER {
onset = 0 (ms)
tau1 = 0.1 (ms) <1e-9,1e9>
tau2 = 1.5 (ms) <1e-9,1e9>
gmax = 0 (uS)
e = 0 (mV)
}

ASSIGNED { v (mV) i (nA) g (uS) factor }

STATE {
A (uS)
B (uS)
}

INITIAL {
LOCAL tp
if (tau1/tau2 > .9999) {
tau1 = .9999*tau2
}
A = 0
B = 0
tp = (tau1*tau2)/(tau2 - tau1) * log(tau2/tau1)
factor = -exp(-tp/tau1) + exp(-tp/tau2)
factor = 1/factor
}

BREAKPOINT {
if (gmax) { at_time(onset) }
SOLVE state METHOD cnexp
A = A + gmax*factor
B = B + gmax*factor
g = B - A
i = g*(v - e)
}

DERIVATIVE state {
A' = -A/tau1
B' = -B/tau2
}

______________________________

I've obviously replaced the parameter 'weight' with a RANGE variable, gmax, and added a parameter, onset, which is intended to be the time that the synapse is activate.

The problems I'm having are:

1) I'm not sure where to put
A = A + gmax*factor
B = B + gmax*factor

which came from

NET_RECEIVE(weight (uS)) {
A = A + weight*factor
B = B + weight*factor
}

in the file exp2syn.mod. I put it in the BREAKPOINT block, but I'm not sure where it belongs.

2) I'm not sure if the BREAKPOINT block code

if (gmax) { at_time(onset) }
SOLVE state METHOD cnexp

is reasonable, because I don't have 't,' or 't-onset' explicitly in the code, anywhere.
mattmc88

Re: exp2syn without NetCon

Post by mattmc88 »

I changed the BREAKPOINT block in my 'exp2delay.mod' to

BREAKPOINT {
if (gmax) { at_time(onset) }
A = gmax*factor
B = gmax*factor
SOLVE state METHOD cnexp
g = B-A
i = g*(v - e)
}
____________

I think this makes more sense. But, when I run 'modlunit' on this file, I get the message

4 [main] rxvy 4240 dtable::stdio_init: couldn't make stderr distinct from stdout

Also, if I put the mod file into the src/nrnoc directory, it doesn't show up in the PointProcess Manager.

Not sure what I'm doing wrong.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: exp2syn without NetCon

Post by ted »

mattmc88 wrote:Well, I attempted step 1, by creating a file called 'exp2alpha.hoc' consisting of the following:
You mean you put hoc and NMODL code into a single file and fed it to NEURON?
Neuron gave some errors that came by too fast to read, and then crashed.
I should think so. Don't mix hoc and NMODL in the same file. NMODL is for adding new functions to NEURON (by which I mean density mechanisms and point processes), and hoc is for using NEURON's functions to specify the biological properties that are represented in a model and then running simulations that use that model.
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: exp2syn without NetCon

Post by ted »

mattmc88 wrote:Going back to my original idea, can I make a modified version of 'exp2syn.mod' that doesn't invoke NetCon, but instead has the onset as a parameter?
. . .
The thing is, I'm not making a network model. I just want to activate exp2syn-type synapses on my single neuron model.
Understood. It is true that events and event-driven synaptic mechanisms were added to NEURON for the purpose of making it easier to build network models, but it turned out that they also make it much easier to deal with models of individual cells, especially when multiple synaptic inputs are involved. I get somewhat evangelistic about this sometimes. Sorry about that.
I've attempted to do this, creating a file called 'exp2delay.mod'
Bet you a nickel that, sooner or later, somebody (you?) will think of a hypothesis that requires revising your model so that it uses events. But if you're determined to plow ahead--and this does have the advantage of requiring the fewest changes to your original hoc code--here are some suggestions:
Drop the STATEs. Exp2Delay (a good name for it, by the way) should just calculate g from the difference between the analytical solutions to
A' = -A/tau1
B' = -B/tau2
You won't need the STATE or DERIVATIVE blocks, and the BREAKPOINT block will look much more like that of the AlphaSynapse mechanism. Instead, use a FUNCTION that computes the "normalized" conductance waveform, and multiply this by gmax.

So here it is, with these changes, and it does work--I'll email you a "test rig" constructed with the GUI that you can use to explore it for yourself.

Code: Select all

: based on AlphaSynapse and Exp2Syn
: like AlphaSynapse, produces a single conductance change at a predetermined time
: like Exp2Syn, time course of conductance change is difference between two exponentials
: tau1 must be < tau2
: if user specifies tau1 >= tau2, initialization will force tau1 to be slightly < tau2,
: and time course will closely approximate an alpha synapse with tau = tau2
: Matt McGinley and Ted Carnevale, 7/21/2010

NEURON {
	POINT_PROCESS Exp2Delay
	RANGE onset, tau1, tau2, gmax, e, i
	NONSPECIFIC_CURRENT i
	RANGE g
}

UNITS {
	(nA) = (nanoamp)
	(mV) = (millivolt)
	(uS) = (microsiemens)
}

PARAMETER {
	onset = 0 (ms)
	tau1 = 0.1 (ms) <1e-9,1e9>
	tau2 = 1.5 (ms) <1e-9,1e9>
	gmax = 0 (uS)
	e = 0	(mV)
}

ASSIGNED { v (mV) i (nA) g (uS) factor }

INITIAL {
	LOCAL tp
	if (tau1/tau2 > .9999) {
		tau1 = .9999*tau2
	}
	tp = (tau1*tau2)/(tau2 - tau1) * log(tau2/tau1)
	factor = -exp(-tp/tau1) + exp(-tp/tau2)
	factor = 1/factor
}

BREAKPOINT {
	if (gmax) { at_time(onset) }
        g = gmax*dblexp(t-onset)

	i = g*(v - e)
}

FUNCTION dblexp(x (ms)) {
  if (x < 0 || x/tau2 > 10) {
    dblexp = 0
  } else {
    dblexp = factor*(-exp(-x/tau1) + exp(-x/tau2))
  }
}
mattmc88

Re: exp2syn without NetCon

Post by mattmc88 »

Ted-

Thanks so much! I'm sure you're right that the NetCon approach is better, but I have time constraints on this project so I'm concerned I'd get bogged down in adapting my code to that approach. If, for the community, you are interested in revamping the code for the NetCon framework, I could send it to you before posting to the ModelDB.

So why was the STATE block used in exp2syn, in the first place? It seems to me that your code would work with the NetCon strategy, simply by importing the weight parameter, and would have the same advantages of simplicity and possibly computational efficiency.

I'll try your code and be excited that it works. Unfortunately, our email server is obnoxious and doesn't allow zip attachments. Can you just send me the files? Or change the zip extension to something else, and I'll change it back? Or send it to my other email: matthew dot j dot mcginley at ohsu dot edu.

Thanks again, Ted!

Matt
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: exp2syn without NetCon

Post by ted »

mattmc88 wrote:If, for the community, you are interested in revamping the code for the NetCon framework, I could send it to you before posting to the ModelDB.
When you publish, be sure to let me know so I can include the citation in NEURON's bibliography list. It's probably best for ModelDB to contain the actual code that was used for the simulations. Besides, to quote a math textbook I once used, conversion to a form that uses events can be "left as an exercise to the reader."
why was the STATE block used in exp2syn, in the first place?
The response of the synaptic conductance to input events is described by a set of differential equations. A closed form expression for the analytical solution is possible only if one knows the event (presynaptic spike) times in advance. But this is impossible because the reason for constructing a computational model of a network is that one does not know the times at which the network's cells will spike.

I just sent the zip file to your other email address. Let me know how it works.
mattmc88

Re: exp2syn without NetCon

Post by mattmc88 »

Oops. Sorry, Ted... my other email is: matthew dot j dot mcginley at gmail dot com (not ohsu dot edu). Can you send the zip, there?
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: exp2syn without NetCon

Post by ted »

Done
mattmc88

Re: exp2syn without NetCon

Post by mattmc88 »

Embarrassing questions:

In what folders do I put the exp2delay.mod and rig.hoc?
Do I need to run mknrndll in the directory with exp2delay.mod?
What do I need to do to make exp2delay.mod automatically come up as a Point Process option in the gui?

I would like to use this with nrn 7.1 on a Windows, and a Linux, machine. Do I need to get into the libnrnoc.so.0.0.0 shared library on the Linux machine? If so, I don't know how.

Thanks, as usual.

Matt
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: exp2syn without NetCon

Post by ted »

Necessary questions. The embarrassing ones are those that should have been asked, but aren't.
mattmc88 wrote:In what folders do I put the exp2delay.mod and rig.hoc?
For the purpose of using the demo, just expand the zip file, which will create a new directory called exp2delay that contains the hoc and mod file. Compile the mod file in the same directory as the hoc file that needs it (with mknrndll under MSWin, or the command line program nrnivmodl under Linux). Then double click on rig.hoc (under Linux, in that direcory execute the command
nrngui rig.hoc
) and NEURON will start, load the compiled mechanisms, and read and execute the statements in rig.hoc. If you examine the stuff that NEURON prints to its xterm ("interpreter window"), you'll see not only the "banner" that states the version of NEURON, but also the names of the mod files whose compiled mechanisms were loaded at startup.
What do I need to do to make exp2delay.mod automatically come up as a Point Process option in the gui?
Nothing. Compiled mechanisms are automatically integrated into the menus of GUI tools.
I would like to use this with nrn 7.1 on a Windows, and a Linux, machine. Do I need to get into the libnrnoc.so.0.0.0 shared library on the Linux machine?
mod files must be compiled on the machine on which they are to be used. Under OS X and MSWin the tool for compiling mod files is called mknrndll, and the result is a file called nrnmech.dll. Under Linux the tool is called nrnivmodl and the result is a subdirectory called i386 (assuming you're using a 32 bit Linux) that contains the shared library (and a bunch of other stuff). If you install a different version of NEURON, you have to delete the nrnmech.dll and all .o and .c files (or the i386 subdirectory and all its contents) and then recompile the mod files.
Post Reply