-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
using LinearAlgebra | ||
|
||
struct SphericalHarmonics | ||
normalize::Bool | ||
normalization::String | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using LinearAlgebra | ||
using StaticArrays | ||
|
||
function su2_generators(j::Int) | ||
m = range(-j, j - 1, step = 1) | ||
raising = diagm(-1 => -sqrt.(j * (j + 1) .- m .* (m .+ 1))) | ||
|
||
m = range(-j + 1, j, step = 1) | ||
lowering = diagm(1 => sqrt.(j * (j + 1) .- m .* (m .- 1))) | ||
|
||
m = range(-j, j, step = 1) | ||
return stack( | ||
[0.5 * (raising + lowering), # x (usually) | ||
Diagonal(1im * m), # z (usually) | ||
-0.5im * (raising - lowering)], # -y (usually) | ||
dims = 3) | ||
end | ||
|
||
function change_basis_real_to_complex(l::Int) | ||
# https://en.wikipedia.org/wiki/Spherical_harmonics#Real_form | ||
q = zeros(ComplexF64, 2 * l + 1, 2 * l + 1) | ||
for m in (-l):-1 | ||
q[l + m + 1, l + abs(m) + 1] = 1 / sqrt(2) | ||
q[l + m + 1, l - abs(m) + 1] = -im / sqrt(2) | ||
end | ||
q[l + 1, l + 1] = 1 | ||
for m in 1:l | ||
q[l + m + 1, l + abs(m) + 1] = (-1)^m / sqrt(2) | ||
q[l + m + 1, l - abs(m) + 1] = im * (-1)^m / sqrt(2) | ||
end | ||
q = (-im)^l * q # Added factor of im^l to make the Clebsch-Gordan coefficients real | ||
return q | ||
end | ||
|
||
function so3_generators(l::Int) | ||
X = su2_generators(l) | ||
Q = change_basis_real_to_complex(l) | ||
Q_c_T = conj(transpose(Q)) | ||
|
||
for i in 1:size(X, 3) | ||
@views X[:, :, i] = Q_c_T * X[:, :, i] * Q | ||
end | ||
return real.(X) | ||
end | ||
|
||
function wigner_D(l::Int, α::T, β::T, γ::T) where {T <: Real} | ||
X = so3_generators(l) | ||
return exp(α * X[:, :, 2]) * exp(β * X[:, :, 1]) * exp(γ * X[:, :, 2]) | ||
end | ||
|
||
function wigner_D(l::Int, angles::Tuple{Vararg{T, 3}}) where {T <: Real} | ||
return wigner_D(l, angles[1], angles[2], angles[3]) | ||
end | ||
|
||
function wigner_D(l::Int, angles::SVector{3, T}) where {T <: Real} | ||
return wigner_D(l, angles[1], angles[2], angles[3]) | ||
end | ||
|
||
Broadcast.broadcast(::typeof(wigner_D), l, α, β, γ) = broadcast(wigner_D, Ref(l), α, β, γ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using e3nn.o3 | ||
using Test | ||
using Rotations | ||
using MLUtils: batch | ||
|
||
@testset "WignerD" begin | ||
@testset "basic" begin | ||
R = rand(RotYXY, 10) | ||
angles = R .|> Rotations.params | ||
D = wigner_D.(1, angles) | ||
@test batch(R - D) .|> abs |> maximum < 1e-8 | ||
end | ||
end |