LCOV - code coverage report
Current view: top level - tests - test_perturbative_deprecated.py (source / functions) Hit Total Coverage
Test: coverage.info Lines: 48 48 100.0 %
Date: 2026-07-28 15:38:42 Functions: 5 5 100.0 %

          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 :     pi_module.diagonalize([system], diagonalizer="eigen")
      31           1 :     basis_pair = pi_module.BasisPair([system, system])
      32           1 :     system_pair = pi_module.SystemPair(basis_pair)
      33           1 :     theta = 0
      34           1 :     r = 12
      35           1 :     system_pair.set_distance_vector(r * np.array([np.sin(theta), 0, np.cos(theta)]), "micrometer")
      36           1 :     system_pair.set_interaction_order(3)
      37           1 :     return system_pair
      38             : 
      39             : 
      40           1 : @pytest.mark.filterwarnings("ignore::DeprecationWarning")
      41           1 : def test_c3_with_system(pi_module: PairinteractionModule, system_pair_sample: SystemPair) -> None:
      42             :     """Test whether the C3 coefficient with a given system is calculated correctly."""
      43           1 :     ket_tuple_list = [
      44             :         (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)),
      45             :         (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)),
      46             :     ]
      47           1 :     c3 = perturbative.get_c3_from_system(
      48             :         system_pair=system_pair_sample, ket_tuple_list=ket_tuple_list, unit="planck_constant * gigahertz * micrometer^3"
      49             :     )
      50           1 :     assert np.isclose(-0.5 * c3, 3.1515)
      51             : 
      52             : 
      53           1 : @pytest.mark.filterwarnings("ignore::DeprecationWarning")
      54           1 : def test_c3_create_system(pi_module: PairinteractionModule) -> None:
      55             :     """Test whether the C3 coefficient with automatically constructed system is calculated correctly."""
      56           1 :     ket_tuple_list = [
      57             :         (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)),
      58             :         (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)),
      59             :     ]
      60           1 :     magnetic_field = ureg.Quantity([0, 0, 10], "gauss")
      61           1 :     electric_field = ureg.Quantity([0, 0, 0], "volt/cm")
      62           1 :     distance_vector = ureg.Quantity([0, 0, 500], "micrometer")
      63             : 
      64           1 :     system = perturbative.create_system_for_perturbative(
      65             :         ket_tuple_list, electric_field, magnetic_field, distance_vector
      66             :     )
      67             : 
      68           1 :     c3 = perturbative.get_c3_from_system(
      69             :         system_pair=system, ket_tuple_list=ket_tuple_list, unit="planck_constant * gigahertz * micrometer^3"
      70             :     )
      71           1 :     assert np.isclose(-0.5 * c3, 3.2188)
      72             : 
      73             : 
      74           1 : @pytest.mark.filterwarnings("ignore::DeprecationWarning")
      75           1 : def test_c6_with_system(pi_module: PairinteractionModule, system_pair_sample: SystemPair) -> None:
      76             :     """Test whether the C6 coefficient with a given system is calculated correctly."""
      77           1 :     ket_atom = pi_module.KetAtom(species="Rb", n=61, l=0, j=0.5, m=0.5)
      78           1 :     c6 = perturbative.get_c6_from_system(
      79             :         ket_tuple=(ket_atom, ket_atom),
      80             :         system_pair=system_pair_sample,
      81             :         unit="planck_constant * gigahertz * micrometer^6",
      82             :     )
      83           1 :     assert np.isclose(c6, 167.880)
      84             : 
      85             : 
      86           1 : @pytest.mark.filterwarnings("ignore::DeprecationWarning")
      87           1 : def test_c6_create_system(pi_module: PairinteractionModule) -> None:
      88             :     """Test whether the C6 coefficient with automatically constructed system is calculated correctly."""
      89           1 :     magnetic_field = ureg.Quantity([0, 0, 10], "gauss")
      90           1 :     electric_field = ureg.Quantity([0, 0, 0], "volt/cm")
      91           1 :     distance_vector = ureg.Quantity([0, 0, 500], "micrometer")
      92           1 :     ket_atom = pi_module.KetAtom(species="Rb", n=61, l=0, j=0.5, m=0.5)
      93             : 
      94           1 :     system = perturbative.create_system_for_perturbative(
      95             :         [(ket_atom, ket_atom)], electric_field, magnetic_field, distance_vector
      96             :     )
      97             : 
      98           1 :     c6 = perturbative.get_c6_from_system(
      99             :         ket_tuple=(ket_atom, ket_atom), system_pair=system, unit="planck_constant * gigahertz * micrometer^6"
     100             :     )
     101           1 :     assert np.isclose(c6, 169.149)

Generated by: LCOV version 1.16