Skip to content
Snippets Groups Projects
Commit 02fcf721 authored by Dilawar Singh's avatar Dilawar Singh
Browse files

Merge commit 'c37dddbf'

parents 2bd23400 c37dddbf
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,9 @@ import sys
def makeModel():
if len( sys.argv ) == 1:
useGsolve = True
useGsolve = True
else:
useGsolve = ( sys.argv[1] == 'True' )
useGsolve = ( sys.argv[1] == 'True' )
# create container for model
model = moose.Neutral( 'model' )
compartment = moose.CubeMesh( '/model/compartment' )
......@@ -92,11 +92,11 @@ so try to use a table to control a pool instead.
To run in stochastic mode::
''python funcInputToPools''
''python funcInputToPools''
To run in deterministic mode::
''python funcInputToPools false''
''python funcInputToPools false''
"""
......@@ -111,7 +111,7 @@ To run in deterministic mode::
# Iterate through all plots, dump their contents to data.plot.
for x in moose.wildcardFind( '/model/graphs/n#' ):
#x.xplot( 'scriptKineticModel.plot', x.name )
#x.xplot( 'scriptKineticModel.plot', x.name )
t = numpy.arange( 0, x.vector.size, 1 ) * x.dt # sec
pylab.plot( t, x.vector, label=x.name )
pylab.legend()
......
......@@ -6,7 +6,7 @@
# Maintainer:
# Created: Sat Oct 04 12:14:15 2014 (+0530)
# Version:
# Last-Updated:
# Last-Updated: Tue Apr 18 17:40:00 2017(+0530)
# By:
# Update #: 0
# URL:
......@@ -48,53 +48,65 @@ import moose
import pylab
import numpy
import sys
import os
def main():
"""
"""
This example illustrates loading, running, and saving a kinetic
model defined in kkit format. It uses a default kkit model but
you can specify another using the command line
<<<<<<< HEAD
``python filename runtime solver``.
=======
``python filename runtime solver``.
>>>>>>> 0e491aa41584cf7a66c0e242374d8ee61660eb7b
We use the gsl solver here.
``python loadKineticModel.py filepath runtime solver``.
We use default solver as gsl.
The model already defines a couple of plots and sets the runtime 20 secs.
"""
defaultsolver = "gsl" # Pick any of gsl, gssa, ee..
defaultfile = '../genesis/kkit_objects_example.g'
defaultruntime = 20.0
try:
sys.argv[1]
except IndexError:
filepath = defaultfile
else:
filepath = sys.argv[1]
if not os.path.exists(filepath):
print ("Filename or path does not exist \"%s\" loading default file \"%s\" " %(filepath ,defaultfile))
filepath = defaultfile
try:
sys.argv[2]
except :
runtime = defaultruntime
else:
runtime = float(sys.argv[2])
"""
solver = "gsl" # Pick any of gsl, gssa, ee..
mfile = '../genesis/kkit_objects_example.g'
runtime = 20.0
if ( len( sys.argv ) >= 3 ):
if sys.argv[1][0] == '/':
mfile = sys.argv[1]
else:
mfile = '../genesis/' + sys.argv[1]
runtime = float( sys.argv[2] )
if ( len( sys.argv ) == 4 ):
solver = sys.argv[3]
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
try:
sys.argv[3]
except :
solver = defaultsolver
else:
solver = sys.argv[3]
modelId = moose.loadModel( filepath, 'model', solver )
# Increase volume so that the stochastic solver gssa
# gives an interesting output
#compt = moose.element( '/model/kinetics' )
#compt.volume = 1e-19
moose.reinit()
moose.start( runtime )
moose.reinit()
moose.start( runtime )
# Display all plots.
for x in moose.wildcardFind( '/model/#graphs/conc#/#' ):
t = numpy.arange( 0, x.vector.size, 1 ) * x.dt
pylab.plot( t, x.vector, label=x.name )
pylab.legend()
pylab.show()
# Display all plots.
for x in moose.wildcardFind( '/model/#graphs/conc#/#' ):
t = numpy.arange( 0, x.vector.size, 1 ) * x.dt
pylab.plot( t, x.vector, label=x.name )
pylab.legend()
pylab.show()
quit()
quit()
# Run the 'main' if this script is executed standalone.
if __name__ == '__main__':
main()
main()
......@@ -48,35 +48,40 @@ from moose.chemUtil.add_Delete_ChemicalSolver import *
def main():
"""
This example illustrates loading, running of an SBML model defined in XML format.
The model 00001-sbml-l3v1.xml is taken from l3v1 SBML testcase.
Default this file load's 00001-sbml-l3v1.xml which is taken from l3v1 SBML testcase.
Plots are setup.
Model is run for 20sec.
As a general rule we created model under '/path/model' and plots under '/path/graphs'.
If someone wants to load anyother file then
`python loadSbmlmodel filepath runtime`
"""
mfile = "../genesis/00001-sbml-l3v1.xml"
dfilepath = "../genesis/00001-sbml-l3v1.xml"
druntime = 20.0
msg = ""
try:
sys.argv[1]
except:
pass
except IndexError:
filepath = dfilepath
else:
mfile = sys.argv[1]
filepath = sys.argv[1]
if not os.path.exists(filepath):
msg = "Filename or path does not exist",filepath,"loading default file",dfilepath
filepath = dfilepath
try:
sys.argv[2]
except:
runtime = 20.0
except :
runtime = druntime
else:
runtime = float(sys.argv[2])
sbmlId = moose.element('/')
# Loading the sbml file into MOOSE, models are loaded in path/model
sbmlId = moose.SBML.readSBML.mooseReadSBML(mfile,'sbml')
# Loading the sbml file into MOOSE, models are loaded in path/model
sbmlId = mooseReadSBML(mfile,'/sbml')
sbmlId = mooseReadSBML(filepath,'/sbml')
if isinstance(sbmlId, (list, tuple)):
print(sbmlId)
print(sbmlId)
elif sbmlId.path != '/':
s1 = moose.element('/sbml/model/compartment/S1')
......@@ -97,8 +102,8 @@ As a general rule we created model under '/path/model' and plots under '/path/gr
# Reset and Run
moose.reinit()
moose.start(runtime)
return sbmlId,True
return sbmlId,False
return sbmlId,True,msg
return sbmlId,False,msg
def displayPlots():
# Display all plots.
......@@ -112,6 +117,13 @@ def displayPlots():
quit()
if __name__=='__main__':
modelPath, modelpathexist = main()
modelPath = moose.element('/')
modelpathexist = False
msg = ""
modelPath, modelpathexist,msg = main()
if msg:
print (msg)
if modelpathexist == True:
displayPlots()
......@@ -385,21 +385,21 @@ def makeChemInCubeMesh():
assert dendKinaseEnzCplx.volume == dendSide * dendSide * dendSide
def makeSolvers( elecDt ):
# Put in the solvers, see how they fare.
# Here we kludge in a single chem solver for the whole system.
ksolve = moose.Ksolve( '/model/ksolve' )
stoich = moose.Stoich( '/model/stoich' )
stoich.compartment = moose.element( '/model/chem/neuroMesh' )
stoich.ksolve = ksolve
stoich.path = '/model/chem/##'
#stoich.method = 'rk5'
moose.useClock( 5, '/model/ksolve', 'init' )
moose.useClock( 6, '/model/ksolve', 'process' )
# Here is the elec solver
hsolve = moose.HSolve( '/model/hsolve' )
moose.useClock( 1, '/model/hsolve', 'process' )
hsolve.dt = elecDt
hsolve.target = '/model/elec/compt'
# Put in the solvers, see how they fare.
# Here we kludge in a single chem solver for the whole system.
ksolve = moose.Ksolve( '/model/ksolve' )
stoich = moose.Stoich( '/model/stoich' )
stoich.compartment = moose.element( '/model/chem/neuroMesh' )
stoich.ksolve = ksolve
stoich.path = '/model/chem/##'
#stoich.method = 'rk5'
moose.useClock( 5, '/model/ksolve', 'init' )
moose.useClock( 6, '/model/ksolve', 'process' )
# Here is the elec solver
hsolve = moose.HSolve( '/model/hsolve' )
moose.useClock( 1, '/model/hsolve', 'process' )
hsolve.dt = elecDt
hsolve.target = '/model/elec/compt'
def makeCubeMultiscale():
makeSpinyCompt()
......@@ -503,22 +503,22 @@ def testCubeMultiscale( useSolver ):
dumpPlots( plotName,runtime )
def main():
"""
A toy compartmental neuronal + chemical model. The neuronal model is in
a dendrite and five dendritic spines. The chemical model is in three
compartments: one for the dendrite,
one for the spine head, and one for the postsynaptic density. However,
the spatial geometry of the neuronal model is ignored and the chemical
model just has three cubic volumes for each compartment. So there
is a functional mapping but spatial considerations are lost.
The electrical model contributes the incoming calcium flux to the
chemical model. This comes from the synaptic channels.
The signalling here does two things to the electrical model. First, the
amount of receptor in the chemical model controls the amount of glutamate
receptor in the PSD. Second, there is a small kinase reaction that
phosphorylates and inactivates the dendritic potassium channel.
"""
testCubeMultiscale( 1 )
"""
A toy compartmental neuronal + chemical model. The neuronal model is in
a dendrite and five dendritic spines. The chemical model is in three
compartments: one for the dendrite,
one for the spine head, and one for the postsynaptic density. However,
the spatial geometry of the neuronal model is ignored and the chemical
model just has three cubic volumes for each compartment. So there
is a functional mapping but spatial considerations are lost.
The electrical model contributes the incoming calcium flux to the
chemical model. This comes from the synaptic channels.
The signalling here does two things to the electrical model. First, the
amount of receptor in the chemical model controls the amount of glutamate
receptor in the PSD. Second, there is a small kinase reaction that
phosphorylates and inactivates the dendritic potassium channel.
"""
testCubeMultiscale( 1 )
if __name__ == '__main__':
main()
......
......@@ -16,77 +16,77 @@ import moose
try:
input = raw_input
except NameError as e:
pass
pass
def makeModel():
# create container for model
model = moose.Neutral( 'model' )
compartment = moose.CubeMesh( '/model/compartment' )
compartment.volume = 1e-20
# the mesh is created automatically by the compartment
mesh = moose.element( '/model/compartment/mesh' )
# create molecules and reactions
a = moose.Pool( '/model/compartment/a' )
b = moose.Pool( '/model/compartment/b' )
c = moose.Pool( '/model/compartment/c' )
enz1 = moose.Enz( '/model/compartment/b/enz1' )
enz2 = moose.Enz( '/model/compartment/c/enz2' )
cplx1 = moose.Pool( '/model/compartment/b/enz1/cplx' )
cplx2 = moose.Pool( '/model/compartment/c/enz2/cplx' )
reac = moose.Reac( '/model/compartment/reac' )
# connect them up for reactions
moose.connect( enz1, 'sub', a, 'reac' )
moose.connect( enz1, 'prd', b, 'reac' )
moose.connect( enz1, 'enz', b, 'reac' )
moose.connect( enz1, 'cplx', cplx1, 'reac' )
moose.connect( enz2, 'sub', b, 'reac' )
moose.connect( enz2, 'prd', a, 'reac' )
moose.connect( enz2, 'enz', c, 'reac' )
moose.connect( enz2, 'cplx', cplx2, 'reac' )
moose.connect( reac, 'sub', a, 'reac' )
moose.connect( reac, 'prd', b, 'reac' )
# connect them up to the compartment for volumes
#for x in ( a, b, c, cplx1, cplx2 ):
# moose.connect( x, 'mesh', mesh, 'mesh' )
# Assign parameters
a.concInit = 1
b.concInit = 0
c.concInit = 0.01
enz1.kcat = 0.4
enz1.Km = 4
enz2.kcat = 0.6
enz2.Km = 0.01
reac.Kf = 0.001
reac.Kb = 0.01
# Create the output tables
graphs = moose.Neutral( '/model/graphs' )
outputA = moose.Table2( '/model/graphs/concA' )
outputB = moose.Table2( '/model/graphs/concB' )
# connect up the tables
moose.connect( outputA, 'requestOut', a, 'getConc' );
moose.connect( outputB, 'requestOut', b, 'getConc' );
'''
# Schedule the whole lot
moose.setClock( 4, 0.01 ) # for the computational objects
moose.setClock( 8, 1.0 ) # for the plots
# The wildcard uses # for single level, and ## for recursive.
moose.useClock( 4, '/model/compartment/##', 'process' )
moose.useClock( 8, '/model/graphs/#', 'process' )
'''
# create container for model
model = moose.Neutral( 'model' )
compartment = moose.CubeMesh( '/model/compartment' )
compartment.volume = 1e-20
# the mesh is created automatically by the compartment
mesh = moose.element( '/model/compartment/mesh' )
# create molecules and reactions
a = moose.Pool( '/model/compartment/a' )
b = moose.Pool( '/model/compartment/b' )
c = moose.Pool( '/model/compartment/c' )
enz1 = moose.Enz( '/model/compartment/b/enz1' )
enz2 = moose.Enz( '/model/compartment/c/enz2' )
cplx1 = moose.Pool( '/model/compartment/b/enz1/cplx' )
cplx2 = moose.Pool( '/model/compartment/c/enz2/cplx' )
reac = moose.Reac( '/model/compartment/reac' )
# connect them up for reactions
moose.connect( enz1, 'sub', a, 'reac' )
moose.connect( enz1, 'prd', b, 'reac' )
moose.connect( enz1, 'enz', b, 'reac' )
moose.connect( enz1, 'cplx', cplx1, 'reac' )
moose.connect( enz2, 'sub', b, 'reac' )
moose.connect( enz2, 'prd', a, 'reac' )
moose.connect( enz2, 'enz', c, 'reac' )
moose.connect( enz2, 'cplx', cplx2, 'reac' )
moose.connect( reac, 'sub', a, 'reac' )
moose.connect( reac, 'prd', b, 'reac' )
# connect them up to the compartment for volumes
#for x in ( a, b, c, cplx1, cplx2 ):
# moose.connect( x, 'mesh', mesh, 'mesh' )
# Assign parameters
a.concInit = 1
b.concInit = 0
c.concInit = 0.01
enz1.kcat = 0.4
enz1.Km = 4
enz2.kcat = 0.6
enz2.Km = 0.01
reac.Kf = 0.001
reac.Kb = 0.01
# Create the output tables
graphs = moose.Neutral( '/model/graphs' )
outputA = moose.Table2( '/model/graphs/concA' )
outputB = moose.Table2( '/model/graphs/concB' )
# connect up the tables
moose.connect( outputA, 'requestOut', a, 'getConc' );
moose.connect( outputB, 'requestOut', b, 'getConc' );
'''
# Schedule the whole lot
moose.setClock( 4, 0.01 ) # for the computational objects
moose.setClock( 8, 1.0 ) # for the plots
# The wildcard uses # for single level, and ## for recursive.
moose.useClock( 4, '/model/compartment/##', 'process' )
moose.useClock( 8, '/model/graphs/#', 'process' )
'''
def displayPlots():
for x in moose.wildcardFind( '/model/graphs/conc#' ):
t = numpy.arange( 0, x.vector.size, 1 ) #sec
pylab.plot( t, x.vector, label=x.name )
for x in moose.wildcardFind( '/model/graphs/conc#' ):
t = numpy.arange( 0, x.vector.size, 1 ) #sec
pylab.plot( t, x.vector, label=x.name )
def main():
......
......@@ -13,113 +13,112 @@ import numpy
import moose
def makeModel():
# create container for model
model = moose.Neutral( 'model' )
compartment = moose.CubeMesh( '/model/compartment' )
compartment.volume = 1e-20
# the mesh is created automatically by the compartment
mesh = moose.element( '/model/compartment/mesh' )
# create molecules and reactions
a = moose.Pool( '/model/compartment/a' )
b = moose.Pool( '/model/compartment/b' )
c = moose.Pool( '/model/compartment/c' )
enz1 = moose.Enz( '/model/compartment/b/enz1' )
enz2 = moose.Enz( '/model/compartment/c/enz2' )
cplx1 = moose.Pool( '/model/compartment/b/enz1/cplx' )
cplx2 = moose.Pool( '/model/compartment/c/enz2/cplx' )
reac = moose.Reac( '/model/compartment/reac' )
# connect them up for reactions
moose.connect( enz1, 'sub', a, 'reac' )
moose.connect( enz1, 'prd', b, 'reac' )
moose.connect( enz1, 'enz', b, 'reac' )
moose.connect( enz1, 'cplx', cplx1, 'reac' )
moose.connect( enz2, 'sub', b, 'reac' )
moose.connect( enz2, 'prd', a, 'reac' )
moose.connect( enz2, 'enz', c, 'reac' )
moose.connect( enz2, 'cplx', cplx2, 'reac' )
moose.connect( reac, 'sub', a, 'reac' )
moose.connect( reac, 'prd', b, 'reac' )
# connect them up to the compartment for volumes
#for x in ( a, b, c, cplx1, cplx2 ):
# moose.connect( x, 'mesh', mesh, 'mesh' )
# Assign parameters
a.concInit = 1
b.concInit = 0
c.concInit = 0.01
enz1.kcat = 0.4
enz1.Km = 4
enz2.kcat = 0.6
enz2.Km = 0.01
reac.Kf = 0.001
reac.Kb = 0.01
# Create the output tables
graphs = moose.Neutral( '/model/graphs' )
outputA = moose.Table2 ( '/model/graphs/concA' )
outputB = moose.Table2 ( '/model/graphs/concB' )
# connect up the tables
moose.connect( outputA, 'requestOut', a, 'getConc' );
moose.connect( outputB, 'requestOut', b, 'getConc' );
# create container for model
model = moose.Neutral( 'model' )
compartment = moose.CubeMesh( '/model/compartment' )
compartment.volume = 1e-20
# the mesh is created automatically by the compartment
mesh = moose.element( '/model/compartment/mesh' )
# create molecules and reactions
a = moose.Pool( '/model/compartment/a' )
b = moose.Pool( '/model/compartment/b' )
c = moose.Pool( '/model/compartment/c' )
enz1 = moose.Enz( '/model/compartment/b/enz1' )
enz2 = moose.Enz( '/model/compartment/c/enz2' )
cplx1 = moose.Pool( '/model/compartment/b/enz1/cplx' )
cplx2 = moose.Pool( '/model/compartment/c/enz2/cplx' )
reac = moose.Reac( '/model/compartment/reac' )
# connect them up for reactions
moose.connect( enz1, 'sub', a, 'reac' )
moose.connect( enz1, 'prd', b, 'reac' )
moose.connect( enz1, 'enz', b, 'reac' )
moose.connect( enz1, 'cplx', cplx1, 'reac' )
moose.connect( enz2, 'sub', b, 'reac' )
moose.connect( enz2, 'prd', a, 'reac' )
moose.connect( enz2, 'enz', c, 'reac' )
moose.connect( enz2, 'cplx', cplx2, 'reac' )
moose.connect( reac, 'sub', a, 'reac' )
moose.connect( reac, 'prd', b, 'reac' )
# connect them up to the compartment for volumes
#for x in ( a, b, c, cplx1, cplx2 ):
# moose.connect( x, 'mesh', mesh, 'mesh' )
# Assign parameters
a.concInit = 1
b.concInit = 0
c.concInit = 0.01
enz1.kcat = 0.4
enz1.Km = 4
enz2.kcat = 0.6
enz2.Km = 0.01
reac.Kf = 0.001
reac.Kb = 0.01
# Create the output tables
graphs = moose.Neutral( '/model/graphs' )
outputA = moose.Table2 ( '/model/graphs/concA' )
outputB = moose.Table2 ( '/model/graphs/concB' )
# connect up the tables
moose.connect( outputA, 'requestOut', a, 'getConc' );
moose.connect( outputB, 'requestOut', b, 'getConc' );
def displayPlots():
for x in moose.wildcardFind( '/model/graphs/conc#' ):
t = numpy.arange( 0, x.vector.size, 1 ) #sec
pylab.plot( t, x.vector, label=x.name )
pylab.legend()
pylab.show()
for x in moose.wildcardFind( '/model/graphs/conc#' ):
t = numpy.arange( 0, x.vector.size, 1 ) #sec
pylab.plot( t, x.vector, label=x.name )
pylab.legend()
pylab.show()
def main():
"""
This example illustrates how to set up a kinetic solver and kinetic model
using the scripting interface. Normally this would be done using the
Shell::doLoadModel command, and normally would be coordinated by the
SimManager as the base of the entire model.
This example creates a bistable model having two enzymes and a reaction.
One of the enzymes is autocatalytic.
The model is set up to run using Exponential Euler integration.
"""
makeModel()
gsolve = moose.Gsolve( '/model/compartment/gsolve' )
stoich = moose.Stoich( '/model/compartment/stoich' )
stoich.compartment = moose.element( '/model/compartment' )
stoich.ksolve = gsolve
stoich.path = "/model/compartment/##"
#solver.method = "rk5"
#mesh = moose.element( "/model/compartment/mesh" )
#moose.connect( mesh, "remesh", solver, "remesh" )
moose.setClock( 5, 1.0 ) # clock for the solver
moose.useClock( 5, '/model/compartment/gsolve', 'process' )
moose.reinit()
moose.start( 100.0 ) # Run the model for 100 seconds.
a = moose.element( '/model/compartment/a' )
b = moose.element( '/model/compartment/b' )
# move most molecules over to bgsolve
b.conc = b.conc + a.conc * 0.9
a.conc = a.conc * 0.1
moose.start( 100.0 ) # Run the model for 100 seconds.
# move most molecules back to a
a.conc = a.conc + b.conc * 0.99
b.conc = b.conc * 0.01
moose.start( 100.0 ) # Run the model for 100 seconds.
# Iterate through all plots, dump their contents to data.plot.
displayPlots()
quit()
"""
This example illustrates how to set up a kinetic solver and kinetic model
using the scripting interface. Normally this would be done using the
Shell::doLoadModel command, and normally would be coordinated by the
SimManager as the base of the entire model.
This example creates a bistable model having two enzymes and a reaction.
One of the enzymes is autocatalytic.
The model is set up to run using Exponential Euler integration.
"""
makeModel()
gsolve = moose.Gsolve( '/model/compartment/gsolve' )
stoich = moose.Stoich( '/model/compartment/stoich' )
stoich.compartment = moose.element( '/model/compartment' )
stoich.ksolve = gsolve
stoich.path = "/model/compartment/##"
#solver.method = "rk5"
#mesh = moose.element( "/model/compartment/mesh" )
#moose.connect( mesh, "remesh", solver, "remesh" )
moose.setClock( 5, 1.0 ) # clock for the solver
moose.useClock( 5, '/model/compartment/gsolve', 'process' )
moose.reinit()
moose.start( 100.0 ) # Run the model for 100 seconds.
a = moose.element( '/model/compartment/a' )
b = moose.element( '/model/compartment/b' )
# move most molecules over to bgsolve
b.conc = b.conc + a.conc * 0.9
a.conc = a.conc * 0.1
moose.start( 100.0 ) # Run the model for 100 seconds.
# move most molecules back to a
a.conc = a.conc + b.conc * 0.99
b.conc = b.conc * 0.01
moose.start( 100.0 ) # Run the model for 100 seconds.
# Iterate through all plots, dump their contents to data.plot.
displayPlots()
quit()
# Run the 'main' if this script is executed standalone.
if __name__ == '__main__':
main()
main()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment