def test_wigner6j_ignore_invalid(): N = np.arange(1, 2) K = np.arange(-2, 3)[:, np.newaxis] with pytest.raises(ValueError): # should raise an error wigner6j(N * 2, K * 2, 0, 0, 0, 0, ignore_invalid=False) # should compute wigner6j(N * 2, K * 2, 0, 0, 0, 0, ignore_invalid=True)
def test_wigner6j_GH13(): """ Test for https://github.com/fujiisoup/py3nj/issues/13 """ N = np.arange(10) J = np.arange(11)[:, np.newaxis] # should not fail wigner6j(0, N * 2, N * 2, J * 2, 2, 2)
def test_wigner6j_value(): # scalar test for six_j, expected in SIX_J: six_j = (np.array(six_j) * 2).astype(int) actual = wigner6j(*six_j) assert np.allclose(actual, expected) # test vector six_j = np.array([six for six, _ in SIX_J]).T * 2 expected = np.array([value for _, value in SIX_J]).T actual = wigner6j(*six_j.astype(int)) assert np.allclose(actual, expected)
def get_prefactors(labels): dim, ll, LL = [np.array(vals) for vals in zip(*labels)] wigner_6j_degrees = 2 * np.array([ll, ll, LL]) wigner_6j_spins = np.array([dim, dim, dim]) - 1 wigner_6j_factors = py3nj.wigner6j(*wigner_6j_degrees.astype(int), *wigner_6j_spins) prefactors = (-1)**(dim - 1 + LL) * ( 2 * ll + 1) * np.sqrt(2 * LL + 1) * wigner_6j_factors return {label: prefactor for label, prefactor in zip(labels, prefactors)}
def test_wigner6j(): n = 10000 n2 = 10 l2 = rng.randint(0, 40, size=n) l3 = rng.randint(0, 40, size=n) l4 = rng.randint(0, 40, size=n) l5 = rng.randint(0, 40, size=n) l6 = rng.randint(0, 40, size=n) l, expected_all = wigner.drc6j(l2, l3, l4, l5, l6) for _ in range(n2): lindex = rng.randint(0, 40, n) two_l1 = l[lindex] actual = wigner6j(two_l1, l2, l3, l4, l5, l6) expected = expected_all[np.arange(len(lindex)), lindex] assert np.allclose(actual, expected)
def wigner6j(jj1, jj2, jj3, jj4, jj5, jj6): """ Calculate the Wigner 6-j symbol, .. math:: \\left\\{\\begin{array}{ccc} j_1 & j_2 & j_3 \\\\ j_4 & j_5 & j_6 \\end{array} \\right\\} Parameters ---------- jj1 : integer Twice the value of :math:`j_1`. jj2 : integer Twice the value of :math:`j_2`. jj3 : integer Twice the value of :math:`j_3`. jj4 : integer Twice the value of :math:`j_4`. jj5 : integer Twice the value of :math:`j_5`. jj6 : integer Twice the value of :math:`j_6`. Returns ------- float The result. Notes ----- This currently wraps the `py3nj <https://github.com/fujiisoup/py3nj>`_ implementation. The back-end may change in the future. Examples -------- >>> n2.angmom.wigner6j(2 * 3, 2 * 6, 2 * 5, 2 * 4, 2 * 6, 2 * 9) -0.020558557070186504 """ result = py3nj.wigner6j(jj1, jj2, jj3, jj4, jj5, jj6) return result