diff --git a/moose-examples/snippets/RandSpikeStats.py b/moose-examples/snippets/RandSpikeStats.py index 377dc18b9659f1ad0c90b8a851aace2949605d60..725ae5d0ac9cc29af6fff70178ae2d747d7e4198 100644 --- a/moose-examples/snippets/RandSpikeStats.py +++ b/moose-examples/snippets/RandSpikeStats.py @@ -141,8 +141,6 @@ def main(): moose.setClock( i, dt ) moose.useClock( 8, '/plot#', 'process' ) ''' - - # Run the 'main' if this script is executed standalone. if __name__ == '__main__': main() diff --git a/moose-examples/snippets/analogStimTable.py b/moose-examples/snippets/analogStimTable.py index f7ce328caa05764ced9b49b6cccaf98204393e79..941de47ec9cf8bb309eee68a50e5cefa2d35dfc1 100644 --- a/moose-examples/snippets/analogStimTable.py +++ b/moose-examples/snippets/analogStimTable.py @@ -95,5 +95,6 @@ if __name__ == '__main__': main() >>>>>>> 0e491aa41584cf7a66c0e242374d8ee61660eb7b + # # stimtable.py ends here diff --git a/moose-examples/snippets/crossComptSimpleReac.py b/moose-examples/snippets/crossComptSimpleReac.py index ddfea60bcdd8bedc6b1a615e371da0334e25706b..e3fffe80d3887f62251259dc95bd25a83a08c617 100644 --- a/moose-examples/snippets/crossComptSimpleReac.py +++ b/moose-examples/snippets/crossComptSimpleReac.py @@ -11,84 +11,84 @@ import math import matplotlib.pyplot as plt -import numpy +import numpy as np import moose def makeModel(): - # create container for model - model = moose.Neutral( 'model' ) - compt0 = moose.CubeMesh( '/model/compt0' ) - compt0.volume = 1e-15 - compt1 = moose.CubeMesh( '/model/compt1' ) - compt1.volume = 1e-16 - compt2 = moose.CubeMesh( '/model/compt2' ) - compt2.volume = 1e-17 - - # Position containers so that they abut each other, with - # compt1 in the middle. - side = compt1.dy - compt0.y1 += side - compt0.y0 += side - compt2.x1 += side - compt2.x0 += side - print(('Volumes = ', compt0.volume, compt1.volume, compt2.volume)) - - # create molecules and reactions - a = moose.Pool( '/model/compt0/a' ) - b = moose.Pool( '/model/compt1/b' ) - c = moose.Pool( '/model/compt2/c' ) - reac0 = moose.Reac( '/model/compt1/reac0' ) - reac1 = moose.Reac( '/model/compt1/reac1' ) - - # connect them up for reactions - moose.connect( reac0, 'sub', a, 'reac' ) - moose.connect( reac0, 'prd', b, 'reac' ) - moose.connect( reac1, 'sub', b, 'reac' ) - moose.connect( reac1, 'prd', c, 'reac' ) - - # Assign parameters - a.concInit = 1 - b.concInit = 12.1 - c.concInit = 1 - reac0.Kf = 0.1 - reac0.Kb = 0.1 - reac1.Kf = 0.1 - reac1.Kb = 0.1 - - # Create the output tables - graphs = moose.Neutral( '/model/graphs' ) - outputA = moose.Table2 ( '/model/graphs/concA' ) - outputB = moose.Table2 ( '/model/graphs/concB' ) - outputC = moose.Table2 ( '/model/graphs/concC' ) - - # connect up the tables - moose.connect( outputA, 'requestOut', a, 'getConc' ); - moose.connect( outputB, 'requestOut', b, 'getConc' ); - moose.connect( outputC, 'requestOut', c, 'getConc' ); - - # Build the solvers. No need for diffusion in this version. - ksolve0 = moose.Ksolve( '/model/compt0/ksolve0' ) - ksolve1 = moose.Ksolve( '/model/compt1/ksolve1' ) - ksolve2 = moose.Ksolve( '/model/compt2/ksolve2' ) - stoich0 = moose.Stoich( '/model/compt0/stoich0' ) - stoich1 = moose.Stoich( '/model/compt1/stoich1' ) - stoich2 = moose.Stoich( '/model/compt2/stoich2' ) - - # Configure solvers - stoich0.compartment = compt0 - stoich1.compartment = compt1 - stoich2.compartment = compt2 - stoich0.ksolve = ksolve0 - stoich1.ksolve = ksolve1 - stoich2.ksolve = ksolve2 - stoich0.path = '/model/compt0/#' - stoich1.path = '/model/compt1/#' - stoich2.path = '/model/compt2/#' - stoich1.buildXreacs( stoich0 ) - stoich1.buildXreacs( stoich2 ) - stoich0.filterXreacs() - stoich1.filterXreacs() - stoich2.filterXreacs() + # create container for model + model = moose.Neutral( 'model' ) + compt0 = moose.CubeMesh( '/model/compt0' ) + compt0.volume = 1e-15 + compt1 = moose.CubeMesh( '/model/compt1' ) + compt1.volume = 1e-16 + compt2 = moose.CubeMesh( '/model/compt2' ) + compt2.volume = 1e-17 + + # Position containers so that they abut each other, with + # compt1 in the middle. + side = compt1.dy + compt0.y1 += side + compt0.y0 += side + compt2.x1 += side + compt2.x0 += side + print(('Volumes = ', compt0.volume, compt1.volume, compt2.volume)) + + # create molecules and reactions + a = moose.Pool( '/model/compt0/a' ) + b = moose.Pool( '/model/compt1/b' ) + c = moose.Pool( '/model/compt2/c' ) + reac0 = moose.Reac( '/model/compt1/reac0' ) + reac1 = moose.Reac( '/model/compt1/reac1' ) + + # connect them up for reactions + moose.connect( reac0, 'sub', a, 'reac' ) + moose.connect( reac0, 'prd', b, 'reac' ) + moose.connect( reac1, 'sub', b, 'reac' ) + moose.connect( reac1, 'prd', c, 'reac' ) + + # Assign parameters + a.concInit = 1 + b.concInit = 12.1 + c.concInit = 1 + reac0.Kf = 0.1 + reac0.Kb = 0.1 + reac1.Kf = 0.1 + reac1.Kb = 0.1 + + # Create the output tables + graphs = moose.Neutral( '/model/graphs' ) + outputA = moose.Table2 ( '/model/graphs/concA' ) + outputB = moose.Table2 ( '/model/graphs/concB' ) + outputC = moose.Table2 ( '/model/graphs/concC' ) + + # connect up the tables + moose.connect( outputA, 'requestOut', a, 'getConc' ); + moose.connect( outputB, 'requestOut', b, 'getConc' ); + moose.connect( outputC, 'requestOut', c, 'getConc' ); + + # Build the solvers. No need for diffusion in this version. + ksolve0 = moose.Ksolve( '/model/compt0/ksolve0' ) + ksolve1 = moose.Ksolve( '/model/compt1/ksolve1' ) + ksolve2 = moose.Ksolve( '/model/compt2/ksolve2' ) + stoich0 = moose.Stoich( '/model/compt0/stoich0' ) + stoich1 = moose.Stoich( '/model/compt1/stoich1' ) + stoich2 = moose.Stoich( '/model/compt2/stoich2' ) + + # Configure solvers + stoich0.compartment = compt0 + stoich1.compartment = compt1 + stoich2.compartment = compt2 + stoich0.ksolve = ksolve0 + stoich1.ksolve = ksolve1 + stoich2.ksolve = ksolve2 + stoich0.path = '/model/compt0/#' + stoich1.path = '/model/compt1/#' + stoich2.path = '/model/compt2/#' + stoich1.buildXreacs( stoich0 ) + stoich1.buildXreacs( stoich2 ) + stoich0.filterXreacs() + stoich1.filterXreacs() + stoich2.filterXreacs() @@ -142,13 +142,17 @@ def main(): # FIXME: Plotting causes seg-fault. ## Iterate through all plots, dump their contents to data.plot. - #for x in moose.wildcardFind( '/model/graphs/conc#' ): - # t = numpy.linspace( 0, runtime, x.vector.size ) # sec - # plt.plot( t, x.vector, label=x.name ) - #plt.legend() - #plt.show() - #quit() - + ### Temp fix, if try to save and plot the graph doesn't give seg fault + for x in moose.wildcardFind( '/model/graphs/conc#' ): + t = np.arange( 0, x.vector.size, 1) # sec + graphpath = x.name+".csv" + #t = np.linspace( 0, runtime,x.vector.size) # sec + f = open(graphpath, "w") + np.savetxt(graphpath, np.vstack((t*plotdt,x.vector))) + plt.plot( t, x.vector, label=x.name ) + plt.legend() + plt.show() + quit() # Run the 'main' if this script is executed standalone. if __name__ == '__main__': main() diff --git a/moose-examples/snippets/cspaceSteadyState.py b/moose-examples/snippets/cspaceSteadyState.py index 12ebb3b87ec413a3f6f29fd4b74f826a49041989..7cd2f012fa2b0b359d8f6aa3e515c9fc0976d0d1 100644 --- a/moose-examples/snippets/cspaceSteadyState.py +++ b/moose-examples/snippets/cspaceSteadyState.py @@ -13,28 +13,28 @@ import numpy import moose 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() + 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() - ''' - scale = 1.0 / ( 1e-15 * 6.022e23 ) - for x in ksolve.nVec[0]: - print x * scale, - # print ksolve.nVec[0] - print state.nIter, state.status, state.stateType, state.nNegEigenvalues, state.nPosEigenvalues, state.solutionStatus - ''' - moose.start( 20.0 ) # Run model for 10 seconds, just for display + state.randomInit() + moose.start( 0.1 ) # Run the model for 2 seconds. + state.settle() + ''' + scale = 1.0 / ( 1e-15 * 6.022e23 ) + for x in ksolve.nVec[0]: + print x * scale, + # print ksolve.nVec[0] + print state.nIter, state.status, state.stateType, state.nNegEigenvalues, state.nPosEigenvalues, state.solutionStatus + ''' + moose.start( 20.0 ) # Run model for 10 seconds, just for display def main(): - """ + """ This example sets up the kinetic solver and steady-state finder, on a bistable model. It looks for the fixed points 100 times, as follows: @@ -91,53 +91,53 @@ def main(): this algorithm! You may wish to sample concentration space logarithmically rather than linearly. - """ - # The wildcard uses # for single level, and ## for recursive. - #compartment = makeModel() - moose.loadModel( '../genesis/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.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() + """ + # The wildcard uses # for single level, and ## for recursive. + #compartment = makeModel() + moose.loadModel( '../genesis/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.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() # Run the 'main' if this script is executed standalone. if __name__ == '__main__': - main() + main() diff --git a/moose-examples/snippets/funcInputToPools.py b/moose-examples/snippets/funcInputToPools.py index 3a8d06fa28d574001d48d4282f01c713e4c9d4fe..45f5c1da9d4f826fe92e3fc5207852e698fef3e7 100644 --- a/moose-examples/snippets/funcInputToPools.py +++ b/moose-examples/snippets/funcInputToPools.py @@ -154,9 +154,6 @@ def makeModel(): stoich.compartment = compartment stoich.ksolve = gsolve stoich.path = '/model/compartment/##' - ''' - ''' - # We need a finer timestep than the default 0.1 seconds, # in order to get numerical accuracy. for i in range (10, 19 ): @@ -164,27 +161,27 @@ def makeModel(): def main(): """ - This example describes the special (and discouraged) use case where - functions provide input to a reaction system. Here we have two functions of - time which control the pool # and pool rate of change, respectively:: +This example describes the special (and discouraged) use case where +functions provide input to a reaction system. Here we have two functions of +time which control the pool # and pool rate of change, respectively:: - number of molecules of a = 1 + sin(t) - rate of change of number of molecules of b = 10 * cos(t) +number of molecules of a = 1 + sin(t) +rate of change of number of molecules of b = 10 * cos(t) - In the stochastic case one must set a special flag *useClockedUpdate* - in order to achieve clock-triggered updates from the functions. This is - needed because the functions do not have reaction events to trigger them, - and even if there were reaction events they might not be frequent enough to - track the periodic updates. The use of this flag slows down the calculations, - so try to use a table to control a pool instead. +In the stochastic case one must set a special flag *useClockedUpdate* +in order to achieve clock-triggered updates from the functions. This is +needed because the functions do not have reaction events to trigger them, +and even if there were reaction events they might not be frequent enough to +track the periodic updates. The use of this flag slows down the calculations, +so try to use a table to control a pool instead. - To run in stochastic mode:: +To run in stochastic mode:: - ''python funcInputToPools'' + ''python funcInputToPools'' - To run in deterministic mode:: +To run in deterministic mode:: - ''python funcInputToPools false'' + ''python funcInputToPools false'' """ @@ -222,4 +219,4 @@ def main(): # Run the 'main' if this script is executed standalone. if __name__ == '__main__': - main() + main() \ No newline at end of file diff --git a/moose-examples/snippets/intfire.py b/moose-examples/snippets/intfire.py deleted file mode 100644 index 35f8fcb9ea245df9b65b40afe7e5ee96ccb5115c..0000000000000000000000000000000000000000 --- a/moose-examples/snippets/intfire.py +++ /dev/null @@ -1,128 +0,0 @@ -<<<<<<< HEAD - -======= ->>>>>>> 0e491aa41584cf7a66c0e242374d8ee61660eb7b -# intfire.py --- -# -# Filename: intfire.py -# Description: -# Author:Subhasis Ray -# Maintainer: -# Created: Thu Jun 21 16:40:25 2012 (+0530) -# Version: -# Last-Updated: Sat Jun 23 13:44:10 2012 (+0530) -# By: subha -# Update #: 35 -# URL: -# Keywords: -# Compatibility: -# -# - -# Commentary: -# -# Code snippet to show some operations on IntFire. -# -# - -# Change log: -# -# -# -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, Fifth -# Floor, Boston, MA 02110-1301, USA. -# -# - -# Code: - -import moose - -def connect_two_intfires(): - """ -Connect two IntFire neurons so that spike events in one gets -transmitted to synapse of the other. -<<<<<<< HEAD -======= - ->>>>>>> 0e491aa41584cf7a66c0e242374d8ee61660eb7b - """ - if1 = moose.IntFire('if1') - if2 = moose.IntFire('if2') - sf1 = moose.SimpleSynHandler( 'if1/sh' ) - moose.connect( sf1, 'activationOut', if1, 'activation' ) - sf1.synapse.num = 1 - syn1 = moose.element(sf1.synapse) - # Connect the spike message of if2 to the first synapse on if1 - moose.connect(if2, 'spikeOut', syn1, 'addSpike') - -def connect_spikegen(): - """ -Connect a SpikeGen object to an IntFire neuron such that spike -events in spikegen get transmitted to the synapse of the IntFire -neuron. - -<<<<<<< HEAD - """ - if3 = moose.IntFire('if3') -======= -if3 = moose.IntFire('if3') - """ ->>>>>>> 0e491aa41584cf7a66c0e242374d8ee61660eb7b - sf3 = moose.SimpleSynHandler( 'if3/sh' ) - moose.connect( sf3, 'activationOut', if3, 'activation' ) - sf3.synapse.num = 1 - sg = moose.SpikeGen('sg') - syn = moose.element(sf3.synapse) - moose.connect(sg, 'spikeOut', syn, 'addSpike') - -def setup_synapse(): - """ -Create an intfire object and create two synapses on it. -<<<<<<< HEAD -======= - ->>>>>>> 0e491aa41584cf7a66c0e242374d8ee61660eb7b - """ - if4 = moose.IntFire('if4') - sf4 = moose.SimpleSynHandler( 'if4/sh' ) - sg1 = moose.SpikeGen('sg1') - sg2 = moose.SpikeGen('sg2') - sf4.synapse.num = 2 # set synapse count to 2 - sf4.synapse[0].weight = 0.5 - sf4.synapse[0].delay = 1e-3 - sf4.synapse[1].weight = 2.0 - sf4.synapse[1].delay = 2e-3 - moose.connect(sg1, 'spikeOut', sf4.synapse[0], 'addSpike') - moose.connect(sg2, 'spikeOut', sf4.synapse[1], 'addSpike') - -def main(): - """ -Demonstrates connection between 2 IntFire neurons to observe -spike generation. -<<<<<<< HEAD -======= - ->>>>>>> 0e491aa41584cf7a66c0e242374d8ee61660eb7b - """ - connect_two_intfires() - connect_spikegen() - setup_synapse() - -if __name__ == '__main__': - main() -# -# intfire.py ends here diff --git a/moose-examples/snippets/loadKineticModel.py b/moose-examples/snippets/loadKineticModel.py deleted file mode 100644 index 25c3f69e5144bc7419ca827e16314e41d1b4c0cb..0000000000000000000000000000000000000000 --- a/moose-examples/snippets/loadKineticModel.py +++ /dev/null @@ -1,100 +0,0 @@ -# loadKineticModel.py --- -# -# Filename: loadKineticModel.py -# Description: -# Author: Upi Bhalla -# Maintainer: -# Created: Sat Oct 04 12:14:15 2014 (+0530) -# Version: -# Last-Updated: -# By: -# Update #: 0 -# URL: -# Keywords: -# Compatibility: -# -# - -# Commentary: -# -# -# -# - -# Change log: -# -# -# -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 3, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, Fifth -# Floor, Boston, MA 02110-1301, USA. -# -# -# Code: - -import moose -import pylab -import numpy -import sys - -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. - The model already defines a couple of plots and sets the runtime 20 secs. - - """ - 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 - - 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() - - quit() - -# Run the 'main' if this script is executed standalone. -if __name__ == '__main__': - main()