From 2d7375798fb0cbaae350ca55a259220e31d0e31a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 23 Feb 2022 12:30:03 -0500 Subject: [PATCH] more python 3 compatibility --- tools/python/dump2cfg.py | 2 +- tools/python/dump2pdb.py | 2 +- tools/python/dump2xyz.py | 2 +- tools/python/dumpsort.py | 2 +- tools/python/neb_combine.py | 3 +- tools/python/neb_final.py | 3 +- tools/python/pizza/cfg.py | 94 +++++++++++++++++++------------------ tools/python/pizza/xyz.py | 28 ++++++----- 8 files changed, 69 insertions(+), 67 deletions(-) diff --git a/tools/python/dump2cfg.py b/tools/python/dump2cfg.py index 901fde5efb..e113d9e635 100755 --- a/tools/python/dump2cfg.py +++ b/tools/python/dump2cfg.py @@ -16,7 +16,7 @@ from dump import dump from cfg import cfg if len(sys.argv) != 8: - raise StandardError, "Syntax: dump2cfg.py dumpfile Nid Ntype Nx Ny Nz cfgfile" + sys.exit("Syntax: dump2cfg.py dumpfile Nid Ntype Nx Ny Nz cfgfile") dumpfile = sys.argv[1] nid = int(sys.argv[2]) diff --git a/tools/python/dump2pdb.py b/tools/python/dump2pdb.py index d9a008df30..c97e09c0a6 100755 --- a/tools/python/dump2pdb.py +++ b/tools/python/dump2pdb.py @@ -18,7 +18,7 @@ from dump import dump from pdbfile import pdbfile if len(sys.argv) != 8 and len(sys.argv) != 9: - raise StandardError, "Syntax: dump2pdb.py dumpfile Nid Ntype Nx Ny Nz pdbfile template" + sys.exit("Syntax: dump2pdb.py dumpfile Nid Ntype Nx Ny Nz pdbfile template") dumpfile = sys.argv[1] nid = int(sys.argv[2]) diff --git a/tools/python/dump2xyz.py b/tools/python/dump2xyz.py index 0f3739a5e7..b24bc603b9 100755 --- a/tools/python/dump2xyz.py +++ b/tools/python/dump2xyz.py @@ -16,7 +16,7 @@ from dump import dump from xyz import xyz if len(sys.argv) != 8: - raise StandardError, "Syntax: dump2xyz.py dumpfile Nid Ntype Nx Ny Nz xyzfile" + sys.exit("Syntax: dump2xyz.py dumpfile Nid Ntype Nx Ny Nz xyzfile") dumpfile = sys.argv[1] nid = int(sys.argv[2]) diff --git a/tools/python/dumpsort.py b/tools/python/dumpsort.py index e4b04009ad..97e3af14f1 100755 --- a/tools/python/dumpsort.py +++ b/tools/python/dumpsort.py @@ -14,7 +14,7 @@ sys.path.append(path) from dump import dump if len(sys.argv) != 4: - raise StandardError, "Syntax: dumpsort.py oldfile N newfile" + sys.exit("Syntax: dumpsort.py oldfile N newfile") oldfile = sys.argv[1] ncolumn = int(sys.argv[2]) diff --git a/tools/python/neb_combine.py b/tools/python/neb_combine.py index bc1c568397..f94bea4875 100755 --- a/tools/python/neb_combine.py +++ b/tools/python/neb_combine.py @@ -38,8 +38,7 @@ while iarg < narg: else: break if iarg < narg or not outfile or not rfiles: - print "Syntax: neb_combine.py -o outfile -b backfile -r dump1 dump2 ..." - sys.exit() + sys.exit("Syntax: neb_combine.py -o outfile -b backfile -r dump1 dump2 ...") if os.path.exists(outfile): os.remove(outfile) diff --git a/tools/python/neb_final.py b/tools/python/neb_final.py index 4b7ddc40eb..ec9fc2e8f7 100755 --- a/tools/python/neb_final.py +++ b/tools/python/neb_final.py @@ -38,8 +38,7 @@ while iarg < narg: else: break if iarg < narg or not outfile or not rfiles: - print "Syntax: neb_final.py -o outfile -b backfile -r dump1 dump2 ..." - sys.exit() + sys.exit("Syntax: neb_final.py -o outfile -b backfile -r dump1 dump2 ...") if os.path.exists(outfile): os.remove(outfile) diff --git a/tools/python/pizza/cfg.py b/tools/python/pizza/cfg.py index bbd930ea3c..d39d8990ce 100644 --- a/tools/python/pizza/cfg.py +++ b/tools/python/pizza/cfg.py @@ -6,6 +6,8 @@ # certain rights in this software. This software is distributed under # the GNU General Public License. +from __future__ import print_function + # cfg tool oneline = "Convert LAMMPS snapshots to AtomEye CFG format" @@ -65,33 +67,33 @@ class cfg: ylen = box[4]-box[1] zlen = box[5]-box[2] - print >>f,"Number of particles = %d " % len(atoms) - print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time - print >>f,"H0(1,1) = %20.10f A " % xlen - print >>f,"H0(1,2) = 0.0 A " - print >>f,"H0(1,3) = 0.0 A " - print >>f,"H0(2,1) = 0.0 A " - print >>f,"H0(2,2) = %20.10f A " % ylen - print >>f,"H0(2,3) = 0.0 A " - print >>f,"H0(3,1) = 0.0 A " - print >>f,"H0(3,2) = 0.0 A " - print >>f,"H0(3,3) = %20.10f A " % zlen - print >>f,"#" + print("Number of particles = %d " % len(atoms), file=f) + print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f) + print("H0(1,1) = %20.10f A " % xlen, file=f) + print("H0(1,2) = 0.0 A ", file=f) + print("H0(1,3) = 0.0 A ", file=f) + print("H0(2,1) = 0.0 A ", file=f) + print("H0(2,2) = %20.10f A " % ylen, file=f) + print("H0(2,3) = 0.0 A ", file=f) + print("H0(3,1) = 0.0 A ", file=f) + print("H0(3,2) = 0.0 A ", file=f) + print("H0(3,3) = %20.10f A " % zlen, file=f) + print("#", file=f) for atom in atoms: itype = int(atom[1]) xfrac = (atom[2]-box[0])/xlen yfrac = (atom[3]-box[1])/ylen zfrac = (atom[4]-box[2])/zlen -# print >>f,"1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7]) - print >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac) +# print("1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7]), file=f) + print("1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f) - print time, + print(time) sys.stdout.flush() n += 1 f.close() - print "\nwrote %d snapshots to %s in CFG format" % (n,file) + print("\nwrote %d snapshots to %s in CFG format" % (n,file)) # -------------------------------------------------------------------- @@ -120,33 +122,33 @@ class cfg: ylen = box[4]-box[1] zlen = box[5]-box[2] - print >>f,"Number of particles = %d " % len(atoms) - print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time - print >>f,"H0(1,1) = %20.10f A " % xlen - print >>f,"H0(1,2) = 0.0 A " - print >>f,"H0(1,3) = 0.0 A " - print >>f,"H0(2,1) = 0.0 A " - print >>f,"H0(2,2) = %20.10f A " % ylen - print >>f,"H0(2,3) = 0.0 A " - print >>f,"H0(3,1) = 0.0 A " - print >>f,"H0(3,2) = 0.0 A " - print >>f,"H0(3,3) = %20.10f A " % zlen - print >>f,"#" + print("Number of particles = %d " % len(atoms), file=f) + print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f) + print("H0(1,1) = %20.10f A " % xlen, file=f) + print("H0(1,2) = 0.0 A ", file=f) + print("H0(1,3) = 0.0 A ", file=f) + print("H0(2,1) = 0.0 A ", file=f) + print("H0(2,2) = %20.10f A " % ylen, file=f) + print("H0(2,3) = 0.0 A ", file=f) + print("H0(3,1) = 0.0 A ", file=f) + print("H0(3,2) = 0.0 A ", file=f) + print("H0(3,3) = %20.10f A " % zlen, file=f) + print("#", file=f) for atom in atoms: itype = int(atom[1]) xfrac = (atom[2]-box[0])/xlen yfrac = (atom[3]-box[1])/ylen zfrac = (atom[4]-box[2])/zlen -# print >>f,"1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7]) - print >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac) +# print("1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7]), file=f) + print("1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f) - print time, + print(time) sys.stdout.flush() f.close() n += 1 - print "\nwrote %s snapshots in CFG format" % n + print("\nwrote %s snapshots in CFG format" % n) # -------------------------------------------------------------------- @@ -163,25 +165,25 @@ class cfg: ylen = box[4]-box[1] zlen = box[5]-box[2] - print >>f,"Number of particles = %d " % len(atoms) - print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time - print >>f,"H0(1,1) = %20.10f A " % xlen - print >>f,"H0(1,2) = 0.0 A " - print >>f,"H0(1,3) = 0.0 A " - print >>f,"H0(2,1) = 0.0 A " - print >>f,"H0(2,2) = %20.10f A " % ylen - print >>f,"H0(2,3) = 0.0 A " - print >>f,"H0(3,1) = 0.0 A " - print >>f,"H0(3,2) = 0.0 A " - print >>f,"H0(3,3) = %20.10f A " % zlen - print >>f,"#" + print("Number of particles = %d " % len(atoms), file=f) + print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f) + print("H0(1,1) = %20.10f A " % xlen, file=f) + print("H0(1,2) = 0.0 A ", file=f) + print("H0(1,3) = 0.0 A ", file=f) + print("H0(2,1) = 0.0 A ", file=f) + print("H0(2,2) = %20.10f A " % ylen, file=f) + print("H0(2,3) = 0.0 A ", file=f) + print("H0(3,1) = 0.0 A ", file=f) + print("H0(3,2) = 0.0 A ", file=f) + print("H0(3,3) = %20.10f A " % zlen, file=f) + print("#", file=f) for atom in atoms: itype = int(atom[1]) xfrac = (atom[2]-box[0])/xlen yfrac = (atom[3]-box[1])/ylen zfrac = (atom[4]-box[2])/zlen -# print >>f,"1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7]) - print >>f,"1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac) +# print("1.0 %d %15.10f %15.10f %15.10f %15.10f %15.10f %15.10f " % (itype,xfrac,yfrac,zfrac,atom[5],atom[6],atom[7]), file=f) + print("1.0 %d %15.10f %15.10f %15.10f 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f) f.close() diff --git a/tools/python/pizza/xyz.py b/tools/python/pizza/xyz.py index 92b681540a..1b905cc046 100644 --- a/tools/python/pizza/xyz.py +++ b/tools/python/pizza/xyz.py @@ -6,6 +6,8 @@ # certain rights in this software. This software is distributed under # the GNU General Public License. +from __future__ import print_function + # xyz tool oneline = "Convert LAMMPS snapshots to XYZ format" @@ -56,18 +58,18 @@ class xyz: if flag == -1: break time,box,atoms,bonds,tris,lines = self.data.viz(which) - print >>f,len(atoms) - print >>f,"Atoms" + print(len(atoms), file=f) + print("Atoms", file=f) for atom in atoms: itype = int(atom[1]) - print >>f,itype,atom[2],atom[3],atom[4] + print(itype,atom[2],atom[3],atom[4], file=f) - print time, + print(time) sys.stdout.flush() n += 1 f.close() - print "\nwrote %d snapshots to %s in XYZ format" % (n,file) + print("\nwrote %d snapshots to %s in XYZ format" % (n,file)) # -------------------------------------------------------------------- @@ -91,17 +93,17 @@ class xyz: file = root + str(n) file += ".xyz" f = open(file,"w") - print >>f,len(atoms) - print >>f,"Atoms" + print(len(atoms), file=f) + print("Atoms", file=f) for atom in atoms: itype = int(atom[1]) - print >>f,itype,atom[2],atom[3],atom[4] - print time, + print(itype,atom[2],atom[3],atom[4], file=f) + print(time) sys.stdout.flush() f.close() n += 1 - print "\nwrote %s snapshots in XYZ format" % n + print("\nwrote %s snapshots in XYZ format" % n) # -------------------------------------------------------------------- @@ -113,9 +115,9 @@ class xyz: which = self.data.findtime(time) time,box,atoms,bonds,tris,lines = self.data.viz(which) f = open(file,"w") - print >>f,len(atoms) - print >>f,"Atoms" + print(len(atoms), file=f) + print("Atoms", file=f) for atom in atoms: itype = int(atom[1]) - print >>f,itype,atom[2],atom[3],atom[4] + print(itype,atom[2],atom[3],atom[4], file=f) f.close()