Line data Source code
1 : # SPDX-FileCopyrightText: 2025 PairInteraction Developers
2 : # SPDX-License-Identifier: LGPL-3.0-or-later
3 :
4 1 : from __future__ import annotations
5 :
6 1 : from typing import TYPE_CHECKING
7 :
8 1 : import numpy as np
9 1 : import pytest
10 1 : from pairinteraction import perturbative
11 1 : from pairinteraction.units import ureg
12 :
13 : if TYPE_CHECKING:
14 : from pairinteraction import SystemPair
15 :
16 : from .utils import PairinteractionModule
17 :
18 :
19 1 : @pytest.fixture
20 1 : def system_pair_sample(pi_module: PairinteractionModule) -> SystemPair:
21 1 : basis = pi_module.BasisAtom(
22 : species="Rb",
23 : n=(59, 63),
24 : l=(0, 1),
25 : m=(-1.5, 1.5),
26 : )
27 1 : system = pi_module.SystemAtom(basis=basis)
28 1 : system.set_diamagnetism_enabled(False)
29 1 : system.set_magnetic_field([0, 0, 1e-3], "gauss")
30 1 : if not system.is_diagonal:
31 1 : pi_module.diagonalize([system], diagonalizer="eigen", sort_by_energy=False)
32 1 : basis_pair = pi_module.BasisPair([system, system])
33 1 : system_pair = pi_module.SystemPair(basis_pair)
34 1 : theta = 0
35 1 : r = 12
36 1 : system_pair.set_distance_vector(r * np.array([np.sin(theta), 0, np.cos(theta)]), "micrometer")
37 1 : system_pair.set_interaction_order(3)
38 1 : return system_pair
39 :
40 :
41 1 : @pytest.mark.filterwarnings("ignore::DeprecationWarning")
42 1 : def test_c3_with_system(pi_module: PairinteractionModule, system_pair_sample: SystemPair) -> None:
43 : """Test whether the C3 coefficient with a given system is calculated correctly."""
44 1 : ket_tuple_list = [
45 : (pi_module.KetAtom("Rb", n=61, l=0, j=0.5, m=0.5), pi_module.KetAtom("Rb", n=61, l=1, j=1.5, m=0.5)),
46 : (pi_module.KetAtom("Rb", n=61, l=1, j=1.5, m=0.5), pi_module.KetAtom("Rb", n=61, l=0, j=0.5, m=0.5)),
47 : ]
48 1 : c3 = perturbative.get_c3_from_system(
49 : system_pair=system_pair_sample, ket_tuple_list=ket_tuple_list, unit="planck_constant * gigahertz * micrometer^3"
50 : )
51 1 : assert np.isclose(-0.5 * c3, 3.1515)
52 :
53 :
54 1 : @pytest.mark.filterwarnings("ignore::DeprecationWarning")
55 1 : def test_c3_create_system(pi_module: PairinteractionModule) -> None:
56 : """Test whether the C3 coefficient with automatically constructed system is calculated correctly."""
57 1 : ket_tuple_list = [
58 : (pi_module.KetAtom("Rb", n=61, l=0, j=0.5, m=0.5), pi_module.KetAtom("Rb", n=61, l=1, j=1.5, m=0.5)),
59 : (pi_module.KetAtom("Rb", n=61, l=1, j=1.5, m=0.5), pi_module.KetAtom("Rb", n=61, l=0, j=0.5, m=0.5)),
60 : ]
61 1 : magnetic_field = ureg.Quantity([0, 0, 10], "gauss")
62 1 : electric_field = ureg.Quantity([0, 0, 0], "volt/cm")
63 1 : distance_vector = ureg.Quantity([0, 0, 500], "micrometer")
64 :
65 1 : system = perturbative.create_system_for_perturbative(
66 : ket_tuple_list, electric_field, magnetic_field, distance_vector
67 : )
68 :
69 1 : c3 = perturbative.get_c3_from_system(
70 : system_pair=system, ket_tuple_list=ket_tuple_list, unit="planck_constant * gigahertz * micrometer^3"
71 : )
72 1 : assert np.isclose(-0.5 * c3, 3.2188)
73 :
74 :
75 1 : @pytest.mark.filterwarnings("ignore::DeprecationWarning")
76 1 : def test_c6_with_system(pi_module: PairinteractionModule, system_pair_sample: SystemPair) -> None:
77 : """Test whether the C6 coefficient with a given system is calculated correctly."""
78 1 : ket_atom = pi_module.KetAtom(species="Rb", n=61, l=0, j=0.5, m=0.5)
79 1 : c6 = perturbative.get_c6_from_system(
80 : ket_tuple=(ket_atom, ket_atom),
81 : system_pair=system_pair_sample,
82 : unit="planck_constant * gigahertz * micrometer^6",
83 : )
84 1 : assert np.isclose(c6, 167.880)
85 :
86 :
87 1 : @pytest.mark.filterwarnings("ignore::DeprecationWarning")
88 1 : def test_c6_create_system(pi_module: PairinteractionModule) -> None:
89 : """Test whether the C6 coefficient with automatically constructed system is calculated correctly."""
90 1 : magnetic_field = ureg.Quantity([0, 0, 10], "gauss")
91 1 : electric_field = ureg.Quantity([0, 0, 0], "volt/cm")
92 1 : distance_vector = ureg.Quantity([0, 0, 500], "micrometer")
93 1 : ket_atom = pi_module.KetAtom(species="Rb", n=61, l=0, j=0.5, m=0.5)
94 :
95 1 : system = perturbative.create_system_for_perturbative(
96 : [(ket_atom, ket_atom)], electric_field, magnetic_field, distance_vector
97 : )
98 :
99 1 : c6 = perturbative.get_c6_from_system(
100 : ket_tuple=(ket_atom, ket_atom), system_pair=system, unit="planck_constant * gigahertz * micrometer^6"
101 : )
102 1 : assert np.isclose(c6, 169.149)
|