Make compliance.py Python 3 compatible
This commit is contained in:
@ -1,13 +1,14 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
# This file reads in the file log.lammps generated by the script ELASTIC/in.elastic
|
# 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
|
# followed by the 6x6 tensor of compliance constants Sij
|
||||||
# It uses the same conventions as described in:
|
# 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 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,9 +45,8 @@ 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,18 +67,18 @@ 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
|
||||||
|
|
||||||
for i in range(6):
|
for i in range(6):
|
||||||
for j in range(3,6):
|
for j in range(3,6):
|
||||||
c[i][j] *= 2.0
|
c[i][j] *= 2.0
|
||||||
|
|
||||||
s = inv(c)
|
s = inv(c)
|
||||||
|
|
||||||
# apply factor of 1/2 to columns of off-diagonal elements
|
# apply factor of 1/2 to columns of off-diagonal elements
|
||||||
@ -86,10 +86,9 @@ s = inv(c)
|
|||||||
for i in range(6):
|
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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user