diff --git a/python/examples/demo.py b/python/examples/demo.py index fb212d0e12..015fcba4cc 100755 --- a/python/examples/demo.py +++ b/python/examples/demo.py @@ -6,13 +6,14 @@ # Syntax: demo.py # uses in.demo as LAMMPS input script +from __future__ import print_function import sys # parse command line argv = sys.argv if len(argv) != 1: - print "Syntax: demo.py" + print("Syntax: demo.py") sys.exit() from lammps import lammps @@ -22,29 +23,29 @@ lmp = lammps() lmp.file("in.demo") -print "\nPython output:" +print("\nPython output:") natoms = lmp.extract_global("natoms",0) mass = lmp.extract_atom("mass",2) x = lmp.extract_atom("x",3) -print "Natoms, mass, x[0][0] coord =",natoms,mass[1],x[0][0] +print("Natoms, mass, x[0][0] coord =",natoms,mass[1],x[0][0]) temp = lmp.extract_compute("thermo_temp",0,0) -print "Temperature from compute =",temp +print("Temperature from compute =",temp) eng = lmp.extract_variable("eng",None,0) -print "Energy from equal-style variable =",eng +print("Energy from equal-style variable =",eng) vy = lmp.extract_variable("vy","all",1) -print "Velocity component from atom-style variable =",vy[1] +print("Velocity component from atom-style variable =",vy[1]) natoms = lmp.get_natoms() -print "Natoms from get_natoms =",natoms +print("Natoms from get_natoms =",natoms) xc = lmp.gather_atoms("x",1,3) -print "Global coords from gather_atoms =",xc[0],xc[1],xc[31] +print("Global coords from gather_atoms =",xc[0],xc[1],xc[31]) xc[0] = xc[0] + 1.0 lmp.scatter_atoms("x",1,3,xc) -print "Changed x[0][0] via scatter_atoms =",x[0][0] +print("Changed x[0][0] via scatter_atoms =",x[0][0]) diff --git a/python/examples/gui.py b/python/examples/gui.py index 0b4981cf57..3fc1d7e36c 100755 --- a/python/examples/gui.py +++ b/python/examples/gui.py @@ -10,6 +10,7 @@ # IMPORTANT: this script cannot yet be run in parallel via Pypar, # because I can't seem to do a MPI-style broadcast in Pypar +from __future__ import print_function import sys,time # methods called by GUI @@ -31,7 +32,7 @@ def quit(): argv = sys.argv if len(argv) != 3: - print "Syntax: gui.py in.lammps Nfreq" + print("Syntax: gui.py in.lammps Nfreq") sys.exit() infile = sys.argv[1] @@ -60,7 +61,10 @@ runflag = 0 temptarget = 1.0 if me == 0: - from Tkinter import * + try: + from Tkinter import * + except: + from tkinter import * tkroot = Tk() tkroot.withdraw() root = Toplevel(tkroot) @@ -108,5 +112,5 @@ while 1: time.sleep(0.01) # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/mc.py b/python/examples/mc.py index 8e556f3c52..9e7317218b 100755 --- a/python/examples/mc.py +++ b/python/examples/mc.py @@ -6,6 +6,7 @@ # Syntax: mc.py in.mc # in.mc = LAMMPS input script +from __future__ import print_function import sys,random,math # set these parameters @@ -21,7 +22,7 @@ random.seed(27848) argv = sys.argv if len(argv) != 2: - print "Syntax: mc.py in.mc" + print("Syntax: mc.py in.mc") sys.exit() infile = sys.argv[1] @@ -50,7 +51,7 @@ lmp.command("variable emin equal $e") x = lmp.extract_atom("x",3) -for i in xrange(natoms): +for i in range(natoms): x[i][0] += deltaperturb * (2*random.random()-1) x[i][1] += deltaperturb * (2*random.random()-1) @@ -68,7 +69,7 @@ estart = lmp.extract_compute("thermo_pe",0,0) / natoms elast = estart naccept = 0 -for i in xrange(nloop): +for i in range(nloop): iatom = random.randrange(0,natoms) x0 = x[iatom][0] y0 = x[iatom][1] @@ -100,9 +101,9 @@ nbuild = lmp.extract_variable("nbuild",None,0) lmp.command("run 0") estop = lmp.extract_compute("thermo_pe",0,0) / natoms -print "MC stats:" -print " starting energy =",estart -print " final energy =",estop -print " minimum energy of perfect lattice =",emin -print " accepted MC moves =",naccept -print " neighbor list rebuilds =",nbuild +print("MC stats:") +print(" starting energy =",estart) +print(" final energy =",estop) +print(" minimum energy of perfect lattice =",emin) +print(" accepted MC moves =",naccept) +print(" neighbor list rebuilds =",nbuild) diff --git a/python/examples/pizza/dump.py b/python/examples/pizza/dump.py index 76e1f3bcee..632e534e8f 100644 --- a/python/examples/pizza/dump.py +++ b/python/examples/pizza/dump.py @@ -179,6 +179,8 @@ d.extra(data) extract bond/tri/line list from data # Imports and external programs +from __future__ import print_function + import sys, commands, re, glob, types from os import popen from math import * # any function could be used by set() @@ -324,7 +326,7 @@ class dump: snap = self.snaps[self.nsnaps] snap.tselect = 1 snap.nselect = snap.natoms - for i in xrange(snap.natoms): snap.aselect[i] = 1 + for i in range(snap.natoms): snap.aselect[i] = 1 self.nsnaps += 1 self.nselect += 1 @@ -370,14 +372,14 @@ class dump: if snap.natoms: words = f.readline().split() ncol = len(words) - for i in xrange(1,snap.natoms): + for i in range(1,snap.natoms): words += f.readline().split() floats = map(float,words) if oldnumeric: atoms = np.zeros((snap.natoms,ncol),np.Float) else: atoms = np.zeros((snap.natoms,ncol),np.float) start = 0 stop = ncol - for i in xrange(snap.natoms): + for i in range(snap.natoms): atoms[i] = floats[start:stop] start = stop stop += ncol @@ -554,9 +556,9 @@ class dump: zprd = snap.zhi - snap.zlo atoms = snap.atoms ids = {} - for i in xrange(snap.natoms): + for i in range(snap.natoms): ids[atoms[i][id]] = i - for i in xrange(snap.natoms): + for i in range(snap.natoms): j = ids[atoms[i][iother]] atoms[i][x] += (atoms[i][ix]-atoms[j][ix])*xprd atoms[i][y] += (atoms[i][iy]-atoms[j][iy])*yprd @@ -570,7 +572,7 @@ class dump: pairs = self.names.items() values = self.names.values() str = "" - for i in xrange(ncol): + for i in range(ncol): if i in values: str += pairs[values.index(i)][0] + ' ' return str @@ -602,7 +604,7 @@ class dump: atoms = snap.atoms ids = atoms[:,id] ordering = np.argsort(ids) - for i in xrange(len(atoms[0])): + for i in range(len(atoms[0])): atoms[:,i] = np.take(atoms[:,i],ordering) # -------------------------------------------------------------------- @@ -630,10 +632,10 @@ class dump: atoms = snap.atoms nvalues = len(atoms[0]) - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue line = "" - for j in xrange(nvalues): + for j in range(nvalues): if (j < 2): line += str(int(atoms[i][j])) + " " else: @@ -666,10 +668,10 @@ class dump: atoms = snap.atoms nvalues = len(atoms[0]) - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue line = "" - for j in xrange(nvalues): + for j in range(nvalues): if (j < 2): line += str(int(atoms[i][j])) + " " else: @@ -688,7 +690,7 @@ class dump: for snap in self.snaps: if not snap.tselect: continue atoms = snap.atoms - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue if atoms[i][icol] < min: min = atoms[i][icol] if atoms[i][icol] > max: max = atoms[i][icol] @@ -715,7 +717,7 @@ class dump: for snap in self.snaps: if not snap.tselect: continue - for i in xrange(snap.natoms): + for i in range(snap.natoms): if snap.aselect[i]: exec ceq # -------------------------------------------------------------------- @@ -733,7 +735,7 @@ class dump: raise StandardError,"vec length does not match # of selected atoms" atoms = snap.atoms m = 0 - for i in xrange(snap.natoms): + for i in range(snap.natoms): if snap.aselect[i]: atoms[i][icol] = vec[m] m += 1 @@ -746,12 +748,12 @@ class dump: icol = self.names[col] id = self.names["id"] ids = {} - for i in xrange(self.snaps[istep].natoms): + for i in range(self.snaps[istep].natoms): ids[self.snaps[istep].atoms[i][id]] = i for snap in self.snaps: if not snap.tselect: continue atoms = snap.atoms - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue j = ids[atoms[i][id]] atoms[i][icol] = self.snaps[istep].atoms[j][icol] @@ -772,7 +774,7 @@ class dump: for snap in self.snaps: if not snap.tselect: continue atoms = snap.atoms - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue ivalue = int((atoms[i][iold] - min) * invdelta) + 1 if ivalue > n: ivalue = n @@ -809,11 +811,11 @@ class dump: for snap in self.snaps: if not snap.tselect: continue atoms = snap.atoms - for i in xrange(snap.natoms): + 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" - for j in xrange(ncol): + for j in range(ncol): values[j][m] = atoms[i][columns[j]] m += 1 @@ -836,9 +838,9 @@ class dump: ncol = len(columns) m = 0 - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue - for j in xrange(ncol): + for j in range(ncol): values[j][m] = snap.atoms[i][columns[j]] m += 1 @@ -887,7 +889,7 @@ class dump: def iterator(self,flag): start = 0 if flag: start = self.iterate + 1 - for i in xrange(start,self.nsnaps): + for i in range(start,self.nsnaps): if self.snaps[i].tselect: self.iterate = i return i,self.snaps[i].time,1 @@ -912,7 +914,7 @@ class dump: # need Numeric/Numpy mode here atoms = [] - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue atom = snap.atoms[i] atoms.append([atom[id],atom[type],atom[x],atom[y],atom[z]]) @@ -927,7 +929,7 @@ class dump: bonds = [] if self.bondflag: alist = {} - for i in xrange(len(atoms)): alist[int(atoms[i][0])] = i + for i in range(len(atoms)): alist[int(atoms[i][0])] = i for bond in self.bondlist: try: i = alist[bond[2]] @@ -953,7 +955,7 @@ class dump: # -------------------------------------------------------------------- def findtime(self,n): - for i in xrange(self.nsnaps): + for i in range(self.nsnaps): if self.snaps[i].time == n: return i raise StandardError, "no step %d exists" % n @@ -982,7 +984,7 @@ class dump: for snap in self.snaps: if not snap.tselect: continue atoms = snap.atoms - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue if atoms[i][icol] > max: max = atoms[i][icol] return int(max) @@ -1008,7 +1010,7 @@ class dump: words = f.readline().split() ncol = len(words) - for i in xrange(1,nbonds): + for i in range(1,nbonds): words += f.readline().split() f.close() @@ -1019,7 +1021,7 @@ class dump: ints = [abs(int(value)) for value in words] start = 0 stop = 4 - for i in xrange(nbonds): + for i in range(nbonds): bondlist[i] = ints[start:stop] start += ncol stop += ncol @@ -1149,7 +1151,7 @@ class tselect: snaps = data.snaps cmd = "flag = " + teststr.replace("$t","snaps[i].time") ccmd = compile(cmd,'','single') - for i in xrange(data.nsnaps): + for i in range(data.nsnaps): if not snaps[i].tselect: continue exec ccmd if not flag: @@ -1173,12 +1175,12 @@ class aselect: if len(args) == 0: # all selected timesteps for snap in data.snaps: if not snap.tselect: continue - for i in xrange(snap.natoms): snap.aselect[i] = 1 + for i in range(snap.natoms): snap.aselect[i] = 1 snap.nselect = snap.natoms else: # one timestep n = data.findtime(args[0]) snap = data.snaps[n] - for i in xrange(snap.natoms): snap.aselect[i] = 1 + for i in range(snap.natoms): snap.aselect[i] = 1 snap.nselect = snap.natoms # -------------------------------------------------------------------- @@ -1201,18 +1203,18 @@ class aselect: if len(args) == 0: # all selected timesteps for snap in data.snaps: if not snap.tselect: continue - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue exec ccmd if not flag: snap.aselect[i] = 0 snap.nselect -= 1 - for i in xrange(data.nsnaps): + for i in range(data.nsnaps): if data.snaps[i].tselect: print "%d atoms of %d selected in first step %d" % \ (data.snaps[i].nselect,data.snaps[i].natoms,data.snaps[i].time) break - for i in xrange(data.nsnaps-1,-1,-1): + for i in range(data.nsnaps-1,-1,-1): if data.snaps[i].tselect: print "%d atoms of %d selected in last step %d" % \ (data.snaps[i].nselect,data.snaps[i].natoms,data.snaps[i].time) @@ -1221,7 +1223,7 @@ class aselect: else: # one timestep n = data.findtime(args[0]) snap = data.snaps[n] - for i in xrange(snap.natoms): + for i in range(snap.natoms): if not snap.aselect[i]: continue exec ccmd if not flag: diff --git a/python/examples/pizza/gnu.py b/python/examples/pizza/gnu.py index f6f0167330..1c6dbee033 100644 --- a/python/examples/pizza/gnu.py +++ b/python/examples/pizza/gnu.py @@ -87,7 +87,7 @@ g.curve(N,'r') set color of curve N import types, os try: from DEFAULTS import PIZZA_GNUPLOT -except: PIZZA_GNUPLOT = "gnuplot" +except: PIZZA_GNUPLOT = "gnuplot -p" try: from DEFAULTS import PIZZA_GNUTERM except: PIZZA_GNUTERM = "x11" @@ -133,7 +133,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 StandardError("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]) @@ -167,11 +167,11 @@ 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 StandardError("vectors must be same length") f = open(filename,'w') nvec = len(vectors) - for i in xrange(n): - for j in xrange(nvec): + for i in range(n): + for j in range(nvec): print >>f,vectors[j][i], print >>f f.close() diff --git a/python/examples/plot.py b/python/examples/plot.py index a3f465ca19..efb9ecaa68 100755 --- a/python/examples/plot.py +++ b/python/examples/plot.py @@ -10,6 +10,7 @@ # compute-ID = ID of compute that calculates temperature # (or any other scalar quantity) +from __future__ import print_function import sys sys.path.append("./pizza") from gnu import gnu @@ -18,7 +19,7 @@ from gnu import gnu argv = sys.argv if len(argv) != 5: - print "Syntax: plot.py in.lammps Nfreq Nsteps compute-ID" + print("Syntax: plot.py in.lammps Nfreq Nsteps compute-ID") sys.exit() infile = sys.argv[1] @@ -71,5 +72,5 @@ while ntimestep < nsteps: lmp.command("run 0 pre no post yes") # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/simple.py b/python/examples/simple.py index 4ca4b81a8d..9315a555fc 100755 --- a/python/examples/simple.py +++ b/python/examples/simple.py @@ -11,13 +11,14 @@ # in.lammps = LAMMPS input script # also need to uncomment either Pypar or mpi4py sections below +from __future__ import print_function import sys # parse command line argv = sys.argv if len(argv) != 2: - print "Syntax: simple.py in.lammps" + print("Syntax: simple.py in.lammps") sys.exit() infile = sys.argv[1] @@ -56,13 +57,13 @@ lmp.scatter_atoms("x",1,3,x) lmp.command("run 1"); f = lmp.extract_atom("f",3) -print "Force on 1 atom via extract_atom: ",f[0][0] +print("Force on 1 atom via extract_atom: ",f[0][0]) fx = lmp.extract_variable("fx","all",1) -print "Force on 1 atom via extract_variable:",fx[0] +print("Force on 1 atom via extract_variable:",fx[0]) # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() # uncomment if running in parallel via mpi4py diff --git a/python/examples/split.py b/python/examples/split.py index 65cf395581..719877d826 100755 --- a/python/examples/split.py +++ b/python/examples/split.py @@ -7,13 +7,14 @@ # Syntax: split.py in.lammps # in.lammps = LAMMPS input script +from __future__ import print_function import sys # parse command line argv = sys.argv if len(argv) != 2: - print "Syntax: simple.py in.lammps" + print("Syntax: simple.py in.lammps") sys.exit() infile = sys.argv[1] @@ -57,12 +58,12 @@ if color == 0: lmp.command("run 1"); f = lmp.extract_atom("f",3) - print "Force on 1 atom via extract_atom: ",f[0][0] + print("Force on 1 atom via extract_atom: ",f[0][0]) fx = lmp.extract_variable("fx","all",1) - print "Force on 1 atom via extract_variable:",fx[0] - print "Proc %d out of %d procs has" % (me,nprocs), lmp - print "Calculation on partition 0 complete" + print("Force on 1 atom via extract_variable:",fx[0]) + print("Proc %d out of %d procs has" % (me,nprocs), lmp) + print("Calculation on partition 0 complete") else: # could run a 2nd calculation on second partition @@ -71,7 +72,7 @@ else: import time time.sleep(2) - print "Calculation on partition 1 complete" + print("Calculation on partition 1 complete") # shutdown mpi4py diff --git a/python/examples/trivial.py b/python/examples/trivial.py index 7e61b97cb3..0e3d6b91af 100755 --- a/python/examples/trivial.py +++ b/python/examples/trivial.py @@ -6,13 +6,14 @@ # Syntax: trivial.py in.lammps # in.lammps = LAMMPS input script +from __future__ import print_function import sys # parse command line argv = sys.argv if len(argv) != 2: - print "Syntax: trivial.py in.lammps" + print("Syntax: trivial.py in.lammps") sys.exit() infile = sys.argv[1] diff --git a/python/examples/viz_atomeye.py b/python/examples/viz_atomeye.py index ca0d60f443..3803b2e79c 100755 --- a/python/examples/viz_atomeye.py +++ b/python/examples/viz_atomeye.py @@ -8,6 +8,7 @@ # Nfreq = dump and viz shapshot every this many steps # Nsteps = run for this many steps +from __future__ import print_function import sys,os # set this to point to AtomEye version 3 executable @@ -19,7 +20,7 @@ ATOMEYE3 = "/home/sjplimp/tools/atomeye3/A3.i686-20060530 > atomeye.out" argv = sys.argv if len(argv) != 4: - print "Syntax: viz_atomeye.py in.lammps Nfreq Nsteps" + print("Syntax: viz_atomeye.py in.lammps Nfreq Nsteps") sys.exit() infile = sys.argv[1] @@ -68,5 +69,5 @@ while ntimestep < nsteps: lmp.command("run 0 pre no post yes") # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/viz_gl.py b/python/examples/viz_gl.py index fcb92e03f2..476509ad43 100755 --- a/python/examples/viz_gl.py +++ b/python/examples/viz_gl.py @@ -8,6 +8,7 @@ # Nfreq = dump and viz shapshot every this many steps # Nsteps = run for this many steps +from __future__ import print_function import sys sys.path.append("./pizza") @@ -15,7 +16,7 @@ sys.path.append("./pizza") argv = sys.argv if len(argv) != 4: - print "Syntax: viz_gl.py in.lammps Nfreq Nsteps" + print("Syntax: viz_gl.py in.lammps Nfreq Nsteps") sys.exit() infile = sys.argv[1] @@ -48,7 +49,11 @@ ntimestep = 0 # just proc 0 handles reading of dump file and viz if me == 0: - import Tkinter + tkroot = None + try: + import Tkinter + except: + import tkinter as Tkinter tkroot = Tkinter.Tk() tkroot.withdraw() @@ -79,5 +84,5 @@ while ntimestep < nsteps: lmp.command("run 0 pre no post yes") # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/viz_pymol.py b/python/examples/viz_pymol.py index 17f3d44810..02178a0fb0 100755 --- a/python/examples/viz_pymol.py +++ b/python/examples/viz_pymol.py @@ -8,6 +8,7 @@ # Nfreq = dump and viz shapshot every this many steps # Nsteps = run for this many steps +from __future__ import print_function import sys sys.path.append("./pizza") @@ -15,7 +16,7 @@ sys.path.append("./pizza") argv = sys.argv if len(argv) != 4: - print "Syntax: viz_pymol.py in.lammps Nfreq Nsteps" + print("Syntax: viz_pymol.py in.lammps Nfreq Nsteps") sys.exit() infile = sys.argv[1] @@ -78,5 +79,5 @@ while ntimestep < nsteps: lmp.command("run 0 pre no post yes") # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/viz_vmd.py b/python/examples/viz_vmd.py index 47f27d26ff..807a8c9d55 100755 --- a/python/examples/viz_vmd.py +++ b/python/examples/viz_vmd.py @@ -8,6 +8,7 @@ # Nfreq = dump and viz shapshot every this many steps # Nsteps = run for this many steps +from __future__ import print_function import sys sys.path.append("./pizza") @@ -15,7 +16,7 @@ sys.path.append("./pizza") argv = sys.argv if len(argv) != 4: - print "Syntax: viz_vmd.py in.lammps Nfreq Nsteps" + print("Syntax: viz_vmd.py in.lammps Nfreq Nsteps") sys.exit() infile = sys.argv[1] @@ -82,10 +83,10 @@ if me == 0: v.flush() # uncomment the following, if you want to work with the viz some more. #v('menu main on') - #print "type quit to terminate." + #print("type quit to terminate.") #v.enter() #v.stop() # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/vizplotgui_atomeye.py b/python/examples/vizplotgui_atomeye.py index 935123d2b6..71730974df 100755 --- a/python/examples/vizplotgui_atomeye.py +++ b/python/examples/vizplotgui_atomeye.py @@ -12,6 +12,7 @@ # IMPORTANT: this script cannot yet be run in parallel via Pypar, # because I can't seem to do a MPI-style broadcast in Pypar +from __future__ import print_function import sys,os,time sys.path.append("./pizza") @@ -50,7 +51,7 @@ def update(ntimestep): argv = sys.argv if len(argv) != 4: - print "Syntax: vizplotgui_atomeye.py in.lammps Nfreq compute-ID" + print("Syntax: vizplotgui_atomeye.py in.lammps Nfreq compute-ID") sys.exit() infile = sys.argv[1] @@ -97,7 +98,10 @@ if me == 0: # display GUI with run/stop buttons and slider for temperature if me == 0: - from Tkinter import * + try: + from Tkinter import * + except: + from tkinter import * tkroot = Tk() tkroot.withdraw() root = Toplevel(tkroot) @@ -161,5 +165,5 @@ while 1: lmp.command("run 0 pre no post yes") # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/vizplotgui_gl.py b/python/examples/vizplotgui_gl.py index ee26487bb2..937670e511 100755 --- a/python/examples/vizplotgui_gl.py +++ b/python/examples/vizplotgui_gl.py @@ -12,6 +12,7 @@ # IMPORTANT: this script cannot yet be run in parallel via Pypar, # because I can't seem to do a MPI-style broadcast in Pypar +from __future__ import print_function import sys,time sys.path.append("./pizza") @@ -46,7 +47,7 @@ def update(ntimestep): argv = sys.argv if len(argv) != 4: - print "Syntax: vizplotgui_gl.py in.lammps Nfreq compute-ID" + print("Syntax: vizplotgui_gl.py in.lammps Nfreq compute-ID") sys.exit() infile = sys.argv[1] @@ -86,7 +87,10 @@ temptarget = 1.0 # just proc 0 handles reading of dump file and viz if me == 0: - from Tkinter import * + try: + from Tkinter import * + except: + from tkinter import * tkroot = Tk() tkroot.withdraw() @@ -107,7 +111,10 @@ if me == 0: # display GUI with run/stop buttons and slider for temperature if me == 0: - from Tkinter import * + try: + from Tkinter import * + except: + from tkinter import * tkroot = Tk() tkroot.withdraw() root = Toplevel(tkroot) @@ -171,5 +178,5 @@ while 1: lmp.command("run 0 pre no post yes") # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/vizplotgui_pymol.py b/python/examples/vizplotgui_pymol.py index c0628a2b1b..c7a8a00c6d 100755 --- a/python/examples/vizplotgui_pymol.py +++ b/python/examples/vizplotgui_pymol.py @@ -12,6 +12,7 @@ # IMPORTANT: this script cannot yet be run in parallel via Pypar, # because I can't seem to do a MPI-style broadcast in Pypar +from __future__ import print_function import sys,time sys.path.append("./pizza") @@ -48,7 +49,7 @@ def update(ntimestep): argv = sys.argv if len(argv) != 4: - print "Syntax: vizplotgui_pymol.py in.lammps Nfreq compute-ID" + print("Syntax: vizplotgui_pymol.py in.lammps Nfreq compute-ID") sys.exit() infile = sys.argv[1] @@ -106,7 +107,10 @@ if me == 0: # display GUI with run/stop buttons and slider for temperature if me == 0: - from Tkinter import * + try: + from Tkinter import * + except: + from tkinter import * tkroot = Tk() tkroot.withdraw() root = Toplevel(tkroot) @@ -170,5 +174,5 @@ while 1: lmp.command("run 0 pre no post yes") # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/examples/vizplotgui_vmd.py b/python/examples/vizplotgui_vmd.py index d969666a1a..9eab0865e2 100755 --- a/python/examples/vizplotgui_vmd.py +++ b/python/examples/vizplotgui_vmd.py @@ -12,6 +12,7 @@ # IMPORTANT: this script cannot yet be run in parallel via Pypar, # because I can't seem to do a MPI-style broadcast in Pypar +from __future__ import print_function import sys,time sys.path.append("./pizza") @@ -47,7 +48,7 @@ def update(ntimestep): argv = sys.argv if len(argv) != 4: - print "Syntax: vizplotgui_vmd.py in.lammps Nfreq compute-ID" + print("Syntax: vizplotgui_vmd.py in.lammps Nfreq compute-ID") sys.exit() infile = sys.argv[1] @@ -105,7 +106,10 @@ if me == 0: # display GUI with run/stop buttons and slider for temperature if me == 0: - from Tkinter import * + try: + from Tkinter import * + except: + from tkinter import * tkroot = Tk() tkroot.withdraw() root = Toplevel(tkroot) @@ -169,5 +173,5 @@ while 1: lmp.command("run 0 pre no post yes") # uncomment if running in parallel via Pypar -#print "Proc %d out of %d procs has" % (me,nprocs), lmp +#print("Proc %d out of %d procs has" % (me,nprocs), lmp) #pypar.finalize() diff --git a/python/lammps.py b/python/lammps.py index 9f40a4304f..8adb29acd4 100644 --- a/python/lammps.py +++ b/python/lammps.py @@ -143,15 +143,15 @@ class lammps(object): return self.lib.lammps_version(self.lmp) def file(self,file): - file = file.encode() + if file: file = file.encode() self.lib.lammps_file(self.lmp,file) def command(self,cmd): - cmd = cmd.encode() + if cmd: cmd = cmd.encode() self.lib.lammps_command(self.lmp,cmd) def extract_global(self,name,type): - name = name.encode() + if name: name = name.encode() if type == 0: self.lib.lammps_extract_global.restype = POINTER(c_int) elif type == 1: @@ -161,7 +161,7 @@ class lammps(object): return ptr[0] def extract_atom(self,name,type): - name = name.encode() + if name: name = name.encode() if type == 0: self.lib.lammps_extract_atom.restype = POINTER(c_int) elif type == 1: @@ -175,7 +175,7 @@ class lammps(object): return ptr def extract_compute(self,id,style,type): - id = id.encode() + if id: id = id.encode() if type == 0: if style > 0: return None self.lib.lammps_extract_compute.restype = POINTER(c_double) @@ -195,7 +195,7 @@ class lammps(object): # double was allocated by library interface function def extract_fix(self,id,style,type,i=0,j=0): - id = id.encode() + if id: id = id.encode() if style == 0: self.lib.lammps_extract_fix.restype = POINTER(c_double) ptr = self.lib.lammps_extract_fix(self.lmp,id,style,type,i,j) @@ -219,8 +219,8 @@ class lammps(object): # memory was allocated by library interface function def extract_variable(self,name,group,type): - name = name.encode() - group = group.encode() + if name: name = name.encode() + if group: group = group.encode() if type == 0: self.lib.lammps_extract_variable.restype = POINTER(c_double) ptr = self.lib.lammps_extract_variable(self.lmp,name,group) @@ -244,8 +244,8 @@ class lammps(object): # returns 0 for success, -1 if failed def set_variable(self,name,value): - name = name.encode() - value = str(value).encode() + if name: name = name.encode() + if value: value = str(value).encode() return self.lib.lammps_set_variable(self.lmp,name,str(value)) # return total number of atoms in system @@ -256,7 +256,7 @@ class lammps(object): # return vector of atom properties gathered across procs, ordered by atom ID def gather_atoms(self,name,type,count): - name = name.encode() + if name: name = name.encode() natoms = self.lib.lammps_get_natoms(self.lmp) if type == 0: data = ((count*natoms)*c_int)() @@ -271,7 +271,7 @@ class lammps(object): # assume vector is of correct type and length, as created by gather_atoms() def scatter_atoms(self,name,type,count,data): - name = name.encode() + if name: name = name.encode() self.lib.lammps_scatter_atoms(self.lmp,name,type,count,data)