Skip to content

Update out_stru parameter and its output context - #8026

Merged
mohanchen merged 14 commits into
deepmodeling:developfrom
mohanchen:2026-09-25-2
Sep 28, 2026
Merged

mohanchen merged 14 commits into
deepmodeling:developfrom
mohanchen:2026-09-25-2

Conversation

@mohanchen

@mohanchen mohanchen commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

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

image

abacus_fixer 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.
@mohanchen mohanchen added Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes The Absolute Zero Reduce the "entropy" of the code to 0 Tests/Examples Issues/PR related to unit tests and integrate tests solve before 3.11 labels Sep 25, 2026
@mohanchen
mohanchen requested a review from ieiue September 25, 2026 10:32
abacus_fixer and others added 3 commits September 25, 2026 22:36
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.
@mohanchen
mohanchen merged commit 52b4a45 into deepmodeling:develop Sep 28, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compile & CICD & Docs & Dependencies Issues related to compiling ABACUS Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes solve before 3.11 Tests/Examples Issues/PR related to unit tests and integrate tests The Absolute Zero Reduce the "entropy" of the code to 0

Projects

None yet

2 participants