python 3 compatibility for examples/*.py files

add from __future__ import
print statement -> print() function
xrange -> range
map() -> list(map())
range() -> list(range())
StandardError -> Exception
This commit is contained in:
danielque
2023-08-10 13:25:36 +02:00
parent 597e606bde
commit 539fd060c2
35 changed files with 106 additions and 88 deletions

View File

@ -5,6 +5,8 @@
# return distance sq between 2 atoms with PBC # return distance sq between 2 atoms with PBC
from __future__ import absolute_import
def distance(box,x1,y1,z1,x2,y2,z2): def distance(box,x1,y1,z1,x2,y2,z2):
delx = x2 - x1 delx = x2 - x1
@ -37,7 +39,7 @@ def distance(box,x1,y1,z1,x2,y2,z2):
# main script # main script
if len(argv) < 3: if len(argv) < 3:
raise StandardError,"group_energy.py data.file dump.file1 dump.file2 ..." raise Exception("group_energy.py data.file dump.file1 dump.file2 ...")
dt = data(argv[1]) # data file dt = data(argv[1]) # data file
q = dt.get("Atoms",4) q = dt.get("Atoms",4)
@ -75,32 +77,32 @@ while 1:
d.aselect.test("$id >= 1 and $id <= 7243 or $id >= 7274 and $id <= 14283", d.aselect.test("$id >= 1 and $id <= 7243 or $id >= 7274 and $id <= 14283",
time) time)
id2,type2,x2,y2,z2 = d.vecs(time,"id","type","x","y","z") id2,type2,x2,y2,z2 = d.vecs(time,"id","type","x","y","z")
id1 = map(int,id1) id1 = list(map(int,id1))
id2 = map(int,id2) id2 = list(map(int,id2))
type1 = map(int,type1) type1 = list(map(int,type1))
type2 = map(int,type2) type2 = list(map(int,type2))
n1 = len(type1) n1 = len(type1)
n2 = len(type2) n2 = len(type2)
for i in xrange(n1): for i in range(n1):
id1[i] -= 1 id1[i] -= 1
type1[i] -= 1 type1[i] -= 1
for i in xrange(n2): for i in range(n2):
id2[i] -= 1 id2[i] -= 1
type2[i] -= 1 type2[i] -= 1
e_coul_sum = 0.0 e_coul_sum = 0.0
e_vdwl_sum = 0.0 e_vdwl_sum = 0.0
for i in xrange(n1): for i in range(n1):
typei = type1[i] typei = type1[i]
qi = q[id1[i]] qi = q[id1[i]]
for j in xrange(n2): for j in range(n2):
rsq = distance(box,x1[i],y1[i],z1[i],x2[j],y2[j],z2[j]) rsq = distance(box,x1[i],y1[i],z1[i],x2[j],y2[j],z2[j])
if rsq < maxcut_sq: if rsq < maxcut_sq:
eng_coul,eng_vdwl = p.single(rsq,typei,type2[j],qi,q[id2[j]]) eng_coul,eng_vdwl = p.single(rsq,typei,type2[j],qi,q[id2[j]])
e_coul_sum += eng_coul e_coul_sum += eng_coul
e_vdwl_sum += eng_vdwl e_vdwl_sum += eng_vdwl
print "eng_coul = %g at timestep %d" % (e_coul_sum,time) print("eng_coul = %g at timestep %d" % (e_coul_sum,time))
print "eng_vdwl = %g at timestep %d" % (e_vdwl_sum,time) print("eng_vdwl = %g at timestep %d" % (e_vdwl_sum,time))
d.tselect.none() d.tselect.none()
d.tselect.one(time) d.tselect.one(time)

View File

@ -1,5 +1,7 @@
# movie of flow around obstacle # movie of flow around obstacle
from __future__ import absolute_import
d = dump("dump.flow") d = dump("dump.flow")
d.map(1,"id",2,"type",3,"x",4,"y",5,"z",6,"vx",7,"vy") d.map(1,"id",2,"type",3,"x",4,"y",5,"z",6,"vx",7,"vy")
d.set("$ke = sqrt($vx*$vx + $vy*$vy)") d.set("$ke = sqrt($vx*$vx + $vy*$vy)")
@ -7,8 +9,8 @@ d.spread("vx",100,"color")
d.atype = "color" d.atype = "color"
r = raster(d) r = raster(d)
r.acol(range(100),["red","red","red","red","yellow","green","blue","purple","purple","purple","purple"]) r.acol(list(range(100)),["red","red","red","red","yellow","green","blue","purple","purple","purple","purple"])
r.arad(range(100),0.5) r.arad(list(range(100)),0.5)
r.rotate(0,-90) r.rotate(0,-90)
r.zoom(1.5) r.zoom(1.5)
r.file = "flow" r.file = "flow"

View File

@ -1,6 +1,6 @@
# movie of melting LJ solid # movie of melting LJ solid
a = dump("dump.melt") a = dump("files/dump.melt")
a.tselect.test("$t == 0") a.tselect.test("$t == 0")
a.scale() a.scale()
a.set("$ix = int($x * 4)") a.set("$ix = int($x * 4)")

View File

@ -1,10 +1,12 @@
# movie of self-assembling micelles # movie of self-assembling micelles
d = dump("dump.micelle") from __future__ import absolute_import
d = dump("files/dump.micelle")
s = svg(d) s = svg(d)
s.acol([1,2,3,4],["blue","red","cyan","yellow"]) s.acol([1,2,3,4],["blue","red","cyan","yellow"])
s.arad(range(4),0.5) s.arad(list(range(4)),0.5)
s.zoom(1.5) s.zoom(1.5)
s.file = "micelle" s.file = "micelle"

View File

@ -1,8 +1,8 @@
# movie of solvated peptide data # movie of solvated peptide data
d = dump("dump.peptide") d = dump("files/dump.peptide")
d.unwrap() d.unwrap()
p = pdb("peptide",d) p = pdbfile("files/peptide",d)
r.file = "peptide"
r = rasmol(p) r = rasmol(p)
r.all() r.all()

View File

@ -1,6 +1,6 @@
# movie of triangular particle data # movie of triangular particle data
d = dump("dump.tri") d = dump("files/dump.tri")
d.set("$center = ((int($id)-1)/36+1)*36") d.set("$center = ((int($id)-1)/36+1)*36")
d.owrap("center") d.owrap("center")

View File

@ -11,4 +11,4 @@ a.next()
a.previous() a.previous()
a.frame(1) a.frame(1)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -9,4 +9,4 @@ dm.extra(b)
g = gl(dm) g = gl(dm)
v = vcr(g) v = vcr(g)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -31,4 +31,4 @@ c.select("A","B","C","linebox","organelle","nuchalf")
g = gl(c) g = gl(c)
v = vcr(g) v = vcr(g)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -9,4 +9,4 @@ x.one()
x.many() x.many()
x.single(0,"tmp.single") x.single(0,"tmp.single")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -14,4 +14,4 @@ c.build(10,25)
c.write("tmp.data.chain") c.write("tmp.data.chain")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -4,13 +4,13 @@
c = log("files/log.ccell") c = log("files/log.ccell")
print "# of vectors =",c.nvec print("# of vectors =",c.nvec)
print "length of vectors =",c.nlen print("length of vectors =",c.nlen)
print "names of vectors =",c.names print("names of vectors =",c.names)
time,a,b = c.get("Step","prey","predator") time,a,b = c.get("Step","prey","predator")
print a,b print(a,b)
c.write("tmp.clog") c.write("tmp.clog")
c.write("tmp.clog.two","Step","prey") c.write("tmp.clog.two","Step","prey")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -2,17 +2,19 @@
# requires files/data.micelle and dump.micelle # requires files/data.micelle and dump.micelle
# creates tmp.data # creates tmp.data
from __future__ import absolute_import
d = data("files/data.micelle") d = data("files/data.micelle")
d.map(1,"id",3,"type",4,"x",5,"y",6,"z") d.map(1,"id",3,"type",4,"x",5,"y",6,"z")
coeffs = d.get("Masses") coeffs = d.get("Masses")
print "Masses",coeffs print("Masses",coeffs)
x = d.get("Atoms",4) x = d.get("Atoms",4)
print "X of 1st atom",x[0] print("X of 1st atom",x[0])
d.title = "New LAMMPS data file" d.title = "New LAMMPS data file"
natoms = d.headers["atoms"] natoms = d.headers["atoms"]
vec = range(1,natoms+1) vec = list(range(1,natoms+1))
vec.reverse() vec.reverse()
d.replace("Atoms",1,vec) d.replace("Atoms",1,vec)
@ -27,4 +29,4 @@ while 1:
d.write("tmp.data") d.write("tmp.data")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -27,12 +27,12 @@ d.set("$xyz = $x + $y + $z")
d.spread("x",100,"color") d.spread("x",100,"color")
d.clone(0,"color") d.clone(0,"color")
print "Time",d.time() print("Time",d.time())
color = d.atom(1,"color") color = d.atom(1,"color")
print "Color of atom 1",color print("Color of atom 1",color)
d.aselect.test("$id <= 10") d.aselect.test("$id <= 10")
color = d.vecs(1000,"color") color = d.vecs(1000,"color")
print "Color of 1st 10 atoms in step 1000",color print("Color of 1st 10 atoms in step 1000",color)
d.atype = "color" d.atype = "color"
@ -42,13 +42,13 @@ while 1:
if flag == -1: break if flag == -1: break
time,box,atoms,bonds,tris,lines = d.viz(index) time,box,atoms,bonds,tris,lines = d.viz(index)
colors = [atom[1] for atom in atoms] colors = [atom[1] for atom in atoms]
print time,colors print(time,colors)
d = dump("files/dump.peptide.*",0) d = dump("files/dump.peptide.*",0)
while 1: while 1:
time = d.next() time = d.next()
if time < 0: break if time < 0: break
print "Incrementally read snaps =",d.nsnaps print("Incrementally read snaps =",d.nsnaps)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -1,4 +1,4 @@
# simple test of xyz tool # simple test of ensight tool
# requires files/dump.micelle.* # requires files/dump.micelle.*
# creates tmp*.case, etc # creates tmp*.case, etc
@ -8,4 +8,4 @@ e.one()
e.many() e.many()
e.single(0) e.single(0)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -2,6 +2,8 @@
# requires files/dump.kinase # requires files/dump.kinase
# creates tmp*.png # creates tmp*.png
from __future__ import absolute_import
d = dump("files/dump.kinase") d = dump("files/dump.kinase")
g = gl(d) g = gl(d)
@ -17,7 +19,7 @@ g.all()
from vizinfo import colors from vizinfo import colors
g.acol([1,4,6,8,9],["gray","red","blue","green","yellow"]) g.acol([1,4,6,8,9],["gray","red","blue","green","yellow"])
g.arad(range(9),0.3) g.arad(list(range(9)),0.3)
#g.label(0.2,0.4,'h',15,"red","test label #1") #g.label(0.2,0.4,'h',15,"red","test label #1")
#g.label(-0.2,-0.4,'h',15,"yellow","test label #2") #g.label(-0.2,-0.4,'h',15,"yellow","test label #2")
@ -25,4 +27,4 @@ g.show(0)
g.pan(60,130,1,60,30,0.5) g.pan(60,130,1,60,30,0.5)
g.all(0,10,0) g.all(0,10,0)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -1,17 +1,19 @@
# simple test of gnu tool # simple test of gnu tool
# creates tmp.eps # creates tmp.eps
from __future__ import absolute_import
g = gnu() g = gnu()
g("plot sin(x) with lines") g("plot sin(x) with lines")
a = range(10) a = list(range(10))
b = [3,6,2,5,7,3,6,5,3,1] b = [3,6,2,5,7,3,6,5,3,1]
g.plot(a) g.plot(a)
g.plot(a,b) g.plot(a,b)
g.plot(a,b,b,a) g.plot(a,b,b,a)
g.mplot(0,10,2,"tmp",a,b) g.mplot(2,10,2,"tmp",a,b)
g.export("tmp.gnu",a,b) g.export("tmp.gnu",a,b)
@ -30,4 +32,4 @@ g.ylog()
g.save("tmp") g.save("tmp")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -10,4 +10,4 @@ g.ytitle("Particle Count")
g.title("Histogram of Particle Density") g.title("Histogram of Particle Density")
g.plot(x,y) g.plot(x,y)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -4,6 +4,6 @@
i = image("files/bucky*.png") i = image("files/bucky*.png")
i.convert("files/bucky*.png","tmp*.gif") i.convert("files/bucky*.png","tmp*.gif")
i.montage("","files/bucky*.png","tmp*.gif","tmpnew*.png") i.montage("","files/bucky*.png","tmp*.gif","tmpnew*.png")
i.view("") i.view("*.png")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -12,4 +12,4 @@ g.lrad(1,5)
g.lcol(1,"green") g.lcol(1,"green")
v = vcr(g) v = vcr(g)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -4,13 +4,13 @@
lg = log("files/log.obstacle") lg = log("files/log.obstacle")
print "# of vectors =",lg.nvec print("# of vectors =",lg.nvec)
print "length of vectors =",lg.nlen print("length of vectors =",lg.nlen)
print "names of vectors =",lg.names print("names of vectors =",lg.names)
time,temp,press = lg.get("Step","Temp","Press") time,temp,press = lg.get("Step","Temp","Press")
print temp,press print(temp,press)
lg.write("tmp.log") lg.write("tmp.log")
lg.write("tmp.log.two","Step","E_pair") lg.write("tmp.log.two","Step","E_pair")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -1,9 +1,11 @@
# simple test of matlab tool # simple test of matlab tool
# creates tmp.eps # creates tmp.eps
from __future__ import absolute_import
m = matlab() m = matlab()
a = range(10) a = list(range(10))
b = [3,6,2,5,7,3,6,5,3,1] b = [3,6,2,5,7,3,6,5,3,1]
m.plot(a) m.plot(a)
@ -30,4 +32,4 @@ m.ylog()
m.save("tmp") m.save("tmp")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -12,7 +12,7 @@ m.tselect.all()
m.tselect.test("$t >= 100 and $t <= 200") m.tselect.test("$t >= 100 and $t <= 200")
m.delete() m.delete()
print "Time",m.time() print("Time",m.time())
m.map(2,"spin") m.map(2,"spin")
m.etype = "spin" m.etype = "spin"
@ -23,13 +23,13 @@ while 1:
if flag == -1: break if flag == -1: break
time,box,atoms,bonds,tris,lines = m.viz(index) time,box,atoms,bonds,tris,lines = m.viz(index)
colors = [tri[1] for tri in tris] colors = [tri[1] for tri in tris]
print time,colors print(time,colors)
m = dump("files/mesh.grain",0) m = dump("files/mesh.grain",0)
while 1: while 1:
time = m.next() time = m.next()
if time < 0: break if time < 0: break
print "Incrementally read snaps =",m.nsnaps print("Incrementally read snaps =",m.nsnaps)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -6,6 +6,6 @@ d = data("files/data.rhodo")
p.coeff(d) p.coeff(d)
p.init(8.0,10.0) p.init(8.0,10.0)
ev,ec = p.single(5.0,1,2,0.5,-0.5) ev,ec = p.single(5.0,1,2,0.5,-0.5)
print "Energies",ev,ec print("Energies",ev,ec)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -7,4 +7,4 @@ p.build(100,"hex2",1,2,3)
p.build(50,"tri5",4,5) p.build(50,"tri5",4,5)
p.write("tmp.data.patch") p.write("tmp.data.patch")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -15,6 +15,6 @@ while 1:
p.single(time,"tmp.single") p.single(time,"tmp.single")
n += 1 n += 1
print "Incrementally processed %d PDB files" % n print("Incrementally processed %d PDB files" % n)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -15,4 +15,4 @@ p.no(2)
p.file("tmp.plotview") p.file("tmp.plotview")
p.save() p.save()
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -8,14 +8,14 @@ p = pdbfile("files/peptide",d)
r = rasmol(p) r = rasmol(p)
r.file = "tmp" r.file = "tmp"
print "kill image window when ready to contine ..." print("kill image window when ready to contine ...")
r.show(0) r.show(0)
r.all() r.all()
# change RasMol settings, run all() with those settings # change RasMol settings, run all() with those settings
print "change RasMol settings as desired, then type 'quit' ..." print("change RasMol settings as desired, then type 'quit' ...")
r.run(0) r.run(0)
r.all("tmp.rasmol") r.all("tmp.rasmol")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -2,6 +2,8 @@
# requires files/dump.kinase # requires files/dump.kinase
# creates tmp*.png # creates tmp*.png
from __future__ import absolute_import
d = dump("files/dump.kinase") d = dump("files/dump.kinase")
r = raster(d) r = raster(d)
@ -10,7 +12,7 @@ r.rotate(60,130)
r.box(1) r.box(1)
r.file = "tmp" r.file = "tmp"
print "kill image window when ready to contine ..." print("kill image window when ready to contine ...")
r.show(0) r.show(0)
r.all() r.all()
a1 = animate("tmp0*png") a1 = animate("tmp0*png")
@ -18,14 +20,14 @@ a1 = animate("tmp0*png")
from vizinfo import colors from vizinfo import colors
r.acol([1,4,6,8,9],["gray","red","blue","green","yellow"]) r.acol([1,4,6,8,9],["gray","red","blue","green","yellow"])
r.arad(range(9),0.3) r.arad(list(range(9)),0.3)
r.label(0.2,0.4,'h',15,"red","test label #1") r.label(0.2,0.4,'h',15,"red","test label #1")
r.label(-0.2,-0.4,'h',15,"yellow","test label #2") r.label(-0.2,-0.4,'h',15,"yellow","test label #2")
print "kill image window when ready to contine ..." print("kill image window when ready to contine ...")
r.show(0) r.show(0)
r.pan(60,130,1,60,30,0.5) r.pan(60,130,1,60,30,0.5)
r.all(0,10,0) r.all(0,10,0)
a2 = animate("tmp0*png") a2 = animate("tmp0*png")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -2,6 +2,8 @@
# requires files/dump.kinase # requires files/dump.kinase
# creates tmp*.png # creates tmp*.png
from __future__ import absolute_import
d = dump("files/dump.kinase") d = dump("files/dump.kinase")
s = svg(d) s = svg(d)
@ -10,20 +12,20 @@ s.rotate(60,130)
s.box(1) s.box(1)
s.file = "tmp" s.file = "tmp"
print "kill image window when ready to contine ..." print("kill image window when ready to contine ...")
s.show(0) s.show(0)
s.all() s.all()
from vizinfo import colors from vizinfo import colors
s.acol([1,4,6,8,9],["gray","red","blue","green","yellow"]) s.acol([1,4,6,8,9],["gray","red","blue","green","yellow"])
s.arad(range(9),0.3) s.arad(list(range(9)),0.3)
s.label(0.2,0.4,'h',15,"red","test label #1") s.label(0.2,0.4,'h',15,"red","test label #1")
s.label(-0.2,-0.4,'h',15,"yellow","test label #2") s.label(-0.2,-0.4,'h',15,"yellow","test label #2")
print "kill image window when ready to contine ..." print("kill image window when ready to contine ...")
s.show(0) s.show(0)
s.pan(60,130,1,60,30,0.5) s.pan(60,130,1,60,30,0.5)
s.all(0,10,0) s.all(0,10,0)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -13,4 +13,4 @@ v.clipxlo(0.2)
v.clipxhi(0.5) v.clipxhi(0.5)
v.play() v.play()
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -4,13 +4,13 @@
v = vec("files/vec.txt") v = vec("files/vec.txt")
print "# of vectors =",v.nvec print("# of vectors =",v.nvec)
print "length of vectors =",v.nlen print("length of vectors =",v.nlen)
print "names of vectors =",v.names print("names of vectors =",v.names)
time,temp,press = v.get(1,"col2",6) time,temp,press = v.get(1,"col2",6)
print temp,press print(temp,press)
v.write("tmp.vec") v.write("tmp.vec")
v.write("tmp.vec.two","col1",3) v.write("tmp.vec.two","col1",3)
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -8,4 +8,4 @@ v.rep('VDW')
v.new('files/peptide.pdb','pdb') v.new('files/peptide.pdb','pdb')
v.flush() v.flush()
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -8,4 +8,4 @@ v.one()
v.many() v.many()
v.single(0,"tmp.single") v.single(0,"tmp.single")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")

View File

@ -8,4 +8,4 @@ x.one()
x.many() x.many()
x.single(0,"tmp.single") x.single(0,"tmp.single")
print "all done ... type CTRL-D to exit Pizza.py" print("all done ... type CTRL-D to exit Pizza.py")