Example #1
0
def plasticity(synchan, plas_params):

    comp = synchan.parent
    for child in comp.children:
        if child.className == 'CaConc' or child.className == 'ZombieCaConc':
            cal = child
            CaMSG = 'concOut'
            break
        elif child.className == 'DifShell':
            cal = child
            CaMSG = 'concentrationOut'
            break
    else:
        print('Could not find calcium objects')
        return

    shname = synchan.path + '/SH'
    sh = moose.element(shname)
    log.debug("{} {} {}", synchan.path, sh.synapse[0], cal.path)

    plasname = comp.path + '/' + NAME_PLAS
    plas = moose.Func(plasname)

    #FIRST: calculate the amount of plasticity
    #y is input plasticity trigger (e.g. Vm or Ca)
    moose.connect(cal, CaMSG, plas, 'yIn')

    #x is the high threshold, z is the low threshold
    #This gives parabolic shape to plasticity between the low and high threshold
    #highfac and lowfac scale the weight change (set in SynParams.py)

    highfac = plas_params.highFactor
    lowfac = plas_params.lowFactor

    expression = highfac + "*(y>x)*(y-x)+(y>z)*(x>y)*(y-z)*(x-y)*" + lowfac

    plas.expr = expression

    #Must define plasticity expression first, else these next assignments do nothing

    plas.x = plas_params.highThreshold
    plas.z = plas_params.lowThreshold
    #SECOND: accumulate all the changes, as percent increase or decrease
    plasCum = moose.Func(plasname + NAME_CUM)
    #need input from the plasticity thresholding function to y
    moose.connect(plas, 'valueOut', plasCum, 'xIn')
    moose.connect(plasCum, 'valueOut', plasCum, 'yIn')
    plasCum.expr = "x+y*z"
    plasCum.z = sh.synapse[0].weight
    plasCum.y = 1.0
    moose.connect(plasCum, 'valueOut', sh.synapse[0], 'setWeight')

    return {'cum': plasCum, 'plas': plas, 'syn': synchan}
Example #2
0
def makeReacs():
    # Parameters
    volume = 1e-15
    CaInitConc = 60e-6
    NA = 6.022e23
    tauI = 1
    tauG = 0.1

    model = moose.Neutral('/cells')
    compartment = moose.CubeMesh('/cells/compartment')
    compartment.volume = volume

    # Make pools
    Ca = moose.BufPool('/cells/compartment/Ca')
    tgtCa = moose.BufPool('/cells/compartment/tgtCa')
    m = moose.Pool('/cells/compartment/m')
    chan = moose.Pool('/cells/compartment/chan')

    # Make Funcs
    f1 = moose.Func('/cells/compartment/f1')
    f2 = moose.Func('/cells/compartment/f2')

    # connect up
    moose.connect(f1, 'valueOut', m, 'increment')
    moose.connect(f2, 'valueOut', chan, 'increment')

    moose.connect(Ca, 'nOut', f1, 'xIn')
    moose.connect(tgtCa, 'nOut', f1, 'yIn')

    moose.connect(m, 'nOut', f2, 'xIn')
    moose.connect(chan, 'nOut', f2, 'yIn')

    # Set params
    Ca.concInit = CaInitConc
    tgtCa.concInit = tgtCaInitConc
    m.concInit = 0.0
    chan.concInit = 0.0
    volscale = 1.0

    f1.expr = str(volscale / tauI) + " * (x-y)"
    f2.expr = str(volscale / tauG) + " * (x-y)"

    #Plotting
    channelPlot = makePlot('channelConc', chan, 'Conc', 18)
    mPlot = makePlot('mConc', m, 'Conc', 18)
    caPlot = makePlot('Ca', Ca, 'Conc', 18)
    targetPlot = makePlot('tgtCa', tgtCa, 'Conc', 18)
    return (channelPlot, mPlot, caPlot)
Example #3
0
def chirp(gen_name="chirp",
          amp=1,
          f0=1,
          f1=50,
          T=0.8,
          start=0.1,
          end=0.5,
          simdt=10E-5,
          phase=0,
          amp_offset=0):
    chirper = moose.element('/chirpgen') if moose.exists(
        '/chirpgen') else moose.Neutral('/chirpgen')
    func_1 = moose.Func(chirper.path + '/' + gen_name)
    func_1.mode = 3
    func_1.expr = '{A}*cos(2*pi*({f1}-{f0})/{T}*x^2 + 2*pi*{f1}*x + {p})+{o}'.format(
        f0=f0, f1=f1, T=T, A=amp, p=phase, o=amp_offset)
    input = moose.StimulusTable(chirper.path + '/xtab')
    xarr = np.arange(start, end, simdt)
    input.vector = xarr
    input.startTime = 0.0
    input.stepPosition = xarr[0]
    input.stopTime = xarr[-1] - xarr[0]
    moose.connect(input, 'output', func_1, 'xIn')
    moose.useClock(0, '%s/##[TYPE=StimulusTable]' % (chirper.path), 'process')
    moose.useClock(0, '%s/##[TYPE=Func]' % (chirper.path), 'process')
    return func_1
Example #4
0
def desensitization(synchan, SynParams):
    '''
    Key equations to be implemented
    dep.expression = "x = x*"+str(dep_constant)+"y*"+str(SynParams.dep_per_spike)
    weight.expression = "weight*1/(1+x)/simdt"
    facsynchan uses:  (1+fac)/(1+dep)/simdt
    x above is dep, and we didn't have fac, hence 1/(1+x)
    weight is the current synaptic weight
    '''
    sh = moose.element(synchan).children[0]

    deppath = synchan.path + '/dep'
    weightpath = synchan.path + '/weight'
    dep = moose.Func(deppath)
    weight = moose.Func(weightpath)
    help_dep = moose.Func(deppath + "/help")

    activation = moose.Func(deppath + "/activation")
    activation_help = moose.Func(deppath + "/activation/help")

    y = moose.Func(deppath + "/y")
    condition = moose.Func(deppath + "/condition")

    help_dep.tick = synchan.tick
    dep.tick = synchan.tick
    weight.tick = synchan.tick
    activation.tick = synchan.tick
    activation_help.tick = synchan.tick
    y.tick = synchan.tick
    condition.tick = synchan.tick

    #x*exp(dt/tau)+y*dep_per_spike, where x is output of self!
    dep_const = np.exp(-synchan.dt / SynParams.dep_tau)
    dep.expr = "x*" + str(dep_const) + "+y*" + str(SynParams.dep_per_spike)
    help_dep.expr = "x"
    weight.expr = "z*(1./(1+x))/" + str(synchan.dt)
    activation.expr = "x+y"
    activation_help.expr = "x"
    y.expr = "x"
    condition.expr = "x&&(x==y)"

    moose.connect(dep, "valueOut", weight, "xIn")
    moose.connect(condition, 'valueOut', dep, 'yIn')
    moose.connect(condition, 'valueOut', weight, 'zIn')
    moose.connect(condition, 'valueOut', activation, 'zIn')
    moose.connect(sh, 'activationOut', activation, 'yIn')
    moose.connect(sh, 'activationOut', y, 'xIn')

    moose.connect(activation, "valueOut", condition, "xIn")
    moose.connect(y, "valueOut", condition, "yIn")
    moose.connect(condition, "valueOut", y, "zIn")
    moose.connect(activation, "valueOut", activation_help, "xIn")
    moose.connect(activation_help, "valueOut", activation, "xIn")
    moose.connect(dep, 'valueOut', help_dep, 'xIn')
    moose.connect(help_dep, 'valueOut', dep, 'xIn')

    moose.connect(weight, "valueOut", synchan, 'activation')
    moose.showmsg(synchan)
    return condition, activation
Example #5
0
def desensitization(synchan, SynParams):
    sh = moose.element(synchan).children[0]

    deppath = synchan.path + '/dep'
    weightpath = synchan.path + '/weight'
    dep = moose.Func(deppath)
    weight = moose.Func(weightpath)
    help_dep = moose.Func(deppath + "/help")

    activation = moose.Func(deppath + "/activation")
    activation_help = moose.Func(deppath + "/activation/help")

    y = moose.Func(deppath + "/y")
    condition = moose.Func(deppath + "/condition")

    help_dep.tick = synchan.tick
    dep.tick = synchan.tick
    weight.tick = synchan.tick
    activation.tick = synchan.tick
    activation_help.tick = synchan.tick
    y.tick = synchan.tick
    condition.tick = synchan.tick

    dep_const = np.exp(-synchan.dt / SynParams.dep_tau)
    dep.expr = "x*" + str(dep_const) + "+y*" + str(SynParams.dep_per_spike)
    help_dep.expr = "x"
    weight.expr = "z*(1./(1+x))/" + str(synchan.dt)
    activation.expr = "x+y"
    activation_help.expr = "x"
    y.expr = "x"
    condition.expr = "x&&(x==y)"

    moose.connect(dep, "valueOut", weight, "xIn")
    moose.connect(condition, 'valueOut', dep, 'yIn')
    moose.connect(condition, 'valueOut', weight, 'zIn')
    moose.connect(condition, 'valueOut', activation, 'zIn')
    moose.connect(sh, 'activationOut', activation, 'yIn')
    moose.connect(sh, 'activationOut', y, 'xIn')

    moose.connect(activation, "valueOut", condition, "xIn")
    moose.connect(y, "valueOut", condition, "yIn")
    moose.connect(condition, "valueOut", y, "zIn")
    moose.connect(activation, "valueOut", activation_help, "xIn")
    moose.connect(activation_help, "valueOut", activation, "xIn")
    moose.connect(dep, 'valueOut', help_dep, 'xIn')
    moose.connect(help_dep, 'valueOut', dep, 'xIn')

    moose.connect(weight, "valueOut", synchan, 'activation')
    moose.showmsg(synchan)
    return condition, activation
Example #6
0
 def __init__(self, *args):
     moose.Compartment.__init__(self, *args)
     self.spikegen = moose.SpikeGen('%s/spike' % (self.path))
     self.spikegen.edgeTriggered = 1 # This ensures that spike is generated only on leading edge.
     self.dynamics = moose.Func('%s/dynamics' % (self.path))
     self.initVm = 0.0
     self.Rm = 10e6
     self.Ra = 1e4
     self.Cm = 100e-9
     self.Em = 0 #-65e-3
     self.initVm = 0 #self.Em
     
     # Note that the result is dependent on exact order of
     # execution of SpikeGen and Func. If Func gets executed first
     # SpikeGen will never cross threshold.
     self.dynamics.expr = 'x >= y? z: x'
     moose.connect(self, 'VmOut', self.dynamics, 'xIn')
     moose.connect(self.dynamics, 'valueOut', self, 'setVm')
     moose.connect(self, 'VmOut', self.spikegen, 'Vm')
Example #7
0
def test_func_nosim():
    """Create a Func object for computing function values without running
    a simulations."""
    # func_0 demonstrates multivariable function
    lib = moose.Neutral('/library')
    func_0 = moose.Func('%s/func_0' % (lib.path))
    func_0.mode = 1
    num = 5
    expr = 'avg('
    for ii in range(num - 1):
        expr += 'x_%d, ' % (ii)
    expr += 'x_%d)' % (num - 1)
    print(('Expression:', expr))
    func_0.expr = expr
    for ii in range(num):
        var = 'x_%d' % (ii)
        print(('Setting:', var, '=', func_0.var[var]))
        func_0.var[var] = float(ii)
    print(('Expression:', func_0.expr))
    print('Variables after assignment:')
    for v in func_0.vars:
        print(('  %s = %g' % (v, func_0.var[v])))
    print(('value %g\n' % (func_0.value)))
Example #8
0
def test_func():
    """This function creates a Func object evaluating a function of a
    single variable. It both shows direct evaluation without running a
    simulation and a case where the x variable comes from another
    source.

    """
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')

    func_1 = moose.Func('%s/func_1' % (model.path))
    func_1.mode = 3  # mode = 1 : value, mode = 2 : derivative
    # Expression is that for tau_m in Traub's NaF channel model
    func_1.expr = 'x < -30e-3? 1.0e-3 * (0.025 + 0.14 * exp((x + 30.0e-3) / 10.0e-3)): 1.0e-3 * (0.02 + 0.145 * exp(( - x - 30.0e-3) / 10.0e-3))'
    # First we display the use of Func as a standalone funculator
    xarr = np.linspace(-120e-3, 40e-3, 1000)
    values = []
    deriv = []
    for x in xarr:
        func_1.var['x'] = x
        values.append(func_1.value)
        deriv.append(func_1.derivative)
    pylab.plot(xarr, values, 'g-', label='f(no-sim)')
    pylab.plot(xarr, np.array(deriv) / 1000, 'k-.', label="1e-3 * f'(no-sim)")

    simdt = xarr[1] - xarr[0]
    input = moose.StimulusTable('%s/xtab' % (model.path))
    input.vector = xarr
    input.startTime = 0.0
    input.stepPosition = xarr[0]
    input.stopTime = xarr[-1] - xarr[0]
    print((input.startTime, input.stopTime))

    moose.connect(input, 'output', func_1, 'xIn')

    x_tab = moose.Table('/data/xtab')
    moose.connect(x_tab, 'requestOut', input, 'getOutputValue')

    y_tab = moose.Table('%s/y' % (data.path))
    moose.connect(y_tab, 'requestOut', func_1, 'getValue')
    yprime_tab = moose.Table('%s/yprime' % (data.path))
    moose.connect(yprime_tab, 'requestOut', func_1, 'getDerivative')
    func_1.mode = 3  # This forces both f ad f' to be computed and sent out
    moose.setClock(0, simdt)
    moose.setClock(1, simdt)
    moose.setClock(2, simdt)
    moose.setClock(3, simdt)
    moose.useClock(0, '%s/##[TYPE=StimulusTable]' % (model.path), 'process')
    moose.useClock(1, '%s/##[TYPE=Func]' % (model.path), 'process')
    moose.useClock(2, '%s/##[TYPE=DiffAmp]' % (model.path), 'process')
    moose.useClock(3, '%s/##' % (data.path), 'process')
    moose.reinit()
    t = xarr[-1] - xarr[0]
    print(('Run for', t))
    moose.start(t)
    y = np.asarray(y_tab.vector)
    yp = np.asarray(yprime_tab.vector)
    pylab.plot(x_tab.vector, y, 'r-.', label='f(x)')
    pylab.plot(x_tab.vector, yp / 1000, 'b--', label="1e-3 * f'(x)")
    pylab.legend()
    pylab.show()
Example #9
0
def printRecursiveTree(elementid, level):
    """ Recursive helper function for printCellTree,
    specify depth/'level' to recurse and print subelements under MOOSE 'elementid'. """
    spacefill = "  " * level
    element = moose.Neutral(elementid)
    for childid in element.children:
        childobj = moose.Neutral(childid)
        classname = childobj.className
        if classname in ["SynChan", "KinSynChan"]:
            childobj = moose.SynChan(childid)
            print(
                spacefill + "|--",
                childobj.name,
                childobj.className,
                "Gbar=",
                childobj.Gbar,
                "numSynapses=",
                childobj.numSynapses,
            )
            return  # Have yet to figure out the children of SynChan, currently not going deeper
        elif classname in ["HHChannel", "HHChannel2D"]:
            childobj = moose.HHChannel(childid)
            print(
                spacefill + "|--",
                childobj.name,
                childobj.className,
                "Gbar=",
                childobj.Gbar,
                "Ek=",
                childobj.Ek,
            )
        elif classname in ["CaConc"]:
            childobj = moose.CaConc(childid)
            print(
                spacefill + "|--",
                childobj.name,
                childobj.className,
                "thick=",
                childobj.thick,
                "B=",
                childobj.B,
            )
        elif classname in ["Mg_block"]:
            childobj = moose.Mg_block(childid)
            print(
                spacefill + "|--",
                childobj.name,
                childobj.className,
                "CMg",
                childobj.CMg,
                "KMg_A",
                childobj.KMg_A,
                "KMg_B",
                childobj.KMg_B,
            )
        elif classname in ["SpikeGen"]:
            childobj = moose.SpikeGen(childid)
            print(
                spacefill + "|--",
                childobj.name,
                childobj.className,
                "threshold",
                childobj.threshold,
            )
        elif classname in ["Func"]:
            childobj = moose.Func(childid)
            print(
                spacefill + "|--",
                childobj.name,
                childobj.className,
                "expr",
                childobj.expr,
            )
        elif classname in [
                "Table"
        ]:  # Table gives segfault if printRecursiveTree is called on it
            return  # so go no deeper
        # for inmsg in childobj.inMessages():
        #    print spacefill+"  |---", inmsg
        # for outmsg in childobj.outMessages():
        #    print spacefill+"  |---", outmsg
        if len(childobj.children) > 0:
            printRecursiveTree(childid, level + 1)