Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/advanced/md.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ When [md_type](./input_files/input-main.md#md_type) is set to npt, [md_pmode](./

Furthermore, ABACUS also provides a [list of keywords](./input_files/input-main.md#molecular-dynamics) to control relevant parmeters used in MD simulations.

MD structure output is controlled by [`out_stru`](./input_files/input-main.md#out_stru), [`out_freq_ion`](./input_files/input-main.md#out_freq_ion), and [`out_app_flag`](./input_files/input-main.md#out_app_flag). Set `out_stru 1`, `out_freq_ion 1`, and `out_app_flag 1` to keep every MD step in the appended `STRU` trajectory. With `out_freq_ion 0`, only `STRU_FINAL` is written. Mode 0 overwrites the periodic `STRU`; mode 2 writes numbered files and `STRU_FINAL` under `STRUC/`. Set `out_stru 2` for CIF geometry: periodic output overwrites `STRU.cif` in modes 0 and 1 or writes numbered `STRU{step}.cif` files in mode 2, and the final geometry is `STRU_FINAL.cif`. CIF omits atomic forces and velocities; the separate `STRU_restart` checkpoint retains velocities for restarting MD.
MD structure output is controlled by [`out_stru`](./input_files/input-main.md#out_stru) and [`out_app_flag`](./input_files/input-main.md#out_app_flag). The optional second value of `out_stru` sets the MD structure interval and defaults to 1: for example, `out_stru 1 5` writes a STRU frame every 5 steps, while `out_stru 1 0` disables periodic frames but still writes `STRU_FINAL`. The structure cadence is independent of `out_freq_ion`, which continues to control electronic and other outputs. Mode 0 overwrites the periodic `STRU`; mode 2 writes numbered files and `STRU_FINAL` under `STRUC/`. Set `out_stru 2 5` for CIF geometry every 5 steps: periodic output overwrites `STRU.cif` in modes 0 and 1 or writes numbered `STRU{step}.cif` files in mode 2, and the final geometry is `STRU_FINAL.cif`. CIF omits atomic forces and velocities; the separate `STRU_restart` checkpoint retains velocities for restarting MD.

Use `out_thermo_freq` to set the output interval for MD step, energy, temperature, and pressure information in `running_md.log` and on screen. The default is 1; set it to 0 to disable this thermodynamic output. The interval counts MD steps from 0, so a value of 10 selects steps 0, 10, 20, and so on, including after a restart.

Expand Down
1 change: 1 addition & 0 deletions source/source_io/module_parameter/input_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ struct Input_para
int out_freq_elec = 0; ///< the frequency of electronic iter to output charge and wavefunction
int out_freq_ion = 0; ///< the frequency ( >= 0 ) of ionic step to output charge density;
///< 0: output only when ion steps are finished
int out_freq_stru = 1; ///< MD structure cadence from optional out_stru second value
int out_freq_td_compat = 0; ///< legacy alias out_freq_td for out_freq_ion in RT-TDDFT
std::vector<int> out_chg = {0, 3}; ///< output charge density. 0: no; 1: yes
bool out_occ_mat = true; ///< output DFT+U occupation matrices;
Expand Down
24 changes: 17 additions & 7 deletions source/source_io/module_parameter/read_inp_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ void ReadInput::item_output()
item.annotation = "print information every few ionic steps";
item.category = "Output information";
item.type = "Integer";
item.description = "Controls the output interval in ionic steps. When set to a positive integer, information such as charge density, local potential, electrostatic potential, Hamiltonian matrix, overlap matrix, density matrix, Mulliken population analysis, and periodic structure files (when out_stru is positive) is printed every n ionic steps."
item.description = "Controls the output interval in ionic steps. When set to a positive integer, information such as charge density, local potential, electrostatic potential, Hamiltonian matrix, overlap matrix, density matrix, and Mulliken population analysis is printed every n ionic steps. In MD, periodic structure frames are controlled by the optional second value of out_stru."
"\n\nThis parameter only controls how often a write happens, not how many files are kept: with out_app_flag = 0 each write overwrites the same fixed filename, with out_app_flag = 1 records are appended to one fixed filename, and with out_app_flag = 2 each written step gets its own g{step} file."
"\n\nIn molecular dynamics calculations, positive out_freq_ion selects periodic structure frames starting at the first step. Zero disables periodic frames; STRU_FINAL or STRU_FINAL.cif is still written when out_stru is positive. MD checkpoints STRU_restart and Restart_md.txt follow md_restartfreq independently."
"\n\nIn molecular dynamics calculations, out_freq_ion does not control periodic structure frames. The optional second value of out_stru sets that cadence (default 1). MD writes STRU_FINAL or STRU_FINAL.cif when out_stru is positive. Checkpoints STRU_restart and Restart_md.txt follow md_restartfreq independently."
"\n\nFor DFT+U calculations with out_occ_mat = 1, a separate occupation-matrix file occ_matg{geom_step}.txt is created for every output ionic step. The converged (or final, if not converged) electronic step is always recorded in that file; when out_freq_elec is set smaller than scf_nmax, additional electronic steps are appended as separate sections, each labelled only with the electronic-step number."
"\n\nIn RT-TDDFT calculations, this parameter counts completed electronic evolution steps (`STEP OF ELECTRON EVOLVE`) instead, because one ionic step contains `estep_per_md` electronic steps. To write once per ionic step, set it to `estep_per_md`.";
item.default_value = "0";
Expand Down Expand Up @@ -579,16 +579,17 @@ The LDOS is evaluated once after all ionic steps finish; the cube header records
Input_Item item("out_stru");
item.annotation = "output the structure files per ion step";
item.category = "Output information";
item.type = "Integer";
item.description = "Controls ordinary structure output in scf/nscf/relax/cell-relax and md calculations. Files are written to OUT.{suffix}/, or to STRUC/ when out_app_flag=2. The relaxation header records version, time, energy and stress; MD frames use a one-based \"# MD step N\" marker. In relax, STRU_NOW is overwritten each step, STRU_FINAL is written at completion, and positive out_freq_ion selects additional periodic files when out_app_flag is 1 or 2. In MD, STRU_FINAL or STRU_FINAL.cif is written at completion and positive out_freq_ion selects periodic frames for all three output modes. For scf/nscf only STRU_FINAL (or STRU_FINAL.cif) is written.\n\n"
item.type = R"(Integer \[Integer\](optional))";
item.description = "The first integer controls ordinary structure output in scf/nscf/relax/cell-relax and md calculations. Files are written to OUT.{suffix}/, or to STRUC/ when out_app_flag=2. The optional second integer controls the periodic MD structure-frame interval and defaults to 1. In MD, for example, 'out_stru 1 5' writes a STRU frame every 5 steps, while 'out_stru 1 0' disables periodic frames but still writes STRU_FINAL. The final STRU (or STRU_FINAL.cif) is written when out_stru is positive; STRU_restart and Restart_md.txt follow md_restartfreq independently. For relax, STRU_NOW is overwritten each step, STRU_FINAL is written at completion, and positive out_freq_ion selects additional periodic files when out_app_flag is 1 or 2. For scf/nscf only STRU_FINAL (or STRU_FINAL.cif) is written.\n\n"
" - 0: No ordinary structure files are output. MD restart checkpoints remain controlled by md_restartfreq.\n"
" - 1: ABACUS STRU format files are output. In relax/cell-relax the latest structure is written to STRU_NOW (overwritten each step), periodic STRU files are written when out_freq_ion is positive and out_app_flag is 1 or 2, and the final structure is written to STRU_FINAL. For scf/nscf only STRU_FINAL is written. In MD, positive out_freq_ion selects periodic STRU files in modes 0, 1 and 2; STRU_FINAL is always written at completion. Mode 1 appends one structure block per selected step to fixed-name STRU.\n"
" - 2: CIF format files are output. In relax/cell-relax, STRU_NOW.cif is overwritten each step and STRU_FINAL.cif is written at completion; periodic CIF files are written with positive out_freq_ion when out_app_flag is 1 or 2. In MD, positive out_freq_ion selects periodic CIF files for all three modes and STRU_FINAL.cif is written at completion. Mode 2 writes numbered STRU{istep}.cif files; modes 0 and 1 overwrite one STRU.cif on each selected step. CIF contains geometry but no per-atom forces or velocities. MD restart checkpoints remain ABACUS STRU files.\n"
"[NOTE] MD writes STRU_FINAL or STRU_FINAL.cif at the end when out_stru is positive. With out_freq_ion>0 it also writes periodic frames from the first step. For ABACUS STRU, out_app_flag=0 overwrites STRU, mode 1 appends marked frames to STRU, and mode 2 writes numbered STRU{istep} files under STRUC/. With out_freq_ion=0 only the final structure is written. MD does not write STRU_NOW. Ordinary MD STRU structures include forces in eV/Angstrom and velocities in atomic units; STRU_restart keeps velocities but omits forces, and is written with Restart_md.txt according to md_restartfreq even when out_stru=0.\n"
" - 1: ABACUS STRU format files are output. In relax/cell-relax the latest structure is written to STRU_NOW (overwritten each step), periodic STRU files are written when out_freq_ion is positive and out_app_flag is 1 or 2, and the final structure is written to STRU_FINAL. For scf/nscf only STRU_FINAL is written. In MD, the optional second integer selects periodic STRU frames and defaults to every step. Mode 1 appends one structure block per selected step to fixed-name STRU.\n"
" - 2: CIF format files are output. In relax/cell-relax, STRU_NOW.cif is overwritten each step and STRU_FINAL.cif is written at completion; periodic CIF files are written with positive out_freq_ion when out_app_flag is 1 or 2. In MD, the optional second integer selects periodic CIF frames and defaults to every step. Mode 2 writes numbered STRU{istep}.cif files; modes 0 and 1 overwrite one STRU.cif on each selected step. CIF contains geometry but no per-atom forces or velocities. MD restart checkpoints remain ABACUS STRU files.\n"
"[NOTE] For MD with out_stru > 0, STRU_FINAL or STRU_FINAL.cif is written at the end. The optional second integer defaults to 1; set it to 0 to disable periodic structure frames while keeping the final structure. For ABACUS STRU, out_app_flag=0 overwrites STRU, mode 1 appends marked frames to STRU, and mode 2 writes numbered STRU{istep} files under STRUC/. MD does not write STRU_NOW. Ordinary MD STRU structures include forces in eV/Angstrom and velocities in atomic units; STRU_restart keeps velocities but omits forces, and is written with Restart_md.txt according to md_restartfreq even when out_stru=0.\n"
"[NOTE] For backward compatibility, true/false (case insensitive) are accepted and converted to 1/0.";
item.default_value = "1";
item.unit = "";
item.read_value = [](const Input_Item& item, Parameter& para) {
const size_t count = item.get_size();
const std::string val = FmtCore::lower(item.str_values[0]);
if (val == "true" || val == "t" || val == "yes" || val == "y" || val == "on" || val == ".true.")
{
Expand Down Expand Up @@ -622,6 +623,11 @@ The LDOS is evaluated once after all ionic steps finish; the cube header records
"out_stru must be one of 0, 1, 2. For backward compatibility, true/false are also accepted. Got: '" + item.str_values[0] + "'.");
}
}
para.input.out_freq_stru = 1;
if (count == 2)
{
para.input.out_freq_stru = std::stoi(item.str_values[1]);
}
};
item.reset_value = [](const Input_Item& item, Parameter& para) {
// For scf/nscf/get_s/get_pchg/get_wf the default is no structure
Expand All @@ -641,6 +647,10 @@ The LDOS is evaluated once after all ionic steps finish; the cube header records
}
};
sync_int(input.out_stru);
item.get_final_value = [](Input_Item& item, const Parameter& para) {
item.final_value << para.input.out_stru << " " << para.input.out_freq_stru;
};
add_int_bcast(input.out_freq_stru);
this->add_item(item);
}
{
Expand Down
39 changes: 30 additions & 9 deletions source/source_io/module_parameter/read_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,33 +494,50 @@ std::string ReadInput::prepare_input(Parameter& param)
errors += item->domain.validate_explicit(item->label, item->str_values);
}

// out_dos, out_mat_xc, out_mat_p and out_mat_exx take one or two tokens.
// Their vector domains skip the whole-token validation of the scalar
// readers, so check that every supplied token is a complete value before
// any read hook runs.
// out_dos, out_mat_xc, out_mat_p, out_mat_exx, and out_stru take one or two
// tokens. Their vector domains skip the whole-token validation of the scalar
// readers, so check that every supplied token is a complete value before any
// read hook runs.
for (const ModuleIO::Input_Item* item : this->readvalue_items)
{
const bool starts_with_boolean = item->label == "out_mat_xc" || item->label == "out_mat_p"
|| item->label == "out_mat_exx";
if (!starts_with_boolean && item->label != "out_dos")
const bool is_out_stru = item->label == "out_stru";
if (!starts_with_boolean && item->label != "out_dos" && !is_out_stru)
{
continue;
}
bool valid = item->str_values.size() == 1 || item->str_values.size() == 2;
if (valid)
{
valid = starts_with_boolean ? is_boolean_token(item->str_values[0])
: is_integer_token(item->str_values[0]);
: (is_out_stru
? is_boolean_token(item->str_values[0]) || is_integer_token(item->str_values[0])
: is_integer_token(item->str_values[0]));
}
if (valid && item->str_values.size() == 2)
{
valid = is_integer_token(item->str_values[1]);
}
if (!valid)
{
errors += input_diagnostic(item->label, longstring(item->str_values), "supplied",
starts_with_boolean ? "Expected a Boolean and an optional Integer."
: "Expected one Integer and an optional precision Integer.");
std::string expected_format_text;
if (starts_with_boolean)
{
expected_format_text = "Expected a Boolean and an optional Integer.";
}
else if (is_out_stru)
{
expected_format_text = "Expected 0, 1, 2 (or a Boolean) and an optional nonnegative Integer.";
}
else
{
expected_format_text = "Expected one Integer and an optional precision Integer.";
}
const std::string expected_format = expected_format_text;
const std::string diagnostic
= input_diagnostic(item->label, longstring(item->str_values), "supplied", expected_format);
errors += diagnostic;
}
}

Expand Down Expand Up @@ -599,6 +616,10 @@ std::string ReadInput::prepare_input(Parameter& param)
{
errors += "Invalid INPUT parameter 'out_mat_tk': precision must be a positive integer.\n";
}
if (param.input.out_freq_stru < 0)
{
errors += "Invalid INPUT parameter 'out_stru': the optional second value must be >= 0.\n";
}

// Snapshot typed effective values once for shared domain and dependency checks.
InputValues values;
Expand Down
1 change: 1 addition & 0 deletions source/source_io/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ foreach(
out_dmk_zero_precision
out_hsk_zero_precision
out_mat_tk_zero_precision
out_stru_negative_frequency
out_mat_p_invalid_boolean
out_mat_p_invalid_precision
out_mat_p_extra_token
Expand Down
4 changes: 4 additions & 0 deletions source/source_io/unittests/test_read_input.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ elseif(INPUT_CASE STREQUAL "out_mat_tk_zero_precision")
string(APPEND contents "out_mat_tk 1 0\n")
set(expected "Invalid INPUT parameter 'out_mat_tk': precision must be a positive integer.")
set(expected_manual "")
elseif(INPUT_CASE STREQUAL "out_stru_negative_frequency")
string(APPEND contents "out_stru 1 -1\n")
set(expected "Invalid INPUT parameter 'out_stru': the optional second value must be >= 0.")
set(expected_manual "")
elseif(INPUT_CASE STREQUAL "out_mat_p_invalid_boolean")
string(APPEND contents "out_mat_p maybe\n")
set(expected "Invalid INPUT parameter 'out_mat_p': supplied 'maybe'")
Expand Down
18 changes: 18 additions & 0 deletions source/source_io/unittests/test_read_input_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,24 @@ TEST_F(InputTest, OutStru)
it->second.str_values = {"2"};
it->second.read_value(it->second, param);
EXPECT_EQ(TestParameters::input(param).out_stru, 2);
EXPECT_EQ(TestParameters::input(param).out_freq_stru, 1);
}
{
it->second.str_values = {"1", "5"};
it->second.read_value(it->second, param);
EXPECT_EQ(TestParameters::input(param).out_stru, 1);
EXPECT_EQ(TestParameters::input(param).out_freq_stru, 5);
}
{
it->second.str_values = {"1", "0"};
it->second.read_value(it->second, param);
EXPECT_EQ(TestParameters::input(param).out_freq_stru, 0);
check_item(it->second, param);
}
{
it->second.str_values = {"1", "-1"};
it->second.read_value(it->second, param);
EXPECT_EQ(TestParameters::input(param).out_freq_stru, -1);
}

// --- Backward-compatible boolean aliases (true -> 1, false -> 0) ---
Expand Down
4 changes: 2 additions & 2 deletions source/source_md/run_md.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void md_line(
}
};

const int output_freq = param_in.inp.out_freq_ion;
const int output_freq = param_in.inp.out_freq_stru;
const int restart_freq = param_in.mdp.md_restartfreq;
const std::string stru_out_dir = param_in.globalv.global_stru_dir;
const std::string restart_stru = param_in.globalv.global_out_dir + "STRU_restart";
Expand Down Expand Up @@ -148,7 +148,7 @@ void md_line(

/// Mark the final ionic step on the cell passed to the solver. The
/// output module then writes the final snapshot even when this step is
/// off the out_freq_ion cadence or its SCF did not converge.
/// off the out_stru cadence or its SCF did not converge.
const bool is_final_step = is_last_step(md_step, mdp.md_nstep);
if (mdcell.has_backing_unitcell())
{
Expand Down
4 changes: 2 additions & 2 deletions source/source_md/run_md.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ namespace Run_MD
inline bool is_cadence_step(const int current_step, const int freq) { return freq > 0 && current_step % freq == 0; }

/// Periodic structure output is independent of the MD restart cadence.
inline bool is_structure_output_step(const int current_step, const int out_freq_ion, const bool out_stru)
inline bool is_structure_output_step(const int current_step, const int out_freq_stru, const bool out_stru)
{
return out_stru && is_cadence_step(current_step, out_freq_ion);
return out_stru && is_cadence_step(current_step, out_freq_stru);
}

/// Returns true when `current_step` is the final ionic step of the run.
Expand Down
16 changes: 0 additions & 16 deletions tests/04_FF/21_LJ_cadence/INPUT

This file was deleted.

19 changes: 0 additions & 19 deletions tests/04_FF/21_LJ_cadence/STRU

This file was deleted.

Loading
Loading