Conversation
…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.
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
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.
Linked Issues
Fixes Refactor: split the monolithic source_cell unitcell_test.cpp into one test file per source file #8083
Fixes The magnetic moment is wrong when set nspin=4 but noncolin=0 #5021
Fixes In SOC calculations, the atomic magnetic moments can be set according to the structure file. #5939
Problem Description
Issue #5021: x/y components of magnetization silently zeroed
When
nspin=4andnoncolin=0, the x/y components of the initial magnetizationset 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 indicationthat 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=4and no initial magnetization is set in STRU, the codeautomatically assigns
(1.0, 1.0, 1.0)to all atoms regardless of elementtype. 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