From 660b4699de8a116a4015e28d0d8fab09847a3fd4 Mon Sep 17 00:00:00 2001 From: Mark Driver Date: Tue, 14 Apr 2020 17:02:17 +0100 Subject: [PATCH] update python3 compatibility of contrib scripts. This update simply updates compliance of print statements, remove mixed space/tab indentation, exception construction calls and moves imports to start of script. --- contrib/python/Gnuplot.py | 26 +++--- contrib/python/Xrtdb.py | 100 ++++++++++---------- contrib/python/dplot.py | 20 ++-- contrib/python/mathutil.py | 116 +++++++++++------------- contrib/python/nwchem_tddft_spectrum.py | 4 +- contrib/python/office.py | 54 +++++------ contrib/python/pes_scan.py | 54 +++++------ 7 files changed, 180 insertions(+), 194 deletions(-) diff --git a/contrib/python/Gnuplot.py b/contrib/python/Gnuplot.py index 21b7c99c6f..31004942f9 100644 --- a/contrib/python/Gnuplot.py +++ b/contrib/python/Gnuplot.py @@ -434,9 +434,9 @@ class File(PlotItem): "using " + string.join(map(repr, self.using), ':')) elif type(self.using) == type(1): - self.options.insert(0, "using " + `self.using`) + self.options.insert(0, "using " + repr(self.using)) else: - raise OptionException('using=' + `self.using`) + raise OptionException('using=' + repr(self.using)) class Data(File): @@ -996,7 +996,7 @@ if __name__ == '__main__': g2.plot(Func("x**2", title="calculated by gnuplot"), d) # Save what we just plotted as a color postscript file: - print "\n******** Generating postscript file 'gnuplot_test1.ps' ********\n" + print("\n******** Generating postscript file 'gnuplot_test1.ps' ********\n") g2.hardcopy('gnuplot_test_plot.ps', color=1) # Demonstrate a 3-d plot: @@ -1028,16 +1028,16 @@ if __name__ == '__main__': # Enable the following code to test the old-style gnuplot interface if 0: - # List of (x, y) pairs - plot([(0.,1),(1.,5),(2.,3),(3.,4)]) + # List of (x, y) pairs + plot([(0.,1),(1.,5),(2.,3),(3.,4)]) - # List of y values, file output - print "\n Generating postscript file 'gnuplot_test2.ps'\n" - plot([1, 5, 3, 4], file='gnuplot_test2.ps') + # List of y values, file output + print("\n Generating postscript file 'gnuplot_test2.ps'\n") + plot([1, 5, 3, 4], file='gnuplot_test2.ps') - # Two plots; each given by a 2d array - x = arange(10, typecode=Float) - y1 = x**2 - y2 = (10-x)**2 - plot(transpose(array([x, y1])), transpose(array([x, y2]))) + # Two plots; each given by a 2d array + x = arange(10, typecode=Float) + y1 = x**2 + y2 = (10-x)**2 + plot(transpose(array([x, y1])), transpose(array([x, y2]))) diff --git a/contrib/python/Xrtdb.py b/contrib/python/Xrtdb.py index 4a3c54c8b9..93b80c0edf 100644 --- a/contrib/python/Xrtdb.py +++ b/contrib/python/Xrtdb.py @@ -7,6 +7,12 @@ DBL = 1013 from Tkinter import * import signal +from SimpleDialog import * +import tkSimpleDialog +import os +import string +import types + class Xrtdb: def __init__(self): @@ -72,8 +78,6 @@ class Xrtdb: # end def __init__ def new(self): - from SimpleDialog import * - import tkSimpleDialog self.selection_clear() @@ -107,8 +111,7 @@ class Xrtdb: # end def new def edit(self): - from SimpleDialog import * - + try: name = self.selection_value() except: @@ -156,7 +159,7 @@ class Xrtdb: # end def delete def help(self): - from SimpleDialog import * + dialog = SimpleDialog(self.root, text="Quit \t- immediately exits.\n" "Delete \t- deletes selected entry.\n" @@ -213,14 +216,12 @@ class Xrtdb: # end def set_text def edit_tmpfile(self): - import os if (os.system('emacs xrtdbtmp.txt')): raise "Edit failed" # end if # end def edit_tmpfile def delete_tmpfile(self): - import os try: os.remove('xrtdbtmp.txt') except: @@ -228,8 +229,7 @@ class Xrtdb: # end try # end def delete_tmpfile - def write_tmpfile(self, values, ma_type): - import types +def write_tmpfile(self, values, ma_type): tmpfile = open('xrtdbtmp.txt','w+') if (type(values) == type([])): for value in values: @@ -241,8 +241,7 @@ class Xrtdb: tmpfile.close() # end def write_tmpfile - def read_tmpfile(self, ma_type): - import string +def read_tmpfile(self, ma_type): result = [] tmpfile = open('xrtdbtmp.txt','r') @@ -271,8 +270,8 @@ class Xrtdb: return result # end def read_tmpfile - def process_tmpfile(self, name, ma_type, isnew): - from SimpleDialog import * +def process_tmpfile(self, name, ma_type, isnew): + # Edit tmpfile # Prompt for saving changes # Try to read the results @@ -302,75 +301,74 @@ class Xrtdb: except NWChemError: self.set_text("%s save failed!" % name) # end try - if (isnew): + if (isnew): # end if # end if # end def process_tmpfile - n = 0 - try: - while (name > self.listbox.get(n)): - n = n + 1 - # end while - except: - pass - # end try - self.listbox.insert(n,name) - self.listbox.see(n) + n = 0 + try: + while (name > self.listbox.get(n)): + n = n + 1 + # end while + except: + pass + # end try + self.listbox.insert(n,name) + self.listbox.see(n) else: - self.set_text("%s nothing saved" % name) + self.set_text("%s nothing saved" % name) self.selection_clear() - def value_to_string(self,value,ma_type): +def value_to_string(self,value,ma_type): if (ma_type == INT): - return "%d" % value + return "%d" % value elif (ma_type == DBL): - return "%21.15e" % value + return "%21.15e" % value elif (ma_type == LOGICAL): - if (value): - return "true" - else: - return "false" + if (value): + return "true" + else: + return "false" # end if elif (ma_type == 1000): # since Tk overwrites defn of CHAR - return value + return value else: - return value + return value # end if # end def value_to_string - def string_to_value(self,value,ma_type): - import string +def string_to_value(self,value,ma_type): if (ma_type == INT): - return string.atoi(value) + return string.atoi(value) elif (ma_type == DBL): - return string.atof(value) + return string.atof(value) elif (ma_type == LOGICAL): - if (value == "true"): - return 1 - elif (value == "false"): - return 0 - else: - raise NWChemError,'invalid value' + if (value == "true"): + return 1 + elif (value == "false"): + return 0 + else: + raise NWChemError('invalid value') # end if elif (ma_type == 1000): # since Tk overwrites defn of CHAR return value else: - raise NWChemError,'invalid type' + raise NWChemError('invalid type') # end if # end def string_to_value - def ma_type_name(self, ma_type): +def ma_type_name(self, ma_type): if (ma_type == INT): - return "int" + return "int" elif (ma_type == DBL): - return "double" + return "double" elif (ma_type == LOGICAL): - return "logical" + return "logical" elif (ma_type == 1000): # since Tk overwrites defn of CHAR - return "char" + return "char" else: - raise NWChemError,'invalid type' + raise NWChemError('invalid type') # end if # end def ma_type_name # end class Xrtdb diff --git a/contrib/python/dplot.py b/contrib/python/dplot.py index 729743a130..865e0e5841 100644 --- a/contrib/python/dplot.py +++ b/contrib/python/dplot.py @@ -68,10 +68,10 @@ class Cube: fac = 0.999999999999999 ix, iy, iz = int((x-self.r0[0])*fac/self.dx), int((y-self.r0[1])*fac/self.dy), int((z-self.r0[2])*fac/self.dz) if ix<0 or ix>=(self.Nx-1) or iy<0 or iy>=(self.Ny-1) or iz<0 or iz>=(self.Nz-1): - print "Trying to find containing box for point out of bounds" - print "point", (x,y,z) - print "lower", self.r0 - print "upper", self.r1 + print("Trying to find containing box for point out of bounds") + print("point", (x,y,z)) + print("lower", self.r0) + print("upper", self.r1) raise IndexError return ix, iy, iz @@ -79,7 +79,7 @@ class Cube: ''' Linear interpolation in 1D ... [xlo---x---xhi] ''' if (xlo-x)>self.eps or (x-xhi)>self.eps: - print "linear_1d: extrapolating! (x, xlo, xhi):", x, xlo, xhi + print("linear_1d: extrapolating! (x, xlo, xhi):", x, xlo, xhi) raise IndexError return flo + (fhi-flo)*(x-xlo)/(xhi-xlo) @@ -160,8 +160,8 @@ def load_gaussian(filename): maxval = max(maxval,abs(value)) c[(ix,iy,iz)] = value except: - print line - print n + print(line) + print(n) raise IndexError n = n + 1 if n == 6: @@ -187,13 +187,13 @@ if __name__ == "__main__": # print the interpolated function and error out along a line dx,dy,dz = (r1[0]-r0[0])/10, (r1[1]-r0[1])/10, (r1[2]-r0[2])/10, - print " x y z exact interp error" - print "------ ------ ------ ---------- ---------- ----------" + print(" x y z exact interp error") + print("------ ------ ------ ---------- ---------- ----------") for i in range(11): x,y,z = r0[0]+i*dx, r0[1]+i*dy, r0[2]+i*dz numeric = c.interp(x,y,z) exact = testfun(x,y,z) - print "%6.2f %6.2f %6.2f %10.6f %10.6f %10.2e" % (x,y,z,exact,numeric,exact-numeric) + print("%6.2f %6.2f %6.2f %10.6f %10.6f %10.2e" % (x,y,z,exact,numeric,exact-numeric)) test() diff --git a/contrib/python/mathutil.py b/contrib/python/mathutil.py index d824a36bb9..8f4c0e8f59 100644 --- a/contrib/python/mathutil.py +++ b/contrib/python/mathutil.py @@ -74,7 +74,7 @@ def printvector(a): n = len(a) for i in range(n): print ("%12.5e "%a[i]), - print " " + print(" ") def printmatrix(a): n = len(a) @@ -152,10 +152,10 @@ def quadratic_step(trust, g0, h0): if h0 > 0: delta2 = -g0/h0 if abs(delta2) > trust: - print " Step restriction: %f %f " % (delta2, trust) + print(" Step restriction: %f %f " % (delta2, trust)) delta2 = abs(trust*delta2)/delta2 else: - print " Negative curvature " + print(" Negative curvature ") delta2 = -abs(trust*g0)/g0 return delta2 @@ -169,26 +169,24 @@ def linesearch(func, x0, s, lsgrad, eps): # bracketed the minimum or gone downhil with enough # energy difference to start fitting - print " Line search: step alpha grad hess value" - print " ---- --------- -------- -------- ----------------" + print(" Line search: step alpha grad hess value") + print(" ---- --------- -------- -------- ----------------") trust = 0.2 alpha0 = 0.0 f0 = func(x0) - print " %9.2e %8.1e %16.8f" % \ - (alpha0, lsgrad, f0) + print(" %9.2e %8.1e %16.8f" % (alpha0, lsgrad, f0)) if lsgrad < 0: alpha1 = alpha0 + trust else: alpha1 = alpha0 - trust f1 = func(takestep(x0,s,alpha1)) - print " %9.2e %16.8f" % \ - (alpha1, f1) + print(" %9.2e %16.8f" % (alpha1, f1)) while f1 > f0: if trust < 0.00125: - print " system is too badly conditioned for initial step" + print(" system is too badly conditioned for initial step") return (alpha0,f0) # Cannot seem to find my way trust = trust * 0.5 if lsgrad < 0: @@ -196,8 +194,7 @@ def linesearch(func, x0, s, lsgrad, eps): else: alpha1 = alpha0 - trust f1 = func(takestep(x0,s,alpha1)) - print " %9.2e %16.8f" % \ - (alpha1, f1) + print(" %9.2e %16.8f" % (alpha1, f1)) g0 = lsgrad h0 = (f1-f0-alpha1*g0)/alpha1**2 @@ -217,21 +214,20 @@ def linesearch(func, x0, s, lsgrad, eps): if iter == 1: f2prev = f2 - print " %9.2e %16.8f" % \ - (alpha2, f2) + print(" %9.2e %16.8f" % (alpha2, f2)) # Check for convergence or insufficient precision to proceed further if (abs(f0-f1)<(10*eps)) and (abs(f1-f2)<(10*eps)): - print " ", - print " Insufficient precision ... terminating LS" + print(" ") + print(" Insufficient precision ... terminating LS") break if (f2-f2prev) > 0: # New point is higher than previous worst if nbackstep < 3: nbackstep = nbackstep + 1 - print " ", - print " Back stepping due to uphill step" + print(" ") + print(" Back stepping due to uphill step") trust = max(0.01,0.2*abs(alpha2 - alpha0)) # Reduce trust radius alpha2 = alpha0 + 0.2*(alpha2 - alpha0) continue @@ -251,12 +247,11 @@ def linesearch(func, x0, s, lsgrad, eps): alpha1, alpha2, f1, f2 = alpha2, alpha1, f2, f1 (f0, g0, h0) = quadfit(alpha0, f0, alpha1, f1, alpha2, f2) - print " %4i %9.2e %8.1e %8.1e %16.8f" % \ - (iter, alpha0, g0, h0, f0) + print(" %4i %9.2e %8.1e %8.1e %16.8f" %(iter, alpha0, g0, h0, f0)) if (h0>0.0) and (abs(g0) < 0.03*abs(lsgrad)): - print " ", - print " gradient reduced 30-fold ... terminating LS" + print(" ") + print(" gradient reduced 30-fold ... terminating LS") break # Determine the next step @@ -264,8 +259,8 @@ def linesearch(func, x0, s, lsgrad, eps): alpha2 = alpha0 + delta df = g0*delta + 0.5*h0*delta*delta if abs(df) < 10.0*eps: - print " ", - print " projected energy reduction < 10*eps ... terminating LS" + print(" ") + print(" projected energy reduction < 10*eps ... terminating LS") break @@ -404,7 +399,7 @@ def hessian_update_bfgs(hp, dx, g, gp): for j in range(n): h[i][j] = h[i][j] + dg[i]*dg[j]/dxdg - hdx[i]*hdx[j]/dxhdx else: - print ' BFGS not updating dxdg (%e), dgdg (%e), dxhdx (%f), dxdx(%e)' % (dxdg, dgdg, dxhdx, dxdx) + print(' BFGS not updating dxdg (%e), dgdg (%e), dxhdx (%f), dxdx(%e)' % (dxdg, dgdg, dxhdx, dxdx)) return h @@ -442,16 +437,16 @@ def quasinr(func, guess, tol, eps, printvar=None): (value,g,h) = numderiv(func, x, step, eps) gmax = max(map(abs,g)) - print ' ' - print ' iter gmax value ' - print ' ---- --------- ----------------' - print "%4i %9.2e %16.8f" % (iter,gmax,value) + print(' ') + print(' iter gmax value ') + print(' ---- --------- ----------------') + print("%4i %9.2e %16.8f" % (iter,gmax,value)) if (printvar): printvar(x) if gmax < tol: - print ' Converged!' + print(' Converged!') break if iter == 0: @@ -463,14 +458,14 @@ def quasinr(func, guess, tol, eps, printvar=None): (v,e) = jacobi(hessian) emax = max(map(abs,e)) emin = emax*1e-4 # Control noise in small eigenvalues - print '\n Eigenvalues of the Hessian:' + print('\n Eigenvalues of the Hessian:') printvector(e) # Transform to spectral form, take step, transform back gs = mxv(v,g) for i in range(n): if e[i] < emin: - print ' Mode %d: small/negative eigenvalue (%f).' % (i, e[i]) + print(' Mode %d: small/negative eigenvalue (%f).' % (i, e[i])) s[i] = -gs[i]/emin else: s[i] = -gs[i]/e[i] @@ -481,8 +476,7 @@ def quasinr(func, guess, tol, eps, printvar=None): for i in range(n): trust = max(abs(x[i]),abs(x[i]/sqrt(max(1e-4,abs(hessian[i][i]))))) if abs(s[i]) > trust: - print ' restricting ', i, trust, abs(x[i]), \ - abs(x[i]/sqrt(abs(hessian[i][i]))), s[i] + print(' restricting ', i, trust, abs(x[i]), abs(x[i]/sqrt(abs(hessian[i][i]))), s[i]) scale = min(scale,trust/abs(s[i])) if scale != 1.0: for i in range(n): @@ -491,7 +485,7 @@ def quasinr(func, guess, tol, eps, printvar=None): (alpha,value) = linesearch(func, x, s, dot(s,g), eps) if alpha == 0.0: - print ' Insufficient precision to proceed further' + print(' Insufficient precision to proceed further') break for i in range(n): @@ -516,13 +510,13 @@ def cgminold(func, dfunc, guess, tol): g = dfunc(x) gmax = max(map(abs,g)) - print ' ' - print ' iter gmax value ' - print ' ---- --------- ----------------' - print "%4i %9.2e %16.8f" % (iter,gmax,value) + print(' ') + print(' iter gmax value ') + print(' ---- --------- ----------------') + print("%4i %9.2e %16.8f" % (iter,gmax,value)) if gmax < tol: - print ' Converged!' + print(' Converged!') break if (iter == 0) or ((iter%20) == 0): @@ -563,13 +557,13 @@ def cgmin(func, dfunc, guess, tol, precond=None, reset=None): g = dfunc(x) gmax = max(map(abs,g)) - print ' ' - print ' iter gmax value ' - print ' ---- --------- ----------------' - print "%4i %9.2e %16.8f" % (iter,gmax,value) + print(' ') + print(' iter gmax value ') + print(' ---- --------- ----------------') + print("%4i %9.2e %16.8f" % (iter,gmax,value)) if gmax < tol: - print ' Converged!' + print(' Converged!') break if precond: @@ -637,16 +631,16 @@ def cgmin2(func, guess, tol, eps, printvar=None,reset=None): (value,g,hh) = numderiv(func, x, step, eps) gmax = max(map(abs,g)) - print ' ' - print ' iter gmax value ' - print ' ---- --------- ----------------' - print "%4i %9.2e %16.8f" % (iter,gmax,value) + print(' ') + print(' iter gmax value ') + print(' ---- --------- ----------------') + print("%4i %9.2e %16.8f" % (iter,gmax,value)) if (printvar): printvar(x) if gmax < tol: - print ' Converged!' + print(' Converged!') break if (iter % reset) == 0: @@ -664,7 +658,7 @@ def cgmin2(func, guess, tol, eps, printvar=None,reset=None): # means that we don't have enough info. if (iter % reset) == 0: if iter != 0: - print" Resetting conjugacy" + print(" Resetting conjugacy") beta = 0.0 else: beta = (dot(precondg,g) - dot(precondg,gp))/(dot(s,g)-dot(s,gp)) @@ -677,12 +671,12 @@ def cgmin2(func, guess, tol, eps, printvar=None,reset=None): if alpha == 0.0: # LS failed, probably due to lack of precision. if beta != 0.0: - print "LS failed - trying preconditioned steepest descent direction" + print("LS failed - trying preconditioned steepest descent direction") for i in range(n): s[i] = -g[i] (alpha,value) = linesearch(func, x, s, dot(s,g), eps) if alpha == 0.0: - print " Insufficient precision to proceed further" + print(" Insufficient precision to proceed further") break for i in range(n): @@ -719,22 +713,22 @@ if __name__ == '__main__': return sum - print '\n\n TESTING QUASI-NR SOLVER \n\n' + print('\n\n TESTING QUASI-NR SOLVER \n\n') quasinr(f, [1.,0.5,0.3,-0.4], 1e-4, 1e-10) - print '\n\n TESTING GC WITH NUM. GRAD. AND DIAG. PRECOND.\n\n' + print('\n\n TESTING GC WITH NUM. GRAD. AND DIAG. PRECOND.\n\n') cgmin2(f, [1.,0.5,0.3,-0.4], 1e-4, 1e-10, reset=20) - print '\n\n TESTING GC WITH ANAL. GRAD. AND WITHOUT OPTIONAL PRECOND.\n\n' + print('\n\n TESTING GC WITH ANAL. GRAD. AND WITHOUT OPTIONAL PRECOND.\n\n') cgmin(f, df, [1.,0.5,0.3,-0.4], 1e-4) - print '\n\n TESTING GC WITH ANAL. GRAD. AND WITH OPTIONAL PRECOND.\n\n' + print('\n\n TESTING GC WITH ANAL. GRAD. AND WITH OPTIONAL PRECOND.\n\n') cgmin(f, df, [1.,0.5,0.3,-0.4], 1e-4, precond=precond) - print '\n\n TESTING GC WITH ANAL. GRAD. AND NO PRECOND.\n\n' + print('\n\n TESTING GC WITH ANAL. GRAD. AND NO PRECOND.\n\n') cgminold(f, df, [1.,0.5,0.3,-0.4], 1e-4) - print '\n\n TESTING JACOBI EIGENSOLVER\n\n' + print('\n\n TESTING JACOBI EIGENSOLVER\n\n') n = 50 a = zeromatrix(n,n) for i in range(n): @@ -743,7 +737,7 @@ if __name__ == '__main__': (v,e)= jacobi(a) - print ' eigenvalues' + print(' eigenvalues') printvector(e) #print ' v ' #printmatrix(v) @@ -754,4 +748,4 @@ if __name__ == '__main__': err = max(err,abs(ev[i][j] - e[i]*v[i][j])) err = err/(n*max(1.0,abs(e[i]))) if err > 1e-12: - print ' Error in eigenvector ', i, err + print(' Error in eigenvector ', i, err) diff --git a/contrib/python/nwchem_tddft_spectrum.py b/contrib/python/nwchem_tddft_spectrum.py index cf443d163d..08c49d2076 100755 --- a/contrib/python/nwchem_tddft_spectrum.py +++ b/contrib/python/nwchem_tddft_spectrum.py @@ -159,10 +159,10 @@ if __name__ == '__main__': kwargs['plot_triplet'] = False kwargs['plot_unrestricted'] = True if key == '-h': - print __doc__ + print(__doc__) sys.exit() if len(args) == 0: - print __doc__ + print(__doc__) sys.exit() for fname in args: nwchem_tddft_spectrum(fname,**kwargs) diff --git a/contrib/python/office.py b/contrib/python/office.py index ee40f6d751..76601914e2 100755 --- a/contrib/python/office.py +++ b/contrib/python/office.py @@ -239,8 +239,7 @@ class Excel: try: charttype = charttypes[charttype] except KeyError: - print 'Excel.chartSelectedRange: Unkown charttype', charttype, \ - ' defaulting to XY' + print('Excel.chartSelectedRange: Unkown charttype', charttype, ' defaulting to XY') charttype = charttypes['xy'] # Make the chart and set how the data will be interpreted @@ -254,8 +253,7 @@ class Excel: elif plotby == 'columns': self.xlApp.ActiveChart.PlotBy = xlColumns else: - print 'Excel.chartSelectedRange: Unknown plotby', charttype, \ - ' defaulting to columns' + print('Excel.chartSelectedRange: Unknown plotby', charttype, ' defaulting to columns') self.xlApp.ActiveChart.PlotBy = xlColumns # Set the title and axis labels @@ -329,7 +327,7 @@ class Excel: if absrow: ar = '$' if abscol: ac = '$' if col < 1 or col > 256: - raise RangeError, 'column index must be in [1,256]' + raise RangeError('column index must be in [1,256]') (c1,c2) = divmod(col-1,26) if c1: c = uppercase[c1] + uppercase[c2] @@ -368,21 +366,21 @@ if __name__ == "__main__": import time # Make a worksheet and test set/getCell xls = Excel() - print ' Setting cell(2,2) to "Hi"' + print(' Setting cell(2,2) to "Hi"') xls.setCell("Hi", 2, 2) - print xls.getCell(2,2) - print ' Setting cell(1,2) to "(1,2)"' + print(xls.getCell(2,2)) + print(' Setting cell(1,2) to "(1,2)"') xls.setCell("(1,2)", 1, 2) - print ' Setting cell(2,1) to "(1,2)"' + print(' Setting cell(2,1) to "(1,2)"') xls.setCell("(2,1)", 2, 1) xls.visible() # Test setting a range to a scalar and getting contiguous range - print ' Setting 9,1,12,2 to 0' + print(' Setting 9,1,12,2 to 0') xls.setRange(0,9,1,12,2) - print ' Getting same contiguous range back ... expecting matrix(4,2)=0' + print(' Getting same contiguous range back ... expecting matrix(4,2)=0') value = xls.getContiguousRange(9,1) - print value + print(value) # Test setting/getting a range from/to a matrix n = 3 @@ -392,12 +390,12 @@ if __name__ == "__main__": x[i] = [0]*m for j in range(m): x[i][j] = i + j - print ' Setting range (3:,4:) to ' - print x + print(' Setting range (3:,4:) to ') + print(x) xls.setRange(x,3,4) # Auto determination of the bottom corner - print ' Got back from same range ',3,3,3+n-1,4+m-1 + print(' Got back from same range ',3,3,3+n-1,4+m-1) y = xls.getRange(3,4,3+n-1,4+m-1) - print y + print(y) # Add names for the series that will eventually become the chart names = [] @@ -406,7 +404,7 @@ if __name__ == "__main__": xls.setRange(names,2,4) # Test selecting a range - print ' Selecting range ', 3,3,3+n-1,4+m-1 + print(' Selecting range ', 3,3,3+n-1,4+m-1) xls.selectRange(3,4,3+n-1,4+m-1) # Test general matrix @@ -420,7 +418,7 @@ if __name__ == "__main__": # Test making an x-y plot just from the data ... use a # second sheet and the simple chart interface - print ' Creating chart of sin(x) and cos(x) using second sheet' + print(' Creating chart of sin(x) and cos(x) using second sheet') n = 20 m = 3 h = 2*pi/(n-1) @@ -435,26 +433,22 @@ if __name__ == "__main__": # Use absolute values for the rows but not the columns to test # reuse of the formula. formula = '=sum('+xls.a1(2,2,absrow=1)+':'+xls.a1(21,2,absrow=1)+')' - print ' The formula is ', formula + print(' The formula is ', formula) xls.setCell('Total',23,1,sheet=2) xls.setCell(formula,23,2,sheet=2) xls.setCell(formula,23,3,sheet=2) # Getting the cell contents back will get the value not the formula - print ' The formula from the sheet is ', xls.getCellFormula(23,2,sheet=2) - print ' The value of the formula (sum of sin) is ', \ - xls.getCell(23,2,sheet=2) - print ' The formula from where there is only the value "Total" is', \ - xls.getCellFormula(23,1,sheet=2) - print ' The formula from where there is nothing ',\ - xls.getCellFormula(23,4,sheet=2) - print ' The value from where there is nothing ',\ - xls.getCell(23,4,sheet=2) + print(' The formula from the sheet is ', xls.getCellFormula(23,2,sheet=2)) + print(' The value of the formula (sum of sin) is ', xls.getCell(23,2,sheet=2)) + print(' The formula from where there is only the value "Total" is', xls.getCellFormula(23,1,sheet=2)) + print(' The formula from where there is nothing ', xls.getCellFormula(23,4,sheet=2)) + print(' The value from where there is nothing ', xls.getCell(23,4,sheet=2)) # Make a surface plot by creating a 2-D grid bordered on the # left and top with strings to indicate the values. Note the # use of a single quote before the value in the labels in # order to force Excel to treat them as strings. - print ' Create surface chart of exp(-0.1*r*r)*cos(1.3*r)' + print(' Create surface chart of exp(-0.1*r*r)*cos(1.3*r)') n = 10 h = 2*pi/(n-1) data = range(n+1) @@ -487,7 +481,7 @@ if __name__ == "__main__": xls.setRange(data,1,5,sheet=2) # Finally make a chart with all options set - print ' Creating chart of sin(x) and cos(x) using second sheet' + print(' Creating chart of sin(x) and cos(x) using second sheet') n = 81 data = range(n+1) data[0] = ['Age', 'Wisdom'] diff --git a/contrib/python/pes_scan.py b/contrib/python/pes_scan.py index a9a9ef5d10..b21ca499f7 100644 --- a/contrib/python/pes_scan.py +++ b/contrib/python/pes_scan.py @@ -50,21 +50,21 @@ def pes_scan(input,start,end,nstep,theory,task): results = [] if (len(start) != len(end)): - raise NWChemError,'pes_scan: inconsistent #parameters' + raise NWChemError('pes_scan: inconsistent #parameters') npoint = (nstep+1)**len(start) if (ga_nodeid() == 0): - print ' ' - print ' Doing a PES Scan on input ' - print ' -------------------------' - print ' ' - print input - print ' ' - print ' Number of points ', npoint - print ' Minimum values ', start - print ' Maximum values ', end - print ' ' + print(' ') + print(' Doing a PES Scan on input ') + print(' -------------------------') + print(' ') + print(input) + print(' ') + print(' Number of points ', npoint) + print(' Minimum values ', start) + print(' Maximum values ', end) + print(' ') step = [] for i in range (0, len(start)): @@ -102,28 +102,28 @@ def pes_scan(input,start,end,nstep,theory,task): if (ga_nodeid() == 0): - print ' ' - print ' Scanning NWChem input - point %d of %d ' % (i+1,npoint) - print ' ' - print input % tuple(new) - print ' ' + print(' ') + print(' Scanning NWChem input - point %d of %d ' % (i+1,npoint)) + print(' ') + print(input % tuple(new)) + print(' ') input_parse(input % tuple(new)) result = task(theory) if (ga_nodeid() == 0): - print ' ' - print ' Scanning NWChem input - results from point ', i+1 - print ' ' - print result - print ' ' + print(' ') + print(' Scanning NWChem input - results from point ', i+1) + print(' ') + print(result) + print(' ') results.append((new,result)); if (ga_nodeid() == 0): - print ' ' - print ' Python Scan Output ' - print ' ' + print(' ') + print(' Python Scan Output ') + print(' ') for i in range(0,len(results)): - print results[i][0], results[i][1] - print ' ' - print ' Python Scan Output Finished ' + print(results[i][0], results[i][1]) + print(' ') + print(' Python Scan Output Finished ') return tuple(results)