Spherical Harmonics

The spherical harmonics \(Y^l(x)\) are functions defined on the sphere \(S^2\). They form a basis of the space on function on the sphere:

\[\mathcal{F} = \{ S^2 \longrightarrow \mathbb{R} \}\]

On this space it is nautal how the group \(O(3)\) acts, Given \(p_a, p_v\) two scalar representations:

\[[L(g) f](x) = p_v(g) f(p_a(g) R(g)^{-1} x), \quad \forall f \in \mathcal{F}, x \in S^2\]

\(L\) is representation of \(O(3)\). But \(L\) is not irreducible. It can be decomposed via a change of basis into a sum of irreps,

\[Y^T L(g) Y = 0 \oplus 1 \oplus 2 \oplus 3 \oplus \dots\]

where the change of basis are the spherical harmonics!

As a consequence, the spherical harmonics are equivariant,

\[Y^l(R(g) x) = D^l(g) Y^l(x)\]
r = s2_grid()

r is a grid on the sphere.

Each point on the sphere has 3 components. If we plot the value of each of the 3 component separately we obtain the following figure:

plot(r, radial_abs=False)

x, y and z are represented as 3 scalar fields on 3 different spheres. To obtain a nicer figure (that looks like the spherical harmonics shown on Wikipedia) we can deform the spheres into a shape that has its radius equal to the absolute value of the plotted quantity:

plot(r)

\(Y^1\) is the identity function. Now let’s compute \(Y^2\), for this we take the tensor product \(r \otimes r\) and extract the \(L=2\) part of it.

tp = o3.ElementwiseTensorProduct("1o", "1o", ['2e'], irrep_normalization='norm')
y2 = tp(r, r)
plot(y2)

Similarly, the next spherical harmonic function \(Y^3\) is the \(L=3\) part of \(r \otimes r \otimes r\):

tp = o3.ElementwiseTensorProduct("2e", "1o", ['3o'], irrep_normalization='norm')
y3 = tp(y2, r)
plot(y3)

The functions below are more efficient versions not using e3nn.o3.ElementwiseTensorProduct:

Details

e3nn.o3.spherical_harmonics(l: Union[int, List[int], str, e3nn.o3._irreps.Irreps], x: torch.Tensor, normalize: bool, normalization: str = 'integral')[source]

Spherical harmonics

https://user-images.githubusercontent.com/333780/79220728-dbe82c00-7e54-11ea-82c7-b3acbd9b2246.gif
Polynomials defined on the 3d space \(Y^l: \mathbb{R}^3 \longrightarrow \mathbb{R}^{2l+1}\)
Usually restricted on the sphere (with normalize=True) \(Y^l: S^2 \longrightarrow \mathbb{R}^{2l+1}\)
who satisfies the following properties:
  • are polynomials of the cartesian coordinates x, y, z

  • is equivariant \(Y^l(R x) = D^l(R) Y^l(x)\)

  • are orthogonal \(\int_{S^2} Y^l_m(x) Y^j_n(x) dx = \text{cste} \; \delta_{lj} \delta_{mn}\)

The value of the constant depends on the choice of normalization.

It obeys the following property:

\[ \begin{align}\begin{aligned}Y^{l+1}_i(x) &= \text{cste}(l) \; & C_{ijk} Y^l_j(x) x_k\\\partial_k Y^{l+1}_i(x) &= \text{cste}(l) \; (l+1) & C_{ijk} Y^l_j(x)\end{aligned}\end{align} \]

Where \(C\) are the wigner_3j.

Note

This function match with this table of standard real spherical harmonics from Wikipedia when normalize=True, normalization='integral' and is called with the argument in the order y,z,x (instead of x,y,z).

Parameters
  • l (int or list of int) – degree of the spherical harmonics.

  • x (torch.Tensor) – tensor \(x\) of shape (..., 3).

  • normalize (bool) – whether to normalize the x to unit vectors that lie on the sphere before projecting onto the spherical harmonics

  • normalization ({'integral', 'component', 'norm'}) – normalization of the output tensors — note that this option is independent of normalize, which controls the processing of the input, rather than the output. Valid options: * component: \(\|Y^l(x)\|^2 = 2l+1, x \in S^2\) * norm: \(\|Y^l(x)\| = 1, x \in S^2\), component / sqrt(2l+1) * integral: \(\int_{S^2} Y^l_m(x)^2 dx = 1\), component / sqrt(4pi)

Returns

a tensor of shape (..., 2l+1)

\[Y^l(x)\]

Return type

torch.Tensor

Examples

>>> spherical_harmonics(0, torch.randn(2, 3), False, normalization='component')
tensor([[1.],
        [1.]])

See also

wigner_D, wigner_3j

e3nn.o3.spherical_harmonics_alpha_beta(l, alpha, beta, *, normalization='integral')[source]

Spherical harmonics of \(\vec r = R_y(\alpha) R_x(\beta) e_y\)

\[Y^l(\alpha, \beta) = S^l(\alpha) P^l(\cos(\beta))\]

where \(P^l\) are the Legendre polynomials

Parameters
  • l (int or list of int) – degree of the spherical harmonics.

  • alpha (torch.Tensor) – tensor of shape (...).

  • beta (torch.Tensor) – tensor of shape (...).

Returns

a tensor of shape (..., 2l+1)

Return type

torch.Tensor

e3nn.o3.Legendre(*args, **kwargs)[source]

GraphModule is an nn.Module generated from an fx.Graph. Graphmodule has a graph attribute, as well as code and forward attributes generated from that graph.

Warning

When graph is reassigned, code and forward will be automatically regenerated. However, if you edit the contents of the graph without reassigning the graph attribute itself, you must call recompile() to update the generated code.

Note

Backwards-compatibility for this API is guaranteed.