Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d64778295e | |||
| f2d890aa58 | |||
| 088e983c78 | |||
| 50efb8ee82 | |||
| e77a3e64b9 | |||
| 8c53380765 | |||
| d4f5ea374a | |||
| cf710bcb9e | |||
| e1556451fa | |||
| 539fd060c2 | |||
| 597e606bde | |||
| d560b34214 |
6531
examples/files/data.peptide
Normal file
6531
examples/files/data.peptide
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@ ITEM: BOX BOUNDS
|
||||
-6.2035 6.2035
|
||||
-6.2035 6.2035
|
||||
-6.2035 6.2035
|
||||
ITEM: ATOMS
|
||||
ITEM: ATOMS id type x y z
|
||||
1965739326 1 -2.73852 3.76042 0.0137829
|
||||
1638062651 1 -4.08446 0.411239 0.994664
|
||||
574343881 1 -2.25466 -3.0259 -0.036883
|
||||
|
||||
24054
examples/files/dump.melt
Normal file
24054
examples/files/dump.melt
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@ ITEM: BOX BOUNDS
|
||||
0 35.8569
|
||||
0 35.8569
|
||||
-0.1 0.1
|
||||
ITEM: ATOMS
|
||||
ITEM: ATOMS id type xs ys zs
|
||||
1 2 0.972698 0.992397 0.5
|
||||
2 1 0.0517232 0.999069 0.5
|
||||
3 1 0.0504894 0.0385782 0.5
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
36.8401937129895 64.2115601793071
|
||||
41.0136911525442 68.3850576188589
|
||||
29.7680952261698 57.1394616924871
|
||||
ITEM: ATOMS
|
||||
ITEM: ATOMS id type xs ys zs ix iy iz
|
||||
31 3 0.22450 0.39503 0.37295 0 0 0
|
||||
306 14 0.29326 0.17604 0.15395 0 0 0
|
||||
16 8 0.31495 0.27307 0.07008 0 0 0
|
||||
|
||||
@ -6,7 +6,7 @@ ITEM: BOX BOUNDS
|
||||
0 27.9398
|
||||
0 27.9398
|
||||
0 27.9398
|
||||
ITEM: ATOMS
|
||||
ITEM: ATOMS id type xs ys zs ix iy iz
|
||||
1 1 0.410912 0.570945 0.36491 0 0 0
|
||||
2 2 0.376227 0.6013 0.339084 0 0 0
|
||||
3 3 0.397383 0.536983 0.387988 0 0 0
|
||||
|
||||
@ -6,7 +6,7 @@ ITEM: BOX BOUNDS
|
||||
0.482127 27.3191
|
||||
0.477796 27.3148
|
||||
0.47406 27.3111
|
||||
ITEM: ATOMS
|
||||
ITEM: ATOMS id type xs ys zs ix iy iz
|
||||
1 1 0.404224 0.524373 0.362448 0 0 0
|
||||
2 2 0.364265 0.561026 0.358768 0 0 0
|
||||
3 3 0.394989 0.481736 0.350359 0 0 0
|
||||
|
||||
@ -5,12 +5,14 @@
|
||||
|
||||
# return distance sq between 2 atoms with PBC
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
def distance(box,x1,y1,z1,x2,y2,z2):
|
||||
|
||||
|
||||
delx = x2 - x1
|
||||
dely = y2 - y1
|
||||
delz = z2 - z1
|
||||
|
||||
|
||||
xprd = box[3] - box[0]
|
||||
yprd = box[4] - box[1]
|
||||
zprd = box[5] - box[2]
|
||||
@ -30,19 +32,19 @@ def distance(box,x1,y1,z1,x2,y2,z2):
|
||||
delz += zprd
|
||||
else:
|
||||
delz -= zprd
|
||||
|
||||
|
||||
distsq = delx*delx + dely*dely + delz*delz
|
||||
return distsq
|
||||
|
||||
# main script
|
||||
|
||||
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)
|
||||
|
||||
files = ' '.join(argv[2:]) # dump files
|
||||
files = ' '.join(argv[2:]) # dump files
|
||||
d = dump(files,0)
|
||||
d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
|
||||
|
||||
@ -75,32 +77,32 @@ while 1:
|
||||
d.aselect.test("$id >= 1 and $id <= 7243 or $id >= 7274 and $id <= 14283",
|
||||
time)
|
||||
id2,type2,x2,y2,z2 = d.vecs(time,"id","type","x","y","z")
|
||||
id1 = map(int,id1)
|
||||
id2 = map(int,id2)
|
||||
type1 = map(int,type1)
|
||||
type2 = map(int,type2)
|
||||
id1 = list(map(int,id1))
|
||||
id2 = list(map(int,id2))
|
||||
type1 = list(map(int,type1))
|
||||
type2 = list(map(int,type2))
|
||||
n1 = len(type1)
|
||||
n2 = len(type2)
|
||||
for i in xrange(n1):
|
||||
for i in range(n1):
|
||||
id1[i] -= 1
|
||||
type1[i] -= 1
|
||||
for i in xrange(n2):
|
||||
for i in range(n2):
|
||||
id2[i] -= 1
|
||||
type2[i] -= 1
|
||||
|
||||
e_coul_sum = 0.0
|
||||
e_vdwl_sum = 0.0
|
||||
for i in xrange(n1):
|
||||
for i in range(n1):
|
||||
typei = type1[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])
|
||||
if rsq < maxcut_sq:
|
||||
eng_coul,eng_vdwl = p.single(rsq,typei,type2[j],qi,q[id2[j]])
|
||||
e_coul_sum += eng_coul
|
||||
e_vdwl_sum += eng_vdwl
|
||||
print "eng_coul = %g at timestep %d" % (e_coul_sum,time)
|
||||
print "eng_vdwl = %g at timestep %d" % (e_vdwl_sum,time)
|
||||
e_coul_sum += eng_coul
|
||||
e_vdwl_sum += eng_vdwl
|
||||
print("eng_coul = %g at timestep %d" % (e_coul_sum,time))
|
||||
print("eng_vdwl = %g at timestep %d" % (e_vdwl_sum,time))
|
||||
|
||||
d.tselect.none()
|
||||
d.tselect.one(time)
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
# movie of flow around obstacle
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
d = dump("dump.flow")
|
||||
d.map(1,"id",2,"type",3,"x",4,"y",5,"z",6,"vx",7,"vy")
|
||||
d.set("$ke = sqrt($vx*$vx + $vy*$vy)")
|
||||
@ -7,8 +9,8 @@ d.spread("vx",100,"color")
|
||||
d.atype = "color"
|
||||
|
||||
r = raster(d)
|
||||
r.acol(range(100),["red","red","red","red","yellow","green","blue","purple","purple","purple","purple"])
|
||||
r.arad(range(100),0.5)
|
||||
r.acol(list(range(100)),["red","red","red","red","yellow","green","blue","purple","purple","purple","purple"])
|
||||
r.arad(list(range(100)),0.5)
|
||||
r.rotate(0,-90)
|
||||
r.zoom(1.5)
|
||||
r.file = "flow"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# movie of melting LJ solid
|
||||
|
||||
a = dump("dump.melt")
|
||||
a = dump("files/dump.melt")
|
||||
a.tselect.test("$t == 0")
|
||||
a.scale()
|
||||
a.set("$ix = int($x * 4)")
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
# movie of self-assembling micelles
|
||||
|
||||
d = dump("dump.micelle")
|
||||
from __future__ import absolute_import
|
||||
|
||||
d = dump("files/dump.micelle")
|
||||
|
||||
s = svg(d)
|
||||
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.file = "micelle"
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
# movie of solvated peptide data
|
||||
|
||||
d = dump("dump.peptide")
|
||||
d = dump("files/dump.peptide")
|
||||
d.unwrap()
|
||||
p = pdb("peptide",d)
|
||||
r.file = "peptide"
|
||||
p = pdbfile("files/peptide",d)
|
||||
|
||||
r = rasmol(p)
|
||||
r.all()
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# movie of triangular particle data
|
||||
|
||||
d = dump("dump.tri")
|
||||
d = dump("files/dump.tri")
|
||||
d.set("$center = ((int($id)-1)/36+1)*36")
|
||||
d.owrap("center")
|
||||
|
||||
|
||||
@ -11,4 +11,4 @@ a.next()
|
||||
a.previous()
|
||||
a.frame(1)
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -9,4 +9,4 @@ dm.extra(b)
|
||||
g = gl(dm)
|
||||
v = vcr(g)
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -30,5 +30,5 @@ c.select("A","B","C","linebox","organelle","nuchalf")
|
||||
|
||||
g = gl(c)
|
||||
v = vcr(g)
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -9,4 +9,4 @@ x.one()
|
||||
x.many()
|
||||
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")
|
||||
|
||||
@ -14,4 +14,4 @@ c.build(10,25)
|
||||
|
||||
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")
|
||||
|
||||
@ -4,13 +4,13 @@
|
||||
|
||||
c = log("files/log.ccell")
|
||||
|
||||
print "# of vectors =",c.nvec
|
||||
print "length of vectors =",c.nlen
|
||||
print "names of vectors =",c.names
|
||||
print("# of vectors =",c.nvec)
|
||||
print("length of vectors =",c.nlen)
|
||||
print("names of vectors =",c.names)
|
||||
|
||||
time,a,b = c.get("Step","prey","predator")
|
||||
print a,b
|
||||
print(a,b)
|
||||
c.write("tmp.clog")
|
||||
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")
|
||||
|
||||
@ -1,18 +1,20 @@
|
||||
# simple test of data tool
|
||||
# requires files/data.micelle
|
||||
# requires files/data.micelle and dump.micelle
|
||||
# creates tmp.data
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
d = data("files/data.micelle")
|
||||
d.map(1,"id",3,"type",4,"x",5,"y",6,"z")
|
||||
coeffs = d.get("Masses")
|
||||
print "Masses",coeffs
|
||||
print("Masses",coeffs)
|
||||
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"
|
||||
|
||||
natoms = d.headers["atoms"]
|
||||
vec = range(1,natoms+1)
|
||||
vec = list(range(1,natoms+1))
|
||||
vec.reverse()
|
||||
d.replace("Atoms",1,vec)
|
||||
|
||||
@ -24,7 +26,7 @@ while 1:
|
||||
index,time,flag = d.iterator(flag)
|
||||
if flag == -1: break
|
||||
time,box,atoms,bonds,tris,lines= d.viz(index)
|
||||
|
||||
|
||||
d.write("tmp.data")
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -27,12 +27,12 @@ d.set("$xyz = $x + $y + $z")
|
||||
d.spread("x",100,"color")
|
||||
d.clone(0,"color")
|
||||
|
||||
print "Time",d.time()
|
||||
print("Time",d.time())
|
||||
color = d.atom(1,"color")
|
||||
print "Color of atom 1",color
|
||||
print("Color of atom 1",color)
|
||||
d.aselect.test("$id <= 10")
|
||||
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"
|
||||
|
||||
@ -42,13 +42,13 @@ while 1:
|
||||
if flag == -1: break
|
||||
time,box,atoms,bonds,tris,lines = d.viz(index)
|
||||
colors = [atom[1] for atom in atoms]
|
||||
print time,colors
|
||||
print(time,colors)
|
||||
|
||||
d = dump("files/dump.peptide.*",0)
|
||||
while 1:
|
||||
time = d.next()
|
||||
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")
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# simple test of xyz tool
|
||||
# simple test of ensight tool
|
||||
# requires files/dump.micelle.*
|
||||
# creates tmp*.case, etc
|
||||
|
||||
@ -8,4 +8,4 @@ e.one()
|
||||
e.many()
|
||||
e.single(0)
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
# requires files/dump.kinase
|
||||
# creates tmp*.png
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
d = dump("files/dump.kinase")
|
||||
g = gl(d)
|
||||
|
||||
@ -17,7 +19,7 @@ g.all()
|
||||
from vizinfo import colors
|
||||
|
||||
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,"yellow","test label #2")
|
||||
|
||||
@ -25,4 +27,4 @@ g.show(0)
|
||||
g.pan(60,130,1,60,30,0.5)
|
||||
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")
|
||||
|
||||
@ -1,17 +1,19 @@
|
||||
# simple test of gnu tool
|
||||
# creates tmp.eps
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
g = gnu()
|
||||
|
||||
g("plot sin(x) with lines")
|
||||
|
||||
a = range(10)
|
||||
a = list(range(10))
|
||||
b = [3,6,2,5,7,3,6,5,3,1]
|
||||
|
||||
g.plot(a)
|
||||
g.plot(a,b)
|
||||
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)
|
||||
|
||||
@ -30,4 +32,4 @@ g.ylog()
|
||||
|
||||
g.save("tmp")
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -10,4 +10,4 @@ g.ytitle("Particle Count")
|
||||
g.title("Histogram of Particle Density")
|
||||
g.plot(x,y)
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -4,6 +4,6 @@
|
||||
i = image("files/bucky*.png")
|
||||
i.convert("files/bucky*.png","tmp*.gif")
|
||||
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")
|
||||
|
||||
@ -12,4 +12,4 @@ g.lrad(1,5)
|
||||
g.lcol(1,"green")
|
||||
v = vcr(g)
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -4,13 +4,13 @@
|
||||
|
||||
lg = log("files/log.obstacle")
|
||||
|
||||
print "# of vectors =",lg.nvec
|
||||
print "length of vectors =",lg.nlen
|
||||
print "names of vectors =",lg.names
|
||||
print("# of vectors =",lg.nvec)
|
||||
print("length of vectors =",lg.nlen)
|
||||
print("names of vectors =",lg.names)
|
||||
|
||||
time,temp,press = lg.get("Step","Temp","Press")
|
||||
print temp,press
|
||||
print(temp,press)
|
||||
lg.write("tmp.log")
|
||||
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")
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
# simple test of matlab tool
|
||||
# creates tmp.eps
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
m = matlab()
|
||||
|
||||
a = range(10)
|
||||
a = list(range(10))
|
||||
b = [3,6,2,5,7,3,6,5,3,1]
|
||||
|
||||
m.plot(a)
|
||||
@ -30,4 +32,4 @@ m.ylog()
|
||||
|
||||
m.save("tmp")
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -12,7 +12,7 @@ m.tselect.all()
|
||||
m.tselect.test("$t >= 100 and $t <= 200")
|
||||
m.delete()
|
||||
|
||||
print "Time",m.time()
|
||||
print("Time",m.time())
|
||||
|
||||
m.map(2,"spin")
|
||||
m.etype = "spin"
|
||||
@ -23,13 +23,13 @@ while 1:
|
||||
if flag == -1: break
|
||||
time,box,atoms,bonds,tris,lines = m.viz(index)
|
||||
colors = [tri[1] for tri in tris]
|
||||
print time,colors
|
||||
print(time,colors)
|
||||
|
||||
m = dump("files/mesh.grain",0)
|
||||
while 1:
|
||||
time = m.next()
|
||||
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")
|
||||
|
||||
@ -6,6 +6,6 @@ d = data("files/data.rhodo")
|
||||
p.coeff(d)
|
||||
p.init(8.0,10.0)
|
||||
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")
|
||||
|
||||
@ -7,4 +7,4 @@ p.build(100,"hex2",1,2,3)
|
||||
p.build(50,"tri5",4,5)
|
||||
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")
|
||||
|
||||
@ -15,6 +15,6 @@ while 1:
|
||||
p.single(time,"tmp.single")
|
||||
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")
|
||||
|
||||
@ -15,4 +15,4 @@ p.no(2)
|
||||
p.file("tmp.plotview")
|
||||
p.save()
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -8,14 +8,14 @@ p = pdbfile("files/peptide",d)
|
||||
r = rasmol(p)
|
||||
r.file = "tmp"
|
||||
|
||||
print "kill image window when ready to contine ..."
|
||||
print("kill image window when ready to contine ...")
|
||||
r.show(0)
|
||||
r.all()
|
||||
|
||||
# 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.all("tmp.rasmol")
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
# requires files/dump.kinase
|
||||
# creates tmp*.png
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
d = dump("files/dump.kinase")
|
||||
r = raster(d)
|
||||
|
||||
@ -10,7 +12,7 @@ r.rotate(60,130)
|
||||
r.box(1)
|
||||
r.file = "tmp"
|
||||
|
||||
print "kill image window when ready to contine ..."
|
||||
print("kill image window when ready to contine ...")
|
||||
r.show(0)
|
||||
r.all()
|
||||
a1 = animate("tmp0*png")
|
||||
@ -18,14 +20,14 @@ a1 = animate("tmp0*png")
|
||||
from vizinfo import colors
|
||||
|
||||
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,"yellow","test label #2")
|
||||
|
||||
print "kill image window when ready to contine ..."
|
||||
print("kill image window when ready to contine ...")
|
||||
r.show(0)
|
||||
r.pan(60,130,1,60,30,0.5)
|
||||
r.all(0,10,0)
|
||||
a2 = animate("tmp0*png")
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
# requires files/dump.kinase
|
||||
# creates tmp*.png
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
d = dump("files/dump.kinase")
|
||||
s = svg(d)
|
||||
|
||||
@ -10,20 +12,20 @@ s.rotate(60,130)
|
||||
s.box(1)
|
||||
s.file = "tmp"
|
||||
|
||||
print "kill image window when ready to contine ..."
|
||||
print("kill image window when ready to contine ...")
|
||||
s.show(0)
|
||||
s.all()
|
||||
|
||||
from vizinfo import colors
|
||||
|
||||
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,"yellow","test label #2")
|
||||
|
||||
print "kill image window when ready to contine ..."
|
||||
print("kill image window when ready to contine ...")
|
||||
s.show(0)
|
||||
s.pan(60,130,1,60,30,0.5)
|
||||
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")
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
# simple test of vcr tool
|
||||
# requires files/bucky*png files
|
||||
|
||||
d = dump("files/dump.micelle")
|
||||
dt = data("files/data.micelle")
|
||||
@ -14,4 +13,4 @@ v.clipxlo(0.2)
|
||||
v.clipxhi(0.5)
|
||||
v.play()
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -4,13 +4,13 @@
|
||||
|
||||
v = vec("files/vec.txt")
|
||||
|
||||
print "# of vectors =",v.nvec
|
||||
print "length of vectors =",v.nlen
|
||||
print "names of vectors =",v.names
|
||||
print("# of vectors =",v.nvec)
|
||||
print("length of vectors =",v.nlen)
|
||||
print("names of vectors =",v.names)
|
||||
|
||||
time,temp,press = v.get(1,"col2",6)
|
||||
print temp,press
|
||||
print(temp,press)
|
||||
v.write("tmp.vec")
|
||||
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")
|
||||
|
||||
@ -8,4 +8,4 @@ v.rep('VDW')
|
||||
v.new('files/peptide.pdb','pdb')
|
||||
v.flush()
|
||||
|
||||
print "all done ... type CTRL-D to exit Pizza.py"
|
||||
print("all done ... type CTRL-D to exit Pizza.py")
|
||||
|
||||
@ -8,4 +8,4 @@ v.one()
|
||||
v.many()
|
||||
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")
|
||||
|
||||
@ -8,4 +8,4 @@ x.one()
|
||||
x.many()
|
||||
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")
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python
|
||||
|
||||
# Script: angle_distribute.py
|
||||
# Script: angle_distribute.py
|
||||
# Purpose: binned angle distributions by angle type
|
||||
# Syntax: angle_distribute.py datafile nbin theta_min theta_max outfile files ...
|
||||
# datafile = lammps data file
|
||||
@ -17,15 +17,14 @@
|
||||
import sys
|
||||
from dump import dump
|
||||
from math import sqrt,acos,atan
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 7:
|
||||
raise StandardError, \
|
||||
"Syntax: angle_distribute.py datafile nbin theta_min theta_max outfile files ..."
|
||||
raise Exception("Syntax: angle_distribute.py datafile nbin theta_min theta_max outfile files ...")
|
||||
|
||||
dt = data(argv[1])
|
||||
dt = data(argv[1])
|
||||
nbins = int(argv[2])
|
||||
theta_min = float(argv[3])
|
||||
theta_max = float(argv[4])
|
||||
@ -40,19 +39,19 @@ atype = nangles * [0]
|
||||
iatom = nangles * [0]
|
||||
jatom = nangles * [0]
|
||||
katom = nangles * [0]
|
||||
for i in xrange(nangles):
|
||||
for i in range(nangles):
|
||||
atype[i] = int(angle[i][1] - 1)
|
||||
iatom[i] = int(angle[i][2] - 1)
|
||||
jatom[i] = int(angle[i][3] - 1)
|
||||
katom[i] = int(angle[i][4] - 1)
|
||||
|
||||
ntypes = 0
|
||||
for i in xrange(nangles): ntypes = max(angle[i][1],ntypes)
|
||||
for i in range(nangles): ntypes = max(angle[i][1],ntypes)
|
||||
ntypes = int(ntypes)
|
||||
ncount = ntypes * [0]
|
||||
bin = nbins * [0]
|
||||
for i in xrange(nbins):
|
||||
bin[i] = ntypes * [0]
|
||||
for i in range(nbins):
|
||||
bin[i] = ntypes * [0]
|
||||
|
||||
# read snapshots one-at-a-time
|
||||
|
||||
@ -64,24 +63,24 @@ PI = 4.0*atan(1.0)
|
||||
while 1:
|
||||
time = d.next()
|
||||
if time == -1: break
|
||||
|
||||
|
||||
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
|
||||
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
|
||||
|
||||
|
||||
xprd = box[3] - box[0]
|
||||
yprd = box[4] - box[1]
|
||||
yprd = box[4] - box[1]
|
||||
zprd = box[5] - box[2]
|
||||
|
||||
d.unscale()
|
||||
|
||||
d.unscale()
|
||||
d.sort()
|
||||
x,y,z = d.vecs(time,"x","y","z")
|
||||
|
||||
for i in xrange(nangles):
|
||||
|
||||
|
||||
for i in range(nangles):
|
||||
|
||||
delx1 = x[iatom[i]] - x[jatom[i]]
|
||||
dely1 = y[iatom[i]] - y[jatom[i]]
|
||||
delz1 = z[iatom[i]] - z[jatom[i]]
|
||||
|
||||
|
||||
if abs(delx1) > 0.5*xprd:
|
||||
if delx1 < 0.0:
|
||||
delx1 += xprd
|
||||
@ -97,13 +96,13 @@ while 1:
|
||||
delz1 += zprd
|
||||
else:
|
||||
delz1 -= zprd
|
||||
|
||||
|
||||
r1 = sqrt(delx1*delx1 + dely1*dely1 + delz1*delz1)
|
||||
|
||||
|
||||
delx2 = x[katom[i]] - x[jatom[i]]
|
||||
dely2 = y[katom[i]] - y[jatom[i]]
|
||||
delz2 = z[katom[i]] - z[jatom[i]]
|
||||
|
||||
|
||||
if abs(delx2) > 0.5*xprd:
|
||||
if delx2 < 0.0:
|
||||
delx2 += xprd
|
||||
@ -119,38 +118,38 @@ while 1:
|
||||
delz2 += zprd
|
||||
else:
|
||||
delz2 -= zprd
|
||||
|
||||
|
||||
r2 = sqrt(delx2*delx2 + dely2*dely2 + delz2*delz2)
|
||||
|
||||
|
||||
c = delx1*delx2 + dely1*dely2 + delz1*delz2
|
||||
c /= r1*r2
|
||||
|
||||
|
||||
if (c > 1.0): c = 1.0
|
||||
if (c < -1.0): c = -1.0
|
||||
|
||||
|
||||
theta = 180.0*acos(c)/PI
|
||||
|
||||
|
||||
ibin = int(nbins*(theta - theta_min)/(theta_max - theta_min) + 0.5)
|
||||
if ((ibin >= 0) and (ibin <= nbins-1)):
|
||||
if ((ibin >= 0) and (ibin <= nbins-1)):
|
||||
bin[ibin][atype[i]] += nbins
|
||||
ncount[atype[i]] += 1
|
||||
else:
|
||||
print "Warning: angle outside specified range"
|
||||
print "angle type:", atype[i]+1
|
||||
print "angle number:", i
|
||||
print time,
|
||||
|
||||
print
|
||||
print "Printing normalized angle distributions to",outfile
|
||||
|
||||
print("Warning: angle outside specified range")
|
||||
print("angle type:", atype[i]+1)
|
||||
print("angle number:", i)
|
||||
print(time, end=' ')
|
||||
|
||||
print()
|
||||
print("Printing normalized angle distributions to",outfile)
|
||||
|
||||
fp = open(outfile,"w")
|
||||
theta_range = theta_max - theta_min
|
||||
for i in xrange(nbins):
|
||||
print >>fp, theta_min + theta_range*float(i)/float(nbins),
|
||||
for j in xrange(ntypes):
|
||||
for i in range(nbins):
|
||||
print(theta_min + theta_range*float(i)/float(nbins), end=' ', file=fp)
|
||||
for j in range(ntypes):
|
||||
if (ncount[j] > 0):
|
||||
print >>fp, float(bin[i][j])/float(ncount[j])/theta_range,
|
||||
print(float(bin[i][j])/float(ncount[j])/theta_range, end=' ', file=fp)
|
||||
else:
|
||||
print >>fp, 0.0,
|
||||
print >>fp
|
||||
print(0.0, end=' ', file=fp)
|
||||
print(file=fp)
|
||||
fp.close()
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
# Script: block.py
|
||||
# Purpose: thermodynamic block averages from LAMMPS log files
|
||||
# Syntax: block.py nblocks nskip log.1 log.2 ...
|
||||
# nblocks = number of blocks for block averages
|
||||
# nblocks = number of blocks for block averages
|
||||
# nskip = skip first nskip samples in the log file(s)
|
||||
# files = series of log files (LAMMPS thermo one style only)
|
||||
# Example: block.py 10 0 log.*
|
||||
@ -13,12 +13,12 @@
|
||||
|
||||
import sys
|
||||
from log import log
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 4:
|
||||
raise StandardError, "Syntax: block.py nblocks nskip log.1 log.2 ..."
|
||||
raise Exception("Syntax: block.py nblocks nskip log.1 log.2 ...")
|
||||
|
||||
nblocks = int(argv[1])
|
||||
nskip = int(argv[2])
|
||||
@ -35,24 +35,24 @@ if "Volume" in l.names:
|
||||
volume = l.get("Volume")
|
||||
else: vflag = 0
|
||||
|
||||
print "Computing %g block averages" % nblocks
|
||||
print "Skipping first %g samples" % nskip
|
||||
print("Computing %g block averages" % nblocks)
|
||||
print("Skipping first %g samples" % nskip)
|
||||
|
||||
n = len(step)
|
||||
n_per_block = (n-nskip)/nblocks
|
||||
k = nskip
|
||||
temperature_ave = []
|
||||
e_bond_ave = []
|
||||
e_pair_ave = []
|
||||
e_pair_ave = []
|
||||
e_total_ave = []
|
||||
pressure_ave = []
|
||||
volume_ave = []
|
||||
|
||||
print
|
||||
print " Block Samples Temperature E_bond E_pair", \
|
||||
" E_total Pressure Volume"
|
||||
print()
|
||||
print(" Block Samples Temperature E_bond E_pair", \
|
||||
" E_total Pressure Volume")
|
||||
|
||||
for i in xrange(nblocks):
|
||||
for i in range(nblocks):
|
||||
temperature_sum = 0
|
||||
e_bond_sum = 0
|
||||
e_pair_sum = 0
|
||||
@ -60,7 +60,7 @@ for i in xrange(nblocks):
|
||||
pressure_sum = 0
|
||||
volume_sum = 0
|
||||
samples = 0
|
||||
for j in xrange(n_per_block):
|
||||
for j in range(n_per_block):
|
||||
temperature_sum += temperature[k]
|
||||
e_bond_sum += e_bond[k]
|
||||
e_pair_sum += e_pair[k]
|
||||
@ -75,42 +75,42 @@ for i in xrange(nblocks):
|
||||
e_total_ave.append(e_total_sum/samples)
|
||||
pressure_ave.append(pressure_sum/samples)
|
||||
volume_ave.append(volume_sum/samples)
|
||||
print " %5i %10i %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
|
||||
print(" %5i %10i %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
|
||||
(i+1, samples, temperature_ave[i], e_bond_ave[i], e_pair_ave[i], \
|
||||
e_total_ave[i], pressure_ave[i], volume_ave[i])
|
||||
e_total_ave[i], pressure_ave[i], volume_ave[i]))
|
||||
|
||||
grand_ave_temperature = 0.0
|
||||
grand_ave_e_bond = 0.0
|
||||
grand_ave_e_pair = 0.0
|
||||
grand_ave_e_total = 0.0
|
||||
grand_ave_pressure = 0.0
|
||||
grand_ave_volume = 0.0
|
||||
grand_ave_volume = 0.0
|
||||
stdev_temperature = 0.0
|
||||
stdev_e_bond = 0.0
|
||||
stdev_e_pair = 0.0
|
||||
stdev_e_total = 0.0
|
||||
stdev_pressure = 0.0
|
||||
stdev_volume = 0.0
|
||||
for i in xrange(nblocks):
|
||||
stdev_volume = 0.0
|
||||
for i in range(nblocks):
|
||||
grand_ave_temperature += temperature_ave[i]
|
||||
grand_ave_e_bond += e_bond_ave[i]
|
||||
grand_ave_e_pair += e_pair_ave[i]
|
||||
grand_ave_e_total += e_total_ave[i]
|
||||
grand_ave_pressure += pressure_ave[i]
|
||||
grand_ave_volume += volume_ave[i]
|
||||
grand_ave_volume += volume_ave[i]
|
||||
grand_ave_temperature /= nblocks
|
||||
grand_ave_e_bond /= nblocks
|
||||
grand_ave_e_pair /= nblocks
|
||||
grand_ave_e_total /= nblocks
|
||||
grand_ave_pressure /= nblocks
|
||||
grand_ave_volume /= nblocks
|
||||
for i in xrange(nblocks):
|
||||
grand_ave_volume /= nblocks
|
||||
for i in range(nblocks):
|
||||
stdev_temperature += (temperature_ave[i] - grand_ave_temperature)* \
|
||||
(temperature_ave[i] - grand_ave_temperature)
|
||||
stdev_e_bond += (e_bond_ave[i] - grand_ave_e_bond)* \
|
||||
(e_bond_ave[i] - grand_ave_e_bond)
|
||||
stdev_e_pair += (e_pair_ave[i] - grand_ave_e_pair)* \
|
||||
(e_pair_ave[i] - grand_ave_e_pair)
|
||||
(e_pair_ave[i] - grand_ave_e_pair)
|
||||
stdev_e_total += (e_total_ave[i] - grand_ave_e_total)* \
|
||||
(e_total_ave[i] - grand_ave_e_total)
|
||||
stdev_pressure += (pressure_ave[i] - grand_ave_pressure)* \
|
||||
@ -123,15 +123,15 @@ stdev_e_bond = sqrt(stdev_e_bond/(nblocks-1))
|
||||
stdev_e_pair = sqrt(stdev_e_pair/(nblocks-1))
|
||||
stdev_e_total = sqrt(stdev_e_total/(nblocks-1))
|
||||
stdev_pressure = sqrt(stdev_pressure/(nblocks-1))
|
||||
stdev_volume = sqrt(stdev_volume/(nblocks-1))
|
||||
stdev_volume = sqrt(stdev_volume/(nblocks-1))
|
||||
|
||||
print " ====================================================", \
|
||||
"==================================="
|
||||
|
||||
print " Ave. %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
|
||||
print(" ====================================================", \
|
||||
"===================================")
|
||||
|
||||
print(" Ave. %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
|
||||
(grand_ave_temperature, grand_ave_e_bond, grand_ave_e_pair, \
|
||||
grand_ave_e_total, grand_ave_pressure, grand_ave_volume)
|
||||
|
||||
print " Stdev %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
|
||||
grand_ave_e_total, grand_ave_pressure, grand_ave_volume))
|
||||
|
||||
print(" Stdev %11.2f %11.2f %11.2f %11.2f %11.2f %11.2f" % \
|
||||
(stdev_temperature, stdev_e_bond, stdev_e_pair, \
|
||||
stdev_e_total, stdev_pressure, stdev_volume)
|
||||
stdev_e_total, stdev_pressure, stdev_volume))
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python
|
||||
|
||||
# Script: bond_distribute.py
|
||||
# Script: bond_distribute.py
|
||||
# Purpose: binned bond length distributions by bond type
|
||||
# Syntax: bond_distribute.py datafile nbin rmin rmax outfile files ...
|
||||
# datafile = lammps data file
|
||||
@ -17,15 +17,14 @@
|
||||
import sys
|
||||
from dump import dump
|
||||
from math import sqrt
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 7:
|
||||
raise StandardError, \
|
||||
"Syntax: bond_distribute.py datafile nbin rmin rmax outfile files ..."
|
||||
raise Exception("Syntax: bond_distribute.py datafile nbin rmin rmax outfile files ...")
|
||||
|
||||
dt = data(argv[1])
|
||||
dt = data(argv[1])
|
||||
nbins = int(argv[2])
|
||||
rmin = float(argv[3])
|
||||
rmax = float(argv[4])
|
||||
@ -39,18 +38,18 @@ nbonds = len(bond)
|
||||
btype = nbonds * [0]
|
||||
iatom = nbonds * [0]
|
||||
jatom = nbonds * [0]
|
||||
for i in xrange(nbonds):
|
||||
for i in range(nbonds):
|
||||
btype[i] = int(bond[i][1] - 1)
|
||||
iatom[i] = int(bond[i][2] - 1)
|
||||
jatom[i] = int(bond[i][3] - 1)
|
||||
|
||||
ntypes = 0
|
||||
for i in xrange(nbonds): ntypes = max(bond[i][1],ntypes)
|
||||
for i in range(nbonds): ntypes = max(bond[i][1],ntypes)
|
||||
ntypes = int(ntypes)
|
||||
ncount = ntypes * [0]
|
||||
bin = nbins * [0]
|
||||
for i in xrange(nbins):
|
||||
bin[i] = ntypes * [0]
|
||||
for i in range(nbins):
|
||||
bin[i] = ntypes * [0]
|
||||
|
||||
# read snapshots one-at-a-time
|
||||
|
||||
@ -60,24 +59,24 @@ d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
|
||||
while 1:
|
||||
time = d.next()
|
||||
if time == -1: break
|
||||
|
||||
|
||||
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
|
||||
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
|
||||
|
||||
|
||||
xprd = box[3] - box[0]
|
||||
yprd = box[4] - box[1]
|
||||
yprd = box[4] - box[1]
|
||||
zprd = box[5] - box[2]
|
||||
|
||||
d.unscale()
|
||||
|
||||
d.unscale()
|
||||
d.sort()
|
||||
x,y,z = d.vecs(time,"x","y","z")
|
||||
|
||||
for i in xrange(nbonds):
|
||||
|
||||
|
||||
for i in range(nbonds):
|
||||
|
||||
delx = x[jatom[i]] - x[iatom[i]]
|
||||
dely = y[jatom[i]] - y[iatom[i]]
|
||||
delz = z[jatom[i]] - z[iatom[i]]
|
||||
|
||||
|
||||
if abs(delx) > 0.5*xprd:
|
||||
if delx < 0.0:
|
||||
delx += xprd
|
||||
@ -93,30 +92,30 @@ while 1:
|
||||
delz += zprd
|
||||
else:
|
||||
delz -= zprd
|
||||
|
||||
|
||||
r = sqrt(delx*delx + dely*dely + delz*delz)
|
||||
|
||||
|
||||
ibin = int(nbins*(r - rmin)/(rmax - rmin) + 0.5)
|
||||
if ((ibin >= 0) and (ibin <= nbins-1)):
|
||||
if ((ibin >= 0) and (ibin <= nbins-1)):
|
||||
bin[ibin][btype[i]] += nbins
|
||||
ncount[btype[i]] += 1
|
||||
else:
|
||||
print "Warning: bond distance outside specified range"
|
||||
print "Bond type:", btype[i]+1
|
||||
print "Bond number:", i
|
||||
print time,
|
||||
|
||||
print
|
||||
print "Printing bond distance normalized distribution to",outfile
|
||||
|
||||
print("Warning: bond distance outside specified range")
|
||||
print("Bond type:", btype[i]+1)
|
||||
print("Bond number:", i)
|
||||
print(time, end=' ')
|
||||
|
||||
print()
|
||||
print("Printing bond distance normalized distribution to",outfile)
|
||||
|
||||
fp = open(outfile,"w")
|
||||
rrange = rmax - rmin
|
||||
for i in xrange(nbins):
|
||||
print >>fp, rmin + rrange*float(i)/float(nbins),
|
||||
for j in xrange(ntypes):
|
||||
for i in range(nbins):
|
||||
print(rmin + rrange*float(i)/float(nbins), end=' ', file=fp)
|
||||
for j in range(ntypes):
|
||||
if (ncount[j] > 0):
|
||||
print >>fp, float(bin[i][j])/float(ncount[j])/rrange,
|
||||
print(float(bin[i][j])/float(ncount[j])/rrange, end=' ', file=fp)
|
||||
else:
|
||||
print >>fp, 0.0,
|
||||
print >>fp
|
||||
print(0.0, end=' ', file=fp)
|
||||
print(file=fp)
|
||||
fp.close()
|
||||
|
||||
@ -15,18 +15,18 @@ from clog import clog
|
||||
from plotview import plotview
|
||||
from gnu import gnu
|
||||
from matlab import matlab
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 3:
|
||||
raise StandardError, "Syntax: clogview.py gnu/matlab files ..."
|
||||
raise Exception("Syntax: clogview.py gnu/matlab files ...")
|
||||
|
||||
style = argv[1]
|
||||
files = ' '.join(argv[2:])
|
||||
|
||||
c = clog(files)
|
||||
exec "plot = %s()" % style
|
||||
exec("plot = %s()" % style)
|
||||
p = plotview(c,plot)
|
||||
p.x = "Time"
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
import sys
|
||||
from dump import dump
|
||||
from gnu import gnu
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
@ -31,11 +31,11 @@ def distance(atom1,atom2,box):
|
||||
x2 = atom2[2]
|
||||
y2 = atom2[3]
|
||||
z2 = atom2[4]
|
||||
|
||||
|
||||
delx = x2 - x1
|
||||
dely = y2 - y1
|
||||
delz = z2 - z1
|
||||
|
||||
|
||||
xprd = box[3] - box[0]
|
||||
yprd = box[4] - box[1]
|
||||
zprd = box[5] - box[2]
|
||||
@ -55,14 +55,14 @@ def distance(atom1,atom2,box):
|
||||
delz += zprd
|
||||
else:
|
||||
delz -= zprd
|
||||
|
||||
|
||||
distsq = delx*delx + dely*dely + delz*delz
|
||||
return distsq
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 6:
|
||||
raise StandardError,"cluster.py type1 type2 cutoff nbin dump.1 dump.2 ..."
|
||||
raise Exception("cluster.py type1 type2 cutoff nbin dump.1 dump.2 ...")
|
||||
|
||||
type1 = int(argv[1])
|
||||
type2 = int(argv[2])
|
||||
@ -81,41 +81,41 @@ d.aselect.test("$type == %d or $type == %d" % (type1,type2))
|
||||
cutsq = cutoff*cutoff
|
||||
cluster = nbin*[0]
|
||||
|
||||
print "Clustering ..."
|
||||
print("Clustering ...")
|
||||
|
||||
flag = 0
|
||||
while 1:
|
||||
which,time,flag = d.iterator(flag)
|
||||
if flag == -1: break
|
||||
time,box,atoms,bonds,tris = d.viz(which)
|
||||
print time,
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
|
||||
# loop over all type1 atoms
|
||||
|
||||
|
||||
n = len(atoms)
|
||||
for i in xrange(n):
|
||||
for i in range(n):
|
||||
itype = atoms[i][1]
|
||||
if itype != type1: continue
|
||||
ncount = 0
|
||||
|
||||
# loop over all type2 atoms
|
||||
# increment cluster count if distance is within cutoff
|
||||
|
||||
for j in xrange(n):
|
||||
|
||||
for j in range(n):
|
||||
jtype = atoms[j][1]
|
||||
if jtype != type2 or i == j: continue
|
||||
if jtype != type2 or i == j: continue
|
||||
distsq = distance(atoms[i],atoms[j],box)
|
||||
if distsq < cutsq: ncount += 1
|
||||
|
||||
# increment histogram count
|
||||
|
||||
|
||||
if ncount >= nbin: cluster[nbin-1] += 1
|
||||
else: cluster[ncount] += 1
|
||||
|
||||
print
|
||||
print "Cluster size and count:"
|
||||
for i in range(nbin): print i,cluster[i]
|
||||
print()
|
||||
print("Cluster size and count:")
|
||||
for i in range(nbin): print(i,cluster[i])
|
||||
|
||||
# comment out if don't want plot
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python
|
||||
|
||||
# Script: density.py
|
||||
# Purpose: binned atom density by atom type
|
||||
@ -14,12 +14,12 @@
|
||||
|
||||
import sys
|
||||
from dump import dump
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 5:
|
||||
raise StandardError, "Syntax: density.py x/y/z nbin outfile files ..."
|
||||
raise Exception("Syntax: density.py x/y/z nbin outfile files ...")
|
||||
|
||||
direction = argv[1]
|
||||
nbins = int(argv[2])
|
||||
@ -41,37 +41,37 @@ while 1:
|
||||
tmp,ntypes = d.minmax("type")
|
||||
ntypes = int(ntypes)
|
||||
bin = nbins * [0]
|
||||
for i in xrange(nbins): bin[i] = ntypes * [0]
|
||||
for i in range(nbins): bin[i] = ntypes * [0]
|
||||
first = 0
|
||||
|
||||
|
||||
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
|
||||
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
|
||||
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
|
||||
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
|
||||
|
||||
if direction == "x": type,x = d.vecs(time,"type","x")
|
||||
elif direction == "y": type,x = d.vecs(time,"type","y")
|
||||
elif direction == "z": type,x = d.vecs(time,"type","z")
|
||||
|
||||
type = map(int,type)
|
||||
|
||||
type = list(map(int,type))
|
||||
natoms = len(type)
|
||||
for i in xrange(natoms): type[i] -= 1
|
||||
|
||||
for i in xrange(natoms):
|
||||
for i in range(natoms): type[i] -= 1
|
||||
|
||||
for i in range(natoms):
|
||||
ibin = int(nbins*x[i] + 0.5)
|
||||
if (ibin < 0): ibin += nbins
|
||||
if (ibin > nbins-1): ibin -= nbins
|
||||
bin[ibin][type[i]] += nbins/vol
|
||||
nsnaps += 1
|
||||
print time,
|
||||
|
||||
print
|
||||
print "Printing ", direction, "-directional density distribution in mol/L to",outfile
|
||||
print(time, end=' ')
|
||||
|
||||
print()
|
||||
print("Printing ", direction, "-directional density distribution in mol/L to",outfile)
|
||||
conversion = 1660.53873 # convert from atoms/Angs^3 to mol/L
|
||||
|
||||
|
||||
fp = open(outfile,"w")
|
||||
for i in xrange(nbins):
|
||||
print >>fp, float(i)/float(nbins),
|
||||
for j in xrange(ntypes):
|
||||
print >>fp, conversion*bin[i][j]/nsnaps,
|
||||
print >>fp
|
||||
for i in range(nbins):
|
||||
print(float(i)/float(nbins), end=' ', file=fp)
|
||||
for j in range(ntypes):
|
||||
print(conversion*bin[i][j]/nsnaps, end=' ', file=fp)
|
||||
print(file=fp)
|
||||
fp.close()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python
|
||||
|
||||
# Script: density2d.py
|
||||
# Purpose: binned atom density by atom type
|
||||
@ -18,12 +18,12 @@
|
||||
import sys
|
||||
import numpy as np
|
||||
from dump import dump
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 5:
|
||||
raise StandardError, "Syntax: density.py x/y/z nbin vmin vmax outfile files ..."
|
||||
raise Exception("Syntax: density.py x/y/z nbin vmin vmax outfile files ...")
|
||||
|
||||
direction = argv[1]
|
||||
nbins = int(argv[2])
|
||||
@ -65,12 +65,12 @@ while 1:
|
||||
ntypes = int(ntypes)
|
||||
bin = np.zeros(shape=(nbins,nbins,ntypes))
|
||||
first = 0
|
||||
|
||||
|
||||
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
|
||||
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
|
||||
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
|
||||
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
|
||||
|
||||
if direction == "z":
|
||||
if direction == "z":
|
||||
type,x,y,z = d.vecs(time,"type","x","y","z")
|
||||
bidirect = 'x/y'
|
||||
dx = box[3] - box[0]
|
||||
@ -90,7 +90,7 @@ while 1:
|
||||
y0 = box[2] + float(dy)/float(nbins)/2.0
|
||||
zmax = min(zmax,box[4])
|
||||
zmin = max(zmin,box[1])
|
||||
elif direction == "x":
|
||||
elif direction == "x":
|
||||
type,x,y,z = d.vecs(time,"type","y","z","x")
|
||||
bidirect = 'y/z'
|
||||
dx = box[4] - box[1]
|
||||
@ -102,11 +102,11 @@ while 1:
|
||||
zmin = max(zmin,box[0])
|
||||
vol = dx * dy * float(zmax - zmin)
|
||||
|
||||
type = map(int,type)
|
||||
type = list(map(int,type))
|
||||
natoms = len(type)
|
||||
for i in xrange(natoms): type[i] -= 1
|
||||
|
||||
for i in xrange(natoms):
|
||||
for i in range(natoms): type[i] -= 1
|
||||
|
||||
for i in range(natoms):
|
||||
ibin = int(nbins*x[i])
|
||||
jbin = int(nbins*y[i])
|
||||
zloc = float(z[i])*float(dz)
|
||||
@ -117,22 +117,22 @@ while 1:
|
||||
if (jbin > nbins-1): jbin = nbins - 1
|
||||
bin[jbin][ibin][type[i]] += nbins*nbins/vol
|
||||
nsnaps += 1
|
||||
print time,
|
||||
print(time, end=' ')
|
||||
|
||||
print
|
||||
print "Printing %s-mapped density distribution for %s-slice [%.2f,%.2f] in mol/L to %s" %(bidirect, direction, zmin, zmax, outfile)
|
||||
print()
|
||||
print("Printing %s-mapped density distribution for %s-slice [%.2f,%.2f] in mol/L to %s" %(bidirect, direction, zmin, zmax, outfile))
|
||||
conversion = 1660.53873 # convert from atoms/Angs^3 to mol/L
|
||||
|
||||
|
||||
fp = open(outfile,"w")
|
||||
# '''Uncomment for column headers. Commented for consistency with density.py'''
|
||||
# print >>fp, " %8s %8s " %('ra', 'rb'),
|
||||
# for k in xrange(ntypes):
|
||||
# print >>fp, " %8s " %(k),
|
||||
# print >>fp
|
||||
for i in xrange(nbins):
|
||||
for j in xrange(nbins):
|
||||
print >>fp, " %8.3f %8.3f " %(float(i)/float(nbins)*float(dx)+float(x0), float(j)/float(nbins)*float(dy)+float(y0)),
|
||||
for k in xrange(ntypes):
|
||||
print >>fp, " %8.3f " % (conversion*bin[j][i][k]/nsnaps),
|
||||
print >>fp
|
||||
for i in range(nbins):
|
||||
for j in range(nbins):
|
||||
print(" %8.3f %8.3f " %(float(i)/float(nbins)*float(dx)+float(x0), float(j)/float(nbins)*float(dy)+float(y0)), end=' ', file=fp)
|
||||
for k in range(ntypes):
|
||||
print(" %8.3f " % (conversion*bin[j][i][k]/nsnaps), end=' ', file=fp)
|
||||
print(file=fp)
|
||||
fp.close()
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python
|
||||
|
||||
# Script: density_area.py
|
||||
# Purpose: binned atom density by atom type and running area under the curve
|
||||
@ -16,12 +16,12 @@
|
||||
|
||||
import sys
|
||||
from dump import dump
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 5:
|
||||
raise StandardError, "Syntax: density.py x/y/z nbin outfile files ..."
|
||||
raise Exception("Syntax: density.py x/y/z nbin outfile files ...")
|
||||
|
||||
direction = argv[1]
|
||||
nbins = int(argv[2])
|
||||
@ -44,54 +44,54 @@ while 1:
|
||||
tmp,ntypes = d.minmax("type")
|
||||
ntypes = int(ntypes)
|
||||
bin = nbins * [0]
|
||||
for i in xrange(nbins): bin[i] = ntypes * [0]
|
||||
for i in range(nbins): bin[i] = ntypes * [0]
|
||||
first = 0
|
||||
|
||||
|
||||
box = (d.snaps[-1].xlo,d.snaps[-1].ylo,d.snaps[-1].zlo,
|
||||
d.snaps[-1].xhi,d.snaps[-1].yhi,d.snaps[-1].zhi)
|
||||
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
|
||||
vol = (box[3] - box[0]) * (box[4] - box[1]) * (box[5] - box[2])
|
||||
|
||||
if direction == "x": type,x = d.vecs(time,"type","x")
|
||||
elif direction == "y": type,x = d.vecs(time,"type","y")
|
||||
elif direction == "z": type,x = d.vecs(time,"type","z")
|
||||
|
||||
type = map(int,type)
|
||||
|
||||
type = list(map(int,type))
|
||||
natoms = len(type)
|
||||
for i in xrange(natoms): type[i] -= 1
|
||||
|
||||
for i in xrange(natoms):
|
||||
for i in range(natoms): type[i] -= 1
|
||||
|
||||
for i in range(natoms):
|
||||
ibin = int(nbins*x[i] + 0.5)
|
||||
if (ibin < 0): ibin += nbins
|
||||
if (ibin > nbins-1): ibin -= nbins
|
||||
bin[ibin][type[i]] += nbins/vol
|
||||
nsnaps += 1
|
||||
print time,
|
||||
|
||||
print
|
||||
print "Printing ",direction,"-directional density distribution in mol/L to", \
|
||||
outfile
|
||||
print(time, end=' ')
|
||||
|
||||
print()
|
||||
print("Printing ",direction,"-directional density distribution in mol/L to", \
|
||||
outfile)
|
||||
conversion = 1660.53873 # convert from atoms/Angs^3 to mol/L
|
||||
|
||||
|
||||
# Output as x, density_1, area_1, ...
|
||||
|
||||
fp = open(outfile,"w")
|
||||
first = 1
|
||||
xden = nbins * [0]
|
||||
yden = nbins * [0]
|
||||
for i in xrange(nbins): yden[i] = ntypes * [0]
|
||||
for i in range(nbins): yden[i] = ntypes * [0]
|
||||
sum = ntypes * [0]
|
||||
for i in xrange(nbins):
|
||||
for i in range(nbins):
|
||||
xden[i] = float(i)/float(nbins)
|
||||
print >>fp, xden[i],
|
||||
print(xden[i], end=' ', file=fp)
|
||||
if first:
|
||||
for j in xrange(ntypes):
|
||||
for j in range(ntypes):
|
||||
yden[i][j] = conversion*bin[i][j]/nsnaps
|
||||
print >>fp, yden[i][j], sum[j],
|
||||
print(yden[i][j], sum[j], end=' ', file=fp)
|
||||
first = 0
|
||||
else:
|
||||
for j in xrange(ntypes):
|
||||
for j in range(ntypes):
|
||||
yden[i][j] = conversion*bin[i][j]/nsnaps
|
||||
sum[j] += 0.5 * (xden[i] - xden[i-1]) * (yden[i][j] + yden[i-1][j])
|
||||
print >>fp, yden[i][j], sum[j],
|
||||
print >>fp
|
||||
print(yden[i][j], sum[j], end=' ', file=fp)
|
||||
print(file=fp)
|
||||
fp.close()
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
# Script: distance.py
|
||||
# Script: distance.py
|
||||
# Purpose: check if any atom pairs are closer than specified distance
|
||||
# Syntax: distance.py maxcut dump.file1 dump.file2 ...
|
||||
# maxcut = flag atoms which are less than this distance apart
|
||||
@ -12,12 +12,12 @@
|
||||
from math import sqrt
|
||||
|
||||
if len(argv) < 3:
|
||||
raise StandardError,"distance.py maxcut dump.file1 dump.file2 ..."
|
||||
|
||||
raise Exception("distance.py maxcut dump.file1 dump.file2 ...")
|
||||
|
||||
maxcut = float(argv[1])
|
||||
maxcut_sq = maxcut*maxcut
|
||||
|
||||
files = ' '.join(argv[2:]) # dump files
|
||||
|
||||
files = ' '.join(argv[2:]) # dump files
|
||||
d = dump(files,0)
|
||||
d.map(1,"id",2,"type",3,"x",4,"y",5,"z")
|
||||
|
||||
@ -35,10 +35,10 @@ while 1:
|
||||
xprd = box[3] - box[0]
|
||||
yprd = box[4] - box[1]
|
||||
zprd = box[5] - box[2]
|
||||
|
||||
for i in xrange(n):
|
||||
for j in xrange(i+1,n):
|
||||
|
||||
|
||||
for i in range(n):
|
||||
for j in range(i+1,n):
|
||||
|
||||
delx = x[j] - x[i]
|
||||
if abs(delx) > 0.5*xprd:
|
||||
if delx < 0.0:
|
||||
@ -46,7 +46,7 @@ while 1:
|
||||
else:
|
||||
delx -= xprd
|
||||
if (delx*delx < maxcut_sq):
|
||||
|
||||
|
||||
dely = y[j] - y[i]
|
||||
if abs(dely) > 0.5*yprd:
|
||||
if dely < 0.0:
|
||||
@ -54,22 +54,22 @@ while 1:
|
||||
else:
|
||||
dely -= yprd
|
||||
if ((dely*dely + delx*delx) < maxcut_sq):
|
||||
|
||||
|
||||
delz = z[j] - z[i]
|
||||
if abs(delz) > 0.5*zprd:
|
||||
if delz < 0.0:
|
||||
delz += zprd
|
||||
else:
|
||||
delz -= zprd
|
||||
|
||||
|
||||
rsq = delx*delx + dely*dely + delz*delz
|
||||
|
||||
if rsq < maxcut_sq:
|
||||
print "time = %d, id[i] = %d, id[j] = %d," \
|
||||
|
||||
if rsq < maxcut_sq:
|
||||
print("time = %d, id[i] = %d, id[j] = %d," \
|
||||
" type[i] = %d, type[j] = %d, distance = %g" % \
|
||||
(time, id[i], id[j], type[i], type[j], sqrt(rsq))
|
||||
(time, id[i], id[j], type[i], type[j], sqrt(rsq)))
|
||||
|
||||
d.tselect.none()
|
||||
d.tselect.one(time)
|
||||
print "timestep = ", time
|
||||
print("timestep = ", time)
|
||||
d.delete()
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
# main script
|
||||
|
||||
if len(argv) < 2:
|
||||
raise StandardError, "Syntax: dview.py dump.1 ..."
|
||||
raise Exception("Syntax: dview.py dump.1 ...")
|
||||
|
||||
files = ' '.join(argv[1:])
|
||||
|
||||
|
||||
@ -13,18 +13,18 @@ import sys
|
||||
from dump import dump
|
||||
|
||||
# w/out Pizza.py these lines need to come before import of gl tool
|
||||
import Tkinter
|
||||
tkroot = Tkinter.Tk()
|
||||
import tkinter
|
||||
tkroot = tkinter.Tk()
|
||||
tkroot.withdraw()
|
||||
|
||||
from gl import gl
|
||||
from vcr import vcr
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 2:
|
||||
raise StandardError, "Syntax: dview.py dump.1 ..."
|
||||
raise Exception("Syntax: dview.py dump.1 ...")
|
||||
|
||||
files = ' '.join(argv[1:])
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python
|
||||
|
||||
# Script: flux.py
|
||||
# Purpose: flux of atoms through a user-defined plane
|
||||
@ -14,12 +14,12 @@
|
||||
|
||||
import sys
|
||||
from dump import dump
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 5:
|
||||
raise StandardError, "Syntax: flux.py x/y/z plane outfile files ..."
|
||||
raise Exception("Syntax: flux.py x/y/z plane outfile files ...")
|
||||
|
||||
direction = argv[1]
|
||||
scaled_plane = float(argv[2])
|
||||
@ -41,47 +41,47 @@ flag = 0
|
||||
while 1:
|
||||
which,time,flag = d.iterator(flag)
|
||||
if flag == -1: break
|
||||
|
||||
|
||||
if direction == "x":
|
||||
id,type,x = d.vecs(time,"id","type","x")
|
||||
lo = d.snaps[which].xlo
|
||||
hi = d.snaps[which].xhi
|
||||
elif direction == "y":
|
||||
id,type,x = d.vecs(time,"id","type","y")
|
||||
lo = d.snaps[which].ylo
|
||||
hi = d.snaps[which].yhi
|
||||
elif direction == "z":
|
||||
lo = d.snaps[which].ylo
|
||||
hi = d.snaps[which].yhi
|
||||
elif direction == "z":
|
||||
id,type,x = d.vecs(time,"id","type","z")
|
||||
lo = d.snaps[which].zlo
|
||||
hi = d.snaps[which].zhi
|
||||
|
||||
prd = hi - lo
|
||||
plane = lo + scaled_plane*prd
|
||||
|
||||
print time,
|
||||
lo = d.snaps[which].zlo
|
||||
hi = d.snaps[which].zhi
|
||||
|
||||
prd = hi - lo
|
||||
plane = lo + scaled_plane*prd
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
natoms = len(x)
|
||||
if jconfig == 0: x_initial = (natoms+1) * [0]
|
||||
jconfig += 1
|
||||
|
||||
typeflux = ntypes * [0]
|
||||
|
||||
for i in xrange(natoms):
|
||||
|
||||
for i in range(natoms):
|
||||
id[i] = int(id[i])
|
||||
type[i] = int(type[i])
|
||||
if jconfig == 1: x_initial[id[i]] = x[i]
|
||||
if x_initial[id[i]] < plane and x[i] > plane :
|
||||
crossings = int((x[i] - plane)/prd) + 1
|
||||
crossings = int((x[i] - plane)/prd) + 1
|
||||
typeflux[type[i]] += crossings
|
||||
elif x_initial[id[i]] > plane and x[i] < plane :
|
||||
crossings = int((plane - x[i])/prd) + 1
|
||||
typeflux[type[i]] -= crossings
|
||||
|
||||
print >>f,time,
|
||||
for j in xrange(ntypes-1):
|
||||
print >>f,typeflux[j+1],
|
||||
print >>f
|
||||
print
|
||||
|
||||
print(time, end=' ', file=f)
|
||||
for j in range(ntypes-1):
|
||||
print(typeflux[j+1], end=' ', file=f)
|
||||
print(file=f)
|
||||
print()
|
||||
|
||||
f.close()
|
||||
|
||||
@ -11,10 +11,10 @@
|
||||
|
||||
import sys
|
||||
from animate import animate
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
# this could be done with one-line alias in shell start-up file
|
||||
|
||||
if len(argv) < 2: raise StandardError, "Syntax: iview.py files ..."
|
||||
if len(argv) < 2: raise Exception("Syntax: iview.py files ...")
|
||||
a = animate(' '.join(argv[1:]))
|
||||
|
||||
@ -15,17 +15,17 @@ from log import log
|
||||
from plotview import plotview
|
||||
from gnu import gnu
|
||||
from matlab import matlab
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 3:
|
||||
raise StandardError, "Syntax: logview.py gnu/matlab files ..."
|
||||
raise Exception("Syntax: logview.py gnu/matlab files ...")
|
||||
|
||||
style = argv[1]
|
||||
files = ' '.join(argv[2:])
|
||||
|
||||
lg = log(files)
|
||||
exec "plot = %s()" % style
|
||||
exec("plot = %s()" % style)
|
||||
p = plotview(lg,plot)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
# Purpose: create images from LAMMPS dump snapshots
|
||||
# Syntax: movie.py raster/svg theta phi dump.1 dump.2 ...
|
||||
# raster/svg = style of image to create
|
||||
# theta/phi = vertical (z) and azimuthal angle to view from
|
||||
# theta/phi = vertical (z) and azimuthal angle to view from
|
||||
# files = one or more dump files
|
||||
# Example: movie.py svg 60 130 dump.*
|
||||
# Author: Steve Plimpton (Sandia)
|
||||
@ -15,12 +15,12 @@ import sys
|
||||
from dump import dump
|
||||
from raster import raster
|
||||
from svg import svg
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) < 5:
|
||||
raise StandardError, "Syntax: movie.py raster/svg theta phi dump.1 ..."
|
||||
raise Exception("Syntax: movie.py raster/svg theta phi dump.1 ...")
|
||||
|
||||
style = argv[1]
|
||||
theta = float(argv[2])
|
||||
@ -28,6 +28,6 @@ phi = float(argv[3])
|
||||
files = ' '.join(argv[4:])
|
||||
|
||||
d = dump(files)
|
||||
exec "viz = %s(d)" % style
|
||||
exec("viz = %s(d)" % style)
|
||||
viz.rotate(theta,phi)
|
||||
viz.all()
|
||||
|
||||
@ -14,17 +14,17 @@ import sys
|
||||
from plotview import plotview
|
||||
from gnu import gnu
|
||||
from matlab import matlab
|
||||
if not globals().has_key("argv"): argv = sys.argv
|
||||
if "argv" not in globals(): argv = sys.argv
|
||||
|
||||
# main script
|
||||
|
||||
if len(argv) != 3:
|
||||
raise StandardError, "Syntax: plot.py gnu/matlab file"
|
||||
raise Exception("Syntax: plot.py gnu/matlab file")
|
||||
|
||||
style = argv[1]
|
||||
file = argv[2]
|
||||
|
||||
v = vec(file)
|
||||
exec "plot = %s()" % style
|
||||
exec("plot = %s()" % style)
|
||||
p = plotview(v,plot)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# --------------
|
||||
|
||||
@ -3,28 +3,38 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# animate tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, os, re, glob
|
||||
try:
|
||||
from Tkinter import *
|
||||
except ImportError:
|
||||
from tkinter import *
|
||||
|
||||
oneline = "Animate a series of image files"
|
||||
|
||||
docstr = """
|
||||
a = animate("image*.png") create GUI to animate set of image files
|
||||
|
||||
a = animate("image*.png",1) 2nd arg = sort filenames, 0 = no sort, def = 1
|
||||
|
||||
Actions (same as GUI widgets):
|
||||
|
||||
a.first() go to first frame
|
||||
a.first() go to first frame
|
||||
a.prev() go to previous frame
|
||||
a.back() play backwards from current frame to start
|
||||
a.stop() stop on current frame
|
||||
a.stop() stop on current frame
|
||||
a.play() play from current frame to end
|
||||
a.next() go to next frame
|
||||
a.last() go to last frame
|
||||
a.next() go to next frame
|
||||
a.last() go to last frame
|
||||
|
||||
a.frame(31) set frame slider
|
||||
a.delay(0.4) set delay slider
|
||||
a.frame(31) set frame slider
|
||||
a.delay(0.4) set delay slider
|
||||
"""
|
||||
|
||||
# History
|
||||
@ -45,11 +55,6 @@ a.delay(0.4) set delay slider
|
||||
# delay_value = delay between frames (secs)
|
||||
# delay_msec = delay in millisec
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, os, commands, re, glob
|
||||
from Tkinter import *
|
||||
from ImageTk import PhotoImage
|
||||
|
||||
# Class definition
|
||||
|
||||
@ -57,32 +62,33 @@ class animate:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self,filestr):
|
||||
def __init__(self,filestr,sortflag=1):
|
||||
self.loop_flag = 0
|
||||
self.delay_value = 0.0
|
||||
self.delay_msec = 0
|
||||
|
||||
# convert filestr into full list of files
|
||||
|
||||
list = str.split(filestr)
|
||||
|
||||
flist = str.split(filestr)
|
||||
self.files = []
|
||||
for file in list: self.files += glob.glob(file)
|
||||
for file in flist: self.files += glob.glob(file)
|
||||
self.nframes = len(self.files)
|
||||
if self.nframes == 0: raise StandardError, "No files to load"
|
||||
if self.nframes == 0: raise Exception("No files to load")
|
||||
if sortflag: self.files.sort()
|
||||
|
||||
# load all images
|
||||
|
||||
|
||||
self.images = []
|
||||
for i in xrange(self.nframes):
|
||||
for i in range(self.nframes):
|
||||
self.images.append(PhotoImage(file=self.files[i]))
|
||||
|
||||
# grab Tk instance from main
|
||||
|
||||
|
||||
from __main__ import tkroot
|
||||
self.tkroot = tkroot
|
||||
|
||||
# GUI control window
|
||||
|
||||
|
||||
win1 = Toplevel(tkroot)
|
||||
win1.title("Pizza.py animate tool")
|
||||
|
||||
@ -95,7 +101,7 @@ class animate:
|
||||
button6 = Button(holder1,text=">",command=self.next).pack(side=LEFT)
|
||||
button7 = Button(holder1,text=">>",command=self.last).pack(side=LEFT)
|
||||
holder1.pack(side=TOP)
|
||||
|
||||
|
||||
holder2 = Frame(win1)
|
||||
self.slider_frame = Scale(holder2,from_=0,to=self.nframes-1,
|
||||
command=self.frame,orient=HORIZONTAL,
|
||||
@ -106,12 +112,12 @@ class animate:
|
||||
self.slider_frame.pack(side=LEFT)
|
||||
self.slider_delay.pack(side=LEFT)
|
||||
holder2.pack(side=TOP)
|
||||
|
||||
|
||||
holder3 = Frame(win1)
|
||||
self.label_frame = Label(holder3)
|
||||
self.label_frame.pack(side=LEFT)
|
||||
holder3.pack(side=TOP)
|
||||
|
||||
|
||||
# image window
|
||||
|
||||
win2 = Toplevel(tkroot)
|
||||
@ -120,7 +126,7 @@ class animate:
|
||||
tkroot.update_idletasks() # force window to appear
|
||||
|
||||
# display 1st image
|
||||
|
||||
|
||||
self.index = 0
|
||||
self.display(self.index)
|
||||
|
||||
@ -135,19 +141,19 @@ class animate:
|
||||
def last(self):
|
||||
self.index = self.nframes - 1
|
||||
self.display(self.index)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def previous(self):
|
||||
if self.index > 0: self.index -= 1
|
||||
self.display(self.index)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def next(self):
|
||||
if self.index < self.nframes - 1: self.index += 1
|
||||
self.display(self.index)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def back(self):
|
||||
@ -157,7 +163,7 @@ class animate:
|
||||
self.index = self.nframes - 1
|
||||
self.display(self.index)
|
||||
self.loop()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def play(self):
|
||||
@ -167,15 +173,15 @@ class animate:
|
||||
self.index = 0
|
||||
self.display(self.index)
|
||||
self.loop()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def stop(self):
|
||||
self.loop_flag = 0
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# loop forward or back until end of animation
|
||||
|
||||
|
||||
def loop(self):
|
||||
if self.loop_flag == 1 and self.index == self.nframes - 1:
|
||||
self.loop_flag = 0
|
||||
@ -190,7 +196,7 @@ class animate:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# display a frame corresponding to iframe
|
||||
|
||||
|
||||
def display(self,iframe):
|
||||
self.image_pane.configure(image=self.images[iframe])
|
||||
self.slider_frame.set(iframe)
|
||||
@ -209,4 +215,4 @@ class animate:
|
||||
self.delay_value = float(value)
|
||||
self.slider_delay.set(self.delay_value)
|
||||
self.delay_msec = int(1000*self.delay_value)
|
||||
|
||||
|
||||
|
||||
62
src/bdump.py
62
src/bdump.py
@ -3,23 +3,30 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# bdump tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, re, glob, types
|
||||
import functools
|
||||
from os import popen
|
||||
|
||||
oneline = "Read dump files with bond info"
|
||||
|
||||
docstr = """
|
||||
b = bdump("dump.one") read in one or more dump files
|
||||
b = bdump("dump.1 dump.2.gz") can be gzipped
|
||||
b = bdump("dump.*") wildcard expands to multiple files
|
||||
b = bdump("dump.*",0) two args = store filenames, but don't read
|
||||
b = bdump("dump.1 dump.2.gz") can be gzipped
|
||||
b = bdump("dump.*") wildcard expands to multiple files
|
||||
b = bdump("dump.*",0) two args = store filenames, but don't read
|
||||
|
||||
incomplete and duplicate snapshots are deleted
|
||||
no column name assignment is performed
|
||||
|
||||
time = b.next() read next snapshot from dump files
|
||||
time = b.next() read next snapshot from dump files
|
||||
|
||||
used with 2-argument constructor to allow reading snapshots one-at-a-time
|
||||
snapshot will be skipped only if another snapshot has same time stamp
|
||||
@ -60,11 +67,6 @@ time,box,atoms,bonds,tris,lines = b.viz(index) return list of viz objects
|
||||
# natoms = # of atoms
|
||||
# atoms[i][j] = 2d array of floats, i = 0 to natoms-1, j = 0 to ncols-1
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, commands, re, glob, types
|
||||
from os import popen
|
||||
|
||||
try:
|
||||
import numpy as np
|
||||
oldnumeric = False
|
||||
@ -92,8 +94,8 @@ class bdump:
|
||||
self.flist = []
|
||||
for word in words: self.flist += glob.glob(word)
|
||||
if len(self.flist) == 0 and len(list) == 1:
|
||||
raise StandardError,"no bdump file specified"
|
||||
|
||||
raise Exception("no bdump file specified")
|
||||
|
||||
if len(list) == 1:
|
||||
self.increment = 0
|
||||
self.read_all()
|
||||
@ -117,26 +119,26 @@ class bdump:
|
||||
snap = self.read_snapshot(f)
|
||||
while snap:
|
||||
self.snaps.append(snap)
|
||||
print snap.time,
|
||||
print(snap.time, end=' ')
|
||||
sys.stdout.flush()
|
||||
snap = self.read_snapshot(f)
|
||||
|
||||
f.close()
|
||||
print
|
||||
print()
|
||||
|
||||
# sort entries by timestep, cull duplicates
|
||||
|
||||
self.snaps.sort(self.compare_time)
|
||||
self.snaps.sort(key = functools.cmp_to_key(self.compare_time))
|
||||
self.cull()
|
||||
self.nsnaps = len(self.snaps)
|
||||
print "read %d snapshots" % self.nsnaps
|
||||
print("read %d snapshots" % self.nsnaps)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# read next snapshot from list of files
|
||||
|
||||
def next(self):
|
||||
|
||||
if not self.increment: raise StandardError,"cannot read incrementally"
|
||||
if not self.increment: raise Exception("cannot read incrementally")
|
||||
|
||||
# read next snapshot in current file using eof as pointer
|
||||
# if fail, try next file
|
||||
@ -148,15 +150,15 @@ class bdump:
|
||||
snap = self.read_snapshot(f)
|
||||
if not snap:
|
||||
self.nextfile += 1
|
||||
if self.nextfile == len(self.flist): return -1
|
||||
if self.nextfile == len(self.flist): return -1
|
||||
f.close()
|
||||
self.eof = 0
|
||||
continue
|
||||
self.eof = 0
|
||||
continue
|
||||
self.eof = f.tell()
|
||||
f.close()
|
||||
try:
|
||||
self.findtime(snap.time)
|
||||
continue
|
||||
continue
|
||||
except: break
|
||||
|
||||
self.snaps.append(snap)
|
||||
@ -170,7 +172,7 @@ class bdump:
|
||||
# return snapshot or 0 if failed
|
||||
# assign column names if not already done and file is self-describing
|
||||
# convert xs,xu to x
|
||||
|
||||
|
||||
def read_snapshot(self,f):
|
||||
try:
|
||||
snap = Snap()
|
||||
@ -183,14 +185,14 @@ class bdump:
|
||||
if snap.natoms:
|
||||
words = f.readline().split()
|
||||
ncol = len(words)
|
||||
for i in xrange(1,snap.natoms):
|
||||
for i in range(1,snap.natoms):
|
||||
words += f.readline().split()
|
||||
floats = map(float,words)
|
||||
floats = list(map(float,words))
|
||||
if oldnumeric: atoms = np.zeros((snap.natoms,ncol),np.Float)
|
||||
else: atoms = np.zeros((snap.natoms,ncol),np.float)
|
||||
start = 0
|
||||
stop = ncol
|
||||
for i in xrange(snap.natoms):
|
||||
for i in range(snap.natoms):
|
||||
atoms[i] = floats[start:stop]
|
||||
start = stop
|
||||
stop += ncol
|
||||
@ -202,10 +204,10 @@ class bdump:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# map atom column names
|
||||
|
||||
|
||||
def map(self,*pairs):
|
||||
if len(pairs) % 2 != 0:
|
||||
raise StandardError, "bdump map() requires pairs of mappings"
|
||||
raise Exception("bdump map() requires pairs of mappings")
|
||||
for i in range(0,len(pairs),2):
|
||||
j = i + 1
|
||||
self.names[pairs[j]] = pairs[i]-1
|
||||
@ -242,7 +244,7 @@ class bdump:
|
||||
del self.snaps[i]
|
||||
else:
|
||||
i += 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# return list of bonds to viz for snapshot isnap
|
||||
# if called with flag, then index is timestep, so convert to snapshot index
|
||||
@ -267,9 +269,9 @@ class bdump:
|
||||
|
||||
# create line list from id,type,atom1,atom2
|
||||
# abs() of type since could be negative
|
||||
|
||||
|
||||
bonds = []
|
||||
for i in xrange(snap.natoms):
|
||||
for i in range(snap.natoms):
|
||||
atom = snap.atoms[i]
|
||||
bonds.append([int(atom[id]),abs(int(atom[type])),
|
||||
int(atom[atom1]),int(atom[atom2])])
|
||||
|
||||
719
src/cdata.py
719
src/cdata.py
File diff suppressed because it is too large
Load Diff
129
src/cfg.py
129
src/cfg.py
@ -3,22 +3,27 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# cfg tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys
|
||||
|
||||
oneline = "Convert LAMMPS snapshots to AtomEye CFG format"
|
||||
|
||||
docstr = """
|
||||
c = cfg(d) d = object containing atom coords (dump, data)
|
||||
c = cfg(d) d = object containing atom coords (dump, data)
|
||||
|
||||
c.one() write all snapshots to tmp.cfg
|
||||
c.one("new") write all snapshots to new.cfg
|
||||
c.many() write snapshots to tmp0000.cfg, tmp0001.cfg, etc
|
||||
c.many("new") write snapshots to new0000.cfg, new0001.cfg, etc
|
||||
c.single(N) write snapshot for timestep N to tmp.cfg
|
||||
c.single(N,"file") write snapshot for timestep N to file.cfg
|
||||
c.single(N) write snapshot for timestep N to tmp.cfg
|
||||
c.single(N,"file") write snapshot for timestep N to file.cfg
|
||||
"""
|
||||
|
||||
# History
|
||||
@ -34,10 +39,6 @@ c.single(N,"file") write snapshot for timestep N to file.cfg
|
||||
# Variables
|
||||
# data = data file to read from
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys
|
||||
|
||||
# Class definition
|
||||
|
||||
class cfg:
|
||||
@ -46,7 +47,7 @@ class cfg:
|
||||
|
||||
def __init__(self,data):
|
||||
self.data = data
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def one(self,*args):
|
||||
@ -65,34 +66,34 @@ class cfg:
|
||||
ylen = box[4]-box[1]
|
||||
zlen = box[5]-box[2]
|
||||
|
||||
print >>f,"Number of particles = %d " % len(atoms)
|
||||
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
|
||||
print >>f,"H0(1,1) = %20.10f A " % xlen
|
||||
print >>f,"H0(1,2) = 0.0 A "
|
||||
print >>f,"H0(1,3) = 0.0 A "
|
||||
print >>f,"H0(2,1) = 0.0 A "
|
||||
print >>f,"H0(2,2) = %20.10f A " % ylen
|
||||
print >>f,"H0(2,3) = 0.0 A "
|
||||
print >>f,"H0(3,1) = 0.0 A "
|
||||
print >>f,"H0(3,2) = 0.0 A "
|
||||
print >>f,"H0(3,3) = %20.10f A " % zlen
|
||||
print >>f,"#"
|
||||
|
||||
print("Number of particles = %d " % len(atoms), file=f)
|
||||
print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f)
|
||||
print("H0(1,1) = %20.10f A " % xlen, file=f)
|
||||
print("H0(1,2) = 0.0 A ", file=f)
|
||||
print("H0(1,3) = 0.0 A ", file=f)
|
||||
print("H0(2,1) = 0.0 A ", file=f)
|
||||
print("H0(2,2) = %20.10f A " % ylen, file=f)
|
||||
print("H0(2,3) = 0.0 A ", file=f)
|
||||
print("H0(3,1) = 0.0 A ", file=f)
|
||||
print("H0(3,2) = 0.0 A ", file=f)
|
||||
print("H0(3,3) = %20.10f A " % zlen, file=f)
|
||||
print("#", file=f)
|
||||
|
||||
for atom in atoms:
|
||||
itype = int(atom[1])
|
||||
xfrac = (atom[2]-box[0])/xlen
|
||||
yfrac = (atom[3]-box[1])/ylen
|
||||
zfrac = (atom[4]-box[2])/zlen
|
||||
# print >>f,"1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7])
|
||||
print >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
|
||||
|
||||
print time,
|
||||
print("1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f)
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
|
||||
f.close()
|
||||
print "\nwrote %d snapshots to %s in CFG format" % (n,file)
|
||||
|
||||
print("\nwrote %d snapshots to %s in CFG format" % (n,file))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def many(self,*args):
|
||||
@ -104,7 +105,7 @@ class cfg:
|
||||
which,time,flag = self.data.iterator(flag)
|
||||
if flag == -1: break
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(which)
|
||||
|
||||
|
||||
if n < 10:
|
||||
file = root + "000" + str(n)
|
||||
elif n < 100:
|
||||
@ -112,7 +113,7 @@ class cfg:
|
||||
elif n < 1000:
|
||||
file = root + "0" + str(n)
|
||||
else:
|
||||
file = root + str(n)
|
||||
file = root + str(n)
|
||||
file += ".cfg"
|
||||
f = open(file,"w")
|
||||
|
||||
@ -120,34 +121,34 @@ class cfg:
|
||||
ylen = box[4]-box[1]
|
||||
zlen = box[5]-box[2]
|
||||
|
||||
print >>f,"Number of particles = %d " % len(atoms)
|
||||
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
|
||||
print >>f,"H0(1,1) = %20.10f A " % xlen
|
||||
print >>f,"H0(1,2) = 0.0 A "
|
||||
print >>f,"H0(1,3) = 0.0 A "
|
||||
print >>f,"H0(2,1) = 0.0 A "
|
||||
print >>f,"H0(2,2) = %20.10f A " % ylen
|
||||
print >>f,"H0(2,3) = 0.0 A "
|
||||
print >>f,"H0(3,1) = 0.0 A "
|
||||
print >>f,"H0(3,2) = 0.0 A "
|
||||
print >>f,"H0(3,3) = %20.10f A " % zlen
|
||||
print >>f,"#"
|
||||
|
||||
print("Number of particles = %d " % len(atoms), file=f)
|
||||
print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f)
|
||||
print("H0(1,1) = %20.10f A " % xlen, file=f)
|
||||
print("H0(1,2) = 0.0 A ", file=f)
|
||||
print("H0(1,3) = 0.0 A ", file=f)
|
||||
print("H0(2,1) = 0.0 A ", file=f)
|
||||
print("H0(2,2) = %20.10f A " % ylen, file=f)
|
||||
print("H0(2,3) = 0.0 A ", file=f)
|
||||
print("H0(3,1) = 0.0 A ", file=f)
|
||||
print("H0(3,2) = 0.0 A ", file=f)
|
||||
print("H0(3,3) = %20.10f A " % zlen, file=f)
|
||||
print("#", file=f)
|
||||
|
||||
for atom in atoms:
|
||||
itype = int(atom[1])
|
||||
xfrac = (atom[2]-box[0])/xlen
|
||||
yfrac = (atom[3]-box[1])/ylen
|
||||
zfrac = (atom[4]-box[2])/zlen
|
||||
# print >>f,"1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7])
|
||||
print >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
|
||||
|
||||
print time,
|
||||
print("1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f)
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
f.close()
|
||||
n += 1
|
||||
|
||||
print "\nwrote %s snapshots in CFG format" % n
|
||||
|
||||
|
||||
print("\nwrote %s snapshots in CFG format" % n)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def single(self,time,*args):
|
||||
@ -163,25 +164,25 @@ class cfg:
|
||||
ylen = box[4]-box[1]
|
||||
zlen = box[5]-box[2]
|
||||
|
||||
print >>f,"Number of particles = %d " % len(atoms)
|
||||
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
|
||||
print >>f,"H0(1,1) = %20.10f A " % xlen
|
||||
print >>f,"H0(1,2) = 0.0 A "
|
||||
print >>f,"H0(1,3) = 0.0 A "
|
||||
print >>f,"H0(2,1) = 0.0 A "
|
||||
print >>f,"H0(2,2) = %20.10f A " % ylen
|
||||
print >>f,"H0(2,3) = 0.0 A "
|
||||
print >>f,"H0(3,1) = 0.0 A "
|
||||
print >>f,"H0(3,2) = 0.0 A "
|
||||
print >>f,"H0(3,3) = %20.10f A " % zlen
|
||||
print >>f,"#"
|
||||
|
||||
print("Number of particles = %d " % len(atoms), file=f)
|
||||
print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f)
|
||||
print("H0(1,1) = %20.10f A " % xlen, file=f)
|
||||
print("H0(1,2) = 0.0 A ", file=f)
|
||||
print("H0(1,3) = 0.0 A ", file=f)
|
||||
print("H0(2,1) = 0.0 A ", file=f)
|
||||
print("H0(2,2) = %20.10f A " % ylen, file=f)
|
||||
print("H0(2,3) = 0.0 A ", file=f)
|
||||
print("H0(3,1) = 0.0 A ", file=f)
|
||||
print("H0(3,2) = 0.0 A ", file=f)
|
||||
print("H0(3,3) = %20.10f A " % zlen, file=f)
|
||||
print("#", file=f)
|
||||
|
||||
for atom in atoms:
|
||||
itype = int(atom[1])
|
||||
xfrac = (atom[2]-box[0])/xlen
|
||||
yfrac = (atom[3]-box[1])/ylen
|
||||
zfrac = (atom[4]-box[2])/zlen
|
||||
# print >>f,"1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7])
|
||||
print >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
|
||||
|
||||
print("1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f)
|
||||
|
||||
f.close()
|
||||
|
||||
63
src/chain.py
63
src/chain.py
@ -3,20 +3,26 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# chain tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, division, absolute_import
|
||||
import math
|
||||
from data import data
|
||||
|
||||
oneline = "Create bead-spring chains for LAMMPS input"
|
||||
|
||||
docstr = """
|
||||
c = chain(N,rho) setup box with N monomers at reduced density rho
|
||||
c = chain(N,rho,1,1,2) x,y,z = aspect ratio of box (def = 1,1,1)
|
||||
c = chain(N,rho,1,1,2) x,y,z = aspect ratio of box (def = 1,1,1)
|
||||
|
||||
c.seed = 48379 set random # seed (def = 12345)
|
||||
c.mtype = 2 set type of monomers (def = 1)
|
||||
c.btype = 1 set type of bonds (def = 1)
|
||||
c.mtype = 2 set type of monomers (def = 1)
|
||||
c.btype = 1 set type of bonds (def = 1)
|
||||
c.blen = 0.97 set length of bonds (def = 0.97)
|
||||
c.dmin = 1.02 set min dist from i-1 to i+1 site (def = 1.02)
|
||||
|
||||
@ -24,11 +30,11 @@ c.id = "chain" set molecule ID to chain # (default)
|
||||
c.id = "end1" set molecule ID to count from one end of chain
|
||||
c.id = "end2" set molecule ID to count from either end of chain
|
||||
|
||||
c.build(100,10) create 100 chains, each of length 10
|
||||
c.build(100,10) create 100 chains, each of length 10
|
||||
|
||||
can be invoked multiple times interleaved with different settings
|
||||
must fill box with total of N monomers
|
||||
|
||||
|
||||
c.write("data.file") write out all built chains to LAMMPS data file
|
||||
"""
|
||||
|
||||
@ -52,15 +58,10 @@ c.write("data.file") write out all built chains to LAMMPS data file
|
||||
# xlo,ylo,zlo = -xyz prd / 2
|
||||
# xhi,yhi,zhi = x,y,zprd /2
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import math
|
||||
from data import data
|
||||
|
||||
# Class definition
|
||||
|
||||
class chain:
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self,n,rhostar,*list):
|
||||
@ -92,12 +93,12 @@ class chain:
|
||||
self.zlo = -self.zprd/2.0
|
||||
self.zhi = self.zprd/2.0
|
||||
|
||||
print "Simulation box: %g by %g by %g" % (self.xprd,self.yprd,self.zprd)
|
||||
print("Simulation box: %g by %g by %g" % (self.xprd,self.yprd,self.zprd))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def build(self,n,nper):
|
||||
for ichain in xrange(n):
|
||||
for ichain in range(n):
|
||||
atoms = []
|
||||
bonds = []
|
||||
id_atom_prev = id_mol_prev = id_bond_prev = 0
|
||||
@ -107,12 +108,12 @@ class chain:
|
||||
if len(self.bonds):
|
||||
id_bond_prev = self.bonds[-1][0]
|
||||
|
||||
for imonomer in xrange(nper):
|
||||
for imonomer in range(nper):
|
||||
if imonomer == 0:
|
||||
x = self.xlo + self.random()*self.xprd
|
||||
y = self.ylo + self.random()*self.yprd
|
||||
z = self.zlo + self.random()*self.zprd
|
||||
ix = iy = iz = 0
|
||||
ix = iy = iz = 0
|
||||
else:
|
||||
restriction = True
|
||||
while restriction:
|
||||
@ -134,7 +135,7 @@ class chain:
|
||||
dz = z - atoms[-2][5]
|
||||
if math.sqrt(dx*dx + dy*dy + dz*dz) <= self.dmin:
|
||||
restriction = True
|
||||
|
||||
|
||||
x,y,z,ix,iy,iz = self.pbc(x,y,z,ix,iy,iz)
|
||||
idatom = id_atom_prev + imonomer + 1
|
||||
if self.id == "chain":
|
||||
@ -143,16 +144,16 @@ class chain:
|
||||
idmol = imonomer + 1
|
||||
elif self.id == "end2":
|
||||
idmol = imonomer + 1
|
||||
if idmol > nper/2:
|
||||
if idmol > nper//2:
|
||||
idmol = nper - imonomer
|
||||
else:
|
||||
raise StandardError,"chain ID is not a valid value"
|
||||
|
||||
raise Exception("chain ID is not a valid value")
|
||||
|
||||
atoms.append([idatom,idmol,self.mtype,x,y,z,ix,iy,iz])
|
||||
if imonomer:
|
||||
bondid = id_bond_prev + imonomer
|
||||
bondid = id_bond_prev + imonomer
|
||||
bonds.append([bondid,self.btype,idatom-1,idatom])
|
||||
|
||||
|
||||
self.atoms += atoms
|
||||
self.bonds += bonds
|
||||
|
||||
@ -160,16 +161,16 @@ class chain:
|
||||
|
||||
def write(self,file):
|
||||
if len(self.atoms) != self.n:
|
||||
raise StandardError,"%d monomers instead of requested %d" % \
|
||||
(len(self.atoms),self.n)
|
||||
raise Exception("%d monomers instead of requested %d" % \
|
||||
(len(self.atoms),self.n))
|
||||
|
||||
list = [atom[2] for atom in self.atoms]
|
||||
atypes = max(list)
|
||||
atlist = [atom[2] for atom in self.atoms]
|
||||
atypes = max(atlist)
|
||||
|
||||
btypes = 0
|
||||
if len(self.bonds):
|
||||
list = [bond[1] for bond in self.bonds]
|
||||
btypes = max(list)
|
||||
btlist = [bond[1] for bond in self.bonds]
|
||||
btypes = max(btlist)
|
||||
|
||||
# create the data file
|
||||
|
||||
@ -186,7 +187,7 @@ class chain:
|
||||
lines = []
|
||||
for i in range(atypes): lines.append("%d 1.0\n" % (i+1))
|
||||
d.sections["Masses"] = lines
|
||||
|
||||
|
||||
lines = []
|
||||
for atom in self.atoms:
|
||||
line = "%d %d %d %g %g %g %d %d %d\n" % \
|
||||
@ -194,7 +195,7 @@ class chain:
|
||||
atom[6], atom[7], atom[8])
|
||||
lines.append(line)
|
||||
d.sections["Atoms"] = lines
|
||||
|
||||
|
||||
lines = []
|
||||
for bond in self.bonds:
|
||||
line = "%d %d %d %d\n" % (bond[0], bond[1], bond[2], bond[3])
|
||||
@ -229,7 +230,7 @@ class chain:
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def random(self):
|
||||
k = self.seed/IQ
|
||||
k = self.seed//IQ
|
||||
self.seed = IA*(self.seed-k*IQ) - IR*k
|
||||
if self.seed < 0:
|
||||
self.seed += IM
|
||||
|
||||
97
src/clog.py
97
src/clog.py
@ -3,11 +3,17 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# clog tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, re, glob
|
||||
from os import popen
|
||||
|
||||
oneline = "Read ChemCell and SPPARKS log files and extract time-series data"
|
||||
|
||||
docstr = """
|
||||
@ -21,12 +27,12 @@ c = clog("log.cell","",0) 3rd arg = average all runs
|
||||
if specify 2nd arg, it delimits a time section
|
||||
no 2nd arg or empty string, use default which is ChemCell specific
|
||||
if specify any 3rd arg, average all runs, assume all start at time 0
|
||||
|
||||
|
||||
nvec = c.nvec # of vectors of thermo info
|
||||
nlen = c.nlen length of each vectors
|
||||
names = c.names list of vector names
|
||||
a,b,... = c.get("A","B",...) return one or more vectors of values
|
||||
c.write("file.txt") write all vectors to a file
|
||||
c.write("file.txt") write all vectors to a file
|
||||
c.write("file.txt","A","B",...) write listed vectors to a file
|
||||
|
||||
get and write allow abbreviated (uniquely) vector names
|
||||
@ -46,11 +52,6 @@ c.write("file.txt","A","B",...) write listed vectors to a file
|
||||
# data[i][j] = 2d array of floats, i = 0 to # of entries, j = 0 to nvecs-1
|
||||
# firststr = string that begins a time-series section in log file
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, re, glob
|
||||
from os import popen
|
||||
|
||||
try: tmp = PIZZA_GUNZIP
|
||||
except: PIZZA_GUNZIP = "gunzip"
|
||||
|
||||
@ -74,24 +75,24 @@ class clog:
|
||||
self.flist = []
|
||||
for word in words: self.flist += glob.glob(word)
|
||||
if len(self.flist) == 0 and len(list) == 1:
|
||||
raise StandardError,"no log file specified"
|
||||
raise Exception("no log file specified")
|
||||
|
||||
if len(list) > 1 and len(list[1]): self.firststr = list[1]
|
||||
if len(list) == 3: self.ave = 1
|
||||
|
||||
|
||||
self.read_all()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# read all log data from all files
|
||||
|
||||
|
||||
def read_all(self):
|
||||
self.read_header(self.flist[0])
|
||||
if self.nvec == 0: raise StandardError,"log file has no values"
|
||||
if self.nvec == 0: raise Exception("log file has no values")
|
||||
|
||||
# read all files
|
||||
|
||||
for file in self.flist: self.read_one(file)
|
||||
print
|
||||
print()
|
||||
|
||||
# if no average, sort entries by timestep, cull duplicates
|
||||
# if average, call self.average()
|
||||
@ -102,33 +103,33 @@ class clog:
|
||||
else: self.average()
|
||||
|
||||
self.nlen = len(self.data)
|
||||
print "read %d log entries" % self.nlen
|
||||
print("read %d log entries" % self.nlen)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def get(self,*keys):
|
||||
if len(keys) == 0:
|
||||
raise StandardError, "no log vectors specified"
|
||||
raise Exception("no log vectors specified")
|
||||
|
||||
map = []
|
||||
for key in keys:
|
||||
if self.ptr.has_key(key):
|
||||
if key in self.ptr:
|
||||
map.append(self.ptr[key])
|
||||
else:
|
||||
count = 0
|
||||
for i in range(self.nvec):
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if count == 1:
|
||||
map.append(index)
|
||||
else:
|
||||
raise StandardError, "unique log vector %s not found" % key
|
||||
raise Exception("unique log vector %s not found" % key)
|
||||
|
||||
vecs = []
|
||||
for i in range(len(keys)):
|
||||
vecs.append(self.nlen * [0])
|
||||
for j in xrange(self.nlen):
|
||||
for j in range(self.nlen):
|
||||
vecs[i][j] = self.data[j][map[i]]
|
||||
|
||||
if len(keys) == 1: return vecs[0]
|
||||
@ -140,26 +141,26 @@ class clog:
|
||||
if len(keys):
|
||||
map = []
|
||||
for key in keys:
|
||||
if self.ptr.has_key(key):
|
||||
if key in self.ptr:
|
||||
map.append(self.ptr[key])
|
||||
else:
|
||||
count = 0
|
||||
for i in range(self.nvec):
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if count == 1:
|
||||
map.append(index)
|
||||
else:
|
||||
raise StandardError, "unique log vector %s not found" % key
|
||||
raise Exception("unique log vector %s not found" % key)
|
||||
else:
|
||||
map = range(self.nvec)
|
||||
map = list(range(self.nvec))
|
||||
|
||||
f = open(filename,"w")
|
||||
for i in xrange(self.nlen):
|
||||
for j in xrange(len(map)):
|
||||
print >>f,self.data[i][map[j]],
|
||||
print >>f
|
||||
for i in range(self.nlen):
|
||||
for j in range(len(map)):
|
||||
print(self.data[i][map[j]], end=' ', file=f)
|
||||
print(file=f)
|
||||
f.close()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -195,17 +196,17 @@ class clog:
|
||||
data.append(self.nvec*[0])
|
||||
nlen += 1
|
||||
counts[j] += 1
|
||||
for m in xrange(self.nvec): data[j][m] += self.data[i][m]
|
||||
for m in range(self.nvec): data[j][m] += self.data[i][m]
|
||||
j += 1
|
||||
i += 1
|
||||
|
||||
for i in xrange(nlen):
|
||||
for j in xrange(self.nvec):
|
||||
for i in range(nlen):
|
||||
for j in range(self.nvec):
|
||||
data[i][j] /= counts[j]
|
||||
|
||||
self.nlen = nlen
|
||||
self.data = data
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def read_header(self,file):
|
||||
@ -261,41 +262,41 @@ class clog:
|
||||
elif s1 >= 0 and s2 >= 0 and s2 < s1: # found s1,s2 with s2 before s1
|
||||
s1 = 0
|
||||
elif s1 == -1 and s2 >= 0: # found s2, but no s1
|
||||
last = 1
|
||||
last = 1
|
||||
s1 = 0
|
||||
elif s1 >= 0 and s2 == -1: # found s1, but no s2
|
||||
last = 1
|
||||
s1 = txt.find("\n",s1) + 1
|
||||
s2 = txt.rfind("\n",s1) + 1
|
||||
eof -= len(txt) - s2
|
||||
eof -= len(txt) - s2
|
||||
elif s1 == -1 and s2 == -1: # found neither
|
||||
# could be end-of-file section
|
||||
# or entire read was one chunk
|
||||
# or entire read was one chunk
|
||||
|
||||
if txt.find("Loop time of",start) == start: # end of file, so exit
|
||||
eof -= len(txt) - start # reset eof to "Loop"
|
||||
break
|
||||
eof -= len(txt) - start # reset eof to "Loop"
|
||||
break
|
||||
|
||||
last = 1 # entire read is a chunk
|
||||
last = 1 # entire read is a chunk
|
||||
s1 = 0
|
||||
s2 = txt.rfind("\n",s1) + 1
|
||||
eof -= len(txt) - s2
|
||||
if s1 == s2: break
|
||||
eof -= len(txt) - s2
|
||||
if s1 == s2: break
|
||||
|
||||
chunk = txt[s1:s2-1]
|
||||
start = s2
|
||||
|
||||
|
||||
# split chunk into entries
|
||||
# parse each entry for numeric fields, append to data
|
||||
|
||||
|
||||
lines = chunk.split("\n")
|
||||
for line in lines:
|
||||
words = line.split()
|
||||
self.data.append(map(float,words))
|
||||
|
||||
self.data.append(list(map(float,words)))
|
||||
|
||||
# print last timestep of chunk
|
||||
|
||||
print int(self.data[len(self.data)-1][0]),
|
||||
print(int(self.data[len(self.data)-1][0]), end=' ')
|
||||
sys.stdout.flush()
|
||||
|
||||
return eof
|
||||
|
||||
154
src/data.py
154
src/data.py
@ -3,16 +3,21 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# data tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
from os import popen
|
||||
|
||||
oneline = "Read, write, manipulate LAMMPS data files"
|
||||
|
||||
docstr = """
|
||||
d = data("data.poly") read a LAMMPS data file, can be gzipped
|
||||
d = data() create an empty data file
|
||||
d = data() create an empty data file
|
||||
|
||||
d.map(1,"id",3,"x") assign names to atom columns (1-N)
|
||||
|
||||
@ -26,17 +31,17 @@ d.reorder("Atoms",1,3,2,4,5) reorder columns (1-N) in a data file section
|
||||
|
||||
1,3,2,4,5 = new order of previous columns, can delete columns this way
|
||||
|
||||
d.title = "My LAMMPS data file" set title of the data file
|
||||
d.title = "My LAMMPS data file" set title of the data file
|
||||
d.headers["atoms"] = 1500 set a header value
|
||||
d.sections["Bonds"] = lines set a section to list of lines (with newlines)
|
||||
d.delete("bonds") delete a keyword or section of data file
|
||||
d.delete("bonds") delete a keyword or section of data file
|
||||
d.delete("Bonds")
|
||||
d.replace("Atoms",5,vec) replace Nth column of section with vector
|
||||
d.newxyz(dmp,1000) replace xyz in Atoms with xyz of snapshot N
|
||||
d.replace("Atoms",5,vec) replace Nth column of section with vector
|
||||
d.newxyz(dmp,1000) replace xyz in Atoms with xyz of snapshot N
|
||||
|
||||
newxyz assumes id,x,y,z are defined in both data and dump files
|
||||
also replaces ix,iy,iz if they are defined
|
||||
|
||||
|
||||
index,time,flag = d.iterator(0/1) loop over single data file snapshot
|
||||
time,box,atoms,bonds,tris,lines = d.viz(index) return list of viz objects
|
||||
|
||||
@ -53,7 +58,7 @@ time,box,atoms,bonds,tris,lines = d.viz(index) return list of viz objects
|
||||
NULL if bonds do not exist
|
||||
tris = NULL
|
||||
lines = NULL
|
||||
|
||||
|
||||
d.write("data.new") write a LAMMPS data file
|
||||
"""
|
||||
|
||||
@ -65,15 +70,11 @@ d.write("data.new") write a LAMMPS data file
|
||||
|
||||
# Variables
|
||||
# title = 1st line of data file
|
||||
# names = dictionary with atom attributes as keys, col #s as values
|
||||
# names = dictionary with atom attributes as keys, col #s as values
|
||||
# headers = dictionary with header name as key, value or tuple as values
|
||||
# sections = dictionary with section name as key, array of lines as values
|
||||
# nselect = 1 = # of snapshots
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from os import popen
|
||||
|
||||
try: tmp = PIZZA_GUNZIP
|
||||
except: PIZZA_GUNZIP = "gunzip"
|
||||
|
||||
@ -85,7 +86,7 @@ class data:
|
||||
|
||||
def __init__(self,*list):
|
||||
self.nselect = 1
|
||||
|
||||
|
||||
if len(list) == 0:
|
||||
self.title = "LAMMPS data file"
|
||||
self.names = {}
|
||||
@ -99,7 +100,7 @@ class data:
|
||||
|
||||
self.title = f.readline()
|
||||
self.names = {}
|
||||
|
||||
|
||||
headers = {}
|
||||
while 1:
|
||||
line = f.readline()
|
||||
@ -109,16 +110,16 @@ class data:
|
||||
found = 0
|
||||
for keyword in hkeywords:
|
||||
if line.find(keyword) >= 0:
|
||||
found = 1
|
||||
words = line.split()
|
||||
if keyword == "xlo xhi" or keyword == "ylo yhi" or \
|
||||
keyword == "zlo zhi":
|
||||
headers[keyword] = (float(words[0]),float(words[1]))
|
||||
elif keyword == "xy xz yz":
|
||||
headers[keyword] = \
|
||||
found = 1
|
||||
words = line.split()
|
||||
if keyword == "xlo xhi" or keyword == "ylo yhi" or \
|
||||
keyword == "zlo zhi":
|
||||
headers[keyword] = (float(words[0]),float(words[1]))
|
||||
elif keyword == "xy xz yz":
|
||||
headers[keyword] = \
|
||||
(float(words[0]),float(words[1]),float(words[2]))
|
||||
else:
|
||||
headers[keyword] = int(words[0])
|
||||
headers[keyword] = int(words[0])
|
||||
if not found:
|
||||
break
|
||||
|
||||
@ -128,22 +129,21 @@ class data:
|
||||
for pair in skeywords:
|
||||
keyword,length = pair[0],pair[1]
|
||||
if keyword == line:
|
||||
found = 1
|
||||
if not headers.has_key(length):
|
||||
raise StandardError, \
|
||||
"data section %s has no matching header value" % line
|
||||
f.readline()
|
||||
found = 1
|
||||
if length not in headers:
|
||||
raise Exception("data section %s has no matching header value" % line)
|
||||
f.readline()
|
||||
list = []
|
||||
for i in xrange(headers[length]): list.append(f.readline())
|
||||
for i in range(headers[length]): list.append(f.readline())
|
||||
sections[keyword] = list
|
||||
if not found:
|
||||
raise StandardError,"invalid section %s in data file" % line
|
||||
raise Exception("invalid section %s in data file" % line)
|
||||
f.readline()
|
||||
line = f.readline()
|
||||
if not line:
|
||||
break
|
||||
line = line.strip()
|
||||
|
||||
|
||||
f.close()
|
||||
self.headers = headers
|
||||
self.sections = sections
|
||||
@ -153,7 +153,7 @@ class data:
|
||||
|
||||
def map(self,*pairs):
|
||||
if len(pairs) % 2 != 0:
|
||||
raise StandardError, "data map() requires pairs of mappings"
|
||||
raise Exception("data map() requires pairs of mappings")
|
||||
for i in range(0,len(pairs),2):
|
||||
j = i + 1
|
||||
self.names[pairs[j]] = pairs[i]-1
|
||||
@ -161,19 +161,19 @@ class data:
|
||||
# --------------------------------------------------------------------
|
||||
# extract info from data file fields
|
||||
|
||||
def get(self,*list):
|
||||
if len(list) == 1:
|
||||
field = list[0]
|
||||
def get(self,*flist):
|
||||
if len(flist) == 1:
|
||||
field = flist[0]
|
||||
array = []
|
||||
lines = self.sections[field]
|
||||
for line in lines:
|
||||
words = line.split()
|
||||
values = map(float,words)
|
||||
values = list(map(float,words))
|
||||
array.append(values)
|
||||
return array
|
||||
elif len(list) == 2:
|
||||
field = list[0]
|
||||
n = list[1] - 1
|
||||
elif len(flist) == 2:
|
||||
field = flist[0]
|
||||
n = flist[1] - 1
|
||||
vec = []
|
||||
lines = self.sections[field]
|
||||
for line in lines:
|
||||
@ -181,7 +181,7 @@ class data:
|
||||
vec.append(float(words[n]))
|
||||
return vec
|
||||
else:
|
||||
raise StandardError, "invalid arguments for data.get()"
|
||||
raise Exception("invalid arguments for data.get()")
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# reorder columns in a data file field
|
||||
@ -192,10 +192,10 @@ class data:
|
||||
oldlines = self.sections[name]
|
||||
newlines = natoms*[""]
|
||||
for index in order:
|
||||
for i in xrange(len(newlines)):
|
||||
for i in range(len(newlines)):
|
||||
words = oldlines[i].split()
|
||||
newlines[i] += words[index-1] + " "
|
||||
for i in xrange(len(newlines)):
|
||||
for i in range(len(newlines)):
|
||||
newlines[i] += "\n"
|
||||
self.sections[name] = newlines
|
||||
|
||||
@ -206,7 +206,7 @@ class data:
|
||||
lines = self.sections[name]
|
||||
newlines = []
|
||||
j = icol - 1
|
||||
for i in xrange(len(lines)):
|
||||
for i in range(len(lines)):
|
||||
line = lines[i]
|
||||
words = line.split()
|
||||
words[j] = str(vector[i])
|
||||
@ -222,56 +222,52 @@ class data:
|
||||
def newxyz(self,dm,ntime):
|
||||
nsnap = dm.findtime(ntime)
|
||||
|
||||
if dm.scaled(nsnap): scaleflag = 1
|
||||
else: scaleflag = 0
|
||||
dm.sort(ntime)
|
||||
|
||||
if scaleflag: dm.unscale(ntime)
|
||||
|
||||
x,y,z = dm.vecs(ntime,"x","y","z")
|
||||
if scaleflag: dm.scale(ntime)
|
||||
|
||||
self.replace("Atoms",self.names['x']+1,x)
|
||||
self.replace("Atoms",self.names['y']+1,y)
|
||||
self.replace("Atoms",self.names['z']+1,z)
|
||||
|
||||
if dm.names.has_key("ix") and self.names.has_key("ix"):
|
||||
|
||||
if "ix" in dm.names and "ix" in self.names:
|
||||
ix,iy,iz = dm.vecs(ntime,"ix","iy","iz")
|
||||
self.replace("Atoms",self.names['ix']+1,ix)
|
||||
self.replace("Atoms",self.names['iy']+1,iy)
|
||||
self.replace("Atoms",self.names['iz']+1,iz)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# delete header value or section from data file
|
||||
|
||||
def delete(self,keyword):
|
||||
|
||||
if self.headers.has_key(keyword): del self.headers[keyword]
|
||||
elif self.sections.has_key(keyword): del self.sections[keyword]
|
||||
else: raise StandardError, "keyword not found in data object"
|
||||
if keyword in self.headers: del self.headers[keyword]
|
||||
elif keyword in self.sections: del self.sections[keyword]
|
||||
else: raise Exception("keyword not found in data object")
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write out a LAMMPS data file
|
||||
|
||||
def write(self,file):
|
||||
f = open(file,"w")
|
||||
print >>f,self.title
|
||||
print(self.title, file=f)
|
||||
for keyword in hkeywords:
|
||||
if self.headers.has_key(keyword):
|
||||
if keyword in self.headers:
|
||||
if keyword == "xlo xhi" or keyword == "ylo yhi" or \
|
||||
keyword == "zlo zhi":
|
||||
pair = self.headers[keyword]
|
||||
print >>f,pair[0],pair[1],keyword
|
||||
pair = self.headers[keyword]
|
||||
print(pair[0],pair[1],keyword, file=f)
|
||||
elif keyword == "xy xz yz":
|
||||
triple = self.headers[keyword]
|
||||
print >>f,triple[0],triple[1],triple[2],keyword
|
||||
triple = self.headers[keyword]
|
||||
print(triple[0],triple[1],triple[2],keyword, file=f)
|
||||
else:
|
||||
print >>f,self.headers[keyword],keyword
|
||||
print(self.headers[keyword],keyword, file=f)
|
||||
for pair in skeywords:
|
||||
keyword = pair[0]
|
||||
if self.sections.has_key(keyword):
|
||||
print >>f,"\n%s\n" % keyword
|
||||
if keyword in self.sections:
|
||||
print("\n%s\n" % keyword, file=f)
|
||||
for line in self.sections[keyword]:
|
||||
print >>f,line,
|
||||
print(line, end=' ', file=f)
|
||||
f.close()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -286,20 +282,20 @@ class data:
|
||||
|
||||
def findtime(self,n):
|
||||
if n == 0: return 0
|
||||
raise StandardError, "no step %d exists" % (n)
|
||||
|
||||
raise Exception("no step %d exists" % (n))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# return list of atoms and bonds to viz for data object
|
||||
|
||||
def viz(self,isnap):
|
||||
if isnap: raise StandardError, "cannot call data.viz() with isnap != 0"
|
||||
|
||||
if isnap: raise Exception("cannot call data.viz() with isnap != 0")
|
||||
|
||||
id = self.names["id"]
|
||||
type = self.names["type"]
|
||||
x = self.names["x"]
|
||||
y = self.names["y"]
|
||||
z = self.names["z"]
|
||||
|
||||
|
||||
xlohi = self.headers["xlo xhi"]
|
||||
ylohi = self.headers["ylo yhi"]
|
||||
zlohi = self.headers["zlo zhi"]
|
||||
@ -318,7 +314,7 @@ class data:
|
||||
# assumes atoms are sorted so can lookup up the 2 atoms in each bond
|
||||
|
||||
bonds = []
|
||||
if self.sections.has_key("Bonds"):
|
||||
if "Bonds" in self.sections:
|
||||
bondlines = self.sections["Bonds"]
|
||||
for line in bondlines:
|
||||
words = line.split()
|
||||
@ -331,8 +327,8 @@ class data:
|
||||
float(atom1words[z]),
|
||||
float(atom2words[x]),float(atom2words[y]),
|
||||
float(atom2words[z]),
|
||||
float(atom1words[type]),float(atom2words[type])])
|
||||
|
||||
float(atom1words[type]),float(atom2words[type])])
|
||||
|
||||
tris = []
|
||||
lines = []
|
||||
return 0,box,atoms,bonds,tris,lines
|
||||
@ -357,18 +353,18 @@ class data:
|
||||
|
||||
hkeywords = ["atoms","lines","tris",
|
||||
"bonds","angles","dihedrals","impropers",
|
||||
"atom types","bond types","angle types","dihedral types",
|
||||
"improper types","xlo xhi","ylo yhi","zlo zhi","xy xz yz"]
|
||||
"atom types","bond types","angle types","dihedral types",
|
||||
"improper types","xlo xhi","ylo yhi","zlo zhi","xy xz yz"]
|
||||
|
||||
skeywords = [["Masses","atom types"],
|
||||
["Atoms","atoms"],["Lines","lines"],["Triangles","tris"],
|
||||
["Bonds","bonds"],
|
||||
["Angles","angles"],["Dihedrals","dihedrals"],
|
||||
["Impropers","impropers"],["Velocities","atoms"],
|
||||
["Angles","angles"],["Dihedrals","dihedrals"],
|
||||
["Impropers","impropers"],["Velocities","atoms"],
|
||||
["Pair Coeffs","atom types"],
|
||||
["Bond Coeffs","bond types"],["Angle Coeffs","angle types"],
|
||||
["Dihedral Coeffs","dihedral types"],
|
||||
["Improper Coeffs","improper types"],
|
||||
["Bond Coeffs","bond types"],["Angle Coeffs","angle types"],
|
||||
["Dihedral Coeffs","dihedral types"],
|
||||
["Improper Coeffs","improper types"],
|
||||
["BondBond Coeffs","angle types"],
|
||||
["BondAngle Coeffs","angle types"],
|
||||
["MiddleBondTorsion Coeffs","dihedral types"],
|
||||
|
||||
497
src/dump.py
497
src/dump.py
File diff suppressed because it is too large
Load Diff
@ -4,10 +4,10 @@ A simple routine to load in a LIGGGHTS hybrid dump file containing
|
||||
contact and contact force data and convert into a .vtk unstructured
|
||||
grid which can be used to visualise the force network. This routine
|
||||
also writes the length of the connection between particles, in order
|
||||
to be able to filter out incorrect connections (produced by the
|
||||
to be able to filter out incorrect connections (produced by the
|
||||
"deform" fix)
|
||||
|
||||
This routine is based on Mark Bentley's dump2force (Space Research Institute,
|
||||
This routine is based on Mark Bentley's dump2force (Space Research Institute,
|
||||
Austrian Academy of Sciences, mark.bentley@oeaw.ac.at)
|
||||
|
||||
contributing author: Stefan Radl, TU Graz (radl@tugraz.at)
|
||||
@ -27,6 +27,7 @@ and dump match the format here - this will be checked in future!
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
from evtk.vtk import VtkFile, VtkGroup, VtkUnstructuredGrid
|
||||
from bdump import bdump
|
||||
import numpy as np
|
||||
@ -39,7 +40,7 @@ import sys, os
|
||||
# Check for command line arguments
|
||||
if len(sys.argv) != 2:
|
||||
sys.exit('Usage: dump2force.py <filename>, where filename is a SINGLE filename; typically dump.<runname>')
|
||||
|
||||
|
||||
elif len(sys.argv) == 2: # we have one input param, that should be parsed as a filename
|
||||
filename = str(sys.argv[1])
|
||||
if not os.path.isfile(filename):
|
||||
@ -80,7 +81,7 @@ timestep = forcedata.next()
|
||||
# NOTE: the first timesteps are often blank, and then natoms returns 0, so this doesn't really work...
|
||||
#
|
||||
if forcedata.snaps[fileindex].natoms !=0 and len(forcedata.snaps[0].atoms[0]) < 12:
|
||||
print "Error - dump file requires at least all parameters from a compute pair/gran/local id pos force (12 in total)"
|
||||
print("Error - dump file requires at least all parameters from a compute pair/gran/local id pos force (12 in total)")
|
||||
sys.exit()
|
||||
|
||||
# loop through available timesteps
|
||||
@ -101,10 +102,10 @@ while timestep >= 0:
|
||||
# one datasets has some missing, data for the previous timestep are still displayed -
|
||||
# this means that it is better here to generate "empty" files for these timesteps.
|
||||
|
||||
if forcedata.snaps[fileindex].natoms == 0:
|
||||
if forcedata.snaps[fileindex].natoms == 0:
|
||||
vtufile = fileprefix+'_'+str(timestep)+'.vtu'
|
||||
vtufile = os.path.join(outputdir,vtufile)
|
||||
vtuwrite = file(vtufile,'w')
|
||||
vtuwrite = open(vtufile,'w')
|
||||
vtuwrite.write("""<?xml version="1.0"?>
|
||||
<VTKFile byte_order="LittleEndian" version="0.1" type="UnstructuredGrid">
|
||||
<UnstructuredGrid>
|
||||
@ -118,7 +119,7 @@ while timestep >= 0:
|
||||
</Piece>
|
||||
</UnstructuredGrid>
|
||||
</VTKFile>""")
|
||||
|
||||
|
||||
else:
|
||||
# ******************************************
|
||||
# Cell and connection lists
|
||||
@ -134,8 +135,8 @@ while timestep >= 0:
|
||||
nconnex = ncells - nperiodic
|
||||
|
||||
# extract the IDs as an array of integers
|
||||
id1 = np.array(forcedata.snaps[fileindex].atoms[:,forcedata.names["id1"]],dtype=long)
|
||||
id2 = np.array(forcedata.snaps[fileindex].atoms[:,forcedata.names["id2"]],dtype=long)
|
||||
id1 = np.array(forcedata.snaps[fileindex].atoms[:,forcedata.names["id1"]],dtype=int)
|
||||
id2 = np.array(forcedata.snaps[fileindex].atoms[:,forcedata.names["id2"]],dtype=int)
|
||||
|
||||
# and convert to lists
|
||||
id1 = id1.tolist()
|
||||
@ -153,7 +154,7 @@ while timestep >= 0:
|
||||
# number of points = number of unique IDs (particles)
|
||||
npoints = len(ids)
|
||||
|
||||
print 'Timestep:',str(timestep),'npoints=',str(npoints),'ncells=',str(ncells),'nperiodic=',nperiodic, 'nconnex=',str(nconnex)
|
||||
print('Timestep:',str(timestep),'npoints=',str(npoints),'ncells=',str(ncells),'nperiodic=',nperiodic, 'nconnex=',str(nconnex))
|
||||
|
||||
|
||||
# ******************************************
|
||||
@ -168,7 +169,7 @@ while timestep >= 0:
|
||||
-np.array(forcedata.snaps[fileindex].atoms[:,forcedata.names["y2"]],dtype=np.float64))**2 \
|
||||
+ \
|
||||
(np.array(forcedata.snaps[fileindex].atoms[:,forcedata.names["z1"]],dtype=np.float64) \
|
||||
-np.array(forcedata.snaps[fileindex].atoms[:,forcedata.names["z2"]],dtype=np.float64))**2
|
||||
-np.array(forcedata.snaps[fileindex].atoms[:,forcedata.names["z2"]],dtype=np.float64))**2
|
||||
connectionLength = np.sqrt(connectionLength)
|
||||
|
||||
|
||||
@ -217,7 +218,7 @@ while timestep >= 0:
|
||||
y = np.zeros( npoints, dtype=np.float64)
|
||||
z = np.zeros( npoints, dtype=np.float64)
|
||||
|
||||
counter = 0
|
||||
counter = 0
|
||||
for id in ids:
|
||||
if id in id1:
|
||||
index = id1.index(id)
|
||||
@ -229,10 +230,10 @@ while timestep >= 0:
|
||||
xtemp,ytemp,ztemp = forcedata.snaps[fileindex].atoms[index,forcedata.names["x2"]], \
|
||||
forcedata.snaps[fileindex].atoms[index,forcedata.names["y2"]], \
|
||||
forcedata.snaps[fileindex].atoms[index,forcedata.names["z2"]]
|
||||
|
||||
|
||||
x[counter]=xtemp
|
||||
y[counter]=ytemp
|
||||
z[counter]=ztemp
|
||||
z[counter]=ztemp
|
||||
counter += 1
|
||||
|
||||
# Now create the connectivity list - this corresponds to pairs of IDs, but referencing
|
||||
@ -241,7 +242,7 @@ while timestep >= 0:
|
||||
|
||||
# If the periodic flag is set for a given interactions, DO NOT connect the points
|
||||
# (to avoid lines that cross the simulation domain)
|
||||
|
||||
|
||||
# Mask out periodic interactions from the cell (connectivity) array
|
||||
# newList = [word for (word, mask) in zip(s,b) if mask]
|
||||
id1_masked = [ident for (ident,mask) in zip(id1,np.invert(periodic)) if mask]
|
||||
|
||||
283
src/ensight.py
283
src/ensight.py
@ -3,15 +3,20 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# ensight tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, types
|
||||
|
||||
oneline = "Convert LAMMPS snapshots or meshes to Ensight format"
|
||||
|
||||
docstr = """
|
||||
e = ensight(d) d = object with atoms or elements (dump,data,mdump)
|
||||
e = ensight(d) d = object with atoms or elements (dump,data,mdump)
|
||||
e.change = 1 set to 1 if element nodal xyz change with time (def = 0)
|
||||
e.maxtype = 10 max particle type, set if query to data will be bad
|
||||
|
||||
@ -50,10 +55,6 @@ e.single(N) same args as one() prepended by N, but write a single snap
|
||||
# which = 0 for particles, 1 for elements
|
||||
# change = 0 for unchanging mesh coords, 1 for changing mesh coords (def = 0)
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, types
|
||||
|
||||
# Class definition
|
||||
|
||||
class ensight:
|
||||
@ -64,22 +65,22 @@ class ensight:
|
||||
self.change = 0
|
||||
self.maxtype = 0
|
||||
self.data = data
|
||||
if type(data) is types.InstanceType and ".dump" in str(data.__class__):
|
||||
if isinstance(data, object) and ".dump" in str(data.__class__):
|
||||
self.which = 0
|
||||
elif type(data) is types.InstanceType and ".data" in str(data.__class__):
|
||||
elif isinstance(data, object) and ".data" in str(data.__class__):
|
||||
self.which = 0
|
||||
elif type(data) is types.InstanceType and ".mdump" in str(data.__class__):
|
||||
elif isinstance(data, object) and ".mdump" in str(data.__class__):
|
||||
self.which = 1
|
||||
elif type(data) is types.InstanceType and ".cdata" in str(data.__class__):
|
||||
elif isinstance(data, object) and ".cdata" in str(data.__class__):
|
||||
self.which = 1
|
||||
else:
|
||||
raise StandardError,"unrecognized object passed to ensight"
|
||||
|
||||
raise Exception("unrecognized object passed to ensight")
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def one(self,*args):
|
||||
if len(args) % 2 == 0: root = "tmp"
|
||||
else:
|
||||
else:
|
||||
root = args[0]
|
||||
args = args[1:]
|
||||
|
||||
@ -90,7 +91,7 @@ class ensight:
|
||||
|
||||
if self.which == 0 and self.maxtype == 0:
|
||||
self.maxtype = self.data.maxtype()
|
||||
|
||||
|
||||
# write Ensight *.case header file
|
||||
|
||||
f = open("%s.case" % root,"w")
|
||||
@ -114,34 +115,34 @@ class ensight:
|
||||
if flag == -1: break
|
||||
|
||||
if self.which == 0:
|
||||
print >>f,"BEGIN TIME STEP"
|
||||
print("BEGIN TIME STEP", file=f)
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(which)
|
||||
self.coord_file_atoms(f,box,atoms)
|
||||
print >>f,"END TIME STEP"
|
||||
print("END TIME STEP", file=f)
|
||||
elif self.change == 0 and first:
|
||||
print >>f,"BEGIN TIME STEP"
|
||||
print("BEGIN TIME STEP", file=f)
|
||||
time,box,nodes,elements,nvalues,evalues = self.data.mviz(which)
|
||||
self.coord_file_elements(f,box,nodes,elements)
|
||||
etype = len(elements[0])
|
||||
first = 0
|
||||
print >>f,"END TIME STEP"
|
||||
print("END TIME STEP", file=f)
|
||||
elif self.change:
|
||||
print >>f,"BEGIN TIME STEP"
|
||||
print("BEGIN TIME STEP", file=f)
|
||||
time,box,nodes,elements,nvalues,evalues = self.data.mviz(which)
|
||||
self.coord_file_elements(f,box,nodes,elements)
|
||||
etype = len(elements[0])
|
||||
print >>f,"END TIME STEP"
|
||||
print("END TIME STEP", file=f)
|
||||
|
||||
for i in range(len(pairs)):
|
||||
print >>vfiles[i],"BEGIN TIME STEP"
|
||||
print("BEGIN TIME STEP", file=vfiles[i])
|
||||
values = self.data.vecs(time,pairs[i][0])
|
||||
if self.which == 0:
|
||||
self.variable_file_atoms(vfiles[i],pairs[i][1],atoms,values)
|
||||
else:
|
||||
self.variable_file_elements(vfiles[i],pairs[i][1],etype,values)
|
||||
print >>vfiles[i],"END TIME STEP"
|
||||
|
||||
print time,
|
||||
print("END TIME STEP", file=vfiles[i])
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
@ -150,13 +151,13 @@ class ensight:
|
||||
f.close()
|
||||
for f in vfiles: f.close()
|
||||
|
||||
print "\nwrote %s snapshots in Ensight format" % n
|
||||
print("\nwrote %s snapshots in Ensight format" % n)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def increment(self,*args):
|
||||
if len(args) % 2 == 0: root = "tmp"
|
||||
else:
|
||||
else:
|
||||
root = args[0]
|
||||
args = args[1:]
|
||||
|
||||
@ -181,41 +182,41 @@ class ensight:
|
||||
first = 1
|
||||
n = etype = 0
|
||||
while 1:
|
||||
time = self.data.next()
|
||||
time = next(self.data)
|
||||
if time == -1: break
|
||||
times.append(time)
|
||||
self.data.tselect.one(time)
|
||||
self.data.delete()
|
||||
|
||||
if self.which == 0:
|
||||
print >>f,"BEGIN TIME STEP"
|
||||
print("BEGIN TIME STEP", file=f)
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(0)
|
||||
self.coord_file_atoms(f,box,atoms)
|
||||
print >>f,"END TIME STEP"
|
||||
print("END TIME STEP", file=f)
|
||||
elif self.change == 0 and first:
|
||||
print >>f,"BEGIN TIME STEP"
|
||||
print("BEGIN TIME STEP", file=f)
|
||||
time,box,nodes,elements,nvalues,evalues = self.data.mviz(0)
|
||||
self.coord_file_elements(f,box,nodes,elements)
|
||||
etype = len(elements[0])
|
||||
first = 0
|
||||
print >>f,"END TIME STEP"
|
||||
print("END TIME STEP", file=f)
|
||||
elif self.change:
|
||||
print >>f,"BEGIN TIME STEP"
|
||||
print("BEGIN TIME STEP", file=f)
|
||||
time,box,nodes,elements,nvalues,evalues = self.data.mviz(0)
|
||||
self.coord_file_elements(f,box,nodes,elements)
|
||||
etype = len(elements[0])
|
||||
print >>f,"END TIME STEP"
|
||||
print("END TIME STEP", file=f)
|
||||
|
||||
for i in range(len(pairs)):
|
||||
print >>vfiles[i],"BEGIN TIME STEP"
|
||||
print("BEGIN TIME STEP", file=vfiles[i])
|
||||
values = self.data.vecs(time,pairs[i][0])
|
||||
if self.which == 0:
|
||||
self.variable_file_atoms(vfiles[i],pairs[i][1],atoms,values)
|
||||
else:
|
||||
self.variable_file_elements(vfiles[i],pairs[i][1],etype,values)
|
||||
print >>vfiles[i],"END TIME STEP"
|
||||
|
||||
print time,
|
||||
print("END TIME STEP", file=vfiles[i])
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
@ -230,13 +231,13 @@ class ensight:
|
||||
self.case_file(f,root,pairs,0,len(times),times)
|
||||
f.close()
|
||||
|
||||
print "\nwrote %s snapshots in Ensight format" % n
|
||||
print("\nwrote %s snapshots in Ensight format" % n)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def many(self,*args):
|
||||
if len(args) % 2 == 0: root = "tmp"
|
||||
else:
|
||||
else:
|
||||
root = args[0]
|
||||
args = args[1:]
|
||||
|
||||
@ -268,20 +269,20 @@ class ensight:
|
||||
files = []
|
||||
if n < 10:
|
||||
file = root + "000" + str(n) + ".xyz"
|
||||
for pair in pairs:
|
||||
files.append(root + "000" + str(n) + "." + pair[0])
|
||||
for pair in pairs:
|
||||
files.append(root + "000" + str(n) + "." + pair[0])
|
||||
elif n < 100:
|
||||
file = root + "00" + str(n) + ".xyz"
|
||||
for pair in pairs:
|
||||
files.append(root + "00" + str(n) + "." + pair[0])
|
||||
for pair in pairs:
|
||||
files.append(root + "00" + str(n) + "." + pair[0])
|
||||
elif n < 1000:
|
||||
file = root + "0" + str(n) + ".xyz"
|
||||
for pair in pairs:
|
||||
files.append(root + "0" + str(n) + "." + pair[0])
|
||||
for pair in pairs:
|
||||
files.append(root + "0" + str(n) + "." + pair[0])
|
||||
else:
|
||||
file = root + str(n) + ".xyz"
|
||||
for pair in pairs:
|
||||
files.append(root + str(n) + "." + pair[0])
|
||||
for pair in pairs:
|
||||
files.append(root + str(n) + "." + pair[0])
|
||||
|
||||
if self.which == 0:
|
||||
f = open(file,"w")
|
||||
@ -309,19 +310,19 @@ class ensight:
|
||||
self.variable_file_atoms(f,pairs[i][1],atoms,values)
|
||||
else:
|
||||
self.variable_file_elements(f,pairs[i][1],etype,values)
|
||||
f.close()
|
||||
f.close()
|
||||
|
||||
print time,
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
print "\nwrote %s snapshots in Ensight format" % n
|
||||
|
||||
print("\nwrote %s snapshots in Ensight format" % n)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def single(self,time,*args):
|
||||
if len(args) % 2 == 0: root = "tmp"
|
||||
else:
|
||||
else:
|
||||
root = args[0]
|
||||
args = args[1:]
|
||||
|
||||
@ -343,7 +344,7 @@ class ensight:
|
||||
|
||||
which = self.data.findtime(time)
|
||||
etype = 0
|
||||
|
||||
|
||||
f = open(root + ".xyz","w")
|
||||
if self.which == 0:
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(which)
|
||||
@ -353,7 +354,7 @@ class ensight:
|
||||
self.coord_file_elements(f,box,nodes,elements)
|
||||
etype = len(elements[0])
|
||||
f.close()
|
||||
|
||||
|
||||
for i in range(len(pairs)):
|
||||
values = self.data.vecs(time,pairs[i][0])
|
||||
f = open(root + "." + pairs[i][0],"w")
|
||||
@ -362,60 +363,60 @@ class ensight:
|
||||
else:
|
||||
self.variable_file_elements(f,pairs[i][1],etype,values)
|
||||
f.close()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write Ensight case file
|
||||
|
||||
def case_file(self,f,root,pairs,multifile,nsnaps,times):
|
||||
print >>f,"# Ensight case file\n"
|
||||
print >>f,"FORMAT\ntype: ensight gold\n"
|
||||
|
||||
print("# Ensight case file\n", file=f)
|
||||
print("FORMAT\ntype: ensight gold\n", file=f)
|
||||
|
||||
if self.which == 0:
|
||||
if multifile:
|
||||
# print >>f,"GEOMETRY\nmodel: %s****.xyz change_coords_only\n" % root
|
||||
print >>f,"GEOMETRY\nmodel: %s****.xyz\n" % root
|
||||
print("GEOMETRY\nmodel: %s****.xyz\n" % root, file=f)
|
||||
else:
|
||||
# print >>f,"GEOMETRY\nmodel: 1 1 %s.xyz change_coords_only\n" % root
|
||||
print >>f,"GEOMETRY\nmodel: 1 1 %s.xyz\n" % root
|
||||
print("GEOMETRY\nmodel: 1 1 %s.xyz\n" % root, file=f)
|
||||
else:
|
||||
if self.change == 0:
|
||||
print >>f,"GEOMETRY\nmodel: %s.xyz\n" % root
|
||||
print("GEOMETRY\nmodel: %s.xyz\n" % root, file=f)
|
||||
elif multifile:
|
||||
print >>f,"GEOMETRY\nmodel: %s****.xyz\n" % root
|
||||
print("GEOMETRY\nmodel: %s****.xyz\n" % root, file=f)
|
||||
else:
|
||||
print >>f,"GEOMETRY\nmodel: 1 1 %s.xyz\n" % root
|
||||
print("GEOMETRY\nmodel: 1 1 %s.xyz\n" % root, file=f)
|
||||
|
||||
if len(pairs):
|
||||
print >>f,"VARIABLE"
|
||||
print("VARIABLE", file=f)
|
||||
for pair in pairs:
|
||||
if self.which == 0:
|
||||
if multifile:
|
||||
print >>f,"scalar per node: %s %s****.%s" % (pair[1],root,pair[0])
|
||||
print("scalar per node: %s %s****.%s" % (pair[1],root,pair[0]), file=f)
|
||||
else:
|
||||
print >>f,"scalar per node: 1 1 %s %s.%s" % (pair[1],root,pair[0])
|
||||
print("scalar per node: 1 1 %s %s.%s" % (pair[1],root,pair[0]), file=f)
|
||||
else:
|
||||
if multifile:
|
||||
print >>f,"scalar per element: %s %s****.%s" % (pair[1],root,pair[0])
|
||||
print("scalar per element: %s %s****.%s" % (pair[1],root,pair[0]), file=f)
|
||||
else:
|
||||
print >>f,"scalar per element: 1 1 %s %s.%s" % (pair[1],root,pair[0])
|
||||
print >>f
|
||||
print("scalar per element: 1 1 %s %s.%s" % (pair[1],root,pair[0]), file=f)
|
||||
print(file=f)
|
||||
|
||||
print >>f,"TIME"
|
||||
print >>f,"time set: 1"
|
||||
print >>f,"number of steps:",nsnaps
|
||||
print >>f,"filename start number: 0"
|
||||
print >>f,"filename increment: 1"
|
||||
print >>f,"time values:"
|
||||
print("TIME", file=f)
|
||||
print("time set: 1", file=f)
|
||||
print("number of steps:",nsnaps, file=f)
|
||||
print("filename start number: 0", file=f)
|
||||
print("filename increment: 1", file=f)
|
||||
print("time values:", file=f)
|
||||
for i in range(nsnaps):
|
||||
print >>f,times[i],
|
||||
if i % 10 == 9: print >>f
|
||||
print >>f
|
||||
print >>f
|
||||
|
||||
print(times[i], end=' ', file=f)
|
||||
if i % 10 == 9: print(file=f)
|
||||
print(file=f)
|
||||
print(file=f)
|
||||
|
||||
if not multifile:
|
||||
print >>f,"FILE"
|
||||
print >>f,"file set: 1"
|
||||
print >>f,"number of steps:",nsnaps
|
||||
print("FILE", file=f)
|
||||
print("file set: 1", file=f)
|
||||
print("number of steps:",nsnaps, file=f)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write Ensight coordinates for atoms
|
||||
@ -423,65 +424,65 @@ class ensight:
|
||||
# one part = coords for all atoms of a single type
|
||||
|
||||
def coord_file_atoms(self,f,box,atoms):
|
||||
print >>f,"Particle geometry\nfor a collection of atoms"
|
||||
print >>f,"node id given"
|
||||
print >>f,"element id off"
|
||||
print >>f,"extents"
|
||||
print >>f,"%12.5e%12.5e" % (box[0],box[3])
|
||||
print >>f,"%12.5e%12.5e" % (box[1],box[4])
|
||||
print >>f,"%12.5e%12.5e" % (box[2],box[5])
|
||||
print("Particle geometry\nfor a collection of atoms", file=f)
|
||||
print("node id given", file=f)
|
||||
print("element id off", file=f)
|
||||
print("extents", file=f)
|
||||
print("%12.5e%12.5e" % (box[0],box[3]), file=f)
|
||||
print("%12.5e%12.5e" % (box[1],box[4]), file=f)
|
||||
print("%12.5e%12.5e" % (box[2],box[5]), file=f)
|
||||
|
||||
for type in xrange(1,self.maxtype+1):
|
||||
print >>f,"part"
|
||||
print >>f,"%10d" % type
|
||||
print >>f,"type",type
|
||||
print >>f,"coordinates"
|
||||
for type in range(1,self.maxtype+1):
|
||||
print("part", file=f)
|
||||
print("%10d" % type, file=f)
|
||||
print("type",type, file=f)
|
||||
print("coordinates", file=f)
|
||||
group = [atom for atom in atoms if int(atom[1]) == type]
|
||||
print >>f,"%10d" % len(group)
|
||||
for atom in group: print >>f,"%10d" % int(atom[0])
|
||||
for atom in group: print >>f,"%12.5e" % atom[2]
|
||||
for atom in group: print >>f,"%12.5e" % atom[3]
|
||||
for atom in group: print >>f,"%12.5e" % atom[4]
|
||||
print >>f,"point"
|
||||
print >>f,"%10d" % len(group)
|
||||
for i in xrange(1,len(group)+1): print >>f,"%10d" % i
|
||||
print("%10d" % len(group), file=f)
|
||||
for atom in group: print("%10d" % int(atom[0]), file=f)
|
||||
for atom in group: print("%12.5e" % atom[2], file=f)
|
||||
for atom in group: print("%12.5e" % atom[3], file=f)
|
||||
for atom in group: print("%12.5e" % atom[4], file=f)
|
||||
print("point", file=f)
|
||||
print("%10d" % len(group), file=f)
|
||||
for i in range(1,len(group)+1): print("%10d" % i, file=f)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write Ensight coordinates for elements
|
||||
|
||||
def coord_file_elements(self,f,box,nodes,elements):
|
||||
print >>f,"Element geometry\nfor a collection of elements"
|
||||
print >>f,"node id given"
|
||||
print >>f,"element id given"
|
||||
print >>f,"extents"
|
||||
print >>f,"%12.5e%12.5e" % (box[0],box[3])
|
||||
print >>f,"%12.5e%12.5e" % (box[1],box[4])
|
||||
print >>f,"%12.5e%12.5e" % (box[2],box[5])
|
||||
print("Element geometry\nfor a collection of elements", file=f)
|
||||
print("node id given", file=f)
|
||||
print("element id given", file=f)
|
||||
print("extents", file=f)
|
||||
print("%12.5e%12.5e" % (box[0],box[3]), file=f)
|
||||
print("%12.5e%12.5e" % (box[1],box[4]), file=f)
|
||||
print("%12.5e%12.5e" % (box[2],box[5]), file=f)
|
||||
|
||||
print >>f,"part"
|
||||
print >>f,"%10d" % 1
|
||||
print >>f,"all elements"
|
||||
print >>f,"coordinates"
|
||||
print >>f,"%10d" % len(nodes)
|
||||
for node in nodes: print >>f,"%10d" % int(node[0])
|
||||
for node in nodes: print >>f,"%12.5e" % node[2]
|
||||
for node in nodes: print >>f,"%12.5e" % node[3]
|
||||
for node in nodes: print >>f,"%12.5e" % node[4]
|
||||
print("part", file=f)
|
||||
print("%10d" % 1, file=f)
|
||||
print("all elements", file=f)
|
||||
print("coordinates", file=f)
|
||||
print("%10d" % len(nodes), file=f)
|
||||
for node in nodes: print("%10d" % int(node[0]), file=f)
|
||||
for node in nodes: print("%12.5e" % node[2], file=f)
|
||||
for node in nodes: print("%12.5e" % node[3], file=f)
|
||||
for node in nodes: print("%12.5e" % node[4], file=f)
|
||||
|
||||
if len(elements[0]) == 5: print >>f,"tria3"
|
||||
elif len(elements[0]) == 6: print >>f,"tetra4"
|
||||
else: raise StandardError,"unrecognized element type"
|
||||
print >>f,"%10d" % len(elements)
|
||||
if len(elements[0]) == 5: print("tria3", file=f)
|
||||
elif len(elements[0]) == 6: print("tetra4", file=f)
|
||||
else: raise Exception("unrecognized element type")
|
||||
print("%10d" % len(elements), file=f)
|
||||
|
||||
for element in elements: print >>f,"%10d" % int(element[0])
|
||||
for element in elements: print("%10d" % int(element[0]), file=f)
|
||||
if len(elements[0]) == 5:
|
||||
for element in elements:
|
||||
print >>f,"%10d%10d%10d" % \
|
||||
(int(element[2]),int(element[3]),int(element[4]))
|
||||
print("%10d%10d%10d" % \
|
||||
(int(element[2]),int(element[3]),int(element[4])), file=f)
|
||||
elif len(elements[0]) == 6:
|
||||
for element in elements:
|
||||
print >>f,"%10d%10d%10d%10d" % \
|
||||
(int(element[2]),int(element[3]),int(element[4]),int(element[5]))
|
||||
print("%10d%10d%10d%10d" % \
|
||||
(int(element[2]),int(element[3]),int(element[4]),int(element[5])), file=f)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write Ensight variable values for atoms
|
||||
@ -489,22 +490,22 @@ class ensight:
|
||||
# one part = values for all atoms of a single type
|
||||
|
||||
def variable_file_atoms(self,f,name,atoms,values):
|
||||
print >>f,"Particle %s" % name
|
||||
for type in xrange(1,self.maxtype+1):
|
||||
print >>f,"part"
|
||||
print >>f,"%10d" % type
|
||||
print >>f,"coordinates"
|
||||
group = [values[i] for i in xrange(len(atoms))
|
||||
print("Particle %s" % name, file=f)
|
||||
for type in range(1,self.maxtype+1):
|
||||
print("part", file=f)
|
||||
print("%10d" % type, file=f)
|
||||
print("coordinates", file=f)
|
||||
group = [values[i] for i in range(len(atoms))
|
||||
if int(atoms[i][1]) == type]
|
||||
for value in group: print >>f,"%12.5e" % value
|
||||
for value in group: print("%12.5e" % value, file=f)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write Ensight variable values for elements
|
||||
|
||||
def variable_file_elements(self,f,name,etype,values):
|
||||
print >>f,"Element %s" % name
|
||||
print >>f,"part"
|
||||
print >>f,"%10d" % 1
|
||||
if etype == 5: print >>f,"tria3"
|
||||
elif etype == 6: print >>f,"tetra4"
|
||||
for value in values: print >>f,"%12.5e" % value
|
||||
print("Element %s" % name, file=f)
|
||||
print("part", file=f)
|
||||
print("%10d" % 1, file=f)
|
||||
if etype == 5: print("tria3", file=f)
|
||||
elif etype == 6: print("tetra4", file=f)
|
||||
for value in values: print("%12.5e" % value, file=f)
|
||||
|
||||
214
src/gl.py
214
src/gl.py
@ -3,11 +3,21 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# gl tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
|
||||
from math import sin,cos,sqrt,pi,acos
|
||||
from OpenGL.Tk import *
|
||||
from OpenGL.GLUT import *
|
||||
from PIL import Image
|
||||
from vizinfo import vizinfo
|
||||
|
||||
oneline = "3d interactive visualization via OpenGL"
|
||||
|
||||
docstr = """
|
||||
@ -16,8 +26,8 @@ g = gl(d) create OpenGL display for data in d
|
||||
d = atom snapshot object (dump, data)
|
||||
|
||||
g.bg("black") set background color (def = "black")
|
||||
g.size(N) set image size to NxN
|
||||
g.size(N,M) set image size to NxM
|
||||
g.size(N) set image size to NxN
|
||||
g.size(N,M) set image size to NxM
|
||||
g.rotate(60,135) view from z theta and azimuthal phi (def = 60,30)
|
||||
g.shift(x,y) translate by x,y pixels in view window (def = 0,0)
|
||||
g.zoom(0.5) scale image by factor (def = 1)
|
||||
@ -27,7 +37,7 @@ g.box(0/1/2,"red",4) set box edge thickness
|
||||
g.file = "image" file prefix for created images (def = "image")
|
||||
|
||||
g.show(N) show image of snapshot at timestep N
|
||||
|
||||
|
||||
g.all() make images of all selected snapshots
|
||||
g.all(P) images of all, start file label at P
|
||||
g.all(N,M,P) make M images of snapshot N, start label at P
|
||||
@ -40,12 +50,12 @@ g.pan() no pan during all() (default)
|
||||
|
||||
g.select = "$x > %g*3.0" string to pass to d.aselect.test() during all()
|
||||
g.select = "" no extra aselect (default)
|
||||
|
||||
|
||||
%g varies from 0.0 to 1.0 from beginning to end of all()
|
||||
|
||||
g.acol(2,"green") set atom colors by atom type (1-N)
|
||||
g.acol([2,4],["red","blue"]) 1st arg = one type or list of types
|
||||
g.acol(0,"blue") 2nd arg = one color or list of colors
|
||||
|
||||
g.acol(2,"green") set atom colors by atom type (1-N)
|
||||
g.acol([2,4],["red","blue"]) 1st arg = one type or list of types
|
||||
g.acol(0,"blue") 2nd arg = one color or list of colors
|
||||
g.acol(range(20),["red","blue"]) if list lengths unequal, interpolate
|
||||
g.acol(range(10),"loop") assign colors in loop, randomly ordered
|
||||
|
||||
@ -55,23 +65,23 @@ g.acol(range(10),"loop") assign colors in loop, randomly ordered
|
||||
|
||||
g.arad([1,2],[0.5,0.3]) set atom radii, same rules as acol()
|
||||
|
||||
g.bcol() set bond color, same args as acol()
|
||||
g.brad() set bond thickness, same args as arad()
|
||||
g.bcol() set bond color, same args as acol()
|
||||
g.brad() set bond thickness, same args as arad()
|
||||
|
||||
g.tcol() set triangle color, same args as acol()
|
||||
g.tfill() set triangle fill, 0 fill, 1 line, 2 both
|
||||
g.tcol() set triangle color, same args as acol()
|
||||
g.tfill() set triangle fill, 0 fill, 1 line, 2 both
|
||||
|
||||
g.lcol() set line color, same args as acol()
|
||||
g.lrad() set line thickness, same args as arad()
|
||||
|
||||
g.adef() set atom/bond/tri/line properties to default
|
||||
g.bdef() default = "loop" for colors, 0.45 for radii
|
||||
g.tdef() default = 0.25 for bond/line thickness
|
||||
g.ldef() default = 0 fill
|
||||
g.bdef() default = "loop" for colors, 0.45 for radii
|
||||
g.tdef() default = 0.25 for bond/line thickness
|
||||
g.ldef() default = 0 fill
|
||||
|
||||
by default 100 types are assigned
|
||||
if atom/bond/tri/line has type > # defined properties, is an error
|
||||
|
||||
|
||||
from vizinfo import colors access color list
|
||||
print colors list defined color names and RGB values
|
||||
colors["nickname"] = [R,G,B] set new RGB values from 0 to 255
|
||||
@ -122,14 +132,6 @@ g.sview(theta,phi,x,y,scale,up) set all view parameters
|
||||
# up[3] = screen up direction in simulation box (unit vector)
|
||||
# right[3] = screen right direction in simulation box (unit vector)
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from math import sin,cos,sqrt,pi,acos
|
||||
from OpenGL.Tk import *
|
||||
from OpenGL.GLUT import *
|
||||
import Image
|
||||
from vizinfo import vizinfo
|
||||
|
||||
# Class definition
|
||||
|
||||
class gl:
|
||||
@ -145,7 +147,7 @@ class gl:
|
||||
self.azphi = 30
|
||||
self.scale = 1.0
|
||||
self.xshift = self.yshift = 0
|
||||
|
||||
|
||||
self.file = "image"
|
||||
self.boxflag = 0
|
||||
self.bxcol = [1,1,0]
|
||||
@ -162,7 +164,7 @@ class gl:
|
||||
self.nsides = 10
|
||||
self.theta_amplify = 2
|
||||
self.shiny = 2
|
||||
|
||||
|
||||
self.clipflag = 0
|
||||
self.clipxlo = self.clipylo = self.clipzlo = 0.0
|
||||
self.clipxhi = self.clipyhi = self.clipzhi = 1.0
|
||||
@ -187,7 +189,7 @@ class gl:
|
||||
self.bdef()
|
||||
self.tdef()
|
||||
self.ldef()
|
||||
|
||||
|
||||
self.center = 3*[0]
|
||||
self.view = 3*[0]
|
||||
self.up = 3*[0]
|
||||
@ -209,7 +211,7 @@ class gl:
|
||||
if not ynew: self.ypixels = self.xpixels
|
||||
else: self.ypixels = ynew
|
||||
self.create_window()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def axis(self,value):
|
||||
@ -221,7 +223,7 @@ class gl:
|
||||
|
||||
def create_window(self):
|
||||
if self.root: self.root.destroy()
|
||||
|
||||
|
||||
from __main__ import tkroot
|
||||
self.root = Toplevel(tkroot)
|
||||
self.root.title('Pizza.py gl tool')
|
||||
@ -230,7 +232,7 @@ class gl:
|
||||
double=1,depth=1)
|
||||
self.w.pack(expand=YES)
|
||||
# self.w.pack(expand=YES,fill=BOTH)
|
||||
|
||||
|
||||
glViewport(0,0,self.xpixels,self.ypixels)
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
@ -245,7 +247,7 @@ class gl:
|
||||
self.w.parent = self
|
||||
self.w.tkRedraw()
|
||||
tkroot.update_idletasks() # force window to appear
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def clip(self,which,value):
|
||||
@ -312,7 +314,7 @@ class gl:
|
||||
self.up[1] = sin(pi*self.azphi/180)
|
||||
self.up[2] = 0.0
|
||||
else:
|
||||
dot = self.view[2] # dot = (0,0,1) . view
|
||||
dot = self.view[2] # dot = (0,0,1) . view
|
||||
self.up[0] = -dot*self.view[0] # up projected onto v = dot * v
|
||||
self.up[1] = -dot*self.view[1] # up perp to v = up - dot * v
|
||||
self.up[2] = 1.0 - dot*self.view[2]
|
||||
@ -323,7 +325,7 @@ class gl:
|
||||
# --------------------------------------------------------------------
|
||||
# reset ztheta,azphi and thus view,up.right
|
||||
# called as function from Pizza.py
|
||||
|
||||
|
||||
def rotate(self,ztheta,azphi):
|
||||
self.ztheta = ztheta
|
||||
self.azphi = azphi
|
||||
@ -364,11 +366,11 @@ class gl:
|
||||
# rotate view,up around axis of rotation = old x new
|
||||
# right = up x view
|
||||
# reset ztheta,azphi from view
|
||||
|
||||
|
||||
def mouse_rotate(self,xnew,ynew,xold,yold):
|
||||
|
||||
# change y pixels to measure from bottom of window instead of top
|
||||
|
||||
|
||||
yold = self.ypixels - yold
|
||||
ynew = self.ypixels - ynew
|
||||
|
||||
@ -405,7 +407,7 @@ class gl:
|
||||
axis[1] = rot[0]*self.right[1] + rot[1]*self.up[1] + rot[2]*self.view[1]
|
||||
axis[2] = rot[0]*self.right[2] + rot[1]*self.up[2] + rot[2]*self.view[2]
|
||||
axis = vecnorm(axis)
|
||||
|
||||
|
||||
# view is changed by (axis x view) scaled by theta
|
||||
# up is changed by (axis x up) scaled by theta
|
||||
# force up to be perp to view via up_perp = up - (up . view) view
|
||||
@ -442,8 +444,8 @@ class gl:
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def shift(self,x,y):
|
||||
self.xshift = x;
|
||||
self.yshift = y;
|
||||
self.xshift = x
|
||||
self.yshift = y
|
||||
self.setview()
|
||||
self.w.tkRedraw()
|
||||
|
||||
@ -466,14 +468,14 @@ class gl:
|
||||
# output: eye = distance to view scene from
|
||||
# xto,yto,zto = point to look to
|
||||
# xfrom,yfrom,zfrom = point to look from
|
||||
|
||||
|
||||
def setview(self):
|
||||
if not self.ready: return # no distance since no scene yet
|
||||
|
||||
|
||||
self.eye = 3 * self.distance / self.scale
|
||||
xfactor = 0.5*self.eye*self.xshift/self.xpixels
|
||||
yfactor = 0.5*self.eye*self.yshift/self.ypixels
|
||||
|
||||
|
||||
self.xto = self.center[0] - xfactor*self.right[0] - yfactor*self.up[0]
|
||||
self.yto = self.center[1] - xfactor*self.right[1] - yfactor*self.up[1]
|
||||
self.zto = self.center[2] - xfactor*self.right[2] - yfactor*self.up[2]
|
||||
@ -484,7 +486,7 @@ class gl:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# box attributes, also used for triangle lines
|
||||
|
||||
|
||||
def box(self,*args):
|
||||
self.boxflag = args[0]
|
||||
if len(args) > 1:
|
||||
@ -498,9 +500,9 @@ class gl:
|
||||
# --------------------------------------------------------------------
|
||||
# grab all selected snapshots from data object
|
||||
# add GL-specific info to each bond
|
||||
|
||||
|
||||
def reload(self):
|
||||
print "Loading data into gl tool ..."
|
||||
print("Loading data into gl tool ...")
|
||||
data = self.data
|
||||
|
||||
self.timeframes = []
|
||||
@ -527,10 +529,10 @@ class gl:
|
||||
self.bondframes.append(bonds)
|
||||
self.triframes.append(tris)
|
||||
self.lineframes.append(lines)
|
||||
|
||||
print time,
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
print
|
||||
print()
|
||||
|
||||
self.nframes = len(self.timeframes)
|
||||
self.distance = compute_distance(self.boxframes[0])
|
||||
@ -543,11 +545,11 @@ class gl:
|
||||
def nolabel(self):
|
||||
self.cachelist = -self.cachelist
|
||||
self.labels = []
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# show a single snapshot
|
||||
# distance from snapshot box or max box for all selected steps
|
||||
|
||||
|
||||
def show(self,ntime):
|
||||
data = self.data
|
||||
which = data.findtime(ntime)
|
||||
@ -569,7 +571,7 @@ class gl:
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
self.save()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def pan(self,*list):
|
||||
@ -582,7 +584,7 @@ class gl:
|
||||
self.ztheta_stop = list[3]
|
||||
self.azphi_stop = list[4]
|
||||
self.scale_stop = list[5]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def all(self,*list):
|
||||
@ -613,7 +615,7 @@ class gl:
|
||||
if flag == -1: break
|
||||
|
||||
fraction = float(i) / (ncount-1)
|
||||
|
||||
|
||||
if self.select != "":
|
||||
newstr = self.select % fraction
|
||||
data.aselect.test(newstr,time)
|
||||
@ -636,7 +638,7 @@ class gl:
|
||||
fraction*(self.scale_stop - self.scale_start)
|
||||
self.viewupright()
|
||||
|
||||
if n == nstart or self.panflag: self.center = compute_center(box)
|
||||
if n == nstart or self.panflag: self.center = compute_center(box)
|
||||
|
||||
if bonds: self.bonds_augment(bonds)
|
||||
|
||||
@ -651,8 +653,8 @@ class gl:
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
self.save(file)
|
||||
|
||||
print time,
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
i += 1
|
||||
n += 1
|
||||
@ -691,7 +693,7 @@ class gl:
|
||||
fraction*(self.scale_stop - self.scale_start)
|
||||
self.viewupright()
|
||||
|
||||
if n == nstart or self.panflag: self.center = compute_center(box)
|
||||
if n == nstart or self.panflag: self.center = compute_center(box)
|
||||
|
||||
if bonds: self.bonds_augment(bonds)
|
||||
|
||||
@ -707,11 +709,11 @@ class gl:
|
||||
self.w.tkRedraw()
|
||||
self.save(file)
|
||||
|
||||
print n,
|
||||
print(n, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
print "\n%d images" % ncount
|
||||
print("\n%d images" % ncount)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
@ -729,19 +731,19 @@ class gl:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# draw the GL scene
|
||||
|
||||
|
||||
def redraw(self,o):
|
||||
# clear window to background color
|
||||
|
||||
|
||||
glClearColor(self.bgcol[0],self.bgcol[1],self.bgcol[2],0)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
|
||||
# not ready if no scene yet
|
||||
|
||||
|
||||
if not self.ready: return
|
||||
|
||||
# set view from eye, distance, 3 lookat vectors (from,to,up)
|
||||
|
||||
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
glLoadIdentity()
|
||||
if self.orthoflag:
|
||||
@ -757,14 +759,14 @@ class gl:
|
||||
|
||||
# draw scene from display list if caching allowed and list hasn't changed
|
||||
# else redraw and store as new display list if caching allowed
|
||||
|
||||
|
||||
if self.cache and self.cachelist > 0: glCallList(self.cachelist);
|
||||
else:
|
||||
if self.cache:
|
||||
if self.cachelist < 0: glDeleteLists(-self.cachelist,1)
|
||||
self.cachelist = glGenLists(1)
|
||||
glNewList(self.cachelist,GL_COMPILE_AND_EXECUTE)
|
||||
|
||||
|
||||
# draw box, clip-box, xyz axes, lines
|
||||
|
||||
glDisable(GL_LIGHTING)
|
||||
@ -777,11 +779,11 @@ class gl:
|
||||
ncolor = self.vizinfo.nlcolor
|
||||
for line in self.linedraw:
|
||||
itype = int(line[1])
|
||||
if itype > ncolor: raise StandardError,"line type too big"
|
||||
if itype > ncolor: raise Exception("line type too big")
|
||||
red,green,blue = self.vizinfo.lcolor[itype]
|
||||
glColor3f(red,green,blue)
|
||||
thick = self.vizinfo.lrad[itype]
|
||||
glLineWidth(thick)
|
||||
glLineWidth(thick)
|
||||
glBegin(GL_LINES)
|
||||
glVertex3f(line[2],line[3],line[4])
|
||||
glVertex3f(line[5],line[6],line[7])
|
||||
@ -826,7 +828,7 @@ class gl:
|
||||
for bond in self.bonddraw:
|
||||
if bond[10] > bound: continue
|
||||
itype = int(bond[1])
|
||||
if itype > ncolor: raise StandardError,"bond type too big"
|
||||
if itype > ncolor: raise Exception("bond type too big")
|
||||
red,green,blue = self.vizinfo.bcolor[itype]
|
||||
rad = self.vizinfo.brad[itype]
|
||||
glPushMatrix()
|
||||
@ -840,7 +842,7 @@ class gl:
|
||||
|
||||
if self.tridraw:
|
||||
fillflag = self.vizinfo.tfill[int(self.tridraw[0][1])]
|
||||
|
||||
|
||||
if fillflag != 1:
|
||||
if fillflag:
|
||||
glEnable(GL_POLYGON_OFFSET_FILL)
|
||||
@ -849,7 +851,7 @@ class gl:
|
||||
ncolor = self.vizinfo.ntcolor
|
||||
for tri in self.tridraw:
|
||||
itype = int(tri[1])
|
||||
if itype > ncolor: raise StandardError,"tri type too big"
|
||||
if itype > ncolor: raise Exception("tri type too big")
|
||||
red,green,blue = self.vizinfo.tcolor[itype]
|
||||
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,[red,green,blue,1.0]);
|
||||
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,self.shiny);
|
||||
@ -907,7 +909,7 @@ class gl:
|
||||
ymin >= ylo and ymax <= yhi and zmin >= zlo and zmax <= zhi:
|
||||
if bond[10] > bound: continue
|
||||
itype = int(bond[1])
|
||||
if itype > ncolor: raise StandardError,"bond type too big"
|
||||
if itype > ncolor: raise Exception("bond type too big")
|
||||
red,green,blue = self.vizinfo.bcolor[itype]
|
||||
rad = self.vizinfo.brad[itype]
|
||||
glPushMatrix()
|
||||
@ -919,7 +921,7 @@ class gl:
|
||||
gluCylinder(obj,rad,rad,bond[10],self.nsides,self.nsides)
|
||||
glPopMatrix()
|
||||
|
||||
if self.tridraw:
|
||||
if self.tridraw:
|
||||
fillflag = self.vizinfo.tfill[int(self.tridraw[0][1])]
|
||||
|
||||
if fillflag != 1:
|
||||
@ -939,7 +941,7 @@ class gl:
|
||||
ymin >= ylo and ymax <= yhi and \
|
||||
zmin >= zlo and zmax <= zhi:
|
||||
itype = int(tri[1])
|
||||
if itype > ncolor: raise StandardError,"tri type too big"
|
||||
if itype > ncolor: raise Exception("tri type too big")
|
||||
red,green,blue = self.vizinfo.tcolor[itype]
|
||||
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,
|
||||
[red,green,blue,1.0]);
|
||||
@ -973,7 +975,7 @@ class gl:
|
||||
glEnd()
|
||||
glEnable(GL_LIGHTING)
|
||||
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL)
|
||||
|
||||
|
||||
if self.cache: glEndList()
|
||||
|
||||
glFlush()
|
||||
@ -981,17 +983,17 @@ class gl:
|
||||
# --------------------------------------------------------------------
|
||||
# make new call list for each atom type
|
||||
# called when atom color/rad/quality is changed
|
||||
|
||||
|
||||
def make_atom_calllist(self):
|
||||
# extend calllist array if necessary
|
||||
|
||||
|
||||
if self.vizinfo.nacolor > self.nclist:
|
||||
for i in range(self.vizinfo.nacolor-self.nclist): self.calllist.append(0)
|
||||
self.nclist = self.vizinfo.nacolor
|
||||
|
||||
# create new calllist for each atom type
|
||||
|
||||
for itype in xrange(1,self.vizinfo.nacolor+1):
|
||||
|
||||
for itype in range(1,self.vizinfo.nacolor+1):
|
||||
if self.calllist[itype]: glDeleteLists(self.calllist[itype],1)
|
||||
ilist = glGenLists(1)
|
||||
self.calllist[itype] = ilist
|
||||
@ -999,12 +1001,12 @@ class gl:
|
||||
red,green,blue = self.vizinfo.acolor[itype]
|
||||
rad = self.vizinfo.arad[itype]
|
||||
glColor3f(red,green,blue);
|
||||
|
||||
|
||||
# glPointSize(10.0*rad)
|
||||
# glBegin(GL_POINTS)
|
||||
# glVertex3f(0.0,0.0,0.0)
|
||||
# glEnd()
|
||||
|
||||
|
||||
glMaterialfv(GL_FRONT,GL_EMISSION,[red,green,blue,1.0]);
|
||||
glMaterialf(GL_FRONT,GL_SHININESS,self.shiny);
|
||||
glutSolidSphere(rad,self.nslices,self.nstacks)
|
||||
@ -1013,7 +1015,7 @@ class gl:
|
||||
# --------------------------------------------------------------------
|
||||
# augment bond info returned by viz() with info needed for GL draw
|
||||
# info = length, theta, -dy, dx for bond orientation
|
||||
|
||||
|
||||
def bonds_augment(self,bonds):
|
||||
for bond in bonds:
|
||||
dx = bond[5] - bond[2]
|
||||
@ -1044,7 +1046,7 @@ class gl:
|
||||
|
||||
glLineWidth(self.bxthick)
|
||||
glColor3f(self.bxcol[0],self.bxcol[1],self.bxcol[2])
|
||||
|
||||
|
||||
glBegin(GL_LINE_LOOP)
|
||||
glVertex3f(xlo,ylo,zlo)
|
||||
glVertex3f(xhi,ylo,zlo)
|
||||
@ -1079,7 +1081,7 @@ class gl:
|
||||
if yhi-ylo > delta: delta = yhi-ylo
|
||||
if zhi-zlo > delta: delta = zhi-zlo
|
||||
delta *= 0.1
|
||||
|
||||
|
||||
glLineWidth(self.bxthick)
|
||||
|
||||
glBegin(GL_LINES)
|
||||
@ -1098,45 +1100,49 @@ class gl:
|
||||
|
||||
def save(self,file=None):
|
||||
self.w.update() # force image on screen to be current before saving it
|
||||
|
||||
|
||||
pstring = glReadPixels(0,0,self.xpixels,self.ypixels,
|
||||
GL_RGBA,GL_UNSIGNED_BYTE)
|
||||
snapshot = Image.fromstring("RGBA",(self.xpixels,self.ypixels),pstring)
|
||||
#snapshot = Image.fromstring("RGBA",(self.xpixels,self.ypixels),pstring)
|
||||
snapshot = Image.frombytes("RGBA",(self.xpixels,self.ypixels),pstring)
|
||||
snapshot = snapshot.transpose(Image.FLIP_TOP_BOTTOM)
|
||||
|
||||
if not file: file = self.file
|
||||
snapshot.save(file + ".png")
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
def adef(self):
|
||||
self.vizinfo.setcolors("atom",range(100),"loop")
|
||||
self.vizinfo.setradii("atom",range(100),0.45)
|
||||
rlist = list(range(100))
|
||||
#self.vizinfo.setcolors("atom",list(range(100)),"loop")
|
||||
#self.vizinfo.setradii("atom",list(range(100)),0.45)
|
||||
self.vizinfo.setcolors("atom",rlist,"loop")
|
||||
self.vizinfo.setradii("atom",rlist,0.45)
|
||||
self.make_atom_calllist()
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def bdef(self):
|
||||
self.vizinfo.setcolors("bond",range(100),"loop")
|
||||
self.vizinfo.setradii("bond",range(100),0.25)
|
||||
self.vizinfo.setcolors("bond",list(range(100)),"loop")
|
||||
self.vizinfo.setradii("bond",list(range(100)),0.25)
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def tdef(self):
|
||||
self.vizinfo.setcolors("tri",range(100),"loop")
|
||||
self.vizinfo.setfills("tri",range(100),0)
|
||||
self.vizinfo.setcolors("tri",list(range(100)),"loop")
|
||||
self.vizinfo.setfills("tri",list(range(100)),0)
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def ldef(self):
|
||||
self.vizinfo.setcolors("line",range(100),"loop")
|
||||
self.vizinfo.setradii("line",range(100),0.25)
|
||||
self.vizinfo.setcolors("line",list(range(100)),"loop")
|
||||
self.vizinfo.setradii("line",list(range(100)),0.25)
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
|
||||
@ -1147,29 +1153,29 @@ class gl:
|
||||
self.make_atom_calllist()
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def arad(self,atypes,radii):
|
||||
self.vizinfo.setradii("atom",atypes,radii)
|
||||
self.vizinfo.setradii("atom",atypes,radii)
|
||||
self.make_atom_calllist()
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def bcol(self,btypes,colors):
|
||||
self.vizinfo.setcolors("bond",btypes,colors)
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def brad(self,btypes,radii):
|
||||
self.vizinfo.setradii("bond",btypes,radii)
|
||||
self.cachelist = -self.cachelist
|
||||
self.w.tkRedraw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def tcol(self,ttypes,colors):
|
||||
@ -1208,10 +1214,10 @@ class MyOpengl(Opengl):
|
||||
args = (self,master,cnf)
|
||||
Opengl.__init__(*args,**kw)
|
||||
Opengl.autospin_allowed = 0
|
||||
|
||||
|
||||
# redraw Opengl scene
|
||||
# call parent redraw() method
|
||||
|
||||
|
||||
def tkRedraw(self,*dummy):
|
||||
if not self.initialised: return
|
||||
self.tk.call(self._w,'makecurrent')
|
||||
@ -1220,7 +1226,7 @@ class MyOpengl(Opengl):
|
||||
|
||||
# left button translate
|
||||
# access parent xshift/yshift and call parent trans() method
|
||||
|
||||
|
||||
def tkTranslate(self,event):
|
||||
dx = event.x - self.xmouse
|
||||
dy = event.y - self.ymouse
|
||||
@ -1240,7 +1246,7 @@ class MyOpengl(Opengl):
|
||||
|
||||
# right button zoom
|
||||
# access parent scale and call parent zoom() method
|
||||
|
||||
|
||||
def tkScale(self,event):
|
||||
scale = 1 - 0.01 * (event.y - self.ymouse)
|
||||
if scale < 0.001: scale = 0.001
|
||||
|
||||
97
src/gnu.py
97
src/gnu.py
@ -3,20 +3,25 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# gnu tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, division, absolute_import
|
||||
import types, os
|
||||
|
||||
oneline = "Create plots via GnuPlot plotting program"
|
||||
|
||||
docstr = """
|
||||
g = gnu() start up GnuPlot
|
||||
g.stop() shut down GnuPlot process
|
||||
|
||||
g = gnu() start up GnuPlot
|
||||
g.stop() shut down GnuPlot process
|
||||
|
||||
g.plot(a) plot vector A against linear index
|
||||
g.plot(a,b) plot B against A
|
||||
g.plot(a,b,c,d,...) plot B against A, D against C, etc
|
||||
g.plot(a,b) plot B against A
|
||||
g.plot(a,b,c,d,...) plot B against A, D against C, etc
|
||||
g.mplot(M,N,S,"file",a,b,...) multiple plots saved to file0000.eps, etc
|
||||
|
||||
each plot argument can be a tuple, list, or Numeric/NumPy vector
|
||||
@ -29,21 +34,21 @@ g.mplot(M,N,S,"file",a,b,...) multiple plots saved to file0000.eps, etc
|
||||
|
||||
g("plot 'file.dat' using 2:3 with lines") execute string in GnuPlot
|
||||
|
||||
g.enter() enter GnuPlot shell
|
||||
g.enter() enter GnuPlot shell
|
||||
gnuplot> plot sin(x) with lines type commands directly to GnuPlot
|
||||
gnuplot> exit, quit exit GnuPlot shell
|
||||
|
||||
gnuplot> exit, quit exit GnuPlot shell
|
||||
|
||||
g.export("data",range(100),a,...) create file with columns of numbers
|
||||
|
||||
all vectors must be of equal length
|
||||
could plot from file with GnuPlot command: plot 'data' using 1:2 with lines
|
||||
|
||||
g.select(N) figure N becomes the current plot
|
||||
|
||||
g.select(N) figure N becomes the current plot
|
||||
|
||||
subsequent commands apply to this plot
|
||||
|
||||
g.hide(N) delete window for figure N
|
||||
g.save("file") save current plot as file.eps
|
||||
g.hide(N) delete window for figure N
|
||||
g.save("file") save current plot as file.eps
|
||||
|
||||
Set attributes for current plot:
|
||||
|
||||
@ -82,10 +87,6 @@ g.curve(N,'r') set color of curve N
|
||||
# figures = list of figure objects with each plot's attributes
|
||||
# so they aren't lost between replots
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import types, os
|
||||
|
||||
try: from DEFAULTS import PIZZA_GNUPLOT
|
||||
except: PIZZA_GNUPLOT = "gnuplot"
|
||||
try: from DEFAULTS import PIZZA_GNUTERM
|
||||
@ -94,7 +95,7 @@ except: PIZZA_GNUTERM = "x11"
|
||||
# Class definition
|
||||
|
||||
class gnu:
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self):
|
||||
@ -102,7 +103,7 @@ class gnu:
|
||||
self.file = "tmp.gnu"
|
||||
self.figures = []
|
||||
self.select(1)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def stop(self):
|
||||
@ -114,12 +115,12 @@ class gnu:
|
||||
def __call__(self,command):
|
||||
self.GNUPLOT.write(command + '\n')
|
||||
self.GNUPLOT.flush()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def enter(self):
|
||||
while 1:
|
||||
command = raw_input("gnuplot> ")
|
||||
command = input("gnuplot> ")
|
||||
if command == "quit" or command == "exit": return
|
||||
self.__call__(command)
|
||||
|
||||
@ -129,15 +130,15 @@ class gnu:
|
||||
def plot(self,*vectors):
|
||||
if len(vectors) == 1:
|
||||
file = self.file + ".%d.1" % self.current
|
||||
linear = range(len(vectors[0]))
|
||||
linear = list(range(len(vectors[0])))
|
||||
self.export(file,linear,vectors[0])
|
||||
self.figures[self.current-1].ncurves = 1
|
||||
else:
|
||||
if len(vectors) % 2: raise StandardError,"vectors must come in pairs"
|
||||
if len(vectors) % 2: raise Exception("vectors must come in pairs")
|
||||
for i in range(0,len(vectors),2):
|
||||
file = self.file + ".%d.%d" % (self.current,i/2+1)
|
||||
file = self.file + ".%d.%d" % (self.current,i//2+1)
|
||||
self.export(file,vectors[i],vectors[i+1])
|
||||
self.figures[self.current-1].ncurves = len(vectors)/2
|
||||
self.figures[self.current-1].ncurves = len(vectors)//2
|
||||
self.draw()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -152,7 +153,7 @@ class gnu:
|
||||
if i: partial_vecs.append(vec[:i])
|
||||
else: partial_vecs.append([0])
|
||||
self.plot(*partial_vecs)
|
||||
|
||||
|
||||
if n < 10: newfile = file + "000" + str(n)
|
||||
elif n < 100: newfile = file + "00" + str(n)
|
||||
elif n < 1000: newfile = file + "0" + str(n)
|
||||
@ -160,20 +161,20 @@ class gnu:
|
||||
|
||||
self.save(newfile)
|
||||
n += 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write list of equal-length vectors to filename
|
||||
|
||||
def export(self,filename,*vectors):
|
||||
n = len(vectors[0])
|
||||
for vector in vectors:
|
||||
if len(vector) != n: raise StandardError,"vectors must be same length"
|
||||
if len(vector) != n: raise Exception("vectors must be same length")
|
||||
f = open(filename,'w')
|
||||
nvec = len(vectors)
|
||||
for i in xrange(n):
|
||||
for j in xrange(nvec):
|
||||
print >>f,vectors[j][i],
|
||||
print >>f
|
||||
for i in range(n):
|
||||
for j in range(nvec):
|
||||
print(vectors[j][i], end=' ', file=f)
|
||||
print(file=f)
|
||||
f.close()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -201,7 +202,7 @@ class gnu:
|
||||
# do not continue until plot file is written out
|
||||
# else script could go forward and change data file
|
||||
# use tmp.done as semaphore to indicate plot is finished
|
||||
|
||||
|
||||
def save(self,file):
|
||||
self.__call__("set terminal postscript enhanced solid lw 2 color portrait")
|
||||
cmd = "set output '%s.eps'" % file
|
||||
@ -212,7 +213,7 @@ class gnu:
|
||||
while not os.path.exists("tmp.done"): continue
|
||||
self.__call__("set output")
|
||||
self.select(self.current)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# restore default attributes by creating a new fig object
|
||||
|
||||
@ -221,7 +222,7 @@ class gnu:
|
||||
fig.ncurves = self.figures[self.current-1].ncurves
|
||||
self.figures[self.current-1] = fig
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def aspect(self,value):
|
||||
@ -245,12 +246,12 @@ class gnu:
|
||||
else:
|
||||
self.figures[self.current-1].ylimit = (values[0],values[1])
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def label(self,x,y,text):
|
||||
self.figures[self.current-1].labels.append((x,y,text))
|
||||
self.figures[self.current-1].nlabels += 1
|
||||
self.figures[self.current-1].nlabels += 1
|
||||
self.draw()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -259,7 +260,7 @@ class gnu:
|
||||
self.figures[self.current-1].nlabel = 0
|
||||
self.figures[self.current-1].labels = []
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def title(self,*strings):
|
||||
@ -276,13 +277,13 @@ class gnu:
|
||||
def xtitle(self,label):
|
||||
self.figures[self.current-1].xtitle = label
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def ytitle(self,label):
|
||||
self.figures[self.current-1].ytitle = label
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def xlog(self):
|
||||
@ -291,7 +292,7 @@ class gnu:
|
||||
else:
|
||||
self.figures[self.current-1].xlog = 1
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def ylog(self):
|
||||
@ -300,7 +301,7 @@ class gnu:
|
||||
else:
|
||||
self.figures[self.current-1].ylog = 1
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def curve(self,num,color):
|
||||
@ -316,10 +317,10 @@ class gnu:
|
||||
def draw(self):
|
||||
fig = self.figures[self.current-1]
|
||||
if not fig.ncurves: return
|
||||
|
||||
|
||||
cmd = 'set size ratio ' + str(1.0/float(fig.aspect))
|
||||
self.__call__(cmd)
|
||||
|
||||
|
||||
cmd = 'set title ' + '"' + fig.title + '"'
|
||||
self.__call__(cmd)
|
||||
cmd = 'set xlabel ' + '"' + fig.xtitle + '"'
|
||||
@ -331,11 +332,11 @@ class gnu:
|
||||
else: self.__call__("unset logscale x")
|
||||
if fig.ylog: self.__call__("set logscale y")
|
||||
else: self.__call__("unset logscale y")
|
||||
if fig.xlimit:
|
||||
if fig.xlimit:
|
||||
cmd = 'set xr [' + str(fig.xlimit[0]) + ':' + str(fig.xlimit[1]) + ']'
|
||||
self.__call__(cmd)
|
||||
else: self.__call__("set xr [*:*]")
|
||||
if fig.ylimit:
|
||||
if fig.ylimit:
|
||||
cmd = 'set yr [' + str(fig.ylimit[0]) + ':' + str(fig.ylimit[1]) + ']'
|
||||
self.__call__(cmd)
|
||||
else: self.__call__("set yr [*:*]")
|
||||
@ -353,7 +354,7 @@ class gnu:
|
||||
for i in range(fig.ncurves):
|
||||
file = self.file + ".%d.%d" % (self.current,i+1)
|
||||
if len(fig.colors) > i and fig.colors[i]:
|
||||
cmd += "'" + file + "' using 1:2 with line %d, " % fig.colors[i]
|
||||
cmd += "'" + file + "' using 1:2 with lines lc %d, " % fig.colors[i]
|
||||
else:
|
||||
cmd += "'" + file + "' using 1:2 with lines, "
|
||||
self.__call__(cmd[:-2])
|
||||
@ -365,7 +366,7 @@ class figure:
|
||||
|
||||
def __init__(self):
|
||||
self.ncurves = 0
|
||||
self.colors = []
|
||||
self.colors = []
|
||||
self.title = ""
|
||||
self.xtitle = ""
|
||||
self.ytitle = ""
|
||||
|
||||
22
src/histo.py
22
src/histo.py
@ -3,7 +3,7 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# histo tool
|
||||
@ -36,17 +36,17 @@ class histo:
|
||||
|
||||
def __init__(self,data):
|
||||
self.data = data
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def compute(self,dim,nbins,lo=None,hi=None):
|
||||
if dim == 'x': idim = 2
|
||||
elif dim == 'y': idim = 3
|
||||
elif dim == 'z': idim = 4
|
||||
else: raise StandardError,"illegal dim value"
|
||||
else: raise Exception("illegal dim value")
|
||||
|
||||
y = nbins*[0]
|
||||
|
||||
|
||||
count = 0
|
||||
n = flag = 0
|
||||
while 1:
|
||||
@ -67,20 +67,20 @@ class histo:
|
||||
|
||||
delta = (hi-lo) / nbins;
|
||||
invdelta = 1.0/delta
|
||||
|
||||
|
||||
for atom in atoms:
|
||||
coord = atom[idim]
|
||||
ibin = int((coord-lo) * invdelta)
|
||||
if ibin < 0 or ibin >= nbins: continue
|
||||
y[ibin] += 1
|
||||
count += 1
|
||||
|
||||
|
||||
n += 1
|
||||
|
||||
x = nbins*[0]
|
||||
for i in xrange(nbins): x[i] = (i+0.5)*delta
|
||||
|
||||
print "histogram snapshots = ",n
|
||||
print "histogram counts (per snap) = %d (%g)" % (count,float(count)/n)
|
||||
print "histogram bounds = ",lo,hi
|
||||
for i in range(nbins): x[i] = (i+0.5)*delta
|
||||
|
||||
print("histogram snapshots = ",n)
|
||||
print("histogram counts (per snap) = %d (%g)" % (count,float(count)/n))
|
||||
print("histogram bounds = ",lo,hi)
|
||||
return x,y
|
||||
|
||||
96
src/image.py
96
src/image.py
@ -3,24 +3,40 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# image tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, os, re, glob
|
||||
try:
|
||||
import commands
|
||||
except ImportError:
|
||||
import subprocess as commands
|
||||
from math import *
|
||||
try:
|
||||
from Tkinter import *
|
||||
except ImportError:
|
||||
from tkinter import *
|
||||
import Pmw
|
||||
from PIL import Image
|
||||
|
||||
oneline = "View and manipulate images"
|
||||
|
||||
docstr = """
|
||||
i = image("my1.gif my2.gif") display thumbnails of matching images
|
||||
i = image("*.png *.gif") wildcards allowed
|
||||
i = image("") blank string matches all image suffixes
|
||||
i = image() no display window opened if no arg
|
||||
i = image("") blank string matches all image suffixes
|
||||
i = image() no display window opened if no arg
|
||||
|
||||
image suffixes for blank string = *.png, *.bmp, *.gif, *.tiff, *.tif
|
||||
click on a thumbnail to view it full-size
|
||||
click on thumbnail again to remove full-sized version
|
||||
|
||||
i.view("*.png *.gif") display thumbnails of matching images
|
||||
i.view("*.png *.gif") display thumbnails of matching images
|
||||
|
||||
view arg is same as constructor arg
|
||||
|
||||
@ -46,14 +62,6 @@ i.montage("-geometry 512x512","i*.png","new.png") 1st arg is switch
|
||||
|
||||
# Variables
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, os, commands, re, glob
|
||||
from math import *
|
||||
from Tkinter import *
|
||||
import Pmw
|
||||
import Image,ImageTk
|
||||
|
||||
try: from DEFAULTS import PIZZA_CONVERT
|
||||
except: PIZZA_CONVERT = "convert"
|
||||
try: from DEFAULTS import PIZZA_MONTAGE
|
||||
@ -62,7 +70,7 @@ except: PIZZA_MONTAGE = "montage"
|
||||
# Class definition
|
||||
|
||||
class image:
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self,filestr=None):
|
||||
@ -77,60 +85,60 @@ class image:
|
||||
list = str.split(filestr)
|
||||
files = []
|
||||
for file in list: files += glob.glob(file)
|
||||
if len(files) == 0: raise StandardError, "no image files to load"
|
||||
if len(files) == 0: raise Exception("no image files to load")
|
||||
|
||||
# grab Tk instance from main
|
||||
|
||||
from __main__ import tkroot
|
||||
|
||||
# GUI control window
|
||||
|
||||
|
||||
gui = Toplevel(tkroot)
|
||||
gui.title('Pizza.py image tool')
|
||||
|
||||
|
||||
scroll = \
|
||||
Pmw.ScrolledFrame(gui,usehullsize=1,hull_width=420,hull_height=500)
|
||||
pane = scroll.interior()
|
||||
|
||||
|
||||
ncolumns = 4
|
||||
for i in xrange(len(files)):
|
||||
|
||||
for i in range(len(files)):
|
||||
|
||||
# create new row frame if 1st in column
|
||||
|
||||
|
||||
if i % ncolumns == 0: rowframe = Frame(pane)
|
||||
oneframe = Frame(rowframe)
|
||||
|
||||
|
||||
# create a thumbnail of image
|
||||
|
||||
|
||||
im = Image.open(files[i])
|
||||
imt = im.copy()
|
||||
imt.thumbnail((60,60),Image.ANTIALIAS)
|
||||
basename = os.path.basename(files[i])
|
||||
imt.save("tmp." + basename)
|
||||
thumbnail = ImageTk.PhotoImage(file = "tmp." + basename)
|
||||
thumbnail = PhotoImage(file = "tmp." + basename)
|
||||
os.remove("tmp." + basename)
|
||||
|
||||
|
||||
# read in full size image
|
||||
# create a thumbnail object that links to it
|
||||
# create button that calls the thumbnail, label with filename
|
||||
# buttton needs to store thumbnail else it is garbage collected
|
||||
|
||||
big = ImageTk.PhotoImage(file=files[i])
|
||||
big = PhotoImage(file=files[i])
|
||||
obj = thumbnails(gui,files[i],big,thumbnail)
|
||||
Button(oneframe,image=thumbnail,command=obj.display).pack(side=TOP)
|
||||
Label(oneframe,text=basename).pack(side=BOTTOM)
|
||||
|
||||
|
||||
# pack into row frame
|
||||
|
||||
|
||||
oneframe.pack(side=LEFT)
|
||||
if (i+1) % ncolumns == 0: rowframe.pack(side=TOP)
|
||||
|
||||
|
||||
if len(files) % ncolumns != 0: rowframe.pack(side=TOP)
|
||||
scroll.pack(side=LEFT)
|
||||
scroll.pack(side=LEFT)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# wrapper on ImageMagick convert command
|
||||
|
||||
|
||||
def convert(self,file1,file2,switch=""):
|
||||
if file1.find('*') < 0 or file2.find('*') < 0:
|
||||
cmd = "%s %s %s %s" % (PIZZA_CONVERT,switch,file1,file2)
|
||||
@ -150,17 +158,17 @@ class image:
|
||||
middle = re.search(expr,file1).group(1)
|
||||
file2 = "%s%s%s" % (pre2,middle,post2)
|
||||
cmd = "%s %s %s %s" % (PIZZA_CONVERT,switch,file1,file2)
|
||||
print middle,
|
||||
print(middle, end=' ')
|
||||
sys.stdout.flush()
|
||||
commands.getoutput(cmd)
|
||||
print
|
||||
print()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# wrapper on ImageMagick montage command
|
||||
|
||||
def montage(self,switch,*fileargs):
|
||||
nsets = len(fileargs)
|
||||
if nsets < 2: raise StandardError,"montage requires 2 or more file args"
|
||||
if nsets < 2: raise Exception("montage requires 2 or more file args")
|
||||
|
||||
for i in range(nsets):
|
||||
if fileargs[i].find('*') < 0:
|
||||
@ -168,13 +176,13 @@ class image:
|
||||
for j in range(nsets): cmd += " %s" % fileargs[j]
|
||||
commands.getoutput(cmd)
|
||||
return
|
||||
|
||||
|
||||
nfiles = len(glob.glob(fileargs[0]))
|
||||
filesets = []
|
||||
for i in range(nsets-1):
|
||||
filesets.append(glob.glob(fileargs[i]))
|
||||
if len(filesets[-1]) != nfiles:
|
||||
raise StandardError,"each montage arg must represent equal # of files"
|
||||
raise Exception("each montage arg must represent equal # of files")
|
||||
|
||||
index = fileargs[0].index('*')
|
||||
pre1 = fileargs[0][:index]
|
||||
@ -191,13 +199,13 @@ class image:
|
||||
fileN = "%s%s%s" % (preN,middle,postN)
|
||||
cmd += " %s" % fileN
|
||||
commands.getoutput(cmd)
|
||||
print middle,
|
||||
print(middle, end=' ')
|
||||
sys.stdout.flush()
|
||||
print
|
||||
print()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# thumbnail class
|
||||
|
||||
|
||||
class thumbnails:
|
||||
|
||||
def __init__(self,root,name,bigimage,thumbimage):
|
||||
@ -207,19 +215,19 @@ class thumbnails:
|
||||
self.name = name
|
||||
self.bigexist = 0
|
||||
self.window = None
|
||||
|
||||
|
||||
def display(self):
|
||||
|
||||
# destroy the big image window
|
||||
|
||||
|
||||
if self.bigexist:
|
||||
self.bigexist = 0
|
||||
if self.window:
|
||||
self.window.destroy()
|
||||
self.window = None
|
||||
|
||||
self.window = None
|
||||
|
||||
# create a new window with the big image
|
||||
|
||||
|
||||
else:
|
||||
self.bigexist = 1
|
||||
self.window = Toplevel(self.root)
|
||||
@ -230,4 +238,4 @@ class thumbnails:
|
||||
# list of file extensions to test for
|
||||
# could add any extensions that PIL recognizes
|
||||
|
||||
extensions = ["*.png", "*.bmp", "*.gif", "*.tiff", "*.tif"]
|
||||
extensions = ["*.png", "*.bmp", "*.gif", "*.tiff", "*.tif"]
|
||||
|
||||
72
src/ldump.py
72
src/ldump.py
@ -3,23 +3,30 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# ldump tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, re, glob, types
|
||||
import functools
|
||||
from os import popen
|
||||
|
||||
oneline = "Read dump files with line segment info"
|
||||
|
||||
docstr = """
|
||||
l = ldump("dump.one") read in one or more dump files
|
||||
l = ldump("dump.1 dump.2.gz") can be gzipped
|
||||
l = ldump("dump.*") wildcard expands to multiple files
|
||||
l = ldump("dump.*",0) two args = store filenames, but don't read
|
||||
l = ldump("dump.1 dump.2.gz") can be gzipped
|
||||
l = ldump("dump.*") wildcard expands to multiple files
|
||||
l = ldump("dump.*",0) two args = store filenames, but don't read
|
||||
|
||||
incomplete and duplicate snapshots are deleted
|
||||
no column name assignment is performed
|
||||
|
||||
time = l.next() read next snapshot from dump files
|
||||
time = l.next() read next snapshot from dump files
|
||||
|
||||
used with 2-argument constructor to allow reading snapshots one-at-a-time
|
||||
snapshot will be skipped only if another snapshot has same time stamp
|
||||
@ -43,7 +50,7 @@ time,box,atoms,bonds,tris,lines = l.viz(index) return list of viz objects
|
||||
lines = id,type,x1,y1,z1,x2,y2,z2 for each line as 2d array
|
||||
id,type are from associated atom
|
||||
|
||||
l.owrap(...) wrap lines to same image as their atoms
|
||||
l.owrap(...) wrap lines to same image as their atoms
|
||||
|
||||
owrap() is called by dump tool's owrap()
|
||||
useful for wrapping all molecule's atoms/lines the same so it is contiguous
|
||||
@ -67,11 +74,6 @@ l.owrap(...) wrap lines to same image as their atoms
|
||||
# xlo,xhi,ylo,yhi,zlo,zhi = box bounds (float)
|
||||
# atoms[i][j] = 2d array of floats, i = 0 to natoms-1, j = 0 to ncols-1
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, commands, re, glob, types
|
||||
from os import popen
|
||||
|
||||
try:
|
||||
import numpy as np
|
||||
oldnumeric = False
|
||||
@ -99,8 +101,8 @@ class ldump:
|
||||
self.flist = []
|
||||
for word in words: self.flist += glob.glob(word)
|
||||
if len(self.flist) == 0 and len(list) == 1:
|
||||
raise StandardError,"no ldump file specified"
|
||||
|
||||
raise Exception("no ldump file specified")
|
||||
|
||||
if len(list) == 1:
|
||||
self.increment = 0
|
||||
self.read_all()
|
||||
@ -124,26 +126,26 @@ class ldump:
|
||||
snap = self.read_snapshot(f)
|
||||
while snap:
|
||||
self.snaps.append(snap)
|
||||
print snap.time,
|
||||
print(snap.time, end=' ')
|
||||
sys.stdout.flush()
|
||||
snap = self.read_snapshot(f)
|
||||
|
||||
f.close()
|
||||
print
|
||||
print()
|
||||
|
||||
# sort entries by timestep, cull duplicates
|
||||
|
||||
self.snaps.sort(self.compare_time)
|
||||
self.snaps.sort(key = functools.cmp_to_key(self.compare_time))
|
||||
self.cull()
|
||||
self.nsnaps = len(self.snaps)
|
||||
print "read %d snapshots" % self.nsnaps
|
||||
print("read %d snapshots" % self.nsnaps)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# read next snapshot from list of files
|
||||
|
||||
def next(self):
|
||||
|
||||
if not self.increment: raise StandardError,"cannot read incrementally"
|
||||
if not self.increment: raise Exception("cannot read incrementally")
|
||||
|
||||
# read next snapshot in current file using eof as pointer
|
||||
# if fail, try next file
|
||||
@ -155,15 +157,15 @@ class ldump:
|
||||
snap = self.read_snapshot(f)
|
||||
if not snap:
|
||||
self.nextfile += 1
|
||||
if self.nextfile == len(self.flist): return -1
|
||||
if self.nextfile == len(self.flist): return -1
|
||||
f.close()
|
||||
self.eof = 0
|
||||
continue
|
||||
self.eof = 0
|
||||
continue
|
||||
self.eof = f.tell()
|
||||
f.close()
|
||||
try:
|
||||
self.findtime(snap.time)
|
||||
continue
|
||||
continue
|
||||
except: break
|
||||
|
||||
self.snaps.append(snap)
|
||||
@ -175,7 +177,7 @@ class ldump:
|
||||
# --------------------------------------------------------------------
|
||||
# read a single snapshot from file f
|
||||
# return snapshot or 0 if failed
|
||||
|
||||
|
||||
def read_snapshot(self,f):
|
||||
try:
|
||||
snap = Snap()
|
||||
@ -197,14 +199,14 @@ class ldump:
|
||||
if snap.natoms:
|
||||
words = f.readline().split()
|
||||
ncol = len(words)
|
||||
for i in xrange(1,snap.natoms):
|
||||
for i in range(1,snap.natoms):
|
||||
words += f.readline().split()
|
||||
floats = map(float,words)
|
||||
floats = list(map(float,words))
|
||||
if oldnumeric: atoms = np.zeros((snap.natoms,ncol),np.Float)
|
||||
else: atoms = np.zeros((snap.natoms,ncol),np.float)
|
||||
start = 0
|
||||
stop = ncol
|
||||
for i in xrange(snap.natoms):
|
||||
for i in range(snap.natoms):
|
||||
atoms[i] = floats[start:stop]
|
||||
start = stop
|
||||
stop += ncol
|
||||
@ -216,10 +218,10 @@ class ldump:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# map atom column names
|
||||
|
||||
|
||||
def map(self,*pairs):
|
||||
if len(pairs) % 2 != 0:
|
||||
raise StandardError, "ldump map() requires pairs of mappings"
|
||||
raise Exception("ldump map() requires pairs of mappings")
|
||||
for i in range(0,len(pairs),2):
|
||||
j = i + 1
|
||||
self.names[pairs[j]] = pairs[i]-1
|
||||
@ -249,9 +251,9 @@ class ldump:
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def findtime(self,n):
|
||||
for i in xrange(self.nsnaps):
|
||||
for i in range(self.nsnaps):
|
||||
if self.snaps[i].time == n: return i
|
||||
raise StandardError, "no step %d exists" % n
|
||||
raise Exception("no step %d exists" % n)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# delete successive snapshots with duplicate time stamp
|
||||
@ -263,7 +265,7 @@ class ldump:
|
||||
del self.snaps[i]
|
||||
else:
|
||||
i += 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# return list of lines to viz for snapshot isnap
|
||||
# if called with flag, then index is timestep, so convert to snapshot index
|
||||
@ -291,9 +293,9 @@ class ldump:
|
||||
|
||||
# create line list from id,type,end1x,end1y,end2x,end2y
|
||||
# don't add line if all 4 values are 0 since not a line
|
||||
|
||||
|
||||
lines = []
|
||||
for i in xrange(snap.natoms):
|
||||
for i in range(snap.natoms):
|
||||
atom = snap.atoms[i]
|
||||
e1x = atom[end1x]
|
||||
e1y = atom[end1y]
|
||||
@ -322,8 +324,8 @@ class ldump:
|
||||
# idump = index of my line I in dump's atoms
|
||||
# jdump = atom J in dump's atoms that atom I was owrapped on
|
||||
# delx,dely = offset applied to atom I and thus to line I
|
||||
|
||||
for i in xrange(snap.natoms):
|
||||
|
||||
for i in range(snap.natoms):
|
||||
tag = atoms[i][id]
|
||||
idump = idsdump[tag]
|
||||
jdump = idsdump[atomsdump[idump][iother]]
|
||||
|
||||
110
src/log.py
110
src/log.py
@ -3,11 +3,18 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# log tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, re, glob
|
||||
import functools
|
||||
from os import popen
|
||||
|
||||
oneline = "Read LAMMPS log files and extract thermodynamic data"
|
||||
|
||||
docstr = """
|
||||
@ -28,7 +35,7 @@ nvec = l.nvec # of vectors of thermo info
|
||||
nlen = l.nlen length of each vectors
|
||||
names = l.names list of vector names
|
||||
t,pe,... = l.get("Time","KE",...) return one or more vectors of values
|
||||
l.write("file.txt") write all vectors to a file
|
||||
l.write("file.txt") write all vectors to a file
|
||||
l.write("file.txt","Time","PE",...) write listed vectors to a file
|
||||
|
||||
get and write allow abbreviated (uniquely) vector names
|
||||
@ -50,11 +57,6 @@ l.write("file.txt","Time","PE",...) write listed vectors to a file
|
||||
# increment = 1 if log file being read incrementally
|
||||
# eof = ptr into incremental file for where to start next read
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, re, glob
|
||||
from os import popen
|
||||
|
||||
try: tmp = PIZZA_GUNZIP
|
||||
except: PIZZA_GUNZIP = "gunzip"
|
||||
|
||||
@ -76,40 +78,40 @@ class log:
|
||||
self.flist = []
|
||||
for word in words: self.flist += glob.glob(word)
|
||||
if len(self.flist) == 0 and len(list) == 1:
|
||||
raise StandardError,"no log file specified"
|
||||
raise Exception("no log file specified")
|
||||
|
||||
if len(list) == 1:
|
||||
self.increment = 0
|
||||
self.read_all()
|
||||
else:
|
||||
if len(self.flist) > 1:
|
||||
raise StandardError,"can only incrementally read one log file"
|
||||
raise Exception("can only incrementally read one log file")
|
||||
self.increment = 1
|
||||
self.eof = 0
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# read all thermo from all files
|
||||
|
||||
|
||||
def read_all(self):
|
||||
self.read_header(self.flist[0])
|
||||
if self.nvec == 0: raise StandardError,"log file has no values"
|
||||
if self.nvec == 0: raise Exception("log file has no values")
|
||||
|
||||
# read all files
|
||||
|
||||
for file in self.flist: self.read_one(file)
|
||||
print
|
||||
print()
|
||||
|
||||
# sort entries by timestep, cull duplicates
|
||||
|
||||
self.data.sort(self.compare)
|
||||
|
||||
self.data.sort(key = functools.cmp_to_key(self.compare))
|
||||
self.cull()
|
||||
self.nlen = len(self.data)
|
||||
print "read %d log entries" % self.nlen
|
||||
print("read %d log entries" % self.nlen)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def next(self):
|
||||
if not self.increment: raise StandardError,"cannot read incrementally"
|
||||
if not self.increment: raise Exception("cannot read incrementally")
|
||||
|
||||
if self.nvec == 0:
|
||||
try: open(self.flist[0],'r')
|
||||
@ -124,27 +126,27 @@ class log:
|
||||
|
||||
def get(self,*keys):
|
||||
if len(keys) == 0:
|
||||
raise StandardError, "no log vectors specified"
|
||||
raise Exception("no log vectors specified")
|
||||
|
||||
map = []
|
||||
for key in keys:
|
||||
if self.ptr.has_key(key):
|
||||
if key in self.ptr:
|
||||
map.append(self.ptr[key])
|
||||
else:
|
||||
count = 0
|
||||
for i in range(self.nvec):
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if count == 1:
|
||||
map.append(index)
|
||||
else:
|
||||
raise StandardError, "unique log vector %s not found" % key
|
||||
raise Exception("unique log vector %s not found" % key)
|
||||
|
||||
vecs = []
|
||||
for i in range(len(keys)):
|
||||
vecs.append(self.nlen * [0])
|
||||
for j in xrange(self.nlen):
|
||||
for j in range(self.nlen):
|
||||
vecs[i][j] = self.data[j][map[i]]
|
||||
|
||||
if len(keys) == 1: return vecs[0]
|
||||
@ -156,26 +158,26 @@ class log:
|
||||
if len(keys):
|
||||
map = []
|
||||
for key in keys:
|
||||
if self.ptr.has_key(key):
|
||||
if key in self.ptr:
|
||||
map.append(self.ptr[key])
|
||||
else:
|
||||
count = 0
|
||||
for i in range(self.nvec):
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if count == 1:
|
||||
map.append(index)
|
||||
else:
|
||||
raise StandardError, "unique log vector %s not found" % key
|
||||
raise Exception("unique log vector %s not found" % key)
|
||||
else:
|
||||
map = range(self.nvec)
|
||||
map = list(range(self.nvec))
|
||||
|
||||
f = open(filename,"w")
|
||||
for i in xrange(self.nlen):
|
||||
for j in xrange(len(map)):
|
||||
print >>f,self.data[i][map[j]],
|
||||
print >>f
|
||||
for i in range(self.nlen):
|
||||
for j in range(len(map)):
|
||||
print(self.data[i][map[j]], end=' ', file=f)
|
||||
print(file=f)
|
||||
f.close()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -224,7 +226,7 @@ class log:
|
||||
keywords.insert(0,"Step")
|
||||
i = 0
|
||||
for keyword in keywords:
|
||||
self.names.append(keyword)
|
||||
self.names.append(keyword)
|
||||
self.ptr[keyword] = i
|
||||
i += 1
|
||||
|
||||
@ -234,25 +236,25 @@ class log:
|
||||
line = txt[s1:s2]
|
||||
words = line.split()
|
||||
for i in range(len(words)):
|
||||
self.names.append(words[i])
|
||||
self.names.append(words[i])
|
||||
self.ptr[words[i]] = i
|
||||
|
||||
self.nvec = len(self.names)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def read_one(self,*list):
|
||||
def read_one(self,*flist):
|
||||
|
||||
# if 2nd arg exists set file ptr to that value
|
||||
# read entire (rest of) file into txt
|
||||
|
||||
file = list[0]
|
||||
file = flist[0]
|
||||
if file[-3:] == ".gz":
|
||||
f = popen("%s -c %s" % (PIZZA_GUNZIP,file),'rb')
|
||||
f = popen("%s -c %s" % (PIZZA_GUNZIP,file),'r')
|
||||
else:
|
||||
f = open(file,'rb')
|
||||
f = open(file,'r')
|
||||
|
||||
if len(list) == 2: f.seek(list[1])
|
||||
if len(flist) == 2: f.seek(flist[1])
|
||||
txt = f.read()
|
||||
if file[-3:] == ".gz": eof = 0
|
||||
else: eof = f.tell()
|
||||
@ -273,43 +275,43 @@ class log:
|
||||
|
||||
if s1 >= 0 and s2 >= 0 and s1 < s2: # found s1,s2 with s1 before s2
|
||||
if self.style == 2:
|
||||
s1 = txt.find("\n",s1) + 1
|
||||
s1 = txt.find("\n",s1) + 1
|
||||
elif s1 >= 0 and s2 >= 0 and s2 < s1: # found s1,s2 with s2 before s1
|
||||
s1 = 0
|
||||
elif s1 == -1 and s2 >= 0: # found s2, but no s1
|
||||
last = 1
|
||||
last = 1
|
||||
s1 = 0
|
||||
elif s1 >= 0 and s2 == -1: # found s1, but no s2
|
||||
last = 1
|
||||
if self.style == 1:
|
||||
s2 = txt.rfind("\n--",s1) + 1
|
||||
else:
|
||||
s1 = txt.find("\n",s1) + 1
|
||||
s1 = txt.find("\n",s1) + 1
|
||||
s2 = txt.rfind("\n",s1) + 1
|
||||
eof -= len(txt) - s2
|
||||
eof -= len(txt) - s2
|
||||
elif s1 == -1 and s2 == -1: # found neither
|
||||
# could be end-of-file section
|
||||
# or entire read was one chunk
|
||||
# or entire read was one chunk
|
||||
|
||||
if txt.find("Loop time of",start) == start: # end of file, so exit
|
||||
eof -= len(txt) - start # reset eof to "Loop"
|
||||
break
|
||||
eof -= len(txt) - start # reset eof to "Loop"
|
||||
break
|
||||
|
||||
last = 1 # entire read is a chunk
|
||||
last = 1 # entire read is a chunk
|
||||
s1 = 0
|
||||
if self.style == 1:
|
||||
s2 = txt.rfind("\n--",s1) + 1
|
||||
else:
|
||||
s2 = txt.rfind("\n",s1) + 1
|
||||
eof -= len(txt) - s2
|
||||
if s1 == s2: break
|
||||
eof -= len(txt) - s2
|
||||
if s1 == s2: break
|
||||
|
||||
chunk = txt[s1:s2-1]
|
||||
start = s2
|
||||
|
||||
# split chunk into entries
|
||||
# parse each entry for numeric fields, append to data
|
||||
|
||||
|
||||
if self.style == 1:
|
||||
sections = chunk.split("\n--")
|
||||
pat1 = re.compile("Step\s*(\S*)\s")
|
||||
@ -318,17 +320,17 @@ class log:
|
||||
word1 = [re.search(pat1,section).group(1)]
|
||||
word2 = re.findall(pat2,section)
|
||||
words = word1 + word2
|
||||
self.data.append(map(float,words))
|
||||
self.data.append(list(map(float,words)))
|
||||
|
||||
else:
|
||||
lines = chunk.split("\n")
|
||||
for line in lines:
|
||||
words = line.split()
|
||||
self.data.append(map(float,words))
|
||||
self.data.append(list(map(float,words)))
|
||||
|
||||
# print last timestep of chunk
|
||||
|
||||
print int(self.data[len(self.data)-1][0]),
|
||||
print(int(self.data[len(self.data)-1][0]), end=' ')
|
||||
sys.stdout.flush()
|
||||
|
||||
return eof
|
||||
|
||||
215
src/lpp.py
215
src/lpp.py
@ -1,33 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import getopt
|
||||
import os
|
||||
import time
|
||||
import sys
|
||||
import multiprocessing
|
||||
import glob
|
||||
import vtk
|
||||
from math import ceil
|
||||
from math import floor
|
||||
from dump import dump
|
||||
oneline = "writing pp-data in vtk format automatically, saving memory"
|
||||
|
||||
docstr = """this is the docstr of LIGGGHTSPostProcessing"""
|
||||
|
||||
from dump import dump
|
||||
from math import floor
|
||||
from math import ceil
|
||||
import vtk
|
||||
import glob
|
||||
import multiprocessing
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
import exceptions
|
||||
# changes py p.s. - include a few command line options
|
||||
import getopt
|
||||
|
||||
|
||||
class lpp:
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# =============================================================================
|
||||
# creates a filelist, seperates it to sublists
|
||||
# creates multiple processes
|
||||
# calls lppWorker for each sublist
|
||||
# lppWorker
|
||||
# calls dump, vtk and manyGran for the given list of files
|
||||
# returns 0
|
||||
#=============================================================================
|
||||
|
||||
# =============================================================================
|
||||
|
||||
def __init__(self, *list, **kwargs):
|
||||
# do argument parsing, raise errors if non-integers were given
|
||||
# this can be changed if one wants less overhead but use more memory:
|
||||
@ -35,44 +36,67 @@ class lpp:
|
||||
self.cpunum = multiprocessing.cpu_count()
|
||||
self.chunksize = 8
|
||||
self.overwrite = True
|
||||
self.Nth = 1
|
||||
self.timesteps = "all"
|
||||
|
||||
if "--chunksize" in kwargs:
|
||||
if "--chunksize" in kwargs:
|
||||
try:
|
||||
if int(kwargs["--chunksize"]) > 0:
|
||||
self.chunksize = int(kwargs["--chunksize"])
|
||||
else: raise ValueError
|
||||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
raise ValueError, "Invalid or no argument given for chunksize"
|
||||
raise ValueError("Invalid or no argument given for chunksize")
|
||||
|
||||
if "--cpunum" in kwargs:
|
||||
if "--Nth" in kwargs:
|
||||
try:
|
||||
if int(kwargs["--Nth"]) > 0 and int(kwargs["--Nth"]) >= self.Nth:
|
||||
self.Nth = int(kwargs["--Nth"])
|
||||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
raise ValueError("Invalid or no argument given for Nth")
|
||||
|
||||
if "--timesteps" in kwargs:
|
||||
try:
|
||||
self.timesteps = kwargs["--timesteps"]
|
||||
except ValueError:
|
||||
raise ValueError("Invalid or no argument given for timesteps")
|
||||
|
||||
if "--cpunum" in kwargs:
|
||||
try:
|
||||
if int(kwargs["--cpunum"]) > 0 and int(kwargs["--cpunum"]) <= self.cpunum:
|
||||
self.cpunum = int(kwargs["--cpunum"])
|
||||
else: raise ValueError
|
||||
else:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
raise ValueError, "Invalid or no argument given for cpunum"
|
||||
raise ValueError("Invalid or no argument given for cpunum")
|
||||
|
||||
# do not overwrite existing files
|
||||
if "--no-overwrite" in kwargs:
|
||||
self.overwrite = False
|
||||
|
||||
|
||||
# suppress output with 'False'
|
||||
if "--debug" in kwargs: self.debugMode = True
|
||||
else: self.debugMode = False
|
||||
|
||||
if "--debug" in kwargs:
|
||||
self.debugMode = True
|
||||
else:
|
||||
self.debugMode = False
|
||||
|
||||
if "--quiet" in kwargs:
|
||||
self.output = False
|
||||
self.debugMode = False
|
||||
else: self.output = True
|
||||
else:
|
||||
self.output = True
|
||||
|
||||
if self.output:
|
||||
print "starting LIGGGHTS memory optimized parallel post processing"
|
||||
print "chunksize:", self.chunksize, "-->",self.chunksize,\
|
||||
"files are processed per chunk. If you run out of memory reduce chunksize."
|
||||
starttime = time.time()
|
||||
print("starting LIGGGHTS memory optimized parallel post processing")
|
||||
print("chunksize:", self.chunksize, "-->",self.chunksize,\
|
||||
"files are processed per chunk. If you run out of memory reduce chunksize.")
|
||||
starttime = time.time()
|
||||
|
||||
if self.debugMode:
|
||||
print("number of process:", os.getpid())
|
||||
|
||||
if self.debugMode: print "number of process:", os.getpid()
|
||||
|
||||
# check whether file-list is nonempty
|
||||
self.flist = []
|
||||
# get file list for windows
|
||||
@ -86,65 +110,72 @@ class lpp:
|
||||
self.flist = list[0]
|
||||
listlen = len(self.flist)
|
||||
if listlen == 0 and len(list) == 1:
|
||||
raise StandardError, "no dump file specified"
|
||||
raise Exception("no dump file specified")
|
||||
if listlen == 1 and self.overwrite == False:
|
||||
raise StandardError, "Cannot process single dump files with --no-overwrite."
|
||||
|
||||
raise Exception("Cannot process single dump files with --no-overwrite.")
|
||||
|
||||
if self.output:
|
||||
print "Working with", self.cpunum, "processes..."
|
||||
|
||||
print("Working with", self.cpunum, "processes...")
|
||||
|
||||
# seperate list in pieces+rest
|
||||
self.slices = []
|
||||
|
||||
|
||||
residualPresent = int(bool(listlen-floor(listlen/self.chunksize)*self.chunksize))
|
||||
|
||||
for i in xrange(int(floor(listlen/self.chunksize))+residualPresent):
|
||||
|
||||
for i in range(int(floor(listlen/self.chunksize))+residualPresent):
|
||||
slice = self.flist[i*self.chunksize:(i+1)*self.chunksize]
|
||||
self.slices.append(slice)
|
||||
self.flist = []
|
||||
|
||||
output = ""
|
||||
if "-o" in kwargs: output = kwargs["-o"]
|
||||
if "-o" in kwargs:
|
||||
output = kwargs["-o"]
|
||||
# generate input for lppWorker
|
||||
dumpInput = [{"filelist":self.slices[i],\
|
||||
"debugMode":self.debugMode,\
|
||||
"output":output,\
|
||||
"overwrite":self.overwrite} \
|
||||
for i in xrange(len(self.slices))]
|
||||
|
||||
if self.debugMode: print "dumpInput:",dumpInput
|
||||
|
||||
"overwrite":self.overwrite,\
|
||||
"timesteps":self.timesteps,\
|
||||
"Nth":self.Nth} \
|
||||
for i in range(len(self.slices))]
|
||||
|
||||
if self.debugMode:
|
||||
print("dumpInput:",dumpInput)
|
||||
|
||||
numberOfRuns = len(dumpInput)
|
||||
i = 0
|
||||
while i < len(dumpInput):
|
||||
|
||||
if self.output:
|
||||
print "calculating chunks",i+1,"-",min(i+self.cpunum,numberOfRuns),"of",numberOfRuns
|
||||
|
||||
if self.debugMode: print "input of this \"map\": ",dumpInput[i:i+self.cpunum]
|
||||
|
||||
if self.output:
|
||||
print("calculating chunks",i+1,"-",min(i+self.cpunum,numberOfRuns),"of",numberOfRuns)
|
||||
|
||||
if self.debugMode:
|
||||
print("input of this \"map\": ",dumpInput[i:i+self.cpunum])
|
||||
|
||||
# create job_server
|
||||
job_server = multiprocessing.Pool(processes = self.cpunum)
|
||||
|
||||
|
||||
# map lppWorker on all inputs via job_server (parallelly)
|
||||
job_server.map_async(lppWorker,dumpInput[i:i+self.cpunum]).get(9999999)
|
||||
|
||||
|
||||
# close jobserver
|
||||
job_server.close()
|
||||
job_server.join()
|
||||
i += self.cpunum
|
||||
|
||||
|
||||
endtime = time.time()
|
||||
if self.output:
|
||||
print "wrote", listlen,"granular snapshots in VTK format"
|
||||
print "time needed:",endtime-starttime,"sec"
|
||||
if self.output:
|
||||
print("wrote", listlen,"granular snapshots in VTK format")
|
||||
print("time needed:",endtime-starttime,"sec")
|
||||
|
||||
def lppWorker(input):
|
||||
flist = input["filelist"]
|
||||
debugMode = input["debugMode"]
|
||||
outfileName = input["output"]
|
||||
overwrite = input["overwrite"]
|
||||
|
||||
Nth = input["Nth"]
|
||||
timesteps = input["timesteps"]
|
||||
|
||||
flistlen = len(flist)
|
||||
# generate name of manyGran
|
||||
splitfname = flist[0].rsplit(".")
|
||||
@ -154,7 +185,7 @@ def lppWorker(input):
|
||||
granName = outfileName + splitfname[len(splitfname)-1]
|
||||
else:
|
||||
granName = outfileName
|
||||
|
||||
|
||||
# if no-overwrite: read timestamp in first line of file
|
||||
# if corresponding dump-file does not already exists: add it to 'shortFlist'
|
||||
# shortFlist ... list of files to finally be processed by dump, and vtk.
|
||||
@ -174,40 +205,60 @@ def lppWorker(input):
|
||||
ff.close()
|
||||
except:
|
||||
continue
|
||||
|
||||
|
||||
# generate filename from time like in vtk,
|
||||
# check if file exists; if yes: do not add to list
|
||||
filename,file_bb,file_walls = vtk.generateFilename(granName,[time],0)
|
||||
if not os.path.isfile(filename):
|
||||
shortFlist.append(f)
|
||||
|
||||
|
||||
# call dump, vtk, manyGran on shortFlist
|
||||
try:
|
||||
d = dump({"filelist":shortFlist, "debugMode":debugMode})
|
||||
|
||||
if timesteps != "all":
|
||||
tsteps = timesteps.split(",")
|
||||
filterstring = ""
|
||||
j = 1
|
||||
for i in tsteps:
|
||||
if j == 1:
|
||||
filterstring = filterstring + "$t == " + str(i)
|
||||
else:
|
||||
filterstring = filterstring + " or $t == " + str(i)
|
||||
j = j + 1
|
||||
d.tselect.test(filterstring)
|
||||
elif Nth != 1:
|
||||
d.tselect.skip(Nth)
|
||||
d.delete()
|
||||
|
||||
v = vtk.vtk(d)
|
||||
if debugMode: print "\nfileNums: ",d.fileNums,"\n"
|
||||
if debugMode:
|
||||
print("\nfileNums: ",d.fileNums,"\n")
|
||||
v.manyGran(granName,fileNos=d.fileNums,output=debugMode)
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
def printHelp():
|
||||
print "usage: pizza [options] dump.example\n where dump.example is a filename",\
|
||||
"or regular expression passing all relevant dump files to pizza."
|
||||
print "Important command line options:"
|
||||
print "-o fname : define output file name (default is liggghts + timestep number)"
|
||||
print "--chunksize : sets the chunksize, default: 8"
|
||||
print "--cpunum : sets the number of processes to start, default (and maximum)",\
|
||||
"is the amout of cpu cores avaliable at your system"
|
||||
print "--help : writes this help message and exits"
|
||||
print "--no-overwrite: disables overwriting of already post-processed files."
|
||||
print "For details, read README_GRANULAR.txt"
|
||||
print("usage: pizza [options] dump.example\n where dump.example is a filename",\
|
||||
"or regular expression passing all relevant dump files to pizza.")
|
||||
print("Important command line options:")
|
||||
print("-o fname : define output file name (default is liggghts + timestep number)")
|
||||
print("--chunksize : sets the chunksize, default: 8")
|
||||
print("--cpunum : sets the number of processes to start, default (and maximum)",\
|
||||
"is the amout of cpu cores avaliable at your system")
|
||||
print("--help : writes this help message and exits")
|
||||
print("--no-overwrite: disables overwriting of already post-processed files.")
|
||||
print("--timesteps: time steps to be converted, input as comma seperated list.")
|
||||
print("--Nth: every Nth time step will be converted, cannot be combined with timesteps.")
|
||||
print("For details, read README_GRANULAR.txt")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
# parse options
|
||||
optlist, args = getopt.gnu_getopt(sys.argv[1:],'o:',['chunksize=','cpunum=','debug','help','quiet','no-overwrite'])
|
||||
optlist, args = getopt.gnu_getopt(sys.argv[1:],'o:',[
|
||||
'chunksize=','cpunum=','Nth=','timesteps=','debug','help','quiet','no-overwrite'])
|
||||
optdict = dict(optlist)
|
||||
if "--help" in optdict:
|
||||
printHelp()
|
||||
@ -215,18 +266,18 @@ if __name__ == "__main__":
|
||||
try:
|
||||
lpp(args,**optdict)
|
||||
except KeyboardInterrupt:
|
||||
print "aborted by user"
|
||||
except BaseException, e:
|
||||
print "aborting due to errors:", e
|
||||
print("aborted by user")
|
||||
except BaseException as e:
|
||||
print("aborting due to errors:", e)
|
||||
|
||||
#===========================================================================
|
||||
# ===========================================================================
|
||||
# except:
|
||||
# if sys.exc_type == exceptions.SystemExit:
|
||||
# pass
|
||||
# else:
|
||||
# print sys.exc_info()
|
||||
#===========================================================================
|
||||
# else:
|
||||
# print(sys.exc_info())
|
||||
# ===========================================================================
|
||||
else:
|
||||
printHelp()
|
||||
|
||||
|
||||
|
||||
|
||||
@ -3,20 +3,25 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# matlab tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, division, absolute_import
|
||||
import types, os
|
||||
|
||||
oneline = "Create plots via MatLab numerical analysis program"
|
||||
|
||||
docstr = """
|
||||
m = matlab() start up MatLab
|
||||
m.stop() shut down MatLab process
|
||||
|
||||
m = matlab() start up MatLab
|
||||
m.stop() shut down MatLab process
|
||||
|
||||
m.plot(a) plot vector A against linear index
|
||||
m.plot(a,b) plot B against A
|
||||
m.plot(a,b,c,d,...) plot B against A, D against C, etc
|
||||
m.plot(a,b) plot B against A
|
||||
m.plot(a,b,c,d,...) plot B against A, D against C, etc
|
||||
m.mplot(M,N,S,"file",a,b,...) multiple plots saved to file0000.eps, etc
|
||||
|
||||
each plot argument can be a tuple, list, or Numeric/NumPy vector
|
||||
@ -29,10 +34,10 @@ m.mplot(M,N,S,"file",a,b,...) multiple plots saved to file0000.eps, etc
|
||||
|
||||
m("c = a + b") execute string in MatLab
|
||||
|
||||
m.enter() enter MatLab shell
|
||||
m.enter() enter MatLab shell
|
||||
matlab> c = a + b type commands directly to MatLab
|
||||
matlab> exit, quit exit MatLab shell
|
||||
|
||||
matlab> exit, quit exit MatLab shell
|
||||
|
||||
m.export("data",range(100),a,...) create file with columns of numbers
|
||||
|
||||
all vectors must be of equal length
|
||||
@ -40,12 +45,12 @@ m.export("data",range(100),a,...) create file with columns of numbers
|
||||
cols = importdata('data')
|
||||
plot(cols(:,1),cols(:,2))
|
||||
|
||||
m.select(N) figure N becomes the current plot
|
||||
|
||||
m.select(N) figure N becomes the current plot
|
||||
|
||||
subsequent commands apply to this plot
|
||||
|
||||
m.hide(N) delete window for figure N
|
||||
m.save("file") save current plot as file.eps
|
||||
m.hide(N) delete window for figure N
|
||||
m.save("file") save current plot as file.eps
|
||||
|
||||
Set attributes for current plot:
|
||||
|
||||
@ -91,17 +96,13 @@ m.curve(N,'b','-','v') set color, line style, symbol of curve N
|
||||
# allow for alternate export command to name the variables from Python
|
||||
# in MatLab and vice versa
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import types, os
|
||||
|
||||
try: from DEFAULTS import PIZZA_MATLAB
|
||||
except: PIZZA_MATLAB = "matlab -nosplash -nodesktop -nojvm"
|
||||
|
||||
# Class definition
|
||||
|
||||
class matlab:
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self):
|
||||
@ -109,7 +110,7 @@ class matlab:
|
||||
self.file = "tmp.matlab"
|
||||
self.figures = []
|
||||
self.select(1)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def stop(self):
|
||||
@ -121,12 +122,12 @@ class matlab:
|
||||
def __call__(self,command):
|
||||
self.MATLAB.write(command + '\n')
|
||||
self.MATLAB.flush()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def enter(self):
|
||||
while 1:
|
||||
command = raw_input("matlab> ")
|
||||
command = input("matlab> ")
|
||||
if command == "quit" or command == "exit": return
|
||||
self.__call__(command)
|
||||
|
||||
@ -136,21 +137,21 @@ class matlab:
|
||||
def plot(self,*vectors):
|
||||
if len(vectors) == 1:
|
||||
file = self.file + ".%d.1" % self.current
|
||||
linear = range(len(vectors[0]))
|
||||
linear = list(range(len(vectors[0])))
|
||||
self.export(file,linear,vectors[0])
|
||||
self.figures[self.current-1].ncurves = 1
|
||||
else:
|
||||
if len(vectors) % 2: raise StandardError,"vectors must come in pairs"
|
||||
if len(vectors) % 2: raise Exception("vectors must come in pairs")
|
||||
for i in range(0,len(vectors),2):
|
||||
file = self.file + ".%d.%d" % (self.current,i/2+1)
|
||||
file = self.file + ".%d.%d" % (self.current,i//2+1)
|
||||
self.export(file,vectors[i],vectors[i+1])
|
||||
self.figures[self.current-1].ncurves = len(vectors)/2
|
||||
self.figures[self.current-1].ncurves = len(vectors)//2
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# create multiple plots from growing vectors, save to numbered files
|
||||
# don't plot empty vector, create a [0] instead
|
||||
|
||||
|
||||
def mplot(self,start,stop,skip,file,*vectors):
|
||||
n = 0
|
||||
for i in range(start,stop,skip):
|
||||
@ -174,13 +175,13 @@ class matlab:
|
||||
def export(self,filename,*vectors):
|
||||
n = len(vectors[0])
|
||||
for vector in vectors:
|
||||
if len(vector) != n: raise StandardError,"vectors must be same length"
|
||||
if len(vector) != n: raise Exception("vectors must be same length")
|
||||
f = open(filename,'w')
|
||||
nvec = len(vectors)
|
||||
for i in xrange(n):
|
||||
for j in xrange(nvec):
|
||||
print >>f,vectors[j][i],
|
||||
print >>f
|
||||
for i in range(n):
|
||||
for j in range(nvec):
|
||||
print(vectors[j][i], end=' ', file=f)
|
||||
print(file=f)
|
||||
f.close()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -212,7 +213,7 @@ class matlab:
|
||||
self.__call__(cmd)
|
||||
self.__call__("!touch tmp.done")
|
||||
while not os.path.exists("tmp.done"): continue
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# restore default attributes by creating a new fig object
|
||||
|
||||
@ -221,7 +222,7 @@ class matlab:
|
||||
fig.ncurves = self.figures[self.current-1].ncurves
|
||||
self.figures[self.current-1] = fig
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def aspect(self,value):
|
||||
@ -245,12 +246,12 @@ class matlab:
|
||||
else:
|
||||
self.figures[self.current-1].ylimit = (values[0],values[1])
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def label(self,x,y,text):
|
||||
self.figures[self.current-1].labels.append((x,y,text))
|
||||
self.figures[self.current-1].nlabels += 1
|
||||
self.figures[self.current-1].nlabels += 1
|
||||
self.draw()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -259,7 +260,7 @@ class matlab:
|
||||
self.figures[self.current-1].nlabel = 0
|
||||
self.figures[self.current-1].labels = []
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def title(self,*strings):
|
||||
@ -276,13 +277,13 @@ class matlab:
|
||||
def xtitle(self,label):
|
||||
self.figures[self.current-1].xtitle = label
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def ytitle(self,label):
|
||||
self.figures[self.current-1].ytitle = label
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def xlog(self):
|
||||
@ -291,7 +292,7 @@ class matlab:
|
||||
else:
|
||||
self.figures[self.current-1].xlog = 1
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def ylog(self):
|
||||
@ -300,7 +301,7 @@ class matlab:
|
||||
else:
|
||||
self.figures[self.current-1].ylog = 1
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def curve(self,num,*settings):
|
||||
@ -348,16 +349,16 @@ class matlab:
|
||||
self.__call__("ylabel('%s','FontSize',16)" % fig.ytitle)
|
||||
|
||||
if fig.xlimit == 0 or fig.ylimit == 0: self.__call__("axis auto")
|
||||
if fig.xlimit:
|
||||
if fig.xlimit:
|
||||
self.__call__("xlim([%g,%g])" % (fig.xlimit[0],fig.xlimit[1]))
|
||||
if fig.ylimit:
|
||||
if fig.ylimit:
|
||||
self.__call__("ylim([%g,%g])" % (fig.ylimit[0],fig.ylimit[1]))
|
||||
|
||||
for i in range(fig.nlabels):
|
||||
x = fig.labels[i][0]
|
||||
y = fig.labels[i][1]
|
||||
text = fig.labels[i][2] # kludge to set label font size
|
||||
self.__call__("text(%g,%g,'%s','FontSize',16)" % (x,y,text))
|
||||
self.__call__("text(%g,%g,'%s','FontSize',16)" % (x,y,text))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# class to store settings for a single plot
|
||||
|
||||
202
src/mdump.py
202
src/mdump.py
@ -3,22 +3,30 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# mdump tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, re, glob, types
|
||||
import functools
|
||||
from os import popen
|
||||
from math import * # any function could be used by set()
|
||||
|
||||
oneline = "Read, write, manipulate mesh dump files"
|
||||
|
||||
docstr = """
|
||||
m = mdump("mesh.one") read in one or more mesh dump files
|
||||
m = mdump("mesh.1 mesh.2.gz") can be gzipped
|
||||
m = mdump("mesh.*") wildcard expands to multiple files
|
||||
m = mdump("mesh.*",0) two args = store filenames, but don't read
|
||||
m = mdump("mesh.1 mesh.2.gz") can be gzipped
|
||||
m = mdump("mesh.*") wildcard expands to multiple files
|
||||
m = mdump("mesh.*",0) two args = store filenames, but don't read
|
||||
|
||||
incomplete and duplicate snapshots are deleted
|
||||
|
||||
time = m.next() read next snapshot from dump files
|
||||
time = m.next() read next snapshot from dump files
|
||||
|
||||
used with 2-argument constructor to allow reading snapshots one-at-a-time
|
||||
snapshot will be skipped only if another snapshot has same time stamp
|
||||
@ -28,20 +36,20 @@ time = m.next() read next snapshot from dump files
|
||||
|
||||
m.map(2,"temperature") assign names to element value columns (1-N)
|
||||
|
||||
m.tselect.all() select all timesteps
|
||||
m.tselect.one(N) select only timestep N
|
||||
m.tselect.none() deselect all timesteps
|
||||
m.tselect.skip(M) select every Mth step
|
||||
m.tselect.all() select all timesteps
|
||||
m.tselect.one(N) select only timestep N
|
||||
m.tselect.none() deselect all timesteps
|
||||
m.tselect.skip(M) select every Mth step
|
||||
m.tselect.test("$t >= 100 and $t < 10000") select matching timesteps
|
||||
m.delete() delete non-selected timesteps
|
||||
m.delete() delete non-selected timesteps
|
||||
|
||||
selecting a timestep also selects all elements in the timestep
|
||||
skip() and test() only select from currently selected timesteps
|
||||
test() uses a Python Boolean expression with $t for timestep value
|
||||
Python comparison syntax: == != < > <= >= and or
|
||||
|
||||
m.eselect.all() select all elems in all steps
|
||||
m.eselect.all(N) select all elems in one step
|
||||
m.eselect.all() select all elems in all steps
|
||||
m.eselect.all(N) select all elems in one step
|
||||
m.eselect.test("$id > 100 and $type == 2") select match elems in all steps
|
||||
m.eselect.test("$id > 100 and $type == 2",N) select matching elems in one step
|
||||
|
||||
@ -52,7 +60,7 @@ m.eselect.test("$id > 100 and $type == 2",N) select matching elems in one step
|
||||
Python comparison syntax: == != < > <= >= and or
|
||||
$name must end with a space
|
||||
|
||||
t = m.time() return vector of selected timestep values
|
||||
t = m.time() return vector of selected timestep values
|
||||
fx,fy,... = m.vecs(1000,"fx","fy",...) return vector(s) for timestep N
|
||||
|
||||
vecs() returns vectors with one value for each selected elem in the timestep
|
||||
@ -124,12 +132,6 @@ m.etype = "color" set column returned as "type" by viz
|
||||
# nevalues = # of node values
|
||||
# evalues[i][j] = 2d array of floats, i = 0 to Nel-1, j = 0 to Ncol
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, commands, re, glob, types
|
||||
from os import popen
|
||||
from math import * # any function could be used by set()
|
||||
|
||||
try:
|
||||
import numpy as np
|
||||
oldnumeric = False
|
||||
@ -160,8 +162,8 @@ class mdump:
|
||||
self.flist = []
|
||||
for word in words: self.flist += glob.glob(word)
|
||||
if len(self.flist) == 0 and len(list) == 1:
|
||||
raise StandardError,"no dump file specified"
|
||||
|
||||
raise Exception("no dump file specified")
|
||||
|
||||
if len(list) == 1:
|
||||
self.increment = 0
|
||||
self.read_all()
|
||||
@ -185,16 +187,16 @@ class mdump:
|
||||
snap = self.read_snapshot(f)
|
||||
while snap:
|
||||
self.snaps.append(snap)
|
||||
print snap.time,
|
||||
print(snap.time, end=' ')
|
||||
sys.stdout.flush()
|
||||
snap = self.read_snapshot(f)
|
||||
|
||||
f.close()
|
||||
print
|
||||
print()
|
||||
|
||||
# sort entries by timestep, cull and combine duplicates
|
||||
|
||||
self.snaps.sort(self.compare_time)
|
||||
self.snaps.sort(key = functools.cmp_to_key(self.compare_time))
|
||||
self.cull()
|
||||
|
||||
# sort all node, element, nvalue, evalue arrays by ID
|
||||
@ -204,33 +206,33 @@ class mdump:
|
||||
array = snap.nodes
|
||||
ids = array[:,0]
|
||||
ordering = np.argsort(ids)
|
||||
for i in xrange(len(array[0])):
|
||||
for i in range(len(array[0])):
|
||||
array[:,i] = np.take(array[:,i],ordering)
|
||||
if snap.eflag:
|
||||
array = snap.elements
|
||||
ids = array[:,0]
|
||||
ordering = np.argsort(ids)
|
||||
for i in xrange(len(array[0])):
|
||||
for i in range(len(array[0])):
|
||||
array[:,i] = np.take(array[:,i],ordering)
|
||||
if snap.nvalueflag:
|
||||
array = snap.nvalues
|
||||
ids = array[:,0]
|
||||
ordering = np.argsort(ids)
|
||||
for i in xrange(len(array[0])):
|
||||
for i in range(len(array[0])):
|
||||
array[:,i] = np.take(array[:,i],ordering)
|
||||
if snap.evalueflag:
|
||||
array = snap.evalues
|
||||
ids = array[:,0]
|
||||
ordering = np.argsort(ids)
|
||||
for i in xrange(len(array[0])):
|
||||
for i in range(len(array[0])):
|
||||
array[:,i] = np.take(array[:,i],ordering)
|
||||
|
||||
# reference definitions of nodes and elements in previous timesteps
|
||||
|
||||
self.reference()
|
||||
|
||||
|
||||
self.nsnaps = len(self.snaps)
|
||||
print "read %d snapshots" % self.nsnaps
|
||||
print("read %d snapshots" % self.nsnaps)
|
||||
|
||||
# select all timesteps and elements
|
||||
|
||||
@ -241,7 +243,7 @@ class mdump:
|
||||
|
||||
def next(self):
|
||||
|
||||
if not self.increment: raise StandardError,"cannot read incrementally"
|
||||
if not self.increment: raise Exception("cannot read incrementally")
|
||||
|
||||
# read next snapshot in current file using eof as pointer
|
||||
# if fail, try next file
|
||||
@ -253,15 +255,15 @@ class mdump:
|
||||
snap = self.read_snapshot(f)
|
||||
if not snap:
|
||||
self.nextfile += 1
|
||||
if self.nextfile == len(self.flist): return -1
|
||||
if self.nextfile == len(self.flist): return -1
|
||||
f.close()
|
||||
self.eof = 0
|
||||
continue
|
||||
self.eof = 0
|
||||
continue
|
||||
self.eof = f.tell()
|
||||
f.close()
|
||||
try:
|
||||
self.findtime(snap.time)
|
||||
continue
|
||||
continue
|
||||
except: break
|
||||
|
||||
# select the new snapshot with all its elements
|
||||
@ -271,7 +273,7 @@ class mdump:
|
||||
snap.tselect = 1
|
||||
snap.nselect = snap.nelements
|
||||
if snap.eflag:
|
||||
for i in xrange(snap.nelements): snap.eselect[i] = 1
|
||||
for i in range(snap.nelements): snap.eselect[i] = 1
|
||||
self.nsnaps += 1
|
||||
self.nselect += 1
|
||||
|
||||
@ -295,7 +297,7 @@ class mdump:
|
||||
elif "NUMBER OF CUBES" in str: snap.eflag = 4
|
||||
elif "NUMBER OF NODE VALUES" in str: snap.nvalueflag = 1
|
||||
elif "NUMBER OF ELEMENT VALUES" in str: snap.evalueflag = 1
|
||||
else: raise StandardError,"unrecognized snapshot in dump file"
|
||||
else: raise Exception("unrecognized snapshot in dump file")
|
||||
n = int(f.readline())
|
||||
|
||||
if snap.eflag: snap.eselect = np.zeros(n)
|
||||
@ -308,19 +310,19 @@ class mdump:
|
||||
snap.ylo,snap.yhi = float(words[0]),float(words[1])
|
||||
words = f.readline().split()
|
||||
snap.zlo,snap.zhi = float(words[0]),float(words[1])
|
||||
|
||||
|
||||
item = f.readline()
|
||||
if n:
|
||||
words = f.readline().split()
|
||||
ncol = len(words)
|
||||
for i in xrange(1,n):
|
||||
for i in range(1,n):
|
||||
words += f.readline().split()
|
||||
floats = map(float,words)
|
||||
floats = list(map(float,words))
|
||||
if oldnumeric: values = np.zeros((n,ncol),np.Float)
|
||||
else: values = np.zeros((n,ncol),np.float)
|
||||
start = 0
|
||||
stop = ncol
|
||||
for i in xrange(n):
|
||||
for i in range(n):
|
||||
values[i] = floats[start:stop]
|
||||
start = stop
|
||||
stop += ncol
|
||||
@ -340,10 +342,10 @@ class mdump:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# map atom column names
|
||||
|
||||
|
||||
def map(self,*pairs):
|
||||
if len(pairs) % 2 != 0:
|
||||
raise StandardError, "mdump map() requires pairs of mappings"
|
||||
raise Exception("mdump map() requires pairs of mappings")
|
||||
for i in range(0,len(pairs),2):
|
||||
j = i + 1
|
||||
self.names[pairs[j]] = pairs[i]-1
|
||||
@ -360,15 +362,15 @@ class mdump:
|
||||
self.nsnaps -= 1
|
||||
ndel += 1
|
||||
else: i += 1
|
||||
print "%d snapshots deleted" % ndel
|
||||
print "%d snapshots remaining" % self.nsnaps
|
||||
print("%d snapshots deleted" % ndel)
|
||||
print("%d snapshots remaining" % self.nsnaps)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# sort elements by ID in all selected timesteps or one timestep
|
||||
|
||||
def sort(self,*list):
|
||||
if len(list) == 0:
|
||||
print "Sorting selected snapshots ..."
|
||||
print("Sorting selected snapshots ...")
|
||||
id = self.names["id"]
|
||||
for snap in self.snaps:
|
||||
if snap.tselect: self.sort_one(snap,id)
|
||||
@ -385,7 +387,7 @@ class mdump:
|
||||
atoms = snap.atoms
|
||||
ids = atoms[:,id]
|
||||
ordering = np.argsort(ids)
|
||||
for i in xrange(len(atoms[0])):
|
||||
for i in range(len(atoms[0])):
|
||||
atoms[:,i] = np.take(atoms[:,i],ordering)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -406,10 +408,10 @@ class mdump:
|
||||
def vecs(self,n,*list):
|
||||
snap = self.snaps[self.findtime(n)]
|
||||
if not snap.evalues:
|
||||
raise StandardError, "snapshot has no element values"
|
||||
|
||||
raise Exception("snapshot has no element values")
|
||||
|
||||
if len(list) == 0:
|
||||
raise StandardError, "no columns specified"
|
||||
raise Exception("no columns specified")
|
||||
columns = []
|
||||
values = []
|
||||
for name in list:
|
||||
@ -418,9 +420,9 @@ class mdump:
|
||||
ncol = len(columns)
|
||||
|
||||
m = 0
|
||||
for i in xrange(len(snap.evalues)):
|
||||
for i in range(len(snap.evalues)):
|
||||
if not snap.eselect[i]: continue
|
||||
for j in xrange(ncol):
|
||||
for j in range(ncol):
|
||||
values[j][m] = snap.evalues[i][columns[j]]
|
||||
m += 1
|
||||
|
||||
@ -441,7 +443,7 @@ class mdump:
|
||||
# --------------------------------------------------------------------
|
||||
# delete successive snapshots with duplicate time stamp
|
||||
# if have same timestamp, combine them if internal flags are different
|
||||
|
||||
|
||||
def cull(self):
|
||||
i = 1
|
||||
while i < len(self.snaps):
|
||||
@ -480,11 +482,11 @@ class mdump:
|
||||
# --------------------------------------------------------------------
|
||||
# insure every snapshot has node and element connectivity info
|
||||
# if not, point it at most recent shapshot that does
|
||||
|
||||
|
||||
def reference(self):
|
||||
for i in xrange(len(self.snaps)):
|
||||
for i in range(len(self.snaps)):
|
||||
if not self.snaps[i].nflag:
|
||||
for j in xrange(i,-1,-1):
|
||||
for j in range(i,-1,-1):
|
||||
if self.snaps[j].nflag:
|
||||
self.snaps[i].nflag = self.snaps[j].nflag
|
||||
self.snaps[i].nnodes = self.snaps[j].nnodes
|
||||
@ -497,9 +499,9 @@ class mdump:
|
||||
self.snaps[i].zhi = self.snaps[j].zhi
|
||||
break
|
||||
if not self.snaps[i].nflag:
|
||||
raise StandardError,"no nodal coords found in previous snapshots"
|
||||
raise Exception("no nodal coords found in previous snapshots")
|
||||
if not self.snaps[i].eflag:
|
||||
for j in xrange(i,-1,-1):
|
||||
for j in range(i,-1,-1):
|
||||
if self.snaps[j].eflag:
|
||||
self.snaps[i].eflag = self.snaps[j].eflag
|
||||
self.snaps[i].nelements = self.snaps[j].nelements
|
||||
@ -507,7 +509,7 @@ class mdump:
|
||||
self.snaps[i].eselect = self.snaps[j].eselect
|
||||
break
|
||||
if not self.snaps[i].eflag:
|
||||
raise StandardError,"no elem connections found in previous snapshots"
|
||||
raise Exception("no elem connections found in previous snapshots")
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# iterate over selected snapshots
|
||||
@ -515,16 +517,16 @@ class mdump:
|
||||
def iterator(self,flag):
|
||||
start = 0
|
||||
if flag: start = self.iterate + 1
|
||||
for i in xrange(start,self.nsnaps):
|
||||
for i in range(start,self.nsnaps):
|
||||
if self.snaps[i].tselect:
|
||||
self.iterate = i
|
||||
return i,self.snaps[i].time,1
|
||||
return 0,0,-1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# return list of triangles to viz for snapshot isnap
|
||||
# if called with flag, then index is timestep, so convert to snapshot index
|
||||
|
||||
|
||||
def viz(self,index,flag=0):
|
||||
if not flag: isnap = index
|
||||
else:
|
||||
@ -536,7 +538,7 @@ class mdump:
|
||||
i += 1
|
||||
isnap = i - 1
|
||||
snap = self.snaps[isnap]
|
||||
|
||||
|
||||
time = snap.time
|
||||
box = [snap.xlo,snap.ylo,snap.zlo,snap.xhi,snap.yhi,snap.zhi]
|
||||
if self.etype == "": type = -1
|
||||
@ -547,17 +549,17 @@ class mdump:
|
||||
|
||||
# create triangle list from all elements
|
||||
# for type, either use element type (-1) or user-defined column in evalues
|
||||
|
||||
|
||||
tris = []
|
||||
nodes = snap.nodes
|
||||
for i in xrange(snap.nelements):
|
||||
for i in range(snap.nelements):
|
||||
if not snap.eselect[i]: continue
|
||||
element = snap.elements[i]
|
||||
if snap.evalueflag: evalue = snap.evalues[i]
|
||||
else: evalues = []
|
||||
|
||||
# single tri, normal = up
|
||||
|
||||
|
||||
if snap.eflag == 1:
|
||||
v1 = nodes[int(element[2])-1][2:5].tolist()
|
||||
v2 = nodes[int(element[3])-1][2:5].tolist()
|
||||
@ -568,7 +570,7 @@ class mdump:
|
||||
else: tris.append([element[0],evalue[type]] + list + n)
|
||||
|
||||
# single tet, convert to 4 tris, normals = out
|
||||
|
||||
|
||||
elif snap.eflag == 2:
|
||||
v1 = nodes[int(element[2])-1][2:5].tolist()
|
||||
v2 = nodes[int(element[3])-1][2:5].tolist()
|
||||
@ -592,7 +594,7 @@ class mdump:
|
||||
else: tris.append([element[0],evalue[type]] + list + n)
|
||||
|
||||
# single square, convert to 2 tris, normals = up
|
||||
|
||||
|
||||
elif snap.eflag == 3:
|
||||
v1 = nodes[int(element[2])-1][2:5].tolist()
|
||||
v2 = nodes[int(element[3])-1][2:5].tolist()
|
||||
@ -608,7 +610,7 @@ class mdump:
|
||||
else: tris.append([element[0],evalue[type]] + list + n)
|
||||
|
||||
# single cube, convert to 12 tris, normals = out
|
||||
|
||||
|
||||
elif snap.eflag == 4:
|
||||
v1 = nodes[int(element[2])-1][2:5].tolist()
|
||||
v2 = nodes[int(element[3])-1][2:5].tolist()
|
||||
@ -666,7 +668,7 @@ class mdump:
|
||||
n = normal(list[0:3],list[3:6],list[6:9])
|
||||
if type == -1: tris.append([element[0],element[1]] + list + n)
|
||||
else: tris.append([element[0],evalue[type]] + list + n)
|
||||
|
||||
|
||||
lines = []
|
||||
|
||||
return time,box,atoms,bonds,tris,lines
|
||||
@ -674,7 +676,7 @@ class mdump:
|
||||
# --------------------------------------------------------------------
|
||||
# return lists of node/element info for snapshot isnap
|
||||
# if called with flag, then index is timestep, so convert to snapshot index
|
||||
|
||||
|
||||
def mviz(self,index,flag=0):
|
||||
if not flag: isnap = index
|
||||
else:
|
||||
@ -686,22 +688,22 @@ class mdump:
|
||||
i += 1
|
||||
isnap = i - 1
|
||||
snap = self.snaps[isnap]
|
||||
|
||||
|
||||
time = snap.time
|
||||
box = [snap.xlo,snap.ylo,snap.zlo,snap.xhi,snap.yhi,snap.zhi]
|
||||
nvalues = []
|
||||
if snap.nvalueflag: nvalues = snap.nvalues
|
||||
evalues = []
|
||||
if snap.nvalueflag: evalues = snap.evalues
|
||||
|
||||
|
||||
return time,box,snap.nodes,snap.elements,nvalues,evalues
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def findtime(self,n):
|
||||
for i in xrange(self.nsnaps):
|
||||
for i in range(self.nsnaps):
|
||||
if self.snaps[i].time == n: return i
|
||||
raise StandardError, "no step %d exists" % n
|
||||
raise Exception("no step %d exists" % n)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# return maximum box size across all selected snapshots
|
||||
@ -718,7 +720,7 @@ class mdump:
|
||||
if zlo == None or snap.zlo < zlo: zlo = snap.zlo
|
||||
if zhi == None or snap.zhi > zhi: zhi = snap.zhi
|
||||
return [xlo,ylo,zlo,xhi,yhi,zhi]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def compare_atom(self,a,b):
|
||||
@ -727,7 +729,7 @@ class mdump:
|
||||
elif a[0] > b[0]:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
return 0
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# one snapshot
|
||||
@ -742,7 +744,7 @@ class tselect:
|
||||
|
||||
def __init__(self,data):
|
||||
self.data = data
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def all(self):
|
||||
@ -751,7 +753,7 @@ class tselect:
|
||||
snap.tselect = 1
|
||||
data.nselect = len(data.snaps)
|
||||
data.eselect.all()
|
||||
print "%d snapshots selected out of %d" % (data.nselect,data.nsnaps)
|
||||
print("%d snapshots selected out of %d" % (data.nselect,data.nsnaps))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
@ -763,7 +765,7 @@ class tselect:
|
||||
data.snaps[i].tselect = 1
|
||||
data.nselect = 1
|
||||
data.eselect.all()
|
||||
print "%d snapshots selected out of %d" % (data.nselect,data.nsnaps)
|
||||
print("%d snapshots selected out of %d" % (data.nselect,data.nsnaps))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
@ -772,7 +774,7 @@ class tselect:
|
||||
for snap in data.snaps:
|
||||
snap.tselect = 0
|
||||
data.nselect = 0
|
||||
print "%d snapshots selected out of %d" % (data.nselect,data.nsnaps)
|
||||
print("%d snapshots selected out of %d" % (data.nselect,data.nsnaps))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
@ -788,8 +790,8 @@ class tselect:
|
||||
snap.tselect = 0
|
||||
data.nselect -= 1
|
||||
data.eselect.all()
|
||||
print "%d snapshots selected out of %d" % (data.nselect,data.nsnaps)
|
||||
|
||||
print("%d snapshots selected out of %d" % (data.nselect,data.nsnaps))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def test(self,teststr):
|
||||
@ -797,14 +799,16 @@ class tselect:
|
||||
snaps = data.snaps
|
||||
cmd = "flag = " + teststr.replace("$t","snaps[i].time")
|
||||
ccmd = compile(cmd,'','single')
|
||||
for i in xrange(data.nsnaps):
|
||||
for i in range(data.nsnaps):
|
||||
if not snaps[i].tselect: continue
|
||||
exec ccmd
|
||||
ldict = {'data':data,'snaps':snaps,'i':i}
|
||||
exec(ccmd,globals(),ldict)
|
||||
flag = ldict['flag']
|
||||
if not flag:
|
||||
snaps[i].tselect = 0
|
||||
data.nselect -= 1
|
||||
data.eselect.all()
|
||||
print "%d snapshots selected out of %d" % (data.nselect,data.nsnaps)
|
||||
print("%d snapshots selected out of %d" % (data.nselect,data.nsnaps))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# element selection class
|
||||
@ -821,12 +825,12 @@ class eselect:
|
||||
if len(args) == 0: # all selected timesteps
|
||||
for snap in data.snaps:
|
||||
if not snap.tselect: continue
|
||||
for i in xrange(snap.nelements): snap.eselect[i] = 1
|
||||
for i in range(snap.nelements): snap.eselect[i] = 1
|
||||
snap.nselect = snap.nelements
|
||||
else: # one timestep
|
||||
n = data.findtime(args[0])
|
||||
snap = data.snaps[n]
|
||||
for i in xrange(snap.nelements): snap.eselect[i] = 1
|
||||
for i in range(snap.nelements): snap.eselect[i] = 1
|
||||
snap.nselect = snap.nelements
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -835,7 +839,7 @@ class eselect:
|
||||
data = self.data
|
||||
|
||||
# replace all $var with snap.atoms references and compile test string
|
||||
|
||||
|
||||
pattern = "\$\w*"
|
||||
list = re.findall(pattern,teststr)
|
||||
for item in list:
|
||||
@ -849,29 +853,29 @@ class eselect:
|
||||
if len(args) == 0: # all selected timesteps
|
||||
for snap in data.snaps:
|
||||
if not snap.tselect: continue
|
||||
for i in xrange(snap.nelements):
|
||||
for i in range(snap.nelements):
|
||||
if not snap.eselect[i]: continue
|
||||
exec ccmd
|
||||
exec(ccmd)
|
||||
if not flag:
|
||||
snap.eselect[i] = 0
|
||||
snap.nselect -= 1
|
||||
for i in xrange(data.nsnaps):
|
||||
for i in range(data.nsnaps):
|
||||
if data.snaps[i].tselect:
|
||||
print "%d atoms of %d selected in first step %d" % \
|
||||
(data.snaps[i].nselect,data.snaps[i].nelements,data.snaps[i].time)
|
||||
print("%d atoms of %d selected in first step %d" % \
|
||||
(data.snaps[i].nselect,data.snaps[i].nelements,data.snaps[i].time))
|
||||
break
|
||||
for i in xrange(data.nsnaps-1,-1,-1):
|
||||
for i in range(data.nsnaps-1,-1,-1):
|
||||
if data.snaps[i].tselect:
|
||||
print "%d atoms of %d selected in last step %d" % \
|
||||
(data.snaps[i].nselect,data.snaps[i].nelements,data.snaps[i].time)
|
||||
print("%d atoms of %d selected in last step %d" % \
|
||||
(data.snaps[i].nselect,data.snaps[i].nelements,data.snaps[i].time))
|
||||
break
|
||||
|
||||
else: # one timestep
|
||||
n = data.findtime(args[0])
|
||||
snap = data.snaps[n]
|
||||
for i in xrange(snap.nelements):
|
||||
for i in range(snap.nelements):
|
||||
if not snap.eselect[i]: continue
|
||||
exec ccmd
|
||||
exec(ccmd)
|
||||
if not flag:
|
||||
snap.eselect[i] = 0
|
||||
snap.nselect -= 1
|
||||
|
||||
91
src/pair.py
91
src/pair.py
@ -3,11 +3,16 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# pair tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
from math import sqrt
|
||||
|
||||
oneline = "Compute LAMMPS pairwise energies"
|
||||
|
||||
docstr = """
|
||||
@ -15,15 +20,15 @@ p = pair("lj/charmm/coul/charmm") create pair object for specific pair style
|
||||
|
||||
available styles: lj/cut, lj/cut/coul/cut, lj/charmm/coul/charmm
|
||||
|
||||
p.coeff(d) extract pairwise coeffs from data object
|
||||
p.init(cut1,cut2,...) setup based on coeffs and cutoffs
|
||||
p.coeff(d) extract pairwise coeffs from data object
|
||||
p.init(cut1,cut2,...) setup based on coeffs and cutoffs
|
||||
|
||||
init args are specific to pair style:
|
||||
lj/cut = cutlj
|
||||
lj/cut/coul/cut = cutlj,cut_coul (cut_coul optional)
|
||||
lj/charmm/coul/charmm = cutlj_inner,cutlj,cutcoul_inner,cut_coul
|
||||
(last 2 optional)
|
||||
|
||||
|
||||
e_vdwl,e_coul = p.single(rsq,itype,jtype,q1,q2,...) compute LJ/Coul energy
|
||||
|
||||
pairwise energy between 2 atoms at distance rsq with their attributes
|
||||
@ -41,10 +46,6 @@ e_vdwl,e_coul = p.single(rsq,itype,jtype,q1,q2,...) compute LJ/Coul energy
|
||||
|
||||
# Variables
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from math import sqrt
|
||||
|
||||
# Class definition
|
||||
|
||||
class pair:
|
||||
@ -68,7 +69,7 @@ class pair:
|
||||
self.init_func = self.init_lj_charmm_coul_charmm
|
||||
self.single_func = self.single_lj_charmm_coul_charmm
|
||||
else:
|
||||
raise StandardError, "this pair style not yet supported"
|
||||
raise Exception("this pair style not yet supported")
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# generic coeff method
|
||||
@ -96,18 +97,18 @@ class pair:
|
||||
epsilon = data.get("Pair Coeffs",2)
|
||||
sigma = data.get("Pair Coeffs",3)
|
||||
ntypes = len(epsilon)
|
||||
|
||||
|
||||
self.lj3 = []
|
||||
self.lj4 = []
|
||||
for i in xrange(ntypes):
|
||||
self.lj4 = []
|
||||
for i in range(ntypes):
|
||||
self.lj3.append(ntypes * [0])
|
||||
self.lj4.append(ntypes * [0])
|
||||
for j in xrange(ntypes):
|
||||
for j in range(ntypes):
|
||||
epsilon_ij = sqrt(epsilon[i]*epsilon[j])
|
||||
sigma_ij = sqrt(sigma[i]*sigma[j])
|
||||
self.lj3[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,12.0);
|
||||
self.lj4[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,6.0);
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# args = cutlj
|
||||
|
||||
@ -117,20 +118,20 @@ class pair:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# args = rsq,itype,jtype
|
||||
|
||||
|
||||
def single_lj_cut(self,list):
|
||||
rsq = list[0]
|
||||
itype = list[1]
|
||||
jtype = list[2]
|
||||
|
||||
|
||||
r2inv = 1.0/rsq
|
||||
|
||||
|
||||
if rsq < self.cut_ljsq:
|
||||
r6inv = r2inv*r2inv*r2inv
|
||||
eng_vdwl = r6inv*(self.lj3[itype][jtype]*r6inv-self.lj4[itype][jtype])
|
||||
else: eng_vdwl = 0.0
|
||||
|
||||
return eng_vdwl
|
||||
|
||||
return eng_vdwl
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# --------------------------------------------------------------------
|
||||
@ -140,52 +141,52 @@ class pair:
|
||||
epsilon = data.get("Pair Coeffs",2)
|
||||
sigma = data.get("Pair Coeffs",3)
|
||||
ntypes = len(epsilon)
|
||||
|
||||
|
||||
self.lj3 = []
|
||||
self.lj4 = []
|
||||
for i in xrange(ntypes):
|
||||
self.lj4 = []
|
||||
for i in range(ntypes):
|
||||
self.lj3.append(ntypes * [0])
|
||||
self.lj4.append(ntypes * [0])
|
||||
for j in xrange(ntypes):
|
||||
for j in range(ntypes):
|
||||
epsilon_ij = sqrt(epsilon[i]*epsilon[j])
|
||||
sigma_ij = sqrt(sigma[i]*sigma[j])
|
||||
self.lj3[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,12.0);
|
||||
self.lj4[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,6.0);
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# args = cutlj, cut_coul (cut_coul optional)
|
||||
|
||||
def init_lj_cut_coul_cut(self,list):
|
||||
self.qqr2e = 332.0636 # convert energy to kcal/mol
|
||||
self.qqr2e = 332.0636 # convert energy to kcal/mol
|
||||
cut_lj = list[0]
|
||||
self.cut_ljsq = cut_lj*cut_lj
|
||||
|
||||
|
||||
if len(list) == 1: cut_coul = cut_lj
|
||||
else: cut_coul = list[1]
|
||||
self.cut_coulsq = cut_coul*cut_coul
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# args = rsq,itype,jtype,q1,q2
|
||||
|
||||
|
||||
def single_lj_cut_coul_cut(self,list):
|
||||
rsq = list[0]
|
||||
itype = list[1]
|
||||
jtype = list[2]
|
||||
q1 = list[3]
|
||||
q2 = list[4]
|
||||
|
||||
|
||||
r2inv = 1.0/rsq
|
||||
|
||||
|
||||
if rsq < self.cut_coulsq: eng_coul = self.qqr2e * q1*q2*sqrt(r2inv)
|
||||
else: eng_coul = 0.0
|
||||
|
||||
|
||||
if rsq < self.cut_ljsq:
|
||||
r6inv = r2inv*r2inv*r2inv
|
||||
eng_vdwl = r6inv*(self.lj3[itype][jtype]*r6inv-self.lj4[itype][jtype])
|
||||
else: eng_vdwl = 0.0
|
||||
|
||||
return eng_coul,eng_vdwl
|
||||
|
||||
|
||||
return eng_coul,eng_vdwl
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# --------------------------------------------------------------------
|
||||
# lj/charmm/coul/charmm methods
|
||||
@ -194,29 +195,29 @@ class pair:
|
||||
epsilon = data.get("Pair Coeffs",2)
|
||||
sigma = data.get("Pair Coeffs",3)
|
||||
ntypes = len(epsilon)
|
||||
|
||||
|
||||
self.lj3 = []
|
||||
self.lj4 = []
|
||||
for i in xrange(ntypes):
|
||||
self.lj4 = []
|
||||
for i in range(ntypes):
|
||||
self.lj3.append(ntypes * [0])
|
||||
self.lj4.append(ntypes * [0])
|
||||
for j in xrange(ntypes):
|
||||
for j in range(ntypes):
|
||||
epsilon_ij = sqrt(epsilon[i]*epsilon[j])
|
||||
sigma_ij = 0.5 * (sigma[i] + sigma[j])
|
||||
self.lj3[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,12.0);
|
||||
self.lj4[i][j] = 4.0 * epsilon_ij * pow(sigma_ij,6.0);
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# args = cutlj_inner,cutlj,cutcoul_inner,cut_coul (last 2 optional)
|
||||
|
||||
def init_lj_charmm_coul_charmm(self,list):
|
||||
self.qqr2e = 332.0636 # convert energy to kcal/mol
|
||||
self.qqr2e = 332.0636 # convert energy to kcal/mol
|
||||
cut_lj_inner = list[0]
|
||||
cut_lj = list[1]
|
||||
|
||||
self.cut_lj_innersq = cut_lj_inner*cut_lj_inner
|
||||
self.cut_ljsq = cut_lj*cut_lj
|
||||
|
||||
|
||||
if len(list) == 2:
|
||||
cut_coul_inner = cut_lj_inner
|
||||
cut_coul = cut_lj
|
||||
@ -235,16 +236,16 @@ class pair:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# args = rsq,itype,jtype,q1,q2
|
||||
|
||||
|
||||
def single_lj_charmm_coul_charmm(self,list):
|
||||
rsq = list[0]
|
||||
itype = list[1]
|
||||
jtype = list[2]
|
||||
q1 = list[3]
|
||||
q2 = list[4]
|
||||
|
||||
|
||||
r2inv = 1.0/rsq
|
||||
|
||||
|
||||
if rsq < self.cut_coulsq:
|
||||
eng_coul = self.qqr2e * q1*q2*sqrt(r2inv)
|
||||
if rsq > self.cut_coul_innersq:
|
||||
@ -253,7 +254,7 @@ class pair:
|
||||
self.denom_coul
|
||||
eng_coul *= switch1
|
||||
else: eng_coul = 0.0
|
||||
|
||||
|
||||
if rsq < self.cut_ljsq:
|
||||
r6inv = r2inv*r2inv*r2inv
|
||||
eng_vdwl = r6inv*(self.lj3[itype][jtype]*r6inv-self.lj4[itype][jtype])
|
||||
@ -263,5 +264,5 @@ class pair:
|
||||
self.denom_lj
|
||||
eng_vdwl *= switch1
|
||||
else: eng_vdwl = 0.0
|
||||
|
||||
|
||||
return eng_coul,eng_vdwl
|
||||
|
||||
145
src/patch.py
145
src/patch.py
@ -3,20 +3,26 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# patch tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
from math import sqrt,pi,cos,sin
|
||||
from data import data
|
||||
|
||||
oneline = "Create patchy Lennard-Jones particles for LAMMPS input"
|
||||
|
||||
docstr = """
|
||||
p = patch(vfrac) setup box with a specified volume fraction
|
||||
p = patch(vfrac,1,1,2) x,y,z = aspect ratio of box (def = 1,1,1)
|
||||
|
||||
p.seed = 48379 set random # seed (def = 12345)
|
||||
p.randomized = 0 1 = choose next particle randomly, 0 = as generated
|
||||
p.dim = 2 set dimension of created box (def = 3)
|
||||
|
||||
p.seed = 48379 set random # seed (def = 12345)
|
||||
p.randomized = 0 1 = choose next particle randomly, 0 = as generated
|
||||
p.dim = 2 set dimension of created box (def = 3)
|
||||
p.blen = 0.97 set length of tether bonds (def = 0.97)
|
||||
p.dmin = 1.02 set min r from i-1 to i+1 tether site (def = 1.02)
|
||||
p.lattice = [Nx,Ny,Nz] generate Nx by Ny by Nz lattice of particles
|
||||
@ -25,7 +31,7 @@ p.lattice = [Nx,Ny,Nz] generate Nx by Ny by Nz lattice of particles
|
||||
lattice = [0,0,0] = generate N particles randomly, default
|
||||
|
||||
p.build(100,"hex2",1,2,3) create 100 "hex2" particles with types 1,2,3
|
||||
|
||||
|
||||
can be invoked multiple times
|
||||
keywords:
|
||||
c60hex2: diam,1,2,3 = C-60 with 2 hex patches and ctr part, types 1,2,3
|
||||
@ -46,7 +52,7 @@ p.build(100,"hex2",1,2,3) create 100 "hex2" particles with types 1,2,3
|
||||
from Alo to Ahi and Blo to Bhi, line type m
|
||||
linetri: Alo,Ahi,Blo,Bhi,m = 3-line 2d triangle with random base
|
||||
from Alo to Ahi and height Blo to Bhi, type m
|
||||
|
||||
|
||||
p.write("data.patch") write out system to LAMMPS data file
|
||||
"""
|
||||
|
||||
@ -61,15 +67,10 @@ p.write("data.patch") write out system to LAMMPS data file
|
||||
# seed = random seed
|
||||
# molecules = list of atoms, grouped by molecule
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from math import sqrt,pi,cos,sin
|
||||
from data import data
|
||||
|
||||
# Class definition
|
||||
|
||||
class patch:
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self,vfrac,*list):
|
||||
@ -98,8 +99,14 @@ class patch:
|
||||
if style == "linebox" or style == "linetri": self.style = "line"
|
||||
if style == "tritet" or style == "tribox": self.style = "tri"
|
||||
cmd = "atoms,bonds,tris,segments,volume = self.%s(*types)" % style
|
||||
for i in xrange(n):
|
||||
exec cmd
|
||||
for i in range(n):
|
||||
ldict = {'i':i,'self':self,'types':types}
|
||||
exec(cmd,globals(),ldict)
|
||||
atoms = ldict['atoms']
|
||||
bonds = ldict['bonds']
|
||||
tris = ldict['tris']
|
||||
segments = ldict['segments']
|
||||
volume = ldict['volume']
|
||||
self.molecules.append([atoms,bonds,tris,segments])
|
||||
self.volume += volume
|
||||
|
||||
@ -131,7 +138,7 @@ class patch:
|
||||
latflag = 1
|
||||
if self.lattice[0]*self.lattice[1]*self.lattice[2] != \
|
||||
len(self.molecules):
|
||||
raise StandardError,"lattice inconsistent with # of molecules"
|
||||
raise Exception("lattice inconsistent with # of molecules")
|
||||
else: latflag = 0
|
||||
|
||||
idatom = idbond = idtri = idmol = 0
|
||||
@ -179,7 +186,7 @@ class patch:
|
||||
#xp[0] = 1; xp[1] = 0; xp[2] = 0
|
||||
#yp[0] = 0; yp[1] = 1; yp[2] = 0
|
||||
#zp[0] = 0; zp[1] = 0; zp[2] = 1
|
||||
|
||||
|
||||
# random origin or lattice site for new particle
|
||||
|
||||
if latflag == 0:
|
||||
@ -195,15 +202,15 @@ class patch:
|
||||
zorig = self.zlo + iz*self.zprd/self.lattice[2]
|
||||
|
||||
#xorig = 0; yorig = 0; zorig = 0
|
||||
|
||||
|
||||
# unpack bonds in molecule before atoms so idatom = all previous atoms
|
||||
|
||||
|
||||
for bond in molecule[1]:
|
||||
idbond += 1
|
||||
bonds.append([idbond,bond[0],bond[1]+idatom+1,bond[2]+idatom+1])
|
||||
|
||||
# unpack triples in molecule as displacements from associated atom
|
||||
|
||||
|
||||
for triple in molecule[2]: triples.append(triple)
|
||||
|
||||
# unpack atoms in molecule
|
||||
@ -223,7 +230,7 @@ class patch:
|
||||
ix = iy = iz = 0
|
||||
x,y,z,ix,iy,iz = self.pbc(x,y,z,ix,iy,iz)
|
||||
atoms.append([idatom,idmol,atom[0],x,y,z,ix,iy,iz])
|
||||
|
||||
|
||||
elif self.style == "tri":
|
||||
for i,atom in enumerate(molecule[0]):
|
||||
idatom += 1
|
||||
@ -239,7 +246,7 @@ class patch:
|
||||
if not triples: triflag = 0
|
||||
else: triflag = 1
|
||||
atoms.append([idatom,idmol,atom[0],triflag,mass,x,y,z,ix,iy,iz])
|
||||
|
||||
|
||||
if triflag:
|
||||
triple = triples[i]
|
||||
xtri = triple[0]
|
||||
@ -272,7 +279,7 @@ class patch:
|
||||
|
||||
list = [atom[2] for atom in atoms]
|
||||
atypes = max(list)
|
||||
|
||||
|
||||
d = data()
|
||||
d.title = "LAMMPS data file for Nanoparticles"
|
||||
d.headers["atoms"] = len(atoms)
|
||||
@ -343,9 +350,9 @@ class patch:
|
||||
if self.lattice[0] or self.lattice[1]:
|
||||
latflag = 1
|
||||
if self.lattice[0]*self.lattice[1] != len(self.molecules):
|
||||
raise StandardError,"lattice inconsistent with # of molecules"
|
||||
raise Exception("lattice inconsistent with # of molecules")
|
||||
else: latflag = 0
|
||||
|
||||
|
||||
idatom = idbond = idmol = 0
|
||||
atoms = []
|
||||
bonds = []
|
||||
@ -357,10 +364,10 @@ class patch:
|
||||
if self.randomized: i = int(self.random()*len(self.molecules))
|
||||
else: i = 0
|
||||
molecule = self.molecules.pop(i)
|
||||
|
||||
|
||||
idmol += 1
|
||||
segments = []
|
||||
|
||||
|
||||
# xp[2],yp[2] = randomly oriented, normalized basis vectors
|
||||
# xp is in random direction
|
||||
# yp is (0,0,1) crossed into xp
|
||||
@ -387,15 +394,15 @@ class patch:
|
||||
xorig = self.xlo + ix*self.xprd/self.lattice[0]
|
||||
yorig = self.ylo + iy*self.yprd/self.lattice[1]
|
||||
zorig = 0.0
|
||||
|
||||
|
||||
# unpack bonds in molecule before atoms so idatom = all previous atoms
|
||||
|
||||
|
||||
for bond in molecule[1]:
|
||||
idbond += 1
|
||||
bonds.append([idbond,bond[0],bond[1]+idatom+1,bond[2]+idatom+1])
|
||||
|
||||
# unpack segments in molecule as displacements from associated atom
|
||||
|
||||
|
||||
for segment in molecule[3]: segments.append(segment)
|
||||
|
||||
# unpack atoms in molecule
|
||||
@ -445,7 +452,7 @@ class patch:
|
||||
segment[2],segment[3],tmp = \
|
||||
self.pbc_near(segment[2],segment[3],0,x,y,z)
|
||||
lines.append([idatom] + segment)
|
||||
|
||||
|
||||
# create the data file
|
||||
|
||||
list = [atom[2] for atom in atoms]
|
||||
@ -464,7 +471,7 @@ class patch:
|
||||
d.headers["zlo zhi"] = (self.zlo,self.zhi)
|
||||
|
||||
# atoms section of data file
|
||||
|
||||
|
||||
records = []
|
||||
if self.style == "molecular":
|
||||
for atom in atoms:
|
||||
@ -502,7 +509,7 @@ class patch:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# adjust x,y,z to be inside periodic box
|
||||
|
||||
|
||||
def pbc(self,x,y,z,ix,iy,iz):
|
||||
if x < self.xlo:
|
||||
x += self.xprd
|
||||
@ -526,7 +533,7 @@ class patch:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# adjust xnew,ynew,znew to be near x,y,z in periodic sense
|
||||
|
||||
|
||||
def pbc_near(self,xnew,ynew,znew,x,y,z):
|
||||
if x-xnew > 0.5*self.xprd: xnew += self.xprd
|
||||
elif xnew-x > 0.5*self.xprd: xnew -= self.xprd
|
||||
@ -540,7 +547,7 @@ class patch:
|
||||
# params = diam,type1,type2,type3
|
||||
# type1 = type of non-patch atoms, type2 = type of patch atoms
|
||||
# type3 = type of center-of-sphere atom
|
||||
|
||||
|
||||
def c60hex2(self,*params):
|
||||
template = BUCKY_60
|
||||
diam = params[0]
|
||||
@ -549,19 +556,19 @@ class patch:
|
||||
atoms = make_sphere(template,diam,params[1],patches)
|
||||
volume = 4.0/3.0 * pi * diam*diam*diam/8
|
||||
return atoms,[],[],[],volume
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# params = diam,type1,type2
|
||||
# type1 = type of large center atom, type2 = type of hex patch atoms
|
||||
|
||||
|
||||
def hex2(self,*params):
|
||||
diam = params[0]
|
||||
type1 = params[1]
|
||||
type2 = params[2]
|
||||
|
||||
|
||||
atoms = []
|
||||
atoms.append([type1,0.0,0.0,0.0])
|
||||
|
||||
|
||||
atoms.append(atom_on_sphere(diam,type2,0.5*diam,0.0,0.0))
|
||||
atoms.append(atom_on_sphere(diam,type2,0.5*diam,1.0,0.0))
|
||||
atoms.append(atom_on_sphere(diam,type2,0.5*diam,-1.0,0.0))
|
||||
@ -580,19 +587,19 @@ class patch:
|
||||
|
||||
volume = 4.0/3.0 * pi * diam*diam*diam/8
|
||||
return atoms,[],[],[],volume
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# params = diam,type1,type2
|
||||
# type1 = type of large center atom, type2 = type of hex patch atoms
|
||||
|
||||
|
||||
def hex4(self,*params):
|
||||
diam = params[0]
|
||||
type1 = params[1]
|
||||
type2 = params[2]
|
||||
|
||||
|
||||
atoms = []
|
||||
atoms.append([type1,0.0,0.0,0.0])
|
||||
|
||||
|
||||
atoms.append(atom_on_sphere(diam,type2,0.5*diam,0.0,0.0))
|
||||
atoms.append(atom_on_sphere(diam,type2,0.5*diam,1.0,0.0))
|
||||
atoms.append(atom_on_sphere(diam,type2,0.5*diam,-1.0,0.0))
|
||||
@ -632,13 +639,13 @@ class patch:
|
||||
# params = diam,nring,type1,type2
|
||||
# nring = # of particles in ring
|
||||
# type1 = type of large center atom, type2 = type of ring atoms
|
||||
|
||||
|
||||
def ring(self,*params):
|
||||
diam = params[0]
|
||||
nring = params[1]
|
||||
type1 = params[2]
|
||||
type2 = params[3]
|
||||
|
||||
|
||||
atoms = []
|
||||
atoms.append([type1,0.0,0.0,0.0])
|
||||
|
||||
@ -655,7 +662,7 @@ class patch:
|
||||
# m12,m12type = length of tethers on each side of ball (m12 = 0 = no tether)
|
||||
# set three types of bonds:
|
||||
# 1 = big to small, 2 = small to small, 3 = across two tethers
|
||||
|
||||
|
||||
def ball(self,*params):
|
||||
diam = params[0]
|
||||
m1 = params[1]
|
||||
@ -684,14 +691,14 @@ class patch:
|
||||
if i == 0: bonds.append([1,0,1+m1])
|
||||
else: bonds.append([2,1+m1+i-1,1+m1+i])
|
||||
if m1 and m2: bonds.append([3,1,m1+1])
|
||||
|
||||
|
||||
volume = 4.0/3.0 * pi * diam*diam*diam/8 + (m1+m2)*pi/6.0
|
||||
return atoms,bonds,[],[],volume
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# params = type1,type2
|
||||
# type1 = type of 1/3 layers, type2 = type of middle layer
|
||||
|
||||
|
||||
def tri5(self,*params):
|
||||
template = TRI5_HOLLOW
|
||||
nlayer = 3
|
||||
@ -724,12 +731,12 @@ class patch:
|
||||
ntype = params[3]
|
||||
m1type = params[4]
|
||||
m2type = params[5]
|
||||
|
||||
|
||||
atoms = []
|
||||
for i in range(n):
|
||||
x,y,z = i*self.blen,0.0,0.0
|
||||
atoms.append([ntype,x,y,z])
|
||||
|
||||
|
||||
if m1: atoms += tether(m1,m1type,self.blen,self.dmin,
|
||||
atoms[n-2],atoms[n-1],self.random)
|
||||
if m2: atoms += tether(m2,m2type,self.blen,self.dmin,
|
||||
@ -742,7 +749,7 @@ class patch:
|
||||
for i in range(m2):
|
||||
if i == 0: bonds.append([1,0,n+m1])
|
||||
else: bonds.append([1,n+m1+i-1,n+m1+i])
|
||||
|
||||
|
||||
volume = (n+m1+m2) * pi / 6.0
|
||||
return atoms,bonds,[],[],volume
|
||||
|
||||
@ -750,7 +757,7 @@ class patch:
|
||||
# params = nsize,m1,m2,m3,ntype,m1type,m2type,m3type
|
||||
# nsize,ntype = size,type of triangle center
|
||||
# m123,m123type = length of tethers on each corner (m123 = 0 = no tether)
|
||||
|
||||
|
||||
def tri(self,*params):
|
||||
nsize = params[0]
|
||||
m1 = params[1]
|
||||
@ -760,7 +767,7 @@ class patch:
|
||||
m1type = params[5]
|
||||
m2type = params[6]
|
||||
m3type = params[7]
|
||||
|
||||
|
||||
atoms = []
|
||||
for i in range(nsize):
|
||||
n = nsize - i
|
||||
@ -794,7 +801,7 @@ class patch:
|
||||
# params = m1,m2,m3,m4,m5,m6,ntype,m1type,m2type,m3type,m4type,m5type,m6type
|
||||
# ntype = type of hex center
|
||||
# m123456,m123456type = length of tethers on each corner (m = 0 = no tether)
|
||||
|
||||
|
||||
def hex(self,*params):
|
||||
m1 = params[0]
|
||||
m2 = params[1]
|
||||
@ -809,7 +816,7 @@ class patch:
|
||||
m4type = params[10]
|
||||
m5type = params[11]
|
||||
m6type = params[12]
|
||||
|
||||
|
||||
atoms = []
|
||||
atoms.append([ntype,0.0,0.0,0.0])
|
||||
atoms.append([ntype,self.blen,0.0,0.0])
|
||||
@ -818,7 +825,7 @@ class patch:
|
||||
atoms.append([ntype,-self.blen/2.0,self.blen*sqrt(3.0)/2.0,0.0])
|
||||
atoms.append([ntype,self.blen/2.0,-self.blen*sqrt(3.0)/2.0,0.0])
|
||||
atoms.append([ntype,-self.blen/2.0,-self.blen*sqrt(3.0)/2.0,0.0])
|
||||
|
||||
|
||||
n = len(atoms)
|
||||
if m1: atoms += tether(m1,m1type,self.blen,self.dmin,
|
||||
atoms[0],atoms[1],self.random)
|
||||
@ -864,7 +871,7 @@ class patch:
|
||||
def dimer(self,*params):
|
||||
sep = params[0]
|
||||
type = params[1]
|
||||
|
||||
|
||||
atoms = []
|
||||
x,y,z = 0.0,0.0,0.0
|
||||
atoms.append([type,x,y,z])
|
||||
@ -885,9 +892,9 @@ class patch:
|
||||
sep = params[1]
|
||||
type = params[2]
|
||||
if n % 2 == 0:
|
||||
raise StandardError, "N in patch::star2d is not odd"
|
||||
raise Exception("N in patch::star2d is not odd")
|
||||
middle = n/2
|
||||
|
||||
|
||||
atoms = []
|
||||
x,y,z = 0.0,0.0,0.0
|
||||
atoms.append([type,x,y,z])
|
||||
@ -919,7 +926,7 @@ class patch:
|
||||
|
||||
height = (m-1) * sep
|
||||
width = (n-1) * sep
|
||||
|
||||
|
||||
atoms = []
|
||||
for i in range(n):
|
||||
x,y,z = i*sep,0.0,0.0
|
||||
@ -941,7 +948,7 @@ class patch:
|
||||
# params = a,type
|
||||
# a = edge length of tet
|
||||
# type = type of each vertex in tet
|
||||
|
||||
|
||||
def tritet(self,*params):
|
||||
a = params[0]
|
||||
type = params[1]
|
||||
@ -985,7 +992,7 @@ class patch:
|
||||
# Blo to Bhi = bounds of edge length in y of box
|
||||
# Clo to Chi = bounds of edge length in y of box
|
||||
# type = type of each vertex in rectangular box
|
||||
|
||||
|
||||
def tribox(self,*params):
|
||||
alo = params[0]
|
||||
ahi = params[1]
|
||||
@ -994,7 +1001,7 @@ class patch:
|
||||
clo = params[4]
|
||||
chi = params[5]
|
||||
type = params[6]
|
||||
|
||||
|
||||
a = alo + self.random()*(ahi-alo)
|
||||
b = blo + self.random()*(bhi-blo)
|
||||
c = clo + self.random()*(chi-clo)
|
||||
@ -1063,7 +1070,7 @@ class patch:
|
||||
# Alo to Ahi = bounds of edge length in x of rectangle
|
||||
# Blo to Bhi = bounds of edge length in y of rectangle
|
||||
# type = type of each line segment in rectangle
|
||||
|
||||
|
||||
def linebox(self,*params):
|
||||
alo = float(params[0])
|
||||
ahi = float(params[1])
|
||||
@ -1073,7 +1080,7 @@ class patch:
|
||||
|
||||
a = alo + self.random()*(ahi-alo)
|
||||
b = blo + self.random()*(bhi-blo)
|
||||
|
||||
|
||||
atoms = []
|
||||
segments = []
|
||||
|
||||
@ -1099,7 +1106,7 @@ class patch:
|
||||
# Alo to Ahi = bounds of base length in x of triangle
|
||||
# Blo to Bhi = bounds of heigth in y of isosceles triangle
|
||||
# type = type of each line segment in triangle
|
||||
|
||||
|
||||
def linetri(self,*params):
|
||||
alo = float(params[0])
|
||||
ahi = float(params[1])
|
||||
@ -1109,7 +1116,7 @@ class patch:
|
||||
|
||||
base = alo + self.random()*(ahi-alo)
|
||||
ht = blo + self.random()*(bhi-blo)
|
||||
|
||||
|
||||
atoms = []
|
||||
segments = []
|
||||
|
||||
@ -1131,7 +1138,7 @@ class patch:
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def random(self):
|
||||
k = self.seed/IQ
|
||||
k = self.seed//IQ
|
||||
self.seed = IA*(self.seed-k*IQ) - IR*k
|
||||
if self.seed < 0:
|
||||
self.seed += IM
|
||||
@ -1208,7 +1215,7 @@ TRI5_HOLLOW = ((0,0,0),(1,0,0),(2,0,0),(3,0,0),(4,0,0),
|
||||
(1.0,2*sqrt(3)/2,0),(3.0,2*sqrt(3)/2,0),
|
||||
(1.5,3*sqrt(3)/2,0),(2.5,3*sqrt(3)/2,0),
|
||||
(2.0,4*sqrt(3)/2,0))
|
||||
|
||||
|
||||
SIMPLE_7 = ((0,0,0),(1,0,0),(-1,0,0),(0,1,0),(0,-1,0),(0,0,1),(0,0,-1))
|
||||
|
||||
# C60 with added center point at end
|
||||
|
||||
@ -3,11 +3,20 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# pdb tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, types, glob
|
||||
try:
|
||||
import urllib.request, urllib.parse, urllib.error
|
||||
except ImportError:
|
||||
import urllib
|
||||
|
||||
oneline = "Read, write PDB files in combo with LAMMPS snapshots"
|
||||
|
||||
docstr = """
|
||||
@ -22,7 +31,7 @@ p = pdbfile("3CRO",d) read in single PDB file with snapshot data
|
||||
if only one 4-char file specified and it is not found,
|
||||
it will be downloaded from http://www.rcsb.org as 3CRO.pdb
|
||||
d arg is object with atom coordinates (dump, data)
|
||||
|
||||
|
||||
p.one() write all output as one big PDB file to tmp.pdb
|
||||
p.one("mine") write to mine.pdb
|
||||
p.many() write one PDB file per snapshot: tmp0000.pdb, ...
|
||||
@ -36,7 +45,7 @@ p.single(N,"new") write as new.pdb
|
||||
if one file in str arg and d: one new PDB file per snapshot
|
||||
using input PDB file as template
|
||||
multiple input PDB files with a d is not allowed
|
||||
|
||||
|
||||
index,time,flag = p.iterator(0)
|
||||
index,time,flag = p.iterator(1)
|
||||
|
||||
@ -62,10 +71,6 @@ index,time,flag = p.iterator(1)
|
||||
# atomlines = dict of ATOM lines in original PDB file
|
||||
# key = atom id, value = tuple of (beginning,end) of line
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, types, glob, urllib
|
||||
|
||||
# Class definition
|
||||
|
||||
class pdbfile:
|
||||
@ -74,7 +79,7 @@ class pdbfile:
|
||||
|
||||
def __init__(self,*args):
|
||||
if len(args) == 1:
|
||||
if type(args[0]) is types.StringType:
|
||||
if type(args[0]) is bytes:
|
||||
filestr = args[0]
|
||||
self.data = None
|
||||
else:
|
||||
@ -83,41 +88,41 @@ class pdbfile:
|
||||
elif len(args) == 2:
|
||||
filestr = args[0]
|
||||
self.data = args[1]
|
||||
else: raise StandardError, "invalid args for pdb()"
|
||||
else: raise Exception("invalid args for pdb()")
|
||||
|
||||
# flist = full list of all PDB input file names
|
||||
# append .pdb if needed
|
||||
|
||||
|
||||
if filestr:
|
||||
list = filestr.split()
|
||||
flist = []
|
||||
for file in list:
|
||||
if '*' in file: flist += glob.glob(file)
|
||||
else: flist.append(file)
|
||||
for i in xrange(len(flist)):
|
||||
for i in range(len(flist)):
|
||||
if flist[i][-4:] != ".pdb": flist[i] += ".pdb"
|
||||
if len(flist) == 0:
|
||||
raise StandardError,"no PDB file specified"
|
||||
raise Exception("no PDB file specified")
|
||||
self.files = flist
|
||||
else: self.files = []
|
||||
|
||||
if len(self.files) > 1 and self.data:
|
||||
raise StandardError, "cannot use multiple PDB files with data object"
|
||||
raise Exception("cannot use multiple PDB files with data object")
|
||||
if len(self.files) == 0 and not self.data:
|
||||
raise StandardError, "no input PDB file(s)"
|
||||
raise Exception("no input PDB file(s)")
|
||||
|
||||
# grab PDB file from http://rcsb.org if not a local file
|
||||
|
||||
|
||||
if len(self.files) == 1 and len(self.files[0]) == 8:
|
||||
try:
|
||||
open(self.files[0],'r').close()
|
||||
except:
|
||||
print "downloading %s from http://rcsb.org" % self.files[0]
|
||||
print("downloading %s from http://rcsb.org" % self.files[0])
|
||||
fetchstr = "http://www.rcsb.org/pdb/cgi/export.cgi/%s?format=PDB&pdbId=2cpk&compression=None" % self.files[0]
|
||||
urllib.urlretrieve(fetchstr,self.files[0])
|
||||
urllib.request.urlretrieve(fetchstr,self.files[0])
|
||||
|
||||
if self.data and len(self.files): self.read_template(self.files[0])
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write a single large PDB file for concatenating all input data or files
|
||||
# if data exists:
|
||||
@ -135,27 +140,27 @@ class pdbfile:
|
||||
f = open(file,'w')
|
||||
|
||||
# use template PDB file with each snapshot
|
||||
|
||||
|
||||
if self.data:
|
||||
n = flag = 0
|
||||
while 1:
|
||||
which,time,flag = self.data.iterator(flag)
|
||||
if flag == -1: break
|
||||
self.convert(f,which)
|
||||
print >>f,"END"
|
||||
print time,
|
||||
print("END", file=f)
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
else:
|
||||
for file in self.files:
|
||||
f.write(open(file,'r').read())
|
||||
print >>f,"END"
|
||||
print file,
|
||||
print("END", file=f)
|
||||
print(file, end=' ')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
f.close()
|
||||
print "\nwrote %d datasets to %s in PDB format" % (n,file)
|
||||
print("\nwrote %d datasets to %s in PDB format" % (n,file))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write series of numbered PDB files
|
||||
@ -189,8 +194,8 @@ class pdbfile:
|
||||
f = open(file,'w')
|
||||
self.convert(f,which)
|
||||
f.close()
|
||||
|
||||
print time,
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
@ -206,16 +211,16 @@ class pdbfile:
|
||||
else:
|
||||
file = root + str(n)
|
||||
file += ".pdb"
|
||||
|
||||
|
||||
f = open(file,'w')
|
||||
f.write(open(infile,'r').read())
|
||||
f.close()
|
||||
print file,
|
||||
print(file, end=' ')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
n += 1
|
||||
|
||||
print "\nwrote %d datasets to %s*.pdb in PDB format" % (n,root)
|
||||
print("\nwrote %d datasets to %s*.pdb in PDB format" % (n,root))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write a single PDB file
|
||||
@ -239,7 +244,7 @@ class pdbfile:
|
||||
self.convert(f,which)
|
||||
else:
|
||||
f.write(open(self.files[time],'r').read())
|
||||
|
||||
|
||||
f.close()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -258,8 +263,8 @@ class pdbfile:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# read a PDB file and store ATOM lines
|
||||
|
||||
def read_template(self,file):
|
||||
|
||||
def read_template(self,file):
|
||||
lines = open(file,'r').readlines()
|
||||
self.atomlines = {}
|
||||
for line in lines:
|
||||
@ -277,13 +282,13 @@ class pdbfile:
|
||||
if len(self.files):
|
||||
for atom in atoms:
|
||||
id = atom[0]
|
||||
if self.atomlines.has_key(id):
|
||||
if id in self.atomlines:
|
||||
(begin,end) = self.atomlines[id]
|
||||
line = "%s%8.3f%8.3f%8.3f%s" % (begin,atom[2],atom[3],atom[4],end)
|
||||
print >>f,line,
|
||||
print(line, end=' ', file=f)
|
||||
else:
|
||||
for atom in atoms:
|
||||
begin = "ATOM %6d %2d R00 1 " % (atom[0],atom[1])
|
||||
middle = "%8.3f%8.3f%8.3f" % (atom[2],atom[3],atom[4])
|
||||
end = " 1.00 0.00 NONE"
|
||||
print >>f,begin+middle+end
|
||||
print(begin+middle+end, file=f)
|
||||
|
||||
193
src/pizza.py
193
src/pizza.py
@ -5,7 +5,7 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# Change log:
|
||||
@ -15,6 +15,12 @@
|
||||
|
||||
# ToDo list:
|
||||
|
||||
# modules needed by pizza.py
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, os, string, glob, re
|
||||
import time
|
||||
|
||||
# Help strings:
|
||||
|
||||
version = "LPP 1.0 based on pizza - 7 Oct 2011"
|
||||
@ -26,12 +32,12 @@ type ? for help, CTRL-D to quit
|
||||
|
||||
help = """
|
||||
pizza.py switch arg(s) switch arg(s) ...
|
||||
-s silent (else print start-up help)
|
||||
-t log dump raster load only these tools
|
||||
-x raster rasmol load all tools except these
|
||||
-s silent (else print start-up help)
|
||||
-t log dump raster load only these tools
|
||||
-x raster rasmol load all tools except these
|
||||
-f mine.py arg1 arg2 run script file with args
|
||||
-c "vec = range(100)" run Python command
|
||||
-q quit (else interactive)
|
||||
-c "vec = range(100)" run Python command
|
||||
-q quit (else interactive)
|
||||
|
||||
Everything typed at the ">" prompt is a Python command
|
||||
|
||||
@ -39,29 +45,24 @@ Additional commands available at ">" prompt:
|
||||
? print help message
|
||||
?? one-line for each tool and script
|
||||
? raster list tool commands or script syntax
|
||||
?? energy.py full documentation of tool or script
|
||||
?? energy.py full documentation of tool or script
|
||||
!ls -l shell command
|
||||
@cd .. cd to a new directory
|
||||
@log tmp.log log all commands typed so far to file
|
||||
@run block.py arg1 arg2 run script file with args
|
||||
@time d = dump("*.dump") time a command
|
||||
|
||||
|
||||
Tools:
|
||||
"""
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# modules needed by pizza.py
|
||||
|
||||
import sys, commands, os, string, exceptions, glob, re
|
||||
from time import clock
|
||||
|
||||
# readline not available in all Pythons
|
||||
|
||||
try:
|
||||
import readline
|
||||
readline_flag = 1
|
||||
except ImportError, exception:
|
||||
print "readline option not available"
|
||||
except ImportError as exception:
|
||||
print("readline option not available")
|
||||
readline_flag = 0
|
||||
|
||||
# create global Tk root if Tkinter is loaded
|
||||
@ -72,10 +73,12 @@ try:
|
||||
import Tkinter
|
||||
tkroot = Tkinter.Tk()
|
||||
tkroot.withdraw()
|
||||
except ImportError, exception:
|
||||
nodisplay = True
|
||||
except ImportError as exception:
|
||||
import tkinter
|
||||
tkroot = tkinter.Tk()
|
||||
tkroot.withdraw()
|
||||
pass
|
||||
except Exception, exception:
|
||||
except Exception as exception:
|
||||
nodisplay = True
|
||||
pass
|
||||
|
||||
@ -86,13 +89,13 @@ def trap(type,value,tback):
|
||||
global argv
|
||||
|
||||
# only check SyntaxErrors
|
||||
|
||||
|
||||
if not isinstance(value,exceptions.SyntaxError):
|
||||
sys.__excepthook__(type,value,tback)
|
||||
return
|
||||
|
||||
|
||||
# special commands at top level only, not in indented text entry
|
||||
|
||||
|
||||
if value.text[0].isspace():
|
||||
sys.__excepthook__(type,value,tback)
|
||||
return
|
||||
@ -105,24 +108,24 @@ def trap(type,value,tback):
|
||||
|
||||
if value.text[0] == "?":
|
||||
words = value.text.split()
|
||||
|
||||
|
||||
if len(words) == 1 and words[0] == "?":
|
||||
print intro[1:] % version
|
||||
print help[1:]," ",
|
||||
for tool in tools: print tool,
|
||||
print
|
||||
|
||||
print(intro[1:] % version)
|
||||
print(help[1:]," ", end=' ')
|
||||
for tool in tools: print(tool, end=' ')
|
||||
print()
|
||||
|
||||
elif len(words) == 1 and words[0] == "??":
|
||||
for tool in tools:
|
||||
exec "oneline = oneline_%s" % tool
|
||||
print "%-11s%s" % (tool,oneline)
|
||||
print
|
||||
|
||||
exec("oneline = oneline_%s" % tool)
|
||||
print("%-11s%s" % (tool,oneline))
|
||||
print()
|
||||
|
||||
scripts = []
|
||||
for dir in PIZZA_SCRIPTS[1:]:
|
||||
list = glob.glob("%s/*.py" % dir)
|
||||
list.sort()
|
||||
scripts += list
|
||||
flist = glob.glob("%s/*.py" % dir)
|
||||
flist.sort()
|
||||
scripts += flist
|
||||
for script in scripts:
|
||||
filename = os.path.basename(script)
|
||||
lines = open(script,'r').readlines()
|
||||
@ -133,8 +136,8 @@ def trap(type,value,tback):
|
||||
break
|
||||
if flag: doc = line[line.find("Purpose:")+8:]
|
||||
else: doc = " not available\n"
|
||||
print "%-20s%s" % (filename,doc),
|
||||
|
||||
print("%-20s%s" % (filename,doc), end=' ')
|
||||
|
||||
elif len(words) == 2 and words[0] == "?":
|
||||
if words[1][-3:] == ".py":
|
||||
fileflag = 0
|
||||
@ -145,26 +148,26 @@ def trap(type,value,tback):
|
||||
lineflag = 0
|
||||
lines = open(filename,'r').readlines()
|
||||
for line in lines:
|
||||
if line.find("# Purpose:") >= 0: print line[2:],
|
||||
if line.find("# Purpose:") >= 0: print(line[2:], end=' ')
|
||||
if line.find("# Syntax:") >= 0:
|
||||
lineflag = 1
|
||||
break
|
||||
if not lineflag: print "%s has no Syntax line" % words[1]
|
||||
else: print line[2:],
|
||||
if not lineflag: print("%s has no Syntax line" % words[1])
|
||||
else: print(line[2:], end=' ')
|
||||
break
|
||||
if not fileflag:
|
||||
print "%s is not a recognized script" % words[1]
|
||||
|
||||
print("%s is not a recognized script" % words[1])
|
||||
|
||||
else:
|
||||
if words[1] in tools:
|
||||
exec "txt = docstr_%s" % words[1]
|
||||
exec("txt = docstr_%s" % words[1])
|
||||
txt = re.sub("\n\s*\n","\n",txt)
|
||||
txt = re.sub("\n .*","",txt)
|
||||
exec "print oneline_%s" % words[1]
|
||||
print txt
|
||||
exec("print oneline_%s" % words[1])
|
||||
print(txt)
|
||||
else:
|
||||
print "%s is not a recognized tool" % words[1]
|
||||
|
||||
print("%s is not a recognized tool" % words[1])
|
||||
|
||||
elif len(words) == 2 and words[0] == "??":
|
||||
if words[1][-3:] == ".py":
|
||||
fileflag = 0
|
||||
@ -175,19 +178,19 @@ def trap(type,value,tback):
|
||||
lines = open(filename,'r').readlines()
|
||||
for line in lines:
|
||||
if len(line.strip()) == 0: continue
|
||||
if line[0] == '#': print line,
|
||||
if line[0] == '#': print(line, end=' ')
|
||||
else: break
|
||||
break
|
||||
if not fileflag:
|
||||
print "%s is not a recognized script" % words[1]
|
||||
print("%s is not a recognized script" % words[1])
|
||||
|
||||
else:
|
||||
if words[1] in tools:
|
||||
exec "print oneline_%s" % words[1]
|
||||
exec "print docstr_%s" % words[1]
|
||||
exec("print oneline_%s" % words[1])
|
||||
exec("print docstr_%s" % words[1])
|
||||
else:
|
||||
print "%s is not a recognized class" % words[1]
|
||||
|
||||
print("%s is not a recognized class" % words[1])
|
||||
|
||||
return
|
||||
|
||||
# shell command like !ls, !ls -l
|
||||
@ -200,7 +203,7 @@ def trap(type,value,tback):
|
||||
# for run and time, use namespace in execfile and exec commands
|
||||
# else variables defined in script/command
|
||||
# won't be set in top-level Pizza.py
|
||||
|
||||
|
||||
if value.text[0] == "@":
|
||||
words = value.text.split()
|
||||
if words[0][1:] == "cd":
|
||||
@ -208,13 +211,13 @@ def trap(type,value,tback):
|
||||
return
|
||||
elif words[0][1:] == "log":
|
||||
if readline_flag == 0:
|
||||
print "cannot use @log without readline module"
|
||||
print("cannot use @log without readline module")
|
||||
return
|
||||
f = open(words[1],"w")
|
||||
print >>f,"# pizza.py log file\n"
|
||||
print("# pizza.py log file\n", file=f)
|
||||
nlines = readline.get_current_history_length()
|
||||
for i in xrange(1,nlines):
|
||||
print >>f,readline.get_history_item(i)
|
||||
for i in range(1,nlines):
|
||||
print(readline.get_history_item(i), file=f)
|
||||
f.close()
|
||||
return
|
||||
elif words[0][1:] == "run":
|
||||
@ -225,21 +228,21 @@ def trap(type,value,tback):
|
||||
fullfile = dir + '/' + file
|
||||
if os.path.exists(fullfile):
|
||||
flag = 1
|
||||
print "Executing file:",fullfile
|
||||
execfile(fullfile,namespace)
|
||||
print("Executing file:",fullfile)
|
||||
exec(compile(open(fullfile).read(), fullfile, 'exec'),namespace)
|
||||
break
|
||||
if not flag: print "Could not find file",file
|
||||
if not flag: print("Could not find file",file)
|
||||
return
|
||||
elif words[0][1:] == "time":
|
||||
cmd = string.join(words[1:])
|
||||
t1 = clock()
|
||||
exec cmd in namespace
|
||||
exec(cmd, namespace)
|
||||
t2 = clock()
|
||||
print "CPU time = ",t2-t1
|
||||
print("CPU time = ",t2-t1)
|
||||
return
|
||||
|
||||
|
||||
# unrecognized command, let system handle error
|
||||
|
||||
|
||||
sys.__excepthook__(type,value,tback)
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
@ -255,7 +258,7 @@ quitflag = 0
|
||||
iarg = 1
|
||||
while (iarg < len(sys.argv)):
|
||||
if (sys.argv[iarg][0] != '-'):
|
||||
print "ERROR: arg is not a switch: %s" % (sys.argv[iarg])
|
||||
print("ERROR: arg is not a switch: %s" % (sys.argv[iarg]))
|
||||
sys.exit()
|
||||
if (sys.argv[iarg] == "-s"):
|
||||
silent = 1
|
||||
@ -274,51 +277,51 @@ while (iarg < len(sys.argv)):
|
||||
iarg = jarg
|
||||
elif (sys.argv[iarg] == "-f"):
|
||||
jarg = iarg + 1
|
||||
list = []
|
||||
flist = []
|
||||
while (jarg < len(sys.argv) and sys.argv[jarg][0] != '-'):
|
||||
list.append(sys.argv[jarg])
|
||||
flist.append(sys.argv[jarg])
|
||||
jarg += 1
|
||||
task = ("script",list)
|
||||
task = ("script",flist)
|
||||
tasks.append(task)
|
||||
iarg = jarg
|
||||
elif (sys.argv[iarg] == "-c"):
|
||||
jarg = iarg + 1
|
||||
list = []
|
||||
clist = []
|
||||
while (jarg < len(sys.argv) and sys.argv[jarg][0] != '-'):
|
||||
list.append(sys.argv[jarg])
|
||||
clist.append(sys.argv[jarg])
|
||||
jarg += 1
|
||||
task = ("command",list)
|
||||
task = ("command",clist)
|
||||
tasks.append(task)
|
||||
iarg = jarg
|
||||
elif (sys.argv[iarg] == "-q"):
|
||||
quitflag = 1
|
||||
iarg += 1
|
||||
else:
|
||||
print "ERROR: unknown switch: %s" % (sys.argv[iarg])
|
||||
print("ERROR: unknown switch: %s" % (sys.argv[iarg]))
|
||||
sys.exit()
|
||||
|
||||
# print intro message
|
||||
|
||||
if not silent: print intro[1:] % version,
|
||||
if not silent: print(intro[1:] % version, end=' ')
|
||||
|
||||
# error test on m,x command-line switches
|
||||
|
||||
if len(yes_tools) > 0 and len(no_tools) > 0:
|
||||
print "ERROR: cannot use -t and -x switches together"
|
||||
print("ERROR: cannot use -t and -x switches together")
|
||||
sys.exit()
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# tools = list of tool names to import
|
||||
# if -t switch was used, tools = just those files
|
||||
# else scan for *.py files in all dirs in PIZZA_TOOLS list
|
||||
# and then Pizza.py src dir (sys.path[0])
|
||||
|
||||
if not silent: print "Loading tools ..."
|
||||
if not silent and nodisplay: print "Display not available ... no GUIs"
|
||||
if not silent: print("Loading tools ...")
|
||||
if not silent and nodisplay: print("Display not available ... no GUIs")
|
||||
|
||||
try: from DEFAULTS import PIZZA_TOOLS
|
||||
except: PIZZA_TOOLS = []
|
||||
PIZZA_TOOLS = map(os.path.expanduser,PIZZA_TOOLS)
|
||||
PIZZA_TOOLS = list(map(os.path.expanduser,PIZZA_TOOLS))
|
||||
PIZZA_TOOLS.append(sys.path[0])
|
||||
|
||||
if len(yes_tools) > 0: tools = yes_tools
|
||||
@ -359,12 +362,12 @@ for tool in tools:
|
||||
failed.append(tool)
|
||||
continue
|
||||
try:
|
||||
exec "from %s import %s" % (tool,tool)
|
||||
exec "from %s import oneline as oneline_%s" % (tool,tool)
|
||||
exec "from %s import docstr as docstr_%s" % (tool,tool)
|
||||
except Exception, exception:
|
||||
print "%s tool did not load:" % tool
|
||||
print " ",exception
|
||||
exec("from %s import %s" % (tool,tool))
|
||||
exec("from %s import oneline as oneline_%s" % (tool,tool))
|
||||
exec("from %s import docstr as docstr_%s" % (tool,tool))
|
||||
except Exception as exception:
|
||||
print("%s tool did not load:" % tool)
|
||||
print(" ",exception)
|
||||
failed.append(tool)
|
||||
|
||||
for dir in PIZZA_TOOLS: sys.path = sys.path[1:]
|
||||
@ -384,7 +387,7 @@ sys.path.insert(0,'')
|
||||
|
||||
try: from DEFAULTS import PIZZA_SCRIPTS
|
||||
except: PIZZA_SCRIPTS = []
|
||||
PIZZA_SCRIPTS = map(os.path.expanduser,PIZZA_SCRIPTS)
|
||||
PIZZA_SCRIPTS = list(map(os.path.expanduser,PIZZA_SCRIPTS))
|
||||
PIZZA_SCRIPTS.insert(0,'.')
|
||||
PIZZA_SCRIPTS.append(sys.path[1][:-3] + "scripts") # path for pizza.py
|
||||
|
||||
@ -403,28 +406,28 @@ for task in tasks:
|
||||
for dir in PIZZA_SCRIPTS:
|
||||
fullfile = dir + '/' + file
|
||||
if os.path.exists(fullfile):
|
||||
print "Executing file:",fullfile
|
||||
execfile(fullfile)
|
||||
print("Executing file:",fullfile)
|
||||
exec(compile(open(fullfile).read(), fullfile, 'exec'))
|
||||
flag = 1
|
||||
break
|
||||
if not flag: print "Could not find file",file
|
||||
except StandardError, exception:
|
||||
if not flag: print("Could not find file",file)
|
||||
except Exception as exception:
|
||||
(type,value,tback) = sys.exc_info()
|
||||
print type,value,tback
|
||||
print(type,value,tback)
|
||||
type = str(type)
|
||||
type = type[type.find(".")+1:]
|
||||
print "%s with value: %s" % (type,value)
|
||||
print("%s with value: %s" % (type,value))
|
||||
tback = tback.tb_next
|
||||
while tback:
|
||||
print "error on line %d of file %s" % \
|
||||
(tback.tb_lineno,tback.tb_frame.f_code.co_filename)
|
||||
print("error on line %d of file %s" % \
|
||||
(tback.tb_lineno,tback.tb_frame.f_code.co_filename))
|
||||
tback = tback.tb_next
|
||||
elif task[0] == "command":
|
||||
argv = task[1]
|
||||
cmd = ""
|
||||
for arg in argv: cmd += arg + " "
|
||||
exec cmd
|
||||
|
||||
exec(cmd)
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# store global namespace
|
||||
# swap in a new exception handler
|
||||
|
||||
@ -3,11 +3,20 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# plotview tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, re, glob, time
|
||||
try:
|
||||
from Tkinter import *
|
||||
except ImportError:
|
||||
from tkinter import *
|
||||
|
||||
oneline = "Plot multiple vectors from a data set"
|
||||
|
||||
docstr = """
|
||||
@ -46,11 +55,6 @@ p.save() save currently selected plot to file.eps
|
||||
# checkvars = list of status of check buttons
|
||||
# checkold = list of status of check buttons before click
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, re, glob, time
|
||||
from Tkinter import *
|
||||
|
||||
# Class definition
|
||||
|
||||
class plotview:
|
||||
@ -62,27 +66,27 @@ class plotview:
|
||||
self.plot = plot
|
||||
|
||||
# create GUI
|
||||
|
||||
|
||||
from __main__ import tkroot
|
||||
root = Toplevel(tkroot)
|
||||
root.title('Pizza.py plotview tool')
|
||||
|
||||
|
||||
self.frame1 = Frame(root)
|
||||
self.frame2 = Frame(root)
|
||||
self.frame3 = Frame(root)
|
||||
|
||||
|
||||
Button(self.frame1,text="Print As:",command=self.save).pack(side=TOP)
|
||||
self.entry = Entry(self.frame1,width=16)
|
||||
self.entry.insert(0,"tmp")
|
||||
self.entry.pack(side=TOP)
|
||||
|
||||
|
||||
Label(self.frame2,text="Select").pack(side=LEFT)
|
||||
Label(self.frame2,text = "Display").pack(side=RIGHT)
|
||||
|
||||
self.nplots = source.nvec
|
||||
self.names = source.names
|
||||
self.x = self.names[0]
|
||||
|
||||
|
||||
self.radiovar = IntVar()
|
||||
self.checkbuttons = []
|
||||
self.checkvars = []
|
||||
@ -91,18 +95,18 @@ class plotview:
|
||||
# for each vector (not including 1st)
|
||||
# create a plot and title it
|
||||
# create a line in GUI with selection and check button
|
||||
|
||||
|
||||
for i in range(self.nplots):
|
||||
self.plot.select(i+1)
|
||||
self.plot.xtitle(self.x)
|
||||
self.plot.ytitle(self.names[i])
|
||||
self.plot.title(self.names[i])
|
||||
|
||||
|
||||
b = BooleanVar()
|
||||
b.set(0)
|
||||
self.checkvars.append(b)
|
||||
self.checkold.append(0)
|
||||
|
||||
|
||||
line = Frame(self.frame3)
|
||||
rtitle = "%d %s" % (i+1,self.names[i])
|
||||
Radiobutton(line, text=rtitle, value=i+1, variable=self.radiovar,
|
||||
@ -119,7 +123,7 @@ class plotview:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# set radio button and checkbox
|
||||
|
||||
|
||||
def select(self,n):
|
||||
self.plot.select(n)
|
||||
self.radiovar.set(n)
|
||||
@ -130,7 +134,7 @@ class plotview:
|
||||
|
||||
def yes(self,n):
|
||||
if not self.checkvars[n-1].get(): self.checkbuttons[n-1].invoke()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# only invoke if currently set
|
||||
|
||||
@ -143,18 +147,18 @@ class plotview:
|
||||
oldtext = self.entry.get()
|
||||
self.entry.delete(0,len(oldtext))
|
||||
self.entry.insert(0,newtext)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def save(self):
|
||||
n = self.radiovar.get()
|
||||
if n == 0: raise StandardError,"no plot selected"
|
||||
if n == 0: raise Exception("no plot selected")
|
||||
name = self.entry.get()
|
||||
self.plot.save(name)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# called when any radio selection button is clicked
|
||||
|
||||
|
||||
def radioselect(self):
|
||||
self.select(self.radiovar.get())
|
||||
|
||||
@ -163,7 +167,7 @@ class plotview:
|
||||
# draws or hides plot
|
||||
# loop is to find which checkbox changed status
|
||||
# grab x,y data to plot out of source object
|
||||
|
||||
|
||||
def check(self):
|
||||
for i in range(self.nplots):
|
||||
if int(self.checkvars[i].get()) != self.checkold[i]:
|
||||
|
||||
@ -3,11 +3,21 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# rasmol tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, os, re, types
|
||||
try:
|
||||
import commands
|
||||
except ImportError:
|
||||
import subprocess as commands
|
||||
from pdbfile import pdbfile
|
||||
|
||||
oneline = "3d visualization via RasMol program"
|
||||
|
||||
docstr = """
|
||||
@ -20,7 +30,7 @@ r.show(N,"my.rasmol") use file as RasMol script
|
||||
|
||||
r.all() make images of all selected snapshots with def script
|
||||
r.all("my.rasmol") use file as RasMol script
|
||||
|
||||
|
||||
r.run(N) run RasMol interactivly on snapshot N
|
||||
r.run(N,"new.rasmol") adjust via mouse or RasMol commands
|
||||
r.run(N,"new.rasmol","old.rasmol") type quit to save RasMol script file
|
||||
@ -38,11 +48,6 @@ r.run(N,"new.rasmol","old.rasmol") type quit to save RasMol script file
|
||||
|
||||
# Variables
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, os, commands, re, types
|
||||
from pdbfile import pdbfile
|
||||
|
||||
try: from DEFAULTS import PIZZA_RASMOL
|
||||
except: PIZZA_RASMOL = "rasmol"
|
||||
try: from DEFAULTS import PIZZA_DISPLAY
|
||||
@ -57,7 +62,7 @@ class rasmol:
|
||||
def __init__(self,pdb):
|
||||
self.pdb = pdb
|
||||
self.file = "image"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def start(self):
|
||||
@ -67,7 +72,7 @@ class rasmol:
|
||||
|
||||
def enter(self):
|
||||
while 1:
|
||||
command = raw_input("rasmol> ")
|
||||
command = input("rasmol> ")
|
||||
if command == "quit" or command == "exit": return
|
||||
self.__call__(command)
|
||||
|
||||
@ -85,56 +90,56 @@ class rasmol:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def show(self,*list):
|
||||
def show(self,*arglist):
|
||||
|
||||
# create tmp.pdb with atom data
|
||||
|
||||
n = list[0]
|
||||
|
||||
n = arglist[0]
|
||||
self.pdb.single(n,"tmp.pdb")
|
||||
|
||||
# if RasMol input script specified, read it
|
||||
# replace load pdb "file" with load pdb "%s"
|
||||
# if no RasMol input script specified, use rasmol_template
|
||||
|
||||
if len(list) == 2:
|
||||
rasmol_text = open(list[1],"r").read()
|
||||
if len(arglist) == 2:
|
||||
rasmol_text = open(arglist[1],"r").read()
|
||||
rasmol_text = re.sub('load pdb ".*"','load pdb "%s"',rasmol_text)
|
||||
else:
|
||||
rasmol_text = rasmol_template
|
||||
|
||||
# write rasmol_text to tmp.rasmol, substituting tmp.pdb for filename
|
||||
|
||||
|
||||
f = open("tmp.rasmol","w")
|
||||
text = rasmol_text % "tmp.pdb"
|
||||
print >>f,text
|
||||
print(text, file=f)
|
||||
f.close()
|
||||
|
||||
# run RasMol to create image in tmp.gif
|
||||
|
||||
|
||||
self.start()
|
||||
self.__call__("source tmp.rasmol")
|
||||
self.__call__("write tmp.gif")
|
||||
self.stop()
|
||||
|
||||
# display the image
|
||||
|
||||
|
||||
cmd = "%s tmp.gif" % (PIZZA_DISPLAY)
|
||||
commands.getoutput(cmd)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def all(self,*list):
|
||||
def all(self,*arglist):
|
||||
|
||||
# if RasMol script specified, read it
|
||||
# replace load pdb "file" with load pdb "%s"
|
||||
# if no RasMol script specified, just use rasmol_template
|
||||
|
||||
if len(list) == 1:
|
||||
rasmol_text = open(list[0],"r").read()
|
||||
if len(arglist) == 1:
|
||||
rasmol_text = open(arglist[0],"r").read()
|
||||
rasmol_text = re.sub('load pdb ".*"','load pdb "%s"',rasmol_text)
|
||||
else:
|
||||
rasmol_text = rasmol_template
|
||||
|
||||
|
||||
# iterate over all timesteps
|
||||
# write snapshot to tmpN.pdb
|
||||
# write RasMol input script to tmpN.rasmol
|
||||
@ -160,10 +165,10 @@ class rasmol:
|
||||
text = rasmol_text % file_pdb
|
||||
file_rasmol = "tmp%s.rasmol" % ncount
|
||||
f = open(file_rasmol,"w")
|
||||
print >>f,text
|
||||
print(text, file=f)
|
||||
f.close()
|
||||
|
||||
print time,
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
@ -172,7 +177,7 @@ class rasmol:
|
||||
self.start()
|
||||
|
||||
loop = n
|
||||
for n in xrange(loop):
|
||||
for n in range(loop):
|
||||
if n < 10:
|
||||
ncount = "000" + str(n)
|
||||
elif n < 100:
|
||||
@ -193,40 +198,40 @@ class rasmol:
|
||||
|
||||
commands.getoutput("rm tmp*.pdb")
|
||||
commands.getoutput("rm tmp*.rasmol")
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def run(self,*list):
|
||||
def run(self,*arglist):
|
||||
|
||||
# create tmp.pdb with atom data
|
||||
|
||||
n = list[0]
|
||||
n = arglist[0]
|
||||
self.pdb.single(n,"tmp.pdb")
|
||||
|
||||
# if RasMol script specified, read it
|
||||
# replace load pdb "file" with load pdb "%s"
|
||||
# if no RasMol script specified, just use rasmol_template
|
||||
|
||||
if len(list) == 3:
|
||||
rasmol_text = open(list[2],"r").read()
|
||||
if len(arglist) == 3:
|
||||
rasmol_text = open(arglist[2],"r").read()
|
||||
rasmol_text = re.sub('load pdb ".*"','load pdb "%s"',rasmol_text)
|
||||
else:
|
||||
rasmol_text = rasmol_template
|
||||
|
||||
# write rasmol_text to tmp.rasmol
|
||||
|
||||
|
||||
f = open("tmp.rasmol","w")
|
||||
text = rasmol_template % "tmp.pdb"
|
||||
print >>f,text
|
||||
print(text, file=f)
|
||||
f.close()
|
||||
|
||||
# run RasMol to create image in tmp.gif
|
||||
|
||||
|
||||
self.start()
|
||||
self.__call__("source tmp.rasmol")
|
||||
self.enter()
|
||||
|
||||
if len(list) > 1: newfile = list[1]
|
||||
|
||||
if len(arglist) > 1: newfile = arglist[1]
|
||||
else: newfile = "tmp.rasmol"
|
||||
self.__call__("write script %s" % newfile)
|
||||
self.stop()
|
||||
|
||||
245
src/raster.py
245
src/raster.py
@ -3,11 +3,22 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# raster tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, os, re
|
||||
try:
|
||||
import commands
|
||||
except ImportError:
|
||||
import subprocess as commands
|
||||
from vizinfo import vizinfo
|
||||
from math import fabs,atan,cos,sin
|
||||
|
||||
oneline = "3d visualization via Raster3d program"
|
||||
|
||||
docstr = """
|
||||
@ -16,8 +27,8 @@ r = raster(d) create Raster3d wrapper for data in d
|
||||
d = atom snapshot object (dump, data)
|
||||
|
||||
r.bg("black") set background color (def = "black")
|
||||
r.size(N) set image size to NxN
|
||||
r.size(N,M) set image size to NxM
|
||||
r.size(N) set image size to NxN
|
||||
r.size(N,M) set image size to NxM
|
||||
r.rotate(60,135) view from z theta and azimuthal phi (def = 60,30)
|
||||
r.shift(x,y) translate by x,y pixels in view window (def = 0,0)
|
||||
r.zoom(0.5) scale image by factor (def = 1)
|
||||
@ -27,7 +38,7 @@ r.box(0/1/2,"red",4) set box edge thickness
|
||||
r.file = "image" file prefix for created images (def = "image")
|
||||
|
||||
r.show(N) show image of snapshot at timestep N
|
||||
|
||||
|
||||
r.all() make images of all selected snapshots
|
||||
r.all(P) images of all, start file label at P
|
||||
r.all(N,M,P) make M images of snapshot N, start label at P
|
||||
@ -40,18 +51,18 @@ r.pan() no pan during all() (default)
|
||||
|
||||
r.select = "$x > %g*3.0" string to pass to d.aselect.test() during all()
|
||||
r.select = "" no extra aselect (default)
|
||||
|
||||
|
||||
%g varies from 0.0 to 1.0 from beginning to end of all()
|
||||
|
||||
r.label(x,y,"h",size,"red","This is a label") add label to each image
|
||||
r.nolabel() delete all labels
|
||||
|
||||
|
||||
x,y coords = -0.5 to 0.5, "h" or "t" for Helvetica or Times font
|
||||
size = fontsize (e.g. 10), "red" = color of text
|
||||
|
||||
r.acol(2,"green") set atom colors by atom type (1-N)
|
||||
r.acol([2,4],["red","blue"]) 1st arg = one type or list of types
|
||||
r.acol(0,"blue") 2nd arg = one color or list of colors
|
||||
|
||||
r.acol(2,"green") set atom colors by atom type (1-N)
|
||||
r.acol([2,4],["red","blue"]) 1st arg = one type or list of types
|
||||
r.acol(0,"blue") 2nd arg = one color or list of colors
|
||||
r.acol(range(20),["red","blue"]) if list lengths unequal, interpolate
|
||||
r.acol(range(10),"loop") assign colors in loop, randomly ordered
|
||||
|
||||
@ -61,23 +72,23 @@ r.acol(range(10),"loop") assign colors in loop, randomly ordered
|
||||
|
||||
r.arad([1,2],[0.5,0.3]) set atom radii, same rules as acol()
|
||||
|
||||
r.bcol() set bond color, same args as acol()
|
||||
r.brad() set bond thickness, same args as arad()
|
||||
r.bcol() set bond color, same args as acol()
|
||||
r.brad() set bond thickness, same args as arad()
|
||||
|
||||
r.tcol() set triangle color, same args as acol()
|
||||
r.tfill() set triangle fill, 0 fill, 1 line, 2 both
|
||||
r.tcol() set triangle color, same args as acol()
|
||||
r.tfill() set triangle fill, 0 fill, 1 line, 2 both
|
||||
|
||||
r.lcol() set line color, same args as acol()
|
||||
r.lrad() set line thickness, same args as arad()
|
||||
|
||||
r.adef() set atom/bond/tri/line properties to default
|
||||
r.bdef() default = "loop" for colors, 0.45 for radii
|
||||
r.tdef() default = 0.25 for bond/line thickness
|
||||
r.ldef() default = 0 fill
|
||||
r.bdef() default = "loop" for colors, 0.45 for radii
|
||||
r.tdef() default = 0.25 for bond/line thickness
|
||||
r.ldef() default = 0 fill
|
||||
|
||||
by default 100 types are assigned
|
||||
if atom/bond/tri/line has type > # defined properties, is an error
|
||||
|
||||
|
||||
from vizinfo import colors access color list
|
||||
print colors list defined color names and RGB values
|
||||
colors["nickname"] = [R,G,B] set new RGB values from 0 to 255
|
||||
@ -108,16 +119,10 @@ colors["nickname"] = [R,G,B] set new RGB values from 0 to 255
|
||||
# vizinfo = scene attributes
|
||||
# xtrans,ytrans,ztrans = translation factors computed by Raster3d
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, os, commands, re
|
||||
from vizinfo import vizinfo
|
||||
from math import fabs,atan,cos,sin
|
||||
|
||||
try: from DEFAULTS import PIZZA_RENDER
|
||||
except: PIZZA_RENDER = "render"
|
||||
try: from DEFAULTS import PIZZA_LABEL3D
|
||||
except: PIZZA_LABEL3D = "label3d"
|
||||
except: PIZZA_LABEL3D = "render -labels"
|
||||
try: from DEFAULTS import PIZZA_DISPLAY
|
||||
except: PIZZA_DISPLAY = "display"
|
||||
|
||||
@ -136,7 +141,7 @@ class raster:
|
||||
self.scale = 1.0
|
||||
self.xshift = self.yshift = 0
|
||||
self.eye = 50.0
|
||||
|
||||
|
||||
self.file = "image"
|
||||
self.boxflag = 0
|
||||
self.bxcol = [1,1,0]
|
||||
@ -152,20 +157,22 @@ class raster:
|
||||
self.tdef()
|
||||
self.ldef()
|
||||
|
||||
os.environ["TMPDIR"] = "/tmp"
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def bg(self,color):
|
||||
from vizinfo import colors
|
||||
self.bgcol = [colors[color][0]/255.0,colors[color][1]/255.0,
|
||||
colors[color][2]/255.0]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def size(self,xnew,ynew=None):
|
||||
self.xpixels = xnew
|
||||
if not ynew: self.ypixels = self.xpixels
|
||||
else: self.ypixels = ynew
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def rotate(self,ztheta,azphi):
|
||||
@ -182,7 +189,7 @@ class raster:
|
||||
|
||||
def zoom(self,scale):
|
||||
self.scale = scale;
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def box(self,*args):
|
||||
@ -195,7 +202,7 @@ class raster:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# scale down point-size by 3x
|
||||
|
||||
|
||||
def label(self,x,y,font,point,color,text):
|
||||
from vizinfo import colors
|
||||
scaledcolor = [colors[color][0]/255.0,colors[color][1]/255.0,
|
||||
@ -207,12 +214,12 @@ class raster:
|
||||
|
||||
def nolabel(self):
|
||||
self.labels = []
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# show a single snapshot
|
||||
# distance from snapshot box or max box for all selected steps
|
||||
# always pre-call single() to re-center simulation data
|
||||
|
||||
|
||||
def show(self,ntime):
|
||||
data = self.data
|
||||
which = data.findtime(ntime)
|
||||
@ -222,12 +229,12 @@ class raster:
|
||||
|
||||
self.xtrans = self.ytrans = self.ztrans = 0.0
|
||||
output = self.single(1,self.file,box,atoms,bonds,tris,lines)
|
||||
print output
|
||||
print(output)
|
||||
nums = re.findall("translation to:\s*(\S*)\s*(\S*)\s*(\S*)\s",output)
|
||||
self.xtrans = float(nums[0][0])
|
||||
self.ytrans = float(nums[0][1])
|
||||
self.ztrans = float(nums[0][2])
|
||||
|
||||
|
||||
self.single(0,self.file,box,atoms,bonds,tris,lines)
|
||||
cmd = "%s %s.png" % (PIZZA_DISPLAY,self.file)
|
||||
commands.getoutput(cmd)
|
||||
@ -244,7 +251,7 @@ class raster:
|
||||
self.ztheta_stop = list[3]
|
||||
self.azphi_stop = list[4]
|
||||
self.scale_stop = list[5]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def all(self,*list):
|
||||
@ -275,7 +282,7 @@ class raster:
|
||||
if flag == -1: break
|
||||
|
||||
fraction = float(i) / (ncount-1)
|
||||
|
||||
|
||||
if self.select != "":
|
||||
newstr = self.select % fraction
|
||||
data.aselect.test(newstr,time)
|
||||
@ -297,16 +304,16 @@ class raster:
|
||||
self.scale = self.scale_start + \
|
||||
fraction*(self.scale_stop - self.scale_start)
|
||||
|
||||
if n == nstart or self.panflag:
|
||||
if n == nstart or self.panflag:
|
||||
self.xtrans = self.ytrans = self.ztrans = 0.0
|
||||
output = self.single(1,file,box,atoms,bonds,tris,lines)
|
||||
output = self.single(1,file,box,atoms,bonds,tris,lines)
|
||||
nums = re.findall("translation to:\s*(\S*)\s*(\S*)\s*(\S*)\s",output)
|
||||
self.xtrans = float(nums[0][0])
|
||||
self.ytrans = float(nums[0][1])
|
||||
self.ztrans = float(nums[0][2])
|
||||
|
||||
self.single(0,file,box,atoms,bonds,tris,lines)
|
||||
print time,
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
i += 1
|
||||
n += 1
|
||||
@ -344,20 +351,20 @@ class raster:
|
||||
self.scale = self.scale_start + \
|
||||
fraction*(self.scale_stop - self.scale_start)
|
||||
|
||||
if n == nstart or self.panflag:
|
||||
if n == nstart or self.panflag:
|
||||
self.xtrans = self.ytrans = self.ztrans = 0.0
|
||||
output = self.single(1,file,box,atoms,bonds,tris,lines)
|
||||
output = self.single(1,file,box,atoms,bonds,tris,lines)
|
||||
nums = re.findall("translation to:\s*(\S*)\s*(\S*)\s*(\S*)\s",output)
|
||||
self.xtrans = float(nums[0][0])
|
||||
self.ytrans = float(nums[0][1])
|
||||
self.ztrans = float(nums[0][2])
|
||||
|
||||
|
||||
self.single(0,file,box,atoms,bonds,tris,lines)
|
||||
print n,
|
||||
print(n, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
print "\n%d images" % ncount
|
||||
print("\n%d images" % ncount)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
@ -374,65 +381,65 @@ class raster:
|
||||
(self.xpixels,self.ypixels,color[0],color[1],color[2],
|
||||
self.eye,matrix,self.xtrans+xshift,self.ytrans+yshift,
|
||||
self.ztrans,1.6*self.distance/self.scale)
|
||||
print >>f,header,
|
||||
print(header, end=' ', file=f)
|
||||
|
||||
# draw box if boxflag or flag is set
|
||||
# flag = 1 is a pre-call of single to set frame size correctly
|
||||
# this keeps the view fixed even if atoms move around
|
||||
|
||||
|
||||
if self.boxflag or flag: box_write(f,box,self.bxcol,self.bxthick)
|
||||
|
||||
ncolor = self.vizinfo.nacolor
|
||||
for atom in atoms:
|
||||
itype = int(atom[1])
|
||||
if itype > ncolor: raise StandardError,"atom type too big"
|
||||
if itype > ncolor: raise Exception("atom type too big")
|
||||
color = self.vizinfo.acolor[itype]
|
||||
rad = self.vizinfo.arad[itype]
|
||||
print >>f,2
|
||||
print >>f,atom[2],atom[3],atom[4],rad,color[0],color[1],color[2]
|
||||
print(2, file=f)
|
||||
print(atom[2],atom[3],atom[4],rad,color[0],color[1],color[2], file=f)
|
||||
|
||||
# need to include vizinfo.tfill options
|
||||
|
||||
ncolor = self.vizinfo.ntcolor
|
||||
for tri in tris:
|
||||
itype = int(tri[1])
|
||||
if itype > ncolor: raise StandardError,"tri type too big"
|
||||
if itype > ncolor: raise Exception("tri type too big")
|
||||
color = self.vizinfo.tcolor[itype]
|
||||
print >>f,1
|
||||
print >>f,tri[2],tri[3],tri[4],tri[5],tri[6],tri[7], \
|
||||
tri[8],tri[9],tri[10],color[0],color[1],color[2]
|
||||
print(1, file=f)
|
||||
print(tri[2],tri[3],tri[4],tri[5],tri[6],tri[7], \
|
||||
tri[8],tri[9],tri[10],color[0],color[1],color[2], file=f)
|
||||
|
||||
bound = 0.25 * self.distance
|
||||
ncolor = self.vizinfo.nbcolor
|
||||
for bond in bonds:
|
||||
itype = int(bond[1])
|
||||
if itype > ncolor: raise StandardError,"bond type too big"
|
||||
if itype > ncolor: raise Exception("bond type too big")
|
||||
color = self.vizinfo.bcolor[itype]
|
||||
rad = self.vizinfo.brad[itype]
|
||||
if fabs(bond[2]-bond[5]) > bound or fabs(bond[3]-bond[6]) > bound:
|
||||
continue
|
||||
print >>f,5
|
||||
print >>f,bond[2],bond[3],bond[4],rad, \
|
||||
bond[5],bond[6],bond[7],0.0,color[0],color[1],color[2]
|
||||
print(5, file=f)
|
||||
print(bond[2],bond[3],bond[4],rad, \
|
||||
bond[5],bond[6],bond[7],0.0,color[0],color[1],color[2], file=f)
|
||||
|
||||
ncolor = self.vizinfo.nlcolor
|
||||
for line in lines:
|
||||
itype = int(line[1])
|
||||
if itype > ncolor: raise StandardError,"line type too big"
|
||||
if itype > ncolor: raise Exception("line type too big")
|
||||
color = self.vizinfo.lcolor[itype]
|
||||
thick = self.vizinfo.lrad[itype]
|
||||
print >>f,3
|
||||
print >>f,line[2],line[3],line[4],thick, \
|
||||
line[5],line[6],line[7],thick,color[0],color[1],color[2]
|
||||
print(3, file=f)
|
||||
print(line[2],line[3],line[4],thick, \
|
||||
line[5],line[6],line[7],thick,color[0],color[1],color[2], file=f)
|
||||
|
||||
for label in self.labels:
|
||||
print >>f,15
|
||||
print >>f,10
|
||||
print >>f,label[2],label[3],label[4]
|
||||
print >>f,11
|
||||
print >>f,label[0],label[1],0.0,label[5][0],label[5][1],label[5][2]
|
||||
print >>f,label[6]
|
||||
|
||||
print(15, file=f)
|
||||
print(10, file=f)
|
||||
print(label[2],label[3],label[4], file=f)
|
||||
print(11, file=f)
|
||||
print(label[0],label[1],0.0,label[5][0],label[5][1],label[5][2], file=f)
|
||||
print(label[6], file=f)
|
||||
|
||||
f.close()
|
||||
|
||||
if len(self.labels) == 0:
|
||||
@ -446,47 +453,47 @@ class raster:
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def adef(self):
|
||||
self.vizinfo.setcolors("atom",range(100),"loop")
|
||||
self.vizinfo.setradii("atom",range(100),0.45)
|
||||
|
||||
self.vizinfo.setcolors("atom",list(range(100)),"loop")
|
||||
self.vizinfo.setradii("atom",list(range(100)),0.45)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def bdef(self):
|
||||
self.vizinfo.setcolors("bond",range(100),"loop")
|
||||
self.vizinfo.setradii("bond",range(100),0.25)
|
||||
|
||||
self.vizinfo.setcolors("bond",list(range(100)),"loop")
|
||||
self.vizinfo.setradii("bond",list(range(100)),0.25)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def tdef(self):
|
||||
self.vizinfo.setcolors("tri",range(100),"loop")
|
||||
self.vizinfo.setfills("tri",range(100),0)
|
||||
self.vizinfo.setcolors("tri",list(range(100)),"loop")
|
||||
self.vizinfo.setfills("tri",list(range(100)),0)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def ldef(self):
|
||||
self.vizinfo.setcolors("line",range(100),"loop")
|
||||
self.vizinfo.setradii("line",range(100),0.25)
|
||||
|
||||
self.vizinfo.setcolors("line",list(range(100)),"loop")
|
||||
self.vizinfo.setradii("line",list(range(100)),0.25)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def acol(self,atypes,colors):
|
||||
self.vizinfo.setcolors("atom",atypes,colors)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def arad(self,atypes,radii):
|
||||
self.vizinfo.setradii("atom",atypes,radii)
|
||||
|
||||
self.vizinfo.setradii("atom",atypes,radii)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def bcol(self,btypes,colors):
|
||||
self.vizinfo.setcolors("bond",btypes,colors)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def brad(self,btypes,radii):
|
||||
self.vizinfo.setradii("bond",btypes,radii)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def tcol(self,ttypes,colors):
|
||||
@ -525,34 +532,34 @@ def box_write(f,box,color,thick):
|
||||
red = color[0]
|
||||
green = color[1]
|
||||
blue = color[2]
|
||||
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zlo,thick,xhi,ylo,zlo,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,yhi,zlo,thick,xhi,yhi,zlo,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zhi,thick,xhi,ylo,zhi,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,yhi,zhi,thick,xhi,yhi,zhi,thick,red,green,blue)
|
||||
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zlo,thick,xlo,yhi,zlo,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xhi,ylo,zlo,thick,xhi,yhi,zlo,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zhi,thick,xlo,yhi,zhi,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xhi,ylo,zhi,thick,xhi,yhi,zhi,thick,red,green,blue)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zlo,thick,xhi,ylo,zlo,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,yhi,zlo,thick,xhi,yhi,zlo,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zhi,thick,xhi,ylo,zhi,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,yhi,zhi,thick,xhi,yhi,zhi,thick,red,green,blue), file=f)
|
||||
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zlo,thick,xlo,yhi,zlo,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xhi,ylo,zlo,thick,xhi,yhi,zlo,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zhi,thick,xlo,yhi,zhi,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xhi,ylo,zhi,thick,xhi,yhi,zhi,thick,red,green,blue), file=f)
|
||||
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zlo,thick,xlo,ylo,zhi,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xhi,ylo,zlo,thick,xhi,ylo,zhi,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,yhi,zlo,thick,xlo,yhi,zhi,thick,red,green,blue), file=f)
|
||||
print("3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xhi,yhi,zlo,thick,xhi,yhi,zhi,thick,red,green,blue), file=f)
|
||||
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,ylo,zlo,thick,xlo,ylo,zhi,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xhi,ylo,zlo,thick,xhi,ylo,zhi,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xlo,yhi,zlo,thick,xlo,yhi,zhi,thick,red,green,blue)
|
||||
print >>f,"3\n%g %g %g %g %g %g %g %g %g %g %g" % \
|
||||
(xhi,yhi,zlo,thick,xhi,yhi,zhi,thick,red,green,blue)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# compute 3x3 rotation matrix for viewing angle
|
||||
|
||||
@ -599,9 +606,9 @@ def rotation_matrix(coord1,angle1,coord2,angle2):
|
||||
a33 = 1.0
|
||||
a12 = a22 = c1
|
||||
a12 = s1; a21 = -s1
|
||||
|
||||
|
||||
# 2nd rotation matrix
|
||||
|
||||
|
||||
b11 = b12 = b13 = b21 = b22 = b23 = b31 = b32 = b33 = 0.0
|
||||
if coord2 == 'x':
|
||||
b11 = 1.0
|
||||
@ -615,26 +622,26 @@ def rotation_matrix(coord1,angle1,coord2,angle2):
|
||||
b33 = 1.0
|
||||
b11 = b22 = c2
|
||||
b12 = s2; b21 = -s2
|
||||
|
||||
|
||||
# full matrix c = b*a
|
||||
|
||||
|
||||
c11 = b11*a11 + b12*a21 + b13*a31
|
||||
c12 = b11*a12 + b12*a22 + b13*a32
|
||||
c13 = b11*a13 + b12*a23 + b13*a33
|
||||
|
||||
|
||||
c21 = b21*a11 + b22*a21 + b23*a31
|
||||
c22 = b21*a12 + b22*a22 + b23*a32
|
||||
c23 = b21*a13 + b22*a23 + b23*a33
|
||||
|
||||
|
||||
c31 = b31*a11 + b32*a21 + b33*a31
|
||||
c32 = b31*a12 + b32*a22 + b33*a32
|
||||
c33 = b31*a13 + b32*a23 + b33*a33
|
||||
|
||||
|
||||
# form rotation matrix
|
||||
# each line padded with 0.0 for 4x4 raster3d matrix
|
||||
|
||||
matrix = "%g %g %g 0.0\n%g %g %g 0.0\n%g %g %g 0.0" % \
|
||||
(c11,c12,c13,c21,c22,c23,c31,c32,c33)
|
||||
(c11,c12,c13,c21,c22,c23,c31,c32,c33)
|
||||
return matrix
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -653,7 +660,7 @@ F no, shadowed rods look funny
|
||||
0.25 specular reflection component
|
||||
%g eye position
|
||||
1 1 1 main light source postion
|
||||
%s
|
||||
%s
|
||||
%g %g %g %g
|
||||
3 mixed object types
|
||||
*
|
||||
|
||||
256
src/svg.py
256
src/svg.py
@ -3,11 +3,23 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# svg tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, os, re
|
||||
try:
|
||||
import commands
|
||||
except ImportError:
|
||||
import subprocess as commands
|
||||
import functools
|
||||
from vizinfo import vizinfo
|
||||
from math import sqrt,atan,cos,sin,fabs
|
||||
|
||||
oneline = "3d visualization via SVG files"
|
||||
|
||||
docstr = """
|
||||
@ -16,8 +28,8 @@ s = svg(d) create SVG object for data in d
|
||||
d = atom snapshot object (dump, data)
|
||||
|
||||
s.bg("black") set background color (def = "black")
|
||||
s.size(N) set image size to NxN
|
||||
s.size(N,M) set image size to NxM
|
||||
s.size(N) set image size to NxN
|
||||
s.size(N,M) set image size to NxM
|
||||
s.rotate(60,135) view from z theta and azimuthal phi (def = 60,30)
|
||||
s.shift(x,y) translate by x,y pixels in view window (def = 0,0)
|
||||
s.zoom(0.5) scale image by factor (def = 1)
|
||||
@ -40,18 +52,18 @@ s.pan() no pan during all() (default)
|
||||
|
||||
s.select = "$x > %g*3.0" string to pass to d.aselect.test() during all()
|
||||
s.select = "" no extra aselect (default)
|
||||
|
||||
|
||||
%g varies from 0.0 to 1.0 from beginning to end of all()
|
||||
|
||||
s.label(x,y,"h",size,"red","This is a label") add label to each image
|
||||
s.nolabel() delete all labels
|
||||
|
||||
|
||||
x,y coords = -0.5 to 0.5, "h" or "t" for Helvetica or Times font
|
||||
size = fontsize (e.g. 10), "red" = color of text
|
||||
|
||||
s.acol(2,"green") set atom colors by atom type (1-N)
|
||||
s.acol([2,4],["red","blue"]) 1st arg = one type or list of types
|
||||
s.acol(0,"blue") 2nd arg = one color or list of colors
|
||||
|
||||
s.acol(2,"green") set atom colors by atom type (1-N)
|
||||
s.acol([2,4],["red","blue"]) 1st arg = one type or list of types
|
||||
s.acol(0,"blue") 2nd arg = one color or list of colors
|
||||
s.acol(range(20),["red","blue"]) if list lengths unequal, interpolate
|
||||
s.acol(range(10),"loop") assign colors in loop, randomly ordered
|
||||
|
||||
@ -61,19 +73,19 @@ s.acol(range(10),"loop") assign colors in loop, randomly ordered
|
||||
|
||||
s.arad([1,2],[0.5,0.3]) set atom radii, same rules as acol()
|
||||
|
||||
s.bcol() set bond color, same args as acol()
|
||||
s.brad() set bond thickness, same args as arad()
|
||||
s.bcol() set bond color, same args as acol()
|
||||
s.brad() set bond thickness, same args as arad()
|
||||
|
||||
s.tcol() set triangle color, same args as acol()
|
||||
s.tfill() set triangle fill, 0 fill, 1 line, 2 both
|
||||
s.tcol() set triangle color, same args as acol()
|
||||
s.tfill() set triangle fill, 0 fill, 1 line, 2 both
|
||||
|
||||
s.lcol() set line color, same args as acol()
|
||||
s.lrad() set line thickness, same args as arad()
|
||||
|
||||
s.adef() set atom/bond/tri/line properties to default
|
||||
s.bdef() default = "loop" for colors, 0.45 for radii
|
||||
s.tdef() default = 0.25 for bond/line thickness
|
||||
s.ldef() default = 0 fill
|
||||
s.bdef() default = "loop" for colors, 0.45 for radii
|
||||
s.tdef() default = 0.25 for bond/line thickness
|
||||
s.ldef() default = 0 fill
|
||||
|
||||
by default 100 types are assigned
|
||||
if atom/bond/tri/line has type > # defined properties, is an error
|
||||
@ -110,12 +122,6 @@ s.thick = 2.0 pixel thickness of black atom border
|
||||
# bgcol = color of background
|
||||
# vizinfo = scene attributes
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, os, commands, re
|
||||
from vizinfo import vizinfo
|
||||
from math import sqrt,atan,cos,sin,fabs
|
||||
|
||||
try: from DEFAULTS import PIZZA_DISPLAY
|
||||
except: PIZZA_DISPLAY = "display"
|
||||
|
||||
@ -149,21 +155,21 @@ class svg:
|
||||
self.bdef()
|
||||
self.tdef()
|
||||
self.ldef()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def bg(self,color):
|
||||
from vizinfo import colors
|
||||
self.bgcol = [colors[color][0]/255.0,colors[color][1]/255.0,
|
||||
colors[color][2]/255.0]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def size(self,newx,newy=None):
|
||||
self.xpixels = xnew
|
||||
if not ynew: self.ypixels = self.xpixels
|
||||
else: self.ypixels = ynew
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def rotate(self,ztheta,azphi):
|
||||
@ -175,7 +181,7 @@ class svg:
|
||||
def shift(self,x,y):
|
||||
self.xshift = x;
|
||||
self.yshift = y;
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def box(self,*args):
|
||||
@ -185,12 +191,12 @@ class svg:
|
||||
self.bxcol = [colors[args[1]][0]/255.0,colors[args[1]][1]/255.0,
|
||||
colors[args[1]][2]/255.0]
|
||||
if len(args) > 2: self.bxthick = args[2]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def zoom(self,factor):
|
||||
self.scale = factor
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def show(self,ntime):
|
||||
@ -199,11 +205,11 @@ class svg:
|
||||
time,box,atoms,bonds,tris,lines = data.viz(which)
|
||||
if self.boxflag == 2: box = data.maxbox()
|
||||
self.distance = compute_distance(box)
|
||||
|
||||
|
||||
self.single(self.file,box,atoms,bonds,tris,lines,1)
|
||||
cmd = "%s %s.svg" % (PIZZA_DISPLAY,self.file)
|
||||
commands.getoutput(cmd)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def pan(self,*list):
|
||||
@ -215,8 +221,8 @@ class svg:
|
||||
self.scale_start = list[2]
|
||||
self.ztheta_stop = list[3]
|
||||
self.azphi_stop = list[4]
|
||||
self.scale_stop = list[5]
|
||||
|
||||
self.scale_stop = list[5]
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def all(self,*list):
|
||||
@ -247,11 +253,11 @@ class svg:
|
||||
if flag == -1: break
|
||||
|
||||
fraction = float(i) / (ncount-1)
|
||||
|
||||
if self.select != "":
|
||||
|
||||
if self.select != "":
|
||||
newstr = self.select % fraction
|
||||
data.aselect.test(newstr,time)
|
||||
time,boxone,atoms,bonds,tris,lines = data.viz(which)
|
||||
time,boxone,atoms,bonds,tris,lines = data.viz(which)
|
||||
|
||||
if self.boxflag < 2: box = boxone
|
||||
if n == nstart: self.distance = compute_distance(box)
|
||||
@ -260,20 +266,20 @@ class svg:
|
||||
elif n < 100: file = self.file + "00" + str(n)
|
||||
elif n < 1000: file = self.file + "0" + str(n)
|
||||
else: file = self.file + str(n)
|
||||
|
||||
if self.panflag:
|
||||
|
||||
if self.panflag:
|
||||
self.ztheta = self.ztheta_start + \
|
||||
fraction*(self.ztheta_stop - self.ztheta_start)
|
||||
self.azphi = self.azphi_start + \
|
||||
fraction*(self.azphi_stop - self.azphi_start)
|
||||
self.scale = self.scale_start + \
|
||||
fraction*(self.scale_stop - self.scale_start)
|
||||
|
||||
scaleflag = 0
|
||||
if n == nstart or self.panflag: scaleflag = 1
|
||||
|
||||
self.single(file,box,atoms,bonds,tris,lines,scaleflag)
|
||||
print time,
|
||||
scaleflag = 0
|
||||
if n == nstart or self.panflag: scaleflag = 1
|
||||
|
||||
self.single(file,box,atoms,bonds,tris,lines,scaleflag)
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
i += 1
|
||||
n += 1
|
||||
@ -289,8 +295,8 @@ class svg:
|
||||
n = nstart
|
||||
for i in range(ncount):
|
||||
fraction = float(i) / (ncount-1)
|
||||
|
||||
if self.select != "":
|
||||
|
||||
if self.select != "":
|
||||
newstr = self.select % fraction
|
||||
data.aselect.test(newstr,ntime)
|
||||
time,boxone,atoms,bonds,tris,lines = data.viz(which)
|
||||
@ -302,25 +308,25 @@ class svg:
|
||||
elif n < 100: file = self.file + "00" + str(n)
|
||||
elif n < 1000: file = self.file + "0" + str(n)
|
||||
else: file = self.file + str(n)
|
||||
|
||||
if self.panflag:
|
||||
|
||||
if self.panflag:
|
||||
self.ztheta = self.ztheta_start + \
|
||||
fraction*(self.ztheta_stop - self.ztheta_start)
|
||||
self.azphi = self.azphi_start + \
|
||||
fraction*(self.azphi_stop - self.azphi_start)
|
||||
self.scale = self.scale_start + \
|
||||
self.scale = self.scale_start + \
|
||||
fraction*(self.scale_stop - self.scale_start)
|
||||
|
||||
scaleflag = 0
|
||||
if n == nstart or self.panflag: scaleflag = 1
|
||||
if n == nstart or self.panflag: scaleflag = 1
|
||||
|
||||
self.single(file,box,atoms,bonds,tris,lines,scaleflag)
|
||||
print n,
|
||||
self.single(file,box,atoms,bonds,tris,lines,scaleflag)
|
||||
print(n, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
print "\n%d images" % ncount
|
||||
|
||||
|
||||
print("\n%d images" % ncount)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def label(self,x,y,font,point,color,text):
|
||||
@ -334,11 +340,11 @@ class svg:
|
||||
|
||||
def nolabel(self):
|
||||
self.labels = []
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def single(self,file,box,atoms,bonds,tris,lines,scaleflag):
|
||||
|
||||
|
||||
matrix = rotation_matrix('x',-self.ztheta,'z',270.0-self.azphi)
|
||||
if scaleflag:
|
||||
self.factor = self.xpixels*self.scale / (1.6*self.distance)
|
||||
@ -359,31 +365,31 @@ class svg:
|
||||
tri[0] = 1
|
||||
newtri = self.transform(tri,matrix)
|
||||
olist.append(newtri)
|
||||
|
||||
|
||||
bound = 0.25 * self.distance
|
||||
for bond in bonds:
|
||||
newbond = [2,bond[1]]
|
||||
dx = bond[5] - bond[2]
|
||||
dy = bond[6] - bond[3]
|
||||
dz = bond[7] - bond[4]
|
||||
dz = bond[7] - bond[4]
|
||||
r = sqrt(dx*dx+dy*dy+dz*dz)
|
||||
if not r: r = 1
|
||||
rad = self.vizinfo.arad[int(bond[9])]
|
||||
newbond.append(bond[2] + (r/r - rad/r) * dx)
|
||||
newbond.append(bond[3] + (r/r - rad/r) * dy)
|
||||
newbond.append(bond[4] + (r/r - rad/r) * dz)
|
||||
|
||||
|
||||
# cut off second side of bond
|
||||
|
||||
|
||||
dx = bond[2] - bond[5]
|
||||
dy = bond[3] - bond[6]
|
||||
dz = bond[4] - bond[7]
|
||||
dz = bond[4] - bond[7]
|
||||
r = sqrt(dx*dx+dy*dy+dz*dz)
|
||||
if not r: r = 1
|
||||
rad = self.vizinfo.arad[int(bond[8])]
|
||||
newbond.append(bond[5] + (r/r - rad/r) * dx)
|
||||
newbond.append(bond[6] + (r/r - rad/r) * dy)
|
||||
newbond.append(bond[7] + (r/r - rad/r) * dz)
|
||||
newbond.append(bond[7] + (r/r - rad/r) * dz)
|
||||
|
||||
if fabs(newbond[2]-newbond[5]) > bound or \
|
||||
fabs(newbond[3]-newbond[6]) > bound: continue
|
||||
@ -391,7 +397,7 @@ class svg:
|
||||
newbond = self.transform(newbond,matrix)
|
||||
if newbond[4] < newbond[7]: newbond[4] = newbond[7]
|
||||
olist.append(newbond)
|
||||
|
||||
|
||||
for line in lines:
|
||||
line[0] = 3
|
||||
newline = self.transform(line,matrix)
|
||||
@ -420,32 +426,32 @@ class svg:
|
||||
# convert objects by factor/offset and sort by z-depth
|
||||
|
||||
self.convert(olist)
|
||||
olist.sort(cmprz)
|
||||
olist.sort(key = functools.cmp_to_key(cmprz))
|
||||
|
||||
# write SVG file
|
||||
|
||||
file += ".svg"
|
||||
f = open(file,"w")
|
||||
|
||||
f = open(file,"w")
|
||||
|
||||
header = '<?xml version="1.0"?> <svg height="%s" width="%s" >' % \
|
||||
(self.ypixels,self.xpixels)
|
||||
header += '<g style="fill-opacity:1.0; stroke:black; stroke-width:0.001;">'
|
||||
print >>f,header
|
||||
print(header, file=f)
|
||||
|
||||
color = '<rect x="0" y="0" height="%s" width="%s" ' % \
|
||||
(self.ypixels,self.xpixels)
|
||||
color += 'fill="rgb(%s,%s,%s)"/>' % \
|
||||
(self.bgcol[0]*255,self.bgcol[1]*255,self.bgcol[2]*255)
|
||||
print >>f,color
|
||||
|
||||
print(color, file=f)
|
||||
|
||||
for element in olist: self.write(f,0,element)
|
||||
for label in self.labels: self.write(f,1,label)
|
||||
|
||||
footer = "</g></svg>"
|
||||
print >> f,footer
|
||||
|
||||
f.close()
|
||||
|
||||
print(footer, file=f)
|
||||
|
||||
f.close()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# rotate with matrix
|
||||
|
||||
@ -476,9 +482,9 @@ class svg:
|
||||
onew.append(matrix[0]*obj[5] + matrix[3]*obj[6] + matrix[6]*obj[7])
|
||||
onew.append(matrix[1]*obj[5] + matrix[4]*obj[6] + matrix[7]*obj[7])
|
||||
onew.append(matrix[2]*obj[5] + matrix[5]*obj[6] + matrix[8]*obj[7])
|
||||
|
||||
|
||||
return onew
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def convert(self,objlist):
|
||||
@ -504,116 +510,116 @@ class svg:
|
||||
obj[3] = yctr - factor*(obj[3] - offsety)
|
||||
obj[5] = factor*(obj[5] - offsetx) + xctr
|
||||
obj[6] = yctr - factor*(obj[6] - offsety)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def write(self,f,flag,*args):
|
||||
if len(args): obj = args[0]
|
||||
|
||||
|
||||
if flag == 0:
|
||||
if obj[0] == 0: # atom with its color and radius
|
||||
itype = int(obj[1])
|
||||
if itype > self.vizinfo.nacolor:
|
||||
raise StandardError,"atom type too big"
|
||||
itype = int(obj[1])
|
||||
if itype > self.vizinfo.nacolor:
|
||||
raise Exception("atom type too big")
|
||||
color = self.vizinfo.acolor[itype]
|
||||
rad = self.vizinfo.arad[itype]
|
||||
print >>f,'<circle cx="%s" cy="%s" r="%s" fill="rgb(%s,%s,%s)" stroke-width="%s" />' % \
|
||||
print('<circle cx="%s" cy="%s" r="%s" fill="rgb(%s,%s,%s)" stroke-width="%s" />' % \
|
||||
(obj[2],obj[3],rad*self.factor,
|
||||
color[0]*255,color[1]*255,color[2]*255,self.thick)
|
||||
|
||||
color[0]*255,color[1]*255,color[2]*255,self.thick), file=f)
|
||||
|
||||
elif obj[0] == 1: # tri with its color (need to add fill type)
|
||||
itype = int(obj[1])
|
||||
if itype > self.vizinfo.ntcolor:
|
||||
raise StandardError,"tri type too big"
|
||||
itype = int(obj[1])
|
||||
if itype > self.vizinfo.ntcolor:
|
||||
raise Exception("tri type too big")
|
||||
color = self.vizinfo.tcolor[itype]
|
||||
print >>f,'<polygon points= "%s,%s %s,%s %s,%s" fill="rgb(%s,%s,%s)" stroke="black" stroke-width="0.01" />' % \
|
||||
print('<polygon points= "%s,%s %s,%s %s,%s" fill="rgb(%s,%s,%s)" stroke="black" stroke-width="0.01" />' % \
|
||||
(obj[2],obj[3],obj[5],obj[6],obj[8],obj[9],
|
||||
color[0]*255,color[1]*255,color[2]*255)
|
||||
color[0]*255,color[1]*255,color[2]*255), file=f)
|
||||
|
||||
elif obj[0] == 2: # bond with its color and thickness
|
||||
itype = int(obj[1])
|
||||
if itype > self.vizinfo.nbcolor:
|
||||
raise StandardError,"bond type too big"
|
||||
if itype > self.vizinfo.nbcolor:
|
||||
raise Exception("bond type too big")
|
||||
color = self.vizinfo.bcolor[itype]
|
||||
thick = self.vizinfo.brad[itype]
|
||||
print >>f,'<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="rgb(%s,%s,%s)" stroke-width="%s" />' % \
|
||||
print('<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="rgb(%s,%s,%s)" stroke-width="%s" />' % \
|
||||
(obj[2],obj[3],obj[5],obj[6],
|
||||
color[0]*255,color[1]*255,color[2]*255,thick*self.factor)
|
||||
|
||||
color[0]*255,color[1]*255,color[2]*255,thick*self.factor), file=f)
|
||||
|
||||
elif obj[0] == 3: # line with its color and thickness
|
||||
itype = int(obj[1])
|
||||
if itype > self.vizinfo.nlcolor:
|
||||
raise StandardError,"line type too big"
|
||||
if itype > self.vizinfo.nlcolor:
|
||||
raise Exception("line type too big")
|
||||
color = self.vizinfo.lcolor[itype]
|
||||
thick = self.vizinfo.lrad[itype]
|
||||
print >>f,'<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="rgb(%s,%s,%s)" stroke-width="%s" />' % \
|
||||
print('<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="rgb(%s,%s,%s)" stroke-width="%s" />' % \
|
||||
(obj[2],obj[3],obj[5],obj[6],
|
||||
color[0]*255,color[1]*255,color[2]*255,thick*self.factor)
|
||||
color[0]*255,color[1]*255,color[2]*255,thick*self.factor), file=f)
|
||||
|
||||
elif obj[0] == 4: # box line with built-in color and thickness
|
||||
color = self.bxcol
|
||||
thick = self.bxthick
|
||||
print >>f,'<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="rgb(%s,%s,%s)" stroke-width="%s" />' % \
|
||||
print('<line x1="%s" y1="%s" x2="%s" y2="%s" stroke="rgb(%s,%s,%s)" stroke-width="%s" />' % \
|
||||
(obj[2],obj[3],obj[5],obj[6],
|
||||
color[0]*255,color[1]*255,color[2]*255,thick*self.factor)
|
||||
color[0]*255,color[1]*255,color[2]*255,thick*self.factor), file=f)
|
||||
|
||||
elif flag == 1:
|
||||
x = (obj[0]*self.xpixels) + (self.xpixels/2.0)
|
||||
y = (self.ypixels/2.0) - (obj[1]*self.ypixels)
|
||||
color = obj[4]
|
||||
print >>f,'<text x="%s" y="%s" font-size="%s" font-family="%s" stroke="rgb(%s,%s,%s)" fill="rgb(%s,%s,%s"> %s </text>' % \
|
||||
print('<text x="%s" y="%s" font-size="%s" font-family="%s" stroke="rgb(%s,%s,%s)" fill="rgb(%s,%s,%s"> %s </text>' % \
|
||||
(x,y,obj[3],obj[2],color[0]*255,color[1]*255,color[2]*255,
|
||||
color[0]*255,color[1]*255,color[2]*255,obj[5])
|
||||
|
||||
color[0]*255,color[1]*255,color[2]*255,obj[5]), file=f)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def adef(self):
|
||||
self.vizinfo.setcolors("atom",range(100),"loop")
|
||||
self.vizinfo.setradii("atom",range(100),0.45)
|
||||
|
||||
self.vizinfo.setcolors("atom",list(range(100)),"loop")
|
||||
self.vizinfo.setradii("atom",list(range(100)),0.45)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def bdef(self):
|
||||
self.vizinfo.setcolors("bond",range(100),"loop")
|
||||
self.vizinfo.setradii("bond",range(100),0.25)
|
||||
|
||||
self.vizinfo.setcolors("bond",list(range(100)),"loop")
|
||||
self.vizinfo.setradii("bond",list(range(100)),0.25)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def tdef(self):
|
||||
self.vizinfo.setcolors("tri",range(100),"loop")
|
||||
self.vizinfo.setfills("tri",range(100),0)
|
||||
self.vizinfo.setcolors("tri",list(range(100)),"loop")
|
||||
self.vizinfo.setfills("tri",list(range(100)),0)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def ldef(self):
|
||||
self.vizinfo.setcolors("line",range(100),"loop")
|
||||
self.vizinfo.setradii("line",range(100),0.25)
|
||||
self.vizinfo.setcolors("line",list(range(100)),"loop")
|
||||
self.vizinfo.setradii("line",list(range(100)),0.25)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def acol(self,atypes,colors):
|
||||
self.vizinfo.setcolors("atom",atypes,colors)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def arad(self,atypes,radii):
|
||||
self.vizinfo.setradii("atom",atypes,radii)
|
||||
|
||||
self.vizinfo.setradii("atom",atypes,radii)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def bcol(self,btypes,colors):
|
||||
self.vizinfo.setcolors("bond",btypes,colors)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def brad(self,btypes,radii):
|
||||
self.vizinfo.setradii("bond",btypes,radii)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def tcol(self,ttypes,colors):
|
||||
self.vizinfo.setcolors("tri",ttypes,colors)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def tfill(self,ttypes,flags):
|
||||
@ -696,9 +702,9 @@ def rotation_matrix(coord1,angle1,coord2,angle2):
|
||||
a33 = 1.0
|
||||
a12 = a22 = c1
|
||||
a12 = s1; a21 = -s1
|
||||
|
||||
|
||||
# 2nd rotation matrix
|
||||
|
||||
|
||||
b11 = b12 = b13 = b21 = b22 = b23 = b31 = b32 = b33 = 0.0
|
||||
if coord2 == 'x':
|
||||
b11 = 1.0
|
||||
@ -712,23 +718,23 @@ def rotation_matrix(coord1,angle1,coord2,angle2):
|
||||
b33 = 1.0
|
||||
b11 = b22 = c2
|
||||
b12 = s2; b21 = -s2
|
||||
|
||||
|
||||
# full matrix c = b*a
|
||||
|
||||
|
||||
c11 = b11*a11 + b12*a21 + b13*a31
|
||||
c12 = b11*a12 + b12*a22 + b13*a32
|
||||
c13 = b11*a13 + b12*a23 + b13*a33
|
||||
|
||||
|
||||
c21 = b21*a11 + b22*a21 + b23*a31
|
||||
c22 = b21*a12 + b22*a22 + b23*a32
|
||||
c23 = b21*a13 + b22*a23 + b23*a33
|
||||
|
||||
|
||||
c31 = b31*a11 + b32*a21 + b33*a31
|
||||
c32 = b31*a12 + b32*a22 + b33*a32
|
||||
c33 = b31*a13 + b32*a23 + b33*a33
|
||||
|
||||
|
||||
# form rotation matrix
|
||||
|
||||
|
||||
matrix = (c11,c12,c13,c21,c22,c23,c31,c32,c33)
|
||||
return matrix
|
||||
|
||||
|
||||
88
src/tdump.py
88
src/tdump.py
@ -3,23 +3,31 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# tdump tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, re, glob, types
|
||||
import functools
|
||||
from math import sqrt
|
||||
from os import popen
|
||||
|
||||
oneline = "Read dump files with triangle info"
|
||||
|
||||
docstr = """
|
||||
t = tdump("dump.one") read in one or more dump files
|
||||
t = tdump("dump.1 dump.2.gz") can be gzipped
|
||||
t = tdump("dump.*") wildcard expands to multiple files
|
||||
t = tdump("dump.*",0) two args = store filenames, but don't read
|
||||
t = tdump("dump.1 dump.2.gz") can be gzipped
|
||||
t = tdump("dump.*") wildcard expands to multiple files
|
||||
t = tdump("dump.*",0) two args = store filenames, but don't read
|
||||
|
||||
incomplete and duplicate snapshots are deleted
|
||||
no column name assignment is performed
|
||||
|
||||
time = t.next() read next snapshot from dump files
|
||||
time = t.next() read next snapshot from dump files
|
||||
|
||||
used with 2-argument constructor to allow reading snapshots one-at-a-time
|
||||
snapshot will be skipped only if another snapshot has same time stamp
|
||||
@ -43,7 +51,7 @@ time,box,atoms,bonds,tris,lines = t.viz(index) return list of viz objects
|
||||
id,type are from associated atom
|
||||
lines = NULL
|
||||
|
||||
t.owrap(...) wrap tris to same image as their atoms
|
||||
t.owrap(...) wrap tris to same image as their atoms
|
||||
|
||||
owrap() is called by dump tool's owrap()
|
||||
useful for wrapping all molecule's atoms/tris the same so it is contiguous
|
||||
@ -67,12 +75,6 @@ t.owrap(...) wrap tris to same image as their atoms
|
||||
# xlo,xhi,ylo,yhi,zlo,zhi = box bounds (float)
|
||||
# atoms[i][j] = 2d array of floats, i = 0 to natoms-1, j = 0 to ncols-1
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, commands, re, glob, types
|
||||
from math import sqrt
|
||||
from os import popen
|
||||
|
||||
try:
|
||||
import numpy as np
|
||||
oldnumeric = False
|
||||
@ -100,8 +102,8 @@ class tdump:
|
||||
self.flist = []
|
||||
for word in words: self.flist += glob.glob(word)
|
||||
if len(self.flist) == 0 and len(list) == 1:
|
||||
raise StandardError,"no ldump file specified"
|
||||
|
||||
raise Exception("no ldump file specified")
|
||||
|
||||
if len(list) == 1:
|
||||
self.increment = 0
|
||||
self.read_all()
|
||||
@ -125,26 +127,26 @@ class tdump:
|
||||
snap = self.read_snapshot(f)
|
||||
while snap:
|
||||
self.snaps.append(snap)
|
||||
print snap.time,
|
||||
print(snap.time, end=' ')
|
||||
sys.stdout.flush()
|
||||
snap = self.read_snapshot(f)
|
||||
|
||||
f.close()
|
||||
print
|
||||
print()
|
||||
|
||||
# sort entries by timestep, cull duplicates
|
||||
|
||||
self.snaps.sort(self.compare_time)
|
||||
self.snaps.sort(key = functools.cmp_to_key(self.compare_time))
|
||||
self.cull()
|
||||
self.nsnaps = len(self.snaps)
|
||||
print "read %d snapshots" % self.nsnaps
|
||||
print("read %d snapshots" % self.nsnaps)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# read next snapshot from list of files
|
||||
|
||||
def next(self):
|
||||
|
||||
if not self.increment: raise StandardError,"cannot read incrementally"
|
||||
if not self.increment: raise Exception("cannot read incrementally")
|
||||
|
||||
# read next snapshot in current file using eof as pointer
|
||||
# if fail, try next file
|
||||
@ -156,15 +158,15 @@ class tdump:
|
||||
snap = self.read_snapshot(f)
|
||||
if not snap:
|
||||
self.nextfile += 1
|
||||
if self.nextfile == len(self.flist): return -1
|
||||
if self.nextfile == len(self.flist): return -1
|
||||
f.close()
|
||||
self.eof = 0
|
||||
continue
|
||||
self.eof = 0
|
||||
continue
|
||||
self.eof = f.tell()
|
||||
f.close()
|
||||
try:
|
||||
self.findtime(snap.time)
|
||||
continue
|
||||
continue
|
||||
except: break
|
||||
|
||||
self.snaps.append(snap)
|
||||
@ -176,7 +178,7 @@ class tdump:
|
||||
# --------------------------------------------------------------------
|
||||
# read a single snapshot from file f
|
||||
# return snapshot or 0 if failed
|
||||
|
||||
|
||||
def read_snapshot(self,f):
|
||||
try:
|
||||
snap = Snap()
|
||||
@ -198,14 +200,14 @@ class tdump:
|
||||
if snap.natoms:
|
||||
words = f.readline().split()
|
||||
ncol = len(words)
|
||||
for i in xrange(1,snap.natoms):
|
||||
for i in range(1,snap.natoms):
|
||||
words += f.readline().split()
|
||||
floats = map(float,words)
|
||||
floats = list(map(float,words))
|
||||
if oldnumeric: atoms = np.zeros((snap.natoms,ncol),np.Float)
|
||||
else: atoms = np.zeros((snap.natoms,ncol),np.float)
|
||||
start = 0
|
||||
stop = ncol
|
||||
for i in xrange(snap.natoms):
|
||||
for i in range(snap.natoms):
|
||||
atoms[i] = floats[start:stop]
|
||||
start = stop
|
||||
stop += ncol
|
||||
@ -217,10 +219,10 @@ class tdump:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# map atom column names
|
||||
|
||||
|
||||
def map(self,*pairs):
|
||||
if len(pairs) % 2 != 0:
|
||||
raise StandardError, "tdump map() requires pairs of mappings"
|
||||
raise Exception("tdump map() requires pairs of mappings")
|
||||
for i in range(0,len(pairs),2):
|
||||
j = i + 1
|
||||
self.names[pairs[j]] = pairs[i]-1
|
||||
@ -248,11 +250,11 @@ class tdump:
|
||||
return 0
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
|
||||
def findtime(self,n):
|
||||
for i in xrange(self.nsnaps):
|
||||
for i in range(self.nsnaps):
|
||||
if self.snaps[i].time == n: return i
|
||||
raise StandardError, "no step %d exists" % n
|
||||
raise Exception("no step %d exists" % n)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# delete successive snapshots with duplicate time stamp
|
||||
@ -264,7 +266,7 @@ class tdump:
|
||||
del self.snaps[i]
|
||||
else:
|
||||
i += 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# return list of lines to viz for snapshot isnap
|
||||
# if called with flag, then index is timestep, so convert to snapshot index
|
||||
@ -295,11 +297,11 @@ class tdump:
|
||||
corner3y = self.names["corner3y"]
|
||||
corner3z = self.names["corner3z"]
|
||||
|
||||
# create line list from id,type,corner1x,...corner3z
|
||||
# don't add line if all 4 values are 0 since not a line
|
||||
|
||||
# create tris list from id,type,corner1x,...corner3z
|
||||
# don't add tri if all 4 values are 0 since not a line
|
||||
|
||||
tris = []
|
||||
for i in xrange(snap.natoms):
|
||||
for i in range(snap.natoms):
|
||||
atom = snap.atoms[i]
|
||||
c1 = [atom[corner1x],atom[corner1y],atom[corner1z]]
|
||||
c2 = [atom[corner2x],atom[corner2y],atom[corner2z]]
|
||||
@ -334,8 +336,8 @@ class tdump:
|
||||
# idump = index of my line I in dump's atoms
|
||||
# jdump = atom J in dump's atoms that atom I was owrapped on
|
||||
# delx,dely = offset applied to atom I and thus to line I
|
||||
|
||||
for i in xrange(snap.natoms):
|
||||
|
||||
for i in range(snap.natoms):
|
||||
tag = atoms[i][id]
|
||||
idump = idsdump[tag]
|
||||
jdump = idsdump[atomsdump[idump][iother]]
|
||||
@ -366,20 +368,20 @@ def normal(x,y,z):
|
||||
v1[0] = y[0] - x[0]
|
||||
v1[1] = y[1] - x[1]
|
||||
v1[2] = y[2] - x[2]
|
||||
|
||||
|
||||
v2 = 3*[0]
|
||||
v2[0] = z[0] - y[0]
|
||||
v2[1] = z[1] - y[1]
|
||||
v2[2] = z[2] - y[2]
|
||||
|
||||
|
||||
n = 3*[0]
|
||||
n[0] = v1[1]*v2[2] - v1[2]*v2[1]
|
||||
n[1] = v1[2]*v2[0] - v1[0]*v2[2]
|
||||
n[2] = v1[0]*v2[1] - v1[1]*v2[0]
|
||||
|
||||
|
||||
length = sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2])
|
||||
n[0] /= length
|
||||
n[1] /= length
|
||||
n[2] /= length
|
||||
|
||||
|
||||
return n
|
||||
|
||||
100
src/vcr.py
100
src/vcr.py
@ -3,11 +3,20 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# vcr tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
try:
|
||||
from Tkinter import *
|
||||
except ImportError:
|
||||
from tkinter import *
|
||||
import types
|
||||
|
||||
oneline = "VCR-style GUI for 3d interactive OpenGL visualization"
|
||||
|
||||
docstr = """
|
||||
@ -16,26 +25,26 @@ v.add(gl) add a gl window to vcr GUI
|
||||
|
||||
Actions (same as GUI widgets):
|
||||
|
||||
v.first() go to first frame
|
||||
v.first() go to first frame
|
||||
v.prev() go to previous frame
|
||||
v.back() play backwards from current frame to start
|
||||
v.stop() stop on current frame
|
||||
v.stop() stop on current frame
|
||||
v.play() play from current frame to end
|
||||
v.next() go to next frame
|
||||
v.last() go to last frame
|
||||
v.next() go to next frame
|
||||
v.last() go to last frame
|
||||
|
||||
v.frame(31) set frame slider
|
||||
v.delay(0.4) set delay slider
|
||||
v.q(5) set quality slider
|
||||
v.frame(31) set frame slider
|
||||
v.delay(0.4) set delay slider
|
||||
v.q(5) set quality slider
|
||||
|
||||
v.xaxis() view scene from x axis
|
||||
v.yaxis() view scene from y axis
|
||||
v.zaxis() view scene from z axis
|
||||
v.box() toggle bounding box
|
||||
v.axis() toggle display of xyz axes
|
||||
v.norm() recenter and resize the view
|
||||
v.ortho() toggle ortho/perspective button
|
||||
v.reload() reload all frames from gl viewer data files
|
||||
v.xaxis() view scene from x axis
|
||||
v.yaxis() view scene from y axis
|
||||
v.zaxis() view scene from z axis
|
||||
v.box() toggle bounding box
|
||||
v.axis() toggle display of xyz axes
|
||||
v.norm() recenter and resize the view
|
||||
v.ortho() toggle ortho/perspective button
|
||||
v.reload() reload all frames from gl viewer data files
|
||||
|
||||
v.clipxlo(0.2) clip scene at x lo fraction of box
|
||||
v.clipxhi(1.0) clip at x hi
|
||||
@ -44,9 +53,9 @@ v.clipyhi(1.0)
|
||||
v.clipzlo(0.2) clip in z
|
||||
v.clipzhi(1.0)
|
||||
|
||||
v.save() save current scene to file.png
|
||||
v.file("image") set filename
|
||||
v.saveall() toggle save-all checkbox
|
||||
v.save() save current scene to file.png
|
||||
v.file("image") set filename
|
||||
v.saveall() toggle save-all checkbox
|
||||
"""
|
||||
|
||||
# History
|
||||
@ -64,11 +73,6 @@ v.saveall() toggle save-all checkbox
|
||||
# delay_value = delay between frames (secs)
|
||||
# delay_msec = delay in millisec
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from Tkinter import *
|
||||
import types
|
||||
|
||||
# Class definition
|
||||
|
||||
class vcr:
|
||||
@ -88,7 +92,7 @@ class vcr:
|
||||
# load data for each viewer
|
||||
# if each viewer has different data set, nframes is for 1st viewer
|
||||
|
||||
if len(views) == 0: raise StandardError,"must have at least one GL viewer"
|
||||
if len(views) == 0: raise Exception("must have at least one GL viewer")
|
||||
self.viewlist = []
|
||||
for view in views: self.viewlist.append(view)
|
||||
for view in self.viewlist: view.reload()
|
||||
@ -108,7 +112,7 @@ class vcr:
|
||||
Button(frame1,text=">",command=self.next).pack(side=LEFT)
|
||||
Button(frame1,text=">>",command=self.last).pack(side=LEFT)
|
||||
frame1.pack()
|
||||
|
||||
|
||||
frame2 = Frame(root)
|
||||
self.slider_frame = Scale(frame2,from_=0,to=self.nframes-1,
|
||||
command=self.frame,orient=HORIZONTAL,
|
||||
@ -121,7 +125,7 @@ class vcr:
|
||||
command=self.delay,orient=HORIZONTAL,
|
||||
label=" Delay")
|
||||
self.slider_frame.pack(side=LEFT)
|
||||
self.slider_quality.pack(side=LEFT)
|
||||
self.slider_quality.pack(side=LEFT)
|
||||
self.slider_delay.pack(side=LEFT)
|
||||
frame2.pack()
|
||||
|
||||
@ -177,7 +181,7 @@ class vcr:
|
||||
Button(frame6,text="Save As:",command=self.save).pack(side=LEFT)
|
||||
self.entry_file = Entry(frame6,width = 16)
|
||||
self.entry_file.insert(0,"image")
|
||||
self.entry_file.pack(side=LEFT)
|
||||
self.entry_file.pack(side=LEFT)
|
||||
self.button_save = Checkbutton(frame6,text="SaveAll",command=self.saveall)
|
||||
self.button_save.pack(side=LEFT)
|
||||
frame6.pack()
|
||||
@ -197,7 +201,7 @@ class vcr:
|
||||
frame8.pack()
|
||||
|
||||
# display 1st image
|
||||
|
||||
|
||||
self.index = 0
|
||||
self.display()
|
||||
|
||||
@ -219,25 +223,25 @@ class vcr:
|
||||
def last(self):
|
||||
self.index = self.nframes - 1
|
||||
self.slider_frame.set(self.index)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def next(self):
|
||||
if self.index < self.nframes - 1:
|
||||
self.index += 1
|
||||
self.slider_frame.set(self.index)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def previous(self):
|
||||
if self.index > 0:
|
||||
self.index -= 1
|
||||
self.slider_frame.set(self.index)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# play backward loop
|
||||
# disable GL caching while animating
|
||||
|
||||
|
||||
def back(self):
|
||||
if self.loop_flag != 0: return
|
||||
self.loop_flag = -1
|
||||
@ -248,7 +252,7 @@ class vcr:
|
||||
self.tkroot.update()
|
||||
if self.saveflag: self.saveloop(0)
|
||||
self.tkroot.after(self.delay_msec,self.loop)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# play forward loop
|
||||
# disable GL caching while animating
|
||||
@ -271,11 +275,11 @@ class vcr:
|
||||
def stop(self):
|
||||
self.loop_flag = 0
|
||||
for view in self.viewlist: view.cache = 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# loop forward or back until end of animation
|
||||
# if save flag is set, change file name and save snapshots
|
||||
|
||||
|
||||
def loop(self):
|
||||
if self.loop_flag == 1 and self.index == self.nframes - 1:
|
||||
self.loop_flag = 0
|
||||
@ -292,7 +296,7 @@ class vcr:
|
||||
# since slider_frame already called it
|
||||
# but seems to be necessary before GL save() saves window to file
|
||||
# else get previous image saved into file at each frame
|
||||
|
||||
|
||||
if self.saveflag:
|
||||
for view in self.viewlist: time,natoms = view.display(self.index)
|
||||
self.saveloop(1)
|
||||
@ -309,7 +313,7 @@ class vcr:
|
||||
def frame(self,value):
|
||||
self.index = int(value)
|
||||
self.display()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def delay(self,value):
|
||||
@ -320,7 +324,7 @@ class vcr:
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def q(self,value):
|
||||
if type(value) is not types.IntType: value = self.slider_quality.get()
|
||||
if type(value) is not int: value = self.slider_quality.get()
|
||||
self.slider_quality.set(value)
|
||||
for view in self.viewlist: view.q(value)
|
||||
|
||||
@ -357,7 +361,7 @@ class vcr:
|
||||
else:
|
||||
self.boxflag = 1
|
||||
for view in self.viewlist: view.box(1)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def axis(self):
|
||||
@ -367,7 +371,7 @@ class vcr:
|
||||
else:
|
||||
self.axisflag = 1
|
||||
for view in self.viewlist: view.axis(1)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def recenter(self):
|
||||
@ -386,7 +390,7 @@ class vcr:
|
||||
self.orthoflag = 1
|
||||
self.button_ortho.config(text="Persp")
|
||||
for view in self.viewlist: view.ortho(1)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def reload(self):
|
||||
@ -449,7 +453,7 @@ class vcr:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# set filename for saving
|
||||
|
||||
|
||||
def file(self,newtext):
|
||||
oldtext = self.entry_file.get()
|
||||
self.entry_file.delete(0,len(oldtext))
|
||||
@ -457,7 +461,7 @@ class vcr:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# toggle save all checkbox
|
||||
|
||||
|
||||
def saveall(self):
|
||||
if self.saveflag:
|
||||
self.saveflag = 0
|
||||
@ -465,11 +469,11 @@ class vcr:
|
||||
else:
|
||||
self.saveflag = 1
|
||||
self.button_save.select()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# save current image to file
|
||||
# if multiple windows change filenames to file.0.png, file.1.png, etc
|
||||
|
||||
|
||||
def save(self):
|
||||
file = self.entry_file.get()
|
||||
if len(self.viewlist) == 1:
|
||||
@ -485,7 +489,7 @@ class vcr:
|
||||
# --------------------------------------------------------------------
|
||||
# save images when in a play/back loop
|
||||
# flag 0 = first save, flag 1 = continuing save, flag -1 = stop
|
||||
|
||||
|
||||
def saveloop(self,flag):
|
||||
if flag == -1:
|
||||
self.file(self.fileroot)
|
||||
@ -502,7 +506,7 @@ class vcr:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# display index frame and set status strings
|
||||
|
||||
|
||||
def display(self):
|
||||
for view in self.viewlist: time,natoms = view.display(self.index)
|
||||
self.label_frame.config(text="Frame: %d" % self.index)
|
||||
|
||||
89
src/vec.py
89
src/vec.py
@ -3,11 +3,16 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# vec tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import types
|
||||
|
||||
oneline = "Create numeric vectors from columns in file or list of vecs"
|
||||
|
||||
docstr = """
|
||||
@ -17,12 +22,12 @@ v = vec(array) array = list of numeric vectors
|
||||
skip blank lines and lines that start with non-numeric characters
|
||||
example array with 2 vecs = [[1,2,3,4,5], [10,20,30,40,50]]
|
||||
assigns names = "col1", "col2", etc
|
||||
|
||||
|
||||
nvec = v.nvec # of vectors
|
||||
nlen = v.nlen lengths of vectors
|
||||
names = v.names list of vector names
|
||||
nlen = v.nlen lengths of vectors
|
||||
names = v.names list of vector names
|
||||
x,y,... = l.get(1,"col2",...) return one or more vectors of values
|
||||
l.write("file.txt") write all vectors to a file
|
||||
l.write("file.txt") write all vectors to a file
|
||||
l.write("file.txt","col1",7,...) write listed vectors to a file
|
||||
|
||||
get and write allow abbreviated (uniquely) vector names or digits (1-Nvec)
|
||||
@ -40,10 +45,6 @@ l.write("file.txt","col1",7,...) write listed vectors to a file
|
||||
# ptr = dictionary, key = name, value = index into data for which column
|
||||
# data[i][j] = 2d array of floats, i = 0 to # of entries, j = 0 to nvecs-1
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import types
|
||||
|
||||
# Class definition
|
||||
|
||||
class vec:
|
||||
@ -52,24 +53,24 @@ class vec:
|
||||
|
||||
def __init__(self,data):
|
||||
self.data = []
|
||||
|
||||
if type(data) == types.StringType:
|
||||
|
||||
if isinstance(data,str):
|
||||
lines = open(data,'r').readlines()
|
||||
for line in lines:
|
||||
words = line.split()
|
||||
if len(words) and words[0][0] in "0123456789.-":
|
||||
self.data.append(map(float,words))
|
||||
elif type(data) == types.ListType:
|
||||
self.data.append(list(map(float,words)))
|
||||
elif isinstance(data, list):
|
||||
nlen = len(data[0])
|
||||
for list in data[1:]:
|
||||
if len(list) != nlen:
|
||||
raise StandardError,"lists are not all same length"
|
||||
for i in xrange(nlen):
|
||||
values = [list[i] for list in data]
|
||||
self.data.append(map(float,values))
|
||||
for dlist in data[1:]:
|
||||
if len(dlist) != nlen:
|
||||
raise Exception("lists are not all same length")
|
||||
for i in range(nlen):
|
||||
values = [dlist[i] for dlist in data]
|
||||
self.data.append(list(map(float,values)))
|
||||
else:
|
||||
raise StandardError,"invalid argument to vec"
|
||||
|
||||
raise Exception("invalid argument to vec")
|
||||
|
||||
if len(self.data) == 0:
|
||||
self.nlen = self.nvec = 0
|
||||
else:
|
||||
@ -77,40 +78,40 @@ class vec:
|
||||
self.nvec = len(self.data[0])
|
||||
|
||||
self.names = []
|
||||
for i in xrange(self.nvec):
|
||||
for i in range(self.nvec):
|
||||
self.names.append(str("col%d" % (i+1)))
|
||||
|
||||
self.ptr = {}
|
||||
for i in xrange(self.nvec):
|
||||
for i in range(self.nvec):
|
||||
self.ptr[self.names[i]] = i
|
||||
|
||||
print "read %d vectors of length %d" % (self.nvec,self.nlen)
|
||||
|
||||
print("read %d vectors of length %d" % (self.nvec,self.nlen))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def get(self,*keys):
|
||||
if len(keys) == 0:
|
||||
raise StandardError, "no vectors specified"
|
||||
raise Exception("no vectors specified")
|
||||
|
||||
map = []
|
||||
for key in keys:
|
||||
if type(key) == types.IntType: map.append(key-1)
|
||||
elif self.ptr.has_key(key): map.append(self.ptr[key])
|
||||
if type(key) == int: map.append(key-1)
|
||||
elif key in self.ptr: map.append(self.ptr[key])
|
||||
else:
|
||||
count = 0
|
||||
for i in range(self.nvec):
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if count == 1:
|
||||
map.append(index)
|
||||
else:
|
||||
raise StandardError, "unique vector %s not found" % key
|
||||
raise Exception("unique vector %s not found" % key)
|
||||
|
||||
vecs = []
|
||||
for i in range(len(keys)):
|
||||
vecs.append(self.nlen * [0])
|
||||
for j in xrange(self.nlen):
|
||||
for j in range(self.nlen):
|
||||
vecs[i][j] = self.data[j][map[i]]
|
||||
|
||||
if len(keys) == 1: return vecs[0]
|
||||
@ -122,24 +123,24 @@ class vec:
|
||||
if len(keys):
|
||||
map = []
|
||||
for key in keys:
|
||||
if type(key) == types.IntType: map.append(key-1)
|
||||
elif self.ptr.has_key(key): map.append(self.ptr[key])
|
||||
if type(key) == int: map.append(key-1)
|
||||
elif key in self.ptr: map.append(self.ptr[key])
|
||||
else:
|
||||
count = 0
|
||||
for i in range(self.nvec):
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if self.names[i].find(key) == 0:
|
||||
count += 1
|
||||
index = i
|
||||
if count == 1:
|
||||
map.append(index)
|
||||
else:
|
||||
raise StandardError, "unique vector %s not found" % key
|
||||
raise Exception("unique vector %s not found" % key)
|
||||
else:
|
||||
map = range(self.nvec)
|
||||
map = list(range(self.nvec))
|
||||
|
||||
f = open(filename,"w")
|
||||
for i in xrange(self.nlen):
|
||||
for j in xrange(len(map)):
|
||||
print >>f,self.data[i][map[j]],
|
||||
print >>f
|
||||
for i in range(self.nlen):
|
||||
for j in range(len(map)):
|
||||
print(self.data[i][map[j]], end=' ', file=f)
|
||||
print(file=f)
|
||||
f.close()
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# vizinfo class, not a top-level Pizza.py tool
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import types
|
||||
|
||||
# Class definition
|
||||
@ -25,7 +26,7 @@ import types
|
||||
class vizinfo:
|
||||
"""
|
||||
Information holder for Pizza.py visualization tools
|
||||
|
||||
|
||||
acolor,bcolor,tcolor,lcolor = RGB values for each atom/bond/tri/line type
|
||||
arad = radius of each atom type
|
||||
brad,lrad = thickness of each bond/line type
|
||||
@ -41,7 +42,7 @@ class vizinfo:
|
||||
setfill() = set triangle fill factor
|
||||
extend() = grow an array
|
||||
"""
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self):
|
||||
@ -57,29 +58,29 @@ class vizinfo:
|
||||
self.nbcolor = self.nbrad = 0
|
||||
self.ntcolor = self.ntfill = 0
|
||||
self.nlcolor = self.nlrad = 0
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# set color RGB for which = atoms, bonds, triangles
|
||||
|
||||
|
||||
def setcolors(self,which,ids,rgbs):
|
||||
|
||||
# convert args into lists if single values
|
||||
# if arg = 0, convert to full-range list
|
||||
|
||||
if type(ids) is types.IntType and ids == 0:
|
||||
if which == "atom": ids = range(self.nacolor)
|
||||
if which == "bond": ids = range(self.nbcolor)
|
||||
if which == "tri": ids = range(self.ntcolor)
|
||||
if which == "line": ids = range(self.nlcolor)
|
||||
if type(ids) is not types.ListType and type(ids) is not types.TupleType:
|
||||
|
||||
if type(ids) is int and ids == 0:
|
||||
if which == "atom": ids = list(range(self.nacolor))
|
||||
if which == "bond": ids = list(range(self.nbcolor))
|
||||
if which == "tri": ids = list(range(self.ntcolor))
|
||||
if which == "line": ids = list(range(self.nlcolor))
|
||||
if type(ids) is not list and type(ids) is not tuple:
|
||||
ids = [ids]
|
||||
if type(rgbs) is not types.ListType and type(rgbs) is not types.TupleType:
|
||||
if type(rgbs) is not list and type(rgbs) is not tuple:
|
||||
rgbs = [rgbs]
|
||||
|
||||
# if list of types has a 0, increment each type value
|
||||
|
||||
if 0 in ids:
|
||||
for i in xrange(len(ids)): ids[i] += 1
|
||||
for i in range(len(ids)): ids[i] += 1
|
||||
|
||||
# extend storage list if necessary
|
||||
# extend other arrays for same "which" so that gl::make_atom_calllist
|
||||
@ -101,20 +102,20 @@ class vizinfo:
|
||||
if max(ids) > self.nlcolor:
|
||||
self.nlcolor = self.extend(self.lcolor,max(ids))
|
||||
self.nlcolor = self.extend(self.lrad,max(ids))
|
||||
|
||||
|
||||
# set color for each type
|
||||
# if list lengths match, set directly, else interpolate
|
||||
# convert final color from 0-255 to 0.0-1.0
|
||||
|
||||
|
||||
ntypes = len(ids)
|
||||
nrgbs = len(rgbs)
|
||||
|
||||
for i in xrange(ntypes):
|
||||
for i in range(ntypes):
|
||||
id = ids[i]
|
||||
|
||||
if rgbs[0] == "loop":
|
||||
list = colors.keys()
|
||||
red,green,blue = colors[list[i % len(colors)]]
|
||||
colorlist = list(colors.keys())
|
||||
red,green,blue = colors[colorlist[i % len(colors)]]
|
||||
elif ntypes == nrgbs:
|
||||
red,green,blue = colors[rgbs[i]]
|
||||
else:
|
||||
@ -135,7 +136,7 @@ class vizinfo:
|
||||
if which == "bond": self.bcolor[id] = color
|
||||
if which == "tri": self.tcolor[id] = color
|
||||
if which == "line": self.lcolor[id] = color
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# set radii for which = atoms, bonds, lines
|
||||
|
||||
@ -143,21 +144,21 @@ class vizinfo:
|
||||
|
||||
# convert args into lists if single values
|
||||
# if arg = 0, convert to full-range list
|
||||
|
||||
if type(ids) is types.IntType and ids == 0:
|
||||
if which == "atom": ids = range(self.narad)
|
||||
if which == "bond": ids = range(self.nbrad)
|
||||
if which == "line": ids = range(self.nlrad)
|
||||
if type(ids) is not types.ListType and type(ids) is not types.TupleType:
|
||||
|
||||
if type(ids) is int and ids == 0:
|
||||
if which == "atom": ids = list(range(self.narad))
|
||||
if which == "bond": ids = list(range(self.nbrad))
|
||||
if which == "line": ids = list(range(self.nlrad))
|
||||
if type(ids) is not list and type(ids) is not tuple:
|
||||
ids = [ids]
|
||||
if type(radii) is not types.ListType and \
|
||||
type(radii) is not types.TupleType:
|
||||
if type(radii) is not list and \
|
||||
type(radii) is not tuple:
|
||||
radii = [radii]
|
||||
|
||||
# if list of types has a 0, increment each type value
|
||||
|
||||
if 0 in ids:
|
||||
for i in xrange(len(ids)): ids[i] += 1
|
||||
for i in range(len(ids)): ids[i] += 1
|
||||
|
||||
# extend storage list if necessary
|
||||
# extend other arrays for same "which" so that gl::make_atom_calllist
|
||||
@ -199,28 +200,28 @@ class vizinfo:
|
||||
if which == "atom": self.arad[id] = rad
|
||||
if which == "bond": self.brad[id] = rad
|
||||
if which == "line": self.lrad[id] = rad
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# set triangle fill style
|
||||
# 0 = fill only, 1 = line only, 2 = fill and line
|
||||
|
||||
|
||||
def setfills(self,which,ids,fills):
|
||||
|
||||
# convert args into lists if single values
|
||||
# if arg = 0, convert to full-range list
|
||||
|
||||
if type(ids) is types.IntType and ids == 0:
|
||||
ids = range(self.ntfill)
|
||||
if type(ids) is not types.ListType and type(ids) is not types.TupleType:
|
||||
|
||||
if type(ids) is int and ids == 0:
|
||||
ids = list(range(self.ntfill))
|
||||
if type(ids) is not list and type(ids) is not tuple:
|
||||
ids = [ids]
|
||||
if type(fills) is not types.ListType and \
|
||||
type(fills) is not types.TupleType:
|
||||
if type(fills) is not list and \
|
||||
type(fills) is not tuple:
|
||||
fills = [fills]
|
||||
|
||||
# if list of types has a 0, increment each type value
|
||||
|
||||
if 0 in ids:
|
||||
for i in xrange(len(ids)): ids[i] += 1
|
||||
for i in range(len(ids)): ids[i] += 1
|
||||
|
||||
# extend storage list if necessary
|
||||
# extend other arrays for same "which" so that gl::make_atom_calllist
|
||||
@ -234,10 +235,10 @@ class vizinfo:
|
||||
# if list lengths match, set directly, else set types to 1st fill value
|
||||
|
||||
if len(fills) == len(ids):
|
||||
for i in xrange(len(ids)): self.tfill[ids[i]] = int(fills[i])
|
||||
for i in range(len(ids)): self.tfill[ids[i]] = int(fills[i])
|
||||
else:
|
||||
for id in ids: self.tfill[id] = int(fills[0])
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def extend(self,array,n):
|
||||
|
||||
69
src/vmd.py
69
src/vmd.py
@ -3,7 +3,7 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# vmd tool
|
||||
@ -14,37 +14,38 @@
|
||||
# open a pipe to the executable,
|
||||
# and feed it Tcl command lines one at a time
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import types, os
|
||||
import numpy
|
||||
|
||||
oneline = "Control VMD from python"
|
||||
|
||||
docstr = """
|
||||
v = vmd() start up VMD
|
||||
v.stop() shut down VMD instance
|
||||
v.clear() delete all visualizations
|
||||
v = vmd() start up VMD
|
||||
v.stop() shut down VMD instance
|
||||
v.clear() delete all visualizations
|
||||
|
||||
v.rep(style) set default representation style. One of
|
||||
(Lines|VDW|Licorice|DynamicBonds|Points|CPK)
|
||||
v.new(file[,type]) load new file (default file type 'lammpstrj')
|
||||
v.rep(style) set default representation style. One of
|
||||
(Lines|VDW|Licorice|DynamicBonds|Points|CPK)
|
||||
v.new(file[,type]) load new file (default file type 'lammpstrj')
|
||||
v.data(file[,atomstyle]) load new data file (default atom style 'full')
|
||||
v.replace(file[,type]) replace current frames with new file
|
||||
v.append(file[,type]) append file to current frame(s)
|
||||
v.replace(file[,type]) replace current frames with new file
|
||||
v.append(file[,type]) append file to current frame(s)
|
||||
v.set(snap,x,y,z,(True|False)) set coordinates from a pizza.py snapshot to new or current frame
|
||||
|
||||
v.frame(frame) set current frame
|
||||
v.flush() flush pending input to VMD and update GUI
|
||||
v.read(file) read Tcl script file (e.g. saved state)
|
||||
|
||||
v.enter() enter interactive shell
|
||||
v.debug([True|False]) display generated VMD script commands?
|
||||
v.frame(frame) set current frame
|
||||
v.flush() flush pending input to VMD and update GUI
|
||||
v.read(file) read Tcl script file (e.g. saved state)
|
||||
|
||||
v.enter() enter interactive shell
|
||||
v.debug([True|False]) display generated VMD script commands?
|
||||
"""
|
||||
|
||||
# History
|
||||
# 11/10, Axel Kohlmeyer (Temple U): original version
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import types, os
|
||||
import numpy
|
||||
|
||||
try: from DEFAULTS import PIZZA_VMDNAME
|
||||
except: PIZZA_VMDNAME = "vmd"
|
||||
try: from DEFAULTS import PIZZA_VMDDIR
|
||||
@ -55,15 +56,15 @@ try: from DEFAULTS import PIZZA_VMDARCH
|
||||
except: PIZZA_VMDARCH = "LINUX"
|
||||
|
||||
try: import pexpect
|
||||
except:
|
||||
print "pexpect from http://pypi.python.org/pypi/pexpect", \
|
||||
"is required for vmd tool"
|
||||
except:
|
||||
print("pexpect from http://pypi.python.org/pypi/pexpect", \
|
||||
"is required for vmd tool")
|
||||
raise
|
||||
|
||||
# Class definition
|
||||
|
||||
class vmd:
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self):
|
||||
@ -95,7 +96,7 @@ class vmd:
|
||||
# open pipe to vmd and wait until we have a prompt
|
||||
self.VMD = pexpect.spawn(self.vmdexe)
|
||||
self.VMD.expect('vmd >')
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# post command to vmd and wait until the prompt returns.
|
||||
def __call__(self,command):
|
||||
@ -103,9 +104,9 @@ class vmd:
|
||||
self.VMD.sendline(command)
|
||||
self.VMD.expect('vmd >')
|
||||
if self.debugme:
|
||||
print "call+result:"+self.VMD.before
|
||||
print("call+result:"+self.VMD.before)
|
||||
return
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# exit VMD
|
||||
def stop(self):
|
||||
@ -121,9 +122,9 @@ class vmd:
|
||||
# turn on debugging info
|
||||
def debug(self,status=True):
|
||||
if status and not self.debugme:
|
||||
print 'Turning vmd.py debugging ON.'
|
||||
print('Turning vmd.py debugging ON.')
|
||||
if not status and self.debugme:
|
||||
print 'Turning vmd.py debugging OFF.'
|
||||
print('Turning vmd.py debugging OFF.')
|
||||
self.debugme = status
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -133,16 +134,16 @@ class vmd:
|
||||
self.__call__('menu main on')
|
||||
while 1:
|
||||
try:
|
||||
command = raw_input("vmd > ")
|
||||
command = input("vmd > ")
|
||||
except EOFError:
|
||||
print "(EOF)"
|
||||
print("(EOF)")
|
||||
self.__call__('menu main off')
|
||||
return
|
||||
if command == "quit" or command == "exit":
|
||||
self.__call__('menu main off')
|
||||
return
|
||||
if command == "gopython":
|
||||
print "gopython not supported here"
|
||||
print("gopython not supported here")
|
||||
continue
|
||||
self.__call__(command)
|
||||
|
||||
@ -190,7 +191,7 @@ class vmd:
|
||||
self.__call__('mol addfile ' + filename + ' mol $tmol type ' + filetype + ' waitfor all')
|
||||
self.__call__('foreach mol [molinfo list] { molinfo $mol set {center_matrix rotate_matrix scale_matrix global_matrix} $viewpoints($mol)}')
|
||||
self.flush()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# replace all frames of a molecule with those from a given file
|
||||
def update(self,filename,filetype='lammpstrj'):
|
||||
@ -201,7 +202,7 @@ class vmd:
|
||||
self.__call__('mol addfile ' + filename + ' mol $tmol type ' + filetype + ' waitfor all')
|
||||
self.__call__('foreach mol [molinfo list] {molinfo $mol set {center_matrix rotate_matrix scale_matrix global_matrix} $viewpoints($mol)}')
|
||||
self.flush()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# add or overwrite coordinates with coordinates in a snapshot
|
||||
def set(self,snap,x,y,z,append=True):
|
||||
|
||||
249
src/vtk.py
249
src/vtk.py
@ -3,21 +3,24 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# vtk tool
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys, re
|
||||
|
||||
oneline = "Convert LAMMPS snapshots to VTK format"
|
||||
|
||||
docstr = """
|
||||
v = vtk(d) d = object containing atom coords (dump, data)
|
||||
v = vtk(d) d = object containing atom coords (dump, data)
|
||||
|
||||
v.one() write all snapshots to tmp.vtk
|
||||
v.one("new") write all snapshots to new.vtk
|
||||
v.many() write snapshots to tmp0000.vtk, tmp0001.vtk, etc
|
||||
v.many("new") write snapshots to new0000.vtk, new0001.vtk, etc
|
||||
v.single(N) write snapshot for timestep N to tmp.vtk
|
||||
v.single(N) write snapshot for timestep N to tmp.vtk
|
||||
v.single(N,"file") write snapshot for timestep N to file.vtk
|
||||
|
||||
surfaces in snapshot will be written to SURF1.vtk, SURF2.vtk, etc
|
||||
@ -34,17 +37,15 @@ v.single(N,"file") write snapshot for timestep N to file.vtk
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys, re
|
||||
|
||||
# Class definition
|
||||
|
||||
class vtk:
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self,data):
|
||||
self.data = data
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def one(self,*args):
|
||||
@ -55,27 +56,27 @@ class vtk:
|
||||
n = flag = 0
|
||||
which,time,flag = self.data.iterator(flag)
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(which)
|
||||
print time,
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
|
||||
if len(tris): surface(tris)
|
||||
|
||||
|
||||
allatoms = []
|
||||
for atom in atoms:
|
||||
allatoms.append(atom)
|
||||
|
||||
|
||||
while 1:
|
||||
which,time,flag = self.data.iterator(flag)
|
||||
if flag == -1: break
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(which)
|
||||
|
||||
|
||||
for atom in atoms: allatoms.append(atom)
|
||||
print time,
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
particle(file,allatoms)
|
||||
print "\nwrote %d snapshots to %s in VTK format" % (n,file)
|
||||
print("\nwrote %d snapshots to %s in VTK format" % (n,file))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
@ -93,7 +94,7 @@ class vtk:
|
||||
if surfflag == 0 and len(tris):
|
||||
surfflag = 1
|
||||
surface(tris)
|
||||
|
||||
|
||||
if n < 10:
|
||||
file = root + "000" + str(n) + ".vtk"
|
||||
elif n < 100:
|
||||
@ -104,19 +105,19 @@ class vtk:
|
||||
file = root + str(n) + ".vtk"
|
||||
|
||||
particle(file,atoms)
|
||||
|
||||
print time,
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
print "\nwrote %s snapshots in VTK format" % n
|
||||
|
||||
print("\nwrote %s snapshots in VTK format" % n)
|
||||
# --------------------------------------------------------------------
|
||||
def manyGran(self,*args,**kwargs):
|
||||
|
||||
|
||||
# check whether to output or not
|
||||
outputfl = True
|
||||
if "output" in kwargs: outputfl = kwargs["output"]
|
||||
|
||||
|
||||
# read startIndex (offset for filename due to parallel processing)
|
||||
startIndex = 0
|
||||
fileNos = []
|
||||
@ -124,14 +125,14 @@ class vtk:
|
||||
fileNos = kwargs["fileNos"]
|
||||
else:
|
||||
fileNos = range(len(self.data.snaps))
|
||||
|
||||
|
||||
# output name
|
||||
if len(args) == 0: root = "tmp"
|
||||
else: root = args[0]
|
||||
|
||||
surfflag = 0
|
||||
n = flag = 0
|
||||
|
||||
|
||||
# iterate over snaps
|
||||
while 1:
|
||||
which,time,flag = self.data.iterator(flag)
|
||||
@ -143,14 +144,14 @@ class vtk:
|
||||
yhi=self.data.snaps[n].yhi
|
||||
zlo=self.data.snaps[n].zlo
|
||||
zhi=self.data.snaps[n].zhi
|
||||
|
||||
|
||||
atoms=self.data.snaps[n].atoms
|
||||
names=self.data.names
|
||||
|
||||
if surfflag == 0 and len(tris):
|
||||
surfflag = 1
|
||||
surface(tris)
|
||||
|
||||
|
||||
file, file_bb, file_walls = generateFilename(root,fileNos,n)
|
||||
|
||||
boundingBox(file_bb,xlo,xhi,ylo,yhi,zlo,zhi)
|
||||
@ -158,12 +159,12 @@ class vtk:
|
||||
try: nvalues = len(self.data.snaps[0].atoms[0])
|
||||
except: nvalues = 0
|
||||
particleGran(file,atoms,names,nvalues)
|
||||
|
||||
if outputfl: print time,
|
||||
|
||||
if outputfl: print(time, end=' ')
|
||||
if outputfl: sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
if outputfl: print "\nwrote %s granular snapshots in VTK format" % n
|
||||
|
||||
if outputfl: print("\nwrote %s granular snapshots in VTK format" % n)
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def single(self,time,*args):
|
||||
@ -209,8 +210,8 @@ def generateFilename(root,fileNos,n):
|
||||
|
||||
def surface(tris):
|
||||
ntypes = tris[-1][1]
|
||||
|
||||
for i in xrange(ntypes):
|
||||
|
||||
for i in range(ntypes):
|
||||
itype = i+1
|
||||
v = {}
|
||||
nvert = ntri = 0
|
||||
@ -218,35 +219,35 @@ def surface(tris):
|
||||
if tri[1] == itype:
|
||||
ntri += 1
|
||||
vert = (tri[2],tri[3],tri[4])
|
||||
if not v.has_key(vert):
|
||||
if vert not in v:
|
||||
v[vert] = nvert
|
||||
nvert += 1
|
||||
vert = (tri[5],tri[6],tri[7])
|
||||
if not v.has_key(vert):
|
||||
if vert not in v:
|
||||
v[vert] = nvert
|
||||
nvert += 1
|
||||
vert = (tri[8],tri[9],tri[10])
|
||||
if not v.has_key(vert):
|
||||
if vert not in v:
|
||||
v[vert] = nvert
|
||||
nvert += 1
|
||||
|
||||
keys = v.keys()
|
||||
keys = list(v.keys())
|
||||
vinverse = {}
|
||||
for key in keys:
|
||||
vinverse[v[key]] = key
|
||||
|
||||
|
||||
filename = "SURF" + str(itype) + ".vtk"
|
||||
f = open(filename,"w")
|
||||
|
||||
print >>f,"# vtk DataFile Version 3.0"
|
||||
print >>f,"Generated by pizza.py"
|
||||
print >>f,"ASCII"
|
||||
print >>f,"DATASET POLYDATA"
|
||||
print >>f,"POINTS %d float" % nvert
|
||||
for i in xrange(nvert):
|
||||
|
||||
print("# vtk DataFile Version 3.0", file=f)
|
||||
print("Generated by pizza.py", file=f)
|
||||
print("ASCII", file=f)
|
||||
print("DATASET POLYDATA", file=f)
|
||||
print("POINTS %d float" % nvert, file=f)
|
||||
for i in range(nvert):
|
||||
tuple = vinverse[i]
|
||||
print >>f,tuple[0],tuple[1],tuple[2]
|
||||
print >>f,"POLYGONS",ntri,4*ntri
|
||||
print(tuple[0],tuple[1],tuple[2], file=f)
|
||||
print("POLYGONS",ntri,4*ntri, file=f)
|
||||
for tri in tris:
|
||||
if tri[1] == itype:
|
||||
vert = (tri[2],tri[3],tri[4])
|
||||
@ -255,10 +256,10 @@ def surface(tris):
|
||||
ivert2 = v[vert]
|
||||
vert = (tri[8],tri[9],tri[10])
|
||||
ivert3 = v[vert]
|
||||
print >>f,3,ivert1,ivert2,ivert3
|
||||
print >>f
|
||||
print >>f,"CELL_DATA",ntri
|
||||
print >>f,"POINT_DATA",nvert
|
||||
print(3,ivert1,ivert2,ivert3, file=f)
|
||||
print(file=f)
|
||||
print("CELL_DATA",ntri, file=f)
|
||||
print("POINT_DATA",nvert, file=f)
|
||||
|
||||
f.close()
|
||||
|
||||
@ -267,42 +268,42 @@ def surface(tris):
|
||||
|
||||
def particle(file,atoms):
|
||||
f = open(file,"w")
|
||||
|
||||
print >>f,"# vtk DataFile Version 2.0"
|
||||
print >>f,"Generated by pizza.py"
|
||||
print >>f,"ASCII"
|
||||
print >>f,"DATASET POLYDATA"
|
||||
print >>f,"POINTS %d float" % len(atoms)
|
||||
|
||||
print("# vtk DataFile Version 2.0", file=f)
|
||||
print("Generated by pizza.py", file=f)
|
||||
print("ASCII", file=f)
|
||||
print("DATASET POLYDATA", file=f)
|
||||
print("POINTS %d float" % len(atoms), file=f)
|
||||
for atom in atoms:
|
||||
print >>f,atom[2],atom[3],atom[4]
|
||||
print >>f,"VERTICES",len(atoms),2*len(atoms)
|
||||
for i in xrange(len(atoms)):
|
||||
print >>f,1,i
|
||||
print >>f,"POINT_DATA",len(atoms)
|
||||
print >>f,"SCALARS atom_type int 1"
|
||||
print >>f,"LOOKUP_TABLE default"
|
||||
print(atom[2],atom[3],atom[4], file=f)
|
||||
print("VERTICES",len(atoms),2*len(atoms), file=f)
|
||||
for i in range(len(atoms)):
|
||||
print(1,i, file=f)
|
||||
print("POINT_DATA",len(atoms), file=f)
|
||||
print("SCALARS atom_type int 1", file=f)
|
||||
print("LOOKUP_TABLE default", file=f)
|
||||
for atom in atoms:
|
||||
itype = int(atom[1])
|
||||
print >>f,itype,
|
||||
print >>f
|
||||
|
||||
print(itype, end=' ', file=f)
|
||||
print(file=f)
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
def boundingBox(file,xlo,xhi,ylo,yhi,zlo,zhi):
|
||||
f = open(file,"w")
|
||||
|
||||
print >>f,"# vtk DataFile Version 2.0"
|
||||
print >>f,"Generated by pizza.py"
|
||||
print >>f,"ASCII"
|
||||
print >>f,"DATASET RECTILINEAR_GRID"
|
||||
print >>f,"DIMENSIONS 2 2 2"
|
||||
print >>f,"X_COORDINATES 2 float"
|
||||
print >>f,xlo,xhi
|
||||
print >>f,"Y_COORDINATES 2 float"
|
||||
print >>f,ylo,yhi
|
||||
print >>f,"Z_COORDINATES 2 float"
|
||||
print >>f,zlo,zhi
|
||||
|
||||
print("# vtk DataFile Version 2.0", file=f)
|
||||
print("Generated by pizza.py", file=f)
|
||||
print("ASCII", file=f)
|
||||
print("DATASET RECTILINEAR_GRID", file=f)
|
||||
print("DIMENSIONS 2 2 2", file=f)
|
||||
print("X_COORDINATES 2 float", file=f)
|
||||
print(xlo,xhi, file=f)
|
||||
print("Y_COORDINATES 2 float", file=f)
|
||||
print(ylo,yhi, file=f)
|
||||
print("Z_COORDINATES 2 float", file=f)
|
||||
print(zlo,zhi, file=f)
|
||||
|
||||
def typestr(o):
|
||||
string = str(type(o))
|
||||
@ -311,39 +312,39 @@ def typestr(o):
|
||||
|
||||
def particleGran(file,atoms,names,n_values):
|
||||
f = open(file,"w")
|
||||
|
||||
|
||||
# if no atoms are present
|
||||
if atoms is None:
|
||||
atoms = []
|
||||
|
||||
|
||||
# find indices of scalars and vectors
|
||||
scalars, vectors = findScalarsAndVectors(names)
|
||||
|
||||
|
||||
# print head
|
||||
print >>f,"# vtk DataFile Version 2.0"
|
||||
print >>f,"Generated by lpp.py"
|
||||
print >>f,"ASCII"
|
||||
print >>f,"DATASET POLYDATA"
|
||||
print >>f,"POINTS %d float" % len(atoms)
|
||||
print("# vtk DataFile Version 2.0", file=f)
|
||||
print("Generated by lpp.py", file=f)
|
||||
print("ASCII", file=f)
|
||||
print("DATASET POLYDATA", file=f)
|
||||
print("POINTS %d float" % len(atoms), file=f)
|
||||
for atom in atoms:
|
||||
print >>f, atom[vectors['x']], atom[vectors['x']+1], atom[vectors['x']+2] #atom[3],atom[4],atom[5] #write x,y,z [atom[0]=id, atom[1]=type]
|
||||
print >>f,"VERTICES",len(atoms),2*len(atoms)
|
||||
for i in xrange(len(atoms)):
|
||||
print >>f,1,i
|
||||
print >>f,"POINT_DATA",len(atoms)
|
||||
|
||||
print(atom[vectors['x']], atom[vectors['x']+1], atom[vectors['x']+2] , file=f) #atom[3],atom[4],atom[5] #write x,y,z [atom[0]=id, atom[1]=type]
|
||||
print("VERTICES", len(atoms), 2*len(atoms), file=f)
|
||||
for i in range(len(atoms)):
|
||||
print(1,i, file=f)
|
||||
print("POINT_DATA",len(atoms), file=f)
|
||||
|
||||
if len(atoms) == 0:
|
||||
print >> f
|
||||
print('', file=f)
|
||||
f.close()
|
||||
return
|
||||
|
||||
# print VECTORS
|
||||
for key in vectors.keys():
|
||||
|
||||
|
||||
# don't print coodinates again
|
||||
if key == 'x':
|
||||
continue
|
||||
|
||||
|
||||
vectortype = 'float'
|
||||
if atoms != []:
|
||||
vectortype = typestr(atoms[0][vectors[key]])
|
||||
@ -352,11 +353,11 @@ def particleGran(file,atoms,names,n_values):
|
||||
else: vectortype = 'float'
|
||||
else: # if no atoms are present
|
||||
pass
|
||||
|
||||
print >>f,"VECTORS",key,vectortype
|
||||
|
||||
print("VECTORS",key,vectortype, file=f)
|
||||
for atom in atoms:
|
||||
print >>f, atom[vectors[key]], atom[vectors[key]+1], atom[vectors[key]+2]
|
||||
|
||||
print(atom[vectors[key]], atom[vectors[key]+1], atom[vectors[key]+2], file=f)
|
||||
|
||||
# print SCALARS
|
||||
for key in scalars.keys():
|
||||
scalartype =''
|
||||
@ -367,30 +368,30 @@ def particleGran(file,atoms,names,n_values):
|
||||
else: scalartype = 'int'
|
||||
else: # if no atoms are present
|
||||
pass
|
||||
|
||||
print >>f,"SCALARS",key,scalartype,1
|
||||
print >>f,"LOOKUP_TABLE default"
|
||||
|
||||
print("SCALARS",key,scalartype,1, file=f)
|
||||
print("LOOKUP_TABLE default", file=f)
|
||||
for atom in atoms:
|
||||
print >>f, atom[scalars[key]]
|
||||
|
||||
print >>f
|
||||
print(atom[scalars[key]], file=f)
|
||||
|
||||
print('', file=f)
|
||||
f.close()
|
||||
|
||||
def findScalarsAndVectors(names):
|
||||
|
||||
|
||||
vectors={}
|
||||
scalars={}
|
||||
|
||||
|
||||
# create reversed dictionary {position:name}
|
||||
indices = {}
|
||||
for name in names:
|
||||
indices[names[name]]=name
|
||||
|
||||
|
||||
# fill missing indices (occurrs e.g. if output is like vx vy vz fx fy fz vx vy vz)
|
||||
for i in xrange(max(indices)):
|
||||
for i in range(max(indices)):
|
||||
if i not in indices:
|
||||
indices[i]=""
|
||||
|
||||
|
||||
# compile regexes to find vectors
|
||||
regvx = re.compile(".*x")
|
||||
regvy = re.compile(".*y")
|
||||
@ -398,53 +399,53 @@ def findScalarsAndVectors(names):
|
||||
regf = re.compile("f_.*\[[0-9]+\]")
|
||||
regc = re.compile("c_.*\[[0-9]+\]")
|
||||
regv = re.compile("v_.*\[[0-9]+\]")
|
||||
|
||||
|
||||
# loop over all indices and look if their names represent a vector (if not: it's a scalar)
|
||||
i = 0
|
||||
while i<= max(indices):
|
||||
|
||||
|
||||
if i+2 <= max(indices) and regvx.match(indices[i]) != None and regvy.match(indices[i+1]) != None and regvz.match(indices[i+2]) != None:
|
||||
|
||||
|
||||
newname=''
|
||||
if len(indices[i]) == 1:
|
||||
newname=indices[i]
|
||||
else:
|
||||
newname=indices[i][:-1]
|
||||
|
||||
|
||||
vectors[newname]=i
|
||||
i+=3
|
||||
continue
|
||||
|
||||
|
||||
if regf.match(indices[i]) != None or regc.match(indices[i]) != None or regv.match(indices[i]) != None:
|
||||
|
||||
|
||||
name = indices[i]
|
||||
number = int( name.split('[')[1].split(']')[0] )
|
||||
nextName = name.split('[')[0]+'['+str(number+1)+']'
|
||||
nextButOneName = name.split('[')[0]+'['+str(number+2)+']'
|
||||
|
||||
|
||||
newname = name[2:-(len(name.split('[')[1])+1)]
|
||||
|
||||
|
||||
if i+2 <= max(indices) and indices[i+1] == nextName and indices[i+2] == nextButOneName:
|
||||
vectors[newname]=i
|
||||
i+=3
|
||||
continue
|
||||
|
||||
|
||||
else:
|
||||
scalars[newname]=i
|
||||
i+=1
|
||||
continue
|
||||
|
||||
|
||||
# program only here if not a vector
|
||||
if indices[i] != '':
|
||||
newname = indices[i]
|
||||
scalars[newname]=i
|
||||
i+=1
|
||||
|
||||
|
||||
if 'x' not in vectors.keys():
|
||||
print "vector x y z has to be contained in dump file. please change liggghts input script accordingly."
|
||||
print("vector x y z has to be contained in dump file. please change liggghts input script accordingly.")
|
||||
exit()
|
||||
|
||||
|
||||
return scalars, vectors
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
57
src/xyz.py
57
src/xyz.py
@ -3,22 +3,26 @@
|
||||
#
|
||||
# Copyright (2005) Sandia Corporation. Under the terms of Contract
|
||||
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
# certain rights in this software. This software is distributed under
|
||||
# certain rights in this software. This software is distributed under
|
||||
# the GNU General Public License.
|
||||
|
||||
# xyz tool
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
from __future__ import print_function, absolute_import
|
||||
import sys
|
||||
oneline = "Convert LAMMPS snapshots to XYZ format"
|
||||
|
||||
docstr = """
|
||||
x = xyz(d) d = object containing atom coords (dump, data)
|
||||
x = xyz(d) d = object containing atom coords (dump, data)
|
||||
|
||||
x.one() write all snapshots to tmp.xyz
|
||||
x.one("new") write all snapshots to new.xyz
|
||||
x.many() write snapshots to tmp0000.xyz, tmp0001.xyz, etc
|
||||
x.many("new") write snapshots to new0000.xyz, new0001.xyz, etc
|
||||
x.single(N) write snapshot for timestep N to tmp.xyz
|
||||
x.single(N,"file") write snapshot for timestep N to file.xyz
|
||||
x.single(N) write snapshot for timestep N to tmp.xyz
|
||||
x.single(N,"file") write snapshot for timestep N to file.xyz
|
||||
"""
|
||||
|
||||
# History
|
||||
@ -29,9 +33,6 @@ x.single(N,"file") write snapshot for timestep N to file.xyz
|
||||
# Variables
|
||||
# data = data file to read from
|
||||
|
||||
# Imports and external programs
|
||||
|
||||
import sys
|
||||
|
||||
# Class definition
|
||||
|
||||
@ -41,7 +42,7 @@ class xyz:
|
||||
|
||||
def __init__(self,data):
|
||||
self.data = data
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def one(self,*args):
|
||||
@ -56,19 +57,19 @@ class xyz:
|
||||
if flag == -1: break
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(which)
|
||||
|
||||
print >>f,len(atoms)
|
||||
print >>f,"Atoms"
|
||||
print(len(atoms), file=f)
|
||||
print("Atoms", file=f)
|
||||
for atom in atoms:
|
||||
itype = int(atom[1])
|
||||
print >>f,itype,atom[2],atom[3],atom[4]
|
||||
|
||||
print time,
|
||||
print(itype,atom[2],atom[3],atom[4], file=f)
|
||||
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
|
||||
|
||||
f.close()
|
||||
print "\nwrote %d snapshots to %s in XYZ format" % (n,file)
|
||||
|
||||
print("\nwrote %d snapshots to %s in XYZ format" % (n,file))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def many(self,*args):
|
||||
@ -80,7 +81,7 @@ class xyz:
|
||||
which,time,flag = self.data.iterator(flag)
|
||||
if flag == -1: break
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(which)
|
||||
|
||||
|
||||
if n < 10:
|
||||
file = root + "000" + str(n)
|
||||
elif n < 100:
|
||||
@ -88,21 +89,21 @@ class xyz:
|
||||
elif n < 1000:
|
||||
file = root + "0" + str(n)
|
||||
else:
|
||||
file = root + str(n)
|
||||
file = root + str(n)
|
||||
file += ".xyz"
|
||||
f = open(file,"w")
|
||||
print >>f,len(atoms)
|
||||
print >>f,"Atoms"
|
||||
print(len(atoms), file=f)
|
||||
print("Atoms", file=f)
|
||||
for atom in atoms:
|
||||
itype = int(atom[1])
|
||||
print >>f,itype,atom[2],atom[3],atom[4]
|
||||
print time,
|
||||
print(itype,atom[2],atom[3],atom[4], file=f)
|
||||
print(time, end=' ')
|
||||
sys.stdout.flush()
|
||||
f.close()
|
||||
n += 1
|
||||
|
||||
print "\nwrote %s snapshots in XYZ format" % n
|
||||
|
||||
|
||||
print("\nwrote %s snapshots in XYZ format" % n)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def single(self,time,*args):
|
||||
@ -113,9 +114,9 @@ class xyz:
|
||||
which = self.data.findtime(time)
|
||||
time,box,atoms,bonds,tris,lines = self.data.viz(which)
|
||||
f = open(file,"w")
|
||||
print >>f,len(atoms)
|
||||
print >>f,"Atoms"
|
||||
print(len(atoms), file=f)
|
||||
print("Atoms", file=f)
|
||||
for atom in atoms:
|
||||
itype = int(atom[1])
|
||||
print >>f,itype,atom[2],atom[3],atom[4]
|
||||
print(itype,atom[2],atom[3],atom[4], file=f)
|
||||
f.close()
|
||||
|
||||
Reference in New Issue
Block a user