Make compliance.py Python 3 compatible

This commit is contained in:
Richard Berger
2021-06-01 15:15:11 -04:00
parent 6f00e98945
commit 49536ce02c

View File

@ -8,6 +8,7 @@
# The units of Cij are whatever was used in log.lammps (usually GPa) # 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) # The units of Sij are the inverse of that (usually 1/GPa)
from __future__ import print_function
from numpy import zeros from numpy import zeros
from numpy.linalg import inv from numpy.linalg import inv
@ -44,8 +45,7 @@ cindices[20] = (4,5)
# open logfile # open logfile
logfile = open("log.lammps",'r') with open("log.lammps",'r') as logfile:
txt = logfile.read() txt = logfile.read()
# search for 21 elastic constants # search for 21 elastic constants
@ -56,7 +56,7 @@ s2 = 0
for ival in range(nvals): for ival in range(nvals):
s1 = txt.find(valstr,s2) s1 = txt.find(valstr,s2)
if (s1 == -1): if (s1 == -1):
print "Failed to find elastic constants in log file" print("Failed to find elastic constants in log file")
exit(1) exit(1)
s1 += 1 s1 += 1
s2 = txt.find("\n",s1) s2 = txt.find("\n",s1)
@ -67,11 +67,11 @@ for ival in range(nvals):
c[i1,i2] = float(words[valpos]) c[i1,i2] = float(words[valpos])
c[i2,i1] = c[i1,i2] c[i2,i1] = c[i1,i2]
print "C tensor [GPa]" print("C tensor [GPa]")
for i in range(6): for i in range(6):
for j in range(6): for j in range(6):
print "%10.8g " % c[i][j], print("%10.8g " % c[i][j], end="")
print print()
# apply factor of 2 to columns of off-diagonal elements # apply factor of 2 to columns of off-diagonal elements
@ -87,9 +87,8 @@ for i in range(6):
for j in range(3,6): for j in range(3,6):
s[i][j] *= 0.5 s[i][j] *= 0.5
print "S tensor [1/GPa]" print("S tensor [1/GPa]")
for i in range(6): for i in range(6):
for j in range(6): for j in range(6):
print "%10.8g " % s[i][j], print("%10.8g " % s[i][j], end="")
print print()