Page 1 of 1

Updating the derivative in a NET_RECEIVE block

Posted: Thu Sep 26, 2024 10:31 pm
by urid
Hi,

I am writing a mod file for a custom synapse that requires updating the derivative of a STATE variable whenever the synapse is turned on and off. The code looks something like this (abstracted). This code works in the case where I am not updating the derivative during a synaptic event, but rather just an ASSIGNED variable. It seems like I might be missing something with how NMODL works because I tried different methods of achieving this and get the same results each time (like computing dA in the breakpoint according to the state of "on"). Any help is appreciated!

Code: Select all

NEURON {
    POINT_PROCESS syn
    RANGE g, e, i, ud, ur
    NONSPECIFIC_CURRENT i
}

PARAMETER {
    g (uS) e (mV)
    ud (ms) ur (ms)
    dur = 3.0 (ms)
}

ASSIGNED {
    i (nA) v (mV) dA(/ms) on ()
}

STATE {
    A ()
}

INITIAL {
    dA = A_off()
    A = 0
}

BREAKPOINT {
    SOLVE states METHOD derivimplicit
    i = g*(v-e)*y(A)
}

DERIVATIVE states {
    A' = dA
}

FUNCTION y(a) () {
	some function that depends on A
}

FUNCTION dA_on() (/ms) {
        dA_on = -A / ud
}

FUNCTION dA_off() (/ms) {
        dA_off= (1-A) / ud
}

NET_RECEIVE (weight, on) { : assume on is passed in as 0
   if (flag == 0) {
        : presynaptic spike began
        if (!on) {
            on = 1            : turn the synapse on
            net_send(dur, 1)  : offset after dur with flag=1
        } else {
            net_move(t + dur) : already on, so postpone offset time
        }
        dA = dA_on()
    }

    if (flag == 1) {
        : presynaptic spike ended
        on = 0               : turn the synapse off
        dA = dA_off()
    }
}

Re: Updating the derivative in a NET_RECEIVE block

Posted: Sun Sep 29, 2024 12:30 pm
by ted
In NMODL the assignment statement
foo = bar()
evaluates the value of bar() at the instant when the statement is executed, and passes that to foo. It does not make foo an alias for bar. If you want the value of foo to be calculated from function f0() when control variable c == 0, and from function f1() when c == 1, the way to do it, in pseudocode, is
if (c==0) foo = f0()
else
if (c==1) foo = f1()