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
8 changes: 4 additions & 4 deletions docs/advanced/elec_properties/hs_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The output filenames depend on the k-point algorithm and `nspin`:

Here `${k}` is the one-based k-point index. For `nspin = 2`, the overlap matrix is spin-independent, so only one overlap file is written for each physical k point. The gamma-only algorithm does not support `nspin = 4`; use the multi-k algorithm with an explicit Gamma-only `KPT` file for a noncollinear calculation at Gamma.

When `out_app_flag` is false, `g${step}` is inserted before `_nao`, where `${step}` is the one-based ionic-step index. For example, the first spin channel at the first k point and first ionic step is written to `hk1s1g1_nao.txt`.
When `out_app_flag` is not 1, `g${step}` is inserted before `_nao`, where `${step}` is the one-based ionic-step index. For example, the first spin channel at the first k point and first ionic step is written to `hk1s1g1_nao.txt`.

Each output block starts with a comment header containing the one-based ionic-step index, filename, `gamma only` flag, and matrix dimensions. It is followed by `Row 1`, `Row 2`, and so on. Each row contains the matrix elements from the diagonal through the upper triangle.

Expand All @@ -57,7 +57,7 @@ For `out_hsk 2`, the filenames in the table above use `.dat` instead of `.txt`.

The file therefore contains `sizeof(int) + N(N+1)/2 * sizeof(double)` bytes for a gamma-only record and `sizeof(int) + N(N+1) * sizeof(double)` bytes for a multi-k or spinor record. The format uses the host integer representation and byte order and is intended for readers using a compatible ABI.

When `out_app_flag` is true, the first ionic step truncates the shared file and every later step appends another complete record. When it is false, each ionic step has a separate filename containing `g${step}` before `_nao`.
When `out_app_flag` is 1, the first ionic step truncates the shared file and every later step appends another complete record. When it is not 1, each ionic step has a separate filename containing `g${step}` before `_nao`.

## out_hsr

Expand Down Expand Up @@ -95,7 +95,7 @@ In gamma-only mode, every generated file reports one Bravais lattice vector and

### Native Binary CSR Format

Set `out_hsr 2` to write the same H(R) and S(R) matrix sets with a `.dat` suffix. For example, an `nspin = 2` calculation writes `hrs1_nao.dat`, `hrs2_nao.dat`, and `sr_nao.dat`. When `out_app_flag` is false, the one-based ionic step is included before `_nao`, for example `hrs1g1_nao.dat` and `srg1_nao.dat`.
Set `out_hsr 2` to write the same H(R) and S(R) matrix sets with a `.dat` suffix. For example, an `nspin = 2` calculation writes `hrs1_nao.dat`, `hrs2_nao.dat`, and `sr_nao.dat`. When `out_app_flag` is not 1, the one-based ionic step is included before `_nao`, for example `hrs1g1_nao.dat` and `srg1_nao.dat`.

Each ionic step is a complete record with no padding or self-describing header:

Expand All @@ -107,7 +107,7 @@ Each ionic step is a complete record with no padding or self-describing header:

All R blocks stored by the internal HContainer are present, including blocks with zero nonzero values. The sparse threshold is `1e-10`, matching text CSR output. The format uses the host integer representation and byte order and therefore requires a compatible ABI. It does not contain unit-cell, spin, or matrix-label metadata; those are determined by the calculation input and filename.

When `out_app_flag` is true, the first ionic step truncates the shared file and later ionic steps append complete records. Otherwise every ionic step is written to its own file.
When `out_app_flag` is 1, the first ionic step truncates the shared file and later ionic steps append complete records. Otherwise every ionic step is written to its own file.

### NPZ Format

Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/elec_properties/position_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Each file or each section of the appended file starts with "STEP: " followed by

Each block here contains the matrix for the corresponding cell. There are three columns in each block, giving the matrix elements in x, y, z directions, respectively. There are altogether nbasis * nbasis lines in each block, which emulates the matrix elements.

In molecular dynamics (MD) calculations, if [out_app_flag](../input_files/input-main.md#out_app_flag) is set to true, then `data-rR-tr` is written in an append manner. Otherwise, output files will be put in a separate directory, `matrix`, and named as `$x`_data-rR-tr, where `$x` is the number of MD step. In addition, the output frequency is controlled by [out_freq_ion](../input_files/input-main.md#out_freq_ion). For example, if we are running a 10-step MD with out_freq_ion = 3, then `$x` will be 0, 3, 6, and 9.
In molecular dynamics (MD) calculations, if [out_app_flag](../input_files/input-main.md#out_app_flag) is set to 1, then `data-rR-tr` is written in an append manner. Otherwise, output files will be put in a separate directory, `matrix`, and named as `$x`_data-rR-tr, where `$x` is the number of MD step. In addition, the output frequency is controlled by [out_freq_ion](../input_files/input-main.md#out_freq_ion). For example, if we are running a 10-step MD with out_freq_ion = 3, then `$x` will be 0, 3, 6, and 9.

## get_s
We also offer the option of only calculating the position matrix without running SCF. For that purpose, in `INPUT` file we need to set the keyword [calculation](../input_files/input-main.md#calculation) to `get_s`, and [out_mat_r](../input_files/input-main.md#out_mat_r) to `true`.
2 changes: 1 addition & 1 deletion docs/advanced/elec_properties/wfc.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The [`init_wfc file binary`](../scf/initialization.md#wavefunction) path reads o

For `basis_type=lcao`, [`out_wfc_lcao`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-wfc-lcao) controls the output of numerical-atomic-orbital coefficients: `1` writes text files with the `.txt` suffix and `2` writes binary files with the `.dat` suffix. Multi-k calculations generate `wfs{spin}k{k-point}_nao.txt` or `.dat`, while Gamma-only calculations generate `wfs{spin}_nao.txt` or `.dat`.

To reuse LCAO coefficients, point `read_file_dir` to the coefficient files and set `init_wfc file txt` for text input or `init_wfc file binary` for binary input. The selected extension is required; there is no automatic format fallback. Only independent files without geometry-step indices are supported, not files accumulated with `out_app_flag`.
To reuse LCAO coefficients, point `read_file_dir` to the coefficient files and set `init_wfc file txt` for text input or `init_wfc file binary` for binary input. The selected extension is required; there is no automatic format fallback. Only independent files without geometry-step indices are supported, not files accumulated with `out_app_flag=1`.

## Wave Function in Real Space

Expand Down
2 changes: 1 addition & 1 deletion docs/advanced/scf/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ For `basis_type=pw`, the available options are:
* `nao+random`: Apply an approximately 5% multiplicative random perturbation to the NAO initialization; any bands not covered by NAO states are first initialized randomly.
* `file binary`: Read binary `wf*_pw.dat` files generated with [`out_wfc_pw=2`](../elec_properties/wfc.md) from `read_file_dir`. The files must match the current k points, `nbands`, plane-wave layout, and lattice. The `txt` format is not supported for PW wavefunctions.

For `basis_type=lcao`, use `init_wfc file txt` to read text `wf*_nao.txt` files generated with [`out_wfc_lcao=1`](../elec_properties/wfc.md), or `init_wfc file binary` to read binary `wf*_nao.dat` files generated with `out_wfc_lcao=2`, from `read_file_dir`. LCAO wavefunctions initialize the density matrix and real-space charge density. The selected format is required; ABACUS does not automatically detect or fall back to the other format. The files must use a compatible NAO basis, match the current k-point and spin setup, and contain enough bands. Only independent files without geometry-step indices are supported, not files accumulated with `out_app_flag`.
For `basis_type=lcao`, use `init_wfc file txt` to read text `wf*_nao.txt` files generated with [`out_wfc_lcao=1`](../elec_properties/wfc.md), or `init_wfc file binary` to read binary `wf*_nao.dat` files generated with `out_wfc_lcao=2`, from `read_file_dir`. LCAO wavefunctions initialize the density matrix and real-space charge density. The selected format is required; ABACUS does not automatically detect or fall back to the other format. The files must use a compatible NAO basis, match the current k-point and spin setup, and contain enough bands. Only independent files without geometry-step indices are supported, not files accumulated with `out_app_flag=1`.

For `basis_type=lcao_in_pw`, `init_wfc` is automatically set to `nao`.

Expand Down
3 changes: 2 additions & 1 deletion examples/17_relax/04_relax_with_output_lcao/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ out_dmr 1
out_dos 1
out_band 1
out_stru 1
out_app_flag 0

out_mat_l 1
out_mat_r 1
out_mat_t 1
#out_mat_dh 1

out_freq_ion 2

out_app_flag 2
2 changes: 2 additions & 0 deletions examples/18_md/02_lcao_output/INPUT
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ md_tchain 1

dft_functional hse
restart_save 1

out_app_flag 0
10 changes: 5 additions & 5 deletions source/source_base/module_out/filename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ std::string filename_output(
const int nspin,
const int nkstot,
const int out_type,
const bool out_app_flag,
const int out_app_flag,
const bool gamma_only,
const int istep,
const int iter)
Expand Down Expand Up @@ -97,14 +97,14 @@ std::string filename_output(
}

std::string istep_block
= (istep >= 0 && (!out_app_flag))
= (istep >= 0 && (out_app_flag != 1))
? "g" + std::to_string(istep + 1) // istep starts from 0
: ""; // only when istep >= 0 and out_app_flag is false will write each wfc to a separate file
: ""; // only when istep >= 0 and out_app_flag is not append mode will write each wfc to a separate file

std::string iter_block
= (iter >= 0 && (!out_app_flag))
= (iter >= 0 && (out_app_flag != 1))
? "e" + std::to_string(iter) // iter starts from 1
: ""; // only when istep >= 0 and out_app_flag is false will write each wfc to a separate file
: ""; // only when istep >= 0 and out_app_flag is not append mode will write each wfc to a separate file

std::string suffix_block;
if (out_type == 1)
Expand Down
4 changes: 2 additions & 2 deletions source/source_base/module_out/filename.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ModuleIO
* @param nspin: number of spin channels, 1,2 or 4
* @param nkstot: number of total k-points
* @param out_type: two types of output file format, 1 for .txt and 2 for .dat (binary)
* @param out_app_flag: whether to append to existing file.
* @param out_app_flag: 0=no append, 1=append to same file, 2=write to subdirectory.
* @param gamma_only: gamma_only algorithm or not.
* @param istep: index of the ion step starting from 0. If < 0, the step number is not included in the file name.
* @param iter: index of the electronic step starting from 0. If < 0, the step number is not included in the file name.
Expand All @@ -31,7 +31,7 @@ std::string filename_output(
const int nspin,
const int nkstot,
const int out_type,
const bool out_app_flag,
const int out_app_flag,
const bool gamma_only,
const int istep=-1,
const int iter=-1);
Expand Down
18 changes: 11 additions & 7 deletions source/source_io/module_ctrl/ctrl_output_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ void ctrl_output_fp(UnitCell& ucell,
ModuleBase::TITLE("ModuleIO", "ctrl_output_fp");
ModuleBase::timer::start("ModuleIO", "ctrl_output_fp");

const bool out_app_flag = inp.out_app_flag;
const int out_app_flag = inp.out_app_flag;
const bool gamma_only = PARAM.globalv.gamma_only_local;
const int nspin = inp.nspin;
const std::string global_out_dir = PARAM.globalv.global_out_dir;
const std::string global_chg_dir = PARAM.globalv.global_chg_dir;
const std::string global_pot_dir = PARAM.globalv.global_pot_dir;
const std::string global_elf_dir = PARAM.globalv.global_elf_dir;
const std::string global_dip_dir = PARAM.globalv.global_dip_dir;

const int output_frequency = inp.esolver_type == "tddft" ? inp.out_freq_td : inp.out_freq_ion;
// Print the global electronic step for TDDFT and the ionic step otherwise.
Expand All @@ -61,7 +65,7 @@ void ctrl_output_fp(UnitCell& ucell,
{
for (int is = 0; is < nspin; ++is)
{
std::string fn = PARAM.globalv.global_out_dir + "chg";
std::string fn = global_chg_dir + "chg";

std::string spin_block;
if (nspin == 2 || nspin == 4)
Expand Down Expand Up @@ -94,7 +98,7 @@ void ctrl_output_fp(UnitCell& ucell,

if (XC_Functional::get_ked_flag())
{
fn = PARAM.globalv.global_out_dir + "tau";
fn = global_chg_dir + "tau";

fn += spin_block + geom_block + ".cube";

Expand Down Expand Up @@ -123,7 +127,7 @@ void ctrl_output_fp(UnitCell& ucell,
{
for (int is = 0; is < nspin; is++)
{
std::string fn = PARAM.globalv.global_out_dir + "pot";
std::string fn = global_pot_dir + "pot";

std::string spin_block;
if (nspin == 2 || nspin == 4)
Expand Down Expand Up @@ -157,7 +161,7 @@ void ctrl_output_fp(UnitCell& ucell,
}
else if (inp.out_pot[0] == 2 && should_output)
{
std::string fn = PARAM.globalv.global_out_dir + "potes";
std::string fn = global_pot_dir + "potes";
fn += geom_block + ".cube";

const std::vector<double>* pcc_potential = pelec->pot->pcc_electron_potential();
Expand Down Expand Up @@ -189,7 +193,7 @@ void ctrl_output_fp(UnitCell& ucell,
module_charge::cal_rhog_symm(is, chr, pw_rhod, ucell.symm);
}

std::string out_dir = PARAM.globalv.global_out_dir;
std::string out_dir = global_elf_dir;
ModuleIO::write_elf(out_dir,
istep,
nspin,
Expand Down Expand Up @@ -226,7 +230,7 @@ void ctrl_output_fp(UnitCell& ucell,
for (int is = 0; is < nspin; ++is)
{
std::stringstream ss_dipole;
ss_dipole << global_out_dir << "dipole_s" << is + 1 << ".txt";
ss_dipole << global_dip_dir << "dipole_s" << is + 1 << ".txt";
ModuleIO::write_dipole(ucell, chr.rho[is], pw_rhod, istep, ss_dipole.str(), ofs_running);
}
}
Expand Down
6 changes: 3 additions & 3 deletions source/source_io/module_ctrl/ctrl_output_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ModuleIO::ctrl_iter_pw(const int istep,
GlobalV::NPROC_IN_POOL,
inp.out_wfc_pw,
inp.ecutwfc,
PARAM.globalv.global_out_dir,
PARAM.globalv.global_psi_dir,
stp.psi_cpu[0],
kv,
pw_wfc,
Expand Down Expand Up @@ -174,7 +174,7 @@ void ModuleIO::ctrl_scf_pw(const int istep,
PARAM.globalv.two_fermi,
inp.out_app_flag,
inp.bndpar,
PARAM.globalv.global_out_dir,
PARAM.globalv.global_dos_dir,
ofs_running);
}
}
Expand Down Expand Up @@ -294,7 +294,7 @@ void ModuleIO::ctrl_runner_pw(UnitCell& ucell,
inp.out_ldos,
inp.stm_bias,
inp.nspin,
PARAM.globalv.global_out_dir,
PARAM.globalv.global_dos_dir,
PARAM.globalv.two_fermi,
inp.nbands,
inp.dos_edelta_ev,
Expand Down
2 changes: 1 addition & 1 deletion source/source_io/module_ctrl/ctrl_runner_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void ctrl_runner_lcao(UnitCell& ucell, // unitcell
{
ModuleIO::Cal_ldos<TK>::cal_ldos_lcao(pelec->eferm, chr, dmat, kv,
pelec->ekb, pelec->wg, psi[0], pgrid, pv, gd, ucell,
inp.stm_bias, inp.nspin, PARAM.globalv.global_out_dir,
inp.stm_bias, inp.nspin, PARAM.globalv.global_dos_dir,
PARAM.globalv.two_fermi, inp.out_ldos[1], ofs_running);
}

Expand Down
19 changes: 10 additions & 9 deletions source/source_io/module_ctrl/ctrl_scf_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,11 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,

//*****

const bool out_app_flag = inp.out_app_flag;
const int out_app_flag = inp.out_app_flag;
const bool gamma_only = PARAM.globalv.gamma_only_local;
const int nspin = inp.nspin;
const std::string global_out_dir = PARAM.globalv.global_out_dir;
const std::string global_mat_dir = PARAM.globalv.global_mat_dir;

//------------------------------------------------------------------
//! 1) print out density of states (DOS)
Expand Down Expand Up @@ -168,7 +169,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
inp.dos_emin_ev,
PARAM.globalv.two_fermi,
inp.bndpar,
PARAM.globalv.global_out_dir,
PARAM.globalv.global_dos_dir,
ofs_running);
}

Expand All @@ -179,7 +180,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
{
const int precision = inp.out_dmr[1];

ModuleIO::write_dmr(dm->get_dmr_vec(), &ucell, precision, pv, out_app_flag,
ModuleIO::write_dmr(dm->get_dmr_vec(), &ucell, precision, pv, (out_app_flag == 1),
ucell.get_iat2iwt(), ucell.nat, istep, ofs_running);
}

Expand All @@ -195,7 +196,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
}
const int precision = inp.out_dmk[1];

ModuleIO::write_dmk(dm->get_dmk_vec(), kv, precision, efermis, &(ucell), pv, global_out_dir, istep, ofs_running);
ModuleIO::write_dmk(dm->get_dmk_vec(), kv, precision, efermis, &(ucell), pv, global_mat_dir, istep, ofs_running);
}

//------------------------------------------------------------------
Expand Down Expand Up @@ -279,7 +280,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
const hamilt::HContainer<TR>* sr = p_hamilt->getSR();

ModuleIO::write_hsr(hr_vec, sr, &ucell, inp.out_hsr[0], precision, pv,
out_app_flag, gamma_only, ucell.get_iat2iwt(), ucell.nat, istep,
(out_app_flag == 1), gamma_only, ucell.get_iat2iwt(), ucell.nat, istep,

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.

[P2] Route the remaining matrix outputs through MAT

In mode 2, this write_hsr call still receives global_out_dir, as do H(k), T(k), Vxc and the NPZ outputs; their writers do not redirect that path. Positive-step r(R)/T(R) output during relax also stays in the root because its MAT selection is restricted to MD. Please apply the selected matrix directory consistently across these producers.

PARAM.globalv.global_out_dir, pelec->eferm,
ofs_running);
}
Expand Down Expand Up @@ -399,7 +400,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
dh_params.nspin = inp.nspin;
dh_params.istep = istep;
dh_params.gamma_only = gamma_only;
dh_params.append = out_app_flag;
dh_params.append = (out_app_flag == 1);
dh_params.ofs_running = &ofs_running;
if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2)
{
Expand Down Expand Up @@ -442,7 +443,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
h_params.nrxx = pw_rho->nrxx;
h_params.nspin = nspin;
h_params.istep = istep;
h_params.append = out_app_flag;
h_params.append = (out_app_flag == 1);
h_params.iat2iwt = ucell.get_iat2iwt();
h_params.nat = ucell.nat;
h_params.nlocal = PARAM.globalv.nlocal;
Expand Down Expand Up @@ -527,7 +528,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
false, // bit
inp.out_mat_tk[1],
1, // true for upper triangle matrix
inp.out_app_flag,
(inp.out_app_flag == 1),
t_fn,
pv,
GlobalV::DRANK,
Expand Down Expand Up @@ -558,7 +559,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
PARAM.globalv.gamma_only_local,
&ofs_running,
GlobalV::MY_RANK);
mylcalculator.calculate(inp.suffix, global_out_dir, ucell, inp.out_mat_l[1], GlobalV::MY_RANK, istep_in);
mylcalculator.calculate(inp.suffix, global_mat_dir, ucell, inp.out_mat_l[1], GlobalV::MY_RANK, istep_in);
}

//------------------------------------------------------------------
Expand Down
Loading
Loading