def create_population(container, size): """Create a population of `size` single compartmental neurons with Na+ and K+ channels. Also create SpikeGen objects and SynChan objects connected to these which can act as plug points for setting up synapses later. This uses ..ref::`ionchannel.create_1comp_neuron`. """ path = container.path print((path, size, type(path))) comps = create_1comp_neuron('{}/neuron'.format(path), number=size) synpath = path+'/synchan' print((synpath, size, type(size))) synchan = moose.vec(synpath, n=size, dtype='SynChan') synchan.Gbar = 1e-8 synchan.tau1 = 2e-3 synchan.tau2 = 2e-3 m = moose.connect(comps, 'channel', synchan, 'channel', 'OneToOne') synhandler = moose.vec('{}/synhandler'.format(path), n=size, dtype='SimpleSynHandler') moose.connect(synhandler, 'activationOut', synchan, 'activation', 'OneToOne') spikegen = moose.vec('{}/spikegen'.format(path), n=size, dtype='SpikeGen') spikegen.threshold = 0.0 m = moose.connect(comps, 'VmOut', spikegen, 'Vm', 'OneToOne') return {'compartment': comps, 'spikegen': spikegen, 'synchan': synchan, 'synhandler': synhandler}
def create_population(container, size): """Create a population of `size` single compartmental neurons with Na+ and K+ channels. Also create SpikeGen objects and SynChan objects connected to these which can act as plug points for setting up synapses later. This uses ..ref::`ionchannel.create_1comp_neuron`. """ path = container.path print path, size, type(path) comps = create_1comp_neuron("{}/neuron".format(path), number=size) synpath = path + "/synchan" print synpath, size, type(size) synchan = moose.vec(synpath, n=size, dtype="SynChan") synchan.Gbar = 1e-8 synchan.tau1 = 2e-3 synchan.tau2 = 2e-3 m = moose.connect(comps, "channel", synchan, "channel", "OneToOne") synhandler = moose.vec("{}/synhandler".format(path), n=size, dtype="SimpleSynHandler") moose.connect(synhandler, "activationOut", synchan, "activation", "OneToOne") spikegen = moose.vec("{}/spikegen".format(path), n=size, dtype="SpikeGen") spikegen.threshold = 0.0 m = moose.connect(comps, "VmOut", spikegen, "Vm", "OneToOne") return {"compartment": comps, "spikegen": spikegen, "synchan": synchan, "synhandler": synhandler}
def find_max_voxel(): #added by Chaitanya spineCa = len(moose.vec( '/model/chem/spine/Ca' )) dendCa = len(moose.vec( '/model/chem/dend/DEND/Ca' )) Ca = len([ x.Ca * 0.0001 for x in moose.wildcardFind( '/model/elec/##[ISA=CaConcBase]') ]) spineCaM = len(moose.vec( '/model/chem/spine/Ca_CaM' )) psdCaM = len(moose.vec( '/model/chem/psd/Ca_CaM' )) return max(spineCa, dendCa, Ca, spineCaM, psdCaM)
def showVisualization(): makeModel() elec = moose.element( '/model/elec' ) elec.setSpineAndPsdMesh( moose.element('/model/chem/spine'), moose.element('/model/chem/psd') ) eHead = moose.wildcardFind( '/model/elec/#head#' ) oldDia = [ i.diameter for i in eHead ] graphs = moose.Neutral( '/graphs' ) #makePlot( 'psd_x', moose.vec( '/model/chem/psd/x' ), 'getN' ) #makePlot( 'head_x', moose.vec( '/model/chem/spine/x' ), 'getN' ) makePlot( 'dend_x', moose.vec( '/model/chem/dend/x' ), 'getN' ) dendZ = makePlot( 'dend_z', moose.vec( '/model/chem/dend/z' ), 'getN' ) makePlot( 'head_z', moose.vec( '/model/chem/spine/z' ), 'getN' ) psdZ = makePlot( 'psd_z', moose.vec( '/model/chem/psd/z' ), 'getN' ) diaTab = makePlot( 'headDia', eHead, 'getDiameter' ) # print diaTab[0].vector[-1] # return dendrite = moose.element("/model/elec/dend") dendrites = [dendrite.path + "/" + str(i) for i in range(len(dendZ))] # print dendrites moose.reinit() spineHeads = moose.wildcardFind( '/model/elec/#head#') # print moose.wildcardFind( '/model/elec/##') # print "dendZ", readValues(dendZ) # print dendrite app = QtGui.QApplication(sys.argv) viewer = create_viewer("/model/elec", dendrite, dendZ, diaTab, psdZ) viewer.showMaximized() viewer.start() return app.exec_()
def saveNeuronPlots( fig, rdes ): #fig = plt.figure( figsize=(12, 10), facecolor='white' ) #fig.subplots_adjust( left = 0.18 ) plt.figure(1) ax = plt.subplot(222) cleanAx( ax, 'C' ) plt.ylabel( 'Vm (mV)', fontsize = 16 ) vtab = moose.element( '/graphs/vtab' ) t = np.arange( 0, len( vtab.vector ), 1 ) * vtab.dt plt.plot( t, vtab.vector * 1000, label="Vm" ) #plt.legend() ax = plt.subplot(223) cleanAx( ax, 'D', showXlabel = True ) pcatab = list( moose.vec( '/graphs/pcatab' ) )[0::50] t = np.arange( 0, len( pcatab[0].vector ), 1 ) * pcatab[0].dt for i in pcatab: plt.plot( t, i.vector * 1000 ) plt.ylabel( '[Ca] (uM)', fontsize = 16 ) plt.xlabel( 'Time (s)', fontsize = 16 ) ax = plt.subplot(224) cleanAx( ax, 'E', showXlabel = True ) rtab = list( moose.vec( '/graphs/rtab' ) )[0::50] t = np.arange( 0, len( rtab[0].vector ), 1 ) * rtab[0].dt for i in rtab: plt.plot( t, i.vector ) plt.ylabel( '# of inserted GluRs', fontsize = 16 ) plt.xlabel( 'Time (s)', fontsize = 16 ) '''
def runTrial( diffusionLength, v, dist, blanks, preStim, postStim ): settleTime = params['settleTime'] vel = moose.vec( '/model/chem/dend/vel' ) vel.nInit = v * diffusionLength #B = moose.vec( '/model/chem/dend/B' ) #B.nInit = 0.004 #print 'runTrial(', v, dist, blanks, ')' runtime = preStim + postStim + (dist+ blanks*2)/float(v) moose.reinit() if not displayMoogli: moose.start( runtime ) tabs = moose.vec( '/model/graphs/plot0' ) #print len(tabs), len( tabs[0].vector ) stride = int(dist) / numSpine #print 'tab number = ', blanks, blanks + dist/2, blanks + dist - 1 ret = [] ps = preStim - 4 * params[ 'stimWidth' ] for i in range( numSpine ): data = tabs[(blanks + i*stride)].vector ret.extend( extractParms( data, ps, runtime + settleTime - postStim, tabs[0].dt ) ) #print ret aoc = 0.0 peak = 0.0 spatialSum = np.array( [0.0, 0.0] ) # aoc, peak settleTime = params['settleTime'] for i in tabs: data = i.vector spatialSum += np.array( extractParms( data, ps, runtime + settleTime - postStim, tabs[0].dt ) ) ret.extend( [spatialSum[0], spatialSum[1] ] ) return ret
def scanDistDtGrid(): seqList, seqScore = makeSequence( numSpine ) #moose.setClock(18, 0.02 ) #print "DT = ", moose.element( '/model/graphs/plot0').dt seqDtRange = ( 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0 ) # Interval between stimuli, in sec drange = ( 5, 10, 15, 20, 25, 30 ) # Distance covered, in diffLen. if displayMoogli: seqDtRange = ( moogliDt, ) drange = ( moogliDistance, ) # seqDtRange = ( 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0 ) # Interval between stimuli, in sec # drange = ( 5, 10, 15, 20, 25, 30 ) allSimOutput = [] ampl = moose.vec( '/model/chem/dend/ampl' ) print("ampl: ", len(ampl)) ampl.nInit = params['stimAmplitude'] blanks = params['blankVoxelsAtEnd'] preStim = params['preStimTime'] postStim = params['postStimTime'] diffusionLength = params['diffusionLength'] for seqDt in seqDtRange: temp2 = [] temp3 = [] for d in drange: # compt = moose.Compartment( '/model/chem/soma') # compt.diameter = params['dendDiameter']/8 dend = moose.element( '/model/chem/dend') # print("dend diameter: ", dend.diameter) moose.le( '/model/chem/dend' ) phase = moose.vec( '/model/chem/dend/phase' ) ampl = moose.vec( '/model/chem/dend/ampl' ) # Old version. Assumes we activate density * d compartments. #ampl.nInit = float(v)/float(d) ampl.nInit = params['stimAmplitude'] Z = moose.vec( '/model/chem/dend/Z' ) stride = int(d) / numSpine Z.nInit = 0 phase.nInit = 10000.0 temp = [] slopes = [] for seq in seqList: print '.', sys.stdout.flush() for j in range( numSpine ): k = (blanks + j * stride) Z[ k ].nInit = 1 phase[ k ].nInit = preStim + seq[j] * seqDt temp.append( runTrial( diffusionLength, seqDt, d, blanks, preStim, postStim )) #print temp simOut = np.array( temp ) temp3.append( simOut ) print seqDt, d #temp[-1], temp[-2], allSimOutput.append( temp3 ) return allSimOutput, seqDtRange, drange
def makeGraphics( cPlotDt, ePlotDt ): plt.ion() fig = plt.figure( figsize=(10,16) ) chem = fig.add_subplot( 411 ) chem.set_ylim( 0, 0.006 ) plt.ylabel( 'Conc (mM)' ) plt.xlabel( 'time (seconds)' ) for x in moose.wildcardFind( '/graphs/chem/#[ISA=Table]' ): pos = numpy.arange( 0, x.vector.size, 1 ) * cPlotDt line1, = chem.plot( pos, x.vector, label=x.name ) plt.legend() elec = fig.add_subplot( 412 ) plt.ylabel( 'Vm (V)' ) plt.xlabel( 'time (seconds)' ) for x in moose.wildcardFind( '/graphs/elec/#[ISA=Table]' ): pos = numpy.arange( 0, x.vector.size, 1 ) * ePlotDt line1, = elec.plot( pos, x.vector, label=x.name ) plt.legend() ca = fig.add_subplot( 413 ) plt.ylabel( '[Ca] (mM)' ) plt.xlabel( 'time (seconds)' ) for x in moose.wildcardFind( '/graphs/ca/#[ISA=Table]' ): pos = numpy.arange( 0, x.vector.size, 1 ) * ePlotDt line1, = ca.plot( pos, x.vector, label=x.name ) plt.legend() lenplot = fig.add_subplot( 414 ) plt.ylabel( 'Ca (mM )' ) plt.xlabel( 'Voxel#)' ) spineCa = moose.vec( '/model/chem/spine/Ca' ) dendCa = moose.vec( '/model/chem/dend/DEND/Ca' ) line1, = lenplot.plot( range( len( spineCa ) ), spineCa.conc, label='spine' ) line2, = lenplot.plot( range( len( dendCa ) ), dendCa.conc, label='dend' ) ca = [ x.Ca * 0.0001 for x in moose.wildcardFind( '/model/elec/##[ISA=CaConcBase]') ] line3, = lenplot.plot( range( len( ca ) ), ca, label='elec' ) spineCaM = moose.vec( '/model/chem/spine/CaM_dash_Ca4' ) line4, = lenplot.plot( range( len( spineCaM ) ), spineCaM.conc, label='spineCaM' ) psdCaM = moose.vec( '/model/chem/psd/CaM_dash_Ca4' ) line5, = lenplot.plot( range( len( psdCaM ) ), psdCaM.conc, label='psdCaM' ) plt.legend() fig.canvas.draw() raw_input() ''' for x in moose.wildcardFind( '/graphs/##[ISA=Table]' ): t = numpy.arange( 0, x.vector.size, 1 ) pylab.plot( t, x.vector, label=x.name ) pylab.legend() pylab.show() ''' print 'All done'
def main(): """ transportBranchingNeuron: This example illustrates bidirectional transport embedded in the branching pseudo 1-dimensional geometry of a neuron. This means that diffusion and transport only happen along the axis of dendritic segments, not radially from inside to outside a dendrite, nor tangentially around the dendrite circumference. In this model there is a molecule **a** starting at the soma, which is transported out to the dendrites. There is another molecule, **b**, which is initially present at the dendrite tips, and is transported toward the soma. This example uses an external model file to specify a binary branching neuron. This model does not have any spines. The electrical model is used here purely for the geometry and is not part of the computations. In this example we build trival chemical model just having molecules **a** and **b** throughout the neuronal geometry, using the makeChemModel function. The model is set up to run using the Ksolve for integration and the Dsolve for handling diffusion. The display has three parts: a. Animated pseudo-3D plot of neuronal geometry, where each point represents a diffusive voxel and moves in the y-axis to show changes in concentration of molecule a. b. Similar animated pseudo-3D plot for molecule b. c. Time-series plot that appears after the simulation has ended. The plots are for the first and last diffusive voxel, that is, the soma and the tip of one of the apical dendrites. """ chemdt = 0.1 # Tested various dts, this is reasonable. diffdt = 0.01 plotdt = 1 animationdt = 5 runtime = 600 makeModel() plotlist = makeDisplay() # Schedule the whole lot for i in range( 11, 17 ): moose.setClock( i, chemdt ) # for the chem objects moose.setClock( 10, diffdt ) # for the diffusion moose.setClock( 18, plotdt ) # for the output tables. moose.reinit() a = moose.vec( '/model/chem/compt0/a' ) b = moose.vec( '/model/chem/compt0/b' ) a0 = sum( a.n ) b0 = sum( b.n ) for i in range( 0, runtime, animationdt ): moose.start( animationdt ) plotlist[4].set_text( "time = %d" % i ) updateDisplay( plotlist ) print 'mass consv a = ', a0, sum( a.n ), ', b = ', b0, sum( b.n ) finalizeDisplay( plotlist, plotdt )
def testRename(self): """Rename an element in a Id and check if that was effective. This tests for setting values also.""" id1 = moose.vec(path='/alpha', n=1, dtype='Neutral') id2 = moose.vec('alpha') id1[0].name = 'bravo' self.assertEqual(id1.path, '/bravo') self.assertEqual(id2.path, '/bravo')
def main(): numpy.random.seed( 1234 ) rdes = buildRdesigneur() rdes.buildModel( '/model' ) assert( moose.exists( '/model' ) ) moose.element( '/model/elec/hsolve' ).tick = -1 for i in range( 0, 10 ): moose.setClock( i, 100 ) for i in range( 10, 18 ): moose.setClock( i, dt ) moose.setClock( 18, plotdt ) moose.reinit() buildPlots() # Run for baseline, tetanus, and post-tetanic settling time print 'starting...' t1 = time.time() moose.start( baselineTime ) caPsd = moose.vec( '/model/chem/psd/Ca_input' ) caDend = moose.vec( '/model/chem/dend/DEND/Ca_input' ) castim = (numpy.random.rand( len( caPsd.concInit ) ) * 0.8 + 0.2) * psdTetCa caPsd.concInit = castim caDend.concInit = numpy.random.rand( len( caDend.concInit ) ) * dendTetCa moose.start( tetTime ) caPsd.concInit = basalCa caDend.concInit = basalCa moose.start( interTetTime ) caPsd.concInit = castim caDend.concInit = numpy.random.rand( len( caDend.concInit ) ) * dendTetCa moose.start( tetTime ) caPsd.concInit = basalCa caDend.concInit = basalCa moose.start( postTetTime ) caPsd.concInit = ltdCa caDend.concInit = ltdCa moose.start( ltdTime ) caPsd.concInit = basalCa caDend.concInit = basalCa moose.start( postLtdTime ) print 'real time = ', time.time() - t1 if do3D: app = QtGui.QApplication(sys.argv) compts = moose.wildcardFind( "/model/elec/#[ISA=compartmentBase]" ) ecomptPath = map( lambda x : x.path, compts ) morphology = moogli.read_morphology_from_moose(name = "", path = "/model/elec") morphology.create_group( "group_all", ecomptPath, -0.08, 0.02, \ [0.0, 0.5, 1.0, 1.0], [1.0, 0.0, 0.0, 0.9] ) viewer = moogli.DynamicMorphologyViewerWidget(morphology) def callback( morphology, viewer ): moose.start( 0.1 ) return True viewer.set_callback( callback, idletime = 0 ) viewer.showMaximized() viewer.show() app.exec_() displayPlots()
def testCompareId(self): """Test the rich comparison between ids""" id1 = moose.vec('A', n=2, dtype='Neutral') id2 = moose.vec('B', n=4, dtype='Neutral') id3 = moose.vec('A') self.assertTrue(id1 < id2) self.assertEqual(id1, id3) self.assertTrue(id2 > id1) self.assertTrue(id2 >= id1) self.assertTrue(id1 <= id2)
def updatePlots( plotlist, time ): a = moose.vec( '/model/compartment/a' ) b = moose.vec( '/model/compartment/b' ) c = moose.vec( '/model/compartment/c' ) d = moose.vec( '/model/compartment/d' ) plotlist[2].set_text( "time = %g" % time ) plotlist[3].set_ydata( a.conc ) plotlist[4].set_ydata( b.conc ) plotlist[5].set_ydata( c.conc ) plotlist[6].set_ydata( d.conc )
def updateGraphics( plotlist ): spineCa = moose.vec( '/model/chem/spine/Ca' ) dendCa = moose.vec( '/model/chem/dend/DEND/Ca' ) plotlist[5].set_ydata( spineCa.conc ) plotlist[6].set_ydata( dendCa.conc ) ca = [ x.Ca * 0.0001 for x in moose.wildcardFind( '/model/elec/##[ISA=CaConcBase]') ] plotlist[7].set_ydata( ca ) spineCaM = moose.vec( '/model/chem/spine/Ca_CaM' ) plotlist[8].set_ydata( spineCaM.conc ) psdCaM = moose.vec( '/model/chem/psd/Ca_CaM' ) plotlist[9].set_ydata( psdCaM.conc ) plotlist[4].canvas.draw()
def updateDisplay( plotlist ): Ca = moose.vec( '/model/chem/compt0/Ca' ) Ca_input = moose.vec( '/model/chem/compt0/Ca_input' ) plotlist[5].set_ydata( Ca.conc ) plotlist[6].set_ydata( Ca_input.conc ) Ca = moose.vec( '/model/chem/compt1/Ca' ) plotlist[7].set_ydata( Ca.conc ) Ca = moose.vec( '/model/chem/compt2/Ca' ) Ca_input = moose.vec( '/model/chem/compt2/Ca_input' ) plotlist[8].set_ydata( Ca.conc ) plotlist[9].set_ydata( Ca_input.conc ) plotlist[4].canvas.draw()
def loadChem( neuroCompt, spineCompt, psdCompt ): # We need the compartments to come in with a volume of 1 to match the # original CubeMesh. assert( neuroCompt.volume == 1.0 ) assert( spineCompt.volume == 1.0 ) assert( psdCompt.volume == 1.0 ) assert( neuroCompt.mesh.num == 1 ) print 'volume = ', neuroCompt.mesh[0].volume #assert( neuroCompt.mesh[0].volume == 1.0 ) #an unfortunate mismatch # So we'll have to resize the volumes of the current compartments to the # new ones. modelId = moose.loadModel( 'diffonly.g', '/model', 'ee' ) #moose.le( '/model/model' ) #moose.le( '/model/model/kinetics' ) #moose.le( '/model/model/kinetics/PSD' ) #moose.le( '/model/model/kinetics/SPINE' ) moose.delete( moose.vec( '/model/model/kinetics/PSD/kreac' ) ) moose.delete( moose.vec( '/model/model/kinetics/SPINE/kreac' ) ) #moose.le( '/model/model/kinetics/PSD' ) #moose.le( '/model/model/kinetics/SPINE' ) pCaCaM = moose.element( '/model/model/kinetics/PSD/Ca_CaM' ) pCaCaM.concInit = 0.001 dCaCaM = moose.element( '/model/model/kinetics/PSD/Ca_CaM' ) sCaCaM = moose.element( '/model/model/kinetics/SPINE/Ca_CaM' ) print "CaCaM.concInit[p,s,d] = ", pCaCaM.concInit, sCaCaM.concInit, dCaCaM.concInit #moose.delete( moose.vec( '/model/model/kinetics/SPINE/Ca_CaM' ) ) #CaCaM2 = moose.element( '/model/model/kinetics/SPINE/Ca_CaM' ) #CaCaM2.concInit = 0.001 chem = moose.element( '/model/model' ) chem.name = 'chem' oldS = moose.element( '/model/chem/compartment_1' ) oldP = moose.element( '/model/chem/compartment_2' ) oldN = moose.element( '/model/chem/kinetics' ) print 'oldvols[p,s,d] = ', oldP.volume, oldS.volume, oldN.volume print 'newvols[p,s,d] = ', psdCompt.mesh[0].volume, spineCompt.mesh[0].volume, neuroCompt.mesh[0].volume oldN.volume = neuroCompt.mesh[0].volume oldS.volume = spineCompt.mesh[0].volume oldP.volume = psdCompt.mesh[0].volume print 'after redoing vols' print "CaCaM.concInit[p,s,d] = ", pCaCaM.concInit, sCaCaM.concInit, dCaCaM.concInit moveCompt( '/model/chem/kinetics/SPINE', oldS, spineCompt ) moveCompt( '/model/chem/kinetics/PSD', oldP, psdCompt ) # Need to do the DEND last because the oldN is /kinetics, # and it will be deleted. moveCompt( '/model/chem/kinetics/DEND', oldN, neuroCompt ) print 'after moving to new compts' print "CaCaM.concInit[p,s,d] = ", pCaCaM.concInit, sCaCaM.concInit, dCaCaM.concInit
def loadtree(hdfnode, moosenode): """Load the element tree saved under the group `hdfnode` into `moosenode`""" pathclass = {} basepath = hdfnode.attr['path'] if basepath != '/': basepath = basepath + '/' emdata = hdfnode['vec'][:] sorted_paths = sorted(emdata['path'], key=lambda x: x.count('/')) dims = dict(emdata['path', 'dims']) classes = dict(emdata['path', 'class']) current = moose.getCwe() moose.setCwe(moosenode) # First create all the ematrices for path in sorted_paths: rpath = path[len(basepath):] classname = classes[path] shape = dims[path] em = moose.vec(rpath, shape, classname) wfields = {} for cinfo in moose.element('/classes').children: cname = cinfo[0].name wfields[cname] = [f[len('set_'):] for f in moose.getFieldNames(cname, 'destFinfo') if f.startswith('set_') and f not in ['set_this', 'set_name', 'set_lastDimension', 'set_runTime'] and not f.startswith('set_num_')] for key in hdfnode['/elements']: dset = hdfnode['/elements/'][key][:] fieldnames = dset.dtype.names for ii in range(len(dset)): obj = moose.element(dset['path'][ii][len(basepath):]) for f in wfields[obj.className]: obj.setField(f, dset[f][ii])
def makeModel(): moose.Neutral( '/library' ) makeCellProto( 'cellProto' ) makeChemProto( 'cProto' ) makeSpineProto2( 'spine' ) rdes = rd.rdesigneur( useGssa = False, \ combineSegments = False, \ stealCellFromLibrary = True, \ diffusionLength = 1e-6, \ cellProto = [['cellProto', 'elec' ]] ,\ spineProto = [['spineProto', 'spine' ]] ,\ chemProto = [['cProto', 'chem' ]] ,\ spineDistrib = [ \ ['spine', '#', \ 'spacing', str( spineSpacing ), \ 'spacingDistrib', str( spineSpacingDistrib ), \ 'angle', str( spineAngle ), \ 'angleDistrib', str( spineAngleDistrib ), \ 'size', str( spineSize ), \ 'sizeDistrib', str( spineSizeDistrib ) ] \ ], \ chemDistrib = [ \ [ "chem", "dend", "install", "1" ] \ ], adaptorList = [ \ [ 'psd/z', 'n', 'spine', 'psdArea', 10.0e-15, 300e-15 ], \ ] \ ) rdes.buildModel( '/model' ) x = moose.vec( '/model/chem/dend/x' ) x.concInit = 0.0 for i in range( 0,20 ): x[i].concInit = concInit
def _parseComptField( self, comptList, plotSpec, knownFields ): # Put in stuff to go through fields if the target is a chem object field = plotSpec[3] if not field in knownFields: print "Warning: Rdesigneur::_parseComptField: Unknown field '", field, "'" return (), "" kf = knownFields[field] # Find the field to decide type. if ( kf[0] == 'CaConcBase' or kf[0] == 'ChanBase' ): objList = self._collapseElistToPathAndClass( comptList, plotSpec[2], kf[0] ) return objList, kf[1] elif (field == 'n' or field == 'conc' ): path = plotSpec[2] pos = path.find( '/' ) if pos == -1: # Assume it is in the dend compartment. path = 'dend/' + path pos = path.find( '/' ) chemCompt = path[:pos] cc = moose.element( self.modelPath + '/chem/' + chemCompt) voxelVec = [] if ( chemCompt == 'dend' ): for i in comptList: voxelVec.extend( cc.dendVoxelsOnCompartment[i] ) else: for i in comptList: voxelVec.extend( cc.spineVoxelsOnCompartment[i] ) # Here we collapse the voxelVec into objects to plot. allObj = moose.vec( self.modelPath + '/chem/' + plotSpec[2] ) objList = [ allObj[int(j)] for j in voxelVec] return objList, kf[1] else: return comptList, kf[1]
def displayPlots(): for x in moose.wildcardFind( '/graphs/#[0]' ): tab = moose.vec( x ) for i in range( len( tab ) ): pylab.plot( tab[i].vector, label=x.name[:-3] + " " + str( i ) ) pylab.legend() pylab.figure()
def printPsd( name ): # Print the vol, the path dist from soma, the electrotonic dist, and N psdR = moose.vec( '/model/chem/psd/tot_PSD_R' ) neuronVoxel = moose.element( '/model/chem/spine' ).neuronVoxel elecComptMap = moose.element( '/model/chem/dend' ).elecComptMap print(("len( neuronVoxel = ", len( neuronVoxel), min( neuronVoxel), max( neuronVoxel))) print((len( elecComptMap), elecComptMap[0], elecComptMap[12])) neuron = moose.element( '/model/elec' ) ncompts = neuron.compartments d = {} j = 0 for i in ncompts: #print i d[i] = j j += 1 f = open( name + ".txt", 'w' ) for i in range( len( psdR ) ): n = psdR[i].n conc = psdR[i].conc vol = psdR[i].volume compt = elecComptMap[ neuronVoxel[i] ] #print compt segIndex = d[compt[0]] p = neuron.geometricalDistanceFromSoma[ segIndex ] L = neuron.electrotonicDistanceFromSoma[ segIndex ] s = str( i ) + " " + str(n) + " " + str( conc ) + " " + str(p) + " " + str(L) + "\n" f.write( s ) f.close()
def main(): """ This illustrates the use of rdesigneur to build a simple dendrite with spines, and then to resize them using spine fields. These are the fields that would be changed dynamically in a simulation with reactions that affect spine geometry. In this simulation there is a propagating reaction wave using a highly abstracted equation, whose product diffuses into the spines and makes them bigger. """ makeModel() elec = moose.element( '/model/elec' ) elec.setSpineAndPsdMesh( moose.element('/model/chem/spine'), moose.element('/model/chem/psd') ) eHead = moose.wildcardFind( '/model/elec/#head#' ) oldDia = [ i.diameter for i in eHead ] graphs = moose.Neutral( '/graphs' ) #makePlot( 'psd_x', moose.vec( '/model/chem/psd/x' ), 'getN' ) #makePlot( 'head_x', moose.vec( '/model/chem/spine/x' ), 'getN' ) makePlot( 'dend_x', moose.vec( '/model/chem/dend/x' ), 'getN' ) makePlot( 'dend_z', moose.vec( '/model/chem/dend/z' ), 'getN' ) makePlot( 'head_z', moose.vec( '/model/chem/spine/z' ), 'getN' ) makePlot( 'psd_z', moose.vec( '/model/chem/psd/z' ), 'getN' ) makePlot( 'headDia', eHead, 'getDiameter' ) ''' debug = moose.PyRun( '/pyrun' ) debug.tick = 10 debug.runString = """print "RUNNING: ", moose.element( '/model/chem/psd/z' ).n, moose.element( '/model/elec/head0' ).diameter""" ''' moose.reinit() moose.start( runtime ) displayPlots() pylab.plot( oldDia, label = 'old Diameter' ) pylab.plot( [ i.diameter for i in eHead ], label = 'new Diameter' ) pylab.legend() pylab.show() app = QtGui.QApplication(sys.argv) #widget = mv.MoogliViewer( '/model' ) morphology = moogli.read_morphology_from_moose( name="", path = '/model/elec' ) widget = moogli.MorphologyViewerWidget( morphology ) widget.show() return app.exec_() quit()
def testPath(self): # Unfortunately the indexing in path seems unstable - in # async13 it is switched to have [0] for the first element, # breaking old code which was supposed to skip the [0] and # include the index only for second entry onwards. self.assertEqual(self.b.path, '/%s[0]/%s[0]' % (self.a_path, 'b')) em = moose.vec(self.c) self.assertEqual(em[1].path, self.c_path + '[1]')
def main(): """ This illustrates the use of rdesigneur to build a simple dendrite with spines, and then to resize them using spine fields. These are the fields that would be changed dynamically in a simulation with reactions that affect spine geometry. In this simulation there is a propagating reaction wave using a highly abstracted equation, whose product diffuses into the spines and makes them bigger. """ makeModel() elec = moose.element( '/model/elec' ) elec.setSpineAndPsdMesh( moose.element('/model/chem/spine'), moose.element('/model/chem/psd') ) eHead = moose.wildcardFind( '/model/elec/#head#' ) oldDia = [ i.diameter for i in eHead ] graphs = moose.Neutral( '/graphs' ) #makePlot( 'psd_x', moose.vec( '/model/chem/psd/x' ), 'getN' ) #makePlot( 'head_x', moose.vec( '/model/chem/spine/x' ), 'getN' ) makePlot( 'dend_x', moose.vec( '/model/chem/dend/x' ), 'getN' ) dendZ = makePlot( 'dend_z', moose.vec( '/model/chem/dend/z' ), 'getN' ) makePlot( 'head_z', moose.vec( '/model/chem/spine/z' ), 'getN' ) psdZ = makePlot( 'psd_z', moose.vec( '/model/chem/psd/z' ), 'getN' ) diaTab = makePlot( 'headDia', eHead, 'getDiameter' ) # print diaTab[0].vector[-1] # return dendrite = moose.element("/model/elec/dend") dendrites = [dendrite.path + "/" + str(i) for i in range(len(dendZ))] # print dendrites moose.reinit() spineHeads = moose.wildcardFind( '/model/elec/#head#') # print moose.wildcardFind( '/model/elec/##') # print "dendZ", readValues(dendZ) # print dendrite app = QtGui.QApplication(sys.argv) viewer = create_viewer("/model/elec", dendrite, dendZ, diaTab, psdZ) viewer.showMaximized() viewer.start() return app.exec_()
def makeDisplay(): plt.ion() fig = plt.figure( figsize=(10,12) ) dend = fig.add_subplot( 411 ) plt.ylabel( 'Conc (mM)' ) plt.xlabel( 'Dend voxel #' ) plt.legend() timeLabel = plt.text(200, 0.5, 'time = 0') spine = fig.add_subplot( 412 ) plt.ylabel( 'Conc (mM)' ) plt.xlabel( 'Spine voxel #' ) plt.legend() psd = fig.add_subplot( 413 ) plt.ylabel( 'Conc (mM)' ) plt.xlabel( 'PSD voxel #' ) plt.legend() timeSeries = fig.add_subplot( 414 ) timeSeries.set_ylim( 0, 2 ) plt.ylabel( 'Conc (mM)' ) plt.xlabel( 'time (seconds)' ) plt.legend() Ca = moose.vec( '/model/chem/compt0/Ca' ) Ca_input = moose.vec( '/model/chem/compt0/Ca_input' ) line1, = dend.plot( list(range( len( Ca ))), Ca.conc, label='Ca' ) line2, = dend.plot( list(range( len( Ca_input ))), Ca_input.conc, label='Ca_input' ) dend.set_ylim( 0, 2 ) Ca = moose.vec( '/model/chem/compt1/Ca' ) line3, = spine.plot( list(range( len( Ca ))), Ca.conc, label='Ca' ) spine.set_ylim( 0, 1 ) Ca = moose.vec( '/model/chem/compt2/Ca' ) Ca_input = moose.vec( '/model/chem/compt2/Ca_input' ) line4, = psd.plot( list(range( len( Ca ))), Ca.conc, label='Ca' ) line5, = psd.plot( list(range( len( Ca_input ))), Ca_input.conc, label='Ca_input' ) psd.set_ylim( 0, 1 ) fig.canvas.draw() return ( timeSeries, dend, spine, psd, fig, line1, line2, line3, line4, line5, timeLabel )
def moveCompt( path, oldParent, newParent ): meshEntries = moose.element( newParent.path + '/mesh' ) # Set up vol messaging from new compts to all their child objects. for x in moose.wildcardFind( path + '/##[ISA=PoolBase]' ): moose.connect( meshEntries, 'mesh', x, 'mesh', 'OneToOne' ) orig = moose.element( path ) moose.move( orig, newParent ) moose.delete( moose.vec( oldParent.path ) ) chem = moose.element( '/model/chem' ) moose.move( newParent, chem )
def updateGraphics( plotlist, voxel_val_dict, idx ): #Edited by Chaitanya spineCa = moose.vec( '/model/chem/spine/Ca' ) dendCa = moose.vec( '/model/chem/dend/DEND/Ca' ) plotlist[5].set_ydata( spineCa.conc ) plotlist[6].set_ydata( dendCa.conc ) ca = [ x.Ca * 0.0001 for x in moose.wildcardFind( '/model/elec/##[ISA=CaConcBase]') ] plotlist[7].set_ydata( ca ) spineCaM = moose.vec( '/model/chem/spine/Ca_CaM' ) plotlist[8].set_ydata( spineCaM.conc ) psdCaM = moose.vec( '/model/chem/psd/Ca_CaM' ) plotlist[9].set_ydata( psdCaM.conc ) plotlist[4].canvas.draw() voxel_val_dict['spine'][:len(spineCa.conc), idx] = spineCa.conc # voxel_val_dict['dend'][:len(dendCa.conc), idx] = dendCa.conc # voxel_val_dict['elec'][:len(ca), idx] = ca # voxel_val_dict['spineCaM'][:len(spineCaM.conc), idx] = spineCaM.conc # voxel_val_dict['psdCaM'][:len(psdCaM.conc), idx] = psdCaM.conc # return voxel_val_dict #
def buildPlots( rdes ): if not moose.exists( '/graphs' ): moose.Neutral( '/graphs' ) numPlots = 10 caPsd = moose.vec( '/model/chem/psd/Ca' ) caHead = moose.vec( '/model/chem/spine/Ca' ) caDend = moose.vec( '/model/chem/dend/Ca_dend_input' ) psdR = moose.vec( '/model/chem/psd/tot_PSD_R' ) numSpines = rdes.spineCompt.mesh.num assert( 2 * numSpines == len( rdes.spineComptElist ) ) assert( len( caPsd ) == numSpines ) assert( len( caHead ) == numSpines ) if numSpines < numPlots: caPsdTab = moose.Table2( '/graphs/caPsdTab', numSpines ).vec caHeadTab = moose.Table2( '/graphs/caHeadTab', numSpines ).vec psdRtab = moose.Table2( '/graphs/psdRtab', numSpines ).vec for i in range( numSpines ): moose.connect( caPsdTab[i], 'requestOut', caPsd[i], 'getConc' ) moose.connect( caHeadTab[i], 'requestOut', caHead[i], 'getConc') moose.connect( psdRtab[i], 'requestOut', psdR[i], 'getN' ) else: caPsdTab = moose.Table2( '/graphs/caPsdTab', numPlots ).vec caHeadTab = moose.Table2( '/graphs/caHeadTab', numPlots ).vec psdRtab = moose.Table2( '/graphs/psdRtab', numPlots ).vec dx = numSpines / numPlots for i in range( numPlots ): moose.connect( caPsdTab[i], 'requestOut', caPsd[i*dx], 'getConc' ) moose.connect( caHeadTab[i], 'requestOut', caHead[i*dx], 'getConc' ) moose.connect( psdRtab[i], 'requestOut', psdR[i*dx], 'getN' ) caDendTab = moose.Table2( '/graphs/caDendTab', len( caDend ) ).vec for i in zip( caDendTab, caDend ): moose.connect( i[0], 'requestOut', i[1], 'getConc' ) vtab = moose.Table( '/graphs/VmTab' ) moose.connect( vtab, 'requestOut', rdes.soma, 'getVm' ) eSpineCaTab = moose.Table( '/graphs/eSpineCaTab' ) path = rdes.spineComptElist[1].path + "/Ca_conc" moose.connect( eSpineCaTab, 'requestOut', path, 'getCa' ) eSpineVmTab = moose.Table( '/graphs/eSpineVmTab' ) moose.connect( eSpineVmTab, 'requestOut', rdes.spineComptElist[1], 'getVm' ) eSpineGkTab = moose.Table( '/graphs/eSpineGkTab' ) path = rdes.spineComptElist[1].path + "/NMDA" moose.connect( eSpineGkTab, 'requestOut', path, 'getGk' )
def makePlots(): plt.ion() fig = plt.figure( figsize=(12,6) ) dynamic = fig.add_subplot( 111 ) a = moose.vec( '/model/compartment/a' ) b = moose.vec( '/model/compartment/b' ) c = moose.vec( '/model/compartment/c' ) d = moose.vec( '/model/compartment/d' ) pos = numpy.arange( 0, a.conc.size, 1 ) aline, = dynamic.plot( pos, a.conc, label='a' ) bline, = dynamic.plot( pos, b.conc, label='b' ) cline, = dynamic.plot( pos, c.conc, label='c' ) dline, = dynamic.plot( pos, d.conc, label='d' ) plt.ylabel( 'Conc (mM)' ) plt.xlabel( 'Cylinder voxel #' ) plt.legend() timelabel = plt.text( 10, 0.8, 'time = 0.0' ) fig.canvas.draw() return( fig, dynamic, timelabel, aline, bline, cline, dline )
def display( self ): for i in self.plotNames: pylab.figure( i[2] ) pylab.title( i[1] ) pylab.xlabel( "Time (s)" ) pylab.ylabel( i[4] ) vtab = moose.vec( i[0] ) t = np.arange( 0, vtab[0].vector.size, 1 ) * vtab[0].dt for j in vtab: pylab.plot( t, j.vector * i[3] ) if len( self.moogList ) > 0: pylab.ion() pylab.show()
def scanDistDtGrid(): seqList, seqScore = makeSequence(numSpine) #moose.setClock(18, 0.02 ) #print "DT = ", moose.element( '/model/graphs/plot0').dt seqDtRange = (0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0 ) # Interval between stimuli, in sec drange = (5, 10, 15, 20, 25, 30) # Distance covered, in diffLen. if displayMoogli: seqDtRange = (moogliDt, ) drange = (moogliDistance, ) # seqDtRange = ( 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0 ) # Interval between stimuli, in sec # drange = ( 5, 10, 15, 20, 25, 30 ) allSimOutput = [] ampl = moose.vec('/model/chem/dend/ampl') print("ampl: ", len(ampl)) ampl.nInit = params['stimAmplitude'] blanks = params['blankVoxelsAtEnd'] preStim = params['preStimTime'] postStim = params['postStimTime'] diffusionLength = params['diffusionLength'] for seqDt in seqDtRange: temp2 = [] temp3 = [] for d in drange: # compt = moose.Compartment( '/model/chem/soma') # compt.diameter = params['dendDiameter']/8 dend = moose.element('/model/chem/dend') # print("dend diameter: ", dend.diameter) moose.le('/model/chem/dend') phase = moose.vec('/model/chem/dend/phase') ampl = moose.vec('/model/chem/dend/ampl') # Old version. Assumes we activate density * d compartments. #ampl.nInit = float(v)/float(d) ampl.nInit = params['stimAmplitude'] Z = moose.vec('/model/chem/dend/Z') stride = int(d) / numSpine Z.nInit = 0 phase.nInit = 10000.0 temp = [] slopes = [] for seq in seqList: print '.', sys.stdout.flush() for j in range(numSpine): k = (blanks + j * stride) Z[k].nInit = 1 phase[k].nInit = preStim + seq[j] * seqDt temp.append( runTrial(diffusionLength, seqDt, d, blanks, preStim, postStim)) #print temp simOut = np.array(temp) temp3.append(simOut) print seqDt, d #temp[-1], temp[-2], allSimOutput.append(temp3) return allSimOutput, seqDtRange, drange
import moose import time import numpy as np import rdesigneur as rd rdes = rd.rdesigneur( turnOffElec=True, #This subdivides the length of the soma into 2 micron voxels diffusionLength=2e-6, chemProto=[['makeChemOscillator()', 'osc']], chemDistrib=[['osc', 'soma', 'install', '1']], plotList=[['soma', '1', 'dend/a', 'conc', 'Concentration of a'], ['soma', '1', 'dend/b', 'conc', 'Concentration of b']], moogList=[['soma', '1', 'dend/a', 'conc', 'a Conc', 0, 360]]) rdes.buildModel() bv = moose.vec('/model/chem/dend/b') bv[0].concInit *= 2 bv[-1].concInit *= 2 moose.reinit() t0 = time.time() moose.start(400) print("[INFO ] Time taken %f" % (time.time() - t0)) rdes.displayMoogli(1, 400, rotation=0, azim=np.pi / 2, elev=0.0)
def main(): library = moose.Neutral('/library') #makePassiveSoma( 'cell', params['dendL'], params['dendDia'] ) makeDendProto() makeChemProto() rdes = rd.rdesigneur( turnOffElec=True, chemPlotDt=0.1, diffusionLength=params['diffusionL'], #cellProto=[['cell','soma']], cellProto=[['elec', 'dend']], chemProto=[['hydra', 'hydra']], chemDistrib=[['hydra', '#soma#,#dend#', 'install', '1']], plotList=[['soma', '1', 'dend/A', 'n', '# of A'], ['soma', '1', 'dend/B', 'n', '# of B']], # moogList = [['soma', '1', 'dend/A', 'n', 'num of A (number)']] ) moose.le('/library') moose.le('/library/hydra') #moose.showfield( '/library/soma/soma' ) rdes.buildModel() #moose.element('/model/chem/dend/B').vec[50].nInit=15.5 A = moose.element('/model/chem/dend/A') B = moose.element('/model/chem/dend/B') C = moose.element('/model/chem/dend/C') A.diffConst = 1e-13 B.diffConst = 0 C.diffConst = 0 B.motorConst = 1e-06 C.motorConst = -1e-06 # A.concInit=1 # B.concInit=10 moose.element('/model/chem/dend/A').vec[244].nInit = 1.2 #moose.element('/model/chem/dend/B').vec[244].nInit=1.2 #moose.element('/model/chem/dend/C').vec[400].nInit=1.2 #moose.element('/model/chem/dend/A').vec[105].nInit=1.2 #moose.element('/model/chem/dend/B').vec[105].nInit=1.2 #moose.element('/model/chem/dend/B').vec[25].nInit=0 #A.nInit=1 #B.nInit=15 #for i in range(0,499): #moose.element('/model/chem/dend/A').vec[i].diffConst=9.45e-12 #moose.element('/model/chem/dend/A').vec[i].diffConst=1e-13 #moose.element('/model/chem/dend/B').vec[i].diffConst=1e-13 #moose.element('/model/chem/dend/B').vec[i].diffConst=0.27e-09 #for i in range(500,999): #moose.element('/model/chem/dend/A').vec[i].diffConst=9.45e-12 #moose.element('/model/chem/dend/A').vec[i].diffConst=1e-13 #moose.element('/model/chem/dend/B').vec[i].diffConst=1e-13 #moose.element('/model/chem/dend/B').vec[i].diffConst=0.27e-09 #for i in range(0,200): #moose.element('/model/chem/dend/A').vec[i].diffConst=1e-13 #for i in range(700,999): #moose.element('/model/chem/dend/A').vec[i].diffConst=1e-13 moose.reinit() moose.start(200) #for t in range(0,3000,500): #moose.start(500) #avec=moose.vec('/model/chem/dend/A').n #plt.plot(avec) avec = moose.vec('/model/chem/dend/A').n bvec = moose.vec('/model/chem/dend/B').n cvec = moose.vec('/model/chem/dend/C').n plt.plot(bvec) return bvec, avec, cvec
def testExtendedSlice(self): em = moose.vec('/testSlice', n=10, g=1, dtype='Neutral') sl = em[2:12:3] for ii, el in enumerate(sl): self.assertEqual(el.path, '/testSlice[%d]' % (2 + ii * 3))
def runPanelCDEF(name, dist, seqDt, numSpine, seq, stimAmpl): numCompts = 10 comptLength = 4 startPos = numCompts * comptLength preStim = 10.0 blanks = 20 print moose.le('/library') rdes = rd.rdesigneur( useGssa=False, turnOffElec=True, chemPlotDt=0.1, #diffusionLength = params['diffusionLength'], diffusionLength=1e-6, #cellProto = [['cell', 'soma']], cellProto=[['./taper.p', 'elec']], chemProto=[['dend', name]], #chemDistrib = [['dend', 'soma', 'install', '1' ]], chemDistrib=[['dend', '#', 'install', '1']], #plotList = [['soma', '1', 'dend' + '/A', 'n', '# of A']], plotList=[['#', '1', 'dend' + '/A', 'n', '# of A']], ) rdes.buildModel() #for i in range( 20 ): #moose.setClock( i, 0.02 ) A = moose.vec('/model/chem/dend/A') print "\n\t $$$>:", moose.element('/model/chem') Z = moose.vec('/model/chem/dend/Z') print moose.element('/model/chem/dend/A/Adot').expr print moose.element('/model/chem/dend/B/Bdot').expr print moose.element('/model/chem/dend/Ca/CaStim').expr phase = moose.vec('/model/chem/dend/phase') ampl = moose.vec('/model/chem/dend/ampl') #vel = moose.vec( '/model/chem/dend/vel' ) #vel.nInit = 1e-6 * seqDt ampl.nInit = stimAmpl stride = int(dist) / numSpine phase.nInit = 10000 Z.nInit = 0 headV = A[0].volume print 'headV is', headV pos = range(startPos + 1, len(A), 2) print pos #pos = (21,23,25,27,29) for j in range(numSpine): #k = blanks + j * stride k = pos[j] print 'Volume of A is ', A[k].volume, A[k - 1].volume, A[ k - 2].volume, A[k - 3].volume print 'k is', k, 'Length of Z is', len(Z.n) Z[k].nInit = 1 phase[k].nInit = preStim + seq[j] * seqDt print 'k is', k, 'phase is', phase[k].n moose.reinit() runtime = 50 snapshot = preStim + seqDt * (numSpine - 0.8) print preStim, seqDt, numSpine, (numSpine - 0.8), "and the Snapshot>:", snapshot #snapshot = 26 moose.start(snapshot) avec = moose.vec('/model/chem/dend/A').n avec_0 = moose.vec('/model/chem/dend/A') moose.start(runtime - snapshot) print avec_0, len(avec), runtime, (runtime - snapshot) tvec = [] for i in range(5): #tab = moose.element( '/model/graphs/plot0[' + str( blanks + i * stride ) + ']' ) tab = moose.element('/model/graphs/plot0[' + str(pos[i]) + ']') dt = tab.dt tvec.append(tab.vector) moose.delete('/model') return dt, tvec, avec
def makeNeuroMeshModel(): diffLength = 10e-6 # But we only want diffusion over part of the model. numSyn = 13 elec = loadElec() synInput = moose.SpikeGen('/model/elec/synInput') synInput.threshold = -1.0 synInput.edgeTriggered = 0 synInput.Vm(0) synInput.refractT = 47e-3 for i in range(numSyn): name = '/model/elec/spine_head_14_' + str(i + 1) r = moose.element(name + '/glu') r.synapse.num = 1 syn = moose.element(r.path + '/synapse') moose.connect(synInput, 'spikeOut', syn, 'addSpike', 'Single') syn.weight = 0.2 * i * (numSyn - 1 - i) syn.delay = i * 1.0e-3 loadChem(diffLength) neuroCompt = moose.element('/model/chem/dend') neuroCompt.diffLength = diffLength neuroCompt.cellPortion(elec, '/model/elec/#') for x in moose.wildcardFind('/model/chem/##[ISA=PoolBase]'): if (x.diffConst > 0): x.diffConst = 1e-11 for x in moose.wildcardFind('/model/chem/##/Ca'): x.diffConst = 1e-10 # Put in dend solvers ns = neuroCompt.numSegments ndc = neuroCompt.numDiffCompts print('ns = ', ns, ', ndc = ', ndc) assert (neuroCompt.numDiffCompts == neuroCompt.mesh.num) assert (ns == 36) # dend, 5x (shaft+head) assert (ndc == 278) nmksolve = moose.Ksolve('/model/chem/dend/ksolve') nmdsolve = moose.Dsolve('/model/chem/dend/dsolve') nmstoich = moose.Stoich('/model/chem/dend/stoich') nmstoich.compartment = neuroCompt nmstoich.ksolve = nmksolve nmstoich.dsolve = nmdsolve nmstoich.path = "/model/chem/dend/##" print('done setting path, numPools = ', nmdsolve.numPools) assert (nmdsolve.numPools == 1) # oddly, numLocalFields does not work. ca = moose.element('/model/chem/dend/DEND/Ca') assert (ca.numData == ndc) # Put in spine solvers. Note that these get info from the neuroCompt spineCompt = moose.element('/model/chem/spine') sdc = spineCompt.mesh.num print('sdc = ', sdc) assert (sdc == 13) smksolve = moose.Ksolve('/model/chem/spine/ksolve') smdsolve = moose.Dsolve('/model/chem/spine/dsolve') smstoich = moose.Stoich('/model/chem/spine/stoich') smstoich.compartment = spineCompt smstoich.ksolve = smksolve smstoich.dsolve = smdsolve smstoich.path = "/model/chem/spine/##" assert (smstoich.numAllPools == 36) # Put in PSD solvers. Note that these get info from the neuroCompt psdCompt = moose.element('/model/chem/psd') pdc = psdCompt.mesh.num assert (pdc == 13) pmksolve = moose.Ksolve('/model/chem/psd/ksolve') pmdsolve = moose.Dsolve('/model/chem/psd/dsolve') pmstoich = moose.Stoich('/model/chem/psd/stoich') pmstoich.compartment = psdCompt pmstoich.ksolve = pmksolve pmstoich.dsolve = pmdsolve pmstoich.path = "/model/chem/psd/##" print('numAllPools = ', pmstoich.numAllPools) assert (pmstoich.numAllPools == 56) foo = moose.element('/model/chem/psd/Ca') bar = moose.element('/model/chem/psd/I1_p') print('PSD: numfoo = ', foo.numData, 'numbar = ', bar.numData) print('PSD: numAllVoxels = ', pmksolve.numAllVoxels) # Put in junctions between diffusion solvers nmdsolve.buildNeuroMeshJunctions(smdsolve, pmdsolve) """ CaNpsd = moose.vec( '/model/chem/psdMesh/PSD/PP1_PSD/CaN' ) print 'numCaN in PSD = ', CaNpsd.nInit, ', vol = ', CaNpsd.volume CaNspine = moose.vec( '/model/chem/spine/SPINE/CaN_BULK/CaN' ) print 'numCaN in spine = ', CaNspine.nInit, ', vol = ', CaNspine.volume """ # set up adaptors aCa = moose.Adaptor('/model/chem/psd/adaptCa', pdc) adaptCa = moose.vec('/model/chem/psd/adaptCa') chemCa = moose.vec('/model/chem/psd/Ca') print('aCa = ', aCa, ' foo = ', foo, "len( ChemCa ) = ", len(chemCa), ", numData = ", chemCa.numData) assert (len(adaptCa) == pdc) assert (len(chemCa) == pdc) for i in range(pdc): path = '/model/elec/spine_head_14_' + str(i + 1) + '/NMDA_Ca_conc' elecCa = moose.element(path) moose.connect(elecCa, 'concOut', adaptCa[i], 'input', 'Single') moose.connect(adaptCa, 'output', chemCa, 'setConc', 'OneToOne') adaptCa[i].inputOffset = 0.0 # adaptCa[i].outputOffset = 0.00008 # 80 nM offset in chem. adaptCa[i].scale = 1e-5 # 520 to 0.0052 mM #print adaptCa.outputOffset #print adaptCa.scale """ """ """
def main(): """ This illustrates the use of rdesigneur to build a simple dendrite with spines, and to confirm that the chemical contents of the spines align with the electrical. Just a single molecule Ca is involved. It diffuses and we plot the distribution. It causes 'inject' of the relevant compartment to rise. """ makeModel() # Create the output tables graphs = moose.Neutral('/graphs') #dendVm = addPlot( 'model/elec/dend', 'getVm', 'dendVm', 8 ) addPlot('model/chem/dend/Ca[0]', 'getConc', 'dCa0', 18) addPlot('model/chem/dend/Ca[25]', 'getConc', 'dCa25', 18) addPlot('model/chem/dend/Ca[49]', 'getConc', 'dCa49', 18) addPlot('model/chem/spine/Ca[0]', 'getN', 'sCa0', 18) addPlot('model/chem/spine/Ca[25]', 'getN', 'sCa25', 18) addPlot('model/chem/spine/Ca[49]', 'getN', 'sCa49', 18) addPlot('model/chem/psd/Ca[0]', 'getConc', 'pCa0', 18) addPlot('model/chem/psd/Ca[25]', 'getConc', 'pCa25', 18) addPlot('model/chem/psd/Ca[49]', 'getConc', 'pCa49', 18) d = moose.vec('/model/chem/dend/Ca') s = moose.vec('/model/chem/spine/Ca') p = moose.vec('/model/chem/psd/Ca') s[5].nInit = 1000 s[40].nInit = 5000 moose.reinit() moose.start(runtime) fig = plt.figure(figsize=(13, 10)) p1 = fig.add_subplot(311) plotVm(p1, 'dend') plotVm(p1, 'head') plotVm(p1, 'psd') p1.legend() #time = numpy.arange( 0, dendVm.vector.size, 1 ) * dendVm.dt #p1.plot( time, dendVm.vector, label = 'dendVm' ) p2 = fig.add_subplot(312) p2.plot(d.conc, label='idendCa') p2.plot(s.conc, label='ispineCa') p2.plot(p.conc, label='ipsdCa') p2.legend() ''' p2 = fig.add_subplot( 312 ) for i in moose.wildcardFind( '/graphs/#Ca#' ): time = numpy.arange( 0, i.vector.size, 1 ) * i.dt p2.plot( time, i.vector, label = i.name ) p2.legend() ''' p3 = fig.add_subplot(313) p3.plot(getMidpts('dend'), d.conc, label='dendCa') #p3.plot( range( 0, len( d ) ), d.conc, label = 'dendCa' ) p3.plot(getMidpts('spine'), s.conc, label='spineCa') p3.plot(getMidpts('psd'), p.conc, label='psdCa') p3.legend() plt.show() app = QtGui.QApplication(sys.argv) #widget = mv.MoogliViewer( '/model' ) morphology = moogli.read_morphology_from_moose(name="", path='/model/elec') widget = moogli.MorphologyViewerWidget(morphology) widget.show() return app.exec_() quit()
def scanDistDtGrid(): numCompts = 22 comptLength = 1 startPos = numCompts * comptLength seqList, seqScore = makeSequence(numSpine) #moose.setClock(18, 0.02 ) #print "DT = ", moose.element( '/model/graphs/plot0').dt seqDtRange = (1.0, 2.0, 3.0, 4.0) # Interval between stimuli, in sec drange = (5, 10, 15, 20) # Distance covered, in diffLen. # seqDtRange = ( 1.0, 2.0, 3.0) # drange = ( 15, 20, ) if displayMoogli: seqDtRange = (moogliDt, ) drange = (moogliDistance, ) allSimOutput = [] ampl = moose.vec('/model/chem/dend/ampl') print("ampl: ", len(ampl)) ampl.nInit = params['stimAmplitude'] blanks = params['blankVoxelsAtEnd'] preStim = params['preStimTime'] postStim = params['postStimTime'] diffusionLength = params['diffusionLength'] f1 = open('./stimPnts.txt', 'a') for seqDt in seqDtRange: temp2 = [] temp3 = [] print >> f1, "dt: ", seqDt for d in drange: print >> f1, "\td: ", d # compt = moose.Compartment( '/model/chem/soma') # compt.diameter = params['dendDiameter']/8 dend = moose.element('/model/chem/dend') # print("dend diameter: ", dend.diameter) moose.le('/model/chem/dend') phase = moose.vec('/model/chem/dend/phase') ampl = moose.vec('/model/chem/dend/ampl') # Old version. Assumes we activate density * d compartments. #ampl.nInit = float(v)/float(d) ampl.nInit = params['stimAmplitude'] Z = moose.vec('/model/chem/dend/Z') print("Z length: ", len(Z)) stride = int(d) / numSpine Z.nInit = 0 phase.nInit = 10000.0 temp = [] slopes = [] pos = range(startPos + 1, len(Z), 2) print pos for seq in seqList: print '.', sys.stdout.flush() for j in range(numSpine): #k = (blanks + j * stride) k = pos[j * stride] print 'k is', k print >> f1, '\t\tk: ', k Z[k].nInit = 1 print 'volumes are', Z[0].volume, Z[k - 2].volume, Z[ k - 1].volume, Z[k].volume, Z[k + 1].volume, Z[k + 2].volume phase[k].nInit = preStim + seq[j] * seqDt temp.append( runTrial(diffusionLength, seqDt, d, blanks, preStim, postStim)) #print temp print >> f1, "\n\n" simOut = np.array(temp) temp3.append(simOut) print seqDt, d #temp[-1], temp[-2], allSimOutput.append(temp3) return allSimOutput, seqDtRange, drange
def main(): global num num = 100 runtime = 11 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') c = moose.element('/model/compartment/c') d = moose.element('/model/compartment/d') s = moose.element('/model/compartment/s') halfWidth = [] timeArr = [] maxFWHH = [] r2 = moose.element('/model/compartment/r2') trialNum = str(c.diffConst) + str(r2.Kf) + str(r2.Kb) 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 ) #timeLabel = plt.text(60, 0.4, 'time = 0') #line1, = ax.plot( pos, a.vec.conc, label='a' ) #line2, = ax.plot( pos, b.vec.conc, label='c' ) #line3, = ax.plot( pos, b.vec.conc, label='d' ) #plt.legend() #fig.canvas.draw() anC = [] mm = moose.vec('/model/compartment/mesh') diffL = moose.element('/model/compartment').diffLength print a.vec[0].nInit, 'diff length', diffL list = [[1e-12, 1], [2e-12, 2], [4e-12, 4], [6e-12, 6], [8e-12, 8], [10e-12, 10]] for j in list: anC = [] for i in range(len(a.vec.conc)): #anC.append((10/numpy.sqrt(4*numpy.pi*a.diffConst*1))*numpy.exp(-(i**2)/4*a.diffConst*1)) #print mm[i].Coordinates[0] anC.append(2.0 * diffL * (3.0 / (math.sqrt(4 * math.pi * a.diffConst * 4))) * math.exp(-(mm[i].Coordinates[0]**2) / (4 * a.diffConst * 4))) #print diffL*(3.0/(math.sqrt(4*math.pi*a.diffConst*4)))*math.exp(-(mm[i].Coordinates[0]**2)/(4*a.diffConst*4)) #anC.append(4*diffL**2*(3/(4*numpy.pi*j[1]*numpy.sqrt(a.diffConst*a.diffConst)))*numpy.exp(-(mm[i].Coordinates[0]**2)/(4*a.diffConst*j[1])-j[0]/(4*a.diffConst*j[1]))) # anC.append(4*diffL**2*(3/(4*numpy.pi*4*numpy.sqrt(4*numpy.pi*4*a.diffConst*a.diffConst*a.diffConst)))*numpy.exp(-(mm[i].Coordinates[0]**2)/(4*a.diffConst*4)-(mm[i].Coordinates[0]**2)/(4*a.diffConst*4)-j/(4*a.diffConst*4))) #print (3/(numpy.sqrt(4*numpy.pi*a.diffConst*1)))*numpy.exp(-(mm[i].Coordinates[0]**2)/(4*a.diffConst*1)) firstCell = diffL * (3.0 / (math.sqrt(4 * math.pi * a.diffConst * 4)) ) * math.exp(-(mm[0].Coordinates[0]**2) / (4 * a.diffConst * 4)) print 'analaytical sum is', sum(anC) - firstCell, 'max of anC is', max( anC) plt.plot(anC) raw_input() time = 0 for t in range(0, runtime): moose.start(0.5) time = time + 0.5 if int(time == 4): print 'numerical sum is', sum(a.vec.conc), max(a.vec.conc) temp = a.vec.conc plt.figure(2) plt.plot(temp) raw_input() aList = a.vec.conc maxa = max(aList) #indMax = numpy.where(aList==maxa) #indMax = num/2 indMax = 0 halfMax = maxa / 2 indHalfMax = (numpy.abs(aList[0:num] - halfMax)).argmin() #print 'maximum value is', maxa, 'postion is', numpy.where(aList==maxa) print 'maximum value is', maxa print 'half height is at', indHalfMax print 'half maximum is', aList[indHalfMax] #halfWidth.append(int(indMax[0])-indHalfMax) #halfWidth.append(indMax-indHalfMax) halfWidth.append(indHalfMax - indMax) timeArr.append(t) #line1.set_ydata( a.vec.conc ) #line2.set_ydata( b.vec.conc ) #line2.set_ydata( c.vec.conc ) #line3.set_ydata( d.vec.conc ) #timeLabel.set_text( "time = %d" % t ) #fig.canvas.draw() print 'minimum and maximum of a', min(a.vec.conc), max(a.vec.conc) maxFWHH.append(max(halfWidth)) print 'max FWHH is', max(halfWidth) fileName = 'data.xml' writeXML(timeArr, halfWidth, maxFWHH, trialNum, fileName)
def test_vec(): foo = moose.Pool('/foo1', 500) bar = moose.vec('/foo1') assert len(bar) == 500
moose.element('/library/osc/spine').volume = 1e-19 moose.copy(compt, '/library/osc', 'psd') moose.element('/library/osc/psd').volume = 1e-20 rdes = rd.rdesigneur( turnOffElec=True, useGssa=False, cellProto=[['./cells/h10.CNG.swc', 'elec']], spineProto=[['makePassiveSpine()', 'spine']], spineDistrib=[["spine", '#apical#,#dend#', '10e-6', '1e-6']], chemProto=[['/library/osc', 'osc']], chemDistrib=[['osc', '#apical#,#dend#', 'install', 'H(p - 5e-4)']], plotList=[['#', '1', 'psd/a', 'conc', 'conc of a in PSD'], ['#', '1', 'spine/a', 'conc', 'conc of a in spine'], ['#', '1', 'dend/a', 'conc', 'conc of a in Dend']]) rdes.buildModel() av = moose.vec('/model/chem/psd/a') av[0].concInit *= 10 ''' dv = moose.vec( '/model/chem/dend/a' ) print len( dv ) dv[0].concInit *= 2 ''' moose.reinit() moose.start(100) rdes.display()
def makeGlobalBalanceNetwork(): stim = moose.RandSpike('/model/stim', params['numInputs']) inhib = moose.LIF('/model/inhib', params['numInhib']) insyn = moose.SimpleSynHandler(inhib.path + '/syns', params['numInhib']) moose.connect(insyn, 'activationOut', inhib, 'activation', 'OneToOne') output = moose.LIF('/model/output', params['numOutput']) outsyn = moose.SimpleSynHandler(output.path + '/syns', params['numOutput']) moose.connect(outsyn, 'activationOut', output, 'activation', 'OneToOne') outInhSyn = moose.SimpleSynHandler(output.path + '/inhsyns', params['numOutput']) moose.connect(outInhSyn, 'activationOut', output, 'activation', 'OneToOne') iv = moose.vec(insyn.path + '/synapse') ov = moose.vec(outsyn.path + '/synapse') oiv = moose.vec(outInhSyn.path + '/synapse') assert len(iv) == 0 assert len(ov) == 0 assert len(oiv) == 0 temp = moose.connect(stim, 'spikeOut', iv, 'addSpike', 'Sparse') inhibMatrix = moose.element(temp) inhibMatrix.setRandomConnectivity(params['stimToInhProb'], params['stimToInhSeed']) cl = inhibMatrix.connectionList # This can change when random-number generator changes. # This was before we used c++11 <random> to generate random numbers. This # test has changes on Tuesday 31 July 2018 11:12:35 AM IST # expectedCl = [ 1,4,13,13,26,42,52,56,80,82,95,97,4,9,0,9,4,8,0,6,1,6,6,7] expectedCl = [0, 6, 47, 50, 56, 67, 98, 2, 0, 3, 5, 4, 8, 3] assert list(cl) == expectedCl, "Expected %s, got %s" % (expectedCl, cl) temp = moose.connect(stim, 'spikeOut', ov, 'addSpike', 'Sparse') excMatrix = moose.element(temp) excMatrix.setRandomConnectivity(params['stimToOutProb'], params['stimToOutSeed']) temp = moose.connect(inhib, 'spikeOut', oiv, 'addSpike', 'Sparse') negFFMatrix = moose.element(temp) negFFMatrix.setRandomConnectivity(params['inhToOutProb'], params['inhToOutSeed']) # print("ConnMtxEntries: ", inhibMatrix.numEntries, excMatrix.numEntries, negFFMatrix.numEntries) got = (inhibMatrix.numEntries, excMatrix.numEntries, negFFMatrix.numEntries) expected = (7, 62, 55) assert expected == got, "Expected %s, Got %s" % (expected, got) cl = negFFMatrix.connectionList numInhSyns = [] niv = 0 nov = 0 noiv = 0 for i in moose.vec(insyn): niv += i.synapse.num numInhSyns.append(i.synapse.num) if i.synapse.num > 0: i.synapse.weight = params['wtStimToInh'] # expected = [2,1,0,0,2,0,3,1,1,2] expected = [1, 0, 1, 2, 1, 1, 0, 0, 1, 0] assert numInhSyns == expected, "Expected %s, got %s" % (expected, numInhSyns) for i in moose.vec(outsyn): print('111', i) nov += i.synapse.num if i.synapse.num > 0: i.synapse.weight = params['wtStimToOut'] for i in moose.vec(outInhSyn): noiv += i.synapse.num #print i.synapse.num if i.synapse.num > 0: i.synapse.weight = params['wtInhToOut'] print("SUMS: ", sum(iv.numField), sum(ov.numField), sum(oiv.numField)) assert [1, 64, 25] == [sum(iv.numField), sum(ov.numField), sum(oiv.numField)] print("SUMS2: ", niv, nov, noiv) assert [7, 62, 55] == [niv, nov, noiv] print("SUMS3: ", sum(insyn.vec.numSynapses), sum(outsyn.vec.numSynapses), sum(outInhSyn.vec.numSynapses)) assert [7, 62, 55] == [ sum(insyn.vec.numSynapses), sum(outsyn.vec.numSynapses), sum(outInhSyn.vec.numSynapses) ] # print(oiv.numField) # print(insyn.vec[1].synapse.num) # print(insyn.vec.numSynapses) # print(sum( insyn.vec.numSynapses )) # niv = iv.numSynapses # ov = iv.numSynapses sv = moose.vec(stim) sv.rate = params['randInputRate'] sv.refractT = params['randRefractTime'] #moose.showfield( sv[7] ) inhib.vec.thresh = params['inhibThresh'] inhib.vec.Rm = params['Rm'] inhib.vec.Cm = params['Cm'] inhib.vec.vReset = params['inhVreset'] inhib.vec.refractoryPeriod = params['inhibRefractTime'] output.vec.thresh = params['outputThresh'] output.vec.Rm = params['Rm'] output.vec.Cm = params['Cm'] output.vec.refractoryPeriod = params['outputRefractTime'] otab = moose.Table('/model/otab', params['numOutput']) moose.connect(otab, 'requestOut', output, 'getVm', 'OneToOne') itab = moose.Table('/model/itab', params['numInhib']) moose.connect(itab, 'requestOut', inhib, 'getVm', 'OneToOne') return inhib, output
def computeTP(t, distS): a = moose.element('/model/compartment/a') b = moose.element('/model/compartment/b') s = moose.element('/model/compartment/s') rec = moose.element('/model/compartment/rec') w = len(a.vec.conc) h = w v2d = [[0 for x in range(w)] for y in range(h)] anC = [] mm = moose.vec('/model/compartment/mesh') diffL = moose.element('/model/compartment').diffLength print a.vec[0].nInit, 'diff length', diffL list = [[distS, t]] SourceC = 4 for j in list: anC = [] anC2 = [] for i in range(len(a.vec.conc)): anC.append(2.0 * diffL * (SourceC / (math.sqrt(4 * math.pi * a.diffConst * j[1]))) * math.exp(-(mm[i].Coordinates[0]**2) / (4 * a.diffConst * j[1]))) for k in range(len(a.vec.conc)): anC2.append(4.0 * diffL**2 * (SourceC / (4 * numpy.pi * j[1] * numpy.sqrt(a.diffConst * a.diffConst))) * numpy.exp(-(mm[i].Coordinates[0]**2) / (4 * a.diffConst * j[1]) - (mm[k].Coordinates[0]**2) / (4 * a.diffConst * j[1]))) v2d[i][k] = 4.0 * diffL**2 * (SourceC / ( 4 * numpy.pi * j[1] * numpy.sqrt(a.diffConst * a.diffConst) )) * numpy.exp(-(mm[i].Coordinates[0]**2) / (4 * a.diffConst * j[1]) - (mm[k].Coordinates[0]**2) / (4 * a.diffConst * j[1])) firstCell = diffL * ( SourceC / (math.sqrt(4 * math.pi * a.diffConst * j[1]))) * math.exp( -(mm[0].Coordinates[0]**2) / (4 * a.diffConst * j[1])) firstCell2 = diffL**2 * (SourceC / ( 4 * numpy.pi * j[1] * numpy.sqrt(a.diffConst * a.diffConst) )) * numpy.exp(-(mm[0].Coordinates[0]**2) / (4 * a.diffConst * j[1]) - (mm[0].Coordinates[0]**2) / (4 * a.diffConst * j[1])) print 'analaytical sum 1D is', sum(anC) - firstCell, 'max of anC is', max( anC) print 'analaytical sum 2D is', sum( anC2) - 2 * firstCell - firstCell2, 'max of anC2 is', max( anC2), firstCell, firstCell2 #plt.plot(anC) #plt.plot(anC2) #raw_input() tempRec = [] anP = True if anP == True: plt.figure(2) plt.title("alongX") for i in range(len(a.vec.conc)): tempRec.append(v2d[i][distS]) plt.plot(tempRec) print 'sum conc at dendrite', sum(tempRec) raw_input() return tempRec
def testNeuroMeshMultiscale(): elecDt = 50e-6 chemDt = 0.005 ePlotDt = 0.5e-3 cPlotDt = 0.005 plotName = 'nm.plot' makeNeuroMeshModel() print("after model is completely done") for i in moose.wildcardFind('/model/chem/#/#/#/transloc#'): print((i[0].name, i[0].Kf, i[0].Kb, i[0].kf, i[0].kb)) makeChemPlots() makeElecPlots() moose.setClock(0, elecDt) moose.setClock(1, elecDt) moose.setClock(2, elecDt) moose.setClock(4, chemDt) moose.setClock(5, chemDt) moose.setClock(6, chemDt) moose.setClock(7, cPlotDt) moose.setClock(8, ePlotDt) moose.useClock(0, '/model/elec/##[ISA=Compartment]', 'init') moose.useClock(1, '/model/elec/##[ISA=Compartment]', 'process') moose.useClock(1, '/model/elec/##[ISA=SpikeGen]', 'process') moose.useClock( 2, '/model/elec/##[ISA=ChanBase],/model/##[ISA=SynBase],/model/##[ISA=CaConc]', 'process') #moose.useClock( 5, '/model/chem/##[ISA=PoolBase],/model/##[ISA=ReacBase],/model/##[ISA=EnzBase]', 'process' ) #moose.useClock( 4, '/model/chem/##[ISA=Adaptor]', 'process' ) moose.useClock(4, '/model/chem/#/dsolve', 'process') moose.useClock(5, '/model/chem/#/ksolve', 'process') moose.useClock(6, '/model/chem/spine/adaptCa', 'process') moose.useClock(6, '/model/chem/dend/DEND/adaptCa', 'process') moose.useClock(7, '/graphs/chem/#', 'process') moose.useClock(8, '/graphs/elec/#', 'process') moose.element('/model/elec/soma').inject = 2e-10 moose.element('/model/chem/psd/Ca').concInit = 0.001 moose.element('/model/chem/spine/Ca').concInit = 0.002 moose.element('/model/chem/dend/DEND/Ca').concInit = 0.003 moose.reinit() moose.start(0.25) plt.ion() fig = plt.figure(figsize=(8, 8)) chem = fig.add_subplot(311) chem.set_ylim(0, 0.002) plt.ylabel('Conc (mM)') plt.xlabel('time (seconds)') for x in moose.wildcardFind('/graphs/chem/#[ISA=Table]'): pos = numpy.arange(0, x.vector.size, 1) * cPlotDt line1, = chem.plot(pos, x.vector, label=x.name) plt.legend() elec = fig.add_subplot(312) plt.ylabel('Vm (V)') plt.xlabel('time (seconds)') for x in moose.wildcardFind('/graphs/elec/#[ISA=Table]'): pos = numpy.arange(0, x.vector.size, 1) * ePlotDt line1, = elec.plot(pos, x.vector, label=x.name) plt.legend() lenplot = fig.add_subplot(313) plt.ylabel('Ca (mM )') plt.xlabel('Voxel#)') spineCa = moose.vec('/model/chem/spine/Ca') dendCa = moose.vec('/model/chem/dend/DEND/Ca') line1, = lenplot.plot(list(range(len(spineCa))), spineCa.conc, label='spine') line2, = lenplot.plot(list(range(len(dendCa))), dendCa.conc, label='dend') ca = [ x.Ca * 0.0001 for x in moose.wildcardFind('/model/elec/##[ISA=CaConc]') ] line3, = lenplot.plot(list(range(len(ca))), ca, label='elec') spineCaM = moose.vec('/model/chem/spine/Ca_CaM') line4, = lenplot.plot(list(range(len(spineCaM))), spineCaM.conc, label='spineCaM') psdCaM = moose.vec('/model/chem/psd/Ca_CaM') line5, = lenplot.plot(list(range(len(psdCaM))), psdCaM.conc, label='psdCaM') plt.legend() fig.canvas.draw() eval(input()) print('All done')
def buildOnePlot(path, field='getConc'): elist = moose.vec('/model/chem/' + path) tabname = path.replace('/', '_') tab = moose.Table2('/graphs/' + tabname, len(elist)).vec moose.connect(tab, 'requestOut', elist, field, 'OneToOne')
def _buildAdaptor( self, meshName, elecRelPath, elecField, \ chemRelPath, chemField, isElecToChem, offset, scale ): #print "offset = ", offset, ", scale = ", scale mesh = moose.element('/model/chem/' + meshName) #elecComptList = mesh.elecComptList if elecRelPath == 'spine': elecComptList = moose.vec(mesh.elecComptList[0].path + '/../spine') else: elecComptList = mesh.elecComptList ''' for i in elecComptList: print i.diameter print len( elecComptList[0] ) print elecComptList[0][0].parent.path print "--------------------------------------" spine = moose.vec( elecComptList[0].path + '/../spine' ) for i in spine: print i.headDiameter moose.le( elecComptList[0][0].parent ) ''' if len(elecComptList) == 0: raise BuildError( \ "buildAdaptor: no elec compts in elecComptList on: " + \ mesh.path ) startVoxelInCompt = mesh.startVoxelInCompt endVoxelInCompt = mesh.endVoxelInCompt capField = elecField[0].capitalize() + elecField[1:] capChemField = chemField[0].capitalize() + chemField[1:] chemPath = mesh.path + '/' + chemRelPath if not (moose.exists(chemPath)): raise BuildError( \ "Error: buildAdaptor: no chem obj in " + chemPath ) chemObj = moose.element(chemPath) assert (chemObj.numData >= len(elecComptList)) adName = '/adapt' for i in range(1, len(elecRelPath)): if (elecRelPath[-i] == '/'): adName += elecRelPath[1 - i] break ad = moose.Adaptor(chemObj.path + adName, len(elecComptList)) #print 'building ', len( elecComptList ), 'adaptors ', adName, ' for: ', mesh.name, elecRelPath, elecField, chemRelPath av = ad.vec chemVec = moose.element(mesh.path + '/' + chemRelPath).vec for i in zip(elecComptList, startVoxelInCompt, endVoxelInCompt, av): i[3].inputOffset = 0.0 i[3].outputOffset = offset i[3].scale = scale if elecRelPath == 'spine': elObj = i[0] else: ePath = i[0].path + '/' + elecRelPath if not (moose.exists(ePath)): raise BuildError( \ "Error: buildAdaptor: no elec obj in " + ePath ) elObj = moose.element(i[0].path + '/' + elecRelPath) if (isElecToChem): elecFieldSrc = 'get' + capField chemFieldDest = 'set' + capChemField #print ePath, elecFieldSrc, scale moose.connect(i[3], 'requestOut', elObj, elecFieldSrc) for j in range(i[1], i[2]): moose.connect(i[3], 'output', chemVec[j], chemFieldDest) else: chemFieldSrc = 'get' + capChemField elecFieldDest = 'set' + capField for j in range(i[1], i[2]): moose.connect(i[3], 'requestOut', chemVec[j], chemFieldSrc) msg = moose.connect(i[3], 'output', elObj, elecFieldDest)
def main(): library = moose.Neutral('/library') makePassiveSoma('cell', params['dendL'], params['dendDia']) makeChemProto() rdes = rd.rdesigneur( turnOffElec=True, chemPlotDt=0.1, diffusionLength=params['diffusionL'], cellProto=[['cell', 'soma']], chemProto=[['hydra', 'hydra']], chemDistrib=[['hydra', 'soma', 'install', '1']], plotList=[['soma', '1', 'dend/A', 'n', '# of A'], ['soma', '1', 'dend/B', 'n', '# of B']], # moogList = [['soma', '1', 'dend/A', 'n', 'num of A (number)']] ) moose.le('/library') moose.le('/library/hydra') moose.showfield('/library/soma/soma') rdes.buildModel() #moose.element('/model/chem/dend/B').vec[50].nInit=15.5 A = moose.vec('/model/chem/dend/A') #B = moose.vec('/model/chem/dend/B') # A.concInit=1 # B.concInit=10 moose.element('/model/chem/dend/B').vec[50].nInit = 10.3 #moose.element('/model/chem/dend/B').vec[25].nInit=0 #A.nInit=1 #B.nInit=15 for i in range(0, 49): moose.element('/model/chem/dend/A').vec[i].diffConst = 1 moose.element('/model/chem/dend/B').vec[i].diffConst = 0 for i in range(50, 99): moose.element('/model/chem/dend/A').vec[i].diffConst = 1 moose.element('/model/chem/dend/B').vec[i].diffConst = 0 print "diffconst is ", moose.element( '/model/chem/dend/A').vec[50].diffConst #for i in range(98,99): #moose.element('/model/chem/dend/A').vec[i].diffConst=1e-06 #moose.element('/model/chem/dend/B').vec[i].diffConst=0 #Adot = moose.element('/model/chem/dend/A/Adot') #Bdot = moose.element('/model/chem/dend/B/Bdot') #print "\n\n\t\t Before Run", Adot, Bdot, A.nInit, B.nInit, A.n, B.n, A.concInit, B.concInit moose.reinit() moose.start(500) #print "\n\n\t\t After Run", A.nInit, B.nInit, A.n, B.n, A.concInit, B.concInit # rdes.display() # rdes.displayMoogli( 1, 400, 0.001 ) avec = moose.vec('/model/chem/dend/A').n bvec = moose.vec('/model/chem/dend/B').n #tab = moose.element( '/model/graphs/plot0') #dt = tab.dt #tvec=[] #tvec.append( tab.vector ) # xplot = [] # xplot.append( avec ) ## t = np.arange( 0, len( tvec[0] ), 1.0 ) * dt plt.plot(bvec) #print bvec, len(bvec), bvec return bvec, avec
def make_network(): size = 1024 dt = 0.2 runsteps = 50 delayMin = 0 delayMax = 4 weightMax = 1 Vmax = 1.0 thresh = 0.4 refractoryPeriod = 0.4 tau = 0.5 connectionProbability = 0.01 random.seed(123) nprand.seed(456) t0 = time.time() network = moose.IntFire('network', size) syns = moose.SimpleSynHandler('/network/syns', size) moose.connect(syns, 'activationOut', network, 'activation', 'OneToOne') moose.le('/network') syns.vec.numSynapses = [1] * size sv = moose.vec('/network/syns/synapse') print(('before connect t = ', time.time() - t0)) mid = moose.connect(network, 'spikeOut', sv, 'addSpike', 'Sparse') print(('after connect t = ', time.time() - t0)) #print mid.destFields m2 = moose.element(mid) m2.setRandomConnectivity(connectionProbability, 5489) print(('after setting connectivity, t = ', time.time() - t0)) #network.vec.Vm = [(Vmax*random.random()) for r in range(size)] network.vec.Vm = nprand.rand(size) * Vmax network.vec.thresh = thresh network.vec.refractoryPeriod = refractoryPeriod network.vec.tau = tau numSynVec = syns.vec.numSynapses print(('Middle of setup, t = ', time.time() - t0)) numTotSyn = sum(numSynVec) print((numSynVec.size, ', tot = ', numTotSyn, ', numSynVec = ', numSynVec)) for item in syns.vec: sh = moose.element(item) sh.synapse.delay = delayMin + (delayMax - delayMin) * nprand.rand( len(sh.synapse)) #sh.synapse.delay = [ (delayMin + random.random() * (delayMax - delayMin ) for r in range( len( sh.synapse ) ) ] sh.synapse.weight = nprand.rand(len(sh.synapse)) * weightMax print(('after setup, t = ', time.time() - t0)) numStats = 100 stats = moose.SpikeStats('/stats', numStats) stats.vec.windowLength = 1 # timesteps to put together. plots = moose.Table('/plot', numStats) convergence = size / numStats for i in range(numStats): for j in range(size / numStats): k = i * convergence + j moose.connect(network.vec[k], 'spikeOut', stats.vec[i], 'addSpike') moose.connect(plots, 'requestOut', stats, 'getMean', 'OneToOne') #moose.useClock( 0, '/network/syns,/network', 'process' ) moose.useClock(0, '/network/syns', 'process') moose.useClock(1, '/network', 'process') moose.useClock(2, '/stats', 'process') moose.useClock(3, '/plot', 'process') moose.setClock(0, dt) moose.setClock(1, dt) moose.setClock(2, dt) moose.setClock(3, dt) moose.setClock(9, dt) t1 = time.time() moose.reinit() print(('reinit time t = ', time.time() - t1)) network.vec.Vm = nprand.rand(size) * Vmax print(('setting Vm , t = ', time.time() - t1)) t1 = time.time() print('starting') moose.start(runsteps * dt) print(('runtime, t = ', time.time() - t1)) print((network.vec.Vm[99:103], network.vec.Vm[900:903])) t = [i * dt for i in range(plots.vec[0].vector.size)] i = 0 for p in plots.vec: pylab.plot(t, p.vector, label=str(i)) i += 1 pylab.xlabel("Time (s)") pylab.ylabel("Vm (mV)") pylab.legend() pylab.show()
def makeGraphics(cPlotDt, ePlotDt): plt.ion() fig = plt.figure(figsize=(10, 16)) chem = fig.add_subplot(411) chem.set_ylim(0, 0.006) plt.ylabel('Conc (mM)') plt.xlabel('time (seconds)') for x in moose.wildcardFind('/graphs/chem/#[ISA=Table]'): pos = numpy.arange(0, x.vector.size, 1) * cPlotDt line1, = chem.plot(pos, x.vector, label=x.name) plt.legend() elec = fig.add_subplot(412) plt.ylabel('Vm (V)') plt.xlabel('time (seconds)') for x in moose.wildcardFind('/graphs/elec/#[ISA=Table]'): pos = numpy.arange(0, x.vector.size, 1) * ePlotDt line1, = elec.plot(pos, x.vector, label=x.name) plt.legend() ca = fig.add_subplot(413) plt.ylabel('[Ca] (mM)') plt.xlabel('time (seconds)') for x in moose.wildcardFind('/graphs/ca/#[ISA=Table]'): pos = numpy.arange(0, x.vector.size, 1) * ePlotDt line1, = ca.plot(pos, x.vector, label=x.name) plt.legend() lenplot = fig.add_subplot(414) plt.ylabel('Ca (mM )') plt.xlabel('Voxel#)') spineCa = moose.vec('/model/chem/spine/Ca') dendCa = moose.vec('/model/chem/dend/DEND/Ca') line1, = lenplot.plot(range(len(spineCa)), spineCa.conc, label='spine') line2, = lenplot.plot(range(len(dendCa)), dendCa.conc, label='dend') ca = [ x.Ca * 0.0001 for x in moose.wildcardFind('/model/elec/##[ISA=CaConcBase]') ] line3, = lenplot.plot(range(len(ca)), ca, label='elec') spineCaM = moose.vec('/model/chem/spine/CaM_dash_Ca4') line4, = lenplot.plot(range(len(spineCaM)), spineCaM.conc, label='spineCaM') psdCaM = moose.vec('/model/chem/psd/CaM_dash_Ca4') line5, = lenplot.plot(range(len(psdCaM)), psdCaM.conc, label='psdCaM') plt.legend() fig.canvas.draw() raw_input() ''' for x in moose.wildcardFind( '/graphs/##[ISA=Table]' ): t = numpy.arange( 0, x.vector.size, 1 ) pylab.plot( t, x.vector, label=x.name ) pylab.legend() pylab.show() ''' print 'All done'
def testGetItem(self): em = moose.vec('testGetItem', n=10, g=1, dtype='Neutral') el = em[5] self.assertEqual(el.path, '/%s[5]' % (em.name))
def makeNeuroMeshModel(): diffLength = 20e-6 # But we only want diffusion over part of the model. numSyn = 13 elec = loadElec() synInput = moose.SpikeGen('/model/elec/synInput') synInput.refractT = 47e-3 synInput.threshold = -1.0 synInput.edgeTriggered = 0 synInput.Vm(0) synInput.refractT = 47e-3 for i in range(numSyn): name = '/model/elec/spine_head_14_' + str(i + 1) r = moose.element(name + '/glu') r.synapse.num = 1 syn = moose.element(r.path + '/synapse') moose.connect(synInput, 'spikeOut', syn, 'addSpike', 'Single') syn.weight = 0.2 * i * (numSyn - 1 - i) syn.delay = i * 1.0e-3 neuroCompt = moose.NeuroMesh('/model/neuroMesh') #print 'neuroMeshvolume = ', neuroCompt.mesh[0].volume neuroCompt.separateSpines = 1 neuroCompt.diffLength = diffLength neuroCompt.geometryPolicy = 'cylinder' spineCompt = moose.SpineMesh('/model/spineMesh') #print 'spineMeshvolume = ', spineCompt.mesh[0].volume moose.connect(neuroCompt, 'spineListOut', spineCompt, 'spineList', 'OneToOne') psdCompt = moose.PsdMesh('/model/psdMesh') #print 'psdMeshvolume = ', psdCompt.mesh[0].volume moose.connect(neuroCompt, 'psdListOut', psdCompt, 'psdList', 'OneToOne') loadChem(neuroCompt, spineCompt, psdCompt) # Put in the solvers, see how they fare. nmksolve = moose.GslStoich('/model/chem/neuroMesh/ksolve') nmksolve.path = '/model/chem/neuroMesh/##' nmksolve.compartment = moose.element('/model/chem/neuroMesh') nmksolve.method = 'rk5' nm = moose.element('/model/chem/neuroMesh/mesh') moose.connect(nm, 'remesh', nmksolve, 'remesh') #print "neuron: nv=", nmksolve.numLocalVoxels, ", nav=", nmksolve.numAllVoxels, nmksolve.numVarPools, nmksolve.numAllPools #print 'setting up smksolve' smksolve = moose.GslStoich('/model/chem/spineMesh/ksolve') smksolve.path = '/model/chem/spineMesh/##' smksolve.compartment = moose.element('/model/chem/spineMesh') smksolve.method = 'rk5' sm = moose.element('/model/chem/spineMesh/mesh') moose.connect(sm, 'remesh', smksolve, 'remesh') #print "spine: nv=", smksolve.numLocalVoxels, ", nav=", smksolve.numAllVoxels, smksolve.numVarPools, smksolve.numAllPools # #print 'setting up pmksolve' pmksolve = moose.GslStoich('/model/chem/psdMesh/ksolve') pmksolve.path = '/model/chem/psdMesh/##' pmksolve.compartment = moose.element('/model/chem/psdMesh') pmksolve.method = 'rk5' pm = moose.element('/model/chem/psdMesh/mesh') moose.connect(pm, 'remesh', pmksolve, 'remesh') #print "psd: nv=", pmksolve.numLocalVoxels, ", nav=", pmksolve.numAllVoxels, pmksolve.numVarPools, pmksolve.numAllPools # print('neuroMeshvolume = ', neuroCompt.mesh[0].volume) #print 'Assigning the cell model' # Now to set up the model. #neuroCompt.cell = elec neuroCompt.cellPortion( elec, '/model/elec/lat_14_#,/model/elec/spine_neck#,/model/elec/spine_head#') """ ns = neuroCompt.numSegments #assert( ns == 11 ) # dend, 5x (shaft+head) ndc = neuroCompt.numDiffCompts #print 'numDiffCompts = ', ndc assert( ndc == 145 ) ndc = neuroCompt.mesh.num #print 'NeuroMeshNum = ', ndc assert( ndc == 145 ) sdc = spineCompt.mesh.num #print 'SpineMeshNum = ', sdc assert( sdc == 13 ) pdc = psdCompt.mesh.num #print 'PsdMeshNum = ', pdc assert( pdc == 13 ) """ mesh = moose.vec('/model/chem/neuroMesh/mesh') #for i in range( ndc ): # print 's[', i, '] = ', mesh[i].volume mesh2 = moose.vec('/model/chem/spineMesh/mesh') # for i in range( sdc ): # print 's[', i, '] = ', mesh2[i].volume #print 'numPSD = ', moose.element( '/model/chem/psdMesh/mesh' ).localNumField mesh = moose.vec('/model/chem/psdMesh/mesh') #print 'psd mesh.volume = ', mesh.volume #for i in range( pdc ): # print 's[', i, '] = ', mesh[i].volume # # We need to use the spine solver as the master for the purposes of # these calculations. This will handle the diffusion calculations # between head and dendrite, and between head and PSD. smksolve.addJunction(nmksolve) #print "spine: nv=", smksolve.numLocalVoxels, ", nav=", smksolve.numAllVoxels, smksolve.numVarPools, smksolve.numAllPools smksolve.addJunction(pmksolve) #print "psd: nv=", pmksolve.numLocalVoxels, ", nav=", pmksolve.numAllVoxels, pmksolve.numVarPools, pmksolve.numAllPools ndc = neuroCompt.numDiffCompts #print 'numDiffCompts = ', ndc assert (ndc == 13) ndc = neuroCompt.mesh.num #print 'NeuroMeshNum = ', ndc assert (ndc == 13) sdc = spineCompt.mesh.num #print 'SpineMeshNum = ', sdc assert (sdc == 13) pdc = psdCompt.mesh.num #print 'PsdMeshNum = ', pdc assert (pdc == 13) """ print 'neuroCompt' for i in range( ndc ): print i, neuroCompt.stencilIndex[i] print i, neuroCompt.stencilRate[i] print 'spineCompt' for i in range( sdc * 3 ): print i, spineCompt.stencilIndex[i] print i, spineCompt.stencilRate[i] print 'psdCompt' for i in range( pdc ): print i, psdCompt.stencilIndex[i] print i, psdCompt.stencilRate[i] print 'Spine parents:' pavoxel = spineCompt.parentVoxel for i in range( sdc ): print i, pavoxel[i] """ # oddly, numLocalFields does not work. #moose.le( '/model/chem/neuroMesh' ) ca = moose.element('/model/chem/neuroMesh/DEND/Ca') assert (ca.lastDimension == ndc) """ CaNpsd = moose.vec( '/model/chem/psdMesh/PSD/PP1_PSD/CaN' ) print 'numCaN in PSD = ', CaNpsd.nInit, ', vol = ', CaNpsd.volume CaNspine = moose.vec( '/model/chem/spineMesh/SPINE/CaN_BULK/CaN' ) print 'numCaN in spine = ', CaNspine.nInit, ', vol = ', CaNspine.volume """ # set up adaptors aCa = moose.Adaptor('/model/chem/psdMesh/adaptCa', pdc) adaptCa = moose.vec('/model/chem/psdMesh/adaptCa') chemCa = moose.vec('/model/chem/psdMesh/PSD/Ca') assert (len(adaptCa) == pdc) assert (len(chemCa) == pdc) for i in range(pdc): path = '/model/elec/spine_head_14_' + str(i + 1) + '/NMDA_Ca_conc' elecCa = moose.element(path) moose.connect(elecCa, 'concOut', adaptCa[i], 'input', 'Single') moose.connect(adaptCa, 'outputSrc', chemCa, 'setConc', 'OneToOne') adaptCa.inputOffset = 0.0 # adaptCa.outputOffset = 80e-6 # 80 nM offset in chem. adaptCa.scale = 1e-5 # 520 to 0.0052 mM
def testIndexError(self): em = moose.vec('testIndexError', n=3, g=1, dtype='Neutral') with self.assertRaises(IndexError): el = em[5]
def main(): """ This illustrates the use of rdesigneur to build a simple dendrite with spines, and then to resize them using spine fields. These are the fields that would be changed dynamically in a simulation with reactions that affect spine geometry. """ makeModel() elec = moose.element( '/model/elec' ) elec.setSpineAndPsdMesh( moose.element('/model/chem/spine'), moose.element('/model/chem/psd') ) caDend = moose.vec( '/model/chem/dend/Ca' ) caHead = moose.vec( '/model/chem/spine/Ca' ) caPsd = moose.vec( '/model/chem/psd/Ca' ) eHead = moose.wildcardFind( '/model/elec/#head#' ) graphs = moose.Neutral( '/graphs' ) psdTab = moose.Table2( '/graphs/psdTab', len( caPsd ) ).vec headTab = moose.Table2( '/graphs/headTab', len( caHead ) ).vec dendTab = moose.Table2( '/graphs/dendTab', len( caDend ) ).vec eTab = moose.Table( '/graphs/eTab', len( eHead ) ).vec stimtab = moose.StimulusTable( '/stim' ) stimtab.stopTime = 0.3 stimtab.loopTime = 0.3 stimtab.doLoop = True stimtab.vector = [ 1.0 + numpy.sin( x ) for x in numpy.arange( 0, 2*PI, PI/1000 ) ] estimtab = moose.StimulusTable( '/estim' ) estimtab.stopTime = 0.001 estimtab.loopTime = 0.001 estimtab.doLoop = True estimtab.vector = [ 1e-9*numpy.sin( x ) for x in numpy.arange( 0, 2*PI, PI/1000 ) ] for i in range( len( caPsd ) ): moose.connect( psdTab[ i ], 'requestOut', caPsd[i], 'getConc' ) for i in range( len( caHead ) ): moose.connect( headTab[ i ], 'requestOut', caHead[i], 'getConc' ) for i in range( len( caDend ) ): moose.connect( dendTab[ i ], 'requestOut', caDend[i], 'getConc' ) for i in range( len( eHead ) ): moose.connect( eTab[ i ], 'requestOut', eHead[i], 'getVm' ) moose.connect( stimtab, 'output', caDend, 'setConc', 'OneToAll' ) dend = moose.element( '/model/elec/dend' ) moose.connect( estimtab, 'output', dend, 'setInject' ) moose.reinit() moose.start( 1 ) head0 = moose.element( '/model/elec/head0' ) shaft1 = moose.element( '/model/elec/shaft1' ) head2 = moose.element( '/model/elec/head2' ) # Here we scale the spine head length while keeping all vols constt. print("Spine 0: longer head, same vol\nSpine 1: longer shaft") print("Spine 2: Bigger head, same diffScale\n") elecParms = [ (i.Rm, i.Cm, i.Ra) for i in ( head0, shaft1, head2) ] chemParms = [ i.volume for i in ( caHead[0], caPsd[0], caHead[1], caPsd[1], caHead[2], caPsd[2] ) ] elec.spine[0].headLength *= 4 # 4x length elec.spine[0].headDiameter *= 0.5 # 1/2 x dia # Here we scale the shaft length. Vols are not touched. elec.spine[1].shaftLength *= 2 # 2 x length #Here we scale the spine head vol while retaining diffScale = xArea/len # This gives 4x vol. hdia = elec.spine[2].headDiameter sdsolve = moose.element( '/model/chem/spine/dsolve' ) elec.spine[2].headLength *= 2 # 2x length elec.spine[2].headDiameter *= numpy.sqrt(2) # sqrt(2) x dia hdia = elec.spine[2].headDiameter print("Checking scaling assertions: ") assertEq( elecParms[0][0] * 0.5 , head0.Rm ) assertEq( elecParms[0][1] * 2 , head0.Cm ) assertEq( elecParms[0][2] * 16 , head0.Ra ) assertEq( chemParms[0] , caHead[0].volume ) assertEq( chemParms[1] * 0.25 , caPsd[0].volume ) assertEq( elecParms[1][0] * 0.5 , shaft1.Rm ) assertEq( elecParms[1][1] * 2 , shaft1.Cm ) assertEq( elecParms[1][2] * 2 , shaft1.Ra ) assertEq( chemParms[2] , caHead[1].volume ) assertEq( chemParms[3] , caPsd[1].volume ) ratio = 2 * numpy.sqrt( 2 ) assertEq( elecParms[2][0] / ratio , head2.Rm ) assertEq( elecParms[2][1] * ratio , head2.Cm ) assertEq( elecParms[2][2] , head2.Ra ) assertEq( chemParms[4] * 4 , caHead[2].volume ) assertEq( chemParms[5] * 2 , caPsd[2].volume ) print("\nAll assertions cleared") moose.start( 2 ) for i in range( len( psdTab ) ): pylab.plot( psdTab[i].vector, label= 'PSD' + str(i) ) pylab.legend() pylab.figure() for i in range( len( headTab ) ): pylab.plot( headTab[i].vector, label= 'head' + str(i) ) pylab.legend() pylab.figure() for i in range( len( dendTab ) ): pylab.plot( dendTab[i].vector, label= 'dendCa' + str(i) ) pylab.legend() pylab.figure() for i in range( len( eTab ) ): pylab.plot( eTab[i].vector, label= 'headVm' + str(i) ) #print i, len( eTab[i].vector ), eTab[i].vector pylab.legend() pylab.show() app = QtGui.QApplication(sys.argv) #widget = mv.MoogliViewer( '/model' ) morphology = moogli.read_morphology_from_moose( name="", path = '/model/elec' ) widget = moogli.MorphologyViewerWidget( morphology ) widget.show() return app.exec_() quit()
def testSlice(self): em = moose.vec('/testSlice', n=10, g=1, dtype='Neutral') sl = em[5:8] for ii, el in enumerate(sl): self.assertEqual(el.path, '/testSlice[%d]' % (5 + ii))
def testCreate(self): em = moose.vec('/test', 10, 0, 'Neutral') self.assertEqual(em.path, '/test')
def scanDistDtGrid(): numComptsSpine = 30 blank1 = 20 blank2 = 50 comptLength = 1 #startPos = (numComptsSpine+blank1+blank2)*comptLength seqList, seqScore = makeSequence( numSpine ) pos = findSpineHead() #moose.setClock(18, 0.02 ) #print "DT = ", moose.element( '/model/graphs/plot0').dt # seqDtRange = ( 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0 ) # Interval between stimuli, in sec # drange = ( 5, 10, 15, 20, 25, 30 ) # Distance covered, in diffLen. seqDtRange = ( 1.0,2.0,3.0,4.0) drange = ( 5,10,15,20) if displayMoogli: seqDtRange = ( moogliDt, ) drange = ( moogliDistance, ) allSimOutput = [] ampl = moose.vec( '/model/chem/dend/ampl' ) # print("ampl: ", len(ampl)) ampl.nInit = params['stimAmplitude'] blanks = params['blankVoxelsAtEnd'] preStim = params['preStimTime'] postStim = params['postStimTime'] diffusionLength = params['diffusionLength'] for seqDt in seqDtRange: temp2 = [] temp3 = [] for d in drange: phase = moose.vec( '/model/chem/dend/phase' ) ampl = moose.vec( '/model/chem/dend/ampl' ) # Old version. Assumes we activate density * d compartments. #ampl.nInit = float(v)/float(d) ampl.nInit = params['stimAmplitude'] Z = moose.vec( '/model/chem/dend/Z' ) print("Z: ", len(Z)) stride = int(d) / numSpine Z.nInit = 0 phase.nInit = 10000.0 temp = [] slopes = [] #pos = range(startPos+1,len(Z),2) for seq in seqList: print '.', sys.stdout.flush() f = 1 print 'position for input are', pos for j in range( numSpine ): # k = blanks + j * stride + np.random.randint(0,20) # k = np.random.randint(0,blanks + j * stride) print("j * stride: ", j*stride) #k = blanks + j * stride k = pos[j*stride] print("k: ", k) f = f + 1 Z[ k ].nInit = 1 print 'volume of input voxel is', Z[k].volume print 'volume of neck is ', Z[k-1].volume print 'volume of neck is ', Z[k+1].volume # Z[ k ].nInit = 0.1 * j phase[ k ].nInit = preStim + seq[j] * seqDt temp.append( runTrial( diffusionLength, seqDt, d, blanks, preStim, postStim, pos)) #print temp simOut = np.array( temp ) temp3.append( simOut ) print seqDt, d #temp[-1], temp[-2], allSimOutput.append( temp3 ) print("Z vector: ", [ i.vec for i in Z] ) return allSimOutput, seqDtRange, drange
def testIdObjId(self): vec = moose.vec(self.a) self.assertEqual(vec, self.a.vec)
def testCreateKW(self): em = moose.vec(path='/testCreateKW', n=10, g=1, dtype='Neutral') self.assertEqual(em.path, '/testCreateKW')
def updateDisplay( plotlist ): a = moose.vec( '/model/chem/compt0/a' ) b = moose.vec( '/model/chem/compt0/b' ) plotlist[2].set_ydata( a.conc * 10 + plotlist[4] ) plotlist[1].canvas.draw()
def makeNeuroMeshModel(): diffLength = 10e-6 # Aim for 2 soma compartments. elec = loadElec() loadChem(diffLength) neuroCompt = moose.element('/model/chem/dend') neuroCompt.diffLength = diffLength neuroCompt.cellPortion(elec, '/model/elec/#') for x in moose.wildcardFind('/model/chem/##[ISA=PoolBase]'): if (x.diffConst > 0): x.diffConst = 1e-11 for x in moose.wildcardFind('/model/chem/##/Ca'): x.diffConst = 1e-10 # Put in dend solvers ns = neuroCompt.numSegments ndc = neuroCompt.numDiffCompts print 'ns = ', ns, ', ndc = ', ndc assert (neuroCompt.numDiffCompts == neuroCompt.mesh.num) assert (ns == 36) # assert (ndc == 278) # nmksolve = moose.Ksolve('/model/chem/dend/ksolve') nmdsolve = moose.Dsolve('/model/chem/dend/dsolve') nmstoich = moose.Stoich('/model/chem/dend/stoich') nmstoich.compartment = neuroCompt nmstoich.ksolve = nmksolve nmstoich.dsolve = nmdsolve nmstoich.path = "/model/chem/dend/##" print 'done setting path, numPools = ', nmdsolve.numPools assert (nmdsolve.numPools == 1) assert (nmdsolve.numAllVoxels == ndc) assert (nmstoich.numAllPools == 1) # oddly, numLocalFields does not work. ca = moose.element('/model/chem/dend/DEND/Ca') assert (ca.numData == ndc) # Put in spine solvers. Note that these get info from the neuroCompt spineCompt = moose.element('/model/chem/spine') sdc = spineCompt.mesh.num print 'sdc = ', sdc assert (sdc == 13) smksolve = moose.Ksolve('/model/chem/spine/ksolve') smdsolve = moose.Dsolve('/model/chem/spine/dsolve') smstoich = moose.Stoich('/model/chem/spine/stoich') smstoich.compartment = spineCompt smstoich.ksolve = smksolve smstoich.dsolve = smdsolve smstoich.path = "/model/chem/spine/##" print 'spine num Pools = ', smstoich.numAllPools, 'dsolve n = ', smdsolve.numPools assert (smstoich.numAllPools == 36) assert (smdsolve.numPools == 31) assert (smdsolve.numAllVoxels == sdc) # Put in PSD solvers. Note that these get info from the neuroCompt psdCompt = moose.element('/model/chem/psd') pdc = psdCompt.mesh.num assert (pdc == 13) pmksolve = moose.Ksolve('/model/chem/psd/ksolve') pmdsolve = moose.Dsolve('/model/chem/psd/dsolve') pmstoich = moose.Stoich('/model/chem/psd/stoich') pmstoich.compartment = psdCompt pmstoich.ksolve = pmksolve pmstoich.dsolve = pmdsolve pmstoich.path = "/model/chem/psd/##" print 'psd num Pools = ', pmstoich.numAllPools assert (pmstoich.numAllPools == 56) assert (pmdsolve.numPools == 49) assert (pmdsolve.numAllVoxels == pdc) foo = moose.element('/model/chem/psd/Ca') print 'PSD: numfoo = ', foo.numData print 'PSD: numAllVoxels = ', pmksolve.numAllVoxels # Put in junctions between the diffusion solvers nmdsolve.buildNeuroMeshJunctions(smdsolve, pmdsolve) # Put in cross-compartment reactions between ksolvers nmstoich.buildXreacs(smstoich) smstoich.buildXreacs(pmstoich) """ CaNpsd = moose.vec( '/model/chem/psdMesh/PSD/PP1_PSD/CaN' ) print 'numCaN in PSD = ', CaNpsd.nInit, ', vol = ', CaNpsd.volume CaNspine = moose.vec( '/model/chem/spine/SPINE/CaN_BULK/CaN' ) print 'numCaN in spine = ', CaNspine.nInit, ', vol = ', CaNspine.volume """ ################################################################## # set up adaptors aCa = moose.Adaptor('/model/chem/spine/adaptCa', sdc) adaptCa = moose.vec('/model/chem/spine/adaptCa') chemCa = moose.vec('/model/chem/spine/Ca') #print 'aCa = ', aCa, ' foo = ', foo, "len( ChemCa ) = ", len( chemCa ), ", numData = ", chemCa.numData, "len( adaptCa ) = ", len( adaptCa ) assert (len(adaptCa) == sdc) assert (len(chemCa) == sdc) for i in range(sdc): elecCa = moose.element('/model/elec/spine_head_14_' + str(i + 1) + '/NMDA_Ca_conc') #print elecCa moose.connect(elecCa, 'concOut', adaptCa[i], 'input', 'Single') moose.connect(adaptCa, 'output', chemCa, 'setConc', 'OneToOne') adaptCa.inputOffset = 0.0 # adaptCa.outputOffset = 0.00008 # 80 nM offset in chem. adaptCa.scale = 5e-3 # 520 to 0.0052 mM #print adaptCa.outputOffset moose.le('/model/chem/dend/DEND') compts = neuroCompt.elecComptList begin = neuroCompt.startVoxelInCompt end = neuroCompt.endVoxelInCompt aCa = moose.Adaptor('/model/chem/dend/DEND/adaptCa', len(compts)) adaptCa = moose.vec('/model/chem/dend/DEND/adaptCa') chemCa = moose.vec('/model/chem/dend/DEND/Ca') #print 'aCa = ', aCa, ' foo = ', foo, "len( ChemCa ) = ", len( chemCa ), ", numData = ", chemCa.numData, "len( adaptCa ) = ", len( adaptCa ) assert (len(chemCa) == ndc) for i in zip(compts, adaptCa, begin, end): name = i[0].path + '/Ca_conc' if (moose.exists(name)): elecCa = moose.element(name) #print i[2], i[3], ' ', elecCa #print i[1] moose.connect(elecCa, 'concOut', i[1], 'input', 'Single') for j in range(i[2], i[3]): moose.connect(i[1], 'output', chemCa[j], 'setConc', 'Single') adaptCa.inputOffset = 0.0 # adaptCa.outputOffset = 0.00008 # 80 nM offset in chem. adaptCa.scale = 20e-6 # 10 arb units to 2 uM.