get rid of (evil) tabs and trailing whitespace in bundled Pizza.py components
This commit is contained in:
@ -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.
|
||||
|
||||
# dump tool
|
||||
@ -12,15 +12,15 @@ oneline = "Read, write, manipulate dump files and particle attributes"
|
||||
|
||||
docstr = """
|
||||
d = dump("dump.one") read in one or more dump files
|
||||
d = dump("dump.1 dump.2.gz") can be gzipped
|
||||
d = dump("dump.*") wildcard expands to multiple files
|
||||
d = dump("dump.*",0) two args = store filenames, but don't read
|
||||
d = dump("dump.1 dump.2.gz") can be gzipped
|
||||
d = dump("dump.*") wildcard expands to multiple files
|
||||
d = dump("dump.*",0) two args = store filenames, but don't read
|
||||
|
||||
incomplete and duplicate snapshots are deleted
|
||||
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
|
||||
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)
|
||||
|
||||
not needed if dump file is self-describing
|
||||
|
||||
d.tselect.all() select all timesteps
|
||||
d.tselect.one(N) select only timestep N
|
||||
d.tselect.none() deselect all timesteps
|
||||
d.tselect.skip(M) select every Mth step
|
||||
|
||||
d.tselect.all() select all timesteps
|
||||
d.tselect.one(N) select only timestep N
|
||||
d.tselect.none() deselect all timesteps
|
||||
d.tselect.skip(M) select every Mth step
|
||||
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
|
||||
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
|
||||
|
||||
d.aselect.all() select all atoms in all steps
|
||||
d.aselect.all(N) select all atoms in one step
|
||||
d.aselect.all() select all atoms in all steps
|
||||
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",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
|
||||
$name must end with a space
|
||||
|
||||
d.write("file") 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.write("file") 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
|
||||
|
||||
write() can be specified with 2 additional flags
|
||||
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
|
||||
|
||||
d.scale() scale x,y,z to 0-1 for all timesteps
|
||||
d.scale(100) scale atom coords for timestep N
|
||||
d.unscale() unscale x,y,z to box size to all timesteps
|
||||
d.unscale(1000) unscale atom coords for timestep N
|
||||
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.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("x") sort atoms by column value in all steps
|
||||
d.sort(1000) sort atoms in timestep N
|
||||
d.scale() scale x,y,z to 0-1 for all timesteps
|
||||
d.scale(100) scale atom coords for timestep N
|
||||
d.unscale() unscale x,y,z to box size to all timesteps
|
||||
d.unscale(1000) unscale atom coords for timestep N
|
||||
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.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("x") sort atoms by column value in all steps
|
||||
d.sort(1000) sort atoms in timestep N
|
||||
|
||||
scale(), unscale(), wrap(), unwrap(), owrap() operate on all steps and atoms
|
||||
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
|
||||
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.spread("ke",N,"color") 2nd col = N ints spread over 1st col
|
||||
d.clone(1000,"color") clone timestep N values to other steps
|
||||
d.spread("ke",N,"color") 2nd col = N ints spread over 1st col
|
||||
d.clone(1000,"color") clone timestep N values to other steps
|
||||
|
||||
minmax() 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
|
||||
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.vecs(1000,"fx","fy",...) return vector(s) for timestep N
|
||||
|
||||
atom() returns vectors with one value for each selected 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
|
||||
d.atype = "color" set column returned as "type" by viz
|
||||
d.extra(obj) extract bond/tri/line info from obj
|
||||
d.atype = "color" set column returned as "type" by viz
|
||||
d.extra(obj) extract bond/tri/line info from obj
|
||||
|
||||
iterator() loops over selected timesteps
|
||||
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
|
||||
atype is column name viz() will return as atom type (def = "type")
|
||||
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.
|
||||
mdump object for tris
|
||||
"""
|
||||
@ -227,7 +227,7 @@ class dump:
|
||||
for word in words: self.flist += glob.glob(word)
|
||||
if len(self.flist) == 0 and len(list) == 1:
|
||||
raise StandardError,"no dump file specified"
|
||||
|
||||
|
||||
if len(list) == 1:
|
||||
self.increment = 0
|
||||
self.read_all()
|
||||
@ -270,7 +270,7 @@ class dump:
|
||||
self.tselect.all()
|
||||
|
||||
# print column assignments
|
||||
|
||||
|
||||
if len(self.names):
|
||||
print "assigned columns:",self.names2str()
|
||||
else:
|
||||
@ -304,15 +304,15 @@ class dump:
|
||||
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 atoms
|
||||
@ -334,7 +334,7 @@ class dump:
|
||||
# assign column names (file must be self-describing)
|
||||
# set scale_original to 0/1/-1 for unscaled/scaled/unknown
|
||||
# convert xs,xu to x in names
|
||||
|
||||
|
||||
def read_snapshot(self,f):
|
||||
try:
|
||||
snap = Snap()
|
||||
@ -351,7 +351,7 @@ class dump:
|
||||
else: snap.boxstr = words[1].strip()
|
||||
if "xy" in snap.boxstr: snap.triclinic = 1
|
||||
else: snap.triclinic = 0
|
||||
|
||||
|
||||
words = f.readline().split()
|
||||
if len(words) == 2:
|
||||
snap.xlo,snap.xhi,snap.xy = float(words[0]),float(words[1]),0.0
|
||||
@ -372,7 +372,7 @@ class dump:
|
||||
else:
|
||||
snap.zlo,snap.zhi,snap.yz = \
|
||||
float(words[0]),float(words[1]),float(words[2])
|
||||
|
||||
|
||||
item = f.readline()
|
||||
if len(self.names) == 0:
|
||||
self.scale_original = -1
|
||||
@ -401,7 +401,7 @@ class dump:
|
||||
else: self.names[words[i]] = i
|
||||
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 snap.natoms:
|
||||
words = f.readline().split()
|
||||
ncol = len(words)
|
||||
@ -424,7 +424,7 @@ class dump:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# map atom column names
|
||||
|
||||
|
||||
def map(self,*pairs):
|
||||
if len(pairs) % 2 != 0:
|
||||
raise StandardError, "dump map() requires pairs of mappings"
|
||||
@ -509,7 +509,7 @@ class dump:
|
||||
atoms[:,y] = (atoms[:,y] - snap.ylo)*h1inv + \
|
||||
(atoms[:,z] - snap.zlo)*h3inv
|
||||
atoms[:,z] = (atoms[:,z] - snap.zlo)*h2inv
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# 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
|
||||
@ -564,7 +564,7 @@ class dump:
|
||||
atoms[:,x] = snap.xlo + atoms[:,x]*h0 + atoms[:,y]*h5 + atoms[:,z]*h4
|
||||
atoms[:,y] = snap.ylo + atoms[:,y]*h1 + atoms[:,z]*h3
|
||||
atoms[:,z] = snap.zlo + atoms[:,z]*h2
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# wrap coords from outside box to inside
|
||||
|
||||
@ -577,7 +577,7 @@ class dump:
|
||||
ix = self.names["ix"]
|
||||
iy = self.names["iy"]
|
||||
iz = self.names["iz"]
|
||||
|
||||
|
||||
for snap in self.snaps:
|
||||
xprd = snap.xhi - snap.xlo
|
||||
yprd = snap.yhi - snap.ylo
|
||||
@ -599,7 +599,7 @@ class dump:
|
||||
ix = self.names["ix"]
|
||||
iy = self.names["iy"]
|
||||
iz = self.names["iz"]
|
||||
|
||||
|
||||
for snap in self.snaps:
|
||||
xprd = snap.xhi - snap.xlo
|
||||
yprd = snap.yhi - snap.ylo
|
||||
@ -612,10 +612,10 @@ class dump:
|
||||
# --------------------------------------------------------------------
|
||||
# wrap coords to same image as atom ID stored in "other" column
|
||||
# if dynamic extra lines or triangles defined, owrap them as well
|
||||
|
||||
|
||||
def owrap(self,other):
|
||||
print "Wrapping to other ..."
|
||||
|
||||
|
||||
id = self.names["id"]
|
||||
x = self.names["x"]
|
||||
y = self.names["y"]
|
||||
@ -641,10 +641,10 @@ class dump:
|
||||
# should bonds also be owrapped ?
|
||||
if self.lineflag == 2 or self.triflag == 2:
|
||||
self.objextra.owrap(snap.time,xprd,yprd,zprd,ids,atoms,iother,ix,iy,iz)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# convert column names assignment to a string, in column order
|
||||
|
||||
|
||||
def names2str(self):
|
||||
pairs = self.names.items()
|
||||
values = self.names.values()
|
||||
@ -697,7 +697,7 @@ class dump:
|
||||
else: id = -1
|
||||
if "type" in self.names: type = self.names["type"]
|
||||
else: type = -1
|
||||
|
||||
|
||||
for snap in self.snaps:
|
||||
if not snap.tselect: continue
|
||||
print snap.time,
|
||||
@ -719,7 +719,7 @@ class dump:
|
||||
print >>f,snap.ylo,snap.yhi
|
||||
print >>f,snap.zlo,snap.zhi
|
||||
print >>f,"ITEM: ATOMS",namestr
|
||||
|
||||
|
||||
atoms = snap.atoms
|
||||
nvalues = len(atoms[0])
|
||||
for i in xrange(snap.natoms):
|
||||
@ -743,7 +743,7 @@ class dump:
|
||||
if not snap.tselect: continue
|
||||
print snap.time,
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
file = root + "." + str(snap.time)
|
||||
f = open(file,"w")
|
||||
print >>f,"ITEM: TIMESTEP"
|
||||
@ -761,7 +761,7 @@ class dump:
|
||||
print >>f,snap.ylo,snap.yhi
|
||||
print >>f,snap.zlo,snap.zhi
|
||||
print >>f,"ITEM: ATOMS",namestr
|
||||
|
||||
|
||||
atoms = snap.atoms
|
||||
nvalues = len(atoms[0])
|
||||
for i in xrange(snap.natoms):
|
||||
@ -803,7 +803,7 @@ class dump:
|
||||
lhs = list[0][1:]
|
||||
if not self.names.has_key(lhs):
|
||||
self.newcolumn(lhs)
|
||||
|
||||
|
||||
for item in list:
|
||||
name = item[1:]
|
||||
column = self.names[name]
|
||||
@ -815,7 +815,7 @@ class dump:
|
||||
if not snap.tselect: continue
|
||||
for i in xrange(snap.natoms):
|
||||
if snap.aselect[i]: exec ceq
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# set a column value via an input vec for all selected snapshots/atoms
|
||||
|
||||
@ -835,7 +835,7 @@ class dump:
|
||||
if snap.aselect[i]:
|
||||
atoms[i][icol] = vec[m]
|
||||
m += 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# clone value in col across selected timesteps for atoms with same ID
|
||||
|
||||
@ -901,7 +901,7 @@ class dump:
|
||||
columns.append(self.names[name])
|
||||
values.append(self.nselect * [0])
|
||||
ncol = len(columns)
|
||||
|
||||
|
||||
id = self.names["id"]
|
||||
m = 0
|
||||
for snap in self.snaps:
|
||||
@ -917,13 +917,13 @@ class dump:
|
||||
|
||||
if len(list) == 1: return values[0]
|
||||
else: return values
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# extract vector(s) of values for selected atoms at chosen timestep
|
||||
|
||||
def vecs(self,n,*list):
|
||||
snap = self.snaps[self.findtime(n)]
|
||||
|
||||
|
||||
if len(list) == 0:
|
||||
raise StandardError, "no columns specified"
|
||||
columns = []
|
||||
@ -978,7 +978,7 @@ class dump:
|
||||
del self.snaps[i]
|
||||
else:
|
||||
i += 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# iterate over selected snapshots
|
||||
|
||||
@ -990,12 +990,12 @@ class dump:
|
||||
self.iterate = i
|
||||
return i,self.snaps[i].time,1
|
||||
return 0,0,-1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# return list of atoms to viz for snapshot isnap
|
||||
# if called with flag, then index is timestep, so convert to snapshot index
|
||||
# augment with bonds, tris, lines if extra() was invoked
|
||||
|
||||
|
||||
def viz(self,index,flag=0):
|
||||
if not flag: isnap = index
|
||||
else:
|
||||
@ -1019,7 +1019,7 @@ class dump:
|
||||
|
||||
# create atom list needed by viz from id,type,x,y,z
|
||||
# need Numeric/Numpy mode here
|
||||
|
||||
|
||||
atoms = []
|
||||
for i in xrange(snap.natoms):
|
||||
if not snap.aselect[i]: continue
|
||||
@ -1059,7 +1059,7 @@ class dump:
|
||||
if self.triflag == 1: tris = self.trilist
|
||||
elif self.triflag == 2:
|
||||
tmp1,tmp2,tmp3,tmp4,tris,tmp5 = self.objextra.viz(time,1)
|
||||
|
||||
|
||||
# create list of lines from static or dynamic tri list
|
||||
# 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)
|
||||
|
||||
return time,box,atoms,bonds,tris,lines
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def findtime(self,n):
|
||||
@ -1115,7 +1115,7 @@ class dump:
|
||||
def extra(self,arg):
|
||||
|
||||
# data object, grab bonds statically
|
||||
|
||||
|
||||
if type(arg) is types.InstanceType and ".data" in str(arg.__class__):
|
||||
self.bondflag = 0
|
||||
try:
|
||||
@ -1132,7 +1132,7 @@ class dump:
|
||||
raise StandardError,"could not extract bonds from data object"
|
||||
|
||||
# cdata object, grab tris and lines statically
|
||||
|
||||
|
||||
elif type(arg) is types.InstanceType and ".cdata" in str(arg.__class__):
|
||||
self.triflag = self.lineflag = 0
|
||||
try:
|
||||
@ -1147,32 +1147,32 @@ class dump:
|
||||
raise StandardError,"could not extract tris/lines from cdata object"
|
||||
|
||||
# mdump object, grab tris dynamically
|
||||
|
||||
|
||||
elif type(arg) is types.InstanceType and ".mdump" in str(arg.__class__):
|
||||
self.triflag = 2
|
||||
self.objextra = arg
|
||||
|
||||
# bdump object, grab bonds dynamically
|
||||
|
||||
|
||||
elif type(arg) is types.InstanceType and ".bdump" in str(arg.__class__):
|
||||
self.bondflag = 2
|
||||
self.objextra = arg
|
||||
|
||||
# ldump object, grab lines dynamically
|
||||
|
||||
|
||||
elif type(arg) is types.InstanceType and ".ldump" in str(arg.__class__):
|
||||
self.lineflag = 2
|
||||
self.objextra = arg
|
||||
|
||||
# tdump object, grab tris dynamically
|
||||
|
||||
|
||||
elif type(arg) is types.InstanceType and ".tdump" in str(arg.__class__):
|
||||
self.triflag = 2
|
||||
self.objextra = arg
|
||||
|
||||
else:
|
||||
raise StandardError,"unrecognized argument to dump.extra()"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def compare_atom(self,a,b):
|
||||
@ -1181,7 +1181,7 @@ class dump:
|
||||
elif a[0] > b[0]:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
return 0
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# one snapshot
|
||||
@ -1196,7 +1196,7 @@ class tselect:
|
||||
|
||||
def __init__(self,data):
|
||||
self.data = data
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def all(self):
|
||||
@ -1243,7 +1243,7 @@ class tselect:
|
||||
data.nselect -= 1
|
||||
data.aselect.all()
|
||||
print "%d snapshots selected out of %d" % (data.nselect,data.nsnaps)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def test(self,teststr):
|
||||
@ -1289,7 +1289,7 @@ class aselect:
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user