get rid of (evil) tabs and trailing whitespace in bundled Pizza.py components

This commit is contained in:
Axel Kohlmeyer
2019-09-19 07:34:27 -04:00
parent df3fad3b49
commit c26c8aca4f
6 changed files with 197 additions and 197 deletions

View File

@ -3,7 +3,7 @@
# #
# Copyright (2005) Sandia Corporation. Under the terms of Contract # Copyright (2005) Sandia Corporation. Under the terms of Contract
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains # 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. # the GNU General Public License.
# cfg tool # cfg tool
@ -11,14 +11,14 @@
oneline = "Convert LAMMPS snapshots to AtomEye CFG format" oneline = "Convert LAMMPS snapshots to AtomEye CFG format"
docstr = """ 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() write all snapshots to tmp.cfg
c.one("new") write all snapshots to new.cfg c.one("new") write all snapshots to new.cfg
c.many() write snapshots to tmp0000.cfg, tmp0001.cfg, etc c.many() write snapshots to tmp0000.cfg, tmp0001.cfg, etc
c.many("new") write snapshots to new0000.cfg, new0001.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) write snapshot for timestep N to tmp.cfg
c.single(N,"file") write snapshot for timestep N to file.cfg c.single(N,"file") write snapshot for timestep N to file.cfg
""" """
# History # History
@ -46,7 +46,7 @@ class cfg:
def __init__(self,data): def __init__(self,data):
self.data = data self.data = data
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def one(self,*args): def one(self,*args):
@ -68,16 +68,16 @@ class cfg:
print >>f,"Number of particles = %d " % len(atoms) print >>f,"Number of particles = %d " % len(atoms)
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
print >>f,"H0(1,1) = %20.10f A " % xlen print >>f,"H0(1,1) = %20.10f A " % xlen
print >>f,"H0(1,2) = 0.0 A " print >>f,"H0(1,2) = 0.0 A "
print >>f,"H0(1,3) = 0.0 A " print >>f,"H0(1,3) = 0.0 A "
print >>f,"H0(2,1) = 0.0 A " print >>f,"H0(2,1) = 0.0 A "
print >>f,"H0(2,2) = %20.10f A " % ylen print >>f,"H0(2,2) = %20.10f A " % ylen
print >>f,"H0(2,3) = 0.0 A " print >>f,"H0(2,3) = 0.0 A "
print >>f,"H0(3,1) = 0.0 A " print >>f,"H0(3,1) = 0.0 A "
print >>f,"H0(3,2) = 0.0 A " print >>f,"H0(3,2) = 0.0 A "
print >>f,"H0(3,3) = %20.10f A " % zlen print >>f,"H0(3,3) = %20.10f A " % zlen
print >>f,"#" print >>f,"#"
for atom in atoms: for atom in atoms:
itype = int(atom[1]) itype = int(atom[1])
xfrac = (atom[2]-box[0])/xlen xfrac = (atom[2]-box[0])/xlen
@ -85,14 +85,14 @@ class cfg:
zfrac = (atom[4]-box[2])/zlen 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 %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 >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
print time, print time,
sys.stdout.flush() sys.stdout.flush()
n += 1 n += 1
f.close() 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): def many(self,*args):
@ -104,7 +104,7 @@ class cfg:
which,time,flag = self.data.iterator(flag) which,time,flag = self.data.iterator(flag)
if flag == -1: break if flag == -1: break
time,box,atoms,bonds,tris,lines = self.data.viz(which) time,box,atoms,bonds,tris,lines = self.data.viz(which)
if n < 10: if n < 10:
file = root + "000" + str(n) file = root + "000" + str(n)
elif n < 100: elif n < 100:
@ -112,7 +112,7 @@ class cfg:
elif n < 1000: elif n < 1000:
file = root + "0" + str(n) file = root + "0" + str(n)
else: else:
file = root + str(n) file = root + str(n)
file += ".cfg" file += ".cfg"
f = open(file,"w") f = open(file,"w")
@ -123,16 +123,16 @@ class cfg:
print >>f,"Number of particles = %d " % len(atoms) print >>f,"Number of particles = %d " % len(atoms)
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
print >>f,"H0(1,1) = %20.10f A " % xlen print >>f,"H0(1,1) = %20.10f A " % xlen
print >>f,"H0(1,2) = 0.0 A " print >>f,"H0(1,2) = 0.0 A "
print >>f,"H0(1,3) = 0.0 A " print >>f,"H0(1,3) = 0.0 A "
print >>f,"H0(2,1) = 0.0 A " print >>f,"H0(2,1) = 0.0 A "
print >>f,"H0(2,2) = %20.10f A " % ylen print >>f,"H0(2,2) = %20.10f A " % ylen
print >>f,"H0(2,3) = 0.0 A " print >>f,"H0(2,3) = 0.0 A "
print >>f,"H0(3,1) = 0.0 A " print >>f,"H0(3,1) = 0.0 A "
print >>f,"H0(3,2) = 0.0 A " print >>f,"H0(3,2) = 0.0 A "
print >>f,"H0(3,3) = %20.10f A " % zlen print >>f,"H0(3,3) = %20.10f A " % zlen
print >>f,"#" print >>f,"#"
for atom in atoms: for atom in atoms:
itype = int(atom[1]) itype = int(atom[1])
xfrac = (atom[2]-box[0])/xlen xfrac = (atom[2]-box[0])/xlen
@ -140,14 +140,14 @@ class cfg:
zfrac = (atom[4]-box[2])/zlen 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 %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 >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
print time, print time,
sys.stdout.flush() sys.stdout.flush()
f.close() f.close()
n += 1 n += 1
print "\nwrote %s snapshots in CFG format" % n print "\nwrote %s snapshots in CFG format" % n
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def single(self,time,*args): def single(self,time,*args):
@ -166,16 +166,16 @@ class cfg:
print >>f,"Number of particles = %d " % len(atoms) print >>f,"Number of particles = %d " % len(atoms)
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time
print >>f,"H0(1,1) = %20.10f A " % xlen print >>f,"H0(1,1) = %20.10f A " % xlen
print >>f,"H0(1,2) = 0.0 A " print >>f,"H0(1,2) = 0.0 A "
print >>f,"H0(1,3) = 0.0 A " print >>f,"H0(1,3) = 0.0 A "
print >>f,"H0(2,1) = 0.0 A " print >>f,"H0(2,1) = 0.0 A "
print >>f,"H0(2,2) = %20.10f A " % ylen print >>f,"H0(2,2) = %20.10f A " % ylen
print >>f,"H0(2,3) = 0.0 A " print >>f,"H0(2,3) = 0.0 A "
print >>f,"H0(3,1) = 0.0 A " print >>f,"H0(3,1) = 0.0 A "
print >>f,"H0(3,2) = 0.0 A " print >>f,"H0(3,2) = 0.0 A "
print >>f,"H0(3,3) = %20.10f A " % zlen print >>f,"H0(3,3) = %20.10f A " % zlen
print >>f,"#" print >>f,"#"
for atom in atoms: for atom in atoms:
itype = int(atom[1]) itype = int(atom[1])
xfrac = (atom[2]-box[0])/xlen xfrac = (atom[2]-box[0])/xlen
@ -183,5 +183,5 @@ class cfg:
zfrac = (atom[4]-box[2])/zlen 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 %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 >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac)
f.close() f.close()

View File

@ -3,7 +3,7 @@
# #
# Copyright (2005) Sandia Corporation. Under the terms of Contract # Copyright (2005) Sandia Corporation. Under the terms of Contract
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains # 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. # the GNU General Public License.
# dump tool # dump tool
@ -12,15 +12,15 @@ oneline = "Read, write, manipulate dump files and particle attributes"
docstr = """ docstr = """
d = dump("dump.one") read in one or more dump files d = dump("dump.one") read in one or more dump files
d = dump("dump.1 dump.2.gz") can be gzipped d = dump("dump.1 dump.2.gz") can be gzipped
d = dump("dump.*") wildcard expands to multiple files d = dump("dump.*") wildcard expands to multiple files
d = dump("dump.*",0) two args = store filenames, but don't read d = dump("dump.*",0) two args = store filenames, but don't read
incomplete and duplicate snapshots are deleted incomplete and duplicate snapshots are deleted
atoms will be unscaled if stored in files as scaled atoms will be unscaled if stored in files as scaled
self-describing column names assigned self-describing column names assigned
time = d.next() read next snapshot from dump files time = d.next() read next snapshot from dump files
used with 2-argument constructor to allow reading snapshots one-at-a-time 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 snapshot will be skipped only if another snapshot has same time stamp
@ -31,21 +31,21 @@ time = d.next() read next snapshot from dump files
d.map(1,"id",3,"x") assign names to columns (1-N) d.map(1,"id",3,"x") assign names to columns (1-N)
not needed if dump file is self-describing not needed if dump file is self-describing
d.tselect.all() select all timesteps d.tselect.all() select all timesteps
d.tselect.one(N) select only timestep N d.tselect.one(N) select only timestep N
d.tselect.none() deselect all timesteps d.tselect.none() deselect all timesteps
d.tselect.skip(M) select every Mth step d.tselect.skip(M) select every Mth step
d.tselect.test("$t >= 100 and $t < 10000") select matching timesteps d.tselect.test("$t >= 100 and $t < 10000") select matching timesteps
d.delete() delete non-selected timesteps d.delete() delete non-selected timesteps
selecting a timestep also selects all atoms in the timestep selecting a timestep also selects all atoms in the timestep
skip() and test() only select from currently selected timesteps skip() and test() only select from currently selected timesteps
test() uses a Python Boolean expression with $t for timestep value test() uses a Python Boolean expression with $t for timestep value
Python comparison syntax: == != < > <= >= and or Python comparison syntax: == != < > <= >= and or
d.aselect.all() select all atoms in all steps d.aselect.all() select all atoms in all steps
d.aselect.all(N) select all atoms in one step d.aselect.all(N) select all atoms in one step
d.aselect.test("$id > 100 and $type == 2") select match atoms in all steps d.aselect.test("$id > 100 and $type == 2") select match atoms in all steps
d.aselect.test("$id > 100 and $type == 2",N) select matching atoms in one step d.aselect.test("$id > 100 and $type == 2",N) select matching atoms in one step
@ -56,24 +56,24 @@ d.aselect.test("$id > 100 and $type == 2",N) select matching atoms in one step
Python comparison syntax: == != < > <= >= and or Python comparison syntax: == != < > <= >= and or
$name must end with a space $name must end with a space
d.write("file") write selected steps/atoms to dump file d.write("file") write selected steps/atoms to dump file
d.write("file",head,app) write selected steps/atoms to dump file d.write("file",head,app) write selected steps/atoms to dump file
d.scatter("tmp") write selected steps/atoms to multiple files d.scatter("tmp") write selected steps/atoms to multiple files
write() can be specified with 2 additional flags write() can be specified with 2 additional flags
head = 0/1 for no/yes snapshot header, app = 0/1 for write vs append head = 0/1 for no/yes snapshot header, app = 0/1 for write vs append
scatter() files are given timestep suffix: e.g. tmp.0, tmp.100, etc scatter() files are given timestep suffix: e.g. tmp.0, tmp.100, etc
d.scale() scale x,y,z to 0-1 for all timesteps d.scale() scale x,y,z to 0-1 for all timesteps
d.scale(100) scale atom coords for timestep N d.scale(100) scale atom coords for timestep N
d.unscale() unscale x,y,z to box size to all timesteps d.unscale() unscale x,y,z to box size to all timesteps
d.unscale(1000) unscale atom coords for timestep N d.unscale(1000) unscale atom coords for timestep N
d.wrap() wrap x,y,z into periodic box via ix,iy,iz d.wrap() wrap x,y,z into periodic box via ix,iy,iz
d.unwrap() unwrap x,y,z out of box via ix,iy,iz d.unwrap() unwrap x,y,z out of box via ix,iy,iz
d.owrap("other") wrap x,y,z to same image as another atom d.owrap("other") wrap x,y,z to same image as another atom
d.sort() sort atoms by atom ID in all selected steps d.sort() sort atoms by atom ID in all selected steps
d.sort("x") sort atoms by column value in all steps d.sort("x") sort atoms by column value in all steps
d.sort(1000) sort atoms in timestep N d.sort(1000) sort atoms in timestep N
scale(), unscale(), wrap(), unwrap(), owrap() operate on all steps and atoms scale(), unscale(), wrap(), unwrap(), owrap() operate on all steps and atoms
wrap(), unwrap(), owrap() require ix,iy,iz be defined wrap(), unwrap(), owrap() require ix,iy,iz be defined
@ -85,8 +85,8 @@ d.sort(1000) sort atoms in timestep N
m1,m2 = d.minmax("type") find min/max values for a column m1,m2 = d.minmax("type") find min/max values for a column
d.set("$ke = $vx * $vx + $vy * $vy") set a column to a computed value d.set("$ke = $vx * $vx + $vy * $vy") set a column to a computed value
d.setv("type",vector) set a column to a vector of values d.setv("type",vector) set a column to a vector of values
d.spread("ke",N,"color") 2nd col = N ints spread over 1st col d.spread("ke",N,"color") 2nd col = N ints spread over 1st col
d.clone(1000,"color") clone timestep N values to other steps d.clone(1000,"color") clone timestep N values to other steps
minmax() operates on selected timesteps and atoms minmax() operates on selected timesteps and atoms
set() operates on selected timesteps and atoms set() operates on selected timesteps and atoms
@ -107,17 +107,17 @@ d.clone(1000,"color") clone timestep N values to other steps
values at every timestep are set to value at timestep N for that atom ID values at every timestep are set to value at timestep N for that atom ID
useful for propagating a color map useful for propagating a color map
t = d.time() return vector of selected timestep values t = d.time() return vector of selected timestep values
fx,fy,... = d.atom(100,"fx","fy",...) return vector(s) for atom ID N fx,fy,... = d.atom(100,"fx","fy",...) return vector(s) for atom ID N
fx,fy,... = d.vecs(1000,"fx","fy",...) return vector(s) for timestep N fx,fy,... = d.vecs(1000,"fx","fy",...) return vector(s) for timestep N
atom() returns vectors with one value for each selected timestep atom() returns vectors with one value for each selected timestep
vecs() returns vectors with one value for each selected atom in the timestep vecs() returns vectors with one value for each selected atom in the timestep
index,time,flag = d.iterator(0/1) loop over dump snapshots index,time,flag = d.iterator(0/1) loop over dump snapshots
time,box,atoms,bonds,tris,lines = d.viz(index) return list of viz objects time,box,atoms,bonds,tris,lines = d.viz(index) return list of viz objects
d.atype = "color" set column returned as "type" by viz d.atype = "color" set column returned as "type" by viz
d.extra(obj) extract bond/tri/line info from obj d.extra(obj) extract bond/tri/line info from obj
iterator() loops over selected timesteps iterator() loops over selected timesteps
iterator() called with arg = 0 first time, with arg = 1 on subsequent calls iterator() called with arg = 0 first time, with arg = 1 on subsequent calls
@ -137,7 +137,7 @@ d.extra(obj) extract bond/tri/line info from obj
if extra() used to define lines, else NULL if extra() used to define lines, else NULL
atype is column name viz() will return as atom type (def = "type") atype is column name viz() will return as atom type (def = "type")
extra() extracts bonds/tris/lines from obj each time viz() is called extra() extracts bonds/tris/lines from obj each time viz() is called
obj can be data object for bonds, cdata object for tris and lines, obj can be data object for bonds, cdata object for tris and lines,
bdump object for bonds, tdump object for tris, ldump object for lines. bdump object for bonds, tdump object for tris, ldump object for lines.
mdump object for tris mdump object for tris
""" """
@ -227,7 +227,7 @@ class dump:
for word in words: self.flist += glob.glob(word) for word in words: self.flist += glob.glob(word)
if len(self.flist) == 0 and len(list) == 1: if len(self.flist) == 0 and len(list) == 1:
raise StandardError,"no dump file specified" raise StandardError,"no dump file specified"
if len(list) == 1: if len(list) == 1:
self.increment = 0 self.increment = 0
self.read_all() self.read_all()
@ -270,7 +270,7 @@ class dump:
self.tselect.all() self.tselect.all()
# print column assignments # print column assignments
if len(self.names): if len(self.names):
print "assigned columns:",self.names2str() print "assigned columns:",self.names2str()
else: else:
@ -304,15 +304,15 @@ class dump:
snap = self.read_snapshot(f) snap = self.read_snapshot(f)
if not snap: if not snap:
self.nextfile += 1 self.nextfile += 1
if self.nextfile == len(self.flist): return -1 if self.nextfile == len(self.flist): return -1
f.close() f.close()
self.eof = 0 self.eof = 0
continue continue
self.eof = f.tell() self.eof = f.tell()
f.close() f.close()
try: try:
self.findtime(snap.time) self.findtime(snap.time)
continue continue
except: break except: break
# select the new snapshot with all its atoms # select the new snapshot with all its atoms
@ -334,7 +334,7 @@ class dump:
# assign column names (file must be self-describing) # assign column names (file must be self-describing)
# set scale_original to 0/1/-1 for unscaled/scaled/unknown # set scale_original to 0/1/-1 for unscaled/scaled/unknown
# convert xs,xu to x in names # convert xs,xu to x in names
def read_snapshot(self,f): def read_snapshot(self,f):
try: try:
snap = Snap() snap = Snap()
@ -351,7 +351,7 @@ class dump:
else: snap.boxstr = words[1].strip() else: snap.boxstr = words[1].strip()
if "xy" in snap.boxstr: snap.triclinic = 1 if "xy" in snap.boxstr: snap.triclinic = 1
else: snap.triclinic = 0 else: snap.triclinic = 0
words = f.readline().split() words = f.readline().split()
if len(words) == 2: if len(words) == 2:
snap.xlo,snap.xhi,snap.xy = float(words[0]),float(words[1]),0.0 snap.xlo,snap.xhi,snap.xy = float(words[0]),float(words[1]),0.0
@ -372,7 +372,7 @@ class dump:
else: else:
snap.zlo,snap.zhi,snap.yz = \ snap.zlo,snap.zhi,snap.yz = \
float(words[0]),float(words[1]),float(words[2]) float(words[0]),float(words[1]),float(words[2])
item = f.readline() item = f.readline()
if len(self.names) == 0: if len(self.names) == 0:
self.scale_original = -1 self.scale_original = -1
@ -401,7 +401,7 @@ class dump:
else: self.names[words[i]] = i else: self.names[words[i]] = i
if xflag == 0 and yflag == 0 and zflag == 0: self.scale_original = 0 if xflag == 0 and yflag == 0 and zflag == 0: self.scale_original = 0
if xflag == 1 and yflag == 1 and zflag == 1: self.scale_original = 1 if xflag == 1 and yflag == 1 and zflag == 1: self.scale_original = 1
if snap.natoms: if snap.natoms:
words = f.readline().split() words = f.readline().split()
ncol = len(words) ncol = len(words)
@ -424,7 +424,7 @@ class dump:
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# map atom column names # map atom column names
def map(self,*pairs): def map(self,*pairs):
if len(pairs) % 2 != 0: if len(pairs) % 2 != 0:
raise StandardError, "dump map() requires pairs of mappings" raise StandardError, "dump map() requires pairs of mappings"
@ -509,7 +509,7 @@ class dump:
atoms[:,y] = (atoms[:,y] - snap.ylo)*h1inv + \ atoms[:,y] = (atoms[:,y] - snap.ylo)*h1inv + \
(atoms[:,z] - snap.zlo)*h3inv (atoms[:,z] - snap.zlo)*h3inv
atoms[:,z] = (atoms[:,z] - snap.zlo)*h2inv atoms[:,z] = (atoms[:,z] - snap.zlo)*h2inv
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# unscale coords from 0-1 to box size for all snapshots or just one # unscale coords from 0-1 to box size for all snapshots or just one
# use 6 params as h-matrix to treat orthogonal or triclinic boxes # use 6 params as h-matrix to treat orthogonal or triclinic boxes
@ -564,7 +564,7 @@ class dump:
atoms[:,x] = snap.xlo + atoms[:,x]*h0 + atoms[:,y]*h5 + atoms[:,z]*h4 atoms[:,x] = snap.xlo + atoms[:,x]*h0 + atoms[:,y]*h5 + atoms[:,z]*h4
atoms[:,y] = snap.ylo + atoms[:,y]*h1 + atoms[:,z]*h3 atoms[:,y] = snap.ylo + atoms[:,y]*h1 + atoms[:,z]*h3
atoms[:,z] = snap.zlo + atoms[:,z]*h2 atoms[:,z] = snap.zlo + atoms[:,z]*h2
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# wrap coords from outside box to inside # wrap coords from outside box to inside
@ -577,7 +577,7 @@ class dump:
ix = self.names["ix"] ix = self.names["ix"]
iy = self.names["iy"] iy = self.names["iy"]
iz = self.names["iz"] iz = self.names["iz"]
for snap in self.snaps: for snap in self.snaps:
xprd = snap.xhi - snap.xlo xprd = snap.xhi - snap.xlo
yprd = snap.yhi - snap.ylo yprd = snap.yhi - snap.ylo
@ -599,7 +599,7 @@ class dump:
ix = self.names["ix"] ix = self.names["ix"]
iy = self.names["iy"] iy = self.names["iy"]
iz = self.names["iz"] iz = self.names["iz"]
for snap in self.snaps: for snap in self.snaps:
xprd = snap.xhi - snap.xlo xprd = snap.xhi - snap.xlo
yprd = snap.yhi - snap.ylo yprd = snap.yhi - snap.ylo
@ -612,10 +612,10 @@ class dump:
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# wrap coords to same image as atom ID stored in "other" column # wrap coords to same image as atom ID stored in "other" column
# if dynamic extra lines or triangles defined, owrap them as well # if dynamic extra lines or triangles defined, owrap them as well
def owrap(self,other): def owrap(self,other):
print "Wrapping to other ..." print "Wrapping to other ..."
id = self.names["id"] id = self.names["id"]
x = self.names["x"] x = self.names["x"]
y = self.names["y"] y = self.names["y"]
@ -641,10 +641,10 @@ class dump:
# should bonds also be owrapped ? # should bonds also be owrapped ?
if self.lineflag == 2 or self.triflag == 2: if self.lineflag == 2 or self.triflag == 2:
self.objextra.owrap(snap.time,xprd,yprd,zprd,ids,atoms,iother,ix,iy,iz) self.objextra.owrap(snap.time,xprd,yprd,zprd,ids,atoms,iother,ix,iy,iz)
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# convert column names assignment to a string, in column order # convert column names assignment to a string, in column order
def names2str(self): def names2str(self):
pairs = self.names.items() pairs = self.names.items()
values = self.names.values() values = self.names.values()
@ -697,7 +697,7 @@ class dump:
else: id = -1 else: id = -1
if "type" in self.names: type = self.names["type"] if "type" in self.names: type = self.names["type"]
else: type = -1 else: type = -1
for snap in self.snaps: for snap in self.snaps:
if not snap.tselect: continue if not snap.tselect: continue
print snap.time, print snap.time,
@ -719,7 +719,7 @@ class dump:
print >>f,snap.ylo,snap.yhi print >>f,snap.ylo,snap.yhi
print >>f,snap.zlo,snap.zhi print >>f,snap.zlo,snap.zhi
print >>f,"ITEM: ATOMS",namestr print >>f,"ITEM: ATOMS",namestr
atoms = snap.atoms atoms = snap.atoms
nvalues = len(atoms[0]) nvalues = len(atoms[0])
for i in xrange(snap.natoms): for i in xrange(snap.natoms):
@ -743,7 +743,7 @@ class dump:
if not snap.tselect: continue if not snap.tselect: continue
print snap.time, print snap.time,
sys.stdout.flush() sys.stdout.flush()
file = root + "." + str(snap.time) file = root + "." + str(snap.time)
f = open(file,"w") f = open(file,"w")
print >>f,"ITEM: TIMESTEP" print >>f,"ITEM: TIMESTEP"
@ -761,7 +761,7 @@ class dump:
print >>f,snap.ylo,snap.yhi print >>f,snap.ylo,snap.yhi
print >>f,snap.zlo,snap.zhi print >>f,snap.zlo,snap.zhi
print >>f,"ITEM: ATOMS",namestr print >>f,"ITEM: ATOMS",namestr
atoms = snap.atoms atoms = snap.atoms
nvalues = len(atoms[0]) nvalues = len(atoms[0])
for i in xrange(snap.natoms): for i in xrange(snap.natoms):
@ -803,7 +803,7 @@ class dump:
lhs = list[0][1:] lhs = list[0][1:]
if not self.names.has_key(lhs): if not self.names.has_key(lhs):
self.newcolumn(lhs) self.newcolumn(lhs)
for item in list: for item in list:
name = item[1:] name = item[1:]
column = self.names[name] column = self.names[name]
@ -815,7 +815,7 @@ class dump:
if not snap.tselect: continue if not snap.tselect: continue
for i in xrange(snap.natoms): for i in xrange(snap.natoms):
if snap.aselect[i]: exec ceq if snap.aselect[i]: exec ceq
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# set a column value via an input vec for all selected snapshots/atoms # set a column value via an input vec for all selected snapshots/atoms
@ -835,7 +835,7 @@ class dump:
if snap.aselect[i]: if snap.aselect[i]:
atoms[i][icol] = vec[m] atoms[i][icol] = vec[m]
m += 1 m += 1
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# clone value in col across selected timesteps for atoms with same ID # clone value in col across selected timesteps for atoms with same ID
@ -901,7 +901,7 @@ class dump:
columns.append(self.names[name]) columns.append(self.names[name])
values.append(self.nselect * [0]) values.append(self.nselect * [0])
ncol = len(columns) ncol = len(columns)
id = self.names["id"] id = self.names["id"]
m = 0 m = 0
for snap in self.snaps: for snap in self.snaps:
@ -917,13 +917,13 @@ class dump:
if len(list) == 1: return values[0] if len(list) == 1: return values[0]
else: return values else: return values
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# extract vector(s) of values for selected atoms at chosen timestep # extract vector(s) of values for selected atoms at chosen timestep
def vecs(self,n,*list): def vecs(self,n,*list):
snap = self.snaps[self.findtime(n)] snap = self.snaps[self.findtime(n)]
if len(list) == 0: if len(list) == 0:
raise StandardError, "no columns specified" raise StandardError, "no columns specified"
columns = [] columns = []
@ -978,7 +978,7 @@ class dump:
del self.snaps[i] del self.snaps[i]
else: else:
i += 1 i += 1
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# iterate over selected snapshots # iterate over selected snapshots
@ -990,12 +990,12 @@ class dump:
self.iterate = i self.iterate = i
return i,self.snaps[i].time,1 return i,self.snaps[i].time,1
return 0,0,-1 return 0,0,-1
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# return list of atoms to viz for snapshot isnap # return list of atoms to viz for snapshot isnap
# if called with flag, then index is timestep, so convert to snapshot index # if called with flag, then index is timestep, so convert to snapshot index
# augment with bonds, tris, lines if extra() was invoked # augment with bonds, tris, lines if extra() was invoked
def viz(self,index,flag=0): def viz(self,index,flag=0):
if not flag: isnap = index if not flag: isnap = index
else: else:
@ -1019,7 +1019,7 @@ class dump:
# create atom list needed by viz from id,type,x,y,z # create atom list needed by viz from id,type,x,y,z
# need Numeric/Numpy mode here # need Numeric/Numpy mode here
atoms = [] atoms = []
for i in xrange(snap.natoms): for i in xrange(snap.natoms):
if not snap.aselect[i]: continue if not snap.aselect[i]: continue
@ -1059,7 +1059,7 @@ class dump:
if self.triflag == 1: tris = self.trilist if self.triflag == 1: tris = self.trilist
elif self.triflag == 2: elif self.triflag == 2:
tmp1,tmp2,tmp3,tmp4,tris,tmp5 = self.objextra.viz(time,1) tmp1,tmp2,tmp3,tmp4,tris,tmp5 = self.objextra.viz(time,1)
# create list of lines from static or dynamic tri list # create list of lines from static or dynamic tri list
# if dynamic, could eliminate lines for unselected atoms # if dynamic, could eliminate lines for unselected atoms
@ -1070,7 +1070,7 @@ class dump:
tmp1,tmp2,tmp3,tmp4,tmp5,lines = self.objextra.viz(time,1) tmp1,tmp2,tmp3,tmp4,tmp5,lines = self.objextra.viz(time,1)
return time,box,atoms,bonds,tris,lines return time,box,atoms,bonds,tris,lines
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def findtime(self,n): def findtime(self,n):
@ -1115,7 +1115,7 @@ class dump:
def extra(self,arg): def extra(self,arg):
# data object, grab bonds statically # data object, grab bonds statically
if type(arg) is types.InstanceType and ".data" in str(arg.__class__): if type(arg) is types.InstanceType and ".data" in str(arg.__class__):
self.bondflag = 0 self.bondflag = 0
try: try:
@ -1132,7 +1132,7 @@ class dump:
raise StandardError,"could not extract bonds from data object" raise StandardError,"could not extract bonds from data object"
# cdata object, grab tris and lines statically # cdata object, grab tris and lines statically
elif type(arg) is types.InstanceType and ".cdata" in str(arg.__class__): elif type(arg) is types.InstanceType and ".cdata" in str(arg.__class__):
self.triflag = self.lineflag = 0 self.triflag = self.lineflag = 0
try: try:
@ -1147,32 +1147,32 @@ class dump:
raise StandardError,"could not extract tris/lines from cdata object" raise StandardError,"could not extract tris/lines from cdata object"
# mdump object, grab tris dynamically # mdump object, grab tris dynamically
elif type(arg) is types.InstanceType and ".mdump" in str(arg.__class__): elif type(arg) is types.InstanceType and ".mdump" in str(arg.__class__):
self.triflag = 2 self.triflag = 2
self.objextra = arg self.objextra = arg
# bdump object, grab bonds dynamically # bdump object, grab bonds dynamically
elif type(arg) is types.InstanceType and ".bdump" in str(arg.__class__): elif type(arg) is types.InstanceType and ".bdump" in str(arg.__class__):
self.bondflag = 2 self.bondflag = 2
self.objextra = arg self.objextra = arg
# ldump object, grab lines dynamically # ldump object, grab lines dynamically
elif type(arg) is types.InstanceType and ".ldump" in str(arg.__class__): elif type(arg) is types.InstanceType and ".ldump" in str(arg.__class__):
self.lineflag = 2 self.lineflag = 2
self.objextra = arg self.objextra = arg
# tdump object, grab tris dynamically # tdump object, grab tris dynamically
elif type(arg) is types.InstanceType and ".tdump" in str(arg.__class__): elif type(arg) is types.InstanceType and ".tdump" in str(arg.__class__):
self.triflag = 2 self.triflag = 2
self.objextra = arg self.objextra = arg
else: else:
raise StandardError,"unrecognized argument to dump.extra()" raise StandardError,"unrecognized argument to dump.extra()"
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def compare_atom(self,a,b): def compare_atom(self,a,b):
@ -1181,7 +1181,7 @@ class dump:
elif a[0] > b[0]: elif a[0] > b[0]:
return 1 return 1
else: else:
return 0 return 0
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# one snapshot # one snapshot
@ -1196,7 +1196,7 @@ class tselect:
def __init__(self,data): def __init__(self,data):
self.data = data self.data = data
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def all(self): def all(self):
@ -1243,7 +1243,7 @@ class tselect:
data.nselect -= 1 data.nselect -= 1
data.aselect.all() data.aselect.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): def test(self,teststr):
@ -1289,7 +1289,7 @@ class aselect:
data = self.data data = self.data
# replace all $var with snap.atoms references and compile test string # replace all $var with snap.atoms references and compile test string
pattern = "\$\w*" pattern = "\$\w*"
list = re.findall(pattern,teststr) list = re.findall(pattern,teststr)
for item in list: for item in list:

View File

@ -3,7 +3,7 @@
# #
# Copyright (2005) Sandia Corporation. Under the terms of Contract # Copyright (2005) Sandia Corporation. Under the terms of Contract
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains # 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. # the GNU General Public License.
# gnu tool # gnu tool
@ -11,12 +11,12 @@
oneline = "Create plots via GnuPlot plotting program" oneline = "Create plots via GnuPlot plotting program"
docstr = """ docstr = """
g = gnu() start up GnuPlot g = gnu() start up GnuPlot
g.stop() shut down GnuPlot process g.stop() shut down GnuPlot process
g.plot(a) plot vector A against linear index g.plot(a) plot vector A against linear index
g.plot(a,b) plot B against A 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,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 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 each plot argument can be a tuple, list, or Numeric/NumPy vector
@ -29,21 +29,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("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> 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 g.export("data",range(100),a,...) create file with columns of numbers
all vectors must be of equal length all vectors must be of equal length
could plot from file with GnuPlot command: plot 'data' using 1:2 with lines 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 subsequent commands apply to this plot
g.hide(N) delete window for figure N g.hide(N) delete window for figure N
g.save("file") save current plot as file.eps g.save("file") save current plot as file.eps
Set attributes for current plot: Set attributes for current plot:
@ -94,7 +94,7 @@ except: PIZZA_GNUTERM = "x11"
# Class definition # Class definition
class gnu: class gnu:
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def __init__(self): def __init__(self):
@ -102,7 +102,7 @@ class gnu:
self.file = "tmp.gnu" self.file = "tmp.gnu"
self.figures = [] self.figures = []
self.select(1) self.select(1)
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def stop(self): def stop(self):
@ -114,7 +114,7 @@ class gnu:
def __call__(self,command): def __call__(self,command):
self.GNUPLOT.write(command + '\n') self.GNUPLOT.write(command + '\n')
self.GNUPLOT.flush() self.GNUPLOT.flush()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def enter(self): def enter(self):
@ -152,7 +152,7 @@ class gnu:
if i: partial_vecs.append(vec[:i]) if i: partial_vecs.append(vec[:i])
else: partial_vecs.append([0]) else: partial_vecs.append([0])
self.plot(*partial_vecs) self.plot(*partial_vecs)
if n < 10: newfile = file + "000" + str(n) if n < 10: newfile = file + "000" + str(n)
elif n < 100: newfile = file + "00" + str(n) elif n < 100: newfile = file + "00" + str(n)
elif n < 1000: newfile = file + "0" + str(n) elif n < 1000: newfile = file + "0" + str(n)
@ -160,7 +160,7 @@ class gnu:
self.save(newfile) self.save(newfile)
n += 1 n += 1
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# write list of equal-length vectors to filename # write list of equal-length vectors to filename
@ -201,7 +201,7 @@ class gnu:
# do not continue until plot file is written out # do not continue until plot file is written out
# else script could go forward and change data file # else script could go forward and change data file
# use tmp.done as semaphore to indicate plot is finished # use tmp.done as semaphore to indicate plot is finished
def save(self,file): def save(self,file):
self.__call__("set terminal postscript enhanced solid lw 2 color portrait") self.__call__("set terminal postscript enhanced solid lw 2 color portrait")
cmd = "set output '%s.eps'" % file cmd = "set output '%s.eps'" % file
@ -212,7 +212,7 @@ class gnu:
while not os.path.exists("tmp.done"): continue while not os.path.exists("tmp.done"): continue
self.__call__("set output") self.__call__("set output")
self.select(self.current) self.select(self.current)
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# restore default attributes by creating a new fig object # restore default attributes by creating a new fig object
@ -221,7 +221,7 @@ class gnu:
fig.ncurves = self.figures[self.current-1].ncurves fig.ncurves = self.figures[self.current-1].ncurves
self.figures[self.current-1] = fig self.figures[self.current-1] = fig
self.draw() self.draw()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def aspect(self,value): def aspect(self,value):
@ -245,12 +245,12 @@ class gnu:
else: else:
self.figures[self.current-1].ylimit = (values[0],values[1]) self.figures[self.current-1].ylimit = (values[0],values[1])
self.draw() self.draw()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def label(self,x,y,text): def label(self,x,y,text):
self.figures[self.current-1].labels.append((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() self.draw()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -259,7 +259,7 @@ class gnu:
self.figures[self.current-1].nlabel = 0 self.figures[self.current-1].nlabel = 0
self.figures[self.current-1].labels = [] self.figures[self.current-1].labels = []
self.draw() self.draw()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def title(self,*strings): def title(self,*strings):
@ -276,13 +276,13 @@ class gnu:
def xtitle(self,label): def xtitle(self,label):
self.figures[self.current-1].xtitle = label self.figures[self.current-1].xtitle = label
self.draw() self.draw()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def ytitle(self,label): def ytitle(self,label):
self.figures[self.current-1].ytitle = label self.figures[self.current-1].ytitle = label
self.draw() self.draw()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def xlog(self): def xlog(self):
@ -291,7 +291,7 @@ class gnu:
else: else:
self.figures[self.current-1].xlog = 1 self.figures[self.current-1].xlog = 1
self.draw() self.draw()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def ylog(self): def ylog(self):
@ -300,7 +300,7 @@ class gnu:
else: else:
self.figures[self.current-1].ylog = 1 self.figures[self.current-1].ylog = 1
self.draw() self.draw()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def curve(self,num,color): def curve(self,num,color):
@ -316,10 +316,10 @@ class gnu:
def draw(self): def draw(self):
fig = self.figures[self.current-1] fig = self.figures[self.current-1]
if not fig.ncurves: return if not fig.ncurves: return
cmd = 'set size ratio ' + str(1.0/float(fig.aspect)) cmd = 'set size ratio ' + str(1.0/float(fig.aspect))
self.__call__(cmd) self.__call__(cmd)
cmd = 'set title ' + '"' + fig.title + '"' cmd = 'set title ' + '"' + fig.title + '"'
self.__call__(cmd) self.__call__(cmd)
cmd = 'set xlabel ' + '"' + fig.xtitle + '"' cmd = 'set xlabel ' + '"' + fig.xtitle + '"'
@ -331,11 +331,11 @@ class gnu:
else: self.__call__("unset logscale x") else: self.__call__("unset logscale x")
if fig.ylog: self.__call__("set logscale y") if fig.ylog: self.__call__("set logscale y")
else: self.__call__("unset 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]) + ']' cmd = 'set xr [' + str(fig.xlimit[0]) + ':' + str(fig.xlimit[1]) + ']'
self.__call__(cmd) self.__call__(cmd)
else: self.__call__("set xr [*:*]") else: self.__call__("set xr [*:*]")
if fig.ylimit: if fig.ylimit:
cmd = 'set yr [' + str(fig.ylimit[0]) + ':' + str(fig.ylimit[1]) + ']' cmd = 'set yr [' + str(fig.ylimit[0]) + ':' + str(fig.ylimit[1]) + ']'
self.__call__(cmd) self.__call__(cmd)
else: self.__call__("set yr [*:*]") else: self.__call__("set yr [*:*]")
@ -365,7 +365,7 @@ class figure:
def __init__(self): def __init__(self):
self.ncurves = 0 self.ncurves = 0
self.colors = [] self.colors = []
self.title = "" self.title = ""
self.xtitle = "" self.xtitle = ""
self.ytitle = "" self.ytitle = ""

View File

@ -3,7 +3,7 @@
# #
# Copyright (2005) Sandia Corporation. Under the terms of Contract # Copyright (2005) Sandia Corporation. Under the terms of Contract
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains # 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. # the GNU General Public License.
# log tool # log tool
@ -28,7 +28,7 @@ nvec = l.nvec # of vectors of thermo info
nlen = l.nlen length of each vectors nlen = l.nlen length of each vectors
names = l.names list of vector names names = l.names list of vector names
t,pe,... = l.get("Time","KE",...) return one or more vectors of values 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 l.write("file.txt","Time","PE",...) write listed vectors to a file
get and write allow abbreviated (uniquely) vector names get and write allow abbreviated (uniquely) vector names
@ -89,7 +89,7 @@ class log:
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# read all thermo from all files # read all thermo from all files
def read_all(self): def read_all(self):
self.read_header(self.flist[0]) self.read_header(self.flist[0])
if self.nvec == 0: raise StandardError,"log file has no values" if self.nvec == 0: raise StandardError,"log file has no values"
@ -100,7 +100,7 @@ class log:
print print
# sort entries by timestep, cull duplicates # sort entries by timestep, cull duplicates
self.data.sort(self.compare) self.data.sort(self.compare)
self.cull() self.cull()
self.nlen = len(self.data) self.nlen = len(self.data)
@ -133,9 +133,9 @@ class log:
else: else:
count = 0 count = 0
for i in range(self.nvec): for i in range(self.nvec):
if self.names[i].find(key) == 0: if self.names[i].find(key) == 0:
count += 1 count += 1
index = i index = i
if count == 1: if count == 1:
map.append(index) map.append(index)
else: else:
@ -161,9 +161,9 @@ class log:
else: else:
count = 0 count = 0
for i in range(self.nvec): for i in range(self.nvec):
if self.names[i].find(key) == 0: if self.names[i].find(key) == 0:
count += 1 count += 1
index = i index = i
if count == 1: if count == 1:
map.append(index) map.append(index)
else: else:
@ -226,7 +226,7 @@ class log:
keywords.insert(0,"Step") keywords.insert(0,"Step")
i = 0 i = 0
for keyword in keywords: for keyword in keywords:
self.names.append(keyword) self.names.append(keyword)
self.ptr[keyword] = i self.ptr[keyword] = i
i += 1 i += 1
@ -236,7 +236,7 @@ class log:
line = txt[s1:s2] line = txt[s1:s2]
words = line.split() words = line.split()
for i in range(len(words)): for i in range(len(words)):
self.names.append(words[i]) self.names.append(words[i])
self.ptr[words[i]] = i self.ptr[words[i]] = i
self.nvec = len(self.names) self.nvec = len(self.names)
@ -275,43 +275,43 @@ class log:
if s1 >= 0 and s2 >= 0 and s1 < s2: # found s1,s2 with s1 before s2 if s1 >= 0 and s2 >= 0 and s1 < s2: # found s1,s2 with s1 before s2
if self.style == 2: 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 elif s1 >= 0 and s2 >= 0 and s2 < s1: # found s1,s2 with s2 before s1
s1 = 0 s1 = 0
elif s1 == -1 and s2 >= 0: # found s2, but no s1 elif s1 == -1 and s2 >= 0: # found s2, but no s1
last = 1 last = 1
s1 = 0 s1 = 0
elif s1 >= 0 and s2 == -1: # found s1, but no s2 elif s1 >= 0 and s2 == -1: # found s1, but no s2
last = 1 last = 1
if self.style == 1: if self.style == 1:
s2 = txt.rfind("\n--",s1) + 1 s2 = txt.rfind("\n--",s1) + 1
else: else:
s1 = txt.find("\n",s1) + 1 s1 = txt.find("\n",s1) + 1
s2 = txt.rfind("\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 elif s1 == -1 and s2 == -1: # found neither
# could be end-of-file section # 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 if txt.find("Loop time of",start) == start: # end of file, so exit
eof -= len(txt) - start # reset eof to "Loop" eof -= len(txt) - start # reset eof to "Loop"
break break
last = 1 # entire read is a chunk last = 1 # entire read is a chunk
s1 = 0 s1 = 0
if self.style == 1: if self.style == 1:
s2 = txt.rfind("\n--",s1) + 1 s2 = txt.rfind("\n--",s1) + 1
else: else:
s2 = txt.rfind("\n",s1) + 1 s2 = txt.rfind("\n",s1) + 1
eof -= len(txt) - s2 eof -= len(txt) - s2
if s1 == s2: break if s1 == s2: break
chunk = txt[s1:s2-1] chunk = txt[s1:s2-1]
start = s2 start = s2
# split chunk into entries # split chunk into entries
# parse each entry for numeric fields, append to data # parse each entry for numeric fields, append to data
if self.style == 1: if self.style == 1:
sections = chunk.split("\n--") sections = chunk.split("\n--")
pat1 = re.compile("Step\s*(\S*)\s") pat1 = re.compile("Step\s*(\S*)\s")

View File

@ -3,7 +3,7 @@
# #
# Copyright (2005) Sandia Corporation. Under the terms of Contract # Copyright (2005) Sandia Corporation. Under the terms of Contract
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains # 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. # the GNU General Public License.
# pdb tool # pdb tool
@ -22,7 +22,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, if only one 4-char file specified and it is not found,
it will be downloaded from http://www.rcsb.org as 3CRO.pdb it will be downloaded from http://www.rcsb.org as 3CRO.pdb
d arg is object with atom coordinates (dump, data) d arg is object with atom coordinates (dump, data)
p.one() write all output as one big PDB file to tmp.pdb p.one() write all output as one big PDB file to tmp.pdb
p.one("mine") write to mine.pdb p.one("mine") write to mine.pdb
p.many() write one PDB file per snapshot: tmp0000.pdb, ... p.many() write one PDB file per snapshot: tmp0000.pdb, ...
@ -36,7 +36,7 @@ p.single(N,"new") write as new.pdb
if one file in str arg and d: one new PDB file per snapshot if one file in str arg and d: one new PDB file per snapshot
using input PDB file as template using input PDB file as template
multiple input PDB files with a d is not allowed multiple input PDB files with a d is not allowed
index,time,flag = p.iterator(0) index,time,flag = p.iterator(0)
index,time,flag = p.iterator(1) index,time,flag = p.iterator(1)
@ -87,7 +87,7 @@ class pdbfile:
# flist = full list of all PDB input file names # flist = full list of all PDB input file names
# append .pdb if needed # append .pdb if needed
if filestr: if filestr:
list = filestr.split() list = filestr.split()
flist = [] flist = []
@ -107,7 +107,7 @@ class pdbfile:
raise StandardError, "no input PDB file(s)" raise StandardError, "no input PDB file(s)"
# grab PDB file from http://rcsb.org if not a local file # grab PDB file from http://rcsb.org if not a local file
if len(self.files) == 1 and len(self.files[0]) == 8: if len(self.files) == 1 and len(self.files[0]) == 8:
try: try:
open(self.files[0],'r').close() open(self.files[0],'r').close()
@ -117,7 +117,7 @@ class pdbfile:
urllib.urlretrieve(fetchstr,self.files[0]) urllib.urlretrieve(fetchstr,self.files[0])
if self.data and len(self.files): self.read_template(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 # write a single large PDB file for concatenating all input data or files
# if data exists: # if data exists:
@ -135,7 +135,7 @@ class pdbfile:
f = open(file,'w') f = open(file,'w')
# use template PDB file with each snapshot # use template PDB file with each snapshot
if self.data: if self.data:
n = flag = 0 n = flag = 0
while 1: while 1:
@ -153,7 +153,7 @@ class pdbfile:
print >>f,"END" print >>f,"END"
print file, print file,
sys.stdout.flush() sys.stdout.flush()
f.close() f.close()
print "\nwrote %d datasets to %s in PDB format" % (n,file) print "\nwrote %d datasets to %s in PDB format" % (n,file)
@ -189,7 +189,7 @@ class pdbfile:
f = open(file,'w') f = open(file,'w')
self.convert(f,which) self.convert(f,which)
f.close() f.close()
print time, print time,
sys.stdout.flush() sys.stdout.flush()
n += 1 n += 1
@ -206,13 +206,13 @@ class pdbfile:
else: else:
file = root + str(n) file = root + str(n)
file += ".pdb" file += ".pdb"
f = open(file,'w') f = open(file,'w')
f.write(open(infile,'r').read()) f.write(open(infile,'r').read())
f.close() f.close()
print file, print file,
sys.stdout.flush() sys.stdout.flush()
n += 1 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)
@ -239,7 +239,7 @@ class pdbfile:
self.convert(f,which) self.convert(f,which)
else: else:
f.write(open(self.files[time],'r').read()) f.write(open(self.files[time],'r').read())
f.close() f.close()
# -------------------------------------------------------------------- # --------------------------------------------------------------------
@ -258,8 +258,8 @@ class pdbfile:
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# read a PDB file and store ATOM lines # read a PDB file and store ATOM lines
def read_template(self,file): def read_template(self,file):
lines = open(file,'r').readlines() lines = open(file,'r').readlines()
self.atomlines = {} self.atomlines = {}
for line in lines: for line in lines:

View File

@ -3,7 +3,7 @@
# #
# Copyright (2005) Sandia Corporation. Under the terms of Contract # Copyright (2005) Sandia Corporation. Under the terms of Contract
# DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains # 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. # the GNU General Public License.
# xyz tool # xyz tool
@ -11,14 +11,14 @@
oneline = "Convert LAMMPS snapshots to XYZ format" oneline = "Convert LAMMPS snapshots to XYZ format"
docstr = """ 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() write all snapshots to tmp.xyz
x.one("new") write all snapshots to new.xyz x.one("new") write all snapshots to new.xyz
x.many() write snapshots to tmp0000.xyz, tmp0001.xyz, etc x.many() write snapshots to tmp0000.xyz, tmp0001.xyz, etc
x.many("new") write snapshots to new0000.xyz, new0001.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) write snapshot for timestep N to tmp.xyz
x.single(N,"file") write snapshot for timestep N to file.xyz x.single(N,"file") write snapshot for timestep N to file.xyz
""" """
# History # History
@ -41,7 +41,7 @@ class xyz:
def __init__(self,data): def __init__(self,data):
self.data = data self.data = data
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def one(self,*args): def one(self,*args):
@ -61,14 +61,14 @@ class xyz:
for atom in atoms: for atom in atoms:
itype = int(atom[1]) itype = int(atom[1])
print >>f,itype,atom[2],atom[3],atom[4] print >>f,itype,atom[2],atom[3],atom[4]
print time, print time,
sys.stdout.flush() sys.stdout.flush()
n += 1 n += 1
f.close() 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): def many(self,*args):
@ -80,7 +80,7 @@ class xyz:
which,time,flag = self.data.iterator(flag) which,time,flag = self.data.iterator(flag)
if flag == -1: break if flag == -1: break
time,box,atoms,bonds,tris,lines = self.data.viz(which) time,box,atoms,bonds,tris,lines = self.data.viz(which)
if n < 10: if n < 10:
file = root + "000" + str(n) file = root + "000" + str(n)
elif n < 100: elif n < 100:
@ -88,7 +88,7 @@ class xyz:
elif n < 1000: elif n < 1000:
file = root + "0" + str(n) file = root + "0" + str(n)
else: else:
file = root + str(n) file = root + str(n)
file += ".xyz" file += ".xyz"
f = open(file,"w") f = open(file,"w")
print >>f,len(atoms) print >>f,len(atoms)
@ -100,9 +100,9 @@ class xyz:
sys.stdout.flush() sys.stdout.flush()
f.close() f.close()
n += 1 n += 1
print "\nwrote %s snapshots in XYZ format" % n print "\nwrote %s snapshots in XYZ format" % n
# -------------------------------------------------------------------- # --------------------------------------------------------------------
def single(self,time,*args): def single(self,time,*args):