Skip to content

Commit

Permalink
Merge pull request #11 from Z2PackDev/clip_trace_value
Browse files Browse the repository at this point in the history
Clip value of rotation matrix trace before passing to arccos.
  • Loading branch information
greschd committed Apr 29, 2020
2 parents 2e831d8 + 3bd9a83 commit defb21f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion symmetry_representation/_get_repr_matrix/_spin_reps.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ def D12(l, m, n, phi):
np.cos(phi / 2.) + 1j * n * np.sin(phi / 2.)]])

n = np.zeros(3)
tr = np.trace(rot)
tr_unclipped = np.trace(rot)
det = np.round(np.linalg.det(rot), 5)
if det == 1.: # rotations
tr = max(min(tr_unclipped, 3), -1)
if not np.isclose(tr, tr_unclipped):
raise ValueError(
f"Rotation matrix has an invalid trace {tr_unclipped}."
)
theta = np.arccos(0.5 * (tr - 1.)) # pylint: disable=assignment-from-no-return,useless-suppression
if theta != 0:
n[0] = rot[2, 1] - rot[1, 2]
Expand All @@ -67,6 +72,11 @@ def D12(l, m, n, phi):
else: # case of unity
spin = D12(0, 0, 0, 0)
elif det == -1.: # improper rotations and reflections
tr = max(min(tr_unclipped, 1), -3)
if not np.isclose(tr, tr_unclipped):
raise ValueError(
f"Rotation matrix has an invalid trace {tr_unclipped}."
)
theta = np.arccos(0.5 * (tr + 1.)) # pylint: disable=assignment-from-no-return,useless-suppression
if np.round(theta, 5) != np.round(np.pi, 5):
n[0] = rot[2, 1] - rot[1, 2]
Expand Down

0 comments on commit defb21f

Please sign in to comment.