def create_rm_visualizer(): # Moogli requires a morphology object. Create a morphology object # by reading the geometry details from all objects of type CompartmentBase # inside /cells[0] morphology = moogli.read_morphology_from_moose(name = "", path = "/cells[0]") # Create a named group of compartments called 'group-all' # which will contain all the compartments of the model. # Each group has a strict upper and lower limit for the # variable which is being visualized. # Both limits map to colors provided to the api. # The value of the variable is linearly mapped to a color value # lying between the upper and lower color values. morphology.create_group( "group-all" # group name , ALL_COMPARTMENTS # sequence of compartments belonging to this group , BASE_RM_VALUE # base value of variable , PEAK_RM_VALUE # peak value of variable , BASE_RM_COLOR # color corresponding to base value , PEAK_RM_COLOR # color corresponding to peak value ) # set initial color of all compartments in accordance with their rm morphology.set_color( "group-all" , [moose.element(x).Rm for x in ALL_COMPARTMENTS] ) # instantiate the visualizer with the morphology object created earlier rm_viewer = moogli.MorphologyViewerWidget(morphology) # make sure that entire model is visible rm_viewer.pitch(math.pi / 2) rm_viewer.zoom(0.25) rm_viewer.setWindowTitle("Rm") return rm_viewer
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 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 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()
import moogli import moose from moose import neuroml from PyQt4 import Qt, QtCore, QtGui import sys import os app = QtGui.QApplication(sys.argv) filename = os.path.join( os.path.split(os.path.realpath(__file__))[0], "../neuroml/PurkinjeCellPassivePulseInput/PurkinjePassive.net.xml") moose.neuroml.loadNeuroML_L123(filename) morphology_distal = moogli.read_morphology_from_moose(name="", path="/cells[0]", radius=moogli.DISTAL) viewer_distal = moogli.MorphologyViewerWidget(morphology_distal) viewer_distal.setWindowTitle("Distal Radius") morphology_averaged = moogli.read_morphology_from_moose(name="", path="/cells[0]", radius=moogli.AVERAGED) viewer_averaged = moogli.MorphologyViewerWidget(morphology_averaged) viewer_averaged.setWindowTitle("Averaged Radius") morphology_proximal_distal = moogli.read_morphology_from_moose( name="", path="/cells[0]", radius=moogli.PROXIMAL_DISTAL) viewer_proximal_distal = moogli.MorphologyViewerWidget( morphology_proximal_distal) viewer_proximal_distal.setWindowTitle("Continous Variation in Radius") viewer_distal.show()