Skip to content

Fix #5021 #5939: warn on ignored x/y magnetization and remove nspin=4 autoset - #8079

Open
mohanchen wants to merge 13 commits into
deepmodeling:developfrom
mohanchen:2026-10-06-a
Open

mohanchen wants to merge 13 commits into
deepmodeling:developfrom
mohanchen:2026-10-06-a

Conversation

@mohanchen

@mohanchen mohanchen commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Linked Issues

Problem Description

Issue #5021: x/y components of magnetization silently zeroed

When nspin=4 and noncolin=0, the x/y components of the initial magnetization
set in STRU are silently zeroed, keeping only the z component. Users who provide
a 3-component magnetization vector (e.g., mag 1.0 0.5 0.3) get no indication
that the x/y components are discarded, which can lead to confusion about why
the final magnetic moment differs from the input.

Issue #5939: nspin=4 auto-assigns (1,1,1) to all atoms

When nspin=4 and no initial magnetization is set in STRU, the code
automatically assigns (1.0, 1.0, 1.0) to all atoms regardless of element
type. This is overly aggressive — non-magnetic elements (e.g., O, H) also get
a magnetic moment, which can alter the SCF convergence path and final results.

Solution

1. Warn when x/y components are

…ation and remove nspin=4 autoset

When nspin=4 with noncolin=0, the x/y components of the initial
magnetization from STRU are silently zeroed. Now a warning is printed
to both stdout and running_scf.log, telling the user that x/y are
ignored and suggesting to set noncolin=1.

When nspin=4 and no initial magnetization is set in STRU, the code
previously auto-assigned (1,1,1) to all atoms. This is removed; the
calculation now starts from zero magnetic moment with a warning,
letting the user decide explicitly.

nspin=2 autoset behavior is unchanged.

Also adds unit tests for both behaviors and updates parameter docs.
@mohanchen
mohanchen requested a review from AsTonyshment October 5, 2026 23:32
@mohanchen mohanchen added Bugs Bugs that only solvable with sufficient knowledge of DFT Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 collinear/non-collinear/SOC/delta-spin Issues related to SOC labels Oct 5, 2026
abacus_fixer and others added 12 commits October 6, 2026 09:57
docs/parameters.yaml is generated from item.description in C++ source.
Commit 98e3f81 added two noncolin notes to the generated yaml and
input-main.md but omitted the generator source, making the yaml
consistency CI check fail. Add the same two notes to the noncolin
description in read_inp_estruc.cpp so regeneration matches.
Follow-up to deepmodeling#5939: nspin=4 with no mag in STRU no longer autosets
(1,1,1); the unit test still expected the old forced moments. Assert
zero magnetization instead and verify the new warning on both stdout
and the running log.
Move JudgeParallel, CalUx1 and CalUx2 to the new test_cal_ux.cpp /
MODULE_CELL_cal_ux_test target, one test file per source file. The new
target compiles ../cal_ux.cpp directly like the old target did;
unitcell_test no longer needs it.
Move ReadOrbFile (kept under the __LCAO guard as before) and
ReadOrbFileWarning to the new test_read_orb.cpp /
MODULE_CELL_read_orb_test target. read_orb.cpp is already part of the
test-only cell_info object library, so no extra source is compiled in.
…suite

CompareAatomLabel and PrintUnitcellPseudo exercise read_pp_ucell.cpp,
so move them from MODULE_CELL_unitcell_test into the existing
MODULE_CELL_unitcell_test_readpp target. The rebuilt cell needed by
PrintUnitcellPseudo uses the C1H2-Index prepare entry. Drop the now
unused read_pp_ucell.h include from unitcell_test.cpp.
Move RemakeCell, RemakeCellWarnings, PeriodicBoundaryAdjustment2 and
UpdateVel to the new test_update_cell.cpp /
MODULE_CELL_update_cell_test target. The commented-out
PeriodicBoundaryAdjustment1 block moves as well and stays commented.
update_cell.cpp is already part of the test-only cell_info library.
Drop the now unused update_cell.h include from unitcell_test.cpp.
PrintCell, PrintTauDirect and PrintTauCartesian exercise print_cell.cpp,
the same source as the PrintSTRU tests already living in
test_print_cell.cpp. Move them into that file/target and reuse the
PrintCellTest fixture. Drop the now unused print_cell.h include and the
stale PrintSTRU navigation comment from unitcell_test.cpp.
…l_test

Add test_cell_tools.cpp / MODULE_CELL_cell_tools_test for the
unitcell:: free functions in cell_tools.cpp:
- new IfCellCanChange truth-table case over the lattice-axis flags
- vector get_atomCounts/get_lnchiCounts cases split out of the mixed
  member/free GetAtomCounts and GetLnchiCounts tests (the member
  get_atom_Counts/get_lnchi_Counts map assertions stay in unitcell_test)
- SelectiveDynamics (if_atoms_can_move) moved verbatim

Setup keeps only the setup_from_input member assertions; its
if_cell_can_change checks are now covered by the dedicated truth table.
Drop the unused cell_tools.h include from unitcell_test.cpp.
Move the 7 STRU header-parsing cases (read_atom_species and
read_lattice_constant, both in read_atom_species.cpp) to the new
test_read_atom_species.cpp / MODULE_CELL_read_atom_species_test target,
kept under the __LCAO guard as before. ReadAtomSpeciesWarning5 uses the
death-test fixture alias; the rest use the new ReadAtomSpeciesTest
fixture. Drop the stale doc entries from unitcell_test.cpp.
Move the 17 read_atom_positions cases (spin/coordinate modes plus the
five warning cases) to the new test_read_atoms.cpp /
MODULE_CELL_read_atoms_test target, kept under the __LCAO guard. This
removes the LCAO block and UcellTestReadStru fixture from
unitcell_test.cpp, which now holds only the 9 UnitCell member-function
tests. Also de-duplicate the triple read_stru.h include. The 6 GlobalV
references are migration-neutral (added = removed).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT collinear/non-collinear/SOC/delta-spin Issues related to SOC Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

1 participant