def _loadElec(self, efile, elecname, combineSegments): library = moose.Neutral('/library') if (efile[len(efile) - 2:] == ".p"): self.elecid = moose.loadModel(efile, self.model.path + '/' + elecname) else: nm = NeuroML() nm.readNeuroMLFromFile( efile, \ params = {'combineSegments': combineSegments, \ 'createPotentialSynapses': True } ) if moose.exists('/cells'): kids = moose.wildcardFind('/cells/#') else: kids = moose.wildcardFind( '/library/#[ISA=Neuron],/library/#[TYPE=Neutral]') if (kids[0].name == 'spine'): kids = kids[1:] assert (len(kids) > 0) self.elecid = kids[0] temp = moose.wildcardFind(self.elecid.path + '/#[ISA=CompartmentBase]') moose.move(self.elecid, self.model) self.elecid.name = elecname self._transformNMDAR(self.elecid.path) kids = moose.wildcardFind('/library/##[0]') for i in kids: i.tick = -1
def _loadElec( self, efile, elecname, combineSegments ): library = moose.Neutral( '/library' ) if ( efile[ len( efile ) - 2:] == ".p" ): self.elecid = moose.loadModel( efile, self.model.path + '/' + elecname )[0] elif ( efile[ len( efile ) - 4:] == ".swc" ): self.elecid = moose.loadModel( efile, self.model.path + '/' + elecname )[0] else: nm = NeuroML() nm.readNeuroMLFromFile( efile, \ params = {'combineSegments': combineSegments, \ 'createPotentialSynapses': True } ) if moose.exists( '/cells' ): kids = moose.wildcardFind( '/cells/#' ) else: kids = moose.wildcardFind( '/library/#[ISA=Neuron],/library/#[TYPE=Neutral]' ) if ( kids[0].name == 'spine' ): kids = kids[1:] assert( len( kids ) > 0 ) self.elecid = kids[0] temp = moose.wildcardFind( self.elecid.path + '/#[ISA=CompartmentBase]' ) moose.move( self.elecid, self.model ) self.elecid.name = elecname self._transformNMDAR( self.elecid.path ) kids = moose.wildcardFind( '/library/##[0]' ) for i in kids: i.tick = -1
def updateDisplay(): makeCylModel() moose.element('/model/elec/').name = 'Cyl' moose.element('/model').name = 'model1' makeYmodel() moose.element('/model/elec/').name = 'Y' moose.move('/model1/Cyl', '/model') #moose.le( '/model/Y' ) #print "################################################" #moose.le( '/model/Cyl' ) vecYdend = moose.wildcardFind('/model/Y/soma,/model/Y/dend#') vecYbranch1 = moose.wildcardFind('/model/Y/branch1#') vecYbranch2 = moose.wildcardFind('/model/Y/branch2#') vecCyl = moose.wildcardFind('/model/Cyl/#[ISA=CompartmentBase]') #vec[0].inject = 1e-10 moose.reinit() dt = interval1 for i in lines: moose.start(dt) #print( len(vecCyl), len(vecYdend), len(vecYbranch1), len(vecYbranch2) ) i.CylLines.set_ydata([v.Vm * 1000 for v in vecCyl]) i.YdendLines.set_ydata([v.Vm * 1000 for v in vecYdend]) i.Ybranch1Lines.set_ydata([v.Vm * 1000 for v in vecYbranch1]) #i.Ybranch2Lines.set_ydata( [v.Vm*1000 for v in vecYbranch2] ) dt = interval2 moose.delete('/model') moose.delete('/model1') moose.delete('/library')
def installCellFromProtos( self ): if self.stealCellFromLibrary: moose.move( self.elecid, self.model ) if self.elecid.name != 'elec': self.elecid.name = 'elec' else: moose.copy( self.elecid, self.model, 'elec' ) self.elecid = moose.element( self.model.path + '/elec' ) self.elecid.buildSegmentTree() # rebuild: copy has happened. if hasattr( self, 'chemid' ): self.validateChem() if self.stealCellFromLibrary: moose.move( self.chemid, self.model ) if self.chemid.name != 'chem': self.chemid.name = 'chem' else: moose.copy( self.chemid, self.model, 'chem' ) self.chemid = moose.element( self.model.path + '/chem' ) ep = self.elecid.path somaList = moose.wildcardFind( ep + '/#oma#[ISA=CompartmentBase]' ) if len( somaList ) == 0: somaList = moose.wildcardFind( ep + '/#[ISA=CompartmentBase]' ) if len( somaList ) == 0: raise BuildError( "installCellFromProto: No soma found" ) maxdia = 0.0 for i in somaList: if ( i.diameter > maxdia ): self.soma = i
def setupEnzymaticReaction(enz, groupName, enzName, specInfoMap, modelAnnotaInfo): enzPool = (modelAnnotaInfo[groupName]["enzyme"]) enzPool = str(idBeginWith(enzPool)) enzParent = specInfoMap[enzPool]["Mpath"] cplx = (modelAnnotaInfo[groupName]["complex"]) cplx = str(idBeginWith(cplx)) complx = moose.element(specInfoMap[cplx]["Mpath"].path) enzyme_ = moose.Enz(enzParent.path + '/' + enzName) moose.move(complx, enzyme_) moose.connect(enzyme_, "cplx", complx, "reac") moose.connect(enzyme_, "enz", enzParent, "reac") sublist = (modelAnnotaInfo[groupName]["substrate"]) prdlist = (modelAnnotaInfo[groupName]["product"]) for si in range(0, len(sublist)): sl = sublist[si] sl = str(idBeginWith(sl)) mSId = specInfoMap[sl]["Mpath"] moose.connect(enzyme_, "sub", mSId, "reac") for pi in range(0, len(prdlist)): pl = prdlist[pi] pl = str(idBeginWith(pl)) mPId = specInfoMap[pl]["Mpath"] moose.connect(enzyme_, "prd", mPId, "reac") if (enz.isSetNotes): pullnotes(enz, enzyme_) return enzyme_, True
def _addSpine(self, parent, spineProto, pos, angle, x, y, z, size, k): spine = moose.copy(spineProto, parent.parent, 'spine' + str(k)) kids = spine[0].children coords = [] ppos = np.array([parent.x0, parent.y0, parent.z0]) for i in kids: #print i.name, k j = i[0] j.name += str(k) #print 'j = ', j coords.append([j.x0, j.y0, j.z0]) coords.append([j.x, j.y, j.z]) self._scaleSpineCompt(j, size) moose.move(i, self.elecid) origin = coords[0] #print 'coords = ', coords # Offset it so shaft starts from surface of parent cylinder origin[0] -= parent.diameter / 2.0 coords = np.array(coords) coords -= origin # place spine shaft base at origin. rot = np.array([x, [0, 0, 0], [0, 0, 0]]) coords = np.dot(coords, rot) moose.delete(spine) moose.connect(parent, "raxial", kids[0], "axial") self._reorientSpine(kids, coords, ppos, pos, size, angle, x, y, z)
def installCellFromProtos(self): if self.stealCellFromLibrary: moose.move(self.elecid, self.model) if self.elecid.name != 'elec': self.elecid.name = 'elec' else: moose.copy(self.elecid, self.model, 'elec') self.elecid = moose.element(self.model.path + '/elec') self.elecid.buildSegmentTree() # rebuild: copy has happened. if hasattr(self, 'chemid'): self.validateChem() if self.stealCellFromLibrary: moose.move(self.chemid, self.model) if self.chemid.name != 'chem': self.chemid.name = 'chem' else: moose.copy(self.chemid, self.model, 'chem') self.chemid = moose.element(self.model.path + '/chem') ep = self.elecid.path somaList = moose.wildcardFind(ep + '/#oma#[ISA=CompartmentBase]') if len(somaList) == 0: somaList = moose.wildcardFind(ep + '/#[ISA=CompartmentBase]') if len(somaList) == 0: raise BuildError("installCellFromProto: No soma found") maxdia = 0.0 for i in somaList: if (i.diameter > maxdia): self.soma = i
def _addSpine( self, parent, spineProto, pos, angle, x, y, z, size, k ): spine = moose.copy( spineProto, parent.parent, 'spine' + str(k) ) kids = spine[0].children coords = [] ppos = np.array( [parent.x0, parent.y0, parent.z0] ) for i in kids: #print i.name, k j = i[0] j.name += str(k) #print 'j = ', j coords.append( [j.x0, j.y0, j.z0] ) coords.append( [j.x, j.y, j.z] ) self._scaleSpineCompt( j, size ) moose.move( i, self.elecid ) origin = coords[0] #print 'coords = ', coords # Offset it so shaft starts from surface of parent cylinder origin[0] -= parent.diameter / 2.0 coords = np.array( coords ) coords -= origin # place spine shaft base at origin. rot = np.array( [x, [0,0,0], [0,0,0]] ) coords = np.dot( coords, rot ) moose.delete( spine ) moose.connect( parent, "raxial", kids[0], "axial" ) self._reorientSpine( kids, coords, ppos, pos, size, angle, x, y, z )
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 buildFromMemory(self, ePath, cPath, doCopy=False): if not self.validateFromMemory(ePath, cPath): return if doCopy: x = moose.copy(cPath, self.model) self.chemid = moose.element(x) self.chemid.name = 'chem' x = moose.copy(ePath, self.model) self.elecid = moose.element(x) self.elecid.name = 'elec' else: self.elecid = moose.element(ePath) self.chemid = moose.element(cPath) if self.elecid.path != self.model.path + '/elec': if (self.elecid.parent != self.model): moose.move(self.elecid, self.model) self.elecid.name = 'elec' if self.chemid.path != self.model.path + '/chem': if (self.chemid.parent != self.model): moose.move(self.chemid, self.model) self.chemid.name = 'chem' ep = self.elecid.path somaList = moose.wildcardFind(ep + '/#oma#[ISA=CompartmentBase]') if len(somaList) == 0: somaList = moose.wildcardFind(ep + '/#[ISA=CompartmentBase]') assert (len(somaList) > 0) maxdia = 0.0 for i in somaList: if (i.diameter > maxdia): self.soma = i #self.soma = self.comptList[0] self._decorateWithSpines() self.spineList = moose.wildcardFind(ep + '/#spine#[ISA=CompartmentBase],' + ep + '/#head#[ISA=CompartmentBase]') if len(self.spineList) == 0: self.spineList = moose.wildcardFind(ep + '/#head#[ISA=CompartmentBase]') nmdarList = moose.wildcardFind(ep + '/##[ISA=NMDAChan]') self.comptList = moose.wildcardFind(ep + '/#[ISA=CompartmentBase]') print("Rdesigneur: Elec model has ", len(self.comptList), " compartments and ", len(self.spineList), " spines with ", len(nmdarList), " NMDARs") self._buildNeuroMesh() self._configureSolvers() for i in self.adaptorList: print(i) self._buildAdaptor(i[0], i[1], i[2], i[3], i[4], i[5], i[6])
def makeCubeMultiscale(): makeSpinyCompt() model = moose.Neutral('/model') elec = moose.element('/n') elec.name = 'elec' moose.move(elec, model) synInput = moose.element('/model/elec/compt/synInput') synInput.refractT = 47e-3 makeChemInCubeMesh() # set up a reaction to fake diffusion between compts. headCa = moose.element('/model/chem/spineMesh/Ca') dendCa = moose.element('/model/chem/neuroMesh/Ca') diffReac = moose.Reac('/model/chem/spineMesh/diff') moose.connect(diffReac, 'sub', headCa, 'reac') moose.connect(diffReac, 'prd', dendCa, 'reac') diffReac.Kf = 1 diffReac.Kb = headCa.volume / dendCa.volume # set up adaptors headCa = moose.element('/model/chem/spineMesh/Ca') dendCa = moose.element('/model/chem/neuroMesh/Ca') adaptCa = moose.Adaptor('/model/chem/adaptCa') elecCa = moose.element('/model/elec/head2/ca') # There are 5 spine heads in the electrical model. Average their input. for i in range(5): path = '/model/elec/head' + str(i) + '/ca' elecCa = moose.element(path) moose.connect(elecCa, 'concOut', adaptCa, 'input', 'Single') moose.connect(adaptCa, 'output', headCa, 'setConc') adaptCa.outputOffset = 0.0001 # 100 nM offset in chem. adaptCa.scale = 0.05 # 0.06 to 0.003 mM adaptGluR = moose.Adaptor('/model/chem/psdMesh/adaptGluR') chemR = moose.element('/model/chem/psdMesh/psdGluR') # Here we connect up the chem adaptors to only 3 of the spine # heads in the elec model, just to make it interesting. elec1R = moose.element('/model/elec/head1/gluR') elec2R = moose.element('/model/elec/head2/gluR') elec3R = moose.element('/model/elec/head3/gluR') moose.connect(adaptGluR, 'requestOut', chemR, 'getN', 'OneToAll') moose.connect(adaptGluR, 'output', elec1R, 'setGbar', 'OneToAll') moose.connect(adaptGluR, 'output', elec2R, 'setGbar', 'OneToAll') moose.connect(adaptGluR, 'output', elec3R, 'setGbar', 'OneToAll') adaptGluR.outputOffset = 1e-9 # pS adaptGluR.scale = 1e-8 / 100 # from n to pS adaptK = moose.Adaptor('/model/chem/neuroMesh/adaptK') chemK = moose.element('/model/chem/neuroMesh/kChan') elecK = moose.element('/model/elec/compt/K') moose.connect(adaptK, 'requestOut', chemK, 'getConc', 'OneToAll') moose.connect(adaptK, 'output', elecK, 'setGbar', 'OneToAll') adaptK.scale = 0.3 # from mM to Siemens
def buildFromMemory( self, ePath, cPath, doCopy = False ): if not self.validateFromMemory( ePath, cPath ): return if doCopy: x = moose.copy( cPath, self.model ) self.chemid = moose.element( x ) self.chemid.name = 'chem' x = moose.copy( ePath, self.model ) self.elecid = moose.element( x ) self.elecid.name = 'elec' else: self.elecid = moose.element( ePath ) self.chemid = moose.element( cPath ) if self.elecid.path != self.model.path + '/elec': if ( self.elecid.parent != self.model ): moose.move( self.elecid, self.model ) self.elecid.name = 'elec' if self.chemid.path != self.model.path + '/chem': if ( self.chemid.parent != self.model ): moose.move( self.chemid, self.model ) self.chemid.name = 'chem' ep = self.elecid.path somaList = moose.wildcardFind( ep + '/#oma#[ISA=CompartmentBase]' ) if len( somaList ) == 0: somaList = moose.wildcardFind( ep + '/#[ISA=CompartmentBase]' ) assert( len( somaList ) > 0 ) maxdia = 0.0 for i in somaList: if ( i.diameter > maxdia ): self.soma = i #self.soma = self.comptList[0] self._decorateWithSpines() self.spineList = moose.wildcardFind( ep + '/#spine#[ISA=CompartmentBase],' + ep + '/#head#[ISA=CompartmentBase]' ) if len( self.spineList ) == 0: self.spineList = moose.wildcardFind( ep + '/#head#[ISA=CompartmentBase]' ) nmdarList = moose.wildcardFind( ep + '/##[ISA=NMDAChan]' ) self.comptList = moose.wildcardFind( ep + '/#[ISA=CompartmentBase]') print "Rdesigneur: Elec model has ", len( self.comptList ), \ " compartments and ", len( self.spineList ), \ " spines with ", len( nmdarList ), " NMDARs" self._buildNeuroMesh() self._configureSolvers() for i in self.adaptorList: print i self._buildAdaptor( i[0],i[1],i[2],i[3],i[4],i[5],i[6] )
def makeCubeMultiscale(): makeSpinyCompt() model = moose.Neutral( '/model' ) elec = moose.element( '/n' ) elec.name = 'elec' moose.move( elec, model ) synInput = moose.element( '/model/elec/compt/synInput' ) synInput.refractT = 47e-3 makeChemInCubeMesh() # set up a reaction to fake diffusion between compts. headCa = moose.element( '/model/chem/spineMesh/Ca' ) dendCa = moose.element( '/model/chem/neuroMesh/Ca' ) diffReac = moose.Reac( '/model/chem/spineMesh/diff' ) moose.connect( diffReac, 'sub', headCa, 'reac' ) moose.connect( diffReac, 'prd', dendCa, 'reac' ) diffReac.Kf = 1 diffReac.Kb = headCa.volume / dendCa.volume # set up adaptors headCa = moose.element( '/model/chem/spineMesh/Ca' ) dendCa = moose.element( '/model/chem/neuroMesh/Ca' ) adaptCa = moose.Adaptor( '/model/chem/adaptCa' ) elecCa = moose.element( '/model/elec/head2/ca' ) # There are 5 spine heads in the electrical model. Average their input. for i in range( 5 ): path = '/model/elec/head' + str( i ) + '/ca' elecCa = moose.element( path ) moose.connect( elecCa, 'concOut', adaptCa, 'input', 'Single' ) moose.connect( adaptCa, 'output', headCa, 'setConc' ) adaptCa.outputOffset = 0.0001 # 100 nM offset in chem. adaptCa.scale = 0.05 # 0.06 to 0.003 mM adaptGluR = moose.Adaptor( '/model/chem/psdMesh/adaptGluR' ) chemR = moose.element( '/model/chem/psdMesh/psdGluR' ) # Here we connect up the chem adaptors to only 3 of the spine # heads in the elec model, just to make it interesting. elec1R = moose.element( '/model/elec/head1/gluR' ) elec2R = moose.element( '/model/elec/head2/gluR' ) elec3R = moose.element( '/model/elec/head3/gluR' ) moose.connect( adaptGluR, 'requestOut', chemR, 'getN', 'OneToAll' ) moose.connect( adaptGluR, 'output', elec1R, 'setGbar', 'OneToAll' ) moose.connect( adaptGluR, 'output', elec2R, 'setGbar', 'OneToAll' ) moose.connect( adaptGluR, 'output', elec3R, 'setGbar', 'OneToAll' ) adaptGluR.outputOffset = 1e-9 # pS adaptGluR.scale = 1e-8 / 100 # from n to pS adaptK = moose.Adaptor( '/model/chem/neuroMesh/adaptK' ) chemK = moose.element( '/model/chem/neuroMesh/kChan' ) elecK = moose.element( '/model/elec/compt/K' ) moose.connect( adaptK, 'requestOut', chemK, 'getConc', 'OneToAll' ) moose.connect( adaptK, 'output', elecK, 'setGbar', 'OneToAll' ) adaptK.scale = 0.3 # from mM to Siemens
def loadGenCsp(target, filename, solver="gsl"): target = target.replace(" ", "") path = '/' + target #Moving the model under /modelname/model and graphs under /model/graphs. #This is passed while loading-time which will be easy for setting the stoich path mpath = '/' + target + '/' + "model" if moose.exists(mpath): moose.delete(mpath) modelpath1 = moose.Neutral('%s' % (target)) modelpath = moose.Neutral('%s/%s' % (modelpath1.path, "model")) model = moose.loadModel(filename, modelpath.path, solver) if not moose.exists(modelpath1.path + '/data'): graphspath = moose.Neutral('%s/%s' % (modelpath1.path, "data")) dataPath = moose.element(modelpath1.path + '/data') i = 0 nGraphs = moose.wildcardFind(modelpath.path + '/graphs/##[TYPE=Table2]') for graphs in nGraphs: if not moose.exists(dataPath.path + '/graph_' + str(i)): graphspath = moose.Neutral('%s/%s' % (dataPath.path, "graph_" + str(i))) else: graphspath = moose.element(dataPath.path + '/graph_' + str(i)) moose.move(graphs.path, graphspath) if len(nGraphs) > 0: i = i + 1 for moregraphs in moose.wildcardFind(modelpath.path + '/moregraphs/##[TYPE=Table2]'): if not moose.exists(dataPath.path + '/graph_' + str(i)): graphspath = moose.Neutral('%s/%s' % (dataPath.path, "graph_" + str(i))) else: graphspath = moose.element(dataPath.path + '/graph_' + str(i)) moose.move(moregraphs.path, graphspath) if moose.exists(modelpath.path + '/info'): AnnotatorOld = moose.element(modelpath.path + '/info') AnnotatorNew = moose.Annotator(modelpath1.path + '/info') AnnotatorNew.runtime = AnnotatorOld.runtime AnnotatorNew.solver = AnnotatorOld.solver moose.delete(AnnotatorOld) moose.delete(modelpath.path + '/graphs') moose.delete(modelpath.path + '/moregraphs') return (modelpath1, modelpath1.path)
def loadGenCsp(target, filename, solver="gsl"): target = target.replace(" ", "") path = "/" + target # Moving the model under /modelname/model and graphs under /model/graphs. # This is passed while loading-time which will be easy for setting the stoich path mpath = "/" + target + "/" + "model" if moose.exists(mpath): moose.delete(mpath) modelpath1 = moose.Neutral("%s" % (target)) modelpath = moose.Neutral("%s/%s" % (modelpath1.path, "model")) model = moose.loadModel(filename, modelpath.path, solver) if not moose.exists(modelpath1.path + "/data"): graphspath = moose.Neutral("%s/%s" % (modelpath1.path, "data")) dataPath = moose.element(modelpath1.path + "/data") i = 0 nGraphs = moose.wildcardFind(modelpath.path + "/graphs/##[TYPE=Table2]") for graphs in nGraphs: if not moose.exists(dataPath.path + "/graph_" + str(i)): graphspath = moose.Neutral("%s/%s" % (dataPath.path, "graph_" + str(i))) else: graphspath = moose.element(dataPath.path + "/graph_" + str(i)) moose.move(graphs.path, graphspath) if len(nGraphs) > 0: i = i + 1 for moregraphs in moose.wildcardFind(modelpath.path + "/moregraphs/##[TYPE=Table2]"): if not moose.exists(dataPath.path + "/graph_" + str(i)): graphspath = moose.Neutral("%s/%s" % (dataPath.path, "graph_" + str(i))) else: graphspath = moose.element(dataPath.path + "/graph_" + str(i)) moose.move(moregraphs.path, graphspath) if moose.exists(modelpath.path + "/info"): AnnotatorOld = moose.element(modelpath.path + "/info") AnnotatorNew = moose.Annotator(modelpath1.path + "/info") AnnotatorNew.runtime = AnnotatorOld.runtime AnnotatorNew.solver = AnnotatorOld.solver moose.delete(AnnotatorOld) moose.delete(modelpath.path + "/graphs") moose.delete(modelpath.path + "/moregraphs") return (modelpath1, modelpath1.path)
def main(): filename = os.path.join( os.path.split(os.path.realpath(__file__))[0] , "../neuroml/CA1/CA1.morph.pop.xml") # filename = os.path.join( os.path.split(os.path.realpath(__file__))[0] # , "../neuroml/PurkinjeCellPassivePulseInput/PurkinjePassive.net.xml") # filename = os.path.join( os.path.split(os.path.realpath(__file__))[0] # , "../neuroml/OlfactoryBulbPassive/OBpassive_numgloms3_seed750.0.xml") popdict, projdict = moose.neuroml.loadNeuroML_L123(filename) modelRoot = moose.Neutral("/" + os.path.splitext(os.path.basename(filename))[0]) element = moose.Neutral(modelRoot.path + "/model") if(moose.exists("/cells")) : moose.move("/cells" , element.path) if(moose.exists("/elec")) : moose.move("/elec" , modelRoot.path) if(moose.exists("/library")): moose.move("/library", modelRoot.path) show_morphology(modelRoot.path)
def makeNeuroMeshModel(): makeSpinyCompt() diffLength = moose.element("/n/compt").length diffLength = diffLength / 10.0 elec = moose.element("/n") elec.name = "elec" model = moose.Neutral("/model") moose.move(elec, model) synInput = moose.element("/model/elec/compt/synInput") synInput.refractT = 47e-3 chem = moose.Neutral("/model/chem") neuroCompt = moose.NeuroMesh("/model/chem/neuroMesh") neuroCompt.separateSpines = 1 neuroCompt.diffLength = diffLength neuroCompt.geometryPolicy = "cylinder" spineCompt = moose.SpineMesh("/model/chem/spineMesh") moose.connect(neuroCompt, "spineListOut", spineCompt, "spineList", "OneToOne") psdCompt = moose.PsdMesh("/model/chem/psdMesh") moose.connect(neuroCompt, "psdListOut", psdCompt, "psdList", "OneToOne") createChemModel(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 'Assigning the cell model' # Now to set up the model. neuroCompt.cell = elec ns = neuroCompt.numSegments # assert( ns == 11 ) # dend, 5x (shaft+head) ndc = neuroCompt.numDiffCompts assert ndc == 10 ndc = neuroCompt.mesh.num assert ndc == 10 sdc = spineCompt.mesh.num assert sdc == 5 pdc = psdCompt.mesh.num assert pdc == 5 # # 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 # Have to pass a message between the various solvers. foo = moose.vec("/model/chem/spineMesh/headGluR") # oddly, numLocalFields does not work. ca = moose.element("/model/chem/neuroMesh/Ca") assert ca.lastDimension == ndc moose.vec("/model/chem/spineMesh/headGluR").nInit = 100 moose.vec("/model/chem/psdMesh/psdGluR").nInit = 0 # set up adaptors aCa = moose.Adaptor("/model/chem/spineMesh/adaptCa", 5) adaptCa = moose.vec("/model/chem/spineMesh/adaptCa") chemCa = moose.vec("/model/chem/spineMesh/Ca") assert len(adaptCa) == 5 for i in range(5): path = "/model/elec/head" + str(i) + "/ca" elecCa = moose.element(path) moose.connect(elecCa, "concOut", adaptCa[i], "input", "Single") moose.connect(adaptCa, "outputSrc", chemCa, "setConc", "OneToOne") adaptCa.outputOffset = 0.0001 # 100 nM offset in chem. adaptCa.scale = 0.05 # 0.06 to 0.003 mM aGluR = moose.Adaptor("/model/chem/psdMesh/adaptGluR", 5) adaptGluR = moose.vec("/model/chem/psdMesh/adaptGluR") chemR = moose.vec("/model/chem/psdMesh/psdGluR") assert len(adaptGluR) == 5 for i in range(5): path = "/model/elec/head" + str(i) + "/gluR" elecR = moose.element(path) moose.connect(adaptGluR[i], "outputSrc", elecR, "setGbar", "Single") # moose.connect( chemR, 'nOut', adaptGluR, 'input', 'OneToOne' ) # Ksolve isn't sending nOut. Not good. So have to use requestOut. moose.connect(adaptGluR, "requestOut", chemR, "getN", "OneToOne") adaptGluR.outputOffset = 1e-7 # pS adaptGluR.scale = 1e-6 / 100 # from n to pS adaptK = moose.Adaptor("/model/chem/neuroMesh/adaptK") chemK = moose.element("/model/chem/neuroMesh/kChan") elecK = moose.element("/model/elec/compt/K") moose.connect(adaptK, "requestOut", chemK, "getConc", "OneToAll") moose.connect(adaptK, "outputSrc", elecK, "setGbar", "Single") adaptK.scale = 0.3 # from mM to Siemens """
def loadFile(filename, target, solver="gsl", merge=True): """Try to load a model from specified `filename` under the element `target`. if `merge` is True, the contents are just loaded at target. If false, everything is deleted from the parent of target unless the parent is root. Returns ------- a dict containing at least these three entries: modeltype: type of the loaded model. subtype: subtype of the loaded model, None if no specific subtype modelroot: root element of the model, None if could not be located - as is the case with Python scripts """ num = 1 newTarget = target while moose.exists(newTarget): newTarget = target + "-" + str(num) num = num + 1 target = newTarget istext = True with open(filename, 'rb') as infile: istext = mtypes.istextfile(infile) if not istext: print 'Cannot handle any binary formats yet' return None parent, child = posixpath.split(target) p = moose.Neutral(parent) if not merge and p.path != '/': for ch in p.children: moose.delete(ch) try: modeltype = mtypes.getType(filename) subtype = mtypes.getSubtype(filename, modeltype) except KeyError: raise FileLoadError('Do not know how to handle this filetype: %s' % (filename)) pwe = moose.getCwe() #self.statusBar.showMessage('Loading model, please wait') # app = QtGui.qApp # app.setOverrideCursor(QtGui.QCursor(Qt.Qt.BusyCursor)) #shows a hourglass - or a busy/working arrow if modeltype == 'genesis': if subtype == 'kkit' or subtype == 'prototype': model, modelpath = loadGenCsp(target, filename, solver) if moose.exists(moose.element(modelpath).path): moose.Annotator(moose.element(modelpath).path + '/info').modeltype = "kkit" else: print " path doesn't exists" moose.le(modelpath) else: print 'Only kkit and prototype files can be loaded.' elif modeltype == 'cspace': model, modelpath = loadGenCsp(target, filename) if moose.exists(modelpath): moose.Annotator( (moose.element(modelpath).path + '/info')).modeltype = "cspace" addSolver(modelpath, 'gsl') elif modeltype == 'xml': if subtype == 'neuroml': popdict, projdict = neuroml.loadNeuroML_L123(filename) # Circus to get the container of populations from loaded neuroml for popinfo in popdict.values(): for cell in popinfo[1].values(): solver = moose.HSolve(cell.path + "/hsolve") solver.target = cell.path # model = cell.parent # break # break # Moving model to a new location under the model name # model name is the filename without extension model = moose.Neutral("/" + splitext(basename(filename))[0]) element = moose.Neutral(model.path + "/model") if (moose.exists("/cells")): moose.move("/cells", element.path) if (moose.exists("/elec")): moose.move("/elec", model.path) if (moose.exists("/library")): moose.move("/library", model.path) # moose.move("cells/", cell.path) elif subtype == 'sbml': if target != '/': if moose.exists(target): moose.delete(target) model = mooseReadSBML(filename, target) if moose.exists(moose.element(model).path): moose.Annotator(moose.element(model).path + '/info').modeltype = "sbml" addSolver(target, 'gsl') else: raise FileLoadError('Do not know how to handle this filetype: %s' % (filename)) moose.setCwe( pwe ) # The MOOSE loadModel changes the current working element to newly loaded model. We revert that behaviour # TODO: check with Aditya how to specify the target for # neuroml reader # app.restoreOverrideCursor() return {'modeltype': modeltype, 'subtype': subtype, 'model': model}
def makeNeuroMeshModel(): makeSpinyCompt() diffLength = moose.element('/n/compt').length diffLength = diffLength / 10.0 elec = moose.element('/n') elec.name = 'elec' model = moose.Neutral('/model') moose.move(elec, model) synInput = moose.element('/model/elec/compt/synInput') synInput.refractT = 47e-3 chem = moose.Neutral('/model/chem') neuroCompt = moose.NeuroMesh('/model/chem/neuroMesh') neuroCompt.separateSpines = 1 neuroCompt.diffLength = diffLength neuroCompt.geometryPolicy = 'cylinder' spineCompt = moose.SpineMesh('/model/chem/spineMesh') moose.connect(neuroCompt, 'spineListOut', spineCompt, 'spineList', 'OneToOne') psdCompt = moose.PsdMesh('/model/chem/psdMesh') moose.connect(neuroCompt, 'psdListOut', psdCompt, 'psdList', 'OneToOne') createChemModel(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 'Assigning the cell model' # Now to set up the model. neuroCompt.cell = elec ns = neuroCompt.numSegments #assert( ns == 11 ) # dend, 5x (shaft+head) ndc = neuroCompt.numDiffCompts assert (ndc == 10) ndc = neuroCompt.mesh.num assert (ndc == 10) sdc = spineCompt.mesh.num assert (sdc == 5) pdc = psdCompt.mesh.num assert (pdc == 5) # # 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 # Have to pass a message between the various solvers. foo = moose.vec('/model/chem/spineMesh/headGluR') # oddly, numLocalFields does not work. ca = moose.element('/model/chem/neuroMesh/Ca') assert (ca.lastDimension == ndc) moose.vec('/model/chem/spineMesh/headGluR').nInit = 100 moose.vec('/model/chem/psdMesh/psdGluR').nInit = 0 # set up adaptors aCa = moose.Adaptor('/model/chem/spineMesh/adaptCa', 5) adaptCa = moose.vec('/model/chem/spineMesh/adaptCa') chemCa = moose.vec('/model/chem/spineMesh/Ca') assert (len(adaptCa) == 5) for i in range(5): path = '/model/elec/head' + str(i) + '/ca' elecCa = moose.element(path) moose.connect(elecCa, 'concOut', adaptCa[i], 'input', 'Single') moose.connect(adaptCa, 'outputSrc', chemCa, 'setConc', 'OneToOne') adaptCa.outputOffset = 0.0001 # 100 nM offset in chem. adaptCa.scale = 0.05 # 0.06 to 0.003 mM aGluR = moose.Adaptor('/model/chem/psdMesh/adaptGluR', 5) adaptGluR = moose.vec('/model/chem/psdMesh/adaptGluR') chemR = moose.vec('/model/chem/psdMesh/psdGluR') assert (len(adaptGluR) == 5) for i in range(5): path = '/model/elec/head' + str(i) + '/gluR' elecR = moose.element(path) moose.connect(adaptGluR[i], 'outputSrc', elecR, 'setGbar', 'Single') #moose.connect( chemR, 'nOut', adaptGluR, 'input', 'OneToOne' ) # Ksolve isn't sending nOut. Not good. So have to use requestOut. moose.connect(adaptGluR, 'requestOut', chemR, 'getN', 'OneToOne') adaptGluR.outputOffset = 1e-7 # pS adaptGluR.scale = 1e-6 / 100 # from n to pS adaptK = moose.Adaptor('/model/chem/neuroMesh/adaptK') chemK = moose.element('/model/chem/neuroMesh/kChan') elecK = moose.element('/model/elec/compt/K') moose.connect(adaptK, 'requestOut', chemK, 'getConc', 'OneToAll') moose.connect(adaptK, 'outputSrc', elecK, 'setGbar', 'Single') adaptK.scale = 0.3 # from mM to Siemens """
def loadFile(filename, target, solver="gsl", merge=True): """Try to load a model from specified `filename` under the element `target`. if `merge` is True, the contents are just loaded at target. If false, everything is deleted from the parent of target unless the parent is root. Returns ------- a dict containing at least these three entries: modeltype: type of the loaded model. subtype: subtype of the loaded model, None if no specific subtype modelroot: root element of the model, None if could not be located - as is the case with Python scripts """ num = 1 newTarget = target while moose.exists(newTarget): newTarget = target + "-" + str(num) num = num + 1 target = newTarget istext = True with open(filename, "rb") as infile: istext = mtypes.istextfile(infile) if not istext: print("Cannot handle any binary formats yet") return None parent, child = posixpath.split(target) p = moose.Neutral(parent) if not merge and p.path != "/": for ch in p.children: moose.delete(ch) try: modeltype = mtypes.getType(filename) subtype = mtypes.getSubtype(filename, modeltype) except KeyError: raise FileLoadError("Do not know how to handle this filetype: %s" % (filename)) pwe = moose.getCwe() # self.statusBar.showMessage('Loading model, please wait') # app = QtGui.qApp # app.setOverrideCursor(QtGui.QCursor(Qt.Qt.BusyCursor)) #shows a hourglass - or a busy/working arrow if modeltype == "genesis": if subtype == "kkit" or subtype == "prototype": model, modelpath = loadGenCsp(target, filename, solver) if moose.exists(moose.element(modelpath).path): moose.Annotator(moose.element(modelpath).path + "/info").modeltype = "kkit" else: print(" path doesn't exists") moose.le(modelpath) else: print("Only kkit and prototype files can be loaded.") elif modeltype == "cspace": model, modelpath = loadGenCsp(target, filename) if moose.exists(modelpath): moose.Annotator((moose.element(modelpath).path + "/info")).modeltype = "cspace" addSolver(modelpath, "gsl") elif modeltype == "xml": if subtype == "neuroml": popdict, projdict = neuroml.loadNeuroML_L123(filename) # Circus to get the container of populations from loaded neuroml for popinfo in list(popdict.values()): for cell in list(popinfo[1].values()): solver = moose.HSolve(cell.path + "/hsolve") solver.target = cell.path # model = cell.parent # break # break # Moving model to a new location under the model name # model name is the filename without extension model = moose.Neutral("/" + splitext(basename(filename))[0]) element = moose.Neutral(model.path + "/model") if moose.exists("/cells"): moose.move("/cells", element.path) if moose.exists("/elec"): moose.move("/elec", model.path) if moose.exists("/library"): moose.move("/library", model.path) # moose.move("cells/", cell.path) elif subtype == "sbml": if target != "/": if moose.exists(target): moose.delete(target) model = mooseReadSBML(filename, target) if moose.exists(moose.element(model).path): moose.Annotator(moose.element(model).path + "/info").modeltype = "sbml" addSolver(target, "gsl") else: raise FileLoadError("Do not know how to handle this filetype: %s" % (filename)) moose.setCwe( pwe ) # The MOOSE loadModel changes the current working element to newly loaded model. We revert that behaviour # TODO: check with Aditya how to specify the target for # neuroml reader # app.restoreOverrideCursor() return {"modeltype": modeltype, "subtype": subtype, "model": model}
def makeNeuroMeshModel(): diffLength = 10e-6 makeSpinyCompt() elec = moose.element( '/n' ) elec.name = 'elec' model = moose.Neutral( '/model' ) moose.move( elec, model ) synInput = moose.element( '/model/elec/compt/synInput' ) synInput.refractT = 47e-3 chem = moose.Neutral( '/model/chem' ) neuroCompt = moose.NeuroMesh( '/model/chem/neuroMesh' ) neuroCompt.separateSpines = 1 neuroCompt.diffLength = diffLength neuroCompt.geometryPolicy = 'cylinder' spineCompt = moose.SpineMesh( '/model/chem/spineMesh' ) moose.connect( neuroCompt, 'spineListOut', spineCompt, 'spineList', 'OneToOne' ) psdCompt = moose.PsdMesh( '/model/chem/psdMesh' ) moose.connect( neuroCompt, 'psdListOut', psdCompt, 'psdList', 'OneToOne' ) createChemModel( neuroCompt, spineCompt, psdCompt ) # Now to set up the model. neuroCompt.cell = elec ns = neuroCompt.numSegments #assert( ns == 11 ) # dend, 5x (shaft+head) ndc = neuroCompt.numDiffCompts assert( ndc == 10 ) ndc = neuroCompt.mesh.num assert( ndc == 10 ) sdc = spineCompt.mesh.num assert( sdc == 5 ) pdc = psdCompt.mesh.num assert( pdc == 5 ) # oddly, numLocalFields does not work. ca = moose.element( '/model/chem/neuroMesh/Ca' ) assert( ca.lastDimension == ndc ) #print ca #print "ns=", ns, ", ndc = ", ndc, ", sdc = ", sdc, ", pdc = ", pdc #print "nca=", ca.localNumField, ",lastDim = ", ca.lastDimension # set up adaptors adaptCa = moose.Adaptor( '/model/chem/neuroMesh/adaptCa' ) chemCa = moose.element( '/model/chem/neuroMesh/Ca' ) elecCa = moose.element( '/model/elec/head2/ca' ) moose.connect( elecCa, 'concOut', adaptCa, 'input', 'OneToOne' ) moose.connect( adaptCa, 'outputSrc', chemCa, 'set_conc', 'OneToOne' ) adaptCa.outputOffset = 0.0001 # 100 nM offset in chem. adaptCa.scale = 0.05 # 0.06 to 0.003 mM adaptGluR = moose.Adaptor( '/model/chem/psdMesh/adaptGluR' ) chemR = moose.element( '/model/chem/psdMesh/psdGluR' ) elec0R = moose.element( '/model/elec/head0/gluR' ) elec1R = moose.element( '/model/elec/head1/gluR' ) elec2R = moose.element( '/model/elec/head2/gluR' ) elec3R = moose.element( '/model/elec/head3/gluR' ) elec4R = moose.element( '/model/elec/head4/gluR' ) moose.connect( adaptGluR, 'requestField', chemR, 'get_n', 'OneToAll' ) moose.connect( adaptGluR, 'outputSrc', elec0R, 'set_Gbar', 'OneToAll' ) moose.connect( adaptGluR, 'outputSrc', elec1R, 'set_Gbar', 'OneToAll' ) moose.connect( adaptGluR, 'outputSrc', elec2R, 'set_Gbar', 'OneToAll' ) moose.connect( adaptGluR, 'outputSrc', elec3R, 'set_Gbar', 'OneToAll' ) moose.connect( adaptGluR, 'outputSrc', elec4R, 'set_Gbar', 'OneToAll' ) adaptGluR.scale = 1e-6 / 100 # from n to pS """
def _moveCompt( self, a, b ): b.setVolumeNotRates( a.volume ) for i in moose.wildcardFind( a.path + '/#' ): if ( i.name != 'mesh' ): moose.move( i, b ) moose.delete( a )
def _moveCompt(self, a, b): b.setVolumeNotRates(a.volume) for i in moose.wildcardFind(a.path + '/#'): if (i.name != 'mesh'): moose.move(i, b) moose.delete(a)
def makeNeuroMeshModel(): makeSpinyCompt() diffLength = moose.element( '/n/compt' ).length diffLength = diffLength / 10.0 elec = moose.element( '/n' ) elec.name = 'elec' model = moose.Neutral( '/model' ) moose.move( elec, model ) synInput = moose.element( '/model/elec/compt/synInput' ) synInput.refractT = 47e-3 chem = moose.Neutral( '/model/chem' ) neuroCompt = moose.NeuroMesh( '/model/chem/neuroMesh' ) neuroCompt.separateSpines = 1 neuroCompt.diffLength = diffLength neuroCompt.geometryPolicy = 'cylinder' spineCompt = moose.SpineMesh( '/model/chem/spineMesh' ) moose.connect( neuroCompt, 'spineListOut', spineCompt, 'spineList', 'OneToOne' ) psdCompt = moose.PsdMesh( '/model/chem/psdMesh' ) moose.connect( neuroCompt, 'psdListOut', psdCompt, 'psdList', 'OneToOne' ) createChemModel( 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 'Assigning the cell model' # Now to set up the model. neuroCompt.cell = elec ns = neuroCompt.numSegments #assert( ns == 11 ) # dend, 5x (shaft+head) ndc = neuroCompt.numDiffCompts assert( ndc == 10 ) ndc = neuroCompt.mesh.num assert( ndc == 10 ) sdc = spineCompt.mesh.num assert( sdc == 5 ) pdc = psdCompt.mesh.num assert( pdc == 5 ) # # 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 # Have to pass a message between the various solvers. foo = moose.vec( '/model/chem/spineMesh/headGluR' ) # oddly, numLocalFields does not work. ca = moose.element( '/model/chem/neuroMesh/Ca' ) assert( ca.lastDimension == ndc ) moose.vec( '/model/chem/spineMesh/headGluR' ).nInit = 100 moose.vec( '/model/chem/psdMesh/psdGluR' ).nInit = 0 # set up adaptors aCa = moose.Adaptor( '/model/chem/spineMesh/adaptCa', 5 ) adaptCa = moose.vec( '/model/chem/spineMesh/adaptCa' ) chemCa = moose.vec( '/model/chem/spineMesh/Ca' ) assert( len( adaptCa ) == 5 ) for i in range( 5 ): path = '/model/elec/head' + str( i ) + '/ca' elecCa = moose.element( path ) moose.connect( elecCa, 'concOut', adaptCa[i], 'input', 'Single' ) moose.connect( adaptCa, 'outputSrc', chemCa, 'setConc', 'OneToOne' ) adaptCa.outputOffset = 0.0001 # 100 nM offset in chem. adaptCa.scale = 0.05 # 0.06 to 0.003 mM aGluR = moose.Adaptor( '/model/chem/psdMesh/adaptGluR', 5 ) adaptGluR = moose.vec( '/model/chem/psdMesh/adaptGluR' ) chemR = moose.vec( '/model/chem/psdMesh/psdGluR' ) assert( len( adaptGluR ) == 5 ) for i in range( 5 ): path = '/model/elec/head' + str( i ) + '/gluR' elecR = moose.element( path ) moose.connect( adaptGluR[i], 'outputSrc', elecR, 'setGbar', 'Single' ) #moose.connect( chemR, 'nOut', adaptGluR, 'input', 'OneToOne' ) # Ksolve isn't sending nOut. Not good. So have to use requestField. moose.connect( adaptGluR, 'requestField', chemR, 'getN', 'OneToOne' ) adaptGluR.outputOffset = 1e-7 # pS adaptGluR.scale = 1e-6 / 100 # from n to pS adaptK = moose.Adaptor( '/model/chem/neuroMesh/adaptK' ) chemK = moose.element( '/model/chem/neuroMesh/kChan' ) elecK = moose.element( '/model/elec/compt/K' ) moose.connect( adaptK, 'requestField', chemK, 'getConc', 'OneToAll' ) moose.connect( adaptK, 'outputSrc', elecK, 'setGbar', 'Single' ) adaptK.scale = 0.3 # from mM to Siemens """
def loadFile(filename, target, solver="gsl", merge=True): """Try to load a model from specified `filename` under the element `target`. if `merge` is True, the contents are just loaded at target. If false, everything is deleted from the parent of target unless the parent is root. Returns ------- a dict containing at least these three entries: modeltype: type of the loaded model. subtype: subtype of the loaded model, None if no specific subtype modelroot: root element of the model, None if could not be located - as is the case with Python scripts """ loaderror = "" num = 1 libsfound = True model = '/' newTarget = target while moose.exists(newTarget): newTarget = target + "-" + str(num) num = num + 1 target = newTarget istext = True with open(filename, 'rb') as infile: istext = mtypes.istextfile(infile) if not istext: print('Cannot handle any binary formats yet') return None # parent, child = posixpath.split(target) # p = moose.Neutral(parent) # if not merge and p.path != '/': # for ch in p.children: # moose.delete(ch) try: modeltype = mtypes.getType(filename) subtype = mtypes.getSubtype(filename, modeltype) except KeyError: raise FileLoadError('Do not know how to handle this filetype: %s' % (filename)) pwe = moose.getCwe() #self.statusBar.showMessage('Loading model, please wait') # app = QtGui.qApp # app.setOverrideCursor(QtGui.QCursor(Qt.Qt.BusyCursor)) #shows a hourglass - or a busy/working arrow if modeltype == 'genesis': if subtype == 'kkit' or subtype == 'prototype': model, modelpath = loadGenCsp(target, filename, solver) xcord, ycord = [], [] if moose.exists(moose.element(modelpath).path): process = True compt = len(moose.wildcardFind(modelpath + '/##[ISA=CubeMesh]')) if not compt: loaderror = "Model has no compartment, atleast one compartment should exist to display the widget" process = False else: p = len(moose.wildcardFind(modelpath + '/##[ISA=PoolBase]')) if p < 2: loaderror = "Model has no pool, atleast two pool should exist to display the widget" process = False if process: if moose.exists(moose.element(modelpath).path): mObj = moose.wildcardFind( moose.element(modelpath).path + '/##[ISA=PoolBase]' + ',' + moose.element(modelpath).path + '/##[ISA=ReacBase]' + ',' + moose.element(modelpath).path + '/##[ISA=EnzBase]' + ',' + moose.element(modelpath).path + '/##[ISA=StimulusTable]') for p in mObj: if not isinstance(moose.element(p.parent), moose.CplxEnzBase): xcord.append(moose.element(p.path + '/info').x) ycord.append(moose.element(p.path + '/info').y) recalculatecoordinatesforKkit(mObj, xcord, ycord) for ememb in moose.wildcardFind( moose.element(modelpath).path + '/##[ISA=EnzBase]'): objInfo = ememb.path + '/info' #Enzyme's textcolor (from kkit) will be bgcolor (in moose) if moose.exists(objInfo): bgcolor = moose.element(objInfo).color moose.element(objInfo).color = moose.element( objInfo).textColor moose.element(objInfo).textColor = bgcolor moose.Annotator(moose.element(modelpath).path + '/info').modeltype = "kkit" else: print(" path doesn't exists") moose.le(modelpath) else: print('Only kkit and prototype files can be loaded.') elif modeltype == 'cspace': model, modelpath = loadGenCsp(target, filename) if moose.exists(modelpath): moose.Annotator( (moose.element(modelpath).path + '/info')).modeltype = "cspace" addSolver(modelpath, 'gsl') elif modeltype == 'xml': if subtype == 'neuroml': popdict, projdict = neuroml.loadNeuroML_L123(filename) # Circus to get the container of populations from loaded neuroml for popinfo in popdict.values(): for cell in popinfo[1].values(): solver = moose.HSolve(cell.path + "/hsolve") solver.target = cell.path # model = cell.parent # break # break # Moving model to a new location under the model name # model name is the filename without extension model = moose.Neutral("/" + splitext(basename(filename))[0]) element = moose.Neutral(model.path + "/model") if (moose.exists("/cells")): moose.move("/cells", element.path) if (moose.exists("/elec")): moose.move("/elec", model.path) if (moose.exists("/library")): moose.move("/library", model.path) # moose.move("cells/", cell.path) elif subtype == 'sbml': foundLibSBML_ = False try: import libsbml foundLibSBML_ = True except ImportError: pass if foundLibSBML_: if target != '/': if moose.exists(target): moose.delete(target) model, loaderror = mooseReadSBML(filename, target) if moose.exists(moose.element(model).path): moose.Annotator(moose.element(model).path + '/info').modeltype = "sbml" addSolver(target, 'gsl') libsfound = foundLibSBML_ else: raise FileLoadError('Do not know how to handle this filetype: %s' % (filename)) moose.setCwe( pwe ) # The MOOSE loadModel changes the current working element to newly loaded model. We revert that behaviour # TODO: check with Aditya how to specify the target for # neuroml reader # app.restoreOverrideCursor() return { 'modeltype': modeltype, 'subtype': subtype, 'model': model, 'foundlib': libsfound, 'loaderror': loaderror }
def loadFile(filename, target, merge=True): """Try to load a model from specified `filename` under the element `target`. if `merge` is True, the contents are just loaded at target. If false, everything is deleted from the parent of target unless the parent is root. Returns ------- a dict containing at least these three entries: modeltype: type of the loaded model. subtype: subtype of the loaded model, None if no specific subtype modelroot: root element of the model, None if could not be located - as is the case with Python scripts """ istext = True with open(filename, 'rb') as infile: istext = mtypes.istextfile(infile) if not istext: print 'Cannot handle any binary formats yet' return None parent, child = posixpath.split(target) p = moose.Neutral(parent) if not merge and p.path != '/': for ch in p.children: moose.delete(ch) try: modeltype = mtypes.getType(filename) subtype = mtypes.getSubtype(filename, modeltype) except KeyError: raise FileLoadError('Do not know how to handle this filetype: %s' % (filename)) pwe = moose.getCwe() #self.statusBar.showMessage('Loading model, please wait') # app = QtGui.qApp # app.setOverrideCursor(QtGui.QCursor(Qt.Qt.BusyCursor)) #shows a hourglass - or a busy/working arrow if modeltype == 'genesis': if subtype == 'kkit' or subtype == 'prototype': model = moose.loadModel(filename, target,'gsl') #Harsha: Moving the model under /modelname/model and graphs under /model/graphs lmodel = moose.Neutral('%s/%s' %(model.path,"model")) for compt in moose.wildcardFind(model.path+'/##[ISA=ChemCompt]'): moose.move(compt.path,lmodel) if not moose.exists(model.path+'/data'): graphspath = moose.Neutral('%s/%s' %(model.path,"data")) dataPath = moose.element(model.path+'/data') i =0 nGraphs = moose.wildcardFind(model.path+'/graphs/##[TYPE=Table2]') for graphs in nGraphs: if not moose.exists(dataPath.path+'/graph_'+str(i)): graphspath = moose.Neutral('%s/%s' %(dataPath.path,"graph_"+str(i))) else: graphspath = moose.element(dataPath.path+'/graph_'+str(i)) moose.move(graphs.path,graphspath) if len(nGraphs) > 0: i = i+1 #print " i ", i,moose.wildcardFind(model.path+'/moregraphs/##[TYPE=Table2]') for moregraphs in moose.wildcardFind(model.path+'/moregraphs/##[TYPE=Table2]'): if not moose.exists(dataPath.path+'/graph_'+str(i)): graphspath = moose.Neutral('%s/%s' %(dataPath.path,"graph_"+str(i))) else: graphspath = moose.element(dataPath.path+'/graph_'+str(i)) moose.move(moregraphs.path,graphspath) moose.delete(model.path+'/graphs') moose.delete(model.path+'/moregraphs') else: print 'Only kkit and prototype files can be loaded.' elif modeltype == 'cspace': model = moose.loadModel(filename, target,'gsl') #Harsha: Moving the model under /modelname/model and graphs under /model/graphs lmodel = moose.Neutral('%s/%s' %(model.path,"model")) for compt in moose.wildcardFind(model.path+'/##[ISA=ChemCompt]'): moose.move(compt.path,lmodel) if not moose.exists(model.path+'/data'): graphspath = moose.Neutral('%s/%s' %(model.path,"data")) dataPath = moose.element(model.path+'/data') i =0 nGraphs = moose.wildcardFind(model.path+'/graphs/##[TYPE=Table2]') for graphs in nGraphs: if not moose.exists(dataPath.path+'/graph_'+str(i)): graphspath = moose.Neutral('%s/%s' %(dataPath.path,"graph_"+str(i))) else: graphspath = moose.element(dataPath.path+'/graph_'+str(i)) moose.move(graphs.path,graphspath) if len(nGraphs) > 0: i = i+1 #print " i ", i,moose.wildcardFind(model.path+'/moregraphs/##[TYPE=Table2]') for moregraphs in moose.wildcardFind(model.path+'/moregraphs/##[TYPE=Table2]'): if not moose.exists(dataPath.path+'/graph_'+str(i)): graphspath = moose.Neutral('%s/%s' %(dataPath.path,"graph_"+str(i))) else: graphspath = moose.element(dataPath.path+'/graph_'+str(i)) moose.move(moregraphs.path,graphspath) moose.delete(model.path+'/graphs') moose.delete(model.path+'/moregraphs') addSolver(target,'gsl') elif modeltype == 'xml': if subtype == 'neuroml': popdict, projdict = neuroml.loadNeuroML_L123(filename) # Circus to get the container of populations from loaded neuroml for popinfo in popdict.values(): for cell in popinfo[1].values(): solver = moose.HSolve(cell.path + "/hsolve") solver.target = cell.path # model = cell.parent # break # break # Moving model to a new location under the model name # model name is the filename without extension model = moose.Neutral("/" + splitext(basename(filename))[0]) element = moose.Neutral(model.path + "/model") if(moose.exists("/cells")) : moose.move("/cells" , element.path) if(moose.exists("/elec")) : moose.move("/elec" , model.path) if(moose.exists("/library")): moose.move("/library", model.path) # moose.move("cells/", cell.path) elif subtype == 'sbml': model = moose.readSBML(filename,target,'gsl') addSolver(target,'gsl') else: raise FileLoadError('Do not know how to handle this filetype: %s' % (filename)) moose.setCwe(pwe) # The MOOSE loadModel changes the current working element to newly loaded model. We revert that behaviour # TODO: check with Aditya how to specify the target for # neuroml reader # app.restoreOverrideCursor() return {'modeltype': modeltype, 'subtype': subtype, 'model': model}