From 4c7af713f15026b34acbfd6c00c3fe12009379ac Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Tue, 14 May 2019 12:56:24 -0400 Subject: [PATCH] added explicit method Rotation.fromBasis, which can treat real and reciprocal basis sets --- python/damask/orientation.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/python/damask/orientation.py b/python/damask/orientation.py index b19037b0c..aae96c8d6 100644 --- a/python/damask/orientation.py +++ b/python/damask/orientation.py @@ -227,12 +227,17 @@ class Rotation: return cls(ax2qu(ax)) @classmethod - def fromMatrix(cls, - matrix, - containsStretch = False): #ToDo: better name? + def fromBasis(cls, + basis, + orthonormal = True, + reciprocal = False, + ): - om = matrix if isinstance(matrix, np.ndarray) else np.array(matrix).reshape((3,3)) # ToDo: Reshape here or require explicit? - if containsStretch: + om = basis if isinstance(basis, np.ndarray) else np.array(basis).reshape((3,3)) + if reciprocal: + om = np.linalg.inv(om.T/np.pi) # transform reciprocal basis set + orthonormal = False # contains stretch + if not orthonormal: (U,S,Vh) = np.linalg.svd(om) # singular value decomposition om = np.dot(U,Vh) if not np.isclose(np.linalg.det(om),1.0): @@ -244,6 +249,13 @@ class Rotation: return cls(om2qu(om)) + @classmethod + def fromMatrix(cls, + om, + ): + + return cls.fromBasis(om) + @classmethod def fromRodrigues(cls, rodrigues,