more python 3 compatibility

This commit is contained in:
Axel Kohlmeyer
2022-02-23 12:30:03 -05:00
parent 5594868ef2
commit 2d7375798f
8 changed files with 69 additions and 67 deletions

View File

@ -16,7 +16,7 @@ from dump import dump
from cfg import cfg from cfg import cfg
if len(sys.argv) != 8: 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] dumpfile = sys.argv[1]
nid = int(sys.argv[2]) nid = int(sys.argv[2])

View File

@ -18,7 +18,7 @@ from dump import dump
from pdbfile import pdbfile from pdbfile import pdbfile
if len(sys.argv) != 8 and len(sys.argv) != 9: 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] dumpfile = sys.argv[1]
nid = int(sys.argv[2]) nid = int(sys.argv[2])

View File

@ -16,7 +16,7 @@ from dump import dump
from xyz import xyz from xyz import xyz
if len(sys.argv) != 8: 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] dumpfile = sys.argv[1]
nid = int(sys.argv[2]) nid = int(sys.argv[2])

View File

@ -14,7 +14,7 @@ sys.path.append(path)
from dump import dump from dump import dump
if len(sys.argv) != 4: 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] oldfile = sys.argv[1]
ncolumn = int(sys.argv[2]) ncolumn = int(sys.argv[2])

View File

@ -38,8 +38,7 @@ while iarg < narg:
else: break else: break
if iarg < narg or not outfile or not rfiles: if iarg < narg or not outfile or not rfiles:
print "Syntax: neb_combine.py -o outfile -b backfile -r dump1 dump2 ..." sys.exit("Syntax: neb_combine.py -o outfile -b backfile -r dump1 dump2 ...")
sys.exit()
if os.path.exists(outfile): os.remove(outfile) if os.path.exists(outfile): os.remove(outfile)

View File

@ -38,8 +38,7 @@ while iarg < narg:
else: break else: break
if iarg < narg or not outfile or not rfiles: if iarg < narg or not outfile or not rfiles:
print "Syntax: neb_final.py -o outfile -b backfile -r dump1 dump2 ..." sys.exit("Syntax: neb_final.py -o outfile -b backfile -r dump1 dump2 ...")
sys.exit()
if os.path.exists(outfile): os.remove(outfile) if os.path.exists(outfile): os.remove(outfile)

View File

@ -6,6 +6,8 @@
# 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.
from __future__ import print_function
# cfg tool # cfg tool
oneline = "Convert LAMMPS snapshots to AtomEye CFG format" oneline = "Convert LAMMPS snapshots to AtomEye CFG format"
@ -65,33 +67,33 @@ class cfg:
ylen = box[4]-box[1] ylen = box[4]-box[1]
zlen = box[5]-box[2] zlen = box[5]-box[2]
print >>f,"Number of particles = %d " % len(atoms) print("Number of particles = %d " % len(atoms), file=f)
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f)
print >>f,"H0(1,1) = %20.10f A " % xlen print("H0(1,1) = %20.10f A " % xlen, file=f)
print >>f,"H0(1,2) = 0.0 A " print("H0(1,2) = 0.0 A ", file=f)
print >>f,"H0(1,3) = 0.0 A " print("H0(1,3) = 0.0 A ", file=f)
print >>f,"H0(2,1) = 0.0 A " print("H0(2,1) = 0.0 A ", file=f)
print >>f,"H0(2,2) = %20.10f A " % ylen print("H0(2,2) = %20.10f A " % ylen, file=f)
print >>f,"H0(2,3) = 0.0 A " print("H0(2,3) = 0.0 A ", file=f)
print >>f,"H0(3,1) = 0.0 A " print("H0(3,1) = 0.0 A ", file=f)
print >>f,"H0(3,2) = 0.0 A " print("H0(3,2) = 0.0 A ", file=f)
print >>f,"H0(3,3) = %20.10f A " % zlen print("H0(3,3) = %20.10f A " % zlen, file=f)
print >>f,"#" print("#", file=f)
for atom in atoms: for atom in atoms:
itype = int(atom[1]) itype = int(atom[1])
xfrac = (atom[2]-box[0])/xlen xfrac = (atom[2]-box[0])/xlen
yfrac = (atom[3]-box[1])/ylen yfrac = (atom[3]-box[1])/ylen
zfrac = (atom[4]-box[2])/zlen 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("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 >>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 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f)
print time, print(time)
sys.stdout.flush() sys.stdout.flush()
n += 1 n += 1
f.close() 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] ylen = box[4]-box[1]
zlen = box[5]-box[2] zlen = box[5]-box[2]
print >>f,"Number of particles = %d " % len(atoms) print("Number of particles = %d " % len(atoms), file=f)
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f)
print >>f,"H0(1,1) = %20.10f A " % xlen print("H0(1,1) = %20.10f A " % xlen, file=f)
print >>f,"H0(1,2) = 0.0 A " print("H0(1,2) = 0.0 A ", file=f)
print >>f,"H0(1,3) = 0.0 A " print("H0(1,3) = 0.0 A ", file=f)
print >>f,"H0(2,1) = 0.0 A " print("H0(2,1) = 0.0 A ", file=f)
print >>f,"H0(2,2) = %20.10f A " % ylen print("H0(2,2) = %20.10f A " % ylen, file=f)
print >>f,"H0(2,3) = 0.0 A " print("H0(2,3) = 0.0 A ", file=f)
print >>f,"H0(3,1) = 0.0 A " print("H0(3,1) = 0.0 A ", file=f)
print >>f,"H0(3,2) = 0.0 A " print("H0(3,2) = 0.0 A ", file=f)
print >>f,"H0(3,3) = %20.10f A " % zlen print("H0(3,3) = %20.10f A " % zlen, file=f)
print >>f,"#" print("#", file=f)
for atom in atoms: for atom in atoms:
itype = int(atom[1]) itype = int(atom[1])
xfrac = (atom[2]-box[0])/xlen xfrac = (atom[2]-box[0])/xlen
yfrac = (atom[3]-box[1])/ylen yfrac = (atom[3]-box[1])/ylen
zfrac = (atom[4]-box[2])/zlen 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("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 >>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 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f)
print time, print(time)
sys.stdout.flush() sys.stdout.flush()
f.close() f.close()
n += 1 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] ylen = box[4]-box[1]
zlen = box[5]-box[2] zlen = box[5]-box[2]
print >>f,"Number of particles = %d " % len(atoms) print("Number of particles = %d " % len(atoms), file=f)
print >>f,"# Timestep %d \n#\nA = 1.0 Angstrom" % time print("# Timestep %d \n#\nA = 1.0 Angstrom" % time, file=f)
print >>f,"H0(1,1) = %20.10f A " % xlen print("H0(1,1) = %20.10f A " % xlen, file=f)
print >>f,"H0(1,2) = 0.0 A " print("H0(1,2) = 0.0 A ", file=f)
print >>f,"H0(1,3) = 0.0 A " print("H0(1,3) = 0.0 A ", file=f)
print >>f,"H0(2,1) = 0.0 A " print("H0(2,1) = 0.0 A ", file=f)
print >>f,"H0(2,2) = %20.10f A " % ylen print("H0(2,2) = %20.10f A " % ylen, file=f)
print >>f,"H0(2,3) = 0.0 A " print("H0(2,3) = 0.0 A ", file=f)
print >>f,"H0(3,1) = 0.0 A " print("H0(3,1) = 0.0 A ", file=f)
print >>f,"H0(3,2) = 0.0 A " print("H0(3,2) = 0.0 A ", file=f)
print >>f,"H0(3,3) = %20.10f A " % zlen print("H0(3,3) = %20.10f A " % zlen, file=f)
print >>f,"#" print("#", file=f)
for atom in atoms: for atom in atoms:
itype = int(atom[1]) itype = int(atom[1])
xfrac = (atom[2]-box[0])/xlen xfrac = (atom[2]-box[0])/xlen
yfrac = (atom[3]-box[1])/ylen yfrac = (atom[3]-box[1])/ylen
zfrac = (atom[4]-box[2])/zlen 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("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 >>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 0.0 0.0 0.0 " % (itype,xfrac,yfrac,zfrac), file=f)
f.close() f.close()

View File

@ -6,6 +6,8 @@
# 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.
from __future__ import print_function
# xyz tool # xyz tool
oneline = "Convert LAMMPS snapshots to XYZ format" oneline = "Convert LAMMPS snapshots to XYZ format"
@ -56,18 +58,18 @@ class xyz:
if flag == -1: break if flag == -1: break
time,box,atoms,bonds,tris,lines = self.data.viz(which) time,box,atoms,bonds,tris,lines = self.data.viz(which)
print >>f,len(atoms) print(len(atoms), file=f)
print >>f,"Atoms" print("Atoms", file=f)
for atom in atoms: for atom in atoms:
itype = int(atom[1]) 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() sys.stdout.flush()
n += 1 n += 1
f.close() 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 = root + str(n)
file += ".xyz" file += ".xyz"
f = open(file,"w") f = open(file,"w")
print >>f,len(atoms) print(len(atoms), file=f)
print >>f,"Atoms" print("Atoms", file=f)
for atom in atoms: for atom in atoms:
itype = int(atom[1]) 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() sys.stdout.flush()
f.close() f.close()
n += 1 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) which = self.data.findtime(time)
time,box,atoms,bonds,tris,lines = self.data.viz(which) time,box,atoms,bonds,tris,lines = self.data.viz(which)
f = open(file,"w") f = open(file,"w")
print >>f,len(atoms) print(len(atoms), file=f)
print >>f,"Atoms" print("Atoms", file=f)
for atom in atoms: for atom in atoms:
itype = int(atom[1]) 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() f.close()