本文整理汇总了Python中moose.loadModel函数的典型用法代码示例。如果您正苦于以下问题:Python loadModel函数的具体用法?Python loadModel怎么用?Python loadModel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loadModel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _loadElec
def _loadElec( self, efile, elecname ):
if ( efile[ len( efile ) - 2:] == ".p" ):
self.elecid = moose.loadModel( efile, '/library/' + elecname)[0]
print self.elecid
elif ( efile[ len( efile ) - 4:] == ".swc" ):
self.elecid = moose.loadModel( efile, '/library/' + elecname)[0]
else:
nm = NeuroML()
print "in _loadElec, combineSegments = ", self.combineSegments
nm.readNeuroMLFromFile( efile, \
params = {'combineSegments': self.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]' )
transformNMDAR( self.elecid.path )
kids = moose.wildcardFind( '/library/##[0]' )
for i in kids:
i.tick = -1
示例2: loadModels
def loadModels(filepath):
""" load models into moose if file, if moosepath itself it passes back the path and
delete solver if exist """
modelpath = '/'
loaded = False
if os.path.isfile(filepath) :
fpath, filename = os.path.split(filepath)
# print " head and tail ",head, " ",tail
# modelpath = filename[filename.rfind('/'): filename.rfind('.')]
# print "modelpath ",modelpath
# ext = os.path.splitext(filename)[1]
# filename = filename.strip()
modelpath = '/'+filename[:filename.rfind('.')]
modeltype = mtypes.getType(filepath)
subtype = mtypes.getSubtype(filepath, modeltype)
if subtype == 'kkit' or modeltype == "cspace":
moose.loadModel(filepath,modelpath)
loaded = True
elif subtype == 'sbml':
#moose.mooseReadSBML(filename,modelpath)
#loaded = True
pass
else:
print("This file is not supported for mergering")
modelpath = moose.Shell('/')
elif moose.exists(filepath):
modelpath = filepath
loaded = True
return modelpath,loaded
示例3: __init__
def __init__(self, *args):
QWidget.__init__(self, *args)
#c = moose.ZombiePool('/compartment')
c = moose.Compartment('/compartment')
moose.loadModel('../Demos/Genesis_files/reaction.g','/rec')
for l in moose.wildcardFind('/rec/##[TYPE=ZombiePool]'):
if( moose.element(l).path == '/rec/kinetics/Sub'):
c = moose.element(l)
tablemodel = ObjectFieldsModel(c,['Field','Value'],self) #my_array, self)
tableview = QTableView()
tableview.setModel(tablemodel)
#tableview.setShowGrid(False)
vh = tableview.verticalHeader()
vh.setVisible(False)
hh = tableview.horizontalHeader()
hh.setStretchLastSection(True)
tableview.setAlternatingRowColors(True)
#tableview.resizeColumnsToContents()
layout = QVBoxLayout(self)
layout.addWidget(tableview)
self.setLayout(layout)
示例4: main
def main( runTime ):
try:
moose.delete('/acc92')
print("Deleted old model")
except Exception as e:
print("Could not clean. model not loaded yet")
moose.loadModel('acc92_caBuff.g',loadpath,'gsl')
ca = moose.element(loadpath+'/kinetics/Ca')
pr = moose.element(loadpath+'/kinetics/protein')
clockdt = moose.Clock('/clock').dts
moose.setClock(8, 0.1)#simdt
moose.setClock(18, 0.1)#plotdt
print clockdt
print " \t \t simdt ", moose.Clock('/clock').dts[8],"plotdt ",moose.Clock('/clock').dts[18]
ori = ca.concInit
tablepath = loadpath+'/kinetics/Ca'
tableele = moose.element(tablepath)
table = moose.Table2(tablepath+'.con')
x = moose.connect(table, 'requestOut', tablepath, 'getConc')
tablepath1 = loadpath+'/kinetics/protein'
tableele1 = moose.element(tablepath1)
table1 = moose.Table2(tablepath1+'.con')
x1 = moose.connect(table1, 'requestOut', tablepath1, 'getConc')
ca.concInit = ori
print("[INFO] Running for 4000 with Ca.conc %s " % ca.conc)
moose.start(4000)
ca.concInit = 5e-03
print("[INFO] Running for 20 with Ca.conc %s " % ca.conc)
moose.start(20)
ca.concInit = ori
moose.start( runTime ) #here give the interval time
ca.concInit = 5e-03
print("[INFO] Running for 20 with Ca.conc %s " % ca.conc)
moose.start(20)
ca.concInit = ori
print("[INFO] Running for 2000 with Ca.conc %s " % ca.conc)
moose.start(2000)
pylab.figure()
pylab.subplot(2, 1, 1)
t = numpy.linspace(0.0, moose.element("/clock").runTime, len(table.vector)) # sec
pylab.plot( t, table.vector, label="Ca Conc (interval- 8000s)" )
pylab.legend()
pylab.subplot(2, 1, 2)
t1 = numpy.linspace(0.0, moose.element("/clock").runTime, len(table1.vector)) # sec
pylab.plot( t1, table1.vector, label="Protein Conc (interval- 8000s)" )
pylab.legend()
pylab.savefig( os.path.join( dataDir, '%s_%s.png' % (table1.name, runTime) ) )
print('[INFO] Saving data to csv files in %s' % dataDir)
tabPath1 = os.path.join( dataDir, '%s_%s.csv' % (table.name, runTime))
numpy.savetxt(tabPath1, numpy.matrix([t, table.vector]).T, newline='\n')
tabPath2 = os.path.join( dataDir, '%s_%s.csv' % (table1.name, runTime) )
numpy.savetxt(tabPath2, numpy.matrix([t1, table1.vector]).T, newline='\n')
示例5: main
def main():
"""This example illustrates loading a kinetic model defined in Genesis format
into Moose using loadModel function and using writeSBML function
one can save the model into SBML format. \n
Moose needs to be compiled with libsbml
"""
#This command loads the file into the path '/Kholodenko'
moose.loadModel('../genesis/Kholodenko.g','/Kholodenko')
#Writes model to xml file
moose.writeSBML('/Kholodenko','Kholodenko_tosbml.xml')
示例6: main
def main():
"""This example illustrates loading a kinetic model defined in Genesis format
into Moose using loadModel function and using writeSBML function
one can save the model into SBML format. \n
libsbml should be installed
"""
#This command loads the file into the path '/Kholodenko'
moose.loadModel('../genesis/Kholodenko.g','/Kholodenko')
#Writes model to xml file
written = mooseWriteSBML('/Kholodenko','../genesis/Kholodenko_tosbml.xml')
print(written)
示例7: main
def main():
# Schedule the whole lot
moose.setClock( 4, 0.1 ) # for the computational objects
moose.setClock( 5, 0.1 ) # clock for the solver
moose.setClock( 8, 1.0 ) # for the plots
# The wildcard uses # for single level, and ## for recursive.
#compartment = makeModel()
moose.loadModel( '../Genesis_files/M1719.cspace', '/model', 'ee' )
compartment = moose.element( 'model/kinetics' )
compartment.name = 'compartment'
ksolve = moose.Ksolve( '/model/compartment/ksolve' )
stoich = moose.Stoich( '/model/compartment/stoich' )
stoich.compartment = compartment
stoich.ksolve = ksolve
#ksolve.stoich = stoich
stoich.path = "/model/compartment/##"
state = moose.SteadyState( '/model/compartment/state' )
moose.useClock( 5, '/model/compartment/ksolve', 'process' )
moose.useClock( 8, '/model/graphs/#', 'process' )
moose.reinit()
state.stoich = stoich
#state.showMatrices()
state.convergenceCriterion = 1e-7
moose.le( '/model/graphs' )
a = moose.element( '/model/compartment/a' )
b = moose.element( '/model/compartment/b' )
c = moose.element( '/model/compartment/c' )
for i in range( 0, 100 ):
getState( ksolve, state )
moose.start( 100.0 ) # Run the model for 100 seconds.
b = moose.element( '/model/compartment/b' )
c = moose.element( '/model/compartment/c' )
# move most molecules over to b
b.conc = b.conc + c.conc * 0.95
c.conc = c.conc * 0.05
moose.start( 100.0 ) # Run the model for 100 seconds.
# move most molecules back to a
c.conc = c.conc + b.conc * 0.95
b.conc = b.conc * 0.05
moose.start( 100.0 ) # Run the model for 100 seconds.
# Iterate through all plots, dump their contents to data.plot.
displayPlots()
quit()
示例8: loadFile
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}
示例9: main
def main():
"""Test main"""
model = moose.Neutral('/model')
moose.loadModel('../Demos/Genesis_files/Kholodenko.g', '/model/Kholodenko')
# tab = moose.element('/model/Kholodenko/graphs/conc1/MAPK_PP.Co')
# print tab
# for t in tab.children:
# print t
app = QtGui.QApplication(sys.argv)
mainwin = QtGui.QMainWindow()
mainwin.setWindowTitle('Model tree test')
wildcardWidget = SearchWidget()
mainwin.setCentralWidget(wildcardWidget)
mainwin.show()
sys.exit(app.exec_())
示例10: main
def main():
#solver = "gsl" # Pick any of gsl, gssa, ee..
solver = "gssa" # Pick any of gsl, gssa, ee..
mfile = '../../Genesis_files/Repressillator.g'
runtime = 6000.0
if ( len( sys.argv ) >= 2 ):
solver = sys.argv[1]
modelId = moose.loadModel( mfile, 'model', solver )
# Increase volume so that the stochastic solver gssa
# gives an interesting output
compt = moose.element( '/model/kinetics' )
compt.volume = 1e-19
dt = moose.element( '/clock' ).dt
moose.reinit()
moose.start( runtime )
# Display all plots.
img = mpimg.imread( 'repressillatorOsc.png' )
fig = plt.figure( figsize=(12, 10 ) )
png = fig.add_subplot( 211 )
imgplot = plt.imshow( img )
ax = fig.add_subplot( 212 )
x = moose.wildcardFind( '/model/#graphs/conc#/#' )
plt.ylabel( 'Conc (mM)' )
plt.xlabel( 'Time (seconds)' )
for x in moose.wildcardFind( '/model/#graphs/conc#/#' ):
t = numpy.arange( 0, x.vector.size, 1 ) * dt
pylab.plot( t, x.vector, label=x.name )
pylab.legend()
pylab.show()
示例11: main
def main():
solver = "gsl"
mfile = '../../Genesis_files/Kholodenko.g'
runtime = 5000.0
if ( len( sys.argv ) >= 2 ):
solver = sys.argv[1]
modelId = moose.loadModel( mfile, 'model', solver )
dt = moose.element( '/clock' ).dt
moose.reinit()
moose.start( runtime )
# Display all plots.
img = mpimg.imread( 'Kholodenko_tut.png' )
fig = plt.figure( figsize=( 12, 10 ) )
png = fig.add_subplot( 211 )
imgplot = plt.imshow( img )
ax = fig.add_subplot( 212 )
x = moose.wildcardFind( '/model/#graphs/conc#/#' )
t = numpy.arange( 0, x[0].vector.size, 1 ) * dt
ax.plot( t, x[0].vector * 100, 'b-', label='Ras-MKKK * 100' )
ax.plot( t, x[1].vector, 'y-', label='MKKK-P' )
ax.plot( t, x[2].vector, 'm-', label='MKK-PP' )
ax.plot( t, x[3].vector, 'r-', label='MAPK-PP' )
plt.ylabel( 'Conc (mM)' )
plt.xlabel( 'Time (seconds)' )
pylab.legend()
pylab.show()
示例12: loadChem
def loadChem( neuroCompt, spineCompt, psdCompt ):
# We need the compartments to come in with a volume of 1 to match the
# original CubeMesh.
assert( neuroCompt.volume == 1.0 )
assert( spineCompt.volume == 1.0 )
assert( psdCompt.volume == 1.0 )
assert( neuroCompt.mesh.num == 1 )
#print 'volume = ', neuroCompt.mesh[0].volume
#assert( neuroCompt.mesh[0].volume == 1.0 )
#an unfortunate mismatch
# So we'll have to resize the volumes of the current compartments to the
# new ones.
modelId = moose.loadModel( 'x_compt.g', '/model', 'ee' )
chem = moose.element( '/model/model' )
chem.name = 'chem'
oldN = moose.element( '/model/chem/compartment_1' )
oldS = moose.element( '/model/chem/compartment_2' )
oldP = moose.element( '/model/chem/kinetics' )
oldN.volume = neuroCompt.mesh[0].volume
oldS.volume = spineCompt.mesh[0].volume
oldP.volume = psdCompt.mesh[0].volume
moveCompt( '/model/chem/kinetics/DEND', oldN, neuroCompt )
moveCompt( '/model/chem/kinetics/SPINE', oldS, spineCompt )
moveCompt( '/model/chem/kinetics/PSD', oldP, psdCompt )
示例13: create_neuron
def create_neuron(model, ntype, ghkYN):
p_file = find_morph_file(model,ntype)
try:
cellproto=moose.loadModel(p_file, ntype)
except IOError:
print('could not load model from {!r}'.format(p_file))
raise
#######channels
Cond = model.Condset[ntype]
for comp in moose.wildcardFind('{}/#[TYPE=Compartment]'.format(ntype)):
#If we are using GHK, just create one GHK per compartment, connect it to comp
#calcium concentration is connected in a different function
if ghkYN:
ghkproto=moose.element('/library/ghk')
ghk=moose.copy(ghkproto,comp,'ghk')[0]
moose.connect(ghk,'channel',comp,'channel')
else:
ghk=[]
for channame in Cond.keys():
c = _util.distance_mapping(Cond[channame], comp)
if c > 0:
log.debug('Testing Cond If {} {}', channame, c)
calciumPermeable = model.Channels[channame].calciumPermeable
add_channel.addOneChan(channame, c, comp, ghkYN, ghk, calciumPermeable=calciumPermeable)
#Compensate for actual, experimentally estimated spine density.
#This gives a model that can be simulated with no explicit spines or
#any number of explicitly modeled spines up to the actual spine density:
spines.compensate_for_spines(model,comp,model.param_cond.NAME_SOMA)
return cellproto
示例14: load_axon
def load_axon():
model = moose.loadModel("axon_passive.p", "/axon")
for x in model[0].children:
print x.path, x.class_
pulsegen = moose.PulseGen("/pulsegen")
pulsegen.delay[0] = simdt * 200 # The Axon.g in oldmoose flips the current every 20 pulses
pulsegen.width[0] = simdt * 200
pulsegen.level[0] = inject
moose.connect(pulsegen, "outputOut", moose.element("/axon/soma"), "injectMsg")
data = moose.Neutral("/data")
tab = moose.Table("%s/Vm100" % (data.path))
moose.connect(tab, "requestData", moose.ObjId("/axon/c100"), "get_Vm")
pulsetab = moose.Table("/data/inject")
moose.connect(pulsetab, "requestData", pulsegen, "get_output")
solver = moose.HSolve("/hsolve")
solver.dt = simdt
solver.target = model.path
return {
"model": model,
"Vm": tab,
"inject": pulsetab,
"soma": moose.element("/axon/soma"),
"pulse": pulsegen,
"solver": solver,
}
示例15: test_symcomp_readcell
def test_symcomp_readcell():
model = moose.Neutral("/model")
cell = moose.loadModel("symcomp.p", "%s/cell" % (model.path))
pg = moose.PulseGen("/model/pulse")
pg.delay[0] = 10e-3
pg.width[0] = 20e-3
pg.level[0] = 1e-6
pg.delay[1] = 1e9
moose.connect(pg, "output", moose.element("/model/cell/d1"), "injectMsg")
data = moose.Neutral("/data")
tab_soma = moose.Table("%s/soma_Vm" % (data.path))
tab_d1 = moose.Table("%s/d1_Vm" % (data.path))
tab_d2 = moose.Table("%s/d2_Vm" % (data.path))
moose.connect(tab_soma, "requestOut", moose.element("/model/cell/soma"), "getVm")
moose.connect(tab_d1, "requestOut", moose.element("/model/cell/d1"), "getVm")
moose.connect(tab_d2, "requestOut", moose.element("/model/cell/d2"), "getVm")
moose.setClock(0, simdt)
moose.setClock(1, simdt)
moose.setClock(2, simdt)
moose.useClock(
0, "/model/##[ISA=Compartment]", "init"
) # This is allowed because SymCompartment is a subclass of Compartment
moose.useClock(1, "/model/##", "process")
moose.useClock(2, "/data/##[ISA=Table]", "process")
moose.reinit()
moose.start(simtime)
t = np.linspace(0, simtime, len(tab_soma.vector))
data_matrix = np.vstack((t, tab_soma.vector, tab_d1.vector, tab_d2.vector))
np.savetxt("symcompartment_readcell.txt", data_matrix.transpose())
pylab.plot(t, tab_soma.vector, label="Vm_soma")
pylab.plot(t, tab_d1.vector, label="Vm_d1")
pylab.plot(t, tab_d2.vector, label="Vm_d2")
pylab.show()