From 87c3f19104ccc8a974be72f96df2c2be92ff8921 Mon Sep 17 00:00:00 2001 From: Eric Hermes Date: Mon, 8 Oct 2018 12:34:53 -0700 Subject: [PATCH] Make more examples Python 3 compatible --- contrib/python/basopt.nw | 8 +++++--- contrib/python/basopt2.nw | 7 ++++--- contrib/python/basopt3.nw | 10 ++++++---- contrib/python/basopt4.nw | 19 ++++++++++--------- contrib/python/bpy.nw | 3 ++- contrib/python/coulombfitting.XF.mol.nw | 24 +++++++++++++----------- contrib/python/coulombfitting.XH.mol.nw | 23 ++++++++++++----------- contrib/python/coulombfitting.atom.nw | 23 ++++++++++++----------- contrib/python/hcn.nw | 5 +++-- contrib/python/isodesmic.nw | 3 ++- contrib/python/nh3.nw | 5 +++-- contrib/python/scanexp.nw | 3 ++- 12 files changed, 74 insertions(+), 59 deletions(-) diff --git a/contrib/python/basopt.nw b/contrib/python/basopt.nw index 60d3c4f831..495027291d 100644 --- a/contrib/python/basopt.nw +++ b/contrib/python/basopt.nw @@ -19,6 +19,8 @@ end print none python noprint + from __future__ import print_function + from mathutil import * # It should only be necessary to modify these three lines for @@ -38,12 +40,12 @@ python noprint return task_energy(theory) def printexp(z): - print "\n Exponents:" + print("\n Exponents:") for i in range(len(z)): print " %14.8f" % (z[i]*z[i]), if ((i+1)%5) == 0: - print "" - print " " + print("") + print(" ") z = array('d',exponents) for i in range(len(z)): diff --git a/contrib/python/basopt2.nw b/contrib/python/basopt2.nw index f35d07ffff..f15a52326b 100644 --- a/contrib/python/basopt2.nw +++ b/contrib/python/basopt2.nw @@ -23,6 +23,7 @@ set int:acc_std 1e-25 print none python noprint + from __future__ import print_function from mathutil import * # It should only be necessary to modify these three lines for @@ -62,12 +63,12 @@ python noprint return task_energy(theory) def printexp(z): - print "\n Exponents:" + print("\n Exponents:") for i in range(len(z)): print " %14.8f" % (z[i]*z[i]), if ((i+1)%5) == 0: - print "" - print " " + print("") + print(" ") z = array('d',exponents) for i in range(len(z)): diff --git a/contrib/python/basopt3.nw b/contrib/python/basopt3.nw index acd45d6430..75ae288f5d 100644 --- a/contrib/python/basopt3.nw +++ b/contrib/python/basopt3.nw @@ -24,6 +24,8 @@ set int:acc_std 1e-25 print none python noprint + from __future__ import print_function + from mathutil import * # It should only be necessary to modify these three lines for @@ -74,12 +76,12 @@ python noprint return task_energy(theory) def printexp(z): - print "\n Exponents:" + print("\n Exponents:") for i in range(len(z)): - print " %14.8f" % (z[i]*z[i]), + print(" %14.8f" % (z[i]*z[i]),) if ((i+1)%5) == 0: - print "" - print " " + print("") + print(" ") z = array('d',exponents) for i in range(len(z)): diff --git a/contrib/python/basopt4.nw b/contrib/python/basopt4.nw index 7713a8f0f5..ea35d5e1c1 100644 --- a/contrib/python/basopt4.nw +++ b/contrib/python/basopt4.nw @@ -25,6 +25,7 @@ set int:acc_std 1e-25 print none python + from __future__ import print_function from mathutil import * n = 6 @@ -56,13 +57,13 @@ python def printexp(z): exponents = make_exp(z) - print '\n alpha %f beta %f' % (z[0]*z[0],z[1]*z[1]) - print ' Exponents:' + print('\n alpha %f beta %f' % (z[0]*z[0],z[1]*z[1])) + print(' Exponents:') for i in range(n): - print " %14.8f" % exponents[i], + print(" %14.8f" % exponents[i],) if ((i+1)%5) == 0: - print "" - print " " + print("") + print(" ") z = zerovector(2) z[0] = sqrt(alpha - 0.001) @@ -73,13 +74,13 @@ python (value,z) = quasinr(energy, z, 1e-4, 1e-9, printexp) (alpha, beta) = make_alpha_beta(z) results[n] = (alpha, beta, value) - print '\n\n Results\n' - print ' n alpha beta energy error ' - print ' --- --------- --------- ------------ -----------' + print('\n\n Results\n') + print(' n alpha beta energy error ') + print(' --- --------- --------- ------------ -----------') (alpha, beta, limit) = results[20] for n in range(2,21): (alpha, beta, value) = results[n] - print '%4i %10.6f %10.6f %12.6f %12.6f' % (n, alpha, beta, value, value-limit) + print('%4i %10.6f %10.6f %12.6f %12.6f' % (n, alpha, beta, value, value-limit)) end task python diff --git a/contrib/python/bpy.nw b/contrib/python/bpy.nw index c82982334b..4df0242721 100644 --- a/contrib/python/bpy.nw +++ b/contrib/python/bpy.nw @@ -13,6 +13,7 @@ mp2; tight; freeze core atomic; end #print low python noprint +from __future__ import print_function supermolecule = 'geometry noprint; N 13.356 -4.360 16.307;H 12.631 -4.575 16.716;N 11.384 -5.455 18.225;C 10.267 -4.749 18.620 ; end\n' fragment1 = 'geometry noprint; N 13.356 -4.360 16.307;H 12.631 -4.575 16.716;bqN 11.384 -5.455 18.225;bqC 10.267 -4.749 18.620; end\n' fragment2 = 'geometry noprint; bqN 13.356 -4.360 16.307;bqH 12.631 -4.575 16.716;N 11.384 -5.455 18.225;C 10.267 -4.749 18.620; end\n' @@ -31,7 +32,7 @@ def bsse_energy(): e = bsse_energy() if (ga_nodeid() == 0): - print ' BSSE energy (hartrees) = %10.7f ' % (e) + print(' BSSE energy (hartrees) = %10.7f ' % (e)) end task python diff --git a/contrib/python/coulombfitting.XF.mol.nw b/contrib/python/coulombfitting.XF.mol.nw index f114890b19..f0a1dcf726 100644 --- a/contrib/python/coulombfitting.XF.mol.nw +++ b/contrib/python/coulombfitting.XF.mol.nw @@ -38,6 +38,8 @@ set int:acc_std 1e-25 print none python + from __future__ import print_function + from mathutil import * run_type = "scf" @@ -129,13 +131,13 @@ python def printexp(z): function_type = ["s", "p", "d", "f", "g", "h", "i"] exponents = make_exp(z) - print ' Exponents:' + print(' Exponents:') for j in range(0,l+1): - print "%s - functions" % (function_type[j]) + print("%s - functions" % (function_type[j])) for i in range(0,n[j]): - print " %14.8f" % exponents[i][j] - print "" - print " " + print(" %14.8f" % exponents[i][j]) + print("") + print(" ") # Setup list of variables to be optimized @@ -174,14 +176,14 @@ python # Print the final results - print '\n\n Results\n' - print ' l n exp0 beta gamma ' - print ' --- --- --------- --------- --------- ' + print('\n\n Results\n') + print(' l n exp0 beta gamma ') + print(' --- --- --------- --------- --------- ') for j in range(0,l+1): (exp0_n, beta_n, gamma_n) = get_exp0_beta_gamma(z,j) - print '%4i %4i %12.6f %10.6f %10.6f' % (j, n[j], exp0_n, beta_n, gamma_n) - print '\n Final energy difference = %12.6f' % value - print '\n Energy without Coulomb fitting = %12.6f' % reference + print('%4i %4i %12.6f %10.6f %10.6f' % (j, n[j], exp0_n, beta_n, gamma_n)) + print('\n Final energy difference = %12.6f' % value) + print('\n Energy without Coulomb fitting = %12.6f' % reference) printexp(z) end diff --git a/contrib/python/coulombfitting.XH.mol.nw b/contrib/python/coulombfitting.XH.mol.nw index 6ea8b32710..f3563120fe 100644 --- a/contrib/python/coulombfitting.XH.mol.nw +++ b/contrib/python/coulombfitting.XH.mol.nw @@ -38,6 +38,7 @@ set int:acc_std 1e-25 print none python + from __future__ import print_function from mathutil import * run_type = "scf" @@ -129,13 +130,13 @@ python def printexp(z): function_type = ["s", "p", "d", "f", "g", "h", "i"] exponents = make_exp(z) - print ' Exponents:' + print(' Exponents:') for j in range(0,l+1): - print "%s - functions" % (function_type[j]) + print("%s - functions" % (function_type[j])) for i in range(0,n[j]): - print " %14.8f" % exponents[i][j] - print "" - print " " + print(" %14.8f" % exponents[i][j]) + print("") + print(" ") # Setup list of variables to be optimized @@ -174,14 +175,14 @@ python # Print the final results - print '\n\n Results\n' - print ' l n exp0 beta gamma ' - print ' --- --- --------- --------- --------- ' + print('\n\n Results\n') + print(' l n exp0 beta gamma ') + print(' --- --- --------- --------- --------- ') for j in range(0,l+1): (exp0_n, beta_n, gamma_n) = get_exp0_beta_gamma(z,j) - print '%4i %4i %12.6f %10.6f %10.6f' % (j, n[j], exp0_n, beta_n, gamma_n) - print '\n Final energy difference = %12.6f' % value - print '\n Energy without Coulomb fitting = %12.6f' % reference + print('%4i %4i %12.6f %10.6f %10.6f' % (j, n[j], exp0_n, beta_n, gamma_n)) + print('\n Final energy difference = %12.6f' % value) + print('\n Energy without Coulomb fitting = %12.6f' % reference) printexp(z) end diff --git a/contrib/python/coulombfitting.atom.nw b/contrib/python/coulombfitting.atom.nw index 0cbe413f98..61e2d1edd7 100644 --- a/contrib/python/coulombfitting.atom.nw +++ b/contrib/python/coulombfitting.atom.nw @@ -37,6 +37,7 @@ set int:acc_std 1e-25 print none python + from __future__ import print_function from mathutil import * run_type = "scf" @@ -127,13 +128,13 @@ python def printexp(z): function_type = ["s", "p", "d", "f", "g", "h", "i"] exponents = make_exp(z) - print ' Exponents:' + print(' Exponents:') for j in range(0,l+1): - print "%s - functions" % (function_type[j]) + print("%s - functions" % (function_type[j])) for i in range(0,n[j]): - print " %14.8f" % exponents[i][j] - print "" - print " " + print(" %14.8f" % exponents[i][j]) + print("") + print(" ") # Setup list of variables to be optimized @@ -170,14 +171,14 @@ python # Print the final results - print '\n\n Results\n' - print ' l n exp0 beta gamma ' - print ' --- --- --------- --------- --------- ' + print('\n\n Results\n') + print(' l n exp0 beta gamma ') + print(' --- --- --------- --------- --------- ') for j in range(0,l+1): (exp0_n, beta_n, gamma_n) = get_exp0_beta_gamma(z,j) - print '%4i %4i %12.6f %10.6f %10.6f' % (j, n[j], exp0_n, beta_n, gamma_n) - print '\n Final energy difference = %12.6f' % value - print '\n Energy without Coulomb fitting = %12.6f' % reference + print('%4i %4i %12.6f %10.6f %10.6f' % (j, n[j], exp0_n, beta_n, gamma_n)) + print('\n Final energy difference = %12.6f' % value) + print('\n Energy without Coulomb fitting = %12.6f' % reference) printexp(z) end diff --git a/contrib/python/hcn.nw b/contrib/python/hcn.nw index 6b7d63c940..81bc1e6c1f 100644 --- a/contrib/python/hcn.nw +++ b/contrib/python/hcn.nw @@ -19,6 +19,7 @@ scf; print none; end driver; print low; end python + from __future__ import print_function import Gnuplot, time, signal, os from math import * from nwgeom import * @@ -70,8 +71,8 @@ python cn = bond_length(1,2) nh = bond_length(2,3) ch = bond_length(1,3) - print ' angle=%6.1f => cn=%5.3f ch=%5.3f nh=%5.3f energy=%10.6f ' % \ - (angle,cn,ch,nh,energy) + print(' angle=%6.1f => cn=%5.3f ch=%5.3f nh=%5.3f energy=%10.6f ' % \ + (angle,cn,ch,nh,energy)) angle = angle + 180 edata = edata + [[angle,energy]] cndata = cndata + [[angle,cn]] diff --git a/contrib/python/isodesmic.nw b/contrib/python/isodesmic.nw index 69212d5945..3ef5749653 100644 --- a/contrib/python/isodesmic.nw +++ b/contrib/python/isodesmic.nw @@ -5,6 +5,7 @@ mp2; freeze atomic; end print none python + from __future__ import print_function energies = {} c2h4 = ''' @@ -43,7 +44,7 @@ python energies[basis] = 2*energy(basis, ch4) - \ 2*energy(basis, h2) - \ energy(basis, c2h4) - if (ga_nodeid() == 0): print basis, ' %8.6f' % energies[basis] + if (ga_nodeid() == 0): print(basis, ' %8.6f' % energies[basis]) end diff --git a/contrib/python/nh3.nw b/contrib/python/nh3.nw index b0f2193bb3..362208dca9 100644 --- a/contrib/python/nh3.nw +++ b/contrib/python/nh3.nw @@ -12,6 +12,7 @@ end print none python + from __future__ import print_function import Gnuplot, time, signal from math import * @@ -86,7 +87,7 @@ python input_parse(geometry % (angle+90)) (energy,gradient) = task_optimize('scf') r = get_bond_length() - print ' angle=%6.2f bond=%6.3f energy=%10.6f ' % (angle,r,energy) + print(' angle=%6.2f bond=%6.3f energy=%10.6f ' % (angle,r,energy)) energies = energies + [[angle,energy]] bonds = bonds + [[angle,r]] energies.sort() @@ -95,7 +96,7 @@ python g.plot(energies) gr.plot(bonds) - print ' Done!' + print(' Done!') time.sleep(90) # time to look at the plot end diff --git a/contrib/python/scanexp.nw b/contrib/python/scanexp.nw index cfa8d8ad9b..7948ed0dbd 100644 --- a/contrib/python/scanexp.nw +++ b/contrib/python/scanexp.nw @@ -11,13 +11,14 @@ end print none python + from __future__ import print_function from nwgeom import * basis = 'basis noprint; H library 3-21g; O library 3-21g; O d; %f 1.0; end' results = scan_input(basis, [0.5], [0.6], 20, 'scf', task_energy) for (p,e) in results: - print ' Exponent = %7.4f Energy = %10.6f ' % (p[0], e) + print(' Exponent = %7.4f Energy = %10.6f ' % (p[0], e)) end task python