sync
This commit is contained in:
@ -16,15 +16,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
|
||||||
if atoms have 5 or 8 columns, assign id,type,x,y,z (ix,iy,iz)
|
if atoms have 5 or 8 columns, assign id,type,x,y,z (ix,iy,iz)
|
||||||
atoms will be unscaled if stored in files as scaled
|
atoms will be unscaled if stored in files as scaled
|
||||||
|
|
||||||
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
|
||||||
@ -36,20 +36,21 @@ d.map(1,"id",3,"x") assign names to atom 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.one(N1,N2,N3) select only timestep N1,N2,N3
|
||||||
d.tselect.skip(M) select every Mth step
|
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.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
|
||||||
|
|
||||||
@ -60,24 +61,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
|
||||||
headd = 0/1 for no/yes snapshot header, app = 0/1 for write vs append
|
headd = 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
|
||||||
@ -89,8 +90,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
|
||||||
@ -111,7 +112,7 @@ 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
|
||||||
|
|
||||||
@ -121,8 +122,8 @@ fx,fy,... = d.vecs(1000,"fx","fy",...) return vector(s) for timestep N
|
|||||||
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 = d.viz(index) return list of viz objects
|
time,box,atoms,bonds,tris = 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("dump.bond") read bond list from dump file
|
d.extra("dump.bond") read bond list from dump file
|
||||||
d.extra(data) extract bond/tri/line list from data
|
d.extra(data) extract bond/tri/line list from data
|
||||||
|
|
||||||
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
|
||||||
@ -299,9 +300,9 @@ class dump:
|
|||||||
|
|
||||||
# if snapshots are scaled, unscale them
|
# if snapshots are scaled, unscale them
|
||||||
|
|
||||||
if (not "x" in self.names) or \
|
if ("x" not in self.names) or \
|
||||||
(not "y" in self.names) or \
|
("y" not in self.names) or \
|
||||||
(not "z" in self.names):
|
("z" not in self.names):
|
||||||
print("no unscaling could be performed")
|
print("no unscaling could be performed")
|
||||||
elif self.nsnaps > 0:
|
elif self.nsnaps > 0:
|
||||||
if self.scaled(self.nsnaps-1): self.unscale()
|
if self.scaled(self.nsnaps-1): self.unscale()
|
||||||
@ -582,8 +583,8 @@ class dump:
|
|||||||
pairs = self.names.items()
|
pairs = self.names.items()
|
||||||
str = ""
|
str = ""
|
||||||
for i in range(ncol):
|
for i in range(ncol):
|
||||||
for p in pairs:
|
for k,v in pairs:
|
||||||
if p[1] == i: str += p[0] + ' '
|
if v == i: str += k + ' '
|
||||||
return str
|
return str
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
@ -723,7 +724,7 @@ class dump:
|
|||||||
column = self.names[name]
|
column = self.names[name]
|
||||||
insert = "snap.atoms[i][%d]" % (column)
|
insert = "snap.atoms[i][%d]" % (column)
|
||||||
eq = eq.replace(item,insert)
|
eq = eq.replace(item,insert)
|
||||||
ceq = compile(eq,'','single')
|
ceq = compile(eq,'<string>','single')
|
||||||
|
|
||||||
for snap in self.snaps:
|
for snap in self.snaps:
|
||||||
if not snap.tselect: continue
|
if not snap.tselect: continue
|
||||||
@ -1117,24 +1118,23 @@ class tselect:
|
|||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
def one(self,n):
|
def one(self,*steps):
|
||||||
data = self.data
|
data = self.data
|
||||||
|
data.nselect = 0
|
||||||
for snap in data.snaps:
|
for snap in data.snaps:
|
||||||
snap.tselect = 0
|
snap.tselect = 0
|
||||||
i = data.findtime(n)
|
|
||||||
data.snaps[i].tselect = 1
|
for n in steps:
|
||||||
data.nselect = 1
|
i = data.findtime(n)
|
||||||
data.aselect.all()
|
data.snaps[i].tselect = 1
|
||||||
|
data.nselect += 1
|
||||||
|
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 none(self):
|
def none(self):
|
||||||
data = self.data
|
self.one()
|
||||||
for snap in data.snaps:
|
|
||||||
snap.tselect = 0
|
|
||||||
data.nselect = 0
|
|
||||||
print("%d snapshots selected out of %d" % (data.nselect,data.nsnaps))
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
@ -1157,11 +1157,11 @@ class tselect:
|
|||||||
def test(self,teststr):
|
def test(self,teststr):
|
||||||
data = self.data
|
data = self.data
|
||||||
snaps = data.snaps
|
snaps = data.snaps
|
||||||
cmd = "flag = " + teststr.replace("$t","snaps[i].time")
|
cmd = teststr.replace("$t","snaps[i].time")
|
||||||
ccmd = compile(cmd,'','single')
|
ccmd = compile(cmd,'<string>','eval')
|
||||||
for i in range(data.nsnaps):
|
for i in range(data.nsnaps):
|
||||||
if not snaps[i].tselect: continue
|
if not snaps[i].tselect: continue
|
||||||
exec(ccmd)
|
flag = eval(ccmd)
|
||||||
if not flag:
|
if not flag:
|
||||||
snaps[i].tselect = 0
|
snaps[i].tselect = 0
|
||||||
data.nselect -= 1
|
data.nselect -= 1
|
||||||
@ -1199,21 +1199,20 @@ class aselect:
|
|||||||
# 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)
|
matches = re.findall(pattern,teststr)
|
||||||
for item in list:
|
for item in matches:
|
||||||
name = item[1:]
|
name = item[1:]
|
||||||
column = data.names[name]
|
column = data.names[name]
|
||||||
insert = "snap.atoms[i][%d]" % column
|
insert = "snap.atoms[i][%d]" % column
|
||||||
teststr = teststr.replace(item,insert)
|
teststr = teststr.replace(item,insert)
|
||||||
cmd = "flag = " + teststr
|
ccmd = compile(teststr,'<string>','eval')
|
||||||
ccmd = compile(cmd,'','single')
|
|
||||||
|
|
||||||
if len(args) == 0: # all selected timesteps
|
if len(args) == 0: # all selected timesteps
|
||||||
for snap in data.snaps:
|
for snap in data.snaps:
|
||||||
if not snap.tselect: continue
|
if not snap.tselect: continue
|
||||||
for i in range(snap.natoms):
|
for i in range(snap.natoms):
|
||||||
if not snap.aselect[i]: continue
|
if not snap.aselect[i]: continue
|
||||||
exec(ccmd)
|
flag = eval(ccmd)
|
||||||
if not flag:
|
if not flag:
|
||||||
snap.aselect[i] = 0
|
snap.aselect[i] = 0
|
||||||
snap.nselect -= 1
|
snap.nselect -= 1
|
||||||
|
|||||||
Reference in New Issue
Block a user