def getComptParent(obj): k = moose.element(obj) while not k.isA["CompartmentBase"]: if k == moose.element("/"): return k.path k = moose.element(k.parent) return k.path
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') dendrite = moose.element("/model/elec/dend") dendrites = [dendrite.path + "/" + str(i) for i in range(len(dendZ))] moose.reinit() spineHeads = moose.wildcardFind('/model/elec/#head#') if doMoo: app = QtGui.QApplication(sys.argv) viewer = create_viewer("/model/elec", dendrite, dendZ, diaTab, psdZ) viewer.showMaximized() viewer.start() return app.exec_()
def interlude2(view): val = [moose.getField(i, view.mooField, "double") * view.mooScale for i in view.mooObj] view.mooGroup.set("color", val, view.mapper) view.yaw(rotation) if moose.element("/clock").currentTime >= runtime: view.stop()
def makeChemProto(name): chem = moose.Neutral('/library/' + name) comptVol = diffLen * dendDia * dendDia * PI / 4.0 for i in (['dend', comptVol], ['spine', 1e-19], ['psd', 1e-20]): print(('making ', i)) compt = moose.CubeMesh(chem.path + '/' + i[0]) compt.volume = i[1] z = moose.Pool(compt.path + '/z') z.concInit = 0.0 z.diffConst = diffConst nInit = comptVol * 6e23 * concInit nstr = str(1 / nInit) x = moose.Pool(chem.path + '/dend/x') x.diffConst = diffConst func = moose.Function(x.path + '/func') func.expr = "-x0 * (0.3 - " + nstr + " * x0) * ( 1 - " + nstr + " * x0)" print((func.expr)) func.x.num = 1 moose.connect(x, 'nOut', func.x[0], 'input') moose.connect(func, 'valueOut', x, 'increment') z = moose.element('/library/' + name + '/dend/z') reac = moose.Reac('/library/' + name + '/dend/reac') reac.Kf = 1 reac.Kb = 10 moose.connect(reac, 'sub', x, 'reac') moose.connect(reac, 'prd', z, 'reac')
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() if doMoo: app = QtGui.QApplication(sys.argv) morphology = moogli.read_morphology_from_moose(name="", path='/model/elec') widget = moogli.MorphologyViewerWidget(morphology) widget.show() return app.exec_() quit()
def interlude(view): moose.start(moogliDt) val = [moose.getField(i, view.mooField, "double") * view.mooScale for i in view.mooObj] # print "LEN = ", len( val ), "field = ", view.mooField view.mooGroup.set("color", val, view.mapper) view.yaw(rotation) # print moogliDt, len( val ), runtime if moose.element("/clock").currentTime >= runtime: view.stop()
def interlude(view): moose.start(frameruntime) network.groups["spine"].groups["head"].set("radius", readValues(diaTab), lambda x: x * 0.5e6) network.groups["spine"].groups["head"].set("color", readValues(psdZ), mapper) chem_compt_group.set("color", readValues(dendZ), mapper) if moose.element("/clock").currentTime >= runtime: view.stop()
def makeMoogli(rd, mooObj, moogliEntry, fieldInfo): mooField = moogliEntry[3] numMoogli = len(mooObj) network = moogli.extensions.moose.read(path=rd.elecid.path, vertices=15) # print len( network.groups["spine"].shapes ) # print len( network.groups["dendrite"].shapes ) # print len( network.groups["soma"].shapes ) # soma = network.groups["soma"].shapes[ '/model/elec/soma'] # print network.groups["soma"].shapes soma = network.groups["soma"].shapes[rd.elecid.path + "/soma[0]"] if mooField == "n" or mooField == "conc": updateGroup = soma.subdivide(numMoogli) displayObj = mooObj else: shell = moose.element("/") displayObj = [i for i in mooObj if i != shell] cpa = [getComptParent(i) for i in displayObj] updateGroup = moogli.Group("update") updateShapes = [network.shapes[i] for i in cpa] # print "########### Len( cpa, mooObj ) = ", len( cpa ), len( mooObj ), len( updateShapes ) updateGroup.attach_shapes(updateShapes) normalizer = moogli.utilities.normalizer(moogliEntry[5], moogliEntry[6], clipleft=True, clipright=True) colormap = moogli.colors.MatplotlibColorMap(matplotlib.cm.rainbow) mapper = moogli.utilities.mapper(colormap, normalizer) viewer = moogli.Viewer("Viewer") if mooField == "n" or mooField == "conc": viewer.attach_shapes(updateGroup.shapes.values()) viewer.detach_shape(soma) else: viewer.attach_shapes(network.shapes.values()) if len(rd.moogNames) == 0: view = moogli.View("main-view", prelude=prelude, interlude=interlude, postlude=postlude) else: view = moogli.View("main-view", prelude=prelude, interlude=interlude2) cb = moogli.widgets.ColorBar( id="cb", title=fieldInfo[3], text_color=moogli.colors.BLACK, position=moogli.geometry.Vec3f(0.975, 0.5, 0.0), size=moogli.geometry.Vec3f(0.30, 0.05, 0.0), text_font="/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf", orientation=math.pi / 2.0, text_character_size=20, label_formatting_precision=0, colormap=moogli.colors.MatplotlibColorMap(matplotlib.cm.rainbow), color_resolution=100, scalar_range=moogli.geometry.Vec2f(moogliEntry[5], moogliEntry[6]), ) view.attach_color_bar(cb) view.rd = rd view.mooObj = displayObj view.mooGroup = updateGroup view.mooField = mooField view.mooScale = fieldInfo[2] view.mapper = mapper viewer.attach_view(view) return viewer