Repository navigation
feat(lcao): output momentum operator matrices via out_mat_p - #8429
Merged
Merged
Conversation
added 3 commits
November 27, 2026 10:59
Add a new INPUT parameter `out_mat_p` for LCAO calculations. When enabled,
the momentum (velocity) operator matrices p = -i grad + i[V_NL, r] are
written as sparse matrices prx_nao.csr, pry_nao.csr and prz_nao.csr
(prxg{step}_nao.csr etc. when out_app_flag = 2), reusing the gradient
term and the nonlocal commutator already implemented for the TDDFT
velocity operator. The matrices are built from the orbital tables and
pseudopotential projectors only, so they are available in both the SCF
and the `calculation = get_s` workflows; nspin = 4 is rejected.
- add Momentum_op::calculate and wire it into ctrl_scf_lcao and ESolver_GetS
- move pos_op_* and velocity_op into source_lcao/module_momentum_op
- extend HContainer with get_basis_index()/get_matrix_dist() and let
Output_HContainer::write_single_R handle flattened local-to-global
indexing for the CSR output
- update parameter description, hs_matrix.md, and add the get_s
integration test (INPUT, refs, props_mat.sh comparisons)
Pass Input_para explicitly into Momentum_op::calculate instead of reading PARAM, and migrate the touched snap_psibeta test into unittests to satisfy the test layout policy. Also remove trailing blank lines from the new CSR reference files.
# Conflicts: # docs/advanced/elec_properties/hs_matrix.md # source/source_esolver/esolver_gets.cpp # tests/03_NAO_multik/get_s/INPUT # tests/03_NAO_multik/get_s/result.ref # tests/integrate/validation_tools/props_common.sh # tests/integrate/validation_tools/props_mat.sh
Merge the position, momentum and angular-momentum matrix writers into one module under source/source_lcao/module_op: - rename module_momentum_op to module_op and move mom_op_mat and angmom_op_mat out of source_io/module_hs, together with their unit tests; - name the angular momentum files lrx/lry/lrz_nao.csr so every R-space operator follows the <quantity>r<axis> pattern used by rrx and prx; - update docs, INPUT descriptions, the relax example, integration references and Makefile.Objects; - add a README describing the module scope and where new operators go.
added 2 commits
November 28, 2026 11:55
Python 3.8 is unavailable on the Ubuntu 26.04 runner image now selected by ubuntu-latest, so use a supported version for the pyabacus and readme checks.
Assemble the momentum operator on rank 0 in a serial layout so the CSR output contains the full matrix instead of rank-local blocks.
ABACUS-PR-BOT
left a comment
Collaborator
There was a problem hiding this comment.
The new output path has two robustness issues: malformed options bypass shared validation, and failed CSR writes can go unreported. Please address the two inline error-handling comments.
Static review only; no builds or runtime tests were run.
Non-blocking: please change the PR's statement that nscf is not wired to distinguish untested behavior from reachability. The ordinary LCAO NSCF route reaches after_scf through Relax_Driver and ESolver_KS::runner, and this controller has no SCF-only guard.
Critsium-xy
approved these changes
Nov 30, 2026
- Validate out_mat_p tokens in prepare_input before read hooks so malformed boolean/precision/extra tokens fail with the shared input_error broadcast on all ranks - Check the bool returned by write_hcontainer_csr and propagate the write failure across ranks before WARNING_QUIT - Reuse the already-initialized LCAO_Orbitals argument instead of re-converting TwoCenterBundle in Momentum_op::calculate - Remove direct MPI_Comm_rank from mom_op_mat.cpp; the caller passes the output-rank decision and ofs_running instead - Log each written momentum matrix filename via write_matrix_notice - Add a parallel writer test with a nonidentity block-cyclic row/col map on a 2x2 process grid - README: add -DBUILD_TESTING=ON to the configure command - Assign the constructed diagnostic to a named local before WARNING_QUIT
# Conflicts: # .github/workflows/readme-metadata.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #7355.
Add a new INPUT keyword
out_mat_pthat writes the three Cartesian components ofthe momentum operator in the NAO basis:
The matrices are produced in the SCF workflow and in
calculation = get_s,where they can be generated without an SCF cycle because they depend only on the
orbital tables and the pseudopotential projectors.
Output
prx_nao.csrpry_nao.csrprz_nao.csrout_mat_p [bool] [precision], defaultFalse 8.out_app_flag = 2, the ionic step is inserted before_nao, e.g.prxg1_nao.csr. Without_app_flag = 0/1the files are overwritten/appendedas usual.
get_shas no ionic step, so it passesistep = -1and writes the step-lessnames.
nspin = 4is rejected during INPUT parsing with an explicit diagnostic: themomentum matrix is written as a scalar (npol = 1) block.
Because the NAO basis is real, every matrix element is purely imaginary, so the
stored real part is identically zero. Both the gradient term (
calculate_grad_term)and the nonlocal-pseudopotential commutator (
calculate_vcomm_r) are included;the
/2factor in the commutator kernel converts the D matrix from Ry to Hartree.What changed
out_mat_pinInput_para, registered inread_inp_out.cpp, with thenspin = 4check inread_input.cpp.source_io/module_hs/mom_op_mat.{h,cpp}builds the matricesthrough the existing
Velocity_opkernel and writes the three CSR files.Momentum_op::calculatetakes every dependency explicitly(
UnitCell,Grid_Driver,TwoCenterBundle,Parallel_Orbitals,LCAO_Orbitals, output dir,Input_para) and does not readPARAM.ctrl_scf_lcao.cpp(SCF) andesolver_gets.cpp(get_s),keeping the upstream
out_mat_lpath intact and runningout_mat_pafter it.pos_op_*andvelocity_op.*move fromsource_io/module_hsinto
source_lcao/module_momentum_op/(pure moves, no behavior change), wiredthrough
CMakeLists.txtandMakefile.Objects.distribution, and let
Output_HContainer::write_single_Rtranslate localblock-cyclic coordinates to global indices. This removes the "to do: consider
2D block-cyclic distribution" gap for the flattened layout.
module_rt/test/snap_psb_half_tddft_test.cppto
module_rt/unittests/test_snap_psb_half_tddft.cpp.docs/advanced/elec_properties/hs_matrix.mdand thecalculationdescription now cover
out_mat_p, the file names, and thenspin = 4restriction.
03_NAO_multik/get_senablesout_mat_pand comparesprx/pry/prz_nao.csrviaprops_common.sh/props_mat.sh(
ComparePx/Py/Pz_pass).Verification
Build (CMake, GNU toolchain,
OMP_NUM_THREADS=1):Unit tests:
Integration case
03_NAO_multik/get_s(calculation = get_s,out_mat_p 1),comparing against the new references at 8 significant digits:
Governance:
No blocking findings; PR-level global dependency budget is unchanged
(
added = 0,removed = 0). The remaining 8 warnings are header-includereviews, all allowed; e.g.
mom_op_mat.hforward-declaresInput_paraand theMomentum-op classes instead of pulling their headers.
git diff upstream/develop --checkpasses.Not covered in this PR
03_NAO_multiksuite and broader TDDFT/LR regressions were not runlocally; only the
get_scase and the migrated TDDFT unit tests above.out_app_flag = 2naming and append behavior,nspin = 2, and MD/multi-stepruns are not exercised by the integration test.
calculation = nscfis not wired; only SCF andget_s.