Skip to content

Commit 9e6bb70

Browse files
authored
Update out_dmk and out_dmr (#6481)
* update SIAB codes * add README.md in tools * update SIAB package * small fix for the file * add geometry index for outputting density matrix in k space * update output of dmk * fix bug in io_dmk_test * update output context of dmk * rename io_dmk to write_dmk * update dmr and dmk parameters, add precision control of the two parameters * update sparse matrix format * update write_dmk * update write dmk * update documents for out_dmk * fix bug about dmk and dmr * update input-main.md * fix a bug in out_mat_hs and out_chg that cannot read notes * fix bug when reading the second parameter of dmk, dmr, out_chg, out_mat_hs, out_mat_tk, out_mat_l * update tests of input parameters * update out_chg command * fix exx error due to nrxx>0 * fix bug * update makefile * update assert of nrxx, which can be 0 in some cases
1 parent d71661d commit 9e6bb70

File tree

30 files changed

+396
-463
lines changed

30 files changed

+396
-463
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,21 +1699,21 @@ These variables are used to control the output of properties.
16991699

17001700
### out_dmk
17011701

1702-
- **Type**: Boolean
1702+
- **Type**: Boolean \[Integer\](optional)
17031703
- **Availability**: Numerical atomic orbital basis
17041704
- **Description**: Whether to output the density matrix for each k-point into files in the folder `OUT.${suffix}`. The files are named as:
17051705
- For gamma only case:
1706-
- nspin = 1: `dms1_nao.csr`;
1706+
- nspin = 1 and 4: `dm_nao.csr`;
17071707
- nspin = 2: `dms1_nao.csr` and `dms2_nao.csr` for the two spin channels.
17081708
- For multi-k points case:
1709-
- nspin = 1: `dms1k1_nao.csr`, `dms1k2_nao.csr`, ...;
1710-
- nspin = 2: `dms1k1_nao.csr`... and `dms2k1_nao.csr`... for the two spin channels.
1709+
- nspin = 1 and 4: `dmk1_nao.csr`, `dmk2_nao.csr`, ...;
1710+
- nspin = 2: `dmk1s1_nao.csr`... and `dmk1s2_nao.csr`... for the two spin channels.
17111711
- **Default**: False
17121712
- **Note**: In the 3.10-LTS version, the parameter is named `out_dm` and the file names are SPIN1_DM and SPIN2_DM, etc.
17131713

17141714
### out_dmr
17151715

1716-
- **Type**: Boolean
1716+
- **Type**: Boolean \[Integer\](optional)
17171717
- **Availability**: Numerical atomic orbital basis (multi-k points)
17181718
- **Description**: Whether to output the density matrix with Bravias lattice vector R index into files in the folder `OUT.${suffix}`. The files are named as `dmr{s}{spin index}{g}{geometry index}{_nao} + {".csr"}`. Here, 's' refers to spin, where s1 means spin up channel while s2 means spin down channel, and the sparse matrix format 'csr' is mentioned in [out_mat_hs2](#out_mat_hs2). Finally, if [out_app_flag](#out_app_flag) is set to false, the file name contains the optional 'g' index for each ionic step that may have different geometries, and if [out_app_flag](#out_app_flag) is set to true, the density matrix with respect to Bravias lattice vector R accumulates during ionic steps:
17191719
- nspin = 1: `dmrs1_nao.csr`;

examples/relax/lcao_output/INPUT

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ suffix autotest
55
nbands 8
66
calculation relax #cell-relax
77
ecutwfc 10
8-
scf_nmax 2
8+
scf_nmax 20
99

1010
basis_type lcao
11-
relax_nmax 5
11+
relax_nmax 1
1212

1313
cal_stress 1
1414
stress_thr 1e-6
@@ -25,16 +25,19 @@ relax_method bfgs
2525
pseudo_dir ../../../tests/PP_ORB
2626
orbital_dir ../../../tests/PP_ORB
2727

28-
nspin 4
28+
nspin 1
2929

30-
out_chg 1
31-
out_pot 1
32-
out_dmk 1
33-
out_dmr 1
30+
out_mat_hs 0 // note
31+
out_mat_tk 1 // note
32+
out_mat_l 1 // note
33+
out_chg 0 8 // note
34+
out_pot 0
35+
out_dmk 0 // note
36+
out_dmr 0 // note
3437
#out_wfc_lcao 1 // OK
35-
out_dos 1
36-
out_band 1
37-
out_stru 1
38+
out_dos 0
39+
out_band 0
40+
out_stru 0
3841
out_app_flag 0
3942

4043
out_interval 1

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ OBJS_IO_LCAO=cal_r_overlap_R.o\
607607
write_eig_occ.o\
608608
get_pchg_lcao.o\
609609
get_wf_lcao.o\
610-
io_dmk.o\
610+
write_dmk.o\
611611
unk_overlap_lcao.o\
612612
read_wfc_nao.o\
613613
read_wfc_lcao.o\

source/source_base/tool_quit.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,21 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
9191
std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
9292

9393
#else
94-
std::cout << " " << std::endl;
95-
std::cout << " ---------------------------------------------------------" << std::endl;
96-
std::cout << " !NOTICE! " << std::endl;
97-
std::cout << " ---------------------------------------------------------" << std::endl;
98-
std::cout << " " << std::endl;
99-
std::cout << " " << description << std::endl;
100-
std::cout << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
101-
std::cout << " " << std::endl;
102-
std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
103-
std::cout << " https://abacus.deepmodeling.com" << std::endl;
104-
std::cout << " For any questions, propose issues on the website" << std::endl;
105-
std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
106-
std::cout << " ---------------------------------------------------------" << std::endl;
107-
std::cout << " !NOTICE! " << std::endl;
108-
std::cout << " ---------------------------------------------------------" << std::endl;
94+
std::cout << " " << std::endl;
95+
std::cout << " ---------------------------------------------------------" << std::endl;
96+
std::cout << " !NOTICE! " << std::endl;
97+
std::cout << " ---------------------------------------------------------" << std::endl;
98+
std::cout << " " << std::endl;
99+
std::cout << " " << description << std::endl;
100+
std::cout << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
101+
std::cout << " " << std::endl;
102+
std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
103+
std::cout << " https://abacus.deepmodeling.com" << std::endl;
104+
std::cout << " For any questions, propose issues on the website" << std::endl;
105+
std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
106+
std::cout << " ---------------------------------------------------------" << std::endl;
107+
std::cout << " !NOTICE! " << std::endl;
108+
std::cout << " ---------------------------------------------------------" << std::endl;
109109

110110

111111
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
#include "source_io/berryphase.h"
1414
#include "source_io/cal_ldos.h"
1515
#include "source_io/cube_io.h"
16-
#include "source_io/io_dmk.h"
17-
#include "source_io/io_npz.h"
16+
//#include "source_io/io_npz.h"
1817
#include "source_io/output_dmk.h"
1918
#include "source_io/output_log.h"
2019
#include "source_io/output_mat_sparse.h"

source/source_hamilt/module_xc/xc_functional_libxc_tools.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ std::vector<double> XC_Functional_Libxc::convert_rho(
1616
#pragma omp parallel for collapse(2) schedule(static, 1024)
1717
#endif
1818
for( int is=0; is<nspin; ++is )
19+
{
1920
for( int ir=0; ir<nrxx; ++ir )
21+
{
2022
rho[ir*nspin+is] = chr->rho[is][ir] + 1.0/nspin*chr->rho_core[ir];
23+
}
24+
}
2125
return rho;
2226
}
2327

@@ -64,7 +68,9 @@ XC_Functional_Libxc::cal_gdr(
6468
#pragma omp parallel for schedule(static, 1024)
6569
#endif
6670
for(std::size_t ir=0; ir<nrxx; ++ir)
71+
{
6772
rhor[ir] = rho[ir*nspin+is];
73+
}
6874
//------------------------------------------
6975
// initialize the charge density array in reciprocal space
7076
// bring electron charge density from real space to reciprocal space
@@ -90,7 +96,9 @@ std::vector<double> XC_Functional_Libxc::convert_sigma(
9096
assert(nspin>0);
9197
const std::size_t nrxx = gdr[0].size();
9298
for(std::size_t is=1; is<nspin; ++is)
99+
{
93100
assert(nrxx==gdr[is].size());
101+
}
94102

95103
std::vector<double> sigma( nrxx * ((1==nspin)?1:3) );
96104
if( 1==nspin )
@@ -126,6 +134,7 @@ std::vector<double> XC_Functional_Libxc::cal_sgn(
126134
const std::vector<double> &rho,
127135
const std::vector<double> &sigma)
128136
{
137+
//assert(nrxx>0); // adding this once will cause error in examples
129138
std::vector<double> sgn(nrxx*nspin, 1.0);
130139
// in the case of GGA correlation for polarized case,
131140
// a cutoff for grho is required to ensure that libxc gives reasonable results
@@ -137,9 +146,13 @@ std::vector<double> XC_Functional_Libxc::cal_sgn(
137146
for( int ir=0; ir<nrxx; ++ir )
138147
{
139148
if ( rho[ir*2]<rho_threshold || std::sqrt(std::abs(sigma[ir*3]))<grho_threshold )
149+
{
140150
sgn[ir*2] = 0.0;
151+
}
141152
if ( rho[ir*2+1]<rho_threshold || std::sqrt(std::abs(sigma[ir*3+2]))<grho_threshold )
153+
{
142154
sgn[ir*2+1] = 0.0;
155+
}
143156
}
144157
}
145158
return sgn;
@@ -158,8 +171,12 @@ double XC_Functional_Libxc::convert_etxc(
158171
#pragma omp parallel for collapse(2) reduction(+:etxc) schedule(static, 256)
159172
#endif
160173
for( int is=0; is<nspin; ++is )
174+
{
161175
for( int ir=0; ir<nrxx; ++ir )
176+
{
162177
etxc += ModuleBase::e2 * exc[ir] * rho[ir*nspin+is] * sgn[ir*nspin+is];
178+
}
179+
}
163180
return etxc;
164181
}
165182

@@ -176,6 +193,7 @@ std::pair<double,ModuleBase::matrix> XC_Functional_Libxc::convert_vtxc_v(
176193
const double tpiba,
177194
const Charge* const chr)
178195
{
196+
// assert(nrxx>0); // will cause error
179197
double vtxc = 0.0;
180198
ModuleBase::matrix v(nspin, nrxx);
181199

@@ -186,9 +204,10 @@ std::pair<double,ModuleBase::matrix> XC_Functional_Libxc::convert_vtxc_v(
186204
{
187205
for( std::size_t ir=0; ir<nrxx; ++ir )
188206
{
189-
const double v_tmp = ModuleBase::e2 * vrho[ir*nspin+is] * sgn[ir*nspin+is];
207+
const std::size_t index = ir*nspin+is;
208+
const double v_tmp = ModuleBase::e2 * vrho[index] * sgn[index];
190209
v(is,ir) += v_tmp;
191-
vtxc += v_tmp * rho[ir*nspin+is];
210+
vtxc += v_tmp * rho[index];
192211
}
193212
}
194213

@@ -226,16 +245,20 @@ std::vector<std::vector<double>> XC_Functional_Libxc::cal_dh(
226245
const double tpiba,
227246
const Charge* const chr)
228247
{
248+
//assert(nrxx>0); // this line will cause bug
229249
std::vector<std::vector<ModuleBase::Vector3<double>>> h(
230250
nspin,
231251
std::vector<ModuleBase::Vector3<double>>(nrxx) );
232-
if( 1==nspin )
252+
253+
if( nspin==1 )
233254
{
234255
#ifdef _OPENMP
235256
#pragma omp parallel for schedule(static, 1024)
236257
#endif
237258
for( std::size_t ir=0; ir<nrxx; ++ir )
259+
{
238260
h[0][ir] = 2.0 * gdr[0][ir] * vsigma[ir] * 2.0 * sgn[ir];
261+
}
239262
}
240263
else
241264
{
@@ -254,7 +277,9 @@ std::vector<std::vector<double>> XC_Functional_Libxc::cal_dh(
254277
// define two dimensional array dh [ nspin, nrxx ]
255278
std::vector<std::vector<double>> dh(nspin, std::vector<double>(nrxx));
256279
for( int is=0; is!=nspin; ++is )
280+
{
257281
XC_Functional::grad_dot( h[is].data(), dh[is].data(), chr->rhopw, tpiba);
282+
}
258283

259284
return dh;
260285
}
@@ -267,11 +292,14 @@ ModuleBase::matrix XC_Functional_Libxc::convert_v_nspin4(
267292
const std::vector<double> &amag,
268293
const ModuleBase::matrix &v)
269294
{
295+
//assert(nrxx>0);
270296
assert(PARAM.inp.nspin==4);
271297
constexpr double vanishing_charge = 1.0e-10;
272298
ModuleBase::matrix v_nspin4(PARAM.inp.nspin, nrxx);
273299
for( int ir=0; ir<nrxx; ++ir )
300+
{
274301
v_nspin4(0,ir) = 0.5 * (v(0,ir)+v(1,ir));
302+
}
275303
if(PARAM.globalv.domag || PARAM.globalv.domag_z)
276304
{
277305
for( int ir=0; ir<nrxx; ++ir )
@@ -280,11 +308,13 @@ ModuleBase::matrix XC_Functional_Libxc::convert_v_nspin4(
280308
{
281309
const double vs = 0.5 * (v(0,ir)-v(1,ir));
282310
for(int ipol=1; ipol<PARAM.inp.nspin; ++ipol)
311+
{
283312
v_nspin4(ipol,ir) = vs * chr->rho[ipol][ir] / amag[ir];
313+
}
284314
}
285315
}
286316
}
287317
return v_nspin4;
288318
}
289319

290-
#endif
320+
#endif

source/source_io/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if(ENABLE_LCAO)
6060
read_wfc_nao.cpp
6161
read_wfc_lcao.cpp
6262
write_wfc_nao.cpp
63-
io_dmk.cpp
63+
write_dmk.cpp
6464
write_dmr.cpp
6565
sparse_matrix.cpp
6666
file_reader.cpp

source/source_io/ctrl_output_lcao.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// functions
99
#include "source_io/write_dos_lcao.h" // use ModuleIO::write_dos_lcao()
1010
#include "source_io/write_dmr.h" // use ModuleIO::write_dmr()
11-
#include "source_io/io_dmk.h" // use ModuleIO::write_dmk()
11+
#include "source_io/write_dmk.h" // use ModuleIO::write_dmk()
1212
#include "source_io/write_HS.h" // use ModuleIO::write_hsk()
1313
#include "source_io/write_wfc_nao.h" // use ModuleIO::write_wfc_nao()
1414
#include "source_io/output_mat_sparse.h" // use ModuleIO::output_mat_sparse()
@@ -92,26 +92,30 @@ void ctrl_output_lcao(UnitCell& ucell,
9292
//------------------------------------------------------------------
9393
//! 1) Output density matrix DM(R)
9494
//------------------------------------------------------------------
95-
if(PARAM.inp.out_dmr)
95+
if(PARAM.inp.out_dmr[0])
9696
{
9797
const auto& dmr_vector = pelec->get_DM()->get_DMR_vector();
98-
ModuleIO::write_dmr(dmr_vector, pv, out_app_flag,
98+
99+
const int precision = PARAM.inp.out_dmr[1];
100+
101+
ModuleIO::write_dmr(dmr_vector, precision, pv, out_app_flag,
99102
ucell.get_iat2iwt(), ucell.nat, istep);
100103
}
101104

102105
//------------------------------------------------------------------
103106
//! 2) Output density matrix DM(k)
104107
//------------------------------------------------------------------
105-
if (PARAM.inp.out_dmk)
108+
if (PARAM.inp.out_dmk[0])
106109
{
107110
std::vector<double> efermis(nspin == 2 ? 2 : 1);
108111
for (int ispin = 0; ispin < efermis.size(); ispin++)
109112
{
110113
efermis[ispin] = pelec->eferm.get_efval(ispin);
111114
}
112-
const int precision = 3;
115+
const int precision = PARAM.inp.out_dmk[1];
116+
113117
ModuleIO::write_dmk(pelec->get_DM()->get_DMK_vector(),
114-
precision, efermis, &(ucell), pv);
118+
precision, efermis, &(ucell), pv, istep);
115119
}
116120

117121
//------------------------------------------------------------------

source/source_io/module_parameter/input_parameter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ struct Input_para
374374
bool out_mul = false; ///< qifeng add 2019-9-10
375375
bool out_proj_band = false; ///< projected band structure calculation jiyy add 2022-05-11
376376
std::string out_level = "ie"; ///< control the output information.
377-
bool out_dmk = false; ///< output density matrix DM(k)
378-
bool out_dmr = false; ///< output density matrix DM(R)
377+
std::vector<int> out_dmr = {0, 8}; ///< output density matrix in real space DM(R)
378+
std::vector<int> out_dmk = {0, 8}; ///< output density matrix in reciprocal space DM(k)
379379
bool out_bandgap = false; ///< QO added for bandgap printing
380380
std::vector<int> out_mat_hs = {0, 8}; ///< output H matrix and S matrix in local basis.
381381
std::vector<int> out_mat_tk = {0, 8}; ///< output T(k) matrix in local basis.

source/source_io/nscf_band.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ void ModuleIO::nscf_band(
2121
ModuleBase::TITLE("ModuleIO","nscf_band");
2222
ModuleBase::timer::tick("ModuleIO", "nscf_band");
2323

24+
assert(precision>0);
25+
2426
GlobalV::ofs_running << "\n";
2527
GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
2628
GlobalV::ofs_running << " | |" << std::endl;

0 commit comments

Comments
 (0)