Repository navigation
Write formatted Wannier90 spin matrices for spinor LCAO calculations - #8331
Open
Stardust0831 wants to merge 6 commits into
Open
Stardust0831 wants to merge 6 commits into
Stardust0831 wants to merge 6 commits into
Conversation
ABACUS-PR-BOT
left a comment
Collaborator
There was a problem hiding this comment.
The Python SPN workflow can mix files from different NSCF runs when a companion output is disabled. This was a static source review; no builds or runtime tests were run.
ZhouXY-PKU
reviewed
Nov 19, 2026
AsTonyshment
approved these changes
Nov 19, 2026
AsTonyshment
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, no other comments from my side.
Use the existing five export prerequisites to choose the default when out_wannier_spn is omitted. Keep explicit flags under the existing INPUT requirement. Match the default when preparing the Python workflow and cover both the SCF and NSCF paths.
This comment was marked as off-topic.
This comment was marked as off-topic.
ABACUS-PR-BOT
left a comment
Collaborator
There was a problem hiding this comment.
One test-coverage suggestion below. This was a static source review; no builds, CLI checks or runtime tests were run.
This branch has not been deployed
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
Add
out_wannier_spnto the direct LCAO Wannier90 interface. ABACUS writes a formatted<seedname>.spnby default whentowannier90=1,calculation=nscf,basis_type=lcao,wannier_method=2andnspin=4. Setout_wannier_spn=0to skip it. In other configurations the default is off, and an explicit1triggers the standard INPUT requirement error. In the Wannier90 input, setspinors = trueandspn_formatted = true.For each k point, the writer folds the existing orbital overlap into S(k) and evaluates the three Pauli matrices between the retained Bloch spinors. It writes the upper triangle in the same band order and gauge as the other Wannier90 files, respecting
exclude_bands. The writer shares its stream status with all MPI ranks after opening and closing the file.When the Python interface requests spin output, it sets the text format and checks that
out_wannier_mmn,out_wannier_amnandout_wannier_eigare enabled before launching NSCF. This prevents a companion file from an earlier calculation inOUT.ABACUSfrom being paired with new spin matrices. Native ABACUS can also export.spnindependently.Addresses #6968 for the direct LCAO interface.
Tests
The regression runs a fully relativistic, noncollinear oxygen system at two k points with different complex overlap matrices and excludes the third band. The SCF run succeeds with the flag omitted and rejects an explicit spin-output request. The direct Wannier NSCF writes the file by default and skips it with an explicit
0. The regression compares every exported complex element against an independent NumPy calculation using the binary wavefunctions and orbital overlaps from the same run. Wannier90 builds the checkpoint andpostw90.xreads the formatted file and computes the spin magnetic moment.The following passed on SAI with Wannier90 3.1.0:
ctest --test-dir build --no-tests=error -V -R '^03_NAO_wannier_spn$' python3 interfaces/Wannier90_interface/tests/check_wannier_spn.py wannier90.x postw90.x mpirun -np 1 /path/to/abacus_basic_para PYTHONPATH=interfaces/Wannier90_interface python3 -m unittest discover -s interfaces/Wannier90_interface/tests -vFor 546 complex elements per run, the maximum absolute error was
4.121e-16with four MPI ranks (CTest) and3.357e-16with one rank, against a tolerance of1e-10. Both runs produced the same spin magnetic moment to the printed precision. The optional CTest invokes the external Wannier90 and postw90 executables to verify compatibility with the consumer.For both MPI configurations, the test verifies that the absolute
.spnpath in the NSCF log points to the generated file. Both configurations also wrote.spnwith all three companion outputs disabled. A directory at the output path forced an open failure, and a symlink to/dev/fullforced a write failure. Each invocation exited with a nonzero status, and every rank's NSCF log contained the corresponding diagnostic.The Python regression prepopulates
OUT.ABACUSwith old files and disables each companion in turn. Each case reports the disabled parameter before launching NSCF or copying files. The full Python workflow passed SCF, NSCF, Wannierisation and postw90, including a rerun with stale files in the working directory.abacus_basic_para -h out_wannier_spndisplayed the input metadata.abacus_basic_para --check-inputgave the expected result for 27 combinations covering an omitted flag, an explicit0and an explicit1. With the flag omitted, the non-spin-polarized diamond example wrote MMN, AMN and EIG and skipped SPN. The spinor Bi2Se3 example produced a formatted SPN with 969,600 complex elements, whichpostw90.xread successfully.