-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_clebsch_gordan.py
151 lines (147 loc) · 6.32 KB
/
test_clebsch_gordan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import re
import BasisLib
from testing import subtests
import numpy as np
import pytest
@pytest.fixture(name='expected_cg')
def fixture_expected_cg() -> np.array:
"""Clebsch-Gordant for max_degree1 = max_degree2 = max_degree3 = 2."""
# pyformat: disable
return np.asarray([
[
[1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1]
],
[
[0, 1, 0, 0, 0, 0, 0, 0, 0],
[np.sqrt(3)/3, 0, 0, 0, 0, 0, -np.sqrt(6)/6, 0, -np.sqrt(2)/2],
[0, 0, 0, np.sqrt(2)/2, 0, np.sqrt(2)/2, 0, 0, 0],
[0, 0, -np.sqrt(2)/2, 0, np.sqrt(2)/2, 0, 0, 0, 0],
[0, 0, 0, np.sqrt(30)/10, 0, -np.sqrt(6)/6, 0, 0, 0],
[0, 0, np.sqrt(30)/10, 0, np.sqrt(6)/6, 0, 0, 0, 0],
[0, -np.sqrt(10)/10, 0, 0, 0, 0, 0, np.sqrt(2)/2, 0],
[0, 0, 0, 0, 0, 0, -np.sqrt(2)/2, 0, np.sqrt(6)/6],
[0, -np.sqrt(30)/10, 0, 0, 0, 0, 0, -np.sqrt(6)/6, 0]
],
[
[0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, -np.sqrt(2)/2, 0, np.sqrt(2)/2, 0, 0, 0],
[np.sqrt(3)/3, 0, 0, 0, 0, 0, np.sqrt(6)/3, 0, 0],
[0, np.sqrt(2)/2, 0, 0, 0, 0, 0, np.sqrt(2)/2, 0],
[0, 0, 0, 0, 0, 0, 0, 0, -np.sqrt(6)/3],
[0, np.sqrt(30)/10, 0, 0, 0, 0, 0, -np.sqrt(6)/6, 0],
[0, 0, np.sqrt(10)/5, 0, 0, 0, 0, 0, 0],
[0, 0, 0, np.sqrt(30)/10, 0, np.sqrt(6)/6, 0, 0, 0],
[0, 0, 0, 0, np.sqrt(6)/3, 0, 0, 0, 0]
],
[
[0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, np.sqrt(2)/2, 0, np.sqrt(2)/2, 0, 0, 0, 0],
[0, -np.sqrt(2)/2, 0, 0, 0, 0, 0, np.sqrt(2)/2, 0],
[np.sqrt(3)/3, 0, 0, 0, 0, 0, -np.sqrt(6)/6, 0, np.sqrt(2)/2],
[0, np.sqrt(30)/10, 0, 0, 0, 0, 0, np.sqrt(6)/6, 0],
[0, 0, 0, 0, 0, 0, np.sqrt(2)/2, 0, np.sqrt(6)/6],
[0, 0, 0, -np.sqrt(10)/10, 0, -np.sqrt(2)/2, 0, 0, 0],
[0, 0, np.sqrt(30)/10, 0, -np.sqrt(6)/6, 0, 0, 0, 0],
[0, 0, 0, np.sqrt(30)/10, 0, -np.sqrt(6)/6, 0, 0, 0]
],
[
[0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, np.sqrt(30)/10, 0, np.sqrt(6)/6, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, np.sqrt(6)/3],
[0, np.sqrt(30)/10, 0, 0, 0, 0, 0, -np.sqrt(6)/6, 0],
[np.sqrt(5)/5, 0, 0, 0, 0, 0, -np.sqrt(14)/7, 0, 0],
[0, -np.sqrt(10)/10, 0, 0, 0, 0, 0, np.sqrt(42)/14, 0],
[0, 0, 0, 0, -np.sqrt(14)/7, 0, 0, 0, 0],
[0, 0, 0, np.sqrt(10)/10, 0, np.sqrt(42)/14, 0, 0, 0],
[0, 0, -np.sqrt(10)/5, 0, 0, 0, 0, 0, 0]
],
[
[0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, np.sqrt(30)/10, 0, -np.sqrt(6)/6, 0, 0, 0, 0],
[0, np.sqrt(30)/10, 0, 0, 0, 0, 0, np.sqrt(6)/6, 0],
[0, 0, 0, 0, 0, 0, -np.sqrt(2)/2, 0, -np.sqrt(6)/6],
[0, np.sqrt(10)/10, 0, 0, 0, 0, 0, np.sqrt(42)/14, 0],
[np.sqrt(5)/5, 0, 0, 0, 0, 0, np.sqrt(14)/14, 0, -np.sqrt(42)/14],
[0, 0, 0, np.sqrt(30)/10, 0, np.sqrt(14)/14, 0, 0, 0],
[0, 0, -np.sqrt(10)/10, 0, np.sqrt(42)/14, 0, 0, 0, 0],
[0, 0, 0, np.sqrt(10)/10, 0, -np.sqrt(42)/14, 0, 0, 0]
],
[
[0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, -np.sqrt(10)/10, 0, 0, 0, 0, 0, -np.sqrt(2)/2, 0],
[0, 0, np.sqrt(10)/5, 0, 0, 0, 0, 0, 0],
[0, 0, 0, -np.sqrt(10)/10, 0, np.sqrt(2)/2, 0, 0, 0],
[0, 0, 0, 0, -np.sqrt(14)/7, 0, 0, 0, 0],
[0, 0, 0, -np.sqrt(30)/10, 0, np.sqrt(14)/14, 0, 0, 0],
[np.sqrt(5)/5, 0, 0, 0, 0, 0, np.sqrt(14)/7, 0, 0],
[0, np.sqrt(30)/10, 0, 0, 0, 0, 0, np.sqrt(14)/14, 0],
[0, 0, 0, 0, 0, 0, 0, 0, -np.sqrt(14)/7]
],
[
[0, 0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, np.sqrt(2)/2, 0, -np.sqrt(6)/6],
[0, 0, 0, np.sqrt(30)/10, 0, -np.sqrt(6)/6, 0, 0, 0],
[0, 0, np.sqrt(30)/10, 0, np.sqrt(6)/6, 0, 0, 0, 0],
[0, 0, 0, -np.sqrt(10)/10, 0, np.sqrt(42)/14, 0, 0, 0],
[0, 0, np.sqrt(10)/10, 0, np.sqrt(42)/14, 0, 0, 0, 0],
[0, -np.sqrt(30)/10, 0, 0, 0, 0, 0, np.sqrt(14)/14, 0],
[np.sqrt(5)/5, 0, 0, 0, 0,0, np.sqrt(14)/14, 0, np.sqrt(42)/14],
[0, np.sqrt(10)/10, 0, 0, 0, 0, 0, np.sqrt(42)/14, 0]
],
[
[0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, -np.sqrt(30)/10, 0, 0, 0, 0, 0, np.sqrt(6)/6, 0],
[0, 0, 0, 0, -np.sqrt(6)/3, 0, 0, 0, 0],
[0, 0, 0, np.sqrt(30)/10, 0, np.sqrt(6)/6, 0, 0, 0],
[0, 0, np.sqrt(10)/5, 0, 0, 0, 0, 0, 0],
[0, 0, 0, -np.sqrt(10)/10, 0, -np.sqrt(42)/14, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, -np.sqrt(14)/7],
[0, -np.sqrt(10)/10, 0, 0, 0, 0, 0, np.sqrt(42)/14, 0],
[np.sqrt(5)/5, 0, 0, 0, 0, 0, -np.sqrt(14)/7, 0, 0]
]
])
# pyformat: enable
@pytest.mark.parametrize('cartesian_order', [False, True])
def test_clebsch_gordan(
cartesian_order: bool,
expected_cg: np.asarray,
max_degree: int = 2,
):
cg = BasisLib.so3.clebsch_gordan(
max_degree, max_degree, max_degree, cartesian_order=cartesian_order
)
if cartesian_order:
p = BasisLib.so3._cartesian_permutation(max_degree)
expected_cg = expected_cg[p, :, :][:, p, :][:, :, p]
assert np.allclose(cg, expected_cg, atol=1e-5)
@pytest.mark.parametrize('l1', [0, 1, 2])
@pytest.mark.parametrize('l2', [0, 1, 2])
@pytest.mark.parametrize('l3', [0, 1, 2])
@pytest.mark.parametrize('cartesian_order', [False, True])
def test_clebsch_gordan_for_degrees(
l1: int,
l2: int,
l3: int,
cartesian_order: bool,
expected_cg: np.array,
) -> None:
cg = BasisLib.so3.clebsch_gordan_for_degrees(
degree1=l1, degree2=l2, degree3=l3, cartesian_order=cartesian_order
)
expected_cg = expected_cg[
l1**2 : (l1 + 1) ** 2, l2**2 : (l2 + 1) ** 2, l3**2 : (l3 + 1) ** 2
]
if cartesian_order:
p1 = BasisLib.so3._cartesian_permutation_for_degree(l1)
p2 = BasisLib.so3._cartesian_permutation_for_degree(l2)
p3 = BasisLib.so3._cartesian_permutation_for_degree(l3)
expected_cg = expected_cg[p1, :, :][:, p2, :][:, :, p3]
assert np.allclose(cg, expected_cg, atol=1e-5)