Lattice from matrix
XinYu73 opened this issue · comments
忻宇 commented
say I have a lattice matrix
array([[ 8.48144648e+00, 6.58925087e-16, -3.37011015e+02],
[ 0.00000000e+00, 1.04253452e+01, 6.38368280e-16],
[ 0.00000000e+00, 0.00000000e+00, 1.86096030e+02]])
matrix2para gives
array([337.11772326, 10.42534517, 186.0960304 , 1.57079633, 3.14159265, 1.57079633])
in this case, a and c are almost collinear, which leads following code giving the wrong answer due to machine precision
# in para2matrix
# Generate an upper-diagonal matrix
a3 = a * cos_beta
a2 = (a * (cos_gamma - (cos_beta * cos_alpha))) / sin_alpha
matrix[2][2] = c
matrix[1][2] = b * cos_alpha
matrix[1][1] = b * sin_alpha
matrix[0][2] = a3
matrix[0][1] = a2
tmp = a ** 2 - a3 ** 2 - a2 ** 2
if tmp > 0:
matrix[0][0] = np.sqrt(a ** 2 - a3 ** 2 - a2 ** 2)
else:
print(tmp)
I suggest that we should use
if tmp >0:
matrix[0][0] = np.sqrt(a ** 2 - a3 ** 2 - a2 ** 2)
elif np.abs(temp) <1e-5:
matrix[0][0] = 0
else:
return 0