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