def makeChannelPrototypes(): """Create channel prototypes for readcell.""" library = moose.Neutral( '/library' ) moose.setCwe( '/library' ) compt = moose.SymCompartment( '/library/symcompartment' ) Em = EREST_ACT + 10.613e-3 compt.Em = Em compt.initVm = EREST_ACT compt.Cm = 7.85e-9 * 0.5 compt.Rm = 4.2e5 * 5.0 compt.Ra = 7639.44e3 nachan = moose.HHChannel( '/library/Na' ) nachan.Xpower = 3 xGate = moose.HHGate(nachan.path + '/gateX') xGate.setupAlpha(Na_m_params + [VDIVS, VMIN, VMAX]) xGate.useInterpolation = 1 nachan.Ypower = 1 yGate = moose.HHGate(nachan.path + '/gateY') yGate.setupAlpha(Na_h_params + [VDIVS, VMIN, VMAX]) yGate.useInterpolation = 1 nachan.Gbar = 0.942e-3 nachan.Ek = 115e-3+EREST_ACT kchan = moose.HHChannel( '/library/K' ) kchan.Xpower = 4.0 xGate = moose.HHGate(kchan.path + '/gateX') xGate.setupAlpha(K_n_params + [VDIVS, VMIN, VMAX]) xGate.useInterpolation = 1 kchan.Gbar = 0.2836e-3 kchan.Ek = -12e-3+EREST_ACT
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 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 makeChannelPrototypes(): """Create channel prototypes for readcell.""" library = moose.Neutral('/library') moose.setCwe('/library') compt = moose.SymCompartment('/library/symcompartment') Em = EREST_ACT + 10.613e-3 compt.Em = Em compt.initVm = EREST_ACT compt.Cm = 7.85e-9 * 0.5 compt.Rm = 4.2e5 * 5.0 compt.Ra = 7639.44e3 nachan = moose.HHChannel('/library/Na') nachan.Xpower = 3 xGate = moose.HHGate(nachan.path + '/gateX') xGate.setupAlpha(Na_m_params + [VDIVS, VMIN, VMAX]) xGate.useInterpolation = 1 nachan.Ypower = 1 yGate = moose.HHGate(nachan.path + '/gateY') yGate.setupAlpha(Na_h_params + [VDIVS, VMIN, VMAX]) yGate.useInterpolation = 1 nachan.Gbar = 0.942e-3 nachan.Ek = 115e-3 + EREST_ACT kchan = moose.HHChannel('/library/K') kchan.Xpower = 4.0 xGate = moose.HHGate(kchan.path + '/gateX') xGate.setupAlpha(K_n_params + [VDIVS, VMIN, VMAX]) xGate.useInterpolation = 1 kchan.Gbar = 0.2836e-3 kchan.Ek = -12e-3 + EREST_ACT
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() if modeltype == 'genesis': if subtype == 'kkit' or subtype == 'prototype': model = moose.loadModel(filename, target) else: print 'Only kkit and prototype files can be loaded.' elif modeltype == 'cspace': model = moose.loadModel(filename, target) elif modeltype == 'xml' and subtype == 'neuroml': model = neuroml.loadNeuroML_L123(filename) 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 return {'modeltype': modeltype, 'subtype': subtype, 'model': model}
def addSpineProto(name='spine', parent='/library', RM=1.0, RA=1.0, CM=0.01, shaftLen=1.e-6, shaftDia=0.2e-6, headLen=0.5e-6, headDia=0.5e-6, synList=(), chanList=(), caTau=0.0): assert (moose.exists(parent)), "%s must exist" % parent spine = moose.Neutral(parent + '/' + name) shaft = buildComptWrapper(spine, 'shaft', shaftLen, shaftDia, 0.0, RM, RA, CM) head = buildComptWrapper(spine, 'head', headLen, headDia, shaftLen, RM, RA, CM) moose.connect(shaft, 'axial', head, 'raxial') if caTau > 0.0: conc = moose.CaConc(head.path + '/Ca_conc') conc.tau = caTau conc.length = head.length conc.diameter = head.diameter conc.thick = 0.0 # The 'B' field is deprecated. # B = 1/(ion_charge * Faraday * volume) #vol = head.length * head.diameter * head.diameter * PI / 4.0 #conc.B = 1.0 / ( 2.0 * FaradayConst * vol ) conc.Ca_base = 0.0 for i in synList: syn = buildSyn(i[0], head, i[1], i[2], i[3], i[4], CM) if i[5] and caTau > 0.0: moose.connect(syn, 'IkOut', conc, 'current') for i in chanList: if (moose.exists(parent + '/' + i[0])): chan = moose.copy(parent + '/' + i[0], head) else: moose.setCwe(head) chan = make_LCa() chan.name = i[0] moose.setCwe('/') chan.Gbar = i[1] * head.Cm / CM #print "CHAN = ", chan, chan.tick, chan.Gbar moose.connect(head, 'channel', chan, 'channel') if i[2] and caTau > 0.0: moose.connect(chan, 'IkOut', conc, 'current') transformNMDAR(parent + '/' + name) return spine
def addSpineProto( name="spine", parent="/library", RM=1.0, RA=1.0, CM=0.01, shaftLen=1.0e-6, shaftDia=0.2e-6, headLen=0.5e-6, headDia=0.5e-6, synList=(), chanList=(), caTau=0.0, ): assert moose.exists(parent), "%s must exist" % parent spine = moose.Neutral(parent + "/" + name) shaft = buildComptWrapper(spine, "shaft", shaftLen, shaftDia, 0.0, RM, RA, CM) head = buildComptWrapper(spine, "head", headLen, headDia, shaftLen, RM, RA, CM) moose.connect(shaft, "axial", head, "raxial") if caTau > 0.0: conc = moose.CaConc(head.path + "/Ca_conc") conc.tau = caTau conc.length = head.length conc.diameter = head.diameter conc.thick = 0.0 # The 'B' field is deprecated. # B = 1/(ion_charge * Faraday * volume) # vol = head.length * head.diameter * head.diameter * PI / 4.0 # conc.B = 1.0 / ( 2.0 * FaradayConst * vol ) conc.Ca_base = 0.0 for i in synList: syn = buildSyn(i[0], head, i[1], i[2], i[3], i[4], CM) if i[5] and caTau > 0.0: moose.connect(syn, "IkOut", conc, "current") for i in chanList: if moose.exists(parent + "/" + i[0]): chan = moose.copy(parent + "/" + i[0], head) else: moose.setCwe(head) chan = make_LCa() chan.name = i[0] moose.setCwe("/") chan.Gbar = i[1] * head.Cm / CM # print "CHAN = ", chan, chan.tick, chan.Gbar moose.connect(head, "channel", chan, "channel") if i[2] and caTau > 0.0: moose.connect(chan, "IkOut", conc, "current") transformNMDAR(parent + "/" + name) return spine
def loadElec(): library = moose.Neutral('/library') moose.setCwe('/library') proto18.make_Ca() proto18.make_Ca_conc() proto18.make_Na() proto18.make_K_DR() proto18.make_K_A() # Disable all the prototypes. for x in moose.wildcardFind("/library/##"): x.tick = -1 model = moose.Neutral('/model') cellId = moose.loadModel(os.path.join(scriptDir, 'soma.p'), '/model/elec', "Neutral") moose.setCwe('/') return cellId
def addSpineProto( name = 'spine', \ RM = 1.0, RA = 1.0, CM = 0.01, \ shaftLen = 1.e-6 , shaftDia = 0.2e-6, \ headLen = 0.5e-6, headDia = 0.5e-6, \ synList = ( ['glu', 0.0, 2e-3, 9e-3, 200.0, False], ['NMDA', 0.0, 20e-3, 20e-3, 80.0, True] ), chanList = ( ['Ca', 1.0, True ], ), caTau = 13.333e-3 ): if not moose.exists( '/library' ): library = moose.Neutral( '/library' ) spine = moose.Neutral( '/library/spine' ) shaft = buildCompt( spine, 'shaft', shaftLen, shaftDia, 0.0, RM, RA, CM ) head = buildCompt( spine, 'head', headLen, headDia, shaftLen, RM, RA, CM ) moose.connect( shaft, 'axial', head, 'raxial' ) if caTau > 0.0: conc = moose.CaConc( head.path + '/Ca_conc' ) conc.tau = caTau conc.length = head.length conc.diameter = head.diameter conc.thick = 0.0 # The 'B' field is deprecated. # B = 1/(ion_charge * Faraday * volume) #vol = head.length * head.diameter * head.diameter * PI / 4.0 #conc.B = 1.0 / ( 2.0 * FaradayConst * vol ) conc.Ca_base = 0.0 for i in synList: syn = buildSyn( i[0], head, i[1], i[2], i[3], i[4], CM ) if i[5] and caTau > 0.0: moose.connect( syn, 'IkOut', conc, 'current' ) for i in chanList: if ( moose.exists( '/library/' + i[0] ) ): chan = moose.copy( '/library/' + i[0], head ) else: moose.setCwe( head ) chan = make_LCa() chan.name = i[0] moose.setCwe( '/' ) chan.Gbar = i[1] * head.Cm / CM print "CHAN = ", chan, chan.tick, chan.Gbar moose.connect( head, 'channel', chan, 'channel' ) if i[2] and caTau > 0.0: moose.connect( chan, 'IkOut', conc, 'current' ) transformNMDAR( '/library/spine' ) return spine
def addSpineProto( name = 'spine', \ RM = 1.0, RA = 1.0, CM = 0.01, \ shaftLen = 1.e-6 , shaftDia = 0.2e-6, \ headLen = 0.5e-6, headDia = 0.5e-6, \ synList = ( ['glu', 0.0, 2e-3, 9e-3, 200.0, False], ['NMDA', 0.0, 20e-3, 20e-3, 80.0, True] ), chanList = ( ['Ca', 1.0, True ], ), caTau = 13.333e-3 ): if not moose.exists( '/library' ): library = moose.Neutral( '/library' ) spine = moose.Neutral( '/library/spine' ) shaft = buildCompt( spine, 'shaft', shaftLen, shaftDia, 0.0, RM, RA, CM ) head = buildCompt( spine, 'head', headLen, headDia, shaftLen, RM, RA, CM ) moose.connect( shaft, 'axial', head, 'raxial' ) if caTau > 0.0: conc = moose.CaConc( head.path + '/Ca_conc' ) conc.tau = caTau conc.length = head.length conc.diameter = head.diameter conc.thick = 0.0 # The 'B' field is deprecated. # B = 1/(ion_charge * Faraday * volume) #vol = head.length * head.diameter * head.diameter * PI / 4.0 #conc.B = 1.0 / ( 2.0 * FaradayConst * vol ) conc.Ca_base = 0.0 for i in synList: syn = buildSyn( i[0], head, i[1], i[2], i[3], i[4], CM ) if i[5] and caTau > 0.0: moose.connect( syn, 'IkOut', conc, 'current' ) for i in chanList: if ( moose.exists( '/library/' + i[0] ) ): chan = moose.copy( '/library/' + i[0], head ) else: moose.setCwe( head ) chan = make_LCa() chan.name = i[0] moose.setCwe( '/' ) chan.Gbar = i[1] * head.Cm / CM #print "CHAN = ", chan, chan.tick, chan.Gbar moose.connect( head, 'channel', chan, 'channel' ) if i[2] and caTau > 0.0: moose.connect( chan, 'IkOut', conc, 'current' ) transformNMDAR( '/library/spine' ) return spine
def addSpineProto( name = 'spine', parent = '/library', RM = 1.0, RA = 1.0, CM = 0.01, shaftLen = 1.e-6 , shaftDia = 0.2e-6, headLen = 0.5e-6, headDia = 0.5e-6, synList = (), chanList = (), caTau = 0.0 ): assert( moose.exists( parent ) ), "%s must exist" % parent spine = moose.Neutral( parent + '/' + name ) shaft = buildComptWrapper( spine, 'shaft', shaftLen, shaftDia, 0.0, RM, RA, CM ) head = buildComptWrapper( spine, 'head', headLen, headDia, shaftLen, RM, RA, CM ) moose.connect( shaft, 'axial', head, 'raxial' ) if caTau > 0.0: conc = moose.CaConc( head.path + '/Ca_conc' ) conc.tau = caTau conc.length = head.length conc.diameter = head.diameter conc.thick = 0.0 # The 'B' field is deprecated. # B = 1/(ion_charge * Faraday * volume) #vol = head.length * head.diameter * head.diameter * PI / 4.0 #conc.B = 1.0 / ( 2.0 * FaradayConst * vol ) conc.Ca_base = 0.0 for i in synList: syn = buildSyn( i[0], head, i[1], i[2], i[3], i[4], CM ) if i[5] and caTau > 0.0: moose.connect( syn, 'IkOut', conc, 'current' ) for i in chanList: if ( moose.exists( parent + '/' + i[0] ) ): chan = moose.copy( parent + '/' + i[0], head ) else: moose.setCwe( head ) chan = make_LCa() chan.name = i[0] moose.setCwe( '/' ) chan.Gbar = i[1] * head.Cm / CM #print "CHAN = ", chan, chan.tick, chan.Gbar moose.connect( head, 'channel', chan, 'channel' ) if i[2] and caTau > 0.0: moose.connect( chan, 'IkOut', conc, 'current' ) transformNMDAR( parent + '/' + name ) return spine
def loadElec(): library = moose.Neutral( '/library' ) moose.setCwe( '/library' ) proto18.make_Ca() proto18.make_Ca_conc() proto18.make_K_AHP() proto18.make_K_C() proto18.make_Na() proto18.make_K_DR() proto18.make_K_A() proto18.make_glu() proto18.make_NMDA() proto18.make_Ca_NMDA() proto18.make_NMDA_Ca_conc() proto18.make_axon() model = moose.Neutral( '/model' ) cellId = moose.loadModel( 'ca1_asym.p', '/model/elec', "Neutral" ) return cellId
def loadElec(): library = moose.Neutral( '/library' ) moose.setCwe( '/library' ) proto18.make_Ca() proto18.make_Ca_conc() proto18.make_K_AHP() proto18.make_K_C() proto18.make_Na() proto18.make_K_DR() proto18.make_K_A() proto18.make_glu() proto18.make_NMDA() proto18.make_Ca_NMDA() proto18.make_NMDA_Ca_conc() proto18.make_axon() model = moose.element( '/model' ) cellId = moose.loadModel( 'ca1_asym.p', '/model/elec', "Neutral" ) return cellId
def loadElec(): library = moose.Neutral( '/library' ) moose.setCwe( '/library' ) proto18.make_Ca() proto18.make_Ca_conc() proto18.make_Na() proto18.make_K_DR() proto18.make_K_A() # Disable all the prototypes. for x in moose.wildcardFind( "/library/##" ): x.tick = -1 model = moose.Neutral( '/model' ) cellId = moose.loadModel( os.path.join( scriptDir, 'soma.p') , '/model/elec', "Neutral" ) moose.setCwe( '/' ) return cellId
def setup_model(root='/', hsolve=True): moose.setCwe(root) model = moose.Neutral('model') data = moose.Neutral('data') cell = DeepBasket('%s/deepbasket' % (model.path)) p = '%s/comp_1' % cell.path soma = moose.element(p) if moose.exists(p) else moose.Compartment(p) if hsolve: solver = moose.HSolve('%s/solve' % (cell.path)) solver.dt = simdt solver.target = cell.path pulse = moose.PulseGen('%s/stimulus' % (model.path)) moose.connect(pulse, 'output', soma, 'injectMsg') tab_vm = moose.Table('%s/spinystellate_soma_Vm' % (data.path)) moose.connect(tab_vm, 'requestOut', soma, 'getVm') tab_stim = moose.Table('%s/spinystellate_soma_inject' % (data.path)) moose.connect(tab_stim, 'requestOut', pulse, 'getOutputValue') utils.setDefaultDt(elecdt=simdt, plotdt2=plotdt) utils.assignDefaultTicks(model, data) return {'stimulus': pulse, 'tab_vm': tab_vm, 'tab_stim': tab_stim}
def test_children(): a1 = moose.Neutral('/a') a2 = moose.Neutral('/a/b') a3 = moose.Neutral('/a/b/c1') moose.Neutral('/a/b/c2') assert len(a1.children) == 1 assert len(a2.children) == 2 moose.le(a1) moose.le(a2) moose.le(a3) moose.setCwe(a3) s = moose.getCwe() assert s == a3, (s, a3) a11 = a1.children[0] ax = moose.element(a1) ax1 = ax.children[0] assert ax == a1 assert ax1 == a11 assert a11[0].isA['Neutral'], a11.isA assert ax1[0].isA['Neutral'], a11.isA print("test_children is done")
def loadElec(): library = moose.Neutral( '/library' ) moose.setCwe( '/library' ) proto18.make_Ca() proto18.make_Ca_conc() proto18.make_Na() proto18.make_K_DR() proto18.make_K_A() # Disable all the prototypes. for x in moose.wildcardFind( "/library/##" ): x.tick = -1 model = moose.Neutral( '/model' ) cellId = moose.loadModel( 'soma.p', '/model/elec', "Neutral" ) moose.setCwe( '/' ) ''' hsolve = moose.HSolve( '/model/elec/hsolve' ) hsolve.dt = 50.0e-6 hsolve.target = '/model/elec/soma' moose.reinit() ''' return cellId
def loadElec(): library = moose.Neutral('/library') moose.setCwe('/library') proto18.make_Ca() proto18.make_Ca_conc() proto18.make_Na() proto18.make_K_DR() proto18.make_K_A() # Disable all the prototypes. for x in moose.wildcardFind("/library/##"): x.tick = -1 model = moose.Neutral('/model') cellId = moose.loadModel('soma.p', '/model/elec', "Neutral") moose.setCwe('/') ''' hsolve = moose.HSolve( '/model/elec/hsolve' ) hsolve.dt = 50.0e-6 hsolve.target = '/model/elec/soma' moose.reinit() ''' return cellId
def readModel(self, filename, target): if isinstance(target, str): if not moose.exists(target): target = moose.Neutral(target) elif isinstance(target, moose.NeutralArray): target = target._id elif isinstance(target, moose.Neutral): target = target._oid.getId() elif not (isinstance(target, moose.Id) or isinstance(target, moose.ObjId)): raise TypeError('Target must be a string or an Id or an ObjId or a moose object.') # current = moose.getCwe() - until the moose unit test bugs are fixed self._moose_root = target with open(filename) as model_file: model = ninemlul.parse(model_file) model.check() spiking_nodes = {} projections = {} synapses = {} for name, component in model.components.items(): if isinstance(component, ninemlul.SpikingNodeType): spiking_nodes[name] = component print spiking_nodes.keys() moose.setCwe(target) # We instantiate the model here. TODO: components are # actually prototypes, we need to make copies of them when # creating Groups for name, node in spiking_nodes.items(): if node.definition.url == 'http://svn.incf.org/svn/nineml/trunk/catalog/neurons/IaF_tau.xml': moose_object = self._create_LeakyIaF(node) self._moose_to_nineml[moose_object] = node self._nineml_to_moose[node] = moose_object elif node.definition.url == 'http://svn.incf.org/svn/nineml/trunk/catalog/neurons/Iz1.xml': moose_object = self._create_IzhikevichNeuron(node) self._moose_to_nineml[moose_object] = node self._nineml_to_moose[node] = moose_object
def loadElec(): library = moose.Neutral( '/library' ) moose.setCwe( '/library' ) model = moose.Neutral( '/model' ) cellId = moose.loadModel( 'mincell.p', '/model/elec', "Neutral" ) return cellId
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 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 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}
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 }
# First pass at loading and running a cell model import os os.environ['NUMPTHREADS'] = '1' import moose import proto18 def dumpPlots( fname ): if ( os.path.exists( fname ) ): os.remove( fname ) tab.xplot( fname, 'soma.Vm' ) catab.xplot( fname, 'soma.Ca' ) library = moose.Neutral( '/library' ) moose.setCwe( '/library' ) proto18.make_Ca() proto18.make_Ca_conc() proto18.make_K_AHP() proto18.make_K_C() proto18.make_Na() proto18.make_K_DR() proto18.make_K_A() proto18.make_glu() proto18.make_NMDA() proto18.make_Ca_NMDA() proto18.make_NMDA_Ca_conc() proto18.make_axon() cellId = moose.loadModel( 'ca1_asym.p', '/cell', "hsolve" ) moose.le( cellId ) moose.le( '/cell/lat_14_1' )
def loadElec(): library = moose.Neutral('/library') moose.setCwe('/library') model = moose.Neutral('/model') cellId = moose.loadModel('mincell.p', '/model/elec', "Neutral") return cellId