diff --git a/examples/ELASTIC/compliance.py b/examples/ELASTIC/compliance.py index 6ef35be553..47f680abb4 100755 --- a/examples/ELASTIC/compliance.py +++ b/examples/ELASTIC/compliance.py @@ -1,13 +1,14 @@ #!/usr/bin/env python # This file reads in the file log.lammps generated by the script ELASTIC/in.elastic -# It prints out the 6x6 tensor of elastic constants Cij +# It prints out the 6x6 tensor of elastic constants Cij # followed by the 6x6 tensor of compliance constants Sij # It uses the same conventions as described in: -# Sprik, Impey and Klein PRB (1984). +# Sprik, Impey and Klein PRB (1984). # The units of Cij are whatever was used in log.lammps (usually GPa) # The units of Sij are the inverse of that (usually 1/GPa) +from __future__ import print_function from numpy import zeros from numpy.linalg import inv @@ -44,9 +45,8 @@ cindices[20] = (4,5) # open logfile -logfile = open("log.lammps",'r') - -txt = logfile.read() +with open("log.lammps",'r') as logfile: + txt = logfile.read() # search for 21 elastic constants @@ -56,7 +56,7 @@ s2 = 0 for ival in range(nvals): s1 = txt.find(valstr,s2) if (s1 == -1): - print "Failed to find elastic constants in log file" + print("Failed to find elastic constants in log file") exit(1) s1 += 1 s2 = txt.find("\n",s1) @@ -67,18 +67,18 @@ for ival in range(nvals): c[i1,i2] = float(words[valpos]) c[i2,i1] = c[i1,i2] -print "C tensor [GPa]" +print("C tensor [GPa]") for i in range(6): for j in range(6): - print "%10.8g " % c[i][j], - print - + print("%10.8g " % c[i][j], end="") + print() + # apply factor of 2 to columns of off-diagonal elements for i in range(6): for j in range(3,6): c[i][j] *= 2.0 - + s = inv(c) # apply factor of 1/2 to columns of off-diagonal elements @@ -86,10 +86,9 @@ s = inv(c) for i in range(6): for j in range(3,6): s[i][j] *= 0.5 - -print "S tensor [1/GPa]" + +print("S tensor [1/GPa]") for i in range(6): for j in range(6): - print "%10.8g " % s[i][j], - print - + print("%10.8g " % s[i][j], end="") + print()