Make compliance.py Python 3 compatible
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
# 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,11 +67,11 @@ 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
|
||||
|
||||
@ -87,9 +87,8 @@ 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()
|
||||
|
||||
Reference in New Issue
Block a user