Repository navigation
[Dependency] Structure_Factor and Soc live in source_pw, but source_psi, source_estate and source_hamilt depend on them #8233
Copy link
Copy link
Closed
Labels
RefactorRefactor ABACUS codesRefactor ABACUS codes
Description
Describe the Code Quality Issue
Structure_Factor and Soc live in source_pw/module_pwdft, but they are not plane-wave method code, and lower layers depend on them:
Structure_Factorholds the structure factor S(G) = Σ exp(−iG·τ) and the phase factors exp(−iG·τ) per atom. It is the Fourier representation of the atomic positions, i.e. geometry.ESolver_FPowns it (source_esolver/esolver_fp.h:78) for every basis type, and LCAO code uses it too.Socholds the spin–angular coupling coefficients of the pseudopotentials, i.e. atomic data. It depends only onsource_base.- The
cal_sk_opkernel (source_pw/module_pwdft/kernels/wf_op.h, with CPU, CUDA and ROCm implementations) computes the same phase factors from atom positions forStructure_Factor::get_sk.
The potential form factors (vl_pw, vnl_pw, vsep_pw) are basis-specific and do belong in source_pw. Together with S(G) they give V(G) = Σ S(G)·v(G).
Because of this placement, lower layers include source_pw:
source_psi→source_pw(the wavefunction initializers need S(G) andSoc):psi_base.cpp:6psi_init_atomic.cpp:13(soc.h),:14psi_init_nao.cpp:5psi_prepare.cpp:23setup_psi_pw.cpp:7setup_psi_pw.h:11
source_estate→source_pw:module_charge/chg_extra.h:9,module_pot/potential_new.h:7,setup_estate_pw.h:6source_hamilt→source_pw:module_surchem/cal_pseudo.cpp:3
Also, kernels/wf_op.h:5 includes source_psi/psi.h but uses nothing from it, only the base_device tags.
Suggested fix
- Move
stru_fac.h,stru_fac.cpp,stru_fac_k.cpp,soc.handsoc.cpptosource_cell/.Structure_Factorneeds onlysource_base,source_basis/module_pwandsource_cell, andsource_cellalready sits abovesource_basis(source_basisincludes nothing fromsource_cell). - Move the
cal_sk_opkernel with them, tosource_cell/kernels/, and drop the unusedpsi.hinclude. - Leave forwarding headers at the old paths, so the higher-layer includers (
source_pw,source_lcao,source_esolver,source_io) need no change in the same PR. Only the lower-layer files listed above change their include line. - Update the build lists: the
source_pw/module_pwdft,source_celland kernel lists in CMake, the unit-test lists that compile these files, andsource/Makefile.Objects.
No behavior change should result.
Acceptance
source_psi,source_estateandsource_hamiltno longer includestru_fac.horsoc.hfromsource_pw.- The CPU, CUDA and ROCm builds compile, with and without LCAO.
- Unit tests pass, plus the
01_PW,02_NAO_Gammaand03_NAO_multikintegration suites.
Additional Context
- Part of [Dependency] Wavefunction container
source_psidepending back on higher layers #7601 and [Dependency] Operator layersource_hamiltdepending back on electronic state/methods #7599. - After this,
source_psistill includessource_hamilt,source_hsolverandsource_pwthroughpsi_prepareandsetup_psi_pw. Those two classes are the PW method's initialization step (they build aHamiltHSOperatorand callDiagoIterAssist::diag_subspace) and should move tosource_pwin a separate change. Structure_Factor::Structure_Factor()(stru_fac.cpp:19-21) readsPARAM.inp.basis_typeandPARAM.inp.device. Moving the file does not change the global-reference count. Passing the device in explicitly is a separate cleanup; its only caller isesolver_fp.cpp.- Open PRs touching the same build lists or headers: Precommit: Format CMake files (Part II) #8187 (CMake formatting), Feature: periodic self-consistent continuum solvation (SCCS) Step4: delayed start, relax, diagnostics and out_sol #8222 and fix(rt): correct hybrid gauge input density for RI exchange #8170 (
potential_new.h).
Task list for Issue attackers (only for developers)
- Identify the specific code file or section with the code quality issue.
- Investigate the issue and determine the root cause.
- Research best practices and potential solutions for the identified issue.
- Refactor the code to improve code quality, following the suggested solution.
- Ensure the refactored code adheres to the project's coding standards.
- Test the refactored code to ensure it functions as expected.
- Update any relevant documentation, if necessary.
- Submit a pull request with the refactored code and a description of the changes made.
Metadata
Metadata
Assignees
Labels
RefactorRefactor ABACUS codesRefactor ABACUS codes
Activity
Drop four unused upward includes in source_estate and source_relax
ABACUS-PR-BOT commentedon Oct 29, 2026
The proposed move is supported by the source. Three details matter for keeping it behavior-preserving:
source_cell/kernelsin the legacy Makefile’sVPATH. The inspected pyabacus lists contain no affected source entries.get_sk’s(G+k)phase and CPU/GPU storage lifecycle. The constructor’s two PARAM reads still select CPU for LCAO; moving them unchanged preserves the global-reference budget but does not remove that configuration dependency.This diagnosis is based on source inspection at
e5ad53046; the CPU/CUDA/ROCm build matrix and tests have not been run.Move Structure_Factor, Soc and the cal_sk_op kernel to source_cell; d…