Update out_stru parameter and its output context - #8026
Merged
Merged
Conversation
added 11 commits
September 25, 2026 13:56
- Remove unused out_interval variable declaration from input_parameter.h - Replace out_interval with out_freq_ion in example INPUT files - Add missing cmath include for std::pow in input_parameter.h
- Element line #magnetism now outputs real initial value instead of 0.0000
- nspin=2: atoms[it].mag[0]
- nspin=4: |atoms[it].m_loc_[0]|
- Add comment "(default, overridden by per-atom mag below)" to clarify
element-line value is a default that can be overridden
- Per-atom mag is now always printed for nspin=2/4:
- magmom=true && atom_mulliken non-empty: Mulliken analysis values
- otherwise: initial values from atoms[it].mag[ia] / m_loc_[ia]
- Update unit tests in unitcell_test.cpp:
- Fix existing expectations for nspin=2 without magmom
- Add new tests for non-zero initial mag, nspin=4 initial mag,
and nspin=4 Mulliken mag
Also update test case relax_out_hk_spin2:
- STRU: add mag 1.0 / mag -1.0 for antiferromagnetic initial state
- INPUT: symmetry 1 -> 0 to allow AFM structure
out_stru was previously only effective for relax/cell-relax; scf and
nscf runs never wrote structure files (and nscf even force-reset
out_stru to 0).
Now:
- Relax_Driver::stru_out/final_out accept scf/nscf in addition to
relax/cell-relax. For scf/nscf only STRU_FINAL (or STRU_FINAL.cif) is
written, since the structure is identical to the single step; the
per-step STRU_NOW and numbered STRU{istep} files remain relax-only,
as do the relax-specific screen messages.
- out_stru reset_value only forces 0 when the user did not set it
explicitly (item.is_read()); scf is added to the offlist so that scf
and nscf produce no structure output by default and become opt-in.
relax/cell-relax keep their default value 1, unchanged.
- Docs (parameters.yaml, input-main.md, INPUT description) updated to
describe the new effective scope and scf/nscf opt-in behavior.
- read_input_item_test.cpp adapted: OutStru test now covers both
"reset when not read" and "preserve explicit user value" cases.
Verification: code edited only; build/tests not run (per user request,
awaiting approval).
The bfgs 2 relax path is already covered by relax_out_hk_spin2 in the same directory and by tests/03_NAO_multik/relax_bfgs2 with multiple k-points. Repurpose the Gamma-only case to exercise relax_method=lbfgs, which had no integration-test coverage, and rename the directory accordingly. result.ref is intentionally dropped; regenerate it with run_debug.sh ref before relying on this test.
- Add const ModuleBase::matrix& force parameter to print_stru_file - When force is provided (nr==nat, nc==3), output positions in Angstrom and forces in eV/Angstrom with 'f' keyword - Update unit note in ATOMIC_POSITIONS header accordingly - Update all existing test calls to pass empty matrix for backward compatibility
- Add force parameter to stru_out() and final_out()
- Move force declaration outside while loop so final_out can access it
- Pass force to print_stru_file for STRU_NOW, STRU{istep+1}, STRU_FINAL
- Add test_print_cell.cpp with MODULE_CELL_print_cell_test target covering nspin=1/2/4 magnetic moment output and force output - Move PrintSTRU tests out of unitcell_test.cpp into the new test file - When forces are present, always emit Cartesian_angstrom coordinates (tau * lat0 * BOHR_TO_A) and forces in eV/Angstrom; internal tau was previously treated as Bohr and missed the lat0 factor, and direct fractional coordinates were incorrectly converted as Cartesian - Include source_base/matrix.h in print_cell.h for the default force argument's complete type
- Always print LATTICE_CONSTANT as 1 Angstrom in Bohr and write lattice vectors directly in Angstrom (lat0 * latvec * BOHR_TO_A), keeping the STRU self-consistent when read back as Cartesian_angstrom - Always use Cartesian_angstrom for Cartesian positions; Direct is only emitted for fractional coordinates without forces, and forces force Cartesian_angstrom output - Print position, velocity and force components separated by single spaces instead of fixed-width columns - Update print_cell unit tests for the new headers and spacing
Reduce force output precision from 10 to 6 decimals in eV/Angstrom; positions and velocities remain at 10 decimals.
Normalize STRU_NOW formatting so values are followed by exactly one space before the trailing comment, and per-atom mag uses one space after the mag keyword. Update print_cell test expectations (including stale lat0/coordinate values) to match current BOHR_TO_A output.
ieiue
approved these changes
Sep 28, 2026
7 tasks done
9 of 20 tasks
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.
fix #6782 , will fix #7614 later
In addition, I have added forces in STRU file.
Now, out_stru works for scf/nscf, the output STRU contains energy, force, and stress, can be used to collect data for training machine learning potentials