Sync copies of pizza
This commit is contained in:
@ -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.
|
||||||
|
|
||||||
# for python3 compatibility
|
# 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)
|
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.none() deselect all timesteps
|
||||||
@ -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 Exception("no dump file specified")
|
raise Exception("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()
|
||||||
|
|
||||||
# set default names for atom columns if file wasn't self-describing
|
# set default names for atom columns if file wasn't self-describing
|
||||||
|
|
||||||
if len(self.snaps) == 0:
|
if len(self.snaps) == 0:
|
||||||
print("no column assignments made")
|
print("no column assignments made")
|
||||||
elif len(self.names):
|
elif len(self.names):
|
||||||
@ -341,7 +341,7 @@ class dump:
|
|||||||
# return snapshot or 0 if failed
|
# return snapshot or 0 if failed
|
||||||
# assign column names if not already done and file is self-describing
|
# assign column names if not already done and file is self-describing
|
||||||
# convert xs,xu to x
|
# convert xs,xu to x
|
||||||
|
|
||||||
def read_snapshot(self,f):
|
def read_snapshot(self,f):
|
||||||
try:
|
try:
|
||||||
snap = Snap()
|
snap = Snap()
|
||||||
@ -414,7 +414,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 Exception("dump map() requires pairs of mappings")
|
raise Exception("dump map() requires pairs of mappings")
|
||||||
@ -492,7 +492,7 @@ class dump:
|
|||||||
atoms[:,x] = snap.xlo + atoms[:,x]*xprd
|
atoms[:,x] = snap.xlo + atoms[:,x]*xprd
|
||||||
atoms[:,y] = snap.ylo + atoms[:,y]*yprd
|
atoms[:,y] = snap.ylo + atoms[:,y]*yprd
|
||||||
atoms[:,z] = snap.zlo + atoms[:,z]*zprd
|
atoms[:,z] = snap.zlo + atoms[:,z]*zprd
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# wrap coords from outside box to inside
|
# wrap coords from outside box to inside
|
||||||
|
|
||||||
@ -505,7 +505,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
|
||||||
@ -527,7 +527,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
|
||||||
@ -542,7 +542,7 @@ class dump:
|
|||||||
|
|
||||||
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"]
|
||||||
@ -551,7 +551,7 @@ class dump:
|
|||||||
iy = self.names["iy"]
|
iy = self.names["iy"]
|
||||||
iz = self.names["iz"]
|
iz = self.names["iz"]
|
||||||
iother = self.names[other]
|
iother = self.names[other]
|
||||||
|
|
||||||
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
|
||||||
@ -568,7 +568,7 @@ class dump:
|
|||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# 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):
|
||||||
ncol = len(self.snaps[0].atoms[0])
|
ncol = len(self.snaps[0].atoms[0])
|
||||||
pairs = self.names.items()
|
pairs = self.names.items()
|
||||||
@ -631,7 +631,7 @@ class dump:
|
|||||||
print(snap.ylo,snap.yhi,file=f)
|
print(snap.ylo,snap.yhi,file=f)
|
||||||
print(snap.zlo,snap.zhi,file=f)
|
print(snap.zlo,snap.zhi,file=f)
|
||||||
print("ITEM: ATOMS",namestr,file=f)
|
print("ITEM: ATOMS",namestr,file=f)
|
||||||
|
|
||||||
atoms = snap.atoms
|
atoms = snap.atoms
|
||||||
nvalues = len(atoms[0])
|
nvalues = len(atoms[0])
|
||||||
for i in range(snap.natoms):
|
for i in range(snap.natoms):
|
||||||
@ -655,7 +655,7 @@ class dump:
|
|||||||
if not snap.tselect: continue
|
if not snap.tselect: continue
|
||||||
print(snap.time,end='')
|
print(snap.time,end='')
|
||||||
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("ITEM: TIMESTEP",file=f)
|
print("ITEM: TIMESTEP",file=f)
|
||||||
@ -667,7 +667,7 @@ class dump:
|
|||||||
print(snap.ylo,snap.yhi,file=f)
|
print(snap.ylo,snap.yhi,file=f)
|
||||||
print(snap.zlo,snap.zhi,file=f)
|
print(snap.zlo,snap.zhi,file=f)
|
||||||
print("ITEM: ATOMS",namestr,file=f)
|
print("ITEM: ATOMS",namestr,file=f)
|
||||||
|
|
||||||
atoms = snap.atoms
|
atoms = snap.atoms
|
||||||
nvalues = len(atoms[0])
|
nvalues = len(atoms[0])
|
||||||
for i in range(snap.natoms):
|
for i in range(snap.natoms):
|
||||||
@ -709,7 +709,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]
|
||||||
@ -721,7 +721,7 @@ class dump:
|
|||||||
if not snap.tselect: continue
|
if not snap.tselect: continue
|
||||||
for i in range(snap.natoms):
|
for i in range(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
|
||||||
|
|
||||||
@ -741,7 +741,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
|
||||||
|
|
||||||
@ -807,7 +807,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:
|
||||||
@ -823,13 +823,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 Exception("no columns specified")
|
raise Exception("no columns specified")
|
||||||
columns = []
|
columns = []
|
||||||
@ -884,7 +884,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
|
||||||
|
|
||||||
@ -896,11 +896,11 @@ 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
|
||||||
# augment with bonds, tris, lines if extra() was invoked
|
# augment with bonds, tris, lines if extra() was invoked
|
||||||
|
|
||||||
def viz(self,isnap):
|
def viz(self,isnap):
|
||||||
snap = self.snaps[isnap]
|
snap = self.snaps[isnap]
|
||||||
|
|
||||||
@ -914,7 +914,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 range(snap.natoms):
|
for i in range(snap.natoms):
|
||||||
if not snap.aselect[i]: continue
|
if not snap.aselect[i]: continue
|
||||||
@ -948,12 +948,12 @@ class dump:
|
|||||||
elif self.triflag == 2:
|
elif self.triflag == 2:
|
||||||
timetmp,boxtmp,atomstmp,bondstmp, \
|
timetmp,boxtmp,atomstmp,bondstmp, \
|
||||||
tris,linestmp = self.triobj.viz(time,1)
|
tris,linestmp = self.triobj.viz(time,1)
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
if self.lineflag: lines = self.linelist
|
if self.lineflag: lines = self.linelist
|
||||||
|
|
||||||
return time,box,atoms,bonds,tris,lines
|
return time,box,atoms,bonds,tris,lines
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
def findtime(self,n):
|
def findtime(self,n):
|
||||||
@ -997,7 +997,7 @@ class dump:
|
|||||||
def extra(self,arg):
|
def extra(self,arg):
|
||||||
|
|
||||||
# read bonds from bond dump file
|
# read bonds from bond dump file
|
||||||
|
|
||||||
if type(arg) is types.StringType:
|
if type(arg) is types.StringType:
|
||||||
try:
|
try:
|
||||||
f = open(arg,'r')
|
f = open(arg,'r')
|
||||||
@ -1017,7 +1017,7 @@ class dump:
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# convert values to int and absolute value since can be negative types
|
# convert values to int and absolute value since can be negative types
|
||||||
|
|
||||||
if oldnumeric: bondlist = np.zeros((nbonds,4),np.Int)
|
if oldnumeric: bondlist = np.zeros((nbonds,4),np.Int)
|
||||||
else: bondlist = np.zeros((nbonds,4),np.int)
|
else: bondlist = np.zeros((nbonds,4),np.int)
|
||||||
ints = [abs(int(value)) for value in words]
|
ints = [abs(int(value)) for value in words]
|
||||||
@ -1032,9 +1032,9 @@ class dump:
|
|||||||
self.bondlist = bondlist
|
self.bondlist = bondlist
|
||||||
except:
|
except:
|
||||||
raise Exception("could not read from bond dump file")
|
raise Exception("could not read from bond dump file")
|
||||||
|
|
||||||
# request bonds from data object
|
# request bonds from data object
|
||||||
|
|
||||||
elif type(arg) is types.InstanceType and ".data" in str(arg.__class__):
|
elif type(arg) is types.InstanceType and ".data" in str(arg.__class__):
|
||||||
try:
|
try:
|
||||||
bondlist = []
|
bondlist = []
|
||||||
@ -1050,7 +1050,7 @@ class dump:
|
|||||||
raise Exception("could not extract bonds from data object")
|
raise Exception("could not extract bonds from data object")
|
||||||
|
|
||||||
# request tris/lines from cdata object
|
# request tris/lines from cdata object
|
||||||
|
|
||||||
elif type(arg) is types.InstanceType and ".cdata" in str(arg.__class__):
|
elif type(arg) is types.InstanceType and ".cdata" in str(arg.__class__):
|
||||||
try:
|
try:
|
||||||
tmp,tmp,tmp,tmp,tris,lines = arg.viz(0)
|
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")
|
raise Exception("could not extract tris/lines from cdata object")
|
||||||
|
|
||||||
# request tris from mdump object
|
# request tris from mdump object
|
||||||
|
|
||||||
elif type(arg) is types.InstanceType and ".mdump" in str(arg.__class__):
|
elif type(arg) is types.InstanceType and ".mdump" in str(arg.__class__):
|
||||||
try:
|
try:
|
||||||
self.triflag = 2
|
self.triflag = 2
|
||||||
@ -1074,7 +1074,7 @@ class dump:
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception("unrecognized argument to dump.extra()")
|
raise Exception("unrecognized argument to dump.extra()")
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
def compare_atom(self,a,b):
|
def compare_atom(self,a,b):
|
||||||
@ -1083,7 +1083,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
|
||||||
@ -1098,7 +1098,7 @@ class tselect:
|
|||||||
|
|
||||||
def __init__(self,data):
|
def __init__(self,data):
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
def all(self):
|
def all(self):
|
||||||
@ -1145,7 +1145,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):
|
||||||
@ -1191,7 +1191,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:
|
||||||
|
|||||||
@ -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.
|
||||||
|
|
||||||
# for python3 compatibility
|
# for python3 compatibility
|
||||||
@ -16,7 +16,7 @@ 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
|
||||||
@ -35,14 +35,14 @@ 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
|
||||||
@ -98,7 +98,7 @@ except ImportError: PIZZA_GNUTERM = "x11"
|
|||||||
# Class definition
|
# Class definition
|
||||||
|
|
||||||
class gnu:
|
class gnu:
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -106,7 +106,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):
|
||||||
@ -118,7 +118,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):
|
||||||
@ -159,7 +159,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)
|
||||||
@ -167,7 +167,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
|
||||||
|
|
||||||
@ -208,7 +208,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
|
||||||
@ -219,7 +219,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
|
||||||
|
|
||||||
@ -228,7 +228,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):
|
||||||
@ -252,12 +252,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()
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
@ -266,7 +266,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):
|
||||||
@ -283,13 +283,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):
|
||||||
@ -298,7 +298,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):
|
||||||
@ -307,7 +307,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):
|
||||||
@ -323,10 +323,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 + '"'
|
||||||
@ -338,11 +338,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 [*:*]")
|
||||||
@ -372,7 +372,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 = ""
|
||||||
|
|||||||
@ -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.
|
||||||
|
|
||||||
# for python3 compatibility
|
# 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,
|
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, ...
|
||||||
@ -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
|
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)
|
||||||
|
|
||||||
@ -97,7 +97,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 = []
|
||||||
@ -117,7 +117,7 @@ class pdbfile:
|
|||||||
raise Exception("no input PDB file(s)")
|
raise Exception("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()
|
||||||
@ -127,7 +127,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:
|
||||||
@ -145,7 +145,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:
|
||||||
@ -163,7 +163,7 @@ class pdbfile:
|
|||||||
print("END",file=f)
|
print("END",file=f)
|
||||||
print(file,end='')
|
print(file,end='')
|
||||||
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))
|
||||||
|
|
||||||
@ -199,7 +199,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,end='')
|
print(time,end='')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
n += 1
|
n += 1
|
||||||
@ -216,13 +216,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,end='')
|
print(file,end='')
|
||||||
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))
|
||||||
@ -249,7 +249,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()
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
@ -268,8 +268,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:
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -6,17 +6,20 @@
|
|||||||
# 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.
|
||||||
|
|
||||||
|
# for python3 compatibility
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
# gnu tool
|
# gnu tool
|
||||||
|
|
||||||
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 +32,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:
|
||||||
|
|
||||||
@ -84,12 +87,13 @@ g.curve(N,'r') set color of curve N
|
|||||||
|
|
||||||
# Imports and external programs
|
# Imports and external programs
|
||||||
|
|
||||||
import types, os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
try: from DEFAULTS import PIZZA_GNUPLOT
|
try: from DEFAULTS import PIZZA_GNUPLOT
|
||||||
except: PIZZA_GNUPLOT = "gnuplot"
|
except ImportError: PIZZA_GNUPLOT = "gnuplot -p"
|
||||||
try: from DEFAULTS import PIZZA_GNUTERM
|
try: from DEFAULTS import PIZZA_GNUTERM
|
||||||
except: PIZZA_GNUTERM = "x11"
|
except ImportError: PIZZA_GNUTERM = "x11"
|
||||||
|
|
||||||
# Class definition
|
# Class definition
|
||||||
|
|
||||||
@ -119,7 +123,10 @@ class gnu:
|
|||||||
|
|
||||||
def enter(self):
|
def enter(self):
|
||||||
while 1:
|
while 1:
|
||||||
command = raw_input("gnuplot> ")
|
if sys.version_info[0] == 3:
|
||||||
|
command = input("gnuplot> ")
|
||||||
|
else:
|
||||||
|
command = raw_input("gnuplot> ")
|
||||||
if command == "quit" or command == "exit": return
|
if command == "quit" or command == "exit": return
|
||||||
self.__call__(command)
|
self.__call__(command)
|
||||||
|
|
||||||
@ -133,7 +140,7 @@ class gnu:
|
|||||||
self.export(file,linear,vectors[0])
|
self.export(file,linear,vectors[0])
|
||||||
self.figures[self.current-1].ncurves = 1
|
self.figures[self.current-1].ncurves = 1
|
||||||
else:
|
else:
|
||||||
if len(vectors) % 2: raise StandardError,"vectors must come in pairs"
|
if len(vectors) % 2: raise Exception("vectors must come in pairs")
|
||||||
for i in range(0,len(vectors),2):
|
for i in range(0,len(vectors),2):
|
||||||
file = self.file + ".%d.%d" % (self.current,i/2+1)
|
file = self.file + ".%d.%d" % (self.current,i/2+1)
|
||||||
self.export(file,vectors[i],vectors[i+1])
|
self.export(file,vectors[i],vectors[i+1])
|
||||||
@ -167,13 +174,13 @@ class gnu:
|
|||||||
def export(self,filename,*vectors):
|
def export(self,filename,*vectors):
|
||||||
n = len(vectors[0])
|
n = len(vectors[0])
|
||||||
for vector in vectors:
|
for vector in vectors:
|
||||||
if len(vector) != n: raise StandardError,"vectors must be same length"
|
if len(vector) != n: raise Exception("vectors must be same length")
|
||||||
f = open(filename,'w')
|
f = open(filename,'w')
|
||||||
nvec = len(vectors)
|
nvec = len(vectors)
|
||||||
for i in xrange(n):
|
for i in range(n):
|
||||||
for j in xrange(nvec):
|
for j in range(nvec):
|
||||||
print >>f,vectors[j][i],
|
print(str(vectors[j][i])+" ",file=f,end='')
|
||||||
print >>f
|
print ("",file=f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
@ -350,7 +357,7 @@ class gnu:
|
|||||||
|
|
||||||
self.__call__("set key off")
|
self.__call__("set key off")
|
||||||
cmd = 'plot '
|
cmd = 'plot '
|
||||||
for i in range(fig.ncurves):
|
for i in range(int(fig.ncurves)):
|
||||||
file = self.file + ".%d.%d" % (self.current,i+1)
|
file = self.file + ".%d.%d" % (self.current,i+1)
|
||||||
if len(fig.colors) > i and fig.colors[i]:
|
if len(fig.colors) > i and fig.colors[i]:
|
||||||
cmd += "'" + file + "' using 1:2 with line %d, " % fig.colors[i]
|
cmd += "'" + file + "' using 1:2 with line %d, " % fig.colors[i]
|
||||||
|
|||||||
@ -6,6 +6,9 @@
|
|||||||
# 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.
|
||||||
|
|
||||||
|
# for python3 compatibility
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
# pdb tool
|
# pdb tool
|
||||||
|
|
||||||
oneline = "Read, write PDB files in combo with LAMMPS snapshots"
|
oneline = "Read, write PDB files in combo with LAMMPS snapshots"
|
||||||
@ -51,6 +54,7 @@ index,time,flag = p.iterator(1)
|
|||||||
|
|
||||||
# History
|
# History
|
||||||
# 8/05, Steve Plimpton (SNL): original version
|
# 8/05, Steve Plimpton (SNL): original version
|
||||||
|
# 3/17, Richard Berger (Temple U): improve Python 3 compatibility
|
||||||
|
|
||||||
# ToDo list
|
# ToDo list
|
||||||
# for generic PDB file (no template) from a LJ unit system,
|
# for generic PDB file (no template) from a LJ unit system,
|
||||||
@ -64,7 +68,13 @@ index,time,flag = p.iterator(1)
|
|||||||
|
|
||||||
# Imports and external programs
|
# Imports and external programs
|
||||||
|
|
||||||
import sys, types, glob, urllib
|
import sys, glob, urllib
|
||||||
|
PY3 = sys.version_info[0] == 3
|
||||||
|
|
||||||
|
if PY3:
|
||||||
|
string_types = str,
|
||||||
|
else:
|
||||||
|
string_types = basestring
|
||||||
|
|
||||||
# Class definition
|
# Class definition
|
||||||
|
|
||||||
@ -74,7 +84,7 @@ class pdbfile:
|
|||||||
|
|
||||||
def __init__(self,*args):
|
def __init__(self,*args):
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
if type(args[0]) is types.StringType:
|
if type(args[0]) is string_types:
|
||||||
filestr = args[0]
|
filestr = args[0]
|
||||||
self.data = None
|
self.data = None
|
||||||
else:
|
else:
|
||||||
@ -83,7 +93,7 @@ class pdbfile:
|
|||||||
elif len(args) == 2:
|
elif len(args) == 2:
|
||||||
filestr = args[0]
|
filestr = args[0]
|
||||||
self.data = args[1]
|
self.data = args[1]
|
||||||
else: raise StandardError, "invalid args for pdb()"
|
else: raise Exception("invalid args for pdb()")
|
||||||
|
|
||||||
# flist = full list of all PDB input file names
|
# flist = full list of all PDB input file names
|
||||||
# append .pdb if needed
|
# append .pdb if needed
|
||||||
@ -94,17 +104,17 @@ class pdbfile:
|
|||||||
for file in list:
|
for file in list:
|
||||||
if '*' in file: flist += glob.glob(file)
|
if '*' in file: flist += glob.glob(file)
|
||||||
else: flist.append(file)
|
else: flist.append(file)
|
||||||
for i in xrange(len(flist)):
|
for i in range(len(flist)):
|
||||||
if flist[i][-4:] != ".pdb": flist[i] += ".pdb"
|
if flist[i][-4:] != ".pdb": flist[i] += ".pdb"
|
||||||
if len(flist) == 0:
|
if len(flist) == 0:
|
||||||
raise StandardError,"no PDB file specified"
|
raise Exception("no PDB file specified")
|
||||||
self.files = flist
|
self.files = flist
|
||||||
else: self.files = []
|
else: self.files = []
|
||||||
|
|
||||||
if len(self.files) > 1 and self.data:
|
if len(self.files) > 1 and self.data:
|
||||||
raise StandardError, "cannot use multiple PDB files with data object"
|
raise Exception("cannot use multiple PDB files with data object")
|
||||||
if len(self.files) == 0 and not self.data:
|
if len(self.files) == 0 and not self.data:
|
||||||
raise StandardError, "no input PDB file(s)"
|
raise Exception("no input PDB file(s)")
|
||||||
|
|
||||||
# grab PDB file from http://rcsb.org if not a local file
|
# grab PDB file from http://rcsb.org if not a local file
|
||||||
|
|
||||||
@ -112,7 +122,7 @@ class pdbfile:
|
|||||||
try:
|
try:
|
||||||
open(self.files[0],'r').close()
|
open(self.files[0],'r').close()
|
||||||
except:
|
except:
|
||||||
print "downloading %s from http://rcsb.org" % self.files[0]
|
print("downloading %s from http://rcsb.org" % self.files[0])
|
||||||
fetchstr = "http://www.rcsb.org/pdb/cgi/export.cgi/%s?format=PDB&pdbId=2cpk&compression=None" % self.files[0]
|
fetchstr = "http://www.rcsb.org/pdb/cgi/export.cgi/%s?format=PDB&pdbId=2cpk&compression=None" % self.files[0]
|
||||||
urllib.urlretrieve(fetchstr,self.files[0])
|
urllib.urlretrieve(fetchstr,self.files[0])
|
||||||
|
|
||||||
@ -142,20 +152,20 @@ class pdbfile:
|
|||||||
which,time,flag = self.data.iterator(flag)
|
which,time,flag = self.data.iterator(flag)
|
||||||
if flag == -1: break
|
if flag == -1: break
|
||||||
self.convert(f,which)
|
self.convert(f,which)
|
||||||
print >>f,"END"
|
print("END",file=f)
|
||||||
print time,
|
print(time,end='')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for file in self.files:
|
for file in self.files:
|
||||||
f.write(open(file,'r').read())
|
f.write(open(file,'r').read())
|
||||||
print >>f,"END"
|
print("END",file=f)
|
||||||
print file,
|
print(file,end='')
|
||||||
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))
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# write series of numbered PDB files
|
# write series of numbered PDB files
|
||||||
@ -190,7 +200,7 @@ class pdbfile:
|
|||||||
self.convert(f,which)
|
self.convert(f,which)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
print time,
|
print(time,end='')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
@ -210,12 +220,12 @@ class pdbfile:
|
|||||||
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,end='')
|
||||||
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))
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# write a single PDB file
|
# write a single PDB file
|
||||||
@ -280,10 +290,10 @@ class pdbfile:
|
|||||||
if self.atomlines.has_key(id):
|
if self.atomlines.has_key(id):
|
||||||
(begin,end) = self.atomlines[id]
|
(begin,end) = self.atomlines[id]
|
||||||
line = "%s%8.3f%8.3f%8.3f%s" % (begin,atom[2],atom[3],atom[4],end)
|
line = "%s%8.3f%8.3f%8.3f%s" % (begin,atom[2],atom[3],atom[4],end)
|
||||||
print >>f,line,
|
print(line,file=f,end='')
|
||||||
else:
|
else:
|
||||||
for atom in atoms:
|
for atom in atoms:
|
||||||
begin = "ATOM %6d %2d R00 1 " % (atom[0],atom[1])
|
begin = "ATOM %6d %2d R00 1 " % (atom[0],atom[1])
|
||||||
middle = "%8.3f%8.3f%8.3f" % (atom[2],atom[3],atom[4])
|
middle = "%8.3f%8.3f%8.3f" % (atom[2],atom[3],atom[4])
|
||||||
end = " 1.00 0.00 NONE"
|
end = " 1.00 0.00 NONE"
|
||||||
print >>f,begin+middle+end
|
print(begin+middle+end,file=f)
|
||||||
|
|||||||
Reference in New Issue
Block a user