From 5b469292d2a37081fec3fffb568b81f66e4d917c Mon Sep 17 00:00:00 2001 From: Yuhang Yu <115705619+irimmal@users.noreply.github.com> Date: Thu, 23 Jul 2026 11:28:06 +0800 Subject: [PATCH] fix: Implement l1 and l2 exchange with CG calculation while include SOC Added functionality to exchange l1 and l2 values and compute Clebsch-Gordan coefficients. --- irrepx/cli.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/irrepx/cli.py b/irrepx/cli.py index 44c5dd0..e15f850 100644 --- a/irrepx/cli.py +++ b/irrepx/cli.py @@ -182,6 +182,19 @@ def _build_cg(target: Path, lmax: int, include_soc: bool = False): data[f"{key}/coo_l"] = cols data[f"{key}/entries"] = vals + # exchange l1 and l2 + blocks = [] + for l3 in range(abs(1 - l2), 1 + l2 + 1): + blocks.append(clebsch_gordan(l2, 1, l3) * np.sqrt(2 * l3 + 1)) + cg_full = np.concatenate(blocks, axis=-1) + rows1, rows2, cols = np.nonzero(cg_full) + vals = cg_full[rows1, rows2, cols] + key = f"l1={l2},l2={1}" + data[f"{key}/coo_l1"] = rows1 + data[f"{key}/coo_l2"] = rows2 + data[f"{key}/coo_l"] = cols + data[f"{key}/entries"] = vals + out = target / "cg.npz" np.savez_compressed(out, **data) extra = " +SOC" if include_soc else ""