Skip to content

Commit 537dd78

Browse files
Merge pull request #1 from CNS-OIST/py2py3
python2/python3 compatibility
2 parents 3a310ca + b6c451e commit 537dd78

File tree

56 files changed

+565
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+565
-489
lines changed

manual_tutorials/HH_APprop/HH_APprop.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# # # # # # # # # # # # # # # # # # # IMPORTS # # # # # # # # # # # # # # # # # #
3535
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3636

37+
from __future__ import print_function
3738
import steps.model as smodel
3839
import steps.geom as sgeom
3940
import steps.rng as srng
@@ -272,14 +273,14 @@
272273
for i in range(mesh.nverts):
273274
if ((mesh.getVertex(i)[2] < (mesh.getBoundMin()[2]+0.1e-6))):
274275
injverts.append(i)
275-
print "Found ", injverts.__len__(), "I_inject vertices"
276+
print("Found ", injverts.__len__(), "I_inject vertices")
276277

277278
facetris = []
278279
for i in range(mesh.ntris):
279280
tri = mesh.getTri(i)
280281
if ((tri[0] in injverts) and (tri[1] in injverts) and (tri[2] in injverts)):
281282
facetris.append(i)
282-
print "Found ", facetris.__len__(), "triangles on bottom face"
283+
print("Found ", facetris.__len__(), "triangles on bottom face")
283284

284285
memb_tris = list(mesh.getSurfTris())
285286

@@ -404,7 +405,7 @@
404405

405406
# Run the simulation
406407
for l in range(N_timepoints):
407-
print "\nTpnt: ", l,
408+
print("\nTpnt: ", l,)
408409

409410
sim.run(DT_sim*l)
410411

manual_tutorials/HH_APprop/HH_APprop_tetode.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# # # # # # # # # # # # # # # # # # # IMPORTS # # # # # # # # # # # # # # # # # #
3535
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3636

37+
from __future__ import print_function
3738
import steps.model as smodel
3839
import steps.geom as sgeom
3940
import steps.rng as srng
@@ -272,14 +273,14 @@
272273
for i in range(mesh.nverts):
273274
if ((mesh.getVertex(i)[2] < (mesh.getBoundMin()[2]+0.1e-6))):
274275
injverts.append(i)
275-
print "Found ", injverts.__len__(), "I_inject vertices"
276+
print("Found ", injverts.__len__(), "I_inject vertices")
276277

277278
facetris = []
278279
for i in range(mesh.ntris):
279280
tri = mesh.getTri(i)
280281
if ((tri[0] in injverts) and (tri[1] in injverts) and (tri[2] in injverts)):
281282
facetris.append(i)
282-
print "Found ", facetris.__len__(), "triangles on bottom face"
283+
print("Found ", facetris.__len__(), "triangles on bottom face")
283284

284285
memb_tris = list(mesh.getSurfTris())
285286

@@ -404,7 +405,7 @@
404405

405406
# Run the simulation
406407
for l in range(N_timepoints):
407-
print "\nTpnt: ", l,
408+
print("\nTpnt: ", l,)
408409

409410
sim.run(DT_sim*l)
410411

manual_tutorials/HH_APprop/HH_APprop_tetopsplit.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
# # # # # # # # # # # # # # # # # # # IMPORTS # # # # # # # # # # # # # # # # # #
3434
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3535

36+
from __future__ import print_function
3637
import steps.model as smodel
3738
import steps.geom as sgeom
3839
import steps.rng as srng
@@ -279,14 +280,14 @@
279280
for i in range(mesh.nverts):
280281
if ((mesh.getVertex(i)[2] < (mesh.getBoundMin()[2]+0.1e-6))):
281282
injverts.append(i)
282-
if steps.mpi.rank ==0: print "Found ", injverts.__len__(), "I_inject vertices"
283+
if steps.mpi.rank ==0: print("Found ", injverts.__len__(), "I_inject vertices")
283284

284285
facetris = []
285286
for i in range(mesh.ntris):
286287
tri = mesh.getTri(i)
287288
if ((tri[0] in injverts) and (tri[1] in injverts) and (tri[2] in injverts)):
288289
facetris.append(i)
289-
if steps.mpi.rank ==0: print "Found ", facetris.__len__(), "triangles on bottom face"
290+
if steps.mpi.rank ==0: print("Found ", facetris.__len__(), "triangles on bottom face")
290291

291292
memb_tris = list(mesh.getSurfTris())
292293

@@ -385,7 +386,7 @@
385386

386387
# Run the simulation
387388
for l in range(N_timepoints):
388-
if steps.mpi.rank ==0: print "Tpnt: ", l,"/", N_timepoints
389+
if steps.mpi.rank ==0: print("Tpnt: ", l,"/", N_timepoints)
389390

390391
sim.run(DT_sim*l)
391392

manual_tutorials/HH_APprop/runHH_APprop.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3232

33+
from __future__ import print_function
3334
from pylab import *
3435

3536
from HH_APprop import *
@@ -42,7 +43,7 @@
4243

4344
def plotVz(tidx):
4445
if (tidx >= tpnt.size):
45-
print 'Time index out of range'
46+
print('Time index out of range')
4647
return
4748
plot(results[1]*1e6, results[0][tidx], \
4849
label=str(1e3*tidx*DT_sim)+'ms', linewidth=3)
@@ -56,7 +57,7 @@ def plotVz(tidx):
5657

5758
def plotIz(tidx, plotstyles = ['-', '--']):
5859
if (tidx >= tpnt.size):
59-
print 'Time index out of range'
60+
print('Time index out of range')
6061
return
6162
plot(results[4]*1e6, results[2][tidx], plotstyles[0],\
6263
label = 'Na: '+str(1e3*tidx*DT_sim)+'ms', linewidth=3)

manual_tutorials/HH_APprop/runHH_APprop_tetode.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
3232

33+
from __future__ import print_function
3334
from pylab import *
3435

3536
from HH_APprop_tetode import *
@@ -42,7 +43,7 @@
4243

4344
def plotVz(tidx):
4445
if (tidx >= tpnt.size):
45-
print 'Time index out of range'
46+
print('Time index out of range')
4647
return
4748
plot(results[1]*1e6, results[0][tidx], \
4849
label=str(1e3*tidx*DT_sim)+'ms', linewidth=3)

manual_tutorials/diffusion/diffusion.py

+54-53
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2929

30+
from __future__ import print_function
3031
import math
3132
import numpy
3233
import pylab
@@ -50,10 +51,10 @@
5051
INT = 0.101
5152

5253
# The number of molecules to be injected into the centre
53-
NINJECT = 10000
54+
NINJECT = 10000
5455

5556
# The number of tetrahedral elements to sample data from.
56-
SAMPLE = 2000
57+
SAMPLE = 2000
5758

5859
# The diffusion constant for our diffusing species (m^2/s)
5960
DCST= 20.0e-12
@@ -70,13 +71,13 @@
7071

7172
def printtime(end_time):
7273

73-
totsecs = int(end_time-beg_time)
74-
sec = totsecs%60
75-
totmin = totsecs/60
76-
min = totmin%60
77-
hours = totmin/60
78-
79-
print 'Simulation time: %d h, %d min, %d sec' %(hours, min, sec)
74+
totsecs = int(end_time-beg_time)
75+
sec = totsecs%60
76+
totmin = totsecs/60
77+
min = totmin%60
78+
hours = totmin/60
79+
80+
print('Simulation time: %d h, %d min, %d sec' %(hours, min, sec))
8081

8182
########################################################################
8283

@@ -92,17 +93,17 @@ def gen_model():
9293

9394
def gen_geom():
9495

95-
print "Loading mesh..."
96+
print("Loading mesh...")
9697
mesh = smeshio.loadMesh('meshes/sphere_rad10_11Ktets')[0]
97-
print "Mesh Loaded"
98+
print("Mesh Loaded")
9899

99-
# Find the total number of tetrahedrons in the mesh
100+
# Find the total number of tetrahedrons in the mesh
100101
ntets = mesh.countTets()
101102
# Create a compartment containing all tetrahedron
102103
comp = stetmesh.TmComp('cyto', mesh, range(ntets))
103104
comp.addVolsys('cytosolv')
104105

105-
print "Finding tetrahedron samples..."
106+
print("Finding tetrahedron samples...")
106107
# Fetch the central tetrahedron index and store:
107108
ctetidx = mesh.findTetByPoint([0.0, 0.0, 0.0])
108109
tetidxs[0] = ctetidx
@@ -155,7 +156,7 @@ def gen_geom():
155156
# Store the radial distance (in microns):
156157
tetrads[i] = r*1.0e6
157158

158-
print "Tetrahedron samples found"
159+
print("Tetrahedron samples found")
159160

160161
return mesh
161162

@@ -181,57 +182,57 @@ def gen_geom():
181182

182183
# Run NITER number of iterations:
183184
for i in range(NITER):
184-
sim.reset()
185-
print "Running iteration", i
185+
sim.reset()
186+
print("Running iteration", i)
186187
# Inject all molecules into the central tet:
187-
sim.setTetCount(ctetidx, 'A', NINJECT)
188-
for j in range(ntpnts):
189-
sim.run(tpnts[j])
188+
sim.setTetCount(ctetidx, 'A', NINJECT)
189+
for j in range(ntpnts):
190+
sim.run(tpnts[j])
190191
# Loop over the tetrahedrons we are saving data for
191-
for k in range(SAMPLE):
192+
for k in range(SAMPLE):
192193
# Save the concentration in the tetrahedron, in uM
193-
res[i, j, k] = sim.getTetConc(int(tetidxs[k]), 'A')*1.0e6
194-
printtime(time.time())
194+
res[i, j, k] = sim.getTetConc(int(tetidxs[k]), 'A')*1.0e6
195+
printtime(time.time())
195196

196197
res_mean = numpy.mean(res, axis = 0)
197198

198199
########################################################################
199200

200201
def plotres(tidx):
201-
if (tidx >= INT/DT):
202-
print "Time index is out of range."
203-
return
204-
205-
pylab.scatter(tetrads, res_mean[tidx], s=2)
206-
pylab.xlabel('Radial distance of tetrahedron ($\mu$m)')
207-
pylab.ylabel('Concentration in tetrahedron ($\mu$M)')
208-
t = tpnts[tidx]
209-
pylab.title('Unbounded diffusion. Time: ' + str(t) + 's')
210-
plotanlyt(t)
211-
pylab.xlim(0.0, 10.0)
212-
pylab.ylim(0.0)
213-
pylab.show()
202+
if (tidx >= INT/DT):
203+
print("Time index is out of range.")
204+
return
205+
206+
pylab.scatter(tetrads, res_mean[tidx], s=2)
207+
pylab.xlabel('Radial distance of tetrahedron ($\mu$m)')
208+
pylab.ylabel('Concentration in tetrahedron ($\mu$M)')
209+
t = tpnts[tidx]
210+
pylab.title('Unbounded diffusion. Time: ' + str(t) + 's')
211+
plotanlyt(t)
212+
pylab.xlim(0.0, 10.0)
213+
pylab.ylim(0.0)
214+
pylab.show()
214215

215216
########################################################################
216217

217-
def plotanlyt(t):
218-
segs = 100
219-
anlytconc = numpy.zeros((segs))
220-
radialds = numpy.zeros((segs))
221-
maxrad = 0.0
222-
for i in tetrads:
223-
if (i > maxrad): maxrad = i
224-
maxrad *= 1e-6
225-
intervals = maxrad/segs
226-
rad = 0.0
227-
for i in range((segs)):
228-
# Find the conc from analytical solution, and convert to mol/L
229-
anlytconc[i]=1.0e3*(1/6.022e23)* \
230-
((NINJECT/(math.pow((4*math.pi*DCST*t),1.5)))* \
231-
(math.exp((-1.0*(rad*rad))/(4*DCST*t))))
232-
radialds[i] = rad*1e6
233-
rad += intervals
234-
pylab.plot(radialds, anlytconc, color = 'red')
218+
def plotanlyt(t):
219+
segs = 100
220+
anlytconc = numpy.zeros((segs))
221+
radialds = numpy.zeros((segs))
222+
maxrad = 0.0
223+
for i in tetrads:
224+
if (i > maxrad): maxrad = i
225+
maxrad *= 1e-6
226+
intervals = maxrad/segs
227+
rad = 0.0
228+
for i in range((segs)):
229+
# Find the conc from analytical solution, and convert to mol/L
230+
anlytconc[i]=1.0e3*(1/6.022e23)* \
231+
((NINJECT/(math.pow((4*math.pi*DCST*t),1.5)))* \
232+
(math.exp((-1.0*(rad*rad))/(4*DCST*t))))
233+
radialds[i] = rad*1e6
234+
rad += intervals
235+
pylab.plot(radialds, anlytconc, color = 'red')
235236

236237
########################################################################
237238

manual_tutorials/diffusion_boundary/diffusion_boundary.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
2929

30+
from __future__ import print_function
3031
import steps.model as smodel
3132
import steps.geom as sgeom
3233
import steps.rng as srng
@@ -151,7 +152,7 @@ def gen_geom():
151152

152153
def plot_binned(t_idx, bin_n = 100):
153154
if (t_idx > tpnts.size):
154-
print "Time index is out of range."
155+
print("Time index is out of range.")
155156
return
156157

157158
z_tets = numpy.zeros(ntets)

manual_tutorials/directional_dcst/boundary_directional_dcst.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
""" Example of directional dcst."""
44

5+
from __future__ import print_function
56
import random
67
import steps.model as smodel
78
import steps.geom as sgeom
@@ -36,23 +37,23 @@
3637

3738
solver = solv.Tetexact(model, mesh, rng)
3839

39-
print "Set directonal dcst from comp1 to comp2, and from comp2 to comp1 to 0..."
40+
print("Set directonal dcst from comp1 to comp2, and from comp2 to comp1 to 0...")
4041
solver.setCompCount("comp1", "A", 100)
4142
solver.setCompCount("comp2", "A", 20)
4243
solver.setDiffBoundaryDcst("boundary", "A", 0)
43-
print "V1 Count: ", solver.getCompCount("comp1", "A")
44-
print "V2 Count: ", solver.getCompCount("comp2", "A")
44+
print("V1 Count: ", solver.getCompCount("comp1", "A"))
45+
print("V2 Count: ", solver.getCompCount("comp2", "A"))
4546
solver.run(1)
46-
print "V1 Count: ", solver.getCompCount("comp1", "A")
47-
print "V2 Count: ", solver.getCompCount("comp2", "A")
47+
print("V1 Count: ", solver.getCompCount("comp1", "A"))
48+
print("V2 Count: ", solver.getCompCount("comp2", "A"))
4849

49-
print "Set directonal dcst from comp1 to comp2 to 1/10 of DCST, and 0 from comp2 to comp1..."
50+
print("Set directonal dcst from comp1 to comp2 to 1/10 of DCST, and 0 from comp2 to comp1...")
5051
solver.reset()
5152
solver.setCompCount("comp1", "A", 100)
5253
solver.setDiffBoundaryDcst("boundary", "A", DCST / 10, "comp2")
5354
solver.setDiffBoundaryDcst("boundary", "A", 0.0, "comp1")
54-
print "V1 Count: ", solver.getCompCount("comp1", "A")
55-
print "V2 Count: ", solver.getCompCount("comp2", "A")
55+
print("V1 Count: ", solver.getCompCount("comp1", "A"))
56+
print("V2 Count: ", solver.getCompCount("comp2", "A"))
5657
solver.run(1)
57-
print "V1 Count: ", solver.getCompCount("comp1", "A")
58-
print "V2 Count: ", solver.getCompCount("comp2", "A")
58+
print("V1 Count: ", solver.getCompCount("comp1", "A"))
59+
print("V2 Count: ", solver.getCompCount("comp2", "A"))

0 commit comments

Comments
 (0)