Skip to content

Commit 6895e56

Browse files
author
Dilawar Singh
committed
All compiles with python2 and python3.
1 parent d9cb5b7 commit 6895e56

5 files changed

Lines changed: 245 additions & 239 deletions

File tree

tutorials/ChemicalBistables/findSteadyState.py

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -50,73 +50,74 @@
5050
import moose
5151

5252
def displayPlots():
53-
for x in moose.wildcardFind( '/model/graphs/conc#/#' ):
54-
t = numpy.arange( 0, x.vector.size, 1 ) #sec
55-
pylab.plot( t, x.vector, label=x.name )
56-
pylab.legend()
57-
pylab.show()
53+
for x in moose.wildcardFind( '/model/graphs/conc#/#' ):
54+
t = numpy.arange( 0, x.vector.size, 1 ) #sec
55+
pylab.plot( t, x.vector, label=x.name )
56+
pylab.legend()
57+
pylab.show()
5858

5959
def getState( ksolve, state ):
60-
state.randomInit()
61-
moose.start( 0.1 ) # Run the model for 2 seconds.
62-
state.settle()
63-
'''
64-
scale = 1.0 / ( 1e-15 * 6.022e23 )
65-
for x in ksolve.nVec[0]:
66-
print x * scale,
67-
# print ksolve.nVec[0]
68-
print state.nIter, state.status, state.stateType, state.nNegEigenvalues, state.nPosEigenvalues, state.solutionStatus
69-
'''
70-
moose.start( 20.0 ) # Run model for 10 seconds, just for display
60+
state.randomInit()
61+
moose.start( 0.1 ) # Run the model for 2 seconds.
62+
state.settle()
63+
64+
'''
65+
scale = 1.0 / ( 1e-15 * 6.022e23 )
66+
for x in ksolve.nVec[0]:
67+
print x * scale,
68+
# print ksolve.nVec[0]
69+
print state.nIter, state.status, state.stateType, state.nNegEigenvalues, state.nPosEigenvalues, state.solutionStatus
70+
'''
71+
moose.start( 20.0 ) # Run model for 10 seconds, just for display
7172

7273

7374
def main():
74-
# Schedule the whole lot
75-
moose.setClock( 4, 0.1 ) # for the computational objects
76-
moose.setClock( 5, 0.2 ) # clock for the solver
77-
moose.setClock( 8, 1.0 ) # for the plots
78-
# The wildcard uses # for single level, and ## for recursive.
79-
#compartment = makeModel()
80-
moose.loadModel( '../../genesis/M1719.g', '/model', 'ee' )
81-
compartment = moose.element( 'model/kinetics' )
82-
compartment.name = 'compartment'
83-
ksolve = moose.Ksolve( '/model/compartment/ksolve' )
84-
stoich = moose.Stoich( '/model/compartment/stoich' )
85-
stoich.compartment = compartment
86-
stoich.ksolve = ksolve
87-
#ksolve.stoich = stoich
88-
stoich.path = "/model/compartment/##"
89-
state = moose.SteadyState( '/model/compartment/state' )
90-
moose.useClock( 5, '/model/compartment/ksolve', 'process' )
91-
moose.useClock( 8, '/model/graphs/#', 'process' )
75+
# Schedule the whole lot
76+
moose.setClock( 4, 0.1 ) # for the computational objects
77+
moose.setClock( 5, 0.2 ) # clock for the solver
78+
moose.setClock( 8, 1.0 ) # for the plots
79+
# The wildcard uses # for single level, and ## for recursive.
80+
#compartment = makeModel()
81+
moose.loadModel( '../../genesis/M1719.g', '/model', 'ee' )
82+
compartment = moose.element( 'model/kinetics' )
83+
compartment.name = 'compartment'
84+
ksolve = moose.Ksolve( '/model/compartment/ksolve' )
85+
stoich = moose.Stoich( '/model/compartment/stoich' )
86+
stoich.compartment = compartment
87+
stoich.ksolve = ksolve
88+
#ksolve.stoich = stoich
89+
stoich.path = "/model/compartment/##"
90+
state = moose.SteadyState( '/model/compartment/state' )
91+
moose.useClock( 5, '/model/compartment/ksolve', 'process' )
92+
moose.useClock( 8, '/model/graphs/#', 'process' )
9293

93-
moose.reinit()
94-
state.stoich = stoich
95-
#state.showMatrices()
96-
state.convergenceCriterion = 1e-7
94+
moose.reinit()
95+
state.stoich = stoich
96+
#state.showMatrices()
97+
state.convergenceCriterion = 1e-7
9798

98-
for i in range( 0, 50 ):
99-
getState( ksolve, state )
100-
101-
moose.start( 100.0 ) # Run the model for 100 seconds.
99+
for i in range( 0, 50 ):
100+
getState( ksolve, state )
101+
102+
moose.start( 100.0 ) # Run the model for 100 seconds.
102103

103-
b = moose.element( '/model/compartment/b' )
104-
c = moose.element( '/model/compartment/c' )
104+
b = moose.element( '/model/compartment/b' )
105+
c = moose.element( '/model/compartment/c' )
105106

106-
# move most molecules over to b
107-
b.conc = b.conc + c.conc * 0.95
108-
c.conc = c.conc * 0.05
109-
moose.start( 100.0 ) # Run the model for 100 seconds.
107+
# move most molecules over to b
108+
b.conc = b.conc + c.conc * 0.95
109+
c.conc = c.conc * 0.05
110+
moose.start( 100.0 ) # Run the model for 100 seconds.
110111

111-
# move most molecules back to a
112-
c.conc = c.conc + b.conc * 0.95
113-
b.conc = b.conc * 0.05
114-
moose.start( 100.0 ) # Run the model for 100 seconds.
112+
# move most molecules back to a
113+
c.conc = c.conc + b.conc * 0.95
114+
b.conc = b.conc * 0.05
115+
moose.start( 100.0 ) # Run the model for 100 seconds.
115116

116-
# Iterate through all plots, dump their contents to data.plot.
117-
displayPlots()
117+
# Iterate through all plots, dump their contents to data.plot.
118+
displayPlots()
118119

119-
quit()
120+
quit()
120121

121122
# Run the 'main' if this script is executed standalone.
122123
if __name__ == '__main__':

tutorials/ChemicalBistables/mapkFB.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import pylab
1414
import numpy
1515
import sys
16+
import os
17+
18+
scriptDir = os.path.dirname( os.path.realpath( __file__ ) )
1619

1720
def main():
1821
"""
@@ -34,37 +37,39 @@ def main():
3437
'turn off'
3538
by setting the system calcium levels to zero for a while. This
3639
is a somewhat unphysiological manipulation!
40+
3741
"""
42+
3843
solver = "gsl" # Pick any of gsl, gssa, ee..
3944
#solver = "gssa" # Pick any of gsl, gssa, ee..
40-
mfile = '../../genesis/acc35.g'
41-
runtime = 2000.0
42-
if ( len( sys.argv ) == 2 ):
43-
solver = sys.argv[1]
44-
modelId = moose.loadModel( mfile, 'model', solver )
45+
mfile = os.path.join( scriptDir, '..', '..', 'genesis' , 'acc35.g' )
46+
runtime = 2000.0
47+
if ( len( sys.argv ) == 2 ):
48+
solver = sys.argv[1]
49+
modelId = moose.loadModel( mfile, 'model', solver )
4550
# Increase volume so that the stochastic solver gssa
4651
# gives an interesting output
4752
compt = moose.element( '/model/kinetics' )
4853
compt.volume = 5e-19
4954

50-
moose.reinit()
51-
moose.start( 500 )
55+
moose.reinit()
56+
moose.start( 500 )
5257
moose.element( '/model/kinetics/PDGFR/PDGF' ).concInit = 0.0001
53-
moose.start( 400 )
58+
moose.start( 400 )
5459
moose.element( '/model/kinetics/PDGFR/PDGF' ).concInit = 0.0
55-
moose.start( 2000 )
60+
moose.start( 2000 )
5661
moose.element( '/model/kinetics/Ca' ).concInit = 0.0
57-
moose.start( 500 )
62+
moose.start( 500 )
5863
moose.element( '/model/kinetics/Ca' ).concInit = 0.00008
59-
moose.start( 2000 )
64+
moose.start( 2000 )
6065

61-
# Display all plots.
66+
# Display all plots.
6267
img = mpimg.imread( 'mapkFB.png' )
6368
fig = plt.figure( figsize=(12, 10 ) )
6469
png = fig.add_subplot( 211 )
6570
imgplot = plt.imshow( img )
6671
ax = fig.add_subplot( 212 )
67-
x = moose.wildcardFind( '/model/#graphs/conc#/#' )
72+
x = moose.wildcardFind( '/model/#graphs/conc#/#' )
6873
t = numpy.arange( 0, x[0].vector.size, 1 ) * x[0].dt
6974
ax.plot( t, x[0].vector, 'b-', label=x[0].name )
7075
ax.plot( t, x[1].vector, 'c-', label=x[1].name )
@@ -77,4 +82,4 @@ def main():
7782

7883
# Run the 'main' if this script is executed standalone.
7984
if __name__ == '__main__':
80-
main()
85+
main()

tutorials/ChemicalBistables/propagationBis.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -50,70 +50,70 @@
5050
import moose
5151

5252
def makeModel():
53-
# create container for model
54-
r0 = 1e-6 # m
55-
r1 = 0.5e-6 # m. Note taper.
56-
num = 200
57-
diffLength = 1e-6 # m
58-
comptLength = num * diffLength # m
59-
diffConst = 20e-12 # m^2/sec
60-
concA = 1 # millimolar
61-
diffDt = 0.02 # for the diffusion
62-
chemDt = 0.2 # for the reaction
53+
# create container for model
54+
r0 = 1e-6 # m
55+
r1 = 0.5e-6 # m. Note taper.
56+
num = 200
57+
diffLength = 1e-6 # m
58+
comptLength = num * diffLength # m
59+
diffConst = 20e-12 # m^2/sec
60+
concA = 1 # millimolar
61+
diffDt = 0.02 # for the diffusion
62+
chemDt = 0.2 # for the reaction
6363
mfile = '../../genesis/M1719.g'
6464

65-
model = moose.Neutral( 'model' )
66-
compartment = moose.CylMesh( '/model/kinetics' )
65+
model = moose.Neutral( 'model' )
66+
compartment = moose.CylMesh( '/model/kinetics' )
6767

68-
# load in model
68+
# load in model
6969
modelId = moose.loadModel( mfile, '/model', 'ee' )
70-
a = moose.element( '/model/kinetics/a' )
71-
b = moose.element( '/model/kinetics/b' )
72-
c = moose.element( '/model/kinetics/c' )
70+
a = moose.element( '/model/kinetics/a' )
71+
b = moose.element( '/model/kinetics/b' )
72+
c = moose.element( '/model/kinetics/c' )
7373

7474
ac = a.concInit
7575
bc = b.concInit
7676
cc = c.concInit
7777

78-
compartment.r0 = r0
79-
compartment.r1 = r1
80-
compartment.x0 = 0
81-
compartment.x1 = comptLength
82-
compartment.diffLength = diffLength
83-
assert( compartment.numDiffCompts == num )
78+
compartment.r0 = r0
79+
compartment.r1 = r1
80+
compartment.x0 = 0
81+
compartment.x1 = comptLength
82+
compartment.diffLength = diffLength
83+
assert( compartment.numDiffCompts == num )
8484

85-
# Assign parameters
85+
# Assign parameters
8686
for x in moose.wildcardFind( '/model/kinetics/##[ISA=PoolBase]' ):
8787
#print 'pools: ', x, x.name
8888
x.diffConst = diffConst
8989

90-
# Make solvers
91-
ksolve = moose.Ksolve( '/model/kinetics/ksolve' )
92-
dsolve = moose.Dsolve( '/model/dsolve' )
90+
# Make solvers
91+
ksolve = moose.Ksolve( '/model/kinetics/ksolve' )
92+
dsolve = moose.Dsolve( '/model/dsolve' )
9393
# Set up clocks.
94-
moose.setClock( 10, diffDt )
94+
moose.setClock( 10, diffDt )
9595
for i in range( 11, 17 ):
96-
moose.setClock( i, chemDt )
96+
moose.setClock( i, chemDt )
9797

98-
stoich = moose.Stoich( '/model/kinetics/stoich' )
99-
stoich.compartment = compartment
100-
stoich.ksolve = ksolve
101-
stoich.dsolve = dsolve
102-
stoich.path = "/model/kinetics/##"
98+
stoich = moose.Stoich( '/model/kinetics/stoich' )
99+
stoich.compartment = compartment
100+
stoich.ksolve = ksolve
101+
stoich.dsolve = dsolve
102+
stoich.path = "/model/kinetics/##"
103103
print(('dsolve.numPools, num = ', dsolve.numPools, num))
104104
b.vec[num-1].concInit *= 1.01 # Break symmetry.
105105

106106
def main():
107107
runtime = 100
108108
displayInterval = 2
109-
makeModel()
110-
dsolve = moose.element( '/model/dsolve' )
111-
moose.reinit()
112-
#moose.start( runtime ) # Run the model for 10 seconds.
109+
makeModel()
110+
dsolve = moose.element( '/model/dsolve' )
111+
moose.reinit()
112+
#moose.start( runtime ) # Run the model for 10 seconds.
113113

114-
a = moose.element( '/model/kinetics/a' )
115-
b = moose.element( '/model/kinetics/b' )
116-
c = moose.element( '/model/kinetics/c' )
114+
a = moose.element( '/model/kinetics/a' )
115+
b = moose.element( '/model/kinetics/b' )
116+
c = moose.element( '/model/kinetics/c' )
117117

118118
img = mpimg.imread( 'propBis.png' )
119119
#imgplot = plt.imshow( img )
@@ -165,4 +165,4 @@ def main():
165165

166166
# Run the 'main' if this script is executed standalone.
167167
if __name__ == '__main__':
168-
main()
168+
main()

0 commit comments

Comments
 (0)