Skip to content

Commit

Permalink
More python3ing
Browse files Browse the repository at this point in the history
Now passes tests for py2 and py3
  • Loading branch information
andreww committed Sep 4, 2020
1 parent 72208f8 commit 8b31943
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
23 changes: 12 additions & 11 deletions CijUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Copyright (c) 2010 Andrew Walker. All rights reserved.
"""
from __future__ import print_function

import numpy as np

Expand Down Expand Up @@ -84,9 +85,9 @@ def CijStability(Cij):
if (np.amin(eigenvalues) > 0.0):
stable = True
else:
print "Crystal not stable to small strains"
print "(Cij not positive definite)"
print "Eigenvalues: " + str(eigenvalues)
print("Crystal not stable to small strains")
print("(Cij not positive definite)")
print("Eigenvalues: " + str(eigenvalues))

return stable

Expand Down Expand Up @@ -120,11 +121,11 @@ def invertCij(Cij, eCij):
# Assuming we have a rank 2 square array
# of the same size for input array.
if (np.ndim(Cij) != 2):
raise ValueError, "Matrix must be rank 2"
raise ValueError("Matrix must be rank 2")
if (np.shape(Cij)[0] != np.shape(Cij)[1]):
raise ValueError, "Matrix must be square"
raise ValueError("Matrix must be square")
if (np.shape(Cij) != np.shape(eCij)):
raise ValueError, "Matrix and error matrix must have same rank and shape"
raise ValueError("Matrix and error matrix must have same rank and shape")

# Calculate the inverse using numpy
Sij = np.linalg.inv(Cij)
Expand Down Expand Up @@ -290,12 +291,12 @@ def youngsmod(Cij, eCij=np.zeros((6,6))):
import sys
inFile = file(sys.argv[1], 'r')
Cij_in = np.loadtxt(inFile)
print "Input matrix:"
print np.array2string(Cij_in,max_line_width=130,suppress_small=True)
print("Input matrix:")
print (np.array2string(Cij_in,max_line_width=130,suppress_small=True))
(voigtB, reussB, voigtG, reussG, hillB, hillG,
dum, dum, dum, dum, dum, dum) = polyCij(Cij_in)
format = "%16s : %11.5f %11.5f %11.5f"
print "\n Voigt Reuss Hill"
print format % ("Bulk Modulus", voigtB, reussB, hillB)
print format % ("Shear Modulus", voigtG, reussG, hillG)
print("\n Voigt Reuss Hill")
print(format % ("Bulk Modulus", voigtB, reussB, hillB))
print(format % ("Shear Modulus", voigtG, reussG, hillG))

6 changes: 3 additions & 3 deletions elastics.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class PotM_Options:
cijdat = open(seedname+".cijdat","r")
print("\nReading strain data from ", seedname+".cijdat\n")

numStrainPatterns = (len(cijdat.readlines())-2)/4 #total for all strain patterns
numStrainPatterns = (len(cijdat.readlines())-2)//4 #total for all strain patterns

#rewind
cijdat.seek(0)
Expand Down Expand Up @@ -198,7 +198,7 @@ class PotM_Options:
finalCijs = S.zeros((21,1))
errors = S.zeros((21,1))

for patt in range(numStrainPatterns/numsteps):
for patt in range(numStrainPatterns//numsteps):

print("\nAnalysing pattern", patt+1, ":")

Expand Down Expand Up @@ -246,7 +246,7 @@ def __fit(index1, index2):

(vmajor,vminor,vmicro) = re.split('\.',S.__version__)

if ( vmajor > 0 or vminor >= 7):
if ( int(vmajor) > 0 or int(vminor) >= 7):
error = stderr
else:
# correct for scipy weirdness - see http://www.scipy.org/scipy/scipy/ticket/8
Expand Down

0 comments on commit 8b31943

Please sign in to comment.