Skip to content

Refactor MD structure, restart, and thermodynamic output - #8375

Open
19hello wants to merge 14 commits into
deepmodeling:developfrom
19hello:refactor/md-output-parameters
Open

19hello wants to merge 14 commits into
deepmodeling:developfrom
19hello:refactor/md-output-parameters

Conversation

@19hello

@19hello 19hello commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Reminder

  • I have read AGENTS.md and docs/developers_guide/agent_governance.md.
  • I have linked an issue or explained why this PR does not need one.
  • I have added adequate unit tests and/or case tests, or explained why not.
  • I have listed the exact verification commands run and their results.
  • I have described user-visible behavior changes, including INPUT parameter changes.
  • I have explained core-module impact for ESolver, HSolver, ElecState, Hamilt, Operator, Psi, or other source/ changes.
  • I have requested any needed governance exception below.

Linked Issue

No issue: this refactor follows the developer's MD output redesign request.

Unit Tests and/or Case Tests for my changes

  • Commands run after merging origin/develop (all passed):
    • cmake --build build_parallel_md1_current --target MODULE_CELL_NEIGHBOR_mdcell_reader abacus_basic_para -j 12
    • env OMP_NUM_THREADS=1 ctest --test-dir build_parallel_md1_current -R '^(MODULE_CELL_NEIGHBOR_mdcell_reader_np4|MODULE_MD_func|MODULE_IO_input_test_para|04_FF_md_output_cadence)$' --output-on-failure — 4/4 passed.
    • python3 tools/03_code_analysis/agent_governance_check.py --base origin/develop --head HEAD --format text — exit 0, migration-neutral global-reference warnings only (9 added, 14 removed, net -5).
    • git diff --check origin/develop...HEAD — passed.
    • build_parallel_md1_current/abacus_basic_para --version — v3.11.0-beta13.
  • Additional focused validation before the base merge (all passed): 04_FF CTest group; targeted Autotest cases md_nvt (LCAO), 103_PW_MD_2O (PW), 25_OF_MD_LDA (OFDFT), 05_PW_MD_SDFT_10S (SDFT), and relax_cell_fix_ac (non-MD); bash -n tests/integrate/validation_tools/props_basic.sh; python3 -m unittest tests/integrate/validation_tools/test_props_basic.py.
  • INPUT CLI: -h out_thermo_freq reports default 1; -h md_thermo_freq rejects the removed name. A valid temporary INPUT accepted out_thermo_freq; the old name was rejected by the parser.
  • Follow-up LCAO print-call ordering check: cmake --build build_parallel_md1_current --target abacus_basic_para -j 12 passed; `env OMP_NUM_THREADS=1 bash ../integrate/Autotest.sh -a /home/fy19/abacus-develop/build_parallel_md1_current/abacus_basic_para -n 4 -o 1 -j 2 -r '^(md_nvt|relax_cell_vdw3) DeePMD and NEP runtime cases could not run because those optional features are disabled in this build. The last change only removes an internal velocity toggle; MDCell STRU always wrote velocities in production before and after it.

What's changed?

  • Unify ordinary MD structure file naming with the existing out_app_flag modes. Periodic frames use out_freq_ion; out_stru=1 writes STRU_FINAL on completion.
  • Make STRU_restart and Restart_md.txt independent checkpoints controlled by md_restartfreq. Restart structures always retain velocities; ordinary MD structures include velocities and per-atom forces. Distributed MDCell rows are sorted by stable atom identity and checked for duplicates/missing atoms.
  • Remove MD_dump and md_dumpfreq, dump_force, dump_vel, dump_virial, and md_out_force INPUT keywords; migrate included cases, ASE reader, postprocessing script, and property collector to STRU.
  • Use MD-only out_thermo_freq (default 1) for MD log summaries, always print the one-based MD STEP label for each summary, and print complete 3x3 virial/total-stress tensors when stress is enabled. Remove the md_thermo_freq alias. MD solvers continue computing forces and stress every step but no longer print solver-specific force/stress tables outside the MD output cadence; non-MD output remains unchanged.
  • Document that CANDELA's legacy geo_in_type ABACUS reader needs trajectory conversion for the new STRU output.

Governance Notes

  • INPUT/docs changes: read_input_item_md.cpp, read_inp_out.cpp, docs/advanced/md.md, docs/advanced/input_files/stru.md, and affected examples/cases are updated. Generated input reference files are intentionally not committed. The final removal of the internal include_velocity argument has no user-visible output change. The MD STEP correction brings the log into line with the existing out_thermo_freq description, which already promises step output regardless of cal_stress.
  • Core module impact: changes are limited to MDCell structure serialization, MD driver output scheduling, and solver log printing; force/stress calculations and non-MD solver output remain as before. The added PARAM references in output/logging functions are local aliases of existing accesses. The one GlobalV::ofs_running reference in restart input reports the required file-read confirmation. The PR-level global-reference count decreases by 5.
  • Exceptions requested: none.
    fromtests/03_NAO_multikpassed 8/8 properties outside the sandbox. This only moves MD guards before the LCAO print calls, with no user-visible output change.\n- MD step label follow-up:cmake --build build_parallel_md1_current --target MODULE_MD_base MODULE_MD_base_mpi abacus_basic_para -j 12passed;env OMP_NUM_THREADS=1 ctest --test-dir build_parallel_md1_current -R '^(MODULE_MD_base|MODULE_MD_base_mpi_np4|04_FF_md_output_cadence) DeePMD and NEP runtime cases could not run because those optional features are disabled in this build. The last change only removes an internal velocity toggle; MDCell STRU always wrote velocities in production before and after it.

What's changed?

  • Unify ordinary MD structure file naming with the existing out_app_flag modes. Periodic frames use out_freq_ion; out_stru=1 writes STRU_FINAL on completion.
  • Make STRU_restart and Restart_md.txt independent checkpoints controlled by md_restartfreq. Restart structures always retain velocities; ordinary MD structures include velocities and per-atom forces. Distributed MDCell rows are sorted by stable atom identity and checked for duplicates/missing atoms.
  • Remove MD_dump and md_dumpfreq, dump_force, dump_vel, dump_virial, and md_out_force INPUT keywords; migrate included cases, ASE reader, postprocessing script, and property collector to STRU.
  • Use MD-only out_thermo_freq (default 1) for MD log summaries and complete 3x3 virial/total-stress tensors. Remove the md_thermo_freq alias. MD solvers continue computing forces and stress every step but no longer print solver-specific force/stress tables outside the MD output cadence; non-MD output remains unchanged.
  • Document that CANDELA's legacy geo_in_type ABACUS reader needs trajectory conversion for the new STRU output.

Governance Notes

  • INPUT/docs changes: read_input_item_md.cpp, read_inp_out.cpp, docs/advanced/md.md, docs/advanced/input_files/stru.md, and affected examples/cases are updated. Generated input reference files are intentionally not committed. The final removal of the internal include_velocity argument has no user-visible output change and needs no further documentation.
  • Core module impact: changes are limited to MDCell structure serialization, MD driver output scheduling, and solver log printing; force/stress calculations and non-MD solver output remain as before. The added PARAM references in output/logging functions are local aliases of existing accesses. The one GlobalV::ofs_running reference in restart input reports the required file-read confirmation. The PR-level global-reference count decreases by 5.
  • Exceptions requested: none.
    --output-on-failurepassed 3/3. The addedtest_md_base.cppcase verifiesMD STEP: 6in the log withcal_stress=0.\n- Stress print guard cleanup: cmake --build build_parallel_md1_current --target abacus_basic_para -j 12passed;env OMP_NUM_THREADS=1 ctest --test-dir build_parallel_md1_current -R '^04_FF_md_output_cadence DeePMD and NEP runtime cases could not run because those optional features are disabled in this build. The last change only removes an internal velocity toggle; MDCell STRU always wrote velocities in production before and after it.

What's changed?

  • Unify ordinary MD structure file naming with the existing out_app_flag modes. Periodic frames use out_freq_ion; out_stru=1 writes STRU_FINAL on completion.
  • Make STRU_restart and Restart_md.txt independent checkpoints controlled by md_restartfreq. Restart structures always retain velocities; ordinary MD structures include velocities and per-atom forces. Distributed MDCell rows are sorted by stable atom identity and checked for duplicates/missing atoms.
  • Remove MD_dump and md_dumpfreq, dump_force, dump_vel, dump_virial, and md_out_force INPUT keywords; migrate included cases, ASE reader, postprocessing script, and property collector to STRU.
  • Use MD-only out_thermo_freq (default 1) for MD log summaries and complete 3x3 virial/total-stress tensors. Remove the md_thermo_freq alias. MD solvers continue computing forces and stress every step but no longer print solver-specific force/stress tables outside the MD output cadence; non-MD output remains unchanged.
  • Document that CANDELA's legacy geo_in_type ABACUS reader needs trajectory conversion for the new STRU output.

Governance Notes

  • INPUT/docs changes: read_input_item_md.cpp, read_inp_out.cpp, docs/advanced/md.md, docs/advanced/input_files/stru.md, and affected examples/cases are updated. Generated input reference files are intentionally not committed. The final removal of the internal include_velocity argument has no user-visible output change and needs no further documentation.
  • Core module impact: changes are limited to MDCell structure serialization, MD driver output scheduling, and solver log printing; force/stress calculations and non-MD solver output remain as before. The added PARAM references in output/logging functions are local aliases of existing accesses. The one GlobalV::ofs_running reference in restart input reports the required file-read confirmation. The PR-level global-reference count decreases by 5.
  • Exceptions requested: none.
    --output-on-failurepassed 1/1;env OMP_NUM_THREADS=1 bash ../integrate/Autotest.sh -a /home/fy19/abacus-develop/build_parallel_md1_current/abacus_basic_para -n 4 -o 1 -j 2 -r '^(md_nvt|relax_cell_vdw3) DeePMD and NEP runtime cases could not run because those optional features are disabled in this build. The last change only removes an internal velocity toggle; MDCell STRU always wrote velocities in production before and after it.

What's changed?

  • Unify ordinary MD structure file naming with the existing out_app_flag modes. Periodic frames use out_freq_ion; out_stru=1 writes STRU_FINAL on completion.
  • Make STRU_restart and Restart_md.txt independent checkpoints controlled by md_restartfreq. Restart structures always retain velocities; ordinary MD structures include velocities and per-atom forces. Distributed MDCell rows are sorted by stable atom identity and checked for duplicates/missing atoms.
  • Remove MD_dump and md_dumpfreq, dump_force, dump_vel, dump_virial, and md_out_force INPUT keywords; migrate included cases, ASE reader, postprocessing script, and property collector to STRU.
  • Use MD-only out_thermo_freq (default 1) for MD log summaries and complete 3x3 virial/total-stress tensors. Remove the md_thermo_freq alias. MD solvers continue computing forces and stress every step but no longer print solver-specific force/stress tables outside the MD output cadence; non-MD output remains unchanged.
  • Document that CANDELA's legacy geo_in_type ABACUS reader needs trajectory conversion for the new STRU output.

Governance Notes

  • INPUT/docs changes: read_input_item_md.cpp, read_inp_out.cpp, docs/advanced/md.md, docs/advanced/input_files/stru.md, and affected examples/cases are updated. Generated input reference files are intentionally not committed. The final removal of the internal include_velocity argument has no user-visible output change and needs no further documentation.
  • Core module impact: changes are limited to MDCell structure serialization, MD driver output scheduling, and solver log printing; force/stress calculations and non-MD solver output remain as before. The added PARAM references in output/logging functions are local aliases of existing accesses. The one GlobalV::ofs_running reference in restart input reports the required file-read confirmation. The PR-level global-reference count decreases by 5.
  • Exceptions requested: none.
    fromtests/03_NAO_multikpassed 8/8 properties. This commit removes an unnecessaryPARAM.inpalias and a redundant condition inModuleIO::print_stress`; output behavior is unchanged and no documentation update is needed.\n- Full integration suite not run locally. DeePMD and NEP runtime cases could not run because those optional features are disabled in this build. The last change only removes an internal velocity toggle; MDCell STRU always wrote velocities in production before and after it.

What's changed?

  • Unify ordinary MD structure file naming with the existing out_app_flag modes. Periodic frames use out_freq_ion; out_stru=1 writes STRU_FINAL on completion.
  • Make STRU_restart and Restart_md.txt independent checkpoints controlled by md_restartfreq. Restart structures always retain velocities; ordinary MD structures include velocities and per-atom forces. Distributed MDCell rows are sorted by stable atom identity and checked for duplicates/missing atoms.
  • Remove MD_dump and md_dumpfreq, dump_force, dump_vel, dump_virial, and md_out_force INPUT keywords; migrate included cases, ASE reader, postprocessing script, and property collector to STRU.
  • Use MD-only out_thermo_freq (default 1) for MD log summaries and complete 3x3 virial/total-stress tensors. Remove the md_thermo_freq alias. MD solvers continue computing forces and stress every step but no longer print solver-specific force/stress tables outside the MD output cadence; non-MD output remains unchanged.
  • Document that CANDELA's legacy geo_in_type ABACUS reader needs trajectory conversion for the new STRU output.

Governance Notes

  • INPUT/docs changes: read_input_item_md.cpp, read_inp_out.cpp, docs/advanced/md.md, docs/advanced/input_files/stru.md, and affected examples/cases are updated. Generated input reference files are intentionally not committed. The final removal of the internal include_velocity argument has no user-visible output change and needs no further documentation.
  • Core module impact: changes are limited to MDCell structure serialization, MD driver output scheduling, and solver log printing; force/stress calculations and non-MD solver output remain as before. The added PARAM references in output/logging functions are local aliases of existing accesses. The one GlobalV::ofs_running reference in restart input reports the required file-read confirmation. The PR-level global-reference count decreases by 5.
  • Exceptions requested: none.

@mohanchen mohanchen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change and it looks good to me.

@ABACUS-PR-BOT ABACUS-PR-BOT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The STRU output migration leaves regressions in ASE reading, legacy restart output and final-stress collection. The inline comments identify five defects and three non-blocking improvements.

Static review only; no builds or runtime tests were run.

log_steps.append(ion_move)
if len(log_steps) != len(energies):
log_steps = list(range(1, len(energies) + 1))
selected = [log_steps.index(step) for step in step_ids]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restarted STRU markers use cumulative MD steps, while the solver logs local #ION MOVE# IDs. If Restart_md.txt contains 5 and the run resumes into a new output suffix with md_nstep=7, the STRU markers are 6/7 but this lookup searches 1/2 and raises ValueError. Please account for the restart offset/run segment before matching frame results, and add a restarted-log reader fixture.

energies = [energies[i] for i in selected]
if len(forces) == len(log_steps):
forces = [forces[i] for i in selected]
if len(stress) == len(log_steps):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MD guards now remove every #TOTAL-STRESS (kbar)# table, but read_stress_from_running_log() still recognizes only that header. Consequently the new ASE path silently returns stress=None even with cal_stress=1. Please read the replacement MD tensors, preserve the electronic-stress convention, and align them by step; the new reader tests currently reuse an old-format log.

{
write_stru_frame(current_step);
ModuleBase::ensure_directory(stru_out_dir);
const std::string filename = ModuleIO::stru_frame_filename(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The restart reader still accepts legacy OUT.<suffix>/STRU/STRU_MD_<step> files, but modes 0/1 now unconditionally write periodic frames to OUT.<suffix>/STRU. On such a restart that path is a directory, so the first frame fails to open and terminates the run. Please retain a safe legacy-directory output route and cover it with a restart case.

press3=0
fi
if ! awk -v p1="$press1" -v p2="$press2" -v p3="$press3" '
/VIRIAL \(kbar\):/ { rows = 3; count = 0; next }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This selects the last printed virial without checking its MD STEP. With md_nstep=5 and out_thermo_freq=3, that tensor is labelled MD STEP: 4, while the final energy and STRU_FINAL forces belong to step 5. Please reject unavailable final-step stress or require an explicit validation cadence, so an earlier tensor is not silently compared as the final result.

"""Read MD frames from appended, numbered, or final STRU output."""
periodic = directory / 'STRU'
numbered = sorted((directory / 'STRUC').glob('STRU[0-9]*'),
key=lambda path: int(path.name[4:]))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The glob also matches leftover relaxation files such as STRUC/STRU1.cif, so int("1.cif") raises ValueError before the current-run announcements can filter them—even when a valid current STRU exists. Please restrict numbered candidates to a full STRU[0-9]+ filename match before converting the suffix.

}
}

TEST(MDCellReaderTest, STRUAtomOrderStaysStableAcrossOwnerChanges)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: the new stable-order fixture fits in one gather batch, while the removed dump tests covered one-row and multiple-batch boundaries. Please retain a writer-level case that crosses the batch boundary and includes an empty rank, so index-range advancement and frame completeness stay covered.

const std::pair<std::int64_t, std::string>& right) { return left.first < right.first; });
}
for (std::size_t it = 0; it < stru_meta.species.size(); ++it)
const int row_bytes = std::max(domain.max(local_row_bytes), 1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: please store domain.max(local_row_bytes) in a named local before passing it to std::max, as required by AGENTS rule 14. This also keeps the collective visible as a separate operation; the new out_stru > 0 argument in run_md.cpp can be named similarly.

"containing atomic velocities.";
ModuleBase::WARNING_QUIT("ReadInput::set_global_dir", message);
}
log_read_file(sys.global_in_stru);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: please emit or flush this confirmation after make_dir_out opens the running log. set_global_dir runs earlier, so the new ofs_running insertion cannot record the restart source in the log on normal startup.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants