Wigner symbols for Python

py3nj is a small library to calculate Wigner symbols, such as wigner’s 3j, 6j, 9j symbols, as well as Clebsch Gordan coefficients.

py3nj mostly wraps the original Fortran implementation in slatec, but it is designed to highly compatible to numpy’s nd-array, i.e. the automatic vectorization is supported.

Installing

py3nj is available on pypi. To install

`bash pip install py3nj `

You may need fortran compiler installed in your environment.

Documentation

Examples

Examples

Basic interfaces

Most basic interface are wigner3j(), wigner6j(), wigner9j(), clebsch_gordan().

For example, if you want to compute

\[\begin{split}\begin{pmatrix} 0&\frac{1}{2}&\frac{1}{2}\\ 0&\frac{1}{2}&-\frac{1}{2} \end{pmatrix}.\end{split}\]

then pass the doubled value, [0, 1, 1, 0, 1, -1] to wigner3j().

In [1]: py3nj.wigner3j(0, 1, 1,
   ...:                0, 1, -1)
   ...: 
Out[1]: 0.7071067811865476

The arguments should be integer or array of integers.

All the functions of py3nj accept array-like as arguments,

In [2]: py3nj.wigner3j([0, 1], [1, 2], [1, 1],
   ...:                [0, -1], [1, 2], [-1, -1])
   ...: 
Out[2]: array([ 0.70710678, -0.57735027])

where the output has the same size of the input. np.ndarray with more than 1 dimension can be also used.

This vectorization not only reduce the python overhead, but also reusing the result with the same argument. Therefore, if you need to compute these coefficients for many cases, it is recommended to consider how your calculation can be vectorized.

Advanced interfaces

py3nj wraps slatec fortran implementation. The similar interfaces to the original slatec functions, wigner.drc3jj() and drc6j() are also supported.

This function computes all the possible values of \(J_1\) and their corresponding 3j symbol with given \(J_2, J_3, M_2, M_3\) values,

In [3]: two_l1, three_j = py3nj.wigner.drc3jj(1, 1, 1, 1)

In [4]: two_l1
Out[4]: array([0, 1, 2])

In [5]: three_j
Out[5]: array([ 0.        ,  0.        , -0.57735027])

This function can be also vectorized,

In [6]: two_l1, three_j = py3nj.wigner.drc3jj([1, 0], [1, 2], [1, 0], [1, 2])

In [7]: two_l1
Out[7]: array([0, 1, 2])

In [8]: three_j
Out[8]: 
array([[ 0.        ,  0.        , -0.57735027],
       [ 0.        ,  0.        ,  0.57735027]])

Note that even in this advanced interfaces, the vectorized version will be much faster than that sequencial calculation if you need many calcluations.

Help & reference

What’s New

v0.1 (29 May 2018)

Initial release.

API reference

This page provides an auto-generated summary of py3nj’s API. For more details and examples, refer to the relevant chapters in the main part of the documentation.

Top-level functions

wigner3j(two_l1, two_l2, two_l3, two_m1, …)

Calculate wigner 3j symbol ( L1 L2 L3) (-M2-M3 M2 M3)

wigner6j(two_l1, two_l2, two_l3, two_l4, …)

Calculate wigner 6j symbol (L1 L2 L3) (L4 L5 L6)

wigner9j(two_l1, two_l2, two_l3, two_l4, …)

Calculate wigner 9j symbol (L1 L2 L3) (L4 L5 L6) (L7 L8 L9)

clebsch_gordan(two_j1, two_j2, two_j3, …)

Calulate Clebsch-Gordan coefficient <j1 m1, j2 m2 | j3 m3>

Wigner module

wigner.drc3jj(two_l2, two_l3, two_m2, two_m3)

Calculate Wigner’s 3j symbol ( L1 L2 L3) (-M2-M3 M2 M3) for all the possible L1 values.

wigner.drc6j(two_l2, two_l3, two_l4, two_l5, …)

Calculate Wigner’s 6j symbol (L1 L2 L3) (L4 L5 L6) for all the possible L1 values.

License

py3nj is available under the open source Apache License.