From 2a348c4fc8c6a11b70895b8af10c8afe2d766b4e Mon Sep 17 00:00:00 2001 From: memii-x Date: Mon, 16 Nov 2026 17:16:27 +0800 Subject: [PATCH 1/4] fix(rt): use matching spin Hamiltonians for commutator current --- .../source_io/module_ctrl/ctrl_output_td.cpp | 4 +- .../source_io/module_current/td_current_io.h | 6 +-- .../module_current/td_current_io_comm.cpp | 34 +++++++++----- tests/08_RI/CASES_CPU.txt | 2 + .../rt_tddft_hse_current_spin2_down/INPUT | 46 +++++++++++++++++++ .../08_RI/rt_tddft_hse_current_spin2_down/KPT | 4 ++ .../rt_tddft_hse_current_spin2_down/README | 1 + .../rt_tddft_hse_current_spin2_down/STRU | 22 +++++++++ .../current_tot.txt.ref | 3 ++ .../result.ref | 4 ++ .../08_RI/rt_tddft_hse_current_spin2_up/INPUT | 46 +++++++++++++++++++ tests/08_RI/rt_tddft_hse_current_spin2_up/KPT | 4 ++ .../rt_tddft_hse_current_spin2_up/README | 1 + .../08_RI/rt_tddft_hse_current_spin2_up/STRU | 22 +++++++++ .../current_tot.txt.ref | 3 ++ .../rt_tddft_hse_current_spin2_up/result.ref | 4 ++ tests/integrate/CMakeLists.txt | 5 ++ .../integrate/validation_tools/props_tddft.sh | 3 ++ .../validation_tools/test_props_tddft.py | 43 +++++++++++++++++ 19 files changed, 241 insertions(+), 16 deletions(-) create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/INPUT create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/KPT create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/README create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/STRU create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/current_tot.txt.ref create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/result.ref create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_up/KPT create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_up/README create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_up/STRU create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref create mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref create mode 100644 tests/integrate/validation_tools/test_props_tddft.py diff --git a/source/source_io/module_ctrl/ctrl_output_td.cpp b/source/source_io/module_ctrl/ctrl_output_td.cpp index 78ca6fe34a9..bdc4282cf9e 100644 --- a/source/source_io/module_ctrl/ctrl_output_td.cpp +++ b/source/source_io/module_ctrl/ctrl_output_td.cpp @@ -51,7 +51,9 @@ void ctrl_output_td(const UnitCell& ucell, } else if (TD_info::out_current == 2) { - ModuleIO::write_current(ucell, grid, istep, psi, pelec, kv, pv, orb, td_p, p_hamilt->getSR(), p_hamilt->getHR(), exx_nao, exx_info); + const hamilt::HContainer* sR = p_hamilt->getSR(); + const std::vector*> spin_hR = p_hamilt->getHR_vector(); + ModuleIO::write_current(ucell, grid, istep, psi, pelec, kv, pv, orb, td_p, sR, spin_hR, exx_nao, exx_info); } #endif // __LCAO } diff --git a/source/source_io/module_current/td_current_io.h b/source/source_io/module_current/td_current_io.h index 69ce2dc0308..e0f85638c6d 100644 --- a/source/source_io/module_current/td_current_io.h +++ b/source/source_io/module_current/td_current_io.h @@ -53,7 +53,7 @@ void write_current( const LCAO_Orbitals& orb, TD_info* td_p, const hamilt::HContainer* sR, - const hamilt::HContainer* hR, + const std::vector*>& spin_hR, const Exx_NAO>& exx_nao, const Exx_Info& exx_info ); @@ -95,7 +95,7 @@ void cal_velocity_basis_k(const UnitCell& ucell, const K_Vectors& kv, const ModuleBase::Vector3*>& rR, const hamilt::HContainer& sR, - const hamilt::HContainer>& hR, + const std::vector>*>& spin_hR, std::vector*>>& velocity_basis_k); void cal_velocity_matrix(const psi::Psi>* psi, @@ -111,7 +111,7 @@ void cal_current_comm_k(const UnitCell& ucell, const K_Vectors& kv, TD_info* td_p, const hamilt::HContainer& sR, - const hamilt::HContainer>& hR, + const std::vector>*>& spin_hR, const psi::Psi>* psi, const elecstate::ElecState* pelec, std::vector>& current_k); diff --git a/source/source_io/module_current/td_current_io_comm.cpp b/source/source_io/module_current/td_current_io_comm.cpp index 12da24fd300..059dd69aa2f 100644 --- a/source/source_io/module_current/td_current_io_comm.cpp +++ b/source/source_io/module_current/td_current_io_comm.cpp @@ -12,6 +12,8 @@ #include "source_lcao/module_rt/td_folding.h" #include "source_lcao/module_rt/td_info.h" #include "td_current_io.h" +#include +#include #ifdef __EXX #include "source_lcao/module_operator_lcao/op_exx_lcao.h" #include "source_lcao/module_ri/exx_lri.h" @@ -257,7 +259,7 @@ void ModuleIO::cal_velocity_basis_k(const UnitCell& ucell, const K_Vectors& kv, const ModuleBase::Vector3*>& rR, const hamilt::HContainer& sR, - const hamilt::HContainer>& hR, + const std::vector>*>& spin_hR, std::vector*>>& velocity_basis_k) { ModuleBase::TITLE("ModuleIO", "cal_velocity_basis_k"); @@ -284,6 +286,7 @@ void ModuleIO::cal_velocity_basis_k(const UnitCell& ucell, for (size_t ik = 0; ik != kv.get_nks(); ++ik) { + const hamilt::HContainer>& hR = *spin_hR[kv.isk[ik]]; // set H(k), S(k) // 1.1 set H(k) ModuleBase::GlobalFunc::ZEROS(hk, pv->para_2d().size()); @@ -615,7 +618,7 @@ void ModuleIO::cal_current_comm_k(const UnitCell& ucell, const K_Vectors& kv, TD_info* td_p, const hamilt::HContainer& sR, - const hamilt::HContainer>& hR, + const std::vector>*>& spin_hR, const psi::Psi>* psi, const elecstate::ElecState* pelec, std::vector>& current_k) @@ -642,9 +645,9 @@ void ModuleIO::cal_current_comm_k(const UnitCell& ucell, } } // set rR - set_rR_from_hR(ucell, GridD, orb, pv, td_p->r_calculator, &hR, rR); + set_rR_from_hR(ucell, GridD, orb, pv, td_p->r_calculator, spin_hR.front(), rR); // set velocity_basis_k - cal_velocity_basis_k(ucell, td_p, orb, pv, kv, rR, sR, hR, velocity_basis_k); + cal_velocity_basis_k(ucell, td_p, orb, pv, kv, rR, sR, spin_hR, velocity_basis_k); // set velocity_k cal_velocity_matrix(psi, pv, kv, velocity_basis_k, velocity_k); @@ -689,7 +692,7 @@ void ModuleIO::write_current(const UnitCell& ucell, const LCAO_Orbitals& orb, TD_info* td_p, const hamilt::HContainer* sR, - const hamilt::HContainer* hR, + const std::vector*>& spin_hR, const Exx_NAO>& exx_nao, const Exx_Info& exx_info) { @@ -700,12 +703,19 @@ void ModuleIO::write_current(const UnitCell& ucell, double omega = ucell.omega; std::vector> current_k; - hamilt::HContainer>* full_hR; - full_hR = new hamilt::HContainer>(pv); + std::vector>>> full_hR; + std::vector>*> current_hR; + for (const hamilt::HContainer* hR : spin_hR) + { + std::unique_ptr>> matrix( + new hamilt::HContainer>(pv)); + hamilt::HContainer>* matrix_ptr = matrix.get(); + sum_HR(ucell, *pv, kv, hR, matrix_ptr, exx_nao, exx_info, *td_p); + current_hR.push_back(matrix_ptr); + full_hR.push_back(std::move(matrix)); + } current_k.resize(kv.get_nks()); - sum_HR(ucell, *pv, kv, hR, full_hR, exx_nao, exx_info, *td_p); - cal_current_comm_k(ucell, GridD, orb, pv, kv, td_p, *sR, *full_hR, psi, pelec, current_k); - delete full_hR; + cal_current_comm_k(ucell, GridD, orb, pv, kv, td_p, *sR, current_hR, psi, pelec, current_k); int nspin0 = 1; if (PARAM.inp.nspin == 2) @@ -772,7 +782,7 @@ template void ModuleIO::write_current(const UnitCell& ucell, const LCAO_Orbitals& orb, TD_info* td_p, const hamilt::HContainer* sR, - const hamilt::HContainer* hR, + const std::vector*>& spin_hR, const Exx_NAO>& exx_nao, const Exx_Info& exx_info); @@ -786,7 +796,7 @@ template void ModuleIO::write_current>(const UnitCell& ucel const LCAO_Orbitals& orb, TD_info* td_p, const hamilt::HContainer>* sR, - const hamilt::HContainer>* hR, + const std::vector>*>& spin_hR, const Exx_NAO>& exx_nao, const Exx_Info& exx_info); #endif //__LCAO diff --git a/tests/08_RI/CASES_CPU.txt b/tests/08_RI/CASES_CPU.txt index c783fa23296..1fb1345696a 100644 --- a/tests/08_RI/CASES_CPU.txt +++ b/tests/08_RI/CASES_CPU.txt @@ -22,6 +22,8 @@ rpa_scf_gamma rpa_scf_shrink_multik rt_tddft_pbe0_gamma rt_tddft_hse_spin2 +rt_tddft_hse_current_spin2_up +rt_tddft_hse_current_spin2_down bse_lr_multik nscf_hse_multik diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/INPUT b/tests/08_RI/rt_tddft_hse_current_spin2_down/INPUT new file mode 100644 index 00000000000..f6b143ef272 --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_down/INPUT @@ -0,0 +1,46 @@ +INPUT_PARAMETERS +calculation md +esolver_type tddft +md_type nve +estep_per_md 2 +td_dt 0.005 +md_tfirst 0 +td_vext 1 # add time-dependent external potential +td_vext_dire 3 # direction along z +td_stype 2 # 2: hybrid gauge +td_ttype 3 # Heaviside type potential +td_tstart 1 # the step electric field starts +td_tend 10 # the step electric field ends +td_heavi_t0 3 +td_heavi_amp 0.05 +pseudo_dir ../../PP_ORB +orbital_dir ../../PP_ORB +basis_type lcao +gamma_only 0 +ecutwfc 5 +ks_solver scalapack_gvx +mixing_type broyden +mixing_beta 0.7 +mixing_gg0 0.0 +dft_functional hse +exx_singularity_correction limits +symmetry -1 +suffix autotest +fixed_atoms 1 +cal_force 0 +dump_force 0 +scf_thr 1e-10 +scf_nmax 150 +md_restartfreq 1 +out_wfc_lcao 0 +out_app_flag 0 +out_freq_td 1 +out_efield 0 +out_vecpot 0 +out_current 2 +md_nstep 1 +nspin 2 +exx_real_number 0 +out_current_k 1 +nbands 8 +nupdown -2 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/KPT b/tests/08_RI/rt_tddft_hse_current_spin2_down/KPT new file mode 100644 index 00000000000..e769af76382 --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_down/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +2 1 1 0 0 0 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/README b/tests/08_RI/rt_tddft_hse_current_spin2_down/README new file mode 100644 index 00000000000..744d66c47b2 --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_down/README @@ -0,0 +1 @@ +Fixed-ion Si HSE/hybrid-gauge commutator current with negative collinear magnetization, paired with positive spin labels. diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/STRU b/tests/08_RI/rt_tddft_hse_current_spin2_down/STRU new file mode 100644 index 00000000000..cc56e752fed --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_down/STRU @@ -0,0 +1,22 @@ +ATOMIC_SPECIES +Si 28.085 Si_dojo_nsoc.upf + +NUMERICAL_ORBITAL +Si_dojo_6au_sz.orb + +LATTICE_CONSTANT +10.2 // add lattice constant + +LATTICE_VECTORS +0.0 0.5 0.5 +0.5 0.0 0.5 +0.5 0.5 0.0 + +ATOMIC_POSITIONS +Cartesian //Cartesian or Direct coordinate. + +Si // Element type +-1.0 // magnetism +2 // number of atoms +0.00 0.00 0.00 0 0 0 +0.25 0.25 0.25 0 0 0 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/current_tot.txt.ref b/tests/08_RI/rt_tddft_hse_current_spin2_down/current_tot.txt.ref new file mode 100644 index 00000000000..ccaf1d76b60 --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_down/current_tot.txt.ref @@ -0,0 +1,3 @@ + 1 -5.525676808421e-19 1.146558911433e-19 6.174713635629e-19 + 2 -3.460422088317e-07 3.460365070079e-07 1.360852686886e-06 + 3 6.189767465306e-07 -6.189864414175e-07 1.006325446354e-05 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/result.ref b/tests/08_RI/rt_tddft_hse_current_spin2_down/result.ref new file mode 100644 index 00000000000..0ab26ad4a4a --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_down/result.ref @@ -0,0 +1,4 @@ +etotref -190.6136470280634 +etotperatomref -95.3068235140317 +CompareCurrent_pass 0 +totaltimeref 1 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT b/tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT new file mode 100644 index 00000000000..e484e1b62c9 --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT @@ -0,0 +1,46 @@ +INPUT_PARAMETERS +calculation md +esolver_type tddft +md_type nve +estep_per_md 2 +td_dt 0.005 +md_tfirst 0 +td_vext 1 # add time-dependent external potential +td_vext_dire 3 # direction along z +td_stype 2 # 2: hybrid gauge +td_ttype 3 # Heaviside type potential +td_tstart 1 # the step electric field starts +td_tend 10 # the step electric field ends +td_heavi_t0 3 +td_heavi_amp 0.05 +pseudo_dir ../../PP_ORB +orbital_dir ../../PP_ORB +basis_type lcao +gamma_only 0 +ecutwfc 5 +ks_solver scalapack_gvx +mixing_type broyden +mixing_beta 0.7 +mixing_gg0 0.0 +dft_functional hse +exx_singularity_correction limits +symmetry -1 +suffix autotest +fixed_atoms 1 +cal_force 0 +dump_force 0 +scf_thr 1e-10 +scf_nmax 150 +md_restartfreq 1 +out_wfc_lcao 0 +out_app_flag 0 +out_freq_td 1 +out_efield 0 +out_vecpot 0 +out_current 2 +md_nstep 1 +nspin 2 +exx_real_number 0 +out_current_k 1 +nbands 8 +nupdown 2 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/KPT b/tests/08_RI/rt_tddft_hse_current_spin2_up/KPT new file mode 100644 index 00000000000..e769af76382 --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +2 1 1 0 0 0 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/README b/tests/08_RI/rt_tddft_hse_current_spin2_up/README new file mode 100644 index 00000000000..7c40b0e5be7 --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/README @@ -0,0 +1 @@ +Fixed-ion Si HSE/hybrid-gauge commutator current with positive collinear magnetization, paired with negative spin labels. diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/STRU b/tests/08_RI/rt_tddft_hse_current_spin2_up/STRU new file mode 100644 index 00000000000..9a24d623b6f --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/STRU @@ -0,0 +1,22 @@ +ATOMIC_SPECIES +Si 28.085 Si_dojo_nsoc.upf + +NUMERICAL_ORBITAL +Si_dojo_6au_sz.orb + +LATTICE_CONSTANT +10.2 // add lattice constant + +LATTICE_VECTORS +0.0 0.5 0.5 +0.5 0.0 0.5 +0.5 0.5 0.0 + +ATOMIC_POSITIONS +Cartesian //Cartesian or Direct coordinate. + +Si // Element type +1.0 // magnetism +2 // number of atoms +0.00 0.00 0.00 0 0 0 +0.25 0.25 0.25 0 0 0 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref b/tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref new file mode 100644 index 00000000000..1e86916b60c --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref @@ -0,0 +1,3 @@ + 1 -2.729262929987e-19 -3.600416917338e-19 8.454553031081e-19 + 2 -3.460422087726e-07 3.460365070477e-07 1.360852686906e-06 + 3 6.189767466041e-07 -6.189864413709e-07 1.006325446346e-05 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref b/tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref new file mode 100644 index 00000000000..0ab26ad4a4a --- /dev/null +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref @@ -0,0 +1,4 @@ +etotref -190.6136470280634 +etotperatomref -95.3068235140317 +CompareCurrent_pass 0 +totaltimeref 1 diff --git a/tests/integrate/CMakeLists.txt b/tests/integrate/CMakeLists.txt index c07cf70b4fa..243a215ee00 100644 --- a/tests/integrate/CMakeLists.txt +++ b/tests/integrate/CMakeLists.txt @@ -32,4 +32,9 @@ if(LR_FORCE_TEST_PYTHON) COMMAND ${LR_FORCE_TEST_PYTHON} -m unittest discover -s ${CMAKE_CURRENT_SOURCE_DIR}/validation_tools -p test_props_basic.py) set_tests_properties(md_force_collector PROPERTIES TIMEOUT 30) + add_test( + NAME td_current_collector + COMMAND ${LR_FORCE_TEST_PYTHON} -m unittest discover -s + ${CMAKE_CURRENT_SOURCE_DIR}/validation_tools -p test_props_tddft.py) + set_tests_properties(td_current_collector PROPERTIES TIMEOUT 30) endif() diff --git a/tests/integrate/validation_tools/props_tddft.sh b/tests/integrate/validation_tools/props_tddft.sh index e9af976d15a..d65135f27fa 100644 --- a/tests/integrate/validation_tools/props_tddft.sh +++ b/tests/integrate/validation_tools/props_tddft.sh @@ -24,6 +24,9 @@ run_tddft_props() { if ! test -z "$out_current" && [ $out_current ]; then current1ref=current_tot.txt.ref current1cal=OUT.autotest/current_tot.txt + if [ "$out_current" == 2 ]; then + current1cal=OUT.autotest/current_tot_comm.txt + fi local current_tol=1e-10 if [ -f threshold ]; then local configured_tol diff --git a/tests/integrate/validation_tools/test_props_tddft.py b/tests/integrate/validation_tools/test_props_tddft.py new file mode 100644 index 00000000000..63e16bb07ee --- /dev/null +++ b/tests/integrate/validation_tools/test_props_tddft.py @@ -0,0 +1,43 @@ +"""Check selection of the current output file in the Autotest collector.""" +from pathlib import Path +import subprocess +import tempfile +import unittest + +TOOLS = Path(__file__).resolve().parent + + +class CurrentCollectionTest(unittest.TestCase): + def collect(self, mode, missing=False): + with tempfile.TemporaryDirectory(prefix="abacus-current-collector-") as scratch: + case = Path(scratch) + output = case / "OUT.autotest" + output.mkdir() + (case / "current_tot.txt.ref").write_text("1 0.1 0.2 0.3\n", encoding="utf-8") + selected = "current_tot_comm.txt" if mode == 2 else "current_tot.txt" + for filename in ("current_tot.txt", "current_tot_comm.txt"): + if filename == selected and missing: + continue + values = "1 0.1 0.2 0.3\n" if filename == selected else "1 9 9 9\n" + (output / filename).write_text(values, encoding="utf-8") + command = ('source "$1"; source "$2"; props_result_file=result.out; ' + 'out_current="$3"; run_tddft_props') + result = subprocess.run( + ["bash", "-c", command, "current-test", str(TOOLS / "props_common.sh"), + str(TOOLS / "props_tddft.sh"), str(mode)], cwd=case, + capture_output=True, text=True, check=False) + self.assertEqual(result.returncode, 0, result.stderr) + return (case / "result.out").read_text(encoding="utf-8") + + def test_velocity_current_file(self): + self.assertIn("CompareCurrent_pass 0", self.collect(1)) + + def test_commutator_current_file(self): + self.assertIn("CompareCurrent_pass 0", self.collect(2)) + + def test_missing_commutator_current_fails(self): + self.assertIn("CompareCurrent_pass 1", self.collect(2, missing=True)) + + +if __name__ == "__main__": + unittest.main() From a0612f0ecb2982c03ea1f980a9d739c0f939252a Mon Sep 17 00:00:00 2001 From: memii-x Date: Mon, 16 Nov 2026 20:39:42 +0800 Subject: [PATCH 2/4] fix(rt): preserve shared Hamiltonian with local potential disabled --- source/source_lcao/hamilt_lcao.cpp | 4 ++ source/source_lcao/hamilt_lcao.h | 2 +- tests/08_RI/CASES_CPU.txt | 1 + tests/08_RI/rt_tddft_pbe_current_shared/INPUT | 45 +++++++++++++++++++ tests/08_RI/rt_tddft_pbe_current_shared/KPT | 4 ++ .../08_RI/rt_tddft_pbe_current_shared/README | 1 + tests/08_RI/rt_tddft_pbe_current_shared/STRU | 22 +++++++++ .../current_tot.txt.ref | 3 ++ .../rt_tddft_pbe_current_shared/result.ref | 4 ++ 9 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/INPUT create mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/KPT create mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/README create mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/STRU create mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/current_tot.txt.ref create mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/result.ref diff --git a/source/source_lcao/hamilt_lcao.cpp b/source/source_lcao/hamilt_lcao.cpp index 0949d98882d..292e71b42e5 100644 --- a/source/source_lcao/hamilt_lcao.cpp +++ b/source/source_lcao/hamilt_lcao.cpp @@ -177,6 +177,10 @@ std::vector*> HamiltLCAO::getHR_vector() TR* down_data = up_data + nnr; this->hr_spin_up_.reset(new HContainer(*this->hR, up_data)); this->hr_spin_dn_.reset(new HContainer(*this->hR, down_data)); + if (!this->vl_in_h) + { + return {this->hR.get(), this->hR.get()}; + } return {this->hr_spin_up_.get(), this->hr_spin_dn_.get()}; } else diff --git a/source/source_lcao/hamilt_lcao.h b/source/source_lcao/hamilt_lcao.h index e446ba5cd75..34851746159 100644 --- a/source/source_lcao/hamilt_lcao.h +++ b/source/source_lcao/hamilt_lcao.h @@ -148,7 +148,7 @@ class HamiltLCAO : public Hamilt std::vector& getHRS2() { return this->hRS2; } /// Get HR as a vector of HContainer pointers (one per spin). - /// For nspin=2, returns pointers to internally managed per-spin wrappers over hRS2. + /// For nspin=2, vl_in_h=0 shares the active H(R), matching updateHk. /// Returned pointers are owned by this class; caller must NOT delete them. std::vector*> getHR_vector(); diff --git a/tests/08_RI/CASES_CPU.txt b/tests/08_RI/CASES_CPU.txt index 1fb1345696a..69bc6483aa2 100644 --- a/tests/08_RI/CASES_CPU.txt +++ b/tests/08_RI/CASES_CPU.txt @@ -24,6 +24,7 @@ rt_tddft_pbe0_gamma rt_tddft_hse_spin2 rt_tddft_hse_current_spin2_up rt_tddft_hse_current_spin2_down +rt_tddft_pbe_current_shared bse_lr_multik nscf_hse_multik diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/INPUT b/tests/08_RI/rt_tddft_pbe_current_shared/INPUT new file mode 100644 index 00000000000..2874d265646 --- /dev/null +++ b/tests/08_RI/rt_tddft_pbe_current_shared/INPUT @@ -0,0 +1,45 @@ +INPUT_PARAMETERS +calculation md +esolver_type tddft +md_type nve +estep_per_md 2 +td_dt 0.005 +md_tfirst 0 +td_vext 1 # add time-dependent external potential +td_vext_dire 3 # direction along z +td_stype 2 # 2: hybrid gauge +td_ttype 3 # Heaviside type potential +td_tstart 1 # the step electric field starts +td_tend 10 # the step electric field ends +td_heavi_t0 3 +td_heavi_amp 0.05 +pseudo_dir ../../PP_ORB +orbital_dir ../../PP_ORB +basis_type lcao +gamma_only 0 +ecutwfc 5 +ks_solver scalapack_gvx +mixing_type broyden +mixing_beta 0.7 +mixing_gg0 0.0 +dft_functional pbe +symmetry -1 +suffix autotest +fixed_atoms 1 +cal_force 0 +dump_force 0 +scf_thr 1e-10 +scf_nmax 150 +md_restartfreq 1 +out_wfc_lcao 0 +out_app_flag 0 +out_freq_td 1 +out_efield 0 +out_vecpot 0 +out_current 2 +md_nstep 1 +nspin 2 +out_current_k 1 +nbands 8 +nupdown 0 +vl_in_h 0 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/KPT b/tests/08_RI/rt_tddft_pbe_current_shared/KPT new file mode 100644 index 00000000000..e769af76382 --- /dev/null +++ b/tests/08_RI/rt_tddft_pbe_current_shared/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +2 1 1 0 0 0 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/README b/tests/08_RI/rt_tddft_pbe_current_shared/README new file mode 100644 index 00000000000..b12fe1a3968 --- /dev/null +++ b/tests/08_RI/rt_tddft_pbe_current_shared/README @@ -0,0 +1 @@ +Fixed-ion Si PBE/hybrid-gauge commutator current with nspin=2 and vl_in_h=0 preserves the shared Hamiltonian for both spins. diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/STRU b/tests/08_RI/rt_tddft_pbe_current_shared/STRU new file mode 100644 index 00000000000..833604ed247 --- /dev/null +++ b/tests/08_RI/rt_tddft_pbe_current_shared/STRU @@ -0,0 +1,22 @@ +ATOMIC_SPECIES +Si 28.085 Si_dojo_nsoc.upf + +NUMERICAL_ORBITAL +Si_dojo_6au_sz.orb + +LATTICE_CONSTANT +10.2 // add lattice constant + +LATTICE_VECTORS +0.0 0.5 0.5 +0.5 0.0 0.5 +0.5 0.5 0.0 + +ATOMIC_POSITIONS +Cartesian //Cartesian or Direct coordinate. + +Si // Element type +0.0 // magnetism +2 // number of atoms +0.00 0.00 0.00 0 0 0 +0.25 0.25 0.25 0 0 0 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/current_tot.txt.ref b/tests/08_RI/rt_tddft_pbe_current_shared/current_tot.txt.ref new file mode 100644 index 00000000000..0c7039c5812 --- /dev/null +++ b/tests/08_RI/rt_tddft_pbe_current_shared/current_tot.txt.ref @@ -0,0 +1,3 @@ + 1 -3.835315875924e-20 3.835315875924e-20 3.835315875924e-20 + 2 -1.251798101654e-19 2.576065252068e-19 -2.934667798613e-19 + 3 2.143991800188e-06 -2.143976741853e-06 9.938600352823e-06 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/result.ref b/tests/08_RI/rt_tddft_pbe_current_shared/result.ref new file mode 100644 index 00000000000..87b7bc32ad0 --- /dev/null +++ b/tests/08_RI/rt_tddft_pbe_current_shared/result.ref @@ -0,0 +1,4 @@ +etotref -49.33792934120299 +etotperatomref -24.668964670601493 +CompareCurrent_pass 0 +totaltimeref 1 From 58c797f99a5e4dee71a503c78616ce1a0b6f9923 Mon Sep 17 00:00:00 2001 From: memii-x Date: Mon, 16 Nov 2026 23:48:35 +0800 Subject: [PATCH 3/4] test(rt): reject incomplete current output in collector --- .../integrate/validation_tools/props_tddft.sh | 14 ++++++-- .../validation_tools/test_props_tddft.py | 32 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/tests/integrate/validation_tools/props_tddft.sh b/tests/integrate/validation_tools/props_tddft.sh index d65135f27fa..9fff21f4907 100644 --- a/tests/integrate/validation_tools/props_tddft.sh +++ b/tests/integrate/validation_tools/props_tddft.sh @@ -35,8 +35,18 @@ run_tddft_props() { current_tol=$configured_tol fi fi - python3 "$COMPARE_SCRIPT" "$current1ref" "$current1cal" -tol "$current_tol" - echo "CompareCurrent_pass $?" >>$props_result_file + local current_status=1 + if [ -f "$current1ref" ] && [ -f "$current1cal" ]; then + local reference_rows + local current_rows + reference_rows=$(awk 'NF { count++ } END { print count+0 }' "$current1ref") + current_rows=$(awk 'NF { count++ } END { print count+0 }' "$current1cal") + if [ "$reference_rows" -gt 0 ] && [ "$current_rows" -ge "$reference_rows" ]; then + python3 "$COMPARE_SCRIPT" "$current1ref" "$current1cal" -tol "$current_tol" + current_status=$? + fi + fi + echo "CompareCurrent_pass $current_status" >>$props_result_file fi #-------------------------------------------- diff --git a/tests/integrate/validation_tools/test_props_tddft.py b/tests/integrate/validation_tools/test_props_tddft.py index 63e16bb07ee..d716b77515f 100644 --- a/tests/integrate/validation_tools/test_props_tddft.py +++ b/tests/integrate/validation_tools/test_props_tddft.py @@ -1,24 +1,27 @@ -"""Check selection of the current output file in the Autotest collector.""" +"""Check current output selection and completeness in the Autotest collector.""" from pathlib import Path import subprocess import tempfile import unittest TOOLS = Path(__file__).resolve().parent +CURRENT = "1 0 0 0\n2 0 0 0\n3 0.1 0.2 0.3\n" class CurrentCollectionTest(unittest.TestCase): - def collect(self, mode, missing=False): + def collect(self, mode, missing=False, current=None, reference=CURRENT): with tempfile.TemporaryDirectory(prefix="abacus-current-collector-") as scratch: case = Path(scratch) output = case / "OUT.autotest" output.mkdir() - (case / "current_tot.txt.ref").write_text("1 0.1 0.2 0.3\n", encoding="utf-8") + (case / "current_tot.txt.ref").write_text(reference, encoding="utf-8") selected = "current_tot_comm.txt" if mode == 2 else "current_tot.txt" for filename in ("current_tot.txt", "current_tot_comm.txt"): if filename == selected and missing: continue - values = "1 0.1 0.2 0.3\n" if filename == selected else "1 9 9 9\n" + values = CURRENT if current is None else current + if filename != selected: + values = "1 9 9 9\n2 9 9 9\n3 9 9 9\n" (output / filename).write_text(values, encoding="utf-8") command = ('source "$1"; source "$2"; props_result_file=result.out; ' 'out_current="$3"; run_tddft_props') @@ -38,6 +41,27 @@ def test_commutator_current_file(self): def test_missing_commutator_current_fails(self): self.assertIn("CompareCurrent_pass 1", self.collect(2, missing=True)) + def test_empty_current_fails(self): + for mode in (1, 2): + with self.subTest(mode=mode): + self.assertIn("CompareCurrent_pass 1", self.collect(mode, current="")) + + def test_truncated_current_fails(self): + for mode in (1, 2): + for rows in (1, 2): + with self.subTest(mode=mode, rows=rows): + current = "\n".join(CURRENT.splitlines()[:rows]) + "\n" + self.assertIn("CompareCurrent_pass 1", self.collect(mode, current=current)) + + def test_empty_reference_fails(self): + self.assertIn("CompareCurrent_pass 1", self.collect(2, reference="")) + + def test_complete_current_without_final_newline(self): + self.assertIn("CompareCurrent_pass 0", self.collect(2, current=CURRENT.rstrip("\n"))) + + def test_longer_current_keeps_reference_prefix(self): + self.assertIn("CompareCurrent_pass 0", self.collect(2, current=CURRENT + "4 0.4 0.5 0.6\n")) + if __name__ == "__main__": unittest.main() From b361de08b9e94b71c498dce8deda6caa01911f89 Mon Sep 17 00:00:00 2001 From: memii-x Date: Thu, 19 Nov 2026 22:32:00 +0800 Subject: [PATCH 4/4] test(rt): streamline the spin-current regression --- tests/08_RI/CASES_CPU.txt | 2 - .../rt_tddft_hse_current_spin2_down/INPUT | 46 ------------- .../08_RI/rt_tddft_hse_current_spin2_down/KPT | 4 -- .../rt_tddft_hse_current_spin2_down/README | 1 - .../rt_tddft_hse_current_spin2_down/STRU | 22 ------ .../current_tot.txt.ref | 3 - .../result.ref | 4 -- .../08_RI/rt_tddft_hse_current_spin2_up/INPUT | 2 +- .../rt_tddft_hse_current_spin2_up/README | 2 +- .../current_tot.txt.ref | 6 +- .../rt_tddft_hse_current_spin2_up/result.ref | 4 +- tests/08_RI/rt_tddft_pbe_current_shared/INPUT | 45 ------------- tests/08_RI/rt_tddft_pbe_current_shared/KPT | 4 -- .../08_RI/rt_tddft_pbe_current_shared/README | 1 - tests/08_RI/rt_tddft_pbe_current_shared/STRU | 22 ------ .../current_tot.txt.ref | 3 - .../rt_tddft_pbe_current_shared/result.ref | 4 -- tests/integrate/CMakeLists.txt | 5 -- .../validation_tools/test_props_tddft.py | 67 ------------------- 19 files changed, 7 insertions(+), 240 deletions(-) delete mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/INPUT delete mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/KPT delete mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/README delete mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/STRU delete mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/current_tot.txt.ref delete mode 100644 tests/08_RI/rt_tddft_hse_current_spin2_down/result.ref delete mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/INPUT delete mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/KPT delete mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/README delete mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/STRU delete mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/current_tot.txt.ref delete mode 100644 tests/08_RI/rt_tddft_pbe_current_shared/result.ref delete mode 100644 tests/integrate/validation_tools/test_props_tddft.py diff --git a/tests/08_RI/CASES_CPU.txt b/tests/08_RI/CASES_CPU.txt index 69bc6483aa2..1c51dd45fd3 100644 --- a/tests/08_RI/CASES_CPU.txt +++ b/tests/08_RI/CASES_CPU.txt @@ -23,8 +23,6 @@ rpa_scf_shrink_multik rt_tddft_pbe0_gamma rt_tddft_hse_spin2 rt_tddft_hse_current_spin2_up -rt_tddft_hse_current_spin2_down -rt_tddft_pbe_current_shared bse_lr_multik nscf_hse_multik diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/INPUT b/tests/08_RI/rt_tddft_hse_current_spin2_down/INPUT deleted file mode 100644 index f6b143ef272..00000000000 --- a/tests/08_RI/rt_tddft_hse_current_spin2_down/INPUT +++ /dev/null @@ -1,46 +0,0 @@ -INPUT_PARAMETERS -calculation md -esolver_type tddft -md_type nve -estep_per_md 2 -td_dt 0.005 -md_tfirst 0 -td_vext 1 # add time-dependent external potential -td_vext_dire 3 # direction along z -td_stype 2 # 2: hybrid gauge -td_ttype 3 # Heaviside type potential -td_tstart 1 # the step electric field starts -td_tend 10 # the step electric field ends -td_heavi_t0 3 -td_heavi_amp 0.05 -pseudo_dir ../../PP_ORB -orbital_dir ../../PP_ORB -basis_type lcao -gamma_only 0 -ecutwfc 5 -ks_solver scalapack_gvx -mixing_type broyden -mixing_beta 0.7 -mixing_gg0 0.0 -dft_functional hse -exx_singularity_correction limits -symmetry -1 -suffix autotest -fixed_atoms 1 -cal_force 0 -dump_force 0 -scf_thr 1e-10 -scf_nmax 150 -md_restartfreq 1 -out_wfc_lcao 0 -out_app_flag 0 -out_freq_td 1 -out_efield 0 -out_vecpot 0 -out_current 2 -md_nstep 1 -nspin 2 -exx_real_number 0 -out_current_k 1 -nbands 8 -nupdown -2 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/KPT b/tests/08_RI/rt_tddft_hse_current_spin2_down/KPT deleted file mode 100644 index e769af76382..00000000000 --- a/tests/08_RI/rt_tddft_hse_current_spin2_down/KPT +++ /dev/null @@ -1,4 +0,0 @@ -K_POINTS -0 -Gamma -2 1 1 0 0 0 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/README b/tests/08_RI/rt_tddft_hse_current_spin2_down/README deleted file mode 100644 index 744d66c47b2..00000000000 --- a/tests/08_RI/rt_tddft_hse_current_spin2_down/README +++ /dev/null @@ -1 +0,0 @@ -Fixed-ion Si HSE/hybrid-gauge commutator current with negative collinear magnetization, paired with positive spin labels. diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/STRU b/tests/08_RI/rt_tddft_hse_current_spin2_down/STRU deleted file mode 100644 index cc56e752fed..00000000000 --- a/tests/08_RI/rt_tddft_hse_current_spin2_down/STRU +++ /dev/null @@ -1,22 +0,0 @@ -ATOMIC_SPECIES -Si 28.085 Si_dojo_nsoc.upf - -NUMERICAL_ORBITAL -Si_dojo_6au_sz.orb - -LATTICE_CONSTANT -10.2 // add lattice constant - -LATTICE_VECTORS -0.0 0.5 0.5 -0.5 0.0 0.5 -0.5 0.5 0.0 - -ATOMIC_POSITIONS -Cartesian //Cartesian or Direct coordinate. - -Si // Element type --1.0 // magnetism -2 // number of atoms -0.00 0.00 0.00 0 0 0 -0.25 0.25 0.25 0 0 0 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/current_tot.txt.ref b/tests/08_RI/rt_tddft_hse_current_spin2_down/current_tot.txt.ref deleted file mode 100644 index ccaf1d76b60..00000000000 --- a/tests/08_RI/rt_tddft_hse_current_spin2_down/current_tot.txt.ref +++ /dev/null @@ -1,3 +0,0 @@ - 1 -5.525676808421e-19 1.146558911433e-19 6.174713635629e-19 - 2 -3.460422088317e-07 3.460365070079e-07 1.360852686886e-06 - 3 6.189767465306e-07 -6.189864414175e-07 1.006325446354e-05 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_down/result.ref b/tests/08_RI/rt_tddft_hse_current_spin2_down/result.ref deleted file mode 100644 index 0ab26ad4a4a..00000000000 --- a/tests/08_RI/rt_tddft_hse_current_spin2_down/result.ref +++ /dev/null @@ -1,4 +0,0 @@ -etotref -190.6136470280634 -etotperatomref -95.3068235140317 -CompareCurrent_pass 0 -totaltimeref 1 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT b/tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT index e484e1b62c9..52c1da78378 100644 --- a/tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/INPUT @@ -29,7 +29,7 @@ suffix autotest fixed_atoms 1 cal_force 0 dump_force 0 -scf_thr 1e-10 +scf_thr 1e-6 scf_nmax 150 md_restartfreq 1 out_wfc_lcao 0 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/README b/tests/08_RI/rt_tddft_hse_current_spin2_up/README index 7c40b0e5be7..cdb6ec114c6 100644 --- a/tests/08_RI/rt_tddft_hse_current_spin2_up/README +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/README @@ -1 +1 @@ -Fixed-ion Si HSE/hybrid-gauge commutator current with positive collinear magnetization, paired with negative spin labels. +Fixed-ion Si HSE/hybrid-gauge commutator current with collinear spin polarization. diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref b/tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref index 1e86916b60c..ab31681f0fb 100644 --- a/tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/current_tot.txt.ref @@ -1,3 +1,3 @@ - 1 -2.729262929987e-19 -3.600416917338e-19 8.454553031081e-19 - 2 -3.460422087726e-07 3.460365070477e-07 1.360852686906e-06 - 3 6.189767466041e-07 -6.189864413709e-07 1.006325446346e-05 + 1 -4.089080634814e-19 4.090305385391e-19 4.090942654256e-19 + 2 -3.550737228392e-07 3.550678480581e-07 1.373779434519e-06 + 3 6.311340786252e-07 -6.311437488938e-07 1.015098378634e-05 diff --git a/tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref b/tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref index 0ab26ad4a4a..d1448e523d4 100644 --- a/tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref +++ b/tests/08_RI/rt_tddft_hse_current_spin2_up/result.ref @@ -1,4 +1,4 @@ -etotref -190.6136470280634 -etotperatomref -95.3068235140317 +etotref -190.6136471104446 +etotperatomref -95.3068235552 CompareCurrent_pass 0 totaltimeref 1 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/INPUT b/tests/08_RI/rt_tddft_pbe_current_shared/INPUT deleted file mode 100644 index 2874d265646..00000000000 --- a/tests/08_RI/rt_tddft_pbe_current_shared/INPUT +++ /dev/null @@ -1,45 +0,0 @@ -INPUT_PARAMETERS -calculation md -esolver_type tddft -md_type nve -estep_per_md 2 -td_dt 0.005 -md_tfirst 0 -td_vext 1 # add time-dependent external potential -td_vext_dire 3 # direction along z -td_stype 2 # 2: hybrid gauge -td_ttype 3 # Heaviside type potential -td_tstart 1 # the step electric field starts -td_tend 10 # the step electric field ends -td_heavi_t0 3 -td_heavi_amp 0.05 -pseudo_dir ../../PP_ORB -orbital_dir ../../PP_ORB -basis_type lcao -gamma_only 0 -ecutwfc 5 -ks_solver scalapack_gvx -mixing_type broyden -mixing_beta 0.7 -mixing_gg0 0.0 -dft_functional pbe -symmetry -1 -suffix autotest -fixed_atoms 1 -cal_force 0 -dump_force 0 -scf_thr 1e-10 -scf_nmax 150 -md_restartfreq 1 -out_wfc_lcao 0 -out_app_flag 0 -out_freq_td 1 -out_efield 0 -out_vecpot 0 -out_current 2 -md_nstep 1 -nspin 2 -out_current_k 1 -nbands 8 -nupdown 0 -vl_in_h 0 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/KPT b/tests/08_RI/rt_tddft_pbe_current_shared/KPT deleted file mode 100644 index e769af76382..00000000000 --- a/tests/08_RI/rt_tddft_pbe_current_shared/KPT +++ /dev/null @@ -1,4 +0,0 @@ -K_POINTS -0 -Gamma -2 1 1 0 0 0 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/README b/tests/08_RI/rt_tddft_pbe_current_shared/README deleted file mode 100644 index b12fe1a3968..00000000000 --- a/tests/08_RI/rt_tddft_pbe_current_shared/README +++ /dev/null @@ -1 +0,0 @@ -Fixed-ion Si PBE/hybrid-gauge commutator current with nspin=2 and vl_in_h=0 preserves the shared Hamiltonian for both spins. diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/STRU b/tests/08_RI/rt_tddft_pbe_current_shared/STRU deleted file mode 100644 index 833604ed247..00000000000 --- a/tests/08_RI/rt_tddft_pbe_current_shared/STRU +++ /dev/null @@ -1,22 +0,0 @@ -ATOMIC_SPECIES -Si 28.085 Si_dojo_nsoc.upf - -NUMERICAL_ORBITAL -Si_dojo_6au_sz.orb - -LATTICE_CONSTANT -10.2 // add lattice constant - -LATTICE_VECTORS -0.0 0.5 0.5 -0.5 0.0 0.5 -0.5 0.5 0.0 - -ATOMIC_POSITIONS -Cartesian //Cartesian or Direct coordinate. - -Si // Element type -0.0 // magnetism -2 // number of atoms -0.00 0.00 0.00 0 0 0 -0.25 0.25 0.25 0 0 0 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/current_tot.txt.ref b/tests/08_RI/rt_tddft_pbe_current_shared/current_tot.txt.ref deleted file mode 100644 index 0c7039c5812..00000000000 --- a/tests/08_RI/rt_tddft_pbe_current_shared/current_tot.txt.ref +++ /dev/null @@ -1,3 +0,0 @@ - 1 -3.835315875924e-20 3.835315875924e-20 3.835315875924e-20 - 2 -1.251798101654e-19 2.576065252068e-19 -2.934667798613e-19 - 3 2.143991800188e-06 -2.143976741853e-06 9.938600352823e-06 diff --git a/tests/08_RI/rt_tddft_pbe_current_shared/result.ref b/tests/08_RI/rt_tddft_pbe_current_shared/result.ref deleted file mode 100644 index 87b7bc32ad0..00000000000 --- a/tests/08_RI/rt_tddft_pbe_current_shared/result.ref +++ /dev/null @@ -1,4 +0,0 @@ -etotref -49.33792934120299 -etotperatomref -24.668964670601493 -CompareCurrent_pass 0 -totaltimeref 1 diff --git a/tests/integrate/CMakeLists.txt b/tests/integrate/CMakeLists.txt index 243a215ee00..c07cf70b4fa 100644 --- a/tests/integrate/CMakeLists.txt +++ b/tests/integrate/CMakeLists.txt @@ -32,9 +32,4 @@ if(LR_FORCE_TEST_PYTHON) COMMAND ${LR_FORCE_TEST_PYTHON} -m unittest discover -s ${CMAKE_CURRENT_SOURCE_DIR}/validation_tools -p test_props_basic.py) set_tests_properties(md_force_collector PROPERTIES TIMEOUT 30) - add_test( - NAME td_current_collector - COMMAND ${LR_FORCE_TEST_PYTHON} -m unittest discover -s - ${CMAKE_CURRENT_SOURCE_DIR}/validation_tools -p test_props_tddft.py) - set_tests_properties(td_current_collector PROPERTIES TIMEOUT 30) endif() diff --git a/tests/integrate/validation_tools/test_props_tddft.py b/tests/integrate/validation_tools/test_props_tddft.py deleted file mode 100644 index d716b77515f..00000000000 --- a/tests/integrate/validation_tools/test_props_tddft.py +++ /dev/null @@ -1,67 +0,0 @@ -"""Check current output selection and completeness in the Autotest collector.""" -from pathlib import Path -import subprocess -import tempfile -import unittest - -TOOLS = Path(__file__).resolve().parent -CURRENT = "1 0 0 0\n2 0 0 0\n3 0.1 0.2 0.3\n" - - -class CurrentCollectionTest(unittest.TestCase): - def collect(self, mode, missing=False, current=None, reference=CURRENT): - with tempfile.TemporaryDirectory(prefix="abacus-current-collector-") as scratch: - case = Path(scratch) - output = case / "OUT.autotest" - output.mkdir() - (case / "current_tot.txt.ref").write_text(reference, encoding="utf-8") - selected = "current_tot_comm.txt" if mode == 2 else "current_tot.txt" - for filename in ("current_tot.txt", "current_tot_comm.txt"): - if filename == selected and missing: - continue - values = CURRENT if current is None else current - if filename != selected: - values = "1 9 9 9\n2 9 9 9\n3 9 9 9\n" - (output / filename).write_text(values, encoding="utf-8") - command = ('source "$1"; source "$2"; props_result_file=result.out; ' - 'out_current="$3"; run_tddft_props') - result = subprocess.run( - ["bash", "-c", command, "current-test", str(TOOLS / "props_common.sh"), - str(TOOLS / "props_tddft.sh"), str(mode)], cwd=case, - capture_output=True, text=True, check=False) - self.assertEqual(result.returncode, 0, result.stderr) - return (case / "result.out").read_text(encoding="utf-8") - - def test_velocity_current_file(self): - self.assertIn("CompareCurrent_pass 0", self.collect(1)) - - def test_commutator_current_file(self): - self.assertIn("CompareCurrent_pass 0", self.collect(2)) - - def test_missing_commutator_current_fails(self): - self.assertIn("CompareCurrent_pass 1", self.collect(2, missing=True)) - - def test_empty_current_fails(self): - for mode in (1, 2): - with self.subTest(mode=mode): - self.assertIn("CompareCurrent_pass 1", self.collect(mode, current="")) - - def test_truncated_current_fails(self): - for mode in (1, 2): - for rows in (1, 2): - with self.subTest(mode=mode, rows=rows): - current = "\n".join(CURRENT.splitlines()[:rows]) + "\n" - self.assertIn("CompareCurrent_pass 1", self.collect(mode, current=current)) - - def test_empty_reference_fails(self): - self.assertIn("CompareCurrent_pass 1", self.collect(2, reference="")) - - def test_complete_current_without_final_newline(self): - self.assertIn("CompareCurrent_pass 0", self.collect(2, current=CURRENT.rstrip("\n"))) - - def test_longer_current_keeps_reference_prefix(self): - self.assertIn("CompareCurrent_pass 0", self.collect(2, current=CURRENT + "4 0.4 0.5 0.6\n")) - - -if __name__ == "__main__": - unittest.main()