Sync copies of pizza
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.
|
||||
|
||||
# for python3 compatibility
|
||||
@ -35,7 +35,7 @@ time = d.next() read next snapshot from dump files
|
||||
d.map(1,"id",3,"x") assign names to atom 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
|
||||
@ -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 Exception("no dump file specified")
|
||||
|
||||
|
||||
if len(list) == 1:
|
||||
self.increment = 0
|
||||
self.read_all()
|
||||
@ -270,7 +270,7 @@ class dump:
|
||||
self.tselect.all()
|
||||
|
||||
# set default names for atom columns if file wasn't self-describing
|
||||
|
||||
|
||||
if len(self.snaps) == 0:
|
||||
print("no column assignments made")
|
||||
elif len(self.names):
|
||||
@ -341,7 +341,7 @@ class dump:
|
||||
# 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()
|
||||
@ -414,7 +414,7 @@ class dump:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# map atom column names
|
||||
|
||||
|
||||
def map(self,*pairs):
|
||||
if len(pairs) % 2 != 0:
|
||||
raise Exception("dump map() requires pairs of mappings")
|
||||
@ -492,7 +492,7 @@ class dump:
|
||||
atoms[:,x] = snap.xlo + atoms[:,x]*xprd
|
||||
atoms[:,y] = snap.ylo + atoms[:,y]*yprd
|
||||
atoms[:,z] = snap.zlo + atoms[:,z]*zprd
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# wrap coords from outside box to inside
|
||||
|
||||
@ -505,7 +505,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
|
||||
@ -527,7 +527,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
|
||||
@ -542,7 +542,7 @@ class dump:
|
||||
|
||||
def owrap(self,other):
|
||||
print("Wrapping to other ...")
|
||||
|
||||
|
||||
id = self.names["id"]
|
||||
x = self.names["x"]
|
||||
y = self.names["y"]
|
||||
@ -551,7 +551,7 @@ class dump:
|
||||
iy = self.names["iy"]
|
||||
iz = self.names["iz"]
|
||||
iother = self.names[other]
|
||||
|
||||
|
||||
for snap in self.snaps:
|
||||
xprd = snap.xhi - snap.xlo
|
||||
yprd = snap.yhi - snap.ylo
|
||||
@ -568,7 +568,7 @@ class dump:
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# convert column names assignment to a string, in column order
|
||||
|
||||
|
||||
def names2str(self):
|
||||
ncol = len(self.snaps[0].atoms[0])
|
||||
pairs = self.names.items()
|
||||
@ -631,7 +631,7 @@ class dump:
|
||||
print(snap.ylo,snap.yhi,file=f)
|
||||
print(snap.zlo,snap.zhi,file=f)
|
||||
print("ITEM: ATOMS",namestr,file=f)
|
||||
|
||||
|
||||
atoms = snap.atoms
|
||||
nvalues = len(atoms[0])
|
||||
for i in range(snap.natoms):
|
||||
@ -655,7 +655,7 @@ class dump:
|
||||
if not snap.tselect: continue
|
||||
print(snap.time,end='')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
file = root + "." + str(snap.time)
|
||||
f = open(file,"w")
|
||||
print("ITEM: TIMESTEP",file=f)
|
||||
@ -667,7 +667,7 @@ class dump:
|
||||
print(snap.ylo,snap.yhi,file=f)
|
||||
print(snap.zlo,snap.zhi,file=f)
|
||||
print("ITEM: ATOMS",namestr,file=f)
|
||||
|
||||
|
||||
atoms = snap.atoms
|
||||
nvalues = len(atoms[0])
|
||||
for i in range(snap.natoms):
|
||||
@ -709,7 +709,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]
|
||||
@ -721,7 +721,7 @@ class dump:
|
||||
if not snap.tselect: continue
|
||||
for i in range(snap.natoms):
|
||||
if snap.aselect[i]: exec(ceq)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# set a column value via an input vec for all selected snapshots/atoms
|
||||
|
||||
@ -741,7 +741,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
|
||||
|
||||
@ -807,7 +807,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:
|
||||
@ -823,13 +823,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 Exception("no columns specified")
|
||||
columns = []
|
||||
@ -884,7 +884,7 @@ class dump:
|
||||
del self.snaps[i]
|
||||
else:
|
||||
i += 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# iterate over selected snapshots
|
||||
|
||||
@ -896,11 +896,11 @@ 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
|
||||
# augment with bonds, tris, lines if extra() was invoked
|
||||
|
||||
|
||||
def viz(self,isnap):
|
||||
snap = self.snaps[isnap]
|
||||
|
||||
@ -914,7 +914,7 @@ class dump:
|
||||
|
||||
# create atom list needed by viz from id,type,x,y,z
|
||||
# need Numeric/Numpy mode here
|
||||
|
||||
|
||||
atoms = []
|
||||
for i in range(snap.natoms):
|
||||
if not snap.aselect[i]: continue
|
||||
@ -948,12 +948,12 @@ class dump:
|
||||
elif self.triflag == 2:
|
||||
timetmp,boxtmp,atomstmp,bondstmp, \
|
||||
tris,linestmp = self.triobj.viz(time,1)
|
||||
|
||||
|
||||
lines = []
|
||||
if self.lineflag: lines = self.linelist
|
||||
|
||||
return time,box,atoms,bonds,tris,lines
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def findtime(self,n):
|
||||
@ -997,7 +997,7 @@ class dump:
|
||||
def extra(self,arg):
|
||||
|
||||
# read bonds from bond dump file
|
||||
|
||||
|
||||
if type(arg) is types.StringType:
|
||||
try:
|
||||
f = open(arg,'r')
|
||||
@ -1017,7 +1017,7 @@ class dump:
|
||||
f.close()
|
||||
|
||||
# convert values to int and absolute value since can be negative types
|
||||
|
||||
|
||||
if oldnumeric: bondlist = np.zeros((nbonds,4),np.Int)
|
||||
else: bondlist = np.zeros((nbonds,4),np.int)
|
||||
ints = [abs(int(value)) for value in words]
|
||||
@ -1032,9 +1032,9 @@ class dump:
|
||||
self.bondlist = bondlist
|
||||
except:
|
||||
raise Exception("could not read from bond dump file")
|
||||
|
||||
|
||||
# request bonds from data object
|
||||
|
||||
|
||||
elif type(arg) is types.InstanceType and ".data" in str(arg.__class__):
|
||||
try:
|
||||
bondlist = []
|
||||
@ -1050,7 +1050,7 @@ class dump:
|
||||
raise Exception("could not extract bonds from data object")
|
||||
|
||||
# request tris/lines from cdata object
|
||||
|
||||
|
||||
elif type(arg) is types.InstanceType and ".cdata" in str(arg.__class__):
|
||||
try:
|
||||
tmp,tmp,tmp,tmp,tris,lines = arg.viz(0)
|
||||
@ -1064,7 +1064,7 @@ class dump:
|
||||
raise Exception("could not extract tris/lines from cdata object")
|
||||
|
||||
# request tris from mdump object
|
||||
|
||||
|
||||
elif type(arg) is types.InstanceType and ".mdump" in str(arg.__class__):
|
||||
try:
|
||||
self.triflag = 2
|
||||
@ -1074,7 +1074,7 @@ class dump:
|
||||
|
||||
else:
|
||||
raise Exception("unrecognized argument to dump.extra()")
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def compare_atom(self,a,b):
|
||||
@ -1083,7 +1083,7 @@ class dump:
|
||||
elif a[0] > b[0]:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
return 0
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# one snapshot
|
||||
@ -1098,7 +1098,7 @@ class tselect:
|
||||
|
||||
def __init__(self,data):
|
||||
self.data = data
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def all(self):
|
||||
@ -1145,7 +1145,7 @@ class tselect:
|
||||
data.nselect -= 1
|
||||
data.aselect.all()
|
||||
print("%d snapshots selected out of %d" % (data.nselect,data.nsnaps))
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def test(self,teststr):
|
||||
@ -1191,7 +1191,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:
|
||||
|
||||
@ -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.
|
||||
|
||||
# for python3 compatibility
|
||||
@ -16,7 +16,7 @@ oneline = "Create plots via GnuPlot plotting program"
|
||||
docstr = """
|
||||
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
|
||||
@ -35,14 +35,14 @@ g("plot 'file.dat' using 2:3 with lines") execute string in GnuPlot
|
||||
g.enter() enter GnuPlot shell
|
||||
gnuplot> plot sin(x) with lines type commands directly to GnuPlot
|
||||
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
|
||||
|
||||
|
||||
subsequent commands apply to this plot
|
||||
|
||||
g.hide(N) delete window for figure N
|
||||
@ -98,7 +98,7 @@ except ImportError: PIZZA_GNUTERM = "x11"
|
||||
# Class definition
|
||||
|
||||
class gnu:
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def __init__(self):
|
||||
@ -106,7 +106,7 @@ class gnu:
|
||||
self.file = "tmp.gnu"
|
||||
self.figures = []
|
||||
self.select(1)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def stop(self):
|
||||
@ -118,7 +118,7 @@ class gnu:
|
||||
def __call__(self,command):
|
||||
self.GNUPLOT.write(command + '\n')
|
||||
self.GNUPLOT.flush()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def enter(self):
|
||||
@ -159,7 +159,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)
|
||||
@ -167,7 +167,7 @@ class gnu:
|
||||
|
||||
self.save(newfile)
|
||||
n += 1
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# write list of equal-length vectors to filename
|
||||
|
||||
@ -208,7 +208,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
|
||||
@ -219,7 +219,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
|
||||
|
||||
@ -228,7 +228,7 @@ class gnu:
|
||||
fig.ncurves = self.figures[self.current-1].ncurves
|
||||
self.figures[self.current-1] = fig
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def aspect(self,value):
|
||||
@ -252,12 +252,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()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -266,7 +266,7 @@ class gnu:
|
||||
self.figures[self.current-1].nlabel = 0
|
||||
self.figures[self.current-1].labels = []
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def title(self,*strings):
|
||||
@ -283,13 +283,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):
|
||||
@ -298,7 +298,7 @@ class gnu:
|
||||
else:
|
||||
self.figures[self.current-1].xlog = 1
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def ylog(self):
|
||||
@ -307,7 +307,7 @@ class gnu:
|
||||
else:
|
||||
self.figures[self.current-1].ylog = 1
|
||||
self.draw()
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
def curve(self,num,color):
|
||||
@ -323,10 +323,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 + '"'
|
||||
@ -338,11 +338,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 [*:*]")
|
||||
@ -372,7 +372,7 @@ class figure:
|
||||
|
||||
def __init__(self):
|
||||
self.ncurves = 0
|
||||
self.colors = []
|
||||
self.colors = []
|
||||
self.title = ""
|
||||
self.xtitle = ""
|
||||
self.ytitle = ""
|
||||
|
||||
@ -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.
|
||||
|
||||
# for python3 compatibility
|
||||
@ -25,7 +25,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, ...
|
||||
@ -39,7 +39,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)
|
||||
|
||||
@ -97,7 +97,7 @@ class pdbfile:
|
||||
|
||||
# flist = full list of all PDB input file names
|
||||
# append .pdb if needed
|
||||
|
||||
|
||||
if filestr:
|
||||
list = filestr.split()
|
||||
flist = []
|
||||
@ -117,7 +117,7 @@ class pdbfile:
|
||||
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()
|
||||
@ -127,7 +127,7 @@ class pdbfile:
|
||||
urllib.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:
|
||||
@ -145,7 +145,7 @@ class pdbfile:
|
||||
f = open(file,'w')
|
||||
|
||||
# use template PDB file with each snapshot
|
||||
|
||||
|
||||
if self.data:
|
||||
n = flag = 0
|
||||
while 1:
|
||||
@ -163,7 +163,7 @@ class pdbfile:
|
||||
print("END",file=f)
|
||||
print(file,end='')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
f.close()
|
||||
print("\nwrote %d datasets to %s in PDB format" % (n,file))
|
||||
|
||||
@ -199,7 +199,7 @@ class pdbfile:
|
||||
f = open(file,'w')
|
||||
self.convert(f,which)
|
||||
f.close()
|
||||
|
||||
|
||||
print(time,end='')
|
||||
sys.stdout.flush()
|
||||
n += 1
|
||||
@ -216,13 +216,13 @@ class pdbfile:
|
||||
else:
|
||||
file = root + str(n)
|
||||
file += ".pdb"
|
||||
|
||||
|
||||
f = open(file,'w')
|
||||
f.write(open(infile,'r').read())
|
||||
f.close()
|
||||
print(file,end='')
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
n += 1
|
||||
|
||||
print("\nwrote %d datasets to %s*.pdb in PDB format" % (n,root))
|
||||
@ -249,7 +249,7 @@ class pdbfile:
|
||||
self.convert(f,which)
|
||||
else:
|
||||
f.write(open(self.files[time],'r').read())
|
||||
|
||||
|
||||
f.close()
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
@ -268,8 +268,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:
|
||||
|
||||
Reference in New Issue
Block a user