python2/3 portability changes suggested by futurize -1

This commit is contained in:
Axel Kohlmeyer
2016-08-09 18:36:29 -04:00
parent ae3f4173c0
commit 0ab96350f0
11 changed files with 58 additions and 58 deletions

View File

@ -224,7 +224,7 @@ class dump:
self.flist = []
for word in words: self.flist += glob.glob(word)
if len(self.flist) == 0 and len(list) == 1:
raise StandardError("no dump file specified")
raise Exception("no dump file specified")
if len(list) == 1:
self.increment = 0
@ -286,9 +286,9 @@ class dump:
# if snapshots are scaled, unscale them
if (not self.names.has_key("x")) or \
(not self.names.has_key("y")) or \
(not self.names.has_key("z")):
if ("x" not in self.names) or \
("y" not in self.names) or \
("z" not in self.names):
print("no unscaling could be performed")
elif self.nsnaps > 0:
if self.scaled(self.nsnaps-1): self.unscale()
@ -299,7 +299,7 @@ class dump:
def next(self):
if not self.increment: raise StandardError("cannot read incrementally")
if not self.increment: raise Exception("cannot read incrementally")
# read next snapshot in current file using eof as pointer
# if fail, try next file
@ -417,7 +417,7 @@ class dump:
def map(self,*pairs):
if len(pairs) % 2 != 0:
raise StandardError("dump map() requires pairs of mappings")
raise Exception("dump map() requires pairs of mappings")
for i in range(0,len(pairs),2):
j = i + 1
self.names[pairs[j]] = pairs[i]-1
@ -589,7 +589,7 @@ class dump:
id = self.names["id"]
for snap in self.snaps:
if snap.tselect: self.sort_one(snap,id)
elif type(list[0]) is types.StringType:
elif type(list[0]) is bytes:
print("Sorting selected snapshots by %s ..." % list[0])
id = self.names[list[0]]
for snap in self.snaps:
@ -707,7 +707,7 @@ class dump:
list = re.findall(pattern,eq)
lhs = list[0][1:]
if not self.names.has_key(lhs):
if lhs not in self.names:
self.newcolumn(lhs)
for item in list:
@ -727,14 +727,14 @@ class dump:
def setv(self,colname,vec):
print("Setting ...")
if not self.names.has_key(colname):
if colname not in self.names:
self.newcolumn(colname)
icol = self.names[colname]
for snap in self.snaps:
if not snap.tselect: continue
if snap.nselect != len(vec):
raise StandardError("vec length does not match # of selected atoms")
raise Exception("vec length does not match # of selected atoms")
atoms = snap.atoms
m = 0
for i in range(snap.natoms):
@ -765,7 +765,7 @@ class dump:
def spread(self,old,n,new):
iold = self.names[old]
if not self.names.has_key(new): self.newcolumn(new)
if new not in self.names: self.newcolumn(new)
inew = self.names[new]
min,max = self.minmax(old)
@ -800,7 +800,7 @@ class dump:
def atom(self,n,*list):
if len(list) == 0:
raise StandardError("no columns specified")
raise Exception("no columns specified")
columns = []
values = []
for name in list:
@ -816,7 +816,7 @@ class dump:
for i in range(snap.natoms):
if atoms[i][id] == n: break
if atoms[i][id] != n:
raise StandardError("could not find atom ID in snapshot")
raise Exception("could not find atom ID in snapshot")
for j in range(ncol):
values[j][m] = atoms[i][columns[j]]
m += 1
@ -831,7 +831,7 @@ class dump:
snap = self.snaps[self.findtime(n)]
if len(list) == 0:
raise StandardError("no columns specified")
raise Exception("no columns specified")
columns = []
values = []
for name in list:
@ -959,7 +959,7 @@ class dump:
def findtime(self,n):
for i in range(self.nsnaps):
if self.snaps[i].time == n: return i
raise StandardError("no step %d exists" % n)
raise Exception("no step %d exists" % n)
# --------------------------------------------------------------------
# return maximum box size across all selected snapshots
@ -998,7 +998,7 @@ class dump:
# read bonds from bond dump file
if type(arg) is types.StringType:
if type(arg) is bytes:
try:
f = open(arg,'r')
@ -1008,7 +1008,7 @@ class dump:
nbonds = int(f.readline())
item = f.readline()
if not re.search("BONDS",item):
raise StandardError("could not read bonds from dump file")
raise Exception("could not read bonds from dump file")
words = f.readline().split()
ncol = len(words)
@ -1031,7 +1031,7 @@ class dump:
self.bondflag = 1
self.bondlist = bondlist
except:
raise StandardError("could not read from bond dump file")
raise Exception("could not read from bond dump file")
# request bonds from data object
@ -1047,7 +1047,7 @@ class dump:
self.bondflag = 1
self.bondlist = bondlist
except:
raise StandardError("could not extract bonds from data object")
raise Exception("could not extract bonds from data object")
# request tris/lines from cdata object
@ -1061,7 +1061,7 @@ class dump:
self.lineflag = 1
self.linelist = lines
except:
raise StandardError("could not extract tris/lines from cdata object")
raise Exception("could not extract tris/lines from cdata object")
# request tris from mdump object
@ -1070,10 +1070,10 @@ class dump:
self.triflag = 2
self.triobj = arg
except:
raise StandardError("could not extract tris from mdump object")
raise Exception("could not extract tris from mdump object")
else:
raise StandardError("unrecognized argument to dump.extra()")
raise Exception("unrecognized argument to dump.extra()")
# --------------------------------------------------------------------

View File

@ -779,7 +779,7 @@ class gl:
ncolor = self.vizinfo.nlcolor
for line in self.linedraw:
itype = int(line[1])
if itype > ncolor: raise StandardError("line type too big")
if itype > ncolor: raise Exception("line type too big")
red,green,blue = self.vizinfo.lcolor[itype]
glColor3f(red,green,blue)
thick = self.vizinfo.lrad[itype]
@ -828,7 +828,7 @@ class gl:
for bond in self.bonddraw:
if bond[10] > bound: continue
itype = int(bond[1])
if itype > ncolor: raise StandardError("bond type too big")
if itype > ncolor: raise Exception("bond type too big")
red,green,blue = self.vizinfo.bcolor[itype]
rad = self.vizinfo.brad[itype]
glPushMatrix()
@ -851,7 +851,7 @@ class gl:
ncolor = self.vizinfo.ntcolor
for tri in self.tridraw:
itype = int(tri[1])
if itype > ncolor: raise StandardError("tri type too big")
if itype > ncolor: raise Exception("tri type too big")
red,green,blue = self.vizinfo.tcolor[itype]
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,[red,green,blue,1.0]);
glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,self.shiny);
@ -909,7 +909,7 @@ class gl:
ymin >= ylo and ymax <= yhi and zmin >= zlo and zmax <= zhi:
if bond[10] > bound: continue
itype = int(bond[1])
if itype > ncolor: raise StandardError("bond type too big")
if itype > ncolor: raise Exception("bond type too big")
red,green,blue = self.vizinfo.bcolor[itype]
rad = self.vizinfo.brad[itype]
glPushMatrix()
@ -941,7 +941,7 @@ class gl:
ymin >= ylo and ymax <= yhi and \
zmin >= zlo and zmax <= zhi:
itype = int(tri[1])
if itype > ncolor: raise StandardError("tri type too big")
if itype > ncolor: raise Exception("tri type too big")
red,green,blue = self.vizinfo.tcolor[itype]
glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,
[red,green,blue,1.0]);

View File

@ -136,7 +136,7 @@ class gnu:
self.export(file,linear,vectors[0])
self.figures[self.current-1].ncurves = 1
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):
file = self.file + ".%d.%d" % (self.current,i/2+1)
self.export(file,vectors[i],vectors[i+1])
@ -170,7 +170,7 @@ class gnu:
def export(self,filename,*vectors):
n = len(vectors[0])
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')
nvec = len(vectors)
for i in range(n):

View File

@ -77,7 +77,7 @@ class pdbfile:
def __init__(self,*args):
if len(args) == 1:
if type(args[0]) is types.StringType:
if type(args[0]) is bytes:
filestr = args[0]
self.data = None
else:
@ -86,7 +86,7 @@ class pdbfile:
elif len(args) == 2:
filestr = args[0]
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
# append .pdb if needed
@ -100,14 +100,14 @@ class pdbfile:
for i in xrange(len(flist)):
if flist[i][-4:] != ".pdb": flist[i] += ".pdb"
if len(flist) == 0:
raise StandardError("no PDB file specified")
raise Exception("no PDB file specified")
self.files = flist
else: self.files = []
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:
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
@ -280,7 +280,7 @@ class pdbfile:
if len(self.files):
for atom in atoms:
id = atom[0]
if self.atomlines.has_key(id):
if id in self.atomlines:
(begin,end) = self.atomlines[id]
line = "%s%8.3f%8.3f%8.3f%s" % (begin,atom[2],atom[3],atom[4],end)
print(line,file=f,end='')

View File

@ -66,14 +66,14 @@ class vizinfo:
# convert args into lists if single values
# if arg = 0, convert to full-range list
if type(ids) is types.IntType and ids == 0:
if type(ids) is int and ids == 0:
if which == "atom": ids = range(self.nacolor)
if which == "bond": ids = range(self.nbcolor)
if which == "tri": ids = range(self.ntcolor)
if which == "line": ids = range(self.nlcolor)
if type(ids) is not types.ListType and type(ids) is not types.TupleType:
if type(ids) is not list and type(ids) is not tuple:
ids = [ids]
if type(rgbs) is not types.ListType and type(rgbs) is not types.TupleType:
if type(rgbs) is not list and type(rgbs) is not tuple:
rgbs = [rgbs]
# if list of types has a 0, increment each type value
@ -144,14 +144,14 @@ class vizinfo:
# convert args into lists if single values
# if arg = 0, convert to full-range list
if type(ids) is types.IntType and ids == 0:
if type(ids) is int and ids == 0:
if which == "atom": ids = range(self.narad)
if which == "bond": ids = range(self.nbrad)
if which == "line": ids = range(self.nlrad)
if type(ids) is not types.ListType and type(ids) is not types.TupleType:
if type(ids) is not list and type(ids) is not tuple:
ids = [ids]
if type(radii) is not types.ListType and \
type(radii) is not types.TupleType:
if type(radii) is not list and \
type(radii) is not tuple:
radii = [radii]
# if list of types has a 0, increment each type value
@ -209,12 +209,12 @@ class vizinfo:
# convert args into lists if single values
# if arg = 0, convert to full-range list
if type(ids) is types.IntType and ids == 0:
if type(ids) is int and ids == 0:
ids = range(self.ntfill)
if type(ids) is not types.ListType and type(ids) is not types.TupleType:
if type(ids) is not list and type(ids) is not tuple:
ids = [ids]
if type(fills) is not types.ListType and \
type(fills) is not types.TupleType:
if type(fills) is not list and \
type(fills) is not tuple:
fills = [fills]
# if list of types has a 0, increment each type value

View File

@ -62,7 +62,7 @@ if me == 0:
d = dump("tmp.dump",0)
g = gl(d)
d.next()
next(d)
d.unscale()
g.zoom(1)
g.shift(0,0)
@ -77,7 +77,7 @@ while ntimestep < nsteps:
lmp.command("run %d pre no post no" % nfreq)
ntimestep += nfreq
if me == 0:
d.next()
next(d)
d.unscale()
g.show(ntimestep)

View File

@ -58,7 +58,7 @@ if me == 0:
d = dump("tmp.dump",0)
p = pdbfile(d)
d.next()
next(d)
d.unscale()
p.single(ntimestep)
pm.load("tmp.pdb")
@ -70,7 +70,7 @@ while ntimestep < nsteps:
lmp.command("run %d pre no post no" % nfreq)
ntimestep += nfreq
if me == 0:
d.next()
next(d)
d.unscale()
p.single(ntimestep)
pm.load("tmp.pdb")

View File

@ -58,7 +58,7 @@ if me == 0:
d = dump('tmp.dump',0)
p = pdbfile(d)
d.next()
next(d)
d.unscale()
p.single(ntimestep)
v.new('tmp.pdb','pdb')
@ -69,7 +69,7 @@ while ntimestep < nsteps:
lmp.command("run %d pre no post no" % nfreq)
ntimestep += nfreq
if me == 0:
d.next()
next(d)
d.unscale()
p.single(ntimestep)
# add frame to current data set

View File

@ -35,7 +35,7 @@ def quit():
# read dump snapshot and viz it, update plot with compute value
def update(ntimestep):
d.next()
next(d)
d.unscale()
g.show(ntimestep)
value = lmp.extract_compute(compute,0,0)
@ -99,7 +99,7 @@ if me == 0:
d = dump("tmp.dump",0)
g = gl(d)
d.next()
next(d)
d.unscale()
g.zoom(1)
g.shift(0,0)

View File

@ -35,7 +35,7 @@ def quit():
# read dump snapshot and viz it, update plot with compute value
def update(ntimestep):
d.next()
next(d)
d.unscale()
p.single(ntimestep)
pm.load("tmp.pdb")
@ -98,7 +98,7 @@ if me == 0:
d = dump("tmp.dump",0)
p = pdbfile(d)
d.next()
next(d)
d.unscale()
p.single(ntimestep)
pm.load("tmp.pdb")

View File

@ -35,7 +35,7 @@ def quit():
# read dump snapshot and viz it, update plot with compute value
def update(ntimestep):
d.next()
next(d)
d.unscale()
p.single(ntimestep)
v.append('tmp.pdb','pdb')
@ -98,7 +98,7 @@ if me == 0:
d = dump('tmp.dump',0)
p = pdbfile(d)
d.next()
next(d)
d.unscale()
p.single(ntimestep)
v.new('tmp.pdb','pdb')