Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8eafd55
update SIAB codes
mohanchen Aug 27, 2025
2428d49
add README.md in tools
mohanchen Aug 28, 2025
a82afbd
update SIAB package
mohanchen Aug 28, 2025
9c828ed
solve conflicts and update
mohanchen Aug 31, 2025
588cf25
small fix for the file
mohanchen Aug 31, 2025
6559298
add geometry index for outputting density matrix in k space
mohanchen Sep 1, 2025
a3193be
update output of dmk
mohanchen Sep 1, 2025
b6c1424
Merge branch 'develop' of https://github.com/mohanchen/abacus-mc into…
mohanchen Sep 1, 2025
f2cbfab
fix bug in io_dmk_test
mohanchen Sep 2, 2025
9d7990d
Merge branch '250831' into develop
mohanchen Sep 2, 2025
9195046
update output context of dmk
mohanchen Sep 2, 2025
52cccd4
rename io_dmk to write_dmk
mohanchen Sep 2, 2025
a846b7e
update dmr and dmk parameters, add precision control of the two param…
mohanchen Sep 3, 2025
a3e799a
update sparse matrix format
mohanchen Sep 3, 2025
b4decee
update write_dmk
mohanchen Sep 5, 2025
df5ccfd
update write dmk
mohanchen Sep 5, 2025
5cd07a1
update documents for out_dmk
mohanchen Sep 5, 2025
d485c9f
Merge branch 'develop' into 20250902
mohanchen Sep 5, 2025
d7f2f76
Merge branch 'develop' of https://github.com/mohanchen/abacus-mc into…
mohanchen Sep 5, 2025
bebc462
Merge branch '20250902' into develop
mohanchen Sep 5, 2025
7822e81
fix bug about dmk and dmr
mohanchen Sep 5, 2025
bf7d41c
update input-main.md
mohanchen Sep 5, 2025
e9677b4
fix a bug in out_mat_hs and out_chg that cannot read notes
mohanchen Sep 6, 2025
ab43e04
fix bug when reading the second parameter of dmk, dmr, out_chg, out_m…
mohanchen Sep 6, 2025
2fe2ecc
update tests of input parameters
mohanchen Sep 6, 2025
44bbd96
update out_chg command
mohanchen Sep 6, 2025
6d0e31d
fix exx error due to nrxx>0
mohanchen Sep 6, 2025
396b379
fix bug
mohanchen Sep 6, 2025
30ac4f6
update makefile
mohanchen Sep 6, 2025
735bfa1
update assert of nrxx, which can be 0 in some cases
mohanchen Sep 6, 2025
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/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -1698,21 +1698,21 @@ These variables are used to control the output of properties.

### out_dmk

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

### out_dmr

- **Type**: Boolean
- **Type**: Boolean \[Integer\](optional)
- **Availability**: Numerical atomic orbital basis (multi-k points)
- **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:
- nspin = 1: `dmrs1_nao.csr`;
Expand Down
30 changes: 15 additions & 15 deletions source/source_base/tool_quit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;

#else
std::cout << " " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " !NOTICE! " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " " << std::endl;
std::cout << " " << description << std::endl;
std::cout << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
std::cout << " " << std::endl;
std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
std::cout << " https://abacus.deepmodeling.com" << std::endl;
std::cout << " For any questions, propose issues on the website" << std::endl;
std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " !NOTICE! " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " !NOTICE! " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " " << std::endl;
std::cout << " " << description << std::endl;
std::cout << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
std::cout << " " << std::endl;
std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
std::cout << " https://abacus.deepmodeling.com" << std::endl;
std::cout << " For any questions, propose issues on the website" << std::endl;
std::cout << " https://github.com/deepmodeling/abacus-develop/issues" << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;
std::cout << " !NOTICE! " << std::endl;
std::cout << " ---------------------------------------------------------" << std::endl;


GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
Expand Down
3 changes: 1 addition & 2 deletions source/source_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include "source_io/berryphase.h"
#include "source_io/cal_ldos.h"
#include "source_io/cube_io.h"
#include "source_io/io_dmk.h"
#include "source_io/io_npz.h"
//#include "source_io/io_npz.h"
#include "source_io/output_dmk.h"
#include "source_io/output_log.h"
#include "source_io/output_mat_sparse.h"
Expand Down
36 changes: 33 additions & 3 deletions source/source_hamilt/module_xc/xc_functional_libxc_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ std::vector<double> XC_Functional_Libxc::convert_rho(
#pragma omp parallel for collapse(2) schedule(static, 1024)
#endif
for( int is=0; is<nspin; ++is )
{
for( int ir=0; ir<nrxx; ++ir )
{
rho[ir*nspin+is] = chr->rho[is][ir] + 1.0/nspin*chr->rho_core[ir];
}
}
return rho;
}

Expand Down Expand Up @@ -64,7 +68,9 @@ XC_Functional_Libxc::cal_gdr(
#pragma omp parallel for schedule(static, 1024)
#endif
for(std::size_t ir=0; ir<nrxx; ++ir)
{
rhor[ir] = rho[ir*nspin+is];
}
//------------------------------------------
// initialize the charge density array in reciprocal space
// bring electron charge density from real space to reciprocal space
Expand All @@ -90,7 +96,9 @@ std::vector<double> XC_Functional_Libxc::convert_sigma(
assert(nspin>0);
const std::size_t nrxx = gdr[0].size();
for(std::size_t is=1; is<nspin; ++is)
{
assert(nrxx==gdr[is].size());
}

std::vector<double> sigma( nrxx * ((1==nspin)?1:3) );
if( 1==nspin )
Expand Down Expand Up @@ -126,6 +134,7 @@ std::vector<double> XC_Functional_Libxc::cal_sgn(
const std::vector<double> &rho,
const std::vector<double> &sigma)
{
assert(nrxx>0);
std::vector<double> sgn(nrxx*nspin, 1.0);
// in the case of GGA correlation for polarized case,
// a cutoff for grho is required to ensure that libxc gives reasonable results
Expand All @@ -137,9 +146,13 @@ std::vector<double> XC_Functional_Libxc::cal_sgn(
for( int ir=0; ir<nrxx; ++ir )
{
if ( rho[ir*2]<rho_threshold || std::sqrt(std::abs(sigma[ir*3]))<grho_threshold )
{
sgn[ir*2] = 0.0;
}
if ( rho[ir*2+1]<rho_threshold || std::sqrt(std::abs(sigma[ir*3+2]))<grho_threshold )
{
sgn[ir*2+1] = 0.0;
}
}
}
return sgn;
Expand All @@ -158,8 +171,12 @@ double XC_Functional_Libxc::convert_etxc(
#pragma omp parallel for collapse(2) reduction(+:etxc) schedule(static, 256)
#endif
for( int is=0; is<nspin; ++is )
{
for( int ir=0; ir<nrxx; ++ir )
{
etxc += ModuleBase::e2 * exc[ir] * rho[ir*nspin+is] * sgn[ir*nspin+is];
}
}
return etxc;
}

Expand All @@ -176,6 +193,7 @@ std::pair<double,ModuleBase::matrix> XC_Functional_Libxc::convert_vtxc_v(
const double tpiba,
const Charge* const chr)
{
assert(nrxx>0);
double vtxc = 0.0;
ModuleBase::matrix v(nspin, nrxx);

Expand All @@ -186,9 +204,10 @@ std::pair<double,ModuleBase::matrix> XC_Functional_Libxc::convert_vtxc_v(
{
for( std::size_t ir=0; ir<nrxx; ++ir )
{
const double v_tmp = ModuleBase::e2 * vrho[ir*nspin+is] * sgn[ir*nspin+is];
const std::size_t index = ir*nspin+is;
const double v_tmp = ModuleBase::e2 * vrho[index] * sgn[index];
v(is,ir) += v_tmp;
vtxc += v_tmp * rho[ir*nspin+is];
vtxc += v_tmp * rho[index];
}
}

Expand Down Expand Up @@ -226,16 +245,20 @@ std::vector<std::vector<double>> XC_Functional_Libxc::cal_dh(
const double tpiba,
const Charge* const chr)
{
assert(nrxx>0);
std::vector<std::vector<ModuleBase::Vector3<double>>> h(
nspin,
std::vector<ModuleBase::Vector3<double>>(nrxx) );

if( 1==nspin )
{
#ifdef _OPENMP
#pragma omp parallel for schedule(static, 1024)
#endif
for( std::size_t ir=0; ir<nrxx; ++ir )
{
h[0][ir] = 2.0 * gdr[0][ir] * vsigma[ir] * 2.0 * sgn[ir];
}
}
else
{
Expand All @@ -254,7 +277,9 @@ std::vector<std::vector<double>> XC_Functional_Libxc::cal_dh(
// define two dimensional array dh [ nspin, nrxx ]
std::vector<std::vector<double>> dh(nspin, std::vector<double>(nrxx));
for( int is=0; is!=nspin; ++is )
{
XC_Functional::grad_dot( h[is].data(), dh[is].data(), chr->rhopw, tpiba);
}

return dh;
}
Expand All @@ -267,11 +292,14 @@ ModuleBase::matrix XC_Functional_Libxc::convert_v_nspin4(
const std::vector<double> &amag,
const ModuleBase::matrix &v)
{
assert(nrxx>0);
assert(PARAM.inp.nspin==4);
constexpr double vanishing_charge = 1.0e-10;
ModuleBase::matrix v_nspin4(PARAM.inp.nspin, nrxx);
for( int ir=0; ir<nrxx; ++ir )
{
v_nspin4(0,ir) = 0.5 * (v(0,ir)+v(1,ir));
}
if(PARAM.globalv.domag || PARAM.globalv.domag_z)
{
for( int ir=0; ir<nrxx; ++ir )
Expand All @@ -280,11 +308,13 @@ ModuleBase::matrix XC_Functional_Libxc::convert_v_nspin4(
{
const double vs = 0.5 * (v(0,ir)-v(1,ir));
for(int ipol=1; ipol<PARAM.inp.nspin; ++ipol)
{
v_nspin4(ipol,ir) = vs * chr->rho[ipol][ir] / amag[ir];
}
}
}
}
return v_nspin4;
}

#endif
#endif
2 changes: 1 addition & 1 deletion source/source_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if(ENABLE_LCAO)
read_wfc_nao.cpp
read_wfc_lcao.cpp
write_wfc_nao.cpp
io_dmk.cpp
write_dmk.cpp
write_dmr.cpp
sparse_matrix.cpp
file_reader.cpp
Expand Down
16 changes: 10 additions & 6 deletions source/source_io/ctrl_output_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// functions
#include "source_io/write_dos_lcao.h" // use ModuleIO::write_dos_lcao()
#include "source_io/write_dmr.h" // use ModuleIO::write_dmr()
#include "source_io/io_dmk.h" // use ModuleIO::write_dmk()
#include "source_io/write_dmk.h" // use ModuleIO::write_dmk()
#include "source_io/write_HS.h" // use ModuleIO::write_hsk()
#include "source_io/write_wfc_nao.h" // use ModuleIO::write_wfc_nao()
#include "source_io/output_mat_sparse.h" // use ModuleIO::output_mat_sparse()
Expand Down Expand Up @@ -92,26 +92,30 @@ void ctrl_output_lcao(UnitCell& ucell,
//------------------------------------------------------------------
//! 1) Output density matrix DM(R)
//------------------------------------------------------------------
if(PARAM.inp.out_dmr)
if(PARAM.inp.out_dmr[0])
{
const auto& dmr_vector = pelec->get_DM()->get_DMR_vector();
ModuleIO::write_dmr(dmr_vector, pv, out_app_flag,

const int precision = PARAM.inp.out_dmr[1];

ModuleIO::write_dmr(dmr_vector, precision, pv, out_app_flag,
ucell.get_iat2iwt(), ucell.nat, istep);
}

//------------------------------------------------------------------
//! 2) Output density matrix DM(k)
//------------------------------------------------------------------
if (PARAM.inp.out_dmk)
if (PARAM.inp.out_dmk[0])
{
std::vector<double> efermis(nspin == 2 ? 2 : 1);
for (int ispin = 0; ispin < efermis.size(); ispin++)
{
efermis[ispin] = pelec->eferm.get_efval(ispin);
}
const int precision = 3;
const int precision = PARAM.inp.out_dmk[1];

ModuleIO::write_dmk(pelec->get_DM()->get_DMK_vector(),
precision, efermis, &(ucell), pv);
precision, efermis, &(ucell), pv, istep);
}

//------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions source/source_io/module_parameter/input_parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ struct Input_para
bool out_mul = false; ///< qifeng add 2019-9-10
bool out_proj_band = false; ///< projected band structure calculation jiyy add 2022-05-11
std::string out_level = "ie"; ///< control the output information.
bool out_dmk = false; ///< output density matrix DM(k)
bool out_dmr = false; ///< output density matrix DM(R)
std::vector<int> out_dmr = {0, 8}; ///< output density matrix in real space DM(R)
std::vector<int> out_dmk = {0, 8}; ///< output density matrix in reciprocal space DM(k)
bool out_bandgap = false; ///< QO added for bandgap printing
std::vector<int> out_mat_hs = {0, 8}; ///< output H matrix and S matrix in local basis.
std::vector<int> out_mat_tk = {0, 8}; ///< output T(k) matrix in local basis.
Expand Down
2 changes: 2 additions & 0 deletions source/source_io/nscf_band.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void ModuleIO::nscf_band(
ModuleBase::TITLE("ModuleIO","nscf_band");
ModuleBase::timer::tick("ModuleIO", "nscf_band");

assert(precision>0);

GlobalV::ofs_running << "\n";
GlobalV::ofs_running << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
GlobalV::ofs_running << " | |" << std::endl;
Expand Down
Loading
Loading