Exemplo n.º 1
0
def library1():
    import moose.genesis
    import moose.SBML
    import moose.chemMerge
    import moose.utils
    import moose.network_utils
    print('done')

    p1 = moose.le()
    a = moose.Pool('/a')
    for i in range(10):
        moose.Pool('/a/p%d' % i)
    p2 = moose.le()
    assert set(p2) - set(p1) == set(['/a'])
    aa = moose.le(a)
    assert len(aa) == 10

    try:
        moose.syncDataHandler('/a')
    except NotImplementedError:
        pass

    try:
        moose.showfield('/x')
    except ValueError:
        pass

    moose.showfield('/a')
    moose.showfields('/a')
def main():
    runtime = 2000
    displayInterval = 2
    makeModel()
    dsolve = moose.element('/model/dsolve')
    moose.reinit()
    #moose.start( runtime ) # Run the model for 10 seconds.

    a = moose.element('/model/compartment/a')
    b = moose.element('/model/compartment/b')
    s = moose.element('/model/compartment/s')
    print moose.showfields(a)

    #    img = mpimg.imread( 'turingPatternTut.png' )
    #imgplot = plt.imshow( img )
    #plt.show()

    plt.ion()
    fig = plt.figure(figsize=(12, 10))
    png = fig.add_subplot(211)
    #  imgplot = plt.imshow( img )
    ax = fig.add_subplot(212)
    ax.set_ylim(0, 2)
    plt.ylabel('Conc (mM)')
    plt.xlabel('Position along cylinder (microns)')
    pos = numpy.arange(0, a.vec.conc.size, 1)
    line1, = ax.plot(pos, a.vec.conc, label='a')
    line2, = ax.plot(pos, b.vec.conc, label='b')
    timeLabel = plt.text(60, 0.4, 'time = 0')
    plt.legend()
    fig.canvas.draw()

    for t in range(displayInterval, runtime, displayInterval):
        #if t>150 and t<170:
        #a.vec[80].conc = 1.2
        #b.vec[85].conc *= 1.2
        #s.vec[85].conc *= 1.2
        #a.vec[80].concInit *= 1.2
        #print 'entering the condition'
        moose.start(displayInterval)
        line1.set_ydata(a.vec.conc)
        line2.set_ydata(b.vec.conc)
        timeLabel.set_text("time = %d" % t)
        fig.canvas.draw()

    print(a.vec.conc)
    file = open('c41', 'w')
    ty = 0
    for tin in a.vec.conc:
        tout = str(tin)
        ty = ty + 1
        file.write(str(ty) + ' ' + tout + '\n')

    print("Hit 'enter' to exit")
    raw_input()
Exemplo n.º 3
0
def makeModel():
    model = moose.Neutral( '/model' )
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel( './branching.p', '/model/cell', 'Neutral' )
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind( '/model/cell/##' ):
        i.tick = -1

    # create container for model
    model = moose.element( '/model' )
    chem = moose.Neutral( '/model/chem' )
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh( '/model/chem/compt0' )
    compt0.separateSpines = 0
    compt0.geometryPolicy = 'cylinder'

    #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel( compt0 ) # Populate all compt with the chem system.

    compt0.diffLength = 1e-6 # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.cell = cell 
    moose.showfields( compt0 )

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve( '/model/chem/compt0/ksolve' )
    dsolve0 = moose.Dsolve( '/model/chem/compt0/dsolve' )
    stoich0 = moose.Stoich( '/model/chem/compt0/stoich' )

    # Configure solvers
    stoich0.compartment = compt0
    stoich0.ksolve = ksolve0
    stoich0.dsolve = dsolve0
    stoich0.path = '/model/chem/compt0/#'
    assert( stoich0.numVarPools == 3 )
    assert( stoich0.numProxyPools == 0 )
    assert( stoich0.numRates == 4 )
    
    num = compt0.numDiffCompts - 1
    moose.element( '/model/chem/compt0/a[' + str(num) + ']' ).concInit *= 1.5

    # Create the output tables
    graphs = moose.Neutral( '/model/graphs' )
    makeTab( 'a_soma', '/model/chem/compt0/a[0]' )
    makeTab( 'b_soma', '/model/chem/compt0/b[0]' )
    makeTab( 'a_apical', '/model/chem/compt0/a[' + str( num ) + ']' )
    makeTab( 'b_apical', '/model/chem/compt0/b[' + str( num ) + ']' )
Exemplo n.º 4
0
def makeModel():
    model = moose.Neutral("/model")
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel("./branching.p", "/model/cell", "Neutral")
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind("/model/cell/##"):
        i.tick = -1

    # create container for model
    model = moose.element("/model")
    chem = moose.Neutral("/model/chem")
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh("/model/chem/compt0")
    compt0.separateSpines = 0
    compt0.geometryPolicy = "cylinder"

    # reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel(compt0)  # Populate all compt with the chem system.

    compt0.diffLength = 1e-6  # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.subTreePath = cell.path + "/#"
    moose.showfields(compt0)

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve("/model/chem/compt0/ksolve")
    dsolve0 = moose.Dsolve("/model/chem/compt0/dsolve")
    stoich0 = moose.Stoich("/model/chem/compt0/stoich")

    # Configure solvers
    stoich0.compartment = compt0
    stoich0.ksolve = ksolve0
    stoich0.dsolve = dsolve0
    stoich0.path = "/model/chem/compt0/#"
    assert stoich0.numVarPools == 3
    assert stoich0.numProxyPools == 0
    assert stoich0.numRates == 4

    num = compt0.numDiffCompts - 1
    moose.element("/model/chem/compt0/a[" + str(num) + "]").concInit *= 1.5

    # Create the output tables
    graphs = moose.Neutral("/model/graphs")
    makeTab("a_soma", "/model/chem/compt0/a[0]")
    makeTab("b_soma", "/model/chem/compt0/b[0]")
    makeTab("a_apical", "/model/chem/compt0/a[" + str(num) + "]")
    makeTab("b_apical", "/model/chem/compt0/b[" + str(num) + "]")
Exemplo n.º 5
0
def main():
    neuron = moose.Neutral("/neuron")
    inputs = moose.Neutral("/inputs")
    outputs = moose.Neutral("/outputs")

    soma = create_spherical_compartment("/neuron/soma", 25e-6, 20e-6, 2.8, 4.0,
                                        0.03)
    pulse = create_pulse('/inputs/somaPulse', 50e-3, 100e-3, 1e-9, soma)
    vmtable = create_table('outputs/somaVmTable', soma, "getVm")
    print(soma.tick)
    print(soma.dt)
    moose.reinit()
    moose.start(300e-3)
    moose.showfields(vmtable)
    moose.showmsg(soma)
    moose.showmsg(pulse)
    moose.showmsg(vmtable)

    plot_table(vmtable)
    pyplot.show()
Exemplo n.º 6
0
def test_simple():
    """First test.
    >>> test_simple() # doctest: +NORMALIZE_WHITESPACE
    Rdesigneur: Elec model has 1 compartments and 0 spines on 0 compartments.
    <BLANKLINE>
    [/model[0]/elec[0]/soma[0]]
    Cm              =7.853981633975e-09
    Em              =-0.0544
    Im              =1.3194689277024895e-08
    Ra              =7639437.268410473
    Rm              =424413.1773342278
    Vm              =-0.06
    className       =ZombieCompartment
    diameter        =0.0005
    dt              =0.0
    fieldIndex      =0
    idValue         =455
    index           =0
    initVm          =-0.065
    inject          =0.0
    length          =0.0005
    name            =soma
    numData         =1
    numField        =1
    path            =/model[0]/elec[0]/soma[0]
    tick            =-2
    x               =0.0005
    x0              =0.0
    y               =0.0
    y0              =0.0
    z               =0.0
    z0              =0.0
    <BLANKLINE>
    INCOMING:
    /model[0]/elec[0]/soma ('parentMsg',) <--- /model[0]/elec ('childOut',)                                         
    OUTGOING:
    """
    rdes = rd.rdesigneur()
    rdes.buildModel()
    moose.showfields(rdes.soma)
    moose.showmsg(rdes.soma)
Exemplo n.º 7
0
def makeModel():
    """
    This example illustrates how to set up a oscillatory Turing pattern 
    in 1-D using reaction diffusion calculations.
    Reaction system is::

        s ---a---> a  // s goes to a, catalyzed by a.
        s ---a---> b  // s goes to b, catalyzed by a.
        a ---b---> s  // a goes to s, catalyzed by b.
        b -------> s  // b is degraded irreversibly to s.
        s ----Receptor---> a  // Receptor is activated by the ligand to cause an increase the conc of a. Here ligand-receptor interaction is not accounted for.
    in sum, **a** has a positive feedback onto itself and also forms **b**.
    **b** has a negative feedback onto **a**.
    Finally, the diffusion constant for **a** is 1/10 that of **b**.

    This chemical system is present in a 1-dimensional (cylindrical) 
    compartment. The entire reaction-diffusion system is set up 
    within the script.
    """
    # create container for model
    r0 = 1e-6  # m
    r1 = 1e-6  # m
    num = 100
    diffLength = 1e-7  # m
    len = num * diffLength  # m
    diffConst = 1e-13  # m^2/sec
    motorRate = 1e-6  # m/sec
    concA = 1  # millimolar
    dt4 = 0.5  # for the diffusion
    dt5 = 0.2  # for the reaction

    model = moose.Neutral('model')
    compartment = moose.CylMesh('/model/compartment')
    compartment.r0 = r0
    compartment.r1 = r1
    compartment.x0 = 0
    compartment.x1 = len
    compartment.diffLength = diffLength

    assert (compartment.numDiffCompts == num)

    # create molecules and reactions
    a = moose.Pool('/model/compartment/a')
    b = moose.Pool('/model/compartment/b')
    s = moose.Pool('/model/compartment/s')
    e1 = moose.MMenz('/model/compartment/e1')
    e2 = moose.MMenz('/model/compartment/e2')
    e3 = moose.MMenz('/model/compartment/e3')
    e4 = moose.MMenz('/model/compartment/e4')
    r1 = moose.Reac('/model/compartment/r1')
    rec = moose.Pool('/model/compartment/rec')

    moose.connect(e1, 'sub', s, 'reac')
    moose.connect(e1, 'prd', a, 'reac')
    moose.connect(a, 'nOut', e1, 'enzDest')
    e1.Km = 1
    e1.kcat = 1

    moose.connect(e2, 'sub', s, 'reac')
    moose.connect(e2, 'prd', b, 'reac')
    moose.connect(a, 'nOut', e2, 'enzDest')
    e2.Km = 1
    e2.kcat = 0.5

    moose.connect(e3, 'sub', a, 'reac')
    moose.connect(e3, 'prd', s, 'reac')
    moose.connect(b, 'nOut', e3, 'enzDest')
    e3.Km = 0.1
    e3.kcat = 1

    moose.connect(r1, 'sub', b, 'reac')
    moose.connect(r1, 'prd', s, 'reac')
    r1.Kf = 0.3  # 1/sec
    r1.Kb = 0.  # 1/sec

    moose.connect(e4, 'sub', s, 'reac')
    moose.connect(e4, 'prd', a, 'reac')
    moose.connect(rec, 'nOut', e4, 'enzDest')
    e4.Km = 0.001
    e4.kcat = 4

    # Assign parameters
    a.diffConst = diffConst / 10
    b.diffConst = diffConst
    s.diffConst = diffConst
    rec.diffConst = diffConst / 20

    # Make solvers
    ksolve = moose.Ksolve('/model/compartment/ksolve')
    dsolve = moose.Dsolve('/model/dsolve')
    # Set up clocks. The dsolver to know before assigning stoich
    moose.setClock(4, dt4)
    moose.setClock(5, dt5)
    moose.useClock(4, '/model/dsolve', 'process')
    # Ksolve must be scheduled after dsolve.
    moose.useClock(5, '/model/compartment/ksolve', 'process')

    stoich = moose.Stoich('/model/compartment/stoich')
    stoich.compartment = compartment
    stoich.ksolve = ksolve
    stoich.dsolve = dsolve
    stoich.path = "/model/compartment/##"
    assert (dsolve.numPools == 4)
    a.vec.concInit = [0.1] * num
    #    a.vec[50].concInit *= 1.2 # slight perturbation at one end.
    a.vec[10].concInit *= 1.2
    a.vec[35].concInit *= 1.2
    a.vec[60].concInit *= 1.2
    a.vec[85].concInit *= 1.2
    print moose.showfields(a)
    b.vec.concInit = [0.1] * num
    s.vec.concInit = [1] * num
    rec.vec.concInit = [0] * num
Exemplo n.º 8
0
def makeModel():
    model = moose.Neutral( '/model' )
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel( './spinyNeuron.p', '/model/cell', 'Neutral' )
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind( '/model/cell/##' ):
        i.tick = -1

    # create container for model
    model = moose.element( '/model' )
    chem = moose.Neutral( '/model/chem' )
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh( '/model/chem/compt0' )
    compt0.separateSpines = 1
    compt0.geometryPolicy = 'cylinder'
    compt1 = moose.SpineMesh( '/model/chem/compt1' )
    moose.connect( compt0, 'spineListOut', compt1, 'spineList', 'OneToOne' )
    compt2 = moose.PsdMesh( '/model/chem/compt2' )
    moose.connect( compt0, 'psdListOut', compt2, 'psdList', 'OneToOne' )

    #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel( compt0, True ) # Populate all 3 compts with the chem system.
    makeChemModel( compt1, False )
    makeChemModel( compt2, True )

    compt0.diffLength = 2e-6 # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.subTreePath = cell.path + "/#"
    moose.showfields( compt0 )

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve( '/model/chem/compt0/ksolve' )
    if useGssa:
        ksolve1 = moose.Gsolve( '/model/chem/compt1/ksolve' )
        ksolve2 = moose.Gsolve( '/model/chem/compt2/ksolve' )
    else:
        ksolve1 = moose.Ksolve( '/model/chem/compt1/ksolve' )
        ksolve2 = moose.Ksolve( '/model/chem/compt2/ksolve' )
    dsolve0 = moose.Dsolve( '/model/chem/compt0/dsolve' )
    dsolve1 = moose.Dsolve( '/model/chem/compt1/dsolve' )
    dsolve2 = moose.Dsolve( '/model/chem/compt2/dsolve' )
    stoich0 = moose.Stoich( '/model/chem/compt0/stoich' )
    stoich1 = moose.Stoich( '/model/chem/compt1/stoich' )
    stoich2 = moose.Stoich( '/model/chem/compt2/stoich' )

    # Configure solvers
    stoich0.compartment = compt0
    stoich1.compartment = compt1
    stoich2.compartment = compt2
    stoich0.ksolve = ksolve0
    stoich1.ksolve = ksolve1
    stoich2.ksolve = ksolve2
    stoich0.dsolve = dsolve0
    stoich1.dsolve = dsolve1
    stoich2.dsolve = dsolve2
    stoich0.path = '/model/chem/compt0/#'
    stoich1.path = '/model/chem/compt1/#'
    stoich2.path = '/model/chem/compt2/#'
    assert( stoich0.numVarPools == 1 )
    assert( stoich0.numProxyPools == 0 )
    assert( stoich0.numRates == 1 )
    assert( stoich1.numVarPools == 1 )
    assert( stoich1.numProxyPools == 0 )
    if useGssa:
        assert( stoich1.numRates == 2 )
        assert( stoich2.numRates == 2 )
    else:
        assert( stoich1.numRates == 1 )
        assert( stoich2.numRates == 1 )
    assert( stoich2.numVarPools == 1 )
    assert( stoich2.numProxyPools == 0 )
    dsolve0.buildNeuroMeshJunctions( dsolve1, dsolve2 )
    stoich0.buildXreacs( stoich1 )
    stoich1.buildXreacs( stoich2 )
    stoich0.filterXreacs()
    stoich1.filterXreacs()
    stoich2.filterXreacs()

    Ca_input_dend = moose.vec( '/model/chem/compt0/Ca_input' )
    print(len( Ca_input_dend ))
    for i in range( 60 ):
        Ca_input_dend[ 3 + i * 3 ].conc = 2.0

    Ca_input_PSD = moose.vec( '/model/chem/compt2/Ca_input' )
    print((len( Ca_input_PSD )))
    for i in range( 5 ):
        Ca_input_PSD[ 2 + i * 2].conc = 1.0

    # Create the output tables
    num = compt0.numDiffCompts - 1
    graphs = moose.Neutral( '/model/graphs' )
    makeTab( 'Ca_soma', '/model/chem/compt0/Ca[0]' )
    makeTab( 'Ca_d1', '/model/chem/compt0/Ca[1]' )
    makeTab( 'Ca_d2', '/model/chem/compt0/Ca[2]' )
    makeTab( 'Ca_d3', '/model/chem/compt0/Ca[3]' )
    makeTab( 'Ca_s3', '/model/chem/compt1/Ca[3]' )
    makeTab( 'Ca_s4', '/model/chem/compt1/Ca[4]' )
    makeTab( 'Ca_s5', '/model/chem/compt1/Ca[5]' )
    makeTab( 'Ca_p3', '/model/chem/compt2/Ca[3]' )
    makeTab( 'Ca_p4', '/model/chem/compt2/Ca[4]' )
    makeTab( 'Ca_p5', '/model/chem/compt2/Ca[5]' )
Exemplo n.º 9
0
def makeModel():
    model = moose.Neutral('/model')
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel('./spinyNeuron.p', '/model/cell', 'Neutral')
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind('/model/cell/##'):
        i.tick = -1

    # create container for model
    model = moose.element('/model')
    chem = moose.Neutral('/model/chem')
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh('/model/chem/compt0')
    compt0.separateSpines = 1
    compt0.geometryPolicy = 'cylinder'
    compt1 = moose.SpineMesh('/model/chem/compt1')
    moose.connect(compt0, 'spineListOut', compt1, 'spineList', 'OneToOne')
    compt2 = moose.PsdMesh('/model/chem/compt2')
    moose.connect(compt0, 'psdListOut', compt2, 'psdList', 'OneToOne')

    #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel(compt0)  # Populate all 3 compts with the chem system.
    makeChemModel(compt1)
    makeChemModel(compt2)

    compt0.diffLength = 2e-6  # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.subTreePath = cell.path + "/##"
    moose.showfields(compt0)

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve('/model/chem/compt0/ksolve')
    ksolve1 = moose.Gsolve('/model/chem/compt1/ksolve')
    ksolve2 = moose.Gsolve('/model/chem/compt2/ksolve')
    #dsolve0 = moose.Dsolve( '/model/chem/compt0/dsolve' )
    #dsolve1 = moose.Dsolve( '/model/chem/compt1/dsolve' )
    #dsolve2 = moose.Dsolve( '/model/chem/compt2/dsolve' )
    stoich0 = moose.Stoich('/model/chem/compt0/stoich')
    stoich1 = moose.Stoich('/model/chem/compt1/stoich')
    stoich2 = moose.Stoich('/model/chem/compt2/stoich')

    # Configure solvers
    stoich0.compartment = compt0
    stoich1.compartment = compt1
    stoich2.compartment = compt2
    stoich0.ksolve = ksolve0
    stoich1.ksolve = ksolve1
    stoich2.ksolve = ksolve2
    #stoich0.dsolve = dsolve0
    #stoich1.dsolve = dsolve1
    #stoich2.dsolve = dsolve2
    stoich0.path = '/model/chem/compt0/#'
    stoich1.path = '/model/chem/compt1/#'
    stoich2.path = '/model/chem/compt2/#'
    assert (stoich0.numVarPools == 3)
    assert (stoich0.numProxyPools == 0)
    assert (stoich0.numRates == 4)
    assert (stoich1.numVarPools == 3)
    assert (stoich1.numProxyPools == 0)
    #assert( stoich1.numRates == 4 )
    assert (stoich2.numVarPools == 3)
    assert (stoich2.numProxyPools == 0)
    #assert( stoich2.numRates == 4 )
    #dsolve0.buildNeuroMeshJunctions( dsolve1, dsolve2 )
    stoich0.buildXreacs(stoich1)
    stoich1.buildXreacs(stoich2)
    stoich0.filterXreacs()
    stoich1.filterXreacs()
    stoich2.filterXreacs()

    moose.element('/model/chem/compt2/a[0]').concInit *= 1.5

    # Create the output tables
    num = compt0.numDiffCompts - 1
    graphs = moose.Neutral('/model/graphs')
    makeTab('a_soma', '/model/chem/compt0/a[0]')
    makeTab('b_soma', '/model/chem/compt0/b[0]')
    makeTab('a_apical', '/model/chem/compt0/a[' + str(num) + ']')
    makeTab('b_apical', '/model/chem/compt0/b[' + str(num) + ']')
    makeTab('a_spine', '/model/chem/compt1/a[5]')
    makeTab('b_spine', '/model/chem/compt1/b[5]')
    makeTab('a_psd', '/model/chem/compt2/a[5]')
    makeTab('b_psd', '/model/chem/compt2/b[5]')
Exemplo n.º 10
0
def test1( ):
    rdes = rd.rdesigneur()
    rdes.buildModel()
    moose.showfields( rdes.soma )
Exemplo n.º 11
0
def test_mgblock():
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    soma = moose.Compartment('/model/soma')
    soma.Em = -60e-3
    soma.Rm = 1e7
    soma.Cm = 1e-9

    ###################################################
    # This is where we create the synapse with MgBlock
    #--------------------------------------------------
    nmda = moose.SynChan('/model/soma/nmda')
    nmda.Gbar = 1e-9
    mgblock = moose.MgBlock('/model/soma/mgblock')
    mgblock.CMg = 2.0
    mgblock.KMg_A = 1/0.33
    mgblock.KMg_B = 1/60.0

    # The synHandler manages the synapses and their learning rules if any.
    synHandler = moose.SimpleSynHandler( '/model/soma/nmda/handler' )
    synHandler.synapse.num = 1
    moose.connect( synHandler, 'activationOut', nmda, 'activation' )



    # MgBlock sits between original channel nmda and the
    # compartment. The origChannel receives the channel message from
    # the nmda SynChan.
    moose.connect(soma, 'VmOut', nmda, 'Vm' )
    moose.connect(nmda, 'channelOut', mgblock, 'origChannel')
    moose.connect(mgblock, 'channel', soma, 'channel')
    # This is for comparing with MgBlock
    nmda_noMg = moose.copy(nmda, soma, 'nmda_noMg')
    moose.connect( nmda_noMg, 'channel', soma, 'channel')
    moose.le( nmda_noMg )

    #########################################
    # The rest is for experiment setup
    spikegen = moose.SpikeGen('/model/spike')
    pulse = moose.PulseGen('/model/input')
    pulse.delay[0] = 10e-3
    pulse.level[0] = 1.0
    pulse.width[0] = 50e-3
    moose.connect(pulse, 'output', spikegen, 'Vm')
    moose.le( synHandler )
    #syn = moose.element(synHandler.path + '/synapse' )
    syn = synHandler.synapse[0]
    syn.delay = simdt * 2
    syn.weight = 10
    moose.connect(spikegen, 'spikeOut', synHandler.synapse[0], 'addSpike')
    moose.le( nmda_noMg )
    noMgSyn = moose.element(nmda_noMg.path + '/handler/synapse' )
    noMgSyn.delay = 0.01
    noMgSyn.weight = 1
    moose.connect(spikegen, 'spikeOut', noMgSyn, 'addSpike')
    moose.showfields( syn )
    moose.showfields( noMgSyn )
    Gnmda = moose.Table('/data/Gnmda')
    moose.connect(Gnmda, 'requestOut', mgblock, 'getGk')
    Gnmda_noMg = moose.Table('/data/Gnmda_noMg')
    moose.connect(Gnmda_noMg, 'requestOut', nmda_noMg, 'getGk')
    Vm = moose.Table('/data/Vm')
    moose.connect(Vm, 'requestOut', soma, 'getVm')
    for i in range( 10 ):
        moose.setClock( i, simdt )
    moose.setClock( Gnmda.tick, plotdt )
    print((spikegen.dt, Gnmda.dt))
    moose.reinit()
    moose.start( simtime )
    t = pylab.linspace(0, simtime*1e3, len(Vm.vector))
    pylab.plot(t, (Vm.vector + 0.06) * 1000, label='Vm (mV)')
    pylab.plot(t, Gnmda.vector * 1e9, label='Gnmda (nS)')
    pylab.plot(t, Gnmda_noMg.vector * 1e9, label='Gnmda no Mg (nS)')
    pylab.legend()
    #data = pylab.vstack((t, Gnmda.vector, Gnmda_noMg.vector)).transpose()
    #pylab.savetxt('mgblock.dat', data)
    pylab.show()
Exemplo n.º 12
0
def makeModel():
    model = moose.Neutral( '/model' )
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel( './spinyNeuron.p', '/model/cell', 'Neutral' )
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind( '/model/cell/##' ):
        i.tick = -1

    # create container for model
    model = moose.element( '/model' )
    chem = moose.Neutral( '/model/chem' )
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh( '/model/chem/compt0' )
    compt0.separateSpines = 1
    compt0.geometryPolicy = 'cylinder'
    compt1 = moose.SpineMesh( '/model/chem/compt1' )
    moose.connect( compt0, 'spineListOut', compt1, 'spineList', 'OneToOne' )
    compt2 = moose.PsdMesh( '/model/chem/compt2' )
    moose.connect( compt0, 'psdListOut', compt2, 'psdList', 'OneToOne' )

    #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel( compt0 ) # Populate all 3 compts with the chem system.
    makeChemModel( compt1 )
    makeChemModel( compt2 )

    compt0.diffLength = 2e-6 # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.subTreePath = cell.path + "/##"
    moose.showfields( compt0 )

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve( '/model/chem/compt0/ksolve' )
    ksolve1 = moose.Gsolve( '/model/chem/compt1/ksolve' )
    ksolve2 = moose.Gsolve( '/model/chem/compt2/ksolve' )
    #dsolve0 = moose.Dsolve( '/model/chem/compt0/dsolve' )
    #dsolve1 = moose.Dsolve( '/model/chem/compt1/dsolve' )
    #dsolve2 = moose.Dsolve( '/model/chem/compt2/dsolve' )
    stoich0 = moose.Stoich( '/model/chem/compt0/stoich' )
    stoich1 = moose.Stoich( '/model/chem/compt1/stoich' )
    stoich2 = moose.Stoich( '/model/chem/compt2/stoich' )

    # Configure solvers
    stoich0.compartment = compt0
    stoich1.compartment = compt1
    stoich2.compartment = compt2
    stoich0.ksolve = ksolve0
    stoich1.ksolve = ksolve1
    stoich2.ksolve = ksolve2
    #stoich0.dsolve = dsolve0
    #stoich1.dsolve = dsolve1
    #stoich2.dsolve = dsolve2
    stoich0.path = '/model/chem/compt0/#'
    stoich1.path = '/model/chem/compt1/#'
    stoich2.path = '/model/chem/compt2/#'
    assert( stoich0.numVarPools == 3 )
    assert( stoich0.numProxyPools == 0 )
    assert( stoich0.numRates == 4 )
    assert( stoich1.numVarPools == 3 )
    assert( stoich1.numProxyPools == 0 )
    #assert( stoich1.numRates == 4 )
    assert( stoich2.numVarPools == 3 )
    assert( stoich2.numProxyPools == 0 )
    #assert( stoich2.numRates == 4 )
    #dsolve0.buildNeuroMeshJunctions( dsolve1, dsolve2 )
    stoich0.buildXreacs( stoich1 )
    stoich1.buildXreacs( stoich2 )
    stoich0.filterXreacs()
    stoich1.filterXreacs()
    stoich2.filterXreacs()

    moose.element( '/model/chem/compt2/a[0]' ).concInit *= 1.5

    # Create the output tables
    num = compt0.numDiffCompts - 1
    graphs = moose.Neutral( '/model/graphs' )
    makeTab( 'a_soma', '/model/chem/compt0/a[0]' )
    makeTab( 'b_soma', '/model/chem/compt0/b[0]' )
    makeTab( 'a_apical', '/model/chem/compt0/a[' + str( num ) + ']' )
    makeTab( 'b_apical', '/model/chem/compt0/b[' + str( num ) + ']' )
    makeTab( 'a_spine', '/model/chem/compt1/a[5]' )
    makeTab( 'b_spine', '/model/chem/compt1/b[5]' )
    makeTab( 'a_psd', '/model/chem/compt2/a[5]' )
    makeTab( 'b_psd', '/model/chem/compt2/b[5]' )
Exemplo n.º 13
0
compartment_diameter = compartment_diameter * 1E-6  # Meters

sa = np.pi * compartment_diameter
curved_sa = sa * compartment_length

soma.Rm = RM * curved_sa
soma.Cm = CM / curved_sa
soma.initVm = initVm
soma.Em = Em

# reset simulation
moose.reinit()

# start simulation at 0 nA injection current.
moose.start(0.3)
moose.showfields(soma)  # check Vm

soma.inject = -1E-12
# reset simulation
moose.reint()
# start simulation at -1pA injection current.
moose.start(0.3)
moose.showfields(soma)

# Creation of pulse generator.
pulse = moose.PulseGen('pulse')
moose.showfield('pulse')
pulse.delay[0] = 50E-3  # First delay.
pulse.width[0] = 100E03  # Pulse width.
pulse.level[0] = 1E-9  # Pulse amplitude.
pulse.delat[1] = 1E9
Exemplo n.º 14
0
def main():
    runtime = 1500
    displayInterval = 2
    makeModel()
    dsolve = moose.element('/model/dsolve')
    moose.reinit()
    #moose.start( runtime ) # Run the model for 10 seconds.

    a = moose.element('/model/compartment/a')
    b = moose.element('/model/compartment/b')
    s = moose.element('/model/compartment/s')
    rec = moose.element('/model/compartment/rec')
    print moose.showfields(a)

    #    img = mpimg.imread( 'turingPatternTut.png' )
    #imgplot = plt.imshow( img )
    #plt.show()

    plt.ion()
    fig = plt.figure(figsize=(12, 10))
    png = fig.add_subplot(211)
    #  imgplot = plt.imshow( img )
    ax = fig.add_subplot(212)
    ax.set_ylim(0, 2)
    plt.ylabel('Conc (mM)')
    plt.xlabel('Position along cylinder (microns)')
    pos = numpy.arange(0, a.vec.conc.size, 1)
    line1, = ax.plot(pos, a.vec.conc, label='a')
    line2, = ax.plot(pos, b.vec.conc, label='b')
    line3, = ax.plot(pos, rec.vec.conc, label='rec')
    line4, = ax.plot(pos, s.vec.conc, label='s')
    timeLabel = plt.text(60, 0.4, 'time = 0')
    plt.legend()
    fig.canvas.draw()
    distS = 1
    posPer = [20, 45]
    timePer = 1
    gaussian = True
    storeAvec = []
    numStimPoints = 2
    print storeAvec
    print rec.vec.conc
    stimPoint = 0
    for ti in range(displayInterval, runtime, displayInterval):
        if ti > 150 and ti < 156:
            print stimPoint
            if gaussian == True:
                tempRec = computeTP(timePer, distS)
                #for pos in posPer[stimPoint]:
                print pos, 'position'
                rec.vec[posPer[stimPoint]].conc = rec.vec[
                    posPer[stimPoint]].conc + tempRec[0]
                for i in range(posPer[stimPoint] + 1, len(a.vec.conc)):
                    rec.vec[i].conc = rec.vec[i].conc + tempRec[
                        i - posPer[stimPoint]]
                    if int(posPer[stimPoint] * 2 - i) >= 0:
                        rec.vec[posPer[stimPoint] + posPer[stimPoint] -
                                i].conc = rec.vec[
                                    posPer[stimPoint] + posPer[stimPoint] -
                                    i].conc + tempRec[i - posPer[stimPoint]]
                rec.vec.conc = rec.vec.conc / 2
                stimPoint = stimPoint + 1
            else:
                #rec.vec[10].conc = 0.07
                #rec.vec[30].conc = 0.07
                rec.vec[22].conc = 0.08

            print 'receptor sum is', sum(rec.vec.conc), max(rec.vec.conc)
            plt.figure(10)
            plt.plot(rec.vec.conc)
            #raw_input()

        moose.start(displayInterval)
        storeAvec.append(a.vec.conc)
        line1.set_ydata(a.vec.conc)
        line2.set_ydata(b.vec.conc)
        line3.set_ydata(rec.vec.conc * 10)
        line4.set_ydata(s.vec.conc)
        timeLabel.set_text("time = %d" % ti)
        fig.canvas.draw()

    print(a.vec.conc)
    file = open('c41', 'w')
    ty = 0
    for tin in a.vec.conc:
        tout = str(tin)
        ty = ty + 1
        file.write(str(ty) + ' ' + tout + '\n')

    print("Hit 'enter' to exit")
    raw_input()
    return storeAvec
Exemplo n.º 15
0
def test_mgblock():
    """
    Demonstrates the use of MgBlock.
    Creates an NMDA channel with MgBlock and another without.
    Connects them up to the compartment on one hand, and to a
    SynHandler on the other, so as to receive synaptic input.
    Delivers two pulses to each receptor, with a small delay in between.

    Plots out the conductance change at each receptor and the reslting
    membrane potential rise at the compartment.

    Note that these NMDA channels do NOT separate out the contributions
    due to calcium and other ions. To do this correctly one should use
    the GHK object.
    """
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    soma = moose.Compartment('/model/soma')
    soma.Em = -60e-3
    soma.Rm = 1e7
    soma.Cm = 1e-9

    ###################################################
    # This is where we create the synapse with MgBlock
    #--------------------------------------------------
    nmda = moose.SynChan('/model/soma/nmda')
    nmda.Gbar = 1e-9
    mgblock = moose.MgBlock('/model/soma/mgblock')
    mgblock.CMg = 2.0
    mgblock.KMg_A = 1/0.33
    mgblock.KMg_B = 1/60.0

    # The synHandler manages the synapses and their learning rules if any.
    synHandler = moose.SimpleSynHandler( '/model/soma/nmda/handler' )
    synHandler.synapse.num = 1
    moose.connect( synHandler, 'activationOut', nmda, 'activation' )


    
    # MgBlock sits between original channel nmda and the
    # compartment. The origChannel receives the channel message from
    # the nmda SynChan.
    moose.connect(soma, 'VmOut', nmda, 'Vm' )
    moose.connect(nmda, 'channelOut', mgblock, 'origChannel')
    moose.connect(mgblock, 'channel', soma, 'channel')    
    # This is for comparing with MgBlock
    nmda_noMg = moose.copy(nmda, soma, 'nmda_noMg')
    moose.connect( nmda_noMg, 'channel', soma, 'channel')
    moose.le( nmda_noMg )

    #########################################
    # The rest is for experiment setup
    spikegen = moose.SpikeGen('/model/spike')
    pulse = moose.PulseGen('/model/input')
    pulse.delay[0] = 10e-3
    pulse.level[0] = 1.0
    pulse.width[0] = 50e-3
    moose.connect(pulse, 'output', spikegen, 'Vm')
    moose.le( synHandler )
    #syn = moose.element(synHandler.path + '/synapse' )
    syn = synHandler.synapse[0]
    syn.delay = simdt * 2
    syn.weight = 10
    moose.connect(spikegen, 'spikeOut', synHandler.synapse[0], 'addSpike')
    moose.le( nmda_noMg )
    noMgSyn = moose.element(nmda_noMg.path + '/handler/synapse' )
    noMgSyn.delay = 0.01
    noMgSyn.weight = 1
    moose.connect(spikegen, 'spikeOut', noMgSyn, 'addSpike')
    moose.showfields( syn )
    moose.showfields( noMgSyn )
    Gnmda = moose.Table('/data/Gnmda')
    moose.connect(Gnmda, 'requestOut', mgblock, 'getGk')
    Gnmda_noMg = moose.Table('/data/Gnmda_noMg')
    moose.connect(Gnmda_noMg, 'requestOut', nmda_noMg, 'getGk')
    Vm = moose.Table('/data/Vm')
    moose.connect(Vm, 'requestOut', soma, 'getVm')
    for i in range( 10 ):
        moose.setClock( i, simdt )
    moose.setClock( Gnmda.tick, plotdt )
    print spikegen.dt, Gnmda.dt
    moose.reinit()
    moose.start( simtime )
    t = pylab.linspace(0, simtime*1e3, len(Vm.vector))
    pylab.plot(t, (Vm.vector + 0.06) * 1000, label='Vm (mV)')
    pylab.plot(t, Gnmda.vector * 1e9, label='Gnmda (nS)')
    pylab.plot(t, Gnmda_noMg.vector * 1e9, label='Gnmda no Mg (nS)')
    pylab.legend()
    #data = pylab.vstack((t, Gnmda.vector, Gnmda_noMg.vector)).transpose()
    #pylab.savetxt('mgblock.dat', data)
    pylab.show()
def main():
    runtime = 1000
    displayInterval = 2
    makeModel()
    dsolve = moose.element('/model/dsolve')
    moose.reinit()
    #moose.start( runtime ) # Run the model for 10 seconds.

    a = moose.element('/model/compartment/a')
    b = moose.element('/model/compartment/b')
    s = moose.element('/model/compartment/s')
    rec = moose.element('/model/compartment/rec')
    print moose.showfields(a)

    #    img = mpimg.imread( 'turingPatternTut.png' )
    #imgplot = plt.imshow( img )
    #plt.show()

    plt.ion()
    fig = plt.figure(figsize=(12, 10))
    png = fig.add_subplot(211)
    #  imgplot = plt.imshow( img )
    ax = fig.add_subplot(212)
    ax.set_ylim(0, 2)
    plt.ylabel('Conc (mM)')
    plt.xlabel('Position along cylinder (microns)')
    pos = numpy.arange(0, a.vec.conc.size, 1)
    line1, = ax.plot(pos, a.vec.conc, label='a')
    line2, = ax.plot(pos, b.vec.conc, label='b')
    line3, = ax.plot(pos, rec.vec.conc, label='rec')
    line4, = ax.plot(pos, s.vec.conc, label='s')
    timeLabel = plt.text(60, 0.4, 'time = 0')
    plt.legend()
    fig.canvas.draw()
    distS = 10
    time = 100
    posPer = 25
    for ti in range(displayInterval, runtime, displayInterval):
        if ti > 100 and ti < 110:
            time = time + 0.5
            tempRec = computeTP(time, distS)
            rec.vec[posPer].conc = tempRec[0]
            for i in range(26, len(a.vec.conc)):
                rec.vec[i].conc = tempRec[i - 25]
                if int(posPer * 2 - i) >= 0:
                    rec.vec[25 + 25 - i].conc = tempRec[i - 25]
            rec.vec.conc = rec.vec.conc / 2
            print 'receptor sum is', sum(rec.vec.conc), max(rec.vec.conc)
            plt.figure(10)
            plt.plot(rec.vec.conc)
            moose.start(0.5)
            raw_input()
        else:
            #a.vec[80].conc = 1.2
            #b.vec[85].conc *= 1.2
            #s.vec[85].conc *= 1.2
            #a.vec[80].concInit *= 1.2
            #print 'entering the condition'
            moose.start(displayInterval)
            line1.set_ydata(a.vec.conc)
            line2.set_ydata(b.vec.conc)
            line3.set_ydata(rec.vec.conc * 10)
            line4.set_ydata(s.vec.conc)
            timeLabel.set_text("time = %d" % ti)
            fig.canvas.draw()

    print(a.vec.conc)
    file = open('c41', 'w')
    ty = 0
    for tin in a.vec.conc:
        tout = str(tin)
        ty = ty + 1
        file.write(str(ty) + ' ' + tout + '\n')

    print("Hit 'enter' to exit")
    raw_input()
Exemplo n.º 17
0
def makeModel():
    model = moose.Neutral('/model')
    # Make neuronal model. It has no channels, just for geometry
    cell = moose.loadModel('./spinyNeuron.p', '/model/cell', 'Neutral')
    # We don't want the cell to do any calculations. Disable everything.
    for i in moose.wildcardFind('/model/cell/##'):
        i.tick = -1

    # create container for model
    model = moose.element('/model')
    chem = moose.Neutral('/model/chem')
    # The naming of the compartments is dicated by the places that the
    # chem model expects to be loaded.
    compt0 = moose.NeuroMesh('/model/chem/compt0')
    compt0.separateSpines = 1
    compt0.geometryPolicy = 'cylinder'
    compt1 = moose.SpineMesh('/model/chem/compt1')
    moose.connect(compt0, 'spineListOut', compt1, 'spineList', 'OneToOne')
    compt2 = moose.PsdMesh('/model/chem/compt2')
    moose.connect(compt0, 'psdListOut', compt2, 'psdList', 'OneToOne')

    #reacSystem = moose.loadModel( 'simpleOsc.g', '/model/chem', 'ee' )
    makeChemModel(compt0, True)  # Populate all 3 compts with the chem system.
    makeChemModel(compt1, False)
    makeChemModel(compt2, True)

    compt0.diffLength = 2e-6  # This will be over 100 compartments.
    # This is the magic command that configures the diffusion compartments.
    compt0.cell = cell
    moose.showfields(compt0)

    # Build the solvers. No need for diffusion in this version.
    ksolve0 = moose.Ksolve('/model/chem/compt0/ksolve')
    if useGssa:
        ksolve1 = moose.Gsolve('/model/chem/compt1/ksolve')
        ksolve2 = moose.Gsolve('/model/chem/compt2/ksolve')
    else:
        ksolve1 = moose.Ksolve('/model/chem/compt1/ksolve')
        ksolve2 = moose.Ksolve('/model/chem/compt2/ksolve')
    dsolve0 = moose.Dsolve('/model/chem/compt0/dsolve')
    dsolve1 = moose.Dsolve('/model/chem/compt1/dsolve')
    dsolve2 = moose.Dsolve('/model/chem/compt2/dsolve')
    stoich0 = moose.Stoich('/model/chem/compt0/stoich')
    stoich1 = moose.Stoich('/model/chem/compt1/stoich')
    stoich2 = moose.Stoich('/model/chem/compt2/stoich')

    # Configure solvers
    stoich0.compartment = compt0
    stoich1.compartment = compt1
    stoich2.compartment = compt2
    stoich0.ksolve = ksolve0
    stoich1.ksolve = ksolve1
    stoich2.ksolve = ksolve2
    stoich0.dsolve = dsolve0
    stoich1.dsolve = dsolve1
    stoich2.dsolve = dsolve2
    stoich0.path = '/model/chem/compt0/#'
    stoich1.path = '/model/chem/compt1/#'
    stoich2.path = '/model/chem/compt2/#'
    assert (stoich0.numVarPools == 1)
    assert (stoich0.numProxyPools == 0)
    assert (stoich0.numRates == 1)
    assert (stoich1.numVarPools == 1)
    assert (stoich1.numProxyPools == 0)
    if useGssa:
        assert (stoich1.numRates == 2)
        assert (stoich2.numRates == 2)
    else:
        assert (stoich1.numRates == 1)
        assert (stoich2.numRates == 1)
    assert (stoich2.numVarPools == 1)
    assert (stoich2.numProxyPools == 0)
    dsolve0.buildNeuroMeshJunctions(dsolve1, dsolve2)
    stoich0.buildXreacs(stoich1)
    stoich1.buildXreacs(stoich2)
    stoich0.filterXreacs()
    stoich1.filterXreacs()
    stoich2.filterXreacs()

    Ca_input_dend = moose.vec('/model/chem/compt0/Ca_input')
    print len(Ca_input_dend)
    for i in range(60):
        Ca_input_dend[3 + i * 3].conc = 2.0

    Ca_input_PSD = moose.vec('/model/chem/compt2/Ca_input')
    print len(Ca_input_PSD)
    for i in range(5):
        Ca_input_PSD[2 + i * 2].conc = 1.0

    # Create the output tables
    num = compt0.numDiffCompts - 1
    graphs = moose.Neutral('/model/graphs')
    makeTab('Ca_soma', '/model/chem/compt0/Ca[0]')
    makeTab('Ca_d1', '/model/chem/compt0/Ca[1]')
    makeTab('Ca_d2', '/model/chem/compt0/Ca[2]')
    makeTab('Ca_d3', '/model/chem/compt0/Ca[3]')
    makeTab('Ca_s3', '/model/chem/compt1/Ca[3]')
    makeTab('Ca_s4', '/model/chem/compt1/Ca[4]')
    makeTab('Ca_s5', '/model/chem/compt1/Ca[5]')
    makeTab('Ca_p3', '/model/chem/compt2/Ca[3]')
    makeTab('Ca_p4', '/model/chem/compt2/Ca[4]')
    makeTab('Ca_p5', '/model/chem/compt2/Ca[5]')
Exemplo n.º 18
0
import moose
import rdesigneur as rd

rdes = rd.rdesigneur()
rdes.buildModel()
moose.showfields(rdes.soma)
Exemplo n.º 19
0
def test1():
    rdes = rd.rdesigneur()
    rdes.buildModel()
    moose.showfields(rdes.soma)
Exemplo n.º 20
0
def main():
    cm = ChannelML( {'temperature': 32 })
    cm.readChannelMLFromFile( 'CA1_migliore_reference/hd.xml' )
    cm.readChannelMLFromFile( 'CA1_migliore_reference/kap.xml' )
    cm.readChannelMLFromFile( 'CA1_migliore_reference/kad.xml' )
    cm.readChannelMLFromFile( 'CA1_migliore_reference/kdr.xml' )
    cm.readChannelMLFromFile( 'CA1_migliore_reference/na3.xml' )
    cm.readChannelMLFromFile( 'CA1_migliore_reference/nax.xml' )
    if ( len( sys.argv ) < 2 ):
        print("Usage: ", sys.argv[0], " filename")
        return

    # filename = "./Bhavika_swcplusnmlfiles/preliminarily corrected nmlfiles/ascoli+buzsaki/valid/" + sys.argv[1]
    filename = sys.argv[1]
    moose.Neutral( '/model' )
    # Load in the swc file.
    cell = moose.loadModel( filename, '/model/ca1' )

    for i in moose.wildcardFind( '/library/##' ):
        i.tick = -1

    chanDistrib = [ \
            "EM", "#", "-58e-3", \
            "initVm", "#", "-65e-3", \
            "RM", "#", "2.8", \
            "CM", "#", "0.01", \
            "RA", "#", "1.5", \
            "RA", "#axon#", "0.5", \

            "hd", "#dend#,#apical#", "5e-2*(1+(r*3e4))", \
            "kdr", "#", "100", \
            "na3", "#soma#,#dend#,#apical#", "250", \
            "nax", "#axon#", "1250", \
            "kap", "#axon#,#soma#", "300", \
            "kap", "#dend#,#apical#", "150*(1+sign(100-r*1e6)) * (1+(r*1e4))", \
            "kad", "#dend#,#apical#", "150*(1+sign(r*1e6-100))*(1+r*1e4)", \
            ]
    moose.showfields( cell[0] )
    cell[0].channelDistribution = chanDistrib
    cell[0].parseChanDistrib()
    for i in range( 8 ):
        moose.setClock( i, simdt )
    hsolve = moose.HSolve( '/model/ca1/hsolve' )
    hsolve.dt = simdt
    hsolve.target = '/model/ca1/soma'
    '''
    '''
    moose.reinit()
    makePlot( cell[0] )

    # Now we set up the display
    moose.le( '/model/ca1/soma' )
    soma = moose.element( '/model/ca1/soma' )
    kap = moose.element( '/model/ca1/soma/kap' )

    graphs = moose.Neutral( '/graphs' )
    vtab = moose.Table( '/graphs/vtab' )
    moose.connect( vtab, 'requestOut', soma, 'getVm' )
    kaptab = moose.Table( '/graphs/kaptab' )
    moose.connect( kaptab, 'requestOut', kap, 'getGk' )

    compts = moose.wildcardFind( "/model/ca1/#[ISA=CompartmentBase]" )
    '''
    for i in compts:
        if moose.exists( i.path + '/Na' ):
            print i.path, moose.element( i.path + '/Na' ).Gbar, \
                moose.element( i.path + '/K_DR' ).Gbar, \
                i.Rm, i.Ra, i.Cm
    '''
    '''
    Na = moose.wildcardFind( '/model/ca1/#/Na#' )
    print Na
    Na2 = []
    for i in compts:
        if ( moose.exists( i.path + '/NaF2' ) ):
            Na2.append(  moose.element( i.path + '/NaF2' ) )
        if ( moose.exists( i.path + '/NaPF_SS' ) ):
            Na2.append(  moose.element( i.path + '/NaPF_SS' ) )
    ecomptPath = map( lambda x : x.path, compts )
    print "Na placed in ", len( Na ), len( Na2 ),  " out of ", len( compts ), " compts."
    '''
    compts[0].inject = inject
    ecomptPath = [x.path for x in compts]

    # Graphics stuff here.
    app = QtGui.QApplication(sys.argv)
    morphology = moogli.read_morphology_from_moose(name = "", path = "/model/ca1")
    morphology.create_group( "group_all", ecomptPath, -0.08, 0.02, \
            [0.0, 0.0, 1.0, 1.0], [1.0, 0.0, 0.0, 0.1] ) 

    viewer = moogli.DynamicMorphologyViewerWidget(morphology)
    def callback( morphology, viewer ):
        moose.start( frameRunTime )
        Vm = [moose.element( x ).Vm for x in compts]
        morphology.set_color( "group_all", Vm )
        currTime = moose.element( '/clock' ).currentTime
        #print currTime, compts[0].Vm
        if ( currTime < runtime ):
            return True
        return False

    viewer.set_callback( callback, idletime = 0 )
    viewer.showMaximized()
    viewer.show()
    app.exec_()
    t = numpy.arange( 0, runtime, vtab.dt )
    fig = plt.figure()
    p1 = fig.add_subplot(311)
    p2 = fig.add_subplot(312)
    p2.plot( t,  vtab.vector, label = 'Vm Soma' )
    p2.legend()
    p3 = fig.add_subplot(313)
    p3.plot( t, kaptab.vector, label = 'kap Soma' )
    p3.legend()
    plt.show()
Exemplo n.º 21
0
def test_mgblock():
    model = moose.Neutral('/model')
    data = moose.Neutral('/data')
    soma = moose.Compartment('/model/soma')
    soma.Em = -60e-3
    soma.Rm = 1e7
    soma.Cm = 1e-9

    ###################################################
    # This is where we create the synapse with MgBlock
    #--------------------------------------------------
    nmda = moose.SynChan('/model/soma/nmda')
    nmda.Gbar = 1e-9
    mgblock = moose.MgBlock('/model/soma/mgblock')
    mgblock.CMg = 2.0
    mgblock.KMg_A = 1 / 0.33
    mgblock.KMg_B = 1 / 60.0

    # The synHandler manages the synapses and their learning rules if any.
    synHandler = moose.SimpleSynHandler('/model/soma/nmda/handler')
    synHandler.synapse.num = 1
    moose.connect(synHandler, 'activationOut', nmda, 'activation')

    # MgBlock sits between original channel nmda and the
    # compartment. The origChannel receives the channel message from
    # the nmda SynChan.
    moose.connect(soma, 'VmOut', nmda, 'Vm')
    moose.connect(nmda, 'channelOut', mgblock, 'origChannel')
    moose.connect(mgblock, 'channel', soma, 'channel')
    # This is for comparing with MgBlock
    nmda_noMg = moose.copy(nmda, soma, 'nmda_noMg')
    moose.connect(nmda_noMg, 'channel', soma, 'channel')
    moose.le(nmda_noMg)

    #########################################
    # The rest is for experiment setup
    spikegen = moose.SpikeGen('/model/spike')
    pulse = moose.PulseGen('/model/input')
    pulse.delay[0] = 10e-3
    pulse.level[0] = 1.0
    pulse.width[0] = 50e-3
    moose.connect(pulse, 'output', spikegen, 'Vm')
    moose.le(synHandler)
    #syn = moose.element(synHandler.path + '/synapse' )
    syn = synHandler.synapse[0]
    syn.delay = simdt * 2
    syn.weight = 10
    moose.connect(spikegen, 'spikeOut', synHandler.synapse[0], 'addSpike')
    moose.le(nmda_noMg)
    noMgSyn = moose.element(nmda_noMg.path + '/handler/synapse')
    noMgSyn.delay = 0.01
    noMgSyn.weight = 1
    moose.connect(spikegen, 'spikeOut', noMgSyn, 'addSpike')
    moose.showfields(syn)
    moose.showfields(noMgSyn)
    Gnmda = moose.Table('/data/Gnmda')
    moose.connect(Gnmda, 'requestOut', mgblock, 'getGk')
    Gnmda_noMg = moose.Table('/data/Gnmda_noMg')
    moose.connect(Gnmda_noMg, 'requestOut', nmda_noMg, 'getGk')
    Vm = moose.Table('/data/Vm')
    moose.connect(Vm, 'requestOut', soma, 'getVm')
    for i in range(10):
        moose.setClock(i, simdt)
    moose.setClock(Gnmda.tick, plotdt)
    print((spikegen.dt, Gnmda.dt))
    moose.reinit()
    moose.start(simtime)
    t = pylab.linspace(0, simtime * 1e3, len(Vm.vector))
    pylab.plot(t, (Vm.vector + 0.06) * 1000, label='Vm (mV)')
    pylab.plot(t, Gnmda.vector * 1e9, label='Gnmda (nS)')
    pylab.plot(t, Gnmda_noMg.vector * 1e9, label='Gnmda no Mg (nS)')
    pylab.legend()
    #data = pylab.vstack((t, Gnmda.vector, Gnmda_noMg.vector)).transpose()
    #pylab.savetxt('mgblock.dat', data)
    pylab.show()