Skip to content

Commit d3c9d0f

Browse files
authored
Update the output filenames of H(k), S(k), T(k) and Vxc. In addition, modify the filenames of H(R), S(R), T(R), and Vxc (#6262)
* begin changing the output file names of out_mat_hs * update output vxc an output tk * Fix example 006_NO_GO_OH in 02_NAO_Gamma * fix a bug * fix 17_NO_KP_OH example in 03_NAO_multik * partly update the 19_NO_KP_OH_nscf exxample and related codes * partly update 20_NO_KP_OHS_S4 * fix the example 20_NO_KP_OHS_S4 * print out the information for H(R), S(R), H(k) and S(k) * update 08_EXX examples * update output filenames related to dH, dS, rR * update documents
1 parent 6654849 commit d3c9d0f

38 files changed

+498
-384
lines changed

docs/advanced/elec_properties/hs_matrix.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and
1212

1313
## out_mat_hs
1414

15-
Users may set the keyword [out_mat_hs](../input_files/input-main.md#out_mat_hs) to true for outputting the upper triangular part of the Hamiltonian matrices and overlap matrices for each k point into files in the directory `OUT.${suffix}`. It is available for both gamma_only and multi-k calculations.
15+
Users can set the keyword [out_mat_hs](../input_files/input-main.md#out_mat_hs) to true for outputting the upper triangular part of the Hamiltonian matrices and overlap matrices for each k point into files in the directory `OUT.${suffix}`. It is available for both gamma_only and multi-k calculations.
1616

1717
The files are named `data-$k-H` and `data-$k-S`, where `$k` is a composite index consisting of the k point index as well as the spin index. The corresponding sequence of the orbitals can be seen in [Basis Set](../pp_orb.md#basis-set).
1818

@@ -35,7 +35,7 @@ The rest of the file contains the upper triangular part of the specified matrice
3535

3636
The output of R-space matrices is controlled by the keyword [out_mat_hs2](../input_files/input-main.md#out_mat_hs2). This functionality is not available for gamma_only calculations. To generate such matrices for gamma only calculations, users should turn off [gamma_only](../input_files/input-main.md#gamma_only), and explicitly specify that gamma point is the only k point in the KPT file.
3737

38-
For single-point SCF calculations, if nspin = 1 or nspin = 4, two files `data-HR-sparse_SPIN0.csr` and `data-SR-sparse_SPIN0.csr` are generated, which contain the Hamiltonian matrix $H(R)$ and overlap matrix $S(R)$ respectively. For nspin = 2, three files `data-HR-sparse_SPIN0.csr` and `data-HR-sparse_SPIN1.csr` and `data-SR-sparse_SPIN0.csr` are created, where the first two contain $H(R)$ for spin up and spin down, respectively.
38+
For single-point SCF calculations, if nspin = 1 or nspin = 4, two files `hrs1_nao.csr` and `sr_nao.csr` are generated, which contain the Hamiltonian matrix $H(R)$ and overlap matrix $S(R)$ respectively. For nspin = 2, three files `hrs1_nao.csr` and `hrs2_nao.csr` and `sr_nao.csr` are created, where the first two files correspodn to $H(R)$ for spin up and spin down, respectively.
3939

4040
As for molecular dynamics calculations, the format is controlled by [out_interval](../input_files/input-main.md#out_interval) and [out_app_flag](../input_files/input-main.md#out_app_flag) in the same manner as the position matrix as detailed in [out_mat_r](../input_files/input-main.md#out_mat_r).
4141

@@ -74,4 +74,4 @@ We provide [examples](https://github.com/deepmodeling/abacus-develop/tree/develo
7474
- out_hs_multik : writing H(k) and S(k) for multi-k calculation
7575
- out_s_multik : running get_S for multi-k calculation
7676

77-
Reference output files are provided in each directory.
77+
Reference output files are provided in each directory.

docs/advanced/input_files/input-main.md

Lines changed: 57 additions & 34 deletions
Large diffs are not rendered by default.

source/module_esolver/lcao_after_scf.cpp

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -126,51 +126,26 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
126126
#endif
127127

128128
//------------------------------------------------------------------
129-
// 5) write Hamiltonian and Overlap matrix in LCAO basis
130-
//------------------------------------------------------------------
131-
for (int ik = 0; ik < this->kv.get_nks(); ++ik)
132-
{
133-
if (PARAM.inp.out_mat_hs[0])
134-
{
135-
this->p_hamilt->updateHk(ik);
136-
}
137-
bool bit = false; // LiuXh, 2017-03-21
138-
// if set bit = true, there would be error in soc-multi-core
139-
// calculation, noted by zhengdy-soc
140-
if (this->psi != nullptr && (istep % PARAM.inp.out_interval == 0))
141-
{
142-
hamilt::MatrixBlock<TK> h_mat;
143-
hamilt::MatrixBlock<TK> s_mat;
144-
145-
this->p_hamilt->matrix(h_mat, s_mat);
146-
147-
if (PARAM.inp.out_mat_hs[0])
148-
{
149-
ModuleIO::save_mat(istep,
150-
h_mat.p,
151-
PARAM.globalv.nlocal,
152-
bit,
153-
PARAM.inp.out_mat_hs[1],
154-
1,
155-
PARAM.inp.out_app_flag,
156-
"H",
157-
"data-" + std::to_string(ik),
158-
this->pv,
159-
GlobalV::DRANK);
160-
ModuleIO::save_mat(istep,
161-
s_mat.p,
162-
PARAM.globalv.nlocal,
163-
bit,
164-
PARAM.inp.out_mat_hs[1],
165-
1,
166-
PARAM.inp.out_app_flag,
167-
"S",
168-
"data-" + std::to_string(ik),
169-
this->pv,
170-
GlobalV::DRANK);
171-
}
172-
}
173-
}
129+
// 5) write H(k) and S(k) in NAO basis set
130+
//------------------------------------------------------------------
131+
if (PARAM.inp.out_mat_hs[0])
132+
{
133+
if (this->psi != nullptr && (istep % PARAM.inp.out_interval == 0))
134+
{
135+
ModuleIO::write_hsk(PARAM.globalv.global_out_dir,
136+
PARAM.inp.nspin,
137+
this->kv.get_nks(),
138+
this->kv.get_nkstot(),
139+
this->kv.ik2iktot,
140+
this->kv.isk,
141+
this->p_hamilt,
142+
this->pv,
143+
PARAM.globalv.gamma_only_local,
144+
PARAM.inp.out_app_flag,
145+
istep,
146+
GlobalV::ofs_running);
147+
}
148+
}
174149

175150
//------------------------------------------------------------------
176151
// 6) write electronic wavefunctions in LCAO basis
@@ -182,9 +157,9 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
182157
this->psi[0],
183158
this->pelec->ekb,
184159
this->pelec->wg,
185-
this->pelec->klist->kvec_c,
186-
this->pelec->klist->ik2iktot,
187-
this->pelec->klist->get_nkstot(),
160+
this->kv.kvec_c,
161+
this->kv.ik2iktot,
162+
this->kv.get_nkstot(),
188163
this->pv,
189164
PARAM.inp.nspin,
190165
istep);
@@ -201,11 +176,11 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
201176
LCAO_Deepks_Interface<TK, TR> deepks_interface(ld_shared_ptr);
202177

203178
deepks_interface.out_deepks_labels(this->pelec->f_en.etot,
204-
this->pelec->klist->get_nks(),
179+
this->kv.get_nks(),
205180
ucell.nat,
206181
PARAM.globalv.nlocal,
207182
this->pelec->ekb,
208-
this->pelec->klist->kvec_d,
183+
this->kv.kvec_d,
209184
ucell,
210185
orb_,
211186
this->gd,
@@ -370,15 +345,23 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
370345
for (int ik = 0; ik < this->kv.get_nks() / nspin_k; ++ik)
371346
{
372347
ekinetic->init(ik);
373-
ModuleIO::save_mat(0,
348+
349+
const int out_label = 1; // 1: .txt, 2: .dat
350+
351+
std::string t_fn = ModuleIO::filename_output(PARAM.globalv.global_out_dir,
352+
"tk","nao",ik,this->kv.ik2iktot,
353+
PARAM.inp.nspin,this->kv.get_nkstot(),
354+
out_label,PARAM.inp.out_app_flag,
355+
PARAM.globalv.gamma_only_local,istep);
356+
357+
ModuleIO::save_mat(istep,
374358
hsk.get_hk(),
375359
PARAM.globalv.nlocal,
376-
false,
360+
false, // bit
377361
PARAM.inp.out_mat_tk[1],
378-
1,
362+
1, // true for upper triangle matrix
379363
PARAM.inp.out_app_flag,
380-
"T",
381-
"data-" + std::to_string(ik),
364+
t_fn,
382365
this->pv,
383366
GlobalV::DRANK);
384367
}

source/module_io/cal_r_overlap_R.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const
274274
int output_R_number = 0;
275275

276276
std::stringstream tem1;
277-
tem1 << PARAM.globalv.global_out_dir << "temp-data-rR-sparse.dat";
277+
tem1 << PARAM.globalv.global_out_dir << "tmp-rr.csr";
278278
std::ofstream ofs_tem1;
279279
std::ifstream ifs_tem1;
280280

@@ -451,15 +451,15 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const
451451
std::stringstream ssr;
452452
if (PARAM.inp.calculation == "md" && !PARAM.inp.out_app_flag)
453453
{
454-
ssr << PARAM.globalv.global_matrix_dir << step << "_"
455-
<< "data-rR-sparse.csr";
454+
ssr << PARAM.globalv.global_matrix_dir
455+
<< "rrg" << step << ".csr";
456456
}
457457
else
458458
{
459-
ssr << PARAM.globalv.global_out_dir << "data-rR-sparse.csr";
459+
ssr << PARAM.globalv.global_out_dir << "rr.csr";
460460
}
461461

462-
if (binary)
462+
if (binary) // .dat
463463
{
464464
ofs_tem1.close();
465465
int nlocal = PARAM.globalv.nlocal;
@@ -480,7 +480,7 @@ void cal_r_overlap_R::out_rR(const UnitCell& ucell, const Grid_Driver& gd, const
480480
ifs_tem1.close();
481481
out_r.close();
482482
}
483-
else
483+
else // .txt
484484
{
485485
ofs_tem1.close();
486486
if (PARAM.inp.calculation == "md" && PARAM.inp.out_app_flag && step)
@@ -524,12 +524,12 @@ void cal_r_overlap_R::out_rR_other(const UnitCell& ucell, const int& istep, cons
524524
std::stringstream ssr;
525525
if (PARAM.inp.calculation == "md" && !PARAM.inp.out_app_flag)
526526
{
527-
ssr << PARAM.globalv.global_matrix_dir << step << "_"
528-
<< "data-rR-sparse.csr";
527+
ssr << PARAM.globalv.global_matrix_dir
528+
<< "rrg" << step << ".csr";
529529
}
530530
else
531531
{
532-
ssr << PARAM.globalv.global_out_dir << "data-rR-sparse.csr";
532+
ssr << PARAM.globalv.global_out_dir << "rr.csr";
533533
}
534534

535535
if (GlobalV::DRANK == 0)
@@ -676,13 +676,13 @@ void cal_r_overlap_R::out_rR_other(const UnitCell& ucell, const int& istep, cons
676676

677677
Parallel_Reduce::reduce_all(rR_nonzero_num, 3);
678678

679-
if (binary)
679+
if (binary) // .dat
680680
{
681681
out_r.write(reinterpret_cast<char*>(&dRx), sizeof(int));
682682
out_r.write(reinterpret_cast<char*>(&dRy), sizeof(int));
683683
out_r.write(reinterpret_cast<char*>(&dRz), sizeof(int));
684684
}
685-
else
685+
else // .txt
686686
{
687687
out_r << dRx << " " << dRy << " " << dRz << std::endl;
688688
}

source/module_io/filename.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ std::string filename_output(
2222
// {k(optinal)}{k-point index}{g(optional)}{geometry index1}{_basis(nao|pw)}
2323
// + {".txt"/".dat"}"
2424

25-
std::set<std::string> valid_properties = {"wf", "chg", "h", "s"};
25+
std::set<std::string> valid_properties = {"wf", "chg", "hk", "sk", "tk", "vxc"};
2626
if (valid_properties.find(property) == valid_properties.end())
2727
{
28-
ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown property");
28+
ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown property in filename function");
2929
}
3030

3131
std::set<std::string> valid_basis = {"pw", "nao"};
3232
if (valid_basis.find(basis) == valid_basis.end())
3333
{
34-
ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown basis");
34+
ModuleBase::WARNING_QUIT("ModuleIO::filename_output", "unknown basis in filename function");
3535
}
3636

3737
assert(ik_local>=0);

source/module_io/write_HS.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
#ifndef WRITE_HS_H
22
#define WRITE_HS_H
33

4-
#include "module_base/global_function.h"
5-
#include "module_base/global_variable.h"
6-
74
#include <string>
5+
#include <vector>
6+
7+
//#include "module_base/global_function.h"
8+
//#include "module_base/global_variable.h"
9+
#include "module_basis/module_ao/parallel_orbitals.h" // use Parallel_Orbitals
10+
811

912
// mohan add this file 2010-09-10
1013
namespace ModuleIO
1114
{
12-
/// @brief save a square matrix
15+
template<typename T>
16+
void write_hsk(
17+
const std::string &global_out_dir,
18+
const int nspin,
19+
const int nks,
20+
const int nkstot,
21+
const std::vector<int> &ik2iktot,
22+
const std::vector<int> &isk,
23+
hamilt::Hamilt<T>* p_hamilt,
24+
const Parallel_Orbitals &pv,
25+
const bool gamma_only,
26+
const bool out_app_flag,
27+
const int istep,
28+
std::ofstream &ofs_running);
29+
30+
/// @brief save a square matrix, such as H(k) and S(k)
1331
/// @param[in] istep : the step of the calculation
1432
/// @param[in] mat : the local matrix
1533
/// @param[in] bit : true for binary, false for decimal
1634
/// @param[in] tri : true for upper triangle, false for full matrix
1735
/// @param[in] app : true for append, false for overwrite
18-
/// @param[in] label : the symbol of the matrix, like "H", "S"
1936
/// @param[in] file_name : the name of the output file
2037
/// @param[in] pv : the 2d-block parallelization information
2138
/// @param[in] drank : the rank of the current process
@@ -27,16 +44,11 @@ namespace ModuleIO
2744
const int precision,
2845
const bool tri,
2946
const bool app,
30-
const std::string label,
3147
const std::string& file_name,
3248
const Parallel_2D& pv,
3349
const int drank,
3450
const bool reduce = true);
3551

36-
37-
// mohan comment out 2021-02-10
38-
// void save_HS_ccf(const int &iter, const int &Hnnz, const int *colptr_H, const int *rowind_H,
39-
// const double *nzval_H, const double *nzval_S, bool bit);
4052
}
4153
#include "write_HS.hpp"
4254
#endif

0 commit comments

Comments
 (0)