コード例 #1
0
ファイル: hdfutil.py プロジェクト: hrani/moose-core
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])
コード例 #2
0
ファイル: mgui.py プロジェクト: physicalist/moose
    def connectBioModel(self):
        connecttoBioModel = BioModelsClientWidget()
        if connecttoBioModel.exec_():
            pass
        filepath = connecttoBioModel.filePath
        if filepath:
            head, fileName = os.path.split(filepath)
            modelName = os.path.splitext(fileName)[0]
            pwe = moose.getCwe()
            ret = loadFile(str(filepath), '/model/%s' % (modelName), merge=False)
            self.objectEditSlot('/',False)
            pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype'])
            try:
                pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])]
            except KeyError:
                pluginName = 'default'
            print 'Loaded model', ret['model'].path,subtype
            self._loadedModels.append([ret['model'].path,pluginName])
            if len(self._loadedModels)>5:
                self._loadedModels.pop(0)

            if not moose.exists(ret['model'].path+'/info'):
                    moose.Annotator(ret['model'].path+'/info')

            modelAnno = moose.Annotator(ret['model'].path+'/info')
            if ret['subtype']:
                modelAnno.modeltype = ret['subtype']
            else:
                modelAnno.modeltype = ret['modeltype']
            modelAnno.dirpath = str(dialog.directory().absolutePath())
            self.loadedModelsAction(ret['model'].path,pluginName)
            self.setPlugin(pluginName, ret['model'].path)
コード例 #3
0
ファイル: hdfutil.py プロジェクト: dilawar/moose-core
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])
コード例 #4
0
ファイル: moose.py プロジェクト: AdrianW15/moose
def pwe():
    """Print present working element. Convenience function for GENESIS
    users. If you want to retrieve the element in stead of printing
    the path, use moose.getCwe()

    """
    pwe_ = moose.getCwe()
    print(pwe_.getPath())
    return pwe_
コード例 #5
0
ファイル: moose.py プロジェクト: pgleeson/moose-core
def pwe():
    """Print present working element. Convenience function for GENESIS
    users. If you want to retrieve the element in stead of printing
    the path, use moose.getCwe()

    """
    pwe_ = moose.getCwe()
    print(pwe_.getPath())
    return pwe_
コード例 #6
0
ファイル: mload.py プロジェクト: Vivek-sagar/moose-1
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}
コード例 #7
0
ファイル: mgui.py プロジェクト: csiki/moose-csiki
 def connectBioModel(self):
     connecttoBioModel = BioModelsClientWidget()
     if connecttoBioModel.exec_():
         pass
     filepath = connecttoBioModel.filePath
     if filepath:
         head, fileName = os.path.split(filepath)
         modelName = os.path.splitext(fileName)[0]
         pwe = moose.getCwe()
         ret = loadFile(str(filepath), '/model/%s' % (modelName), merge=False)
         self.objectEditSlot('/',False)
         pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype'])
         try:
             pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])]
         except KeyError:
             pluginName = 'default'
         
         print 'Loaded model', ret['model'].path
         self.setPlugin(pluginName, ret['model'].path)
コード例 #8
0
ファイル: test_api.py プロジェクト: sanjayankur31/moose-core
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")
コード例 #9
0
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}
コード例 #10
0
ファイル: mload.py プロジェクト: dilawar/moose-gui
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}
コード例 #11
0
ファイル: mload.py プロジェクト: BhallaLab/moose-package
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
    }
コード例 #12
0
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}