import math
import pylab
import numpy
import moose
%matplotlib inline
def displayPlots():
for x in moose.wildcardFind( '/model/graphs/#' ):
t = numpy.arange( 0, x.vector.size, 1 ) #sec
pylab.plot( t, x.vector, label=x.name )
pylab.legend()
pylab.show()
def getState( ksolve, state ):
state.randomInit()
moose.start( 0.1 ) # Run the model for 2 seconds.
state.settle()
moose.start( 20.0 ) # Run model for 10 seconds, just for display
def main():
#One can build own model or load pre-existing model
#Here we have taken pre-existing model which is in cspace format
moose.loadModel( '../../../../moose-examples/genesis/M1719.cspace', '/model', 'ee' )
compartment = moose.element( 'model/kinetics' )
compartment.name = 'compartment'
#setting up the solver
ksolve = moose.Ksolve( '/model/compartment/ksolve' )
stoich = moose.Stoich( '/model/compartment/stoich' )
stoich.compartment = compartment
stoich.ksolve = ksolve
stoich.path = "/model/compartment/##"
#setting up state
state = moose.SteadyState( '/model/compartment/state' )
moose.reinit()
state.stoich = stoich
state.convergenceCriterion = 1e-7
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()
# Run the 'main' if this script is executed standalone.
if __name__ == '__main__':
main()