From 3aff900866223de07d69a86a095c310024bb6f34 Mon Sep 17 00:00:00 2001 From: Dilawar Singh <dilawars@ncbs.res.in> Date: Fri, 2 Mar 2018 16:51:20 +0530 Subject: [PATCH] Squashed 'moose-examples/' changes from bd41d06..3047477 3047477 python3/python2 compatible call to raw_input. git-subtree-dir: moose-examples git-subtree-split: 3047477ce74705290cb282ac1dca7fcff3f4cf3f --- paper-2015/Fig6_NetMultiscale/ReducedModel.py | 5 ++++- snippets/IntegrateFireZoo.py | 8 +++++++- snippets/cylinderDiffusion.py | 7 ++++--- snippets/diffSpinyNeuron.py | 8 ++++++-- snippets/gssaRDspiny.py | 7 +++++-- snippets/reacDiffBranchingNeuron.py | 16 +++++----------- tutorials/ChemicalBistables/propagationBis.py | 5 ++++- tutorials/ChemicalBistables/scaleVolumes.py | 8 +++++--- tutorials/ChemicalBistables/simpleBis.py | 5 ++++- tutorials/ChemicalOscillators/TuringOneDim.py | 5 ++++- 10 files changed, 48 insertions(+), 26 deletions(-) diff --git a/paper-2015/Fig6_NetMultiscale/ReducedModel.py b/paper-2015/Fig6_NetMultiscale/ReducedModel.py index 3f151cb3..d7314107 100644 --- a/paper-2015/Fig6_NetMultiscale/ReducedModel.py +++ b/paper-2015/Fig6_NetMultiscale/ReducedModel.py @@ -885,4 +885,7 @@ if __name__=='__main__': plt.show() plt.savefig( fname + '.svg', bbox_inches='tight') print( "Hit 'enter' to exit" ) - input() + try: + raw_input() + except Exception as e: + input( ) diff --git a/snippets/IntegrateFireZoo.py b/snippets/IntegrateFireZoo.py index 0fe761a0..dc40a584 100644 --- a/snippets/IntegrateFireZoo.py +++ b/snippets/IntegrateFireZoo.py @@ -120,7 +120,13 @@ def main(): #choiceKey = 'LIF' #### No need, am inputting it from the user on the terminal choiceKeys = list(neuronChoices.keys()) # keys() does not retain the order in dict defn above! - choiceIndex = eval(str(input('Choose a number corresponding to your desired neuron: '+str([(i,key) for (i,key) in enumerate(choiceKeys)])+' -- '))) + + try: + v = raw_input('Choose a number corresponding to your desired neuron: '+str([(i,key) for (i,key) in enumerate(choiceKeys)])+' -- ') + except NameError as e: + v = input('Choose a number corresponding to your desired neuron: '+str([(i,key) for (i,key) in enumerate(choiceKeys)])+' -- ') + + choiceIndex = eval(v) choiceKey = choiceKeys[choiceIndex] neuronChoice = neuronChoices[choiceKey] diff --git a/snippets/cylinderDiffusion.py b/snippets/cylinderDiffusion.py index a2c21570..f7c5095a 100644 --- a/snippets/cylinderDiffusion.py +++ b/snippets/cylinderDiffusion.py @@ -184,11 +184,12 @@ def main(): print((atot2/atot, btot2/btot, ctot2/ctot, dtot2/dtot)) print(('Initial to final (b+c)=', (btot2 + ctot2) / (btot + ctot ))) print("\nHit '0' to exit") - eval(str(input())) - + try: + raw_input( ) + except NameError as e: # python3 + input( ) quit() - # Run the 'main' if this script is executed standalone. if __name__ == '__main__': main() diff --git a/snippets/diffSpinyNeuron.py b/snippets/diffSpinyNeuron.py index 5749b95e..06ae26d3 100644 --- a/snippets/diffSpinyNeuron.py +++ b/snippets/diffSpinyNeuron.py @@ -103,7 +103,7 @@ def makeModel(): stoich2.filterXreacs() Ca_input_dend = moose.vec( '/model/chem/compt0/Ca_input' ) - print((len( Ca_input_dend ))) + print(len( Ca_input_dend )) for i in range( 60 ): Ca_input_dend[ 3 + i * 3 ].conc = 2.0 @@ -197,8 +197,12 @@ def finalizeDisplay( plotlist, cPlotDt ): pos = numpy.arange( 0, x.vector.size, 1 ) * cPlotDt line1, = plotlist[0].plot( pos, x.vector, label=x.name ) plotlist[4].canvas.draw() + print( "Hit '0' to exit" ) - raw_input() + try: + raw_input() + except NameError as e: #python3 + input( ) def makeChemModel( compt, doInput ): """ diff --git a/snippets/gssaRDspiny.py b/snippets/gssaRDspiny.py index 6308e5bc..8b3269ad 100644 --- a/snippets/gssaRDspiny.py +++ b/snippets/gssaRDspiny.py @@ -180,8 +180,11 @@ def finalizeDisplay( plotlist, cPlotDt ): pos = numpy.arange( 0, x.vector.size, 1 ) * cPlotDt line1, = plotlist[0].plot( pos, x.vector, label=x.name ) plotlist[4].canvas.draw() - print( "Hit '0' to exit" ) - eval(str(input())) + print( "Hit any key to exit" ) + try: + raw_input( ) + except NameError as e: + input( ) def makeChemModel( compt ): """ diff --git a/snippets/reacDiffBranchingNeuron.py b/snippets/reacDiffBranchingNeuron.py index 96ddc145..018717d2 100644 --- a/snippets/reacDiffBranchingNeuron.py +++ b/snippets/reacDiffBranchingNeuron.py @@ -112,28 +112,22 @@ def finalizeDisplay( plotlist, cPlotDt ): line1, = plotlist[0].plot( pos, x.vector, label=x.name ) plt.legend() plotlist[1].canvas.draw() - print( "Hit '0' to exit" ) - eval(str(input())) + print( "Hit any key to exit" ) + try: + a = raw_input( ) + except NameError as e: + a = input( ) def makeChemModel( compt ): """ This function sets up a simple oscillatory chemical system within the script. The reaction system is:: -<<<<<<< HEAD s ---a---> a // s goes to a, catalyzed by a. s ---a---> b // s goes to b, catalyzed by a. a ---b---> s // a goes to s, catalyzed by b. b -------> s // b is degraded irreversibly to s. -======= - - s ---a---> a // s goes to a, catalyzed by a. - s ---a---> b // s goes to b, catalyzed by a. - a ---b---> s // a goes to s, catalyzed by b. - b -------> s // b is degraded irreversibly to s. - ->>>>>>> 0e491aa41584cf7a66c0e242374d8ee61660eb7b in sum, **a** has a positive feedback onto itself and also forms **b**. **b** has a negative feedback onto **a**. Finally, the diffusion constant for **a** is 1/10 that of **b**. diff --git a/tutorials/ChemicalBistables/propagationBis.py b/tutorials/ChemicalBistables/propagationBis.py index add79df3..8b982c63 100644 --- a/tutorials/ChemicalBistables/propagationBis.py +++ b/tutorials/ChemicalBistables/propagationBis.py @@ -159,7 +159,10 @@ def main(): fig.canvas.draw() print( "Hit 'enter' to exit" ) - eval(input()) + try: + raw_input( ) + except NameError as e: # python3 + input( ) diff --git a/tutorials/ChemicalBistables/scaleVolumes.py b/tutorials/ChemicalBistables/scaleVolumes.py index 66b869ff..49bf206e 100644 --- a/tutorials/ChemicalBistables/scaleVolumes.py +++ b/tutorials/ChemicalBistables/scaleVolumes.py @@ -153,9 +153,11 @@ def main(): # Iterate through all plots, dump their contents to data.plot. displayPlots() pylab.show( block=False ) - print(('vol = ', vol, 'hit enter to go to next plot')) - input() - + print( 'vol = %f . hit enter to go to next plot' % vol ) + try: + raw_input() + except NameError as e: + input( ) quit() # Run the 'main' if this script is executed standalone. diff --git a/tutorials/ChemicalBistables/simpleBis.py b/tutorials/ChemicalBistables/simpleBis.py index 4c577f55..3bbfc700 100644 --- a/tutorials/ChemicalBistables/simpleBis.py +++ b/tutorials/ChemicalBistables/simpleBis.py @@ -134,7 +134,10 @@ def main(): # Iterate through all plots, dump their contents to data.plot. displayPlots() - raw_input( 'Press any key to quit' ) + try: + raw_input( 'Press any key to quit' ) + except NameError as e: + input( 'Press any key to quit' ) # Run the 'main' if this script is executed standalone. diff --git a/tutorials/ChemicalOscillators/TuringOneDim.py b/tutorials/ChemicalOscillators/TuringOneDim.py index e755d257..bc27761a 100644 --- a/tutorials/ChemicalOscillators/TuringOneDim.py +++ b/tutorials/ChemicalOscillators/TuringOneDim.py @@ -160,7 +160,10 @@ def main(): fig.canvas.draw() print( "Hit 'enter' to exit" ) - raw_input( ) + try: + raw_input( ) + except NameError as e: # python3 + input( ) -- GitLab