Skip to content

Commit d989b82

Browse files
authored
Feature: term-separated LCAO Hamiltonian atomic derivatives (dH) (#7473)
* initial version of writing H and dH terms (except exx) * correct 1-electron terms: T, Vl, Vnl * fix pot register * Gint_drho * add EXX H&dH, dH (H-F term) of Veff Hartree, and refactor * add dm_container_to_Ds and exx nscf-from-dm workflow; minor refactor OperatorEXX * fix parallel segfaults and kinetic sign * XC H-F term (FD) * enable value-adding HContainers, total dH and atom-specified output; enable nspin=2 * dH test cases * exclude cal_exx_dHs with __EXX_DEV flag, waiting for LibRI PR merged * small fixes * change scf_in_dmr ref due to not renormalizing charge at init_chg==dm * fix conflict #7462 #7475 #7478 * Revert reference change by adding option dm_no_renormalize to init_chg This reverts commit ed14d9f. * fix pyabacus CI
1 parent b389b8f commit d989b82

71 files changed

Lines changed: 4850 additions & 129 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ option(ENABLE_MLALGO "Enable the machine learning algorithms" OFF)
3535
option(ENABLE_LCAO "Enable LCAO algorithm" ON)
3636
option(USE_ELPA "Enable ELPA for LCAO" ON)
3737
option(ENABLE_LIBRI "Enable LibRI for hybrid functional" OFF)
38+
option(EXX_DEV "Enable LibRI developing features" OFF)
3839
option(ENABLE_LIBCOMM "Enable LibComm" OFF)
3940
option(ENABLE_PEXSI "Enable PEXSI for LCAO" OFF)
4041
option(ENABLE_DFTD4 "Enable DFT-D4 dispersion correction" OFF)
@@ -651,6 +652,9 @@ if(ENABLE_LIBRI)
651652
endif()
652653
abacus_add_feature_definitions(__EXX EXX_DM=3 EXX_H_COMM=2 TEST_EXX_LCAO=0
653654
TEST_EXX_RADIAL=1)
655+
if(EXX_DEV)
656+
abacus_add_feature_definitions(__EXX_DEV)
657+
endif()
654658
endif()
655659

656660
if(ENABLE_LIBRI OR DEFINED LIBCOMM_DIR)

docs/advanced/input_files/input-main.md

Lines changed: 131 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,23 @@
166166
- [out\_stru](#out_stru)
167167
- [out\_level](#out_level)
168168
- [out\_mat\_hs](#out_mat_hs)
169+
- [out\_mat\_h\_t](#out_mat_h_t)
170+
- [out\_mat\_h\_vl](#out_mat_h_vl)
171+
- [out\_mat\_h\_vnl](#out_mat_h_vnl)
172+
- [out\_mat\_h\_vh](#out_mat_h_vh)
173+
- [out\_mat\_h\_vxc](#out_mat_h_vxc)
174+
- [out\_mat\_h\_exx](#out_mat_h_exx)
169175
- [out\_mat\_hs2](#out_mat_hs2)
170176
- [out\_mat\_tk](#out_mat_tk)
171177
- [out\_mat\_r](#out_mat_r)
172178
- [out\_mat\_t](#out_mat_t)
173179
- [out\_mat\_dh](#out_mat_dh)
180+
- [out\_mat\_dh\_t](#out_mat_dh_t)
181+
- [out\_mat\_dh\_vl](#out_mat_dh_vl)
182+
- [out\_mat\_dh\_vnl](#out_mat_dh_vnl)
183+
- [out\_mat\_dh\_vh](#out_mat_dh_vh)
184+
- [out\_mat\_dh\_vxc](#out_mat_dh_vxc)
185+
- [out\_mat\_dh\_exx](#out_mat_dh_exx)
174186
- [out\_mat\_ds](#out_mat_ds)
175187
- [out\_mat\_xc](#out_mat_xc)
176188
- [out\_mat\_xc2](#out_mat_xc2)
@@ -1869,7 +1881,7 @@
18691881

18701882
The corresponding sequence of the orbitals can be seen in Basis Set.
18711883

1872-
Also controled by out_freq_ion and out_app_flag.
1884+
Also controlled by out_freq_ion and out_app_flag.
18731885

18741886
> Note: In the 3.10-LTS version, the file names are WFC_NAO_GAMMA1_ION1.txt and WFC_NAO_K1_ION1.txt, etc.
18751887
- **Default**: 0
@@ -1930,7 +1942,7 @@
19301942

19311943
- **Type**: Boolean \[Integer\](optional)
19321944
- **Availability**: *Numerical atomic orbital basis*
1933-
- **Description**: Whether to print the upper triangular part of the Hamiltonian matrices and overlap matrices for each k-point into files in the directory OUT.${suffix}. The second number controls precision. For more information, please refer to hs_matrix.md. Also controled by out_freq_ion and out_app_flag.
1945+
- **Description**: Whether to print the upper triangular part of the Hamiltonian matrices and overlap matrices for each k-point into files in the directory OUT.${suffix}. The second number controls precision. For more information, please refer to hs_matrix.md. Also controlled by out_freq_ion and out_app_flag.
19341946
- For gamma only case:
19351947
- nspin = 1: hks1_nao.txt for the Hamiltonian matrix and sks1_nao.txt for the overlap matrix;
19361948
- nspin = 2: hks1_nao.txt and hks2_nao.txt for the Hamiltonian matrix and sks1_nao.txt for the overlap matrix. Note that the code will not output sks2_nao.txt because it is the same as sks1_nao.txt;
@@ -1944,6 +1956,54 @@
19441956
- **Default**: False 8
19451957
- **Unit**: Ry
19461958

1959+
### out_mat_h_t
1960+
1961+
- **Type**: Boolean \[Integer\](optional)
1962+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
1963+
- **Description**: Whether to print the kinetic energy matrix $T_{\mu\nu}(k) = \langle\phi_\mu|\hat{T}|\phi_\nu\rangle(k)$ for each k-point. The output format and file naming (e.g. `tks1_nao.txt`, `tks1k1_nao.txt`) follow [`out_mat_hs`](#out_mat_hs).
1964+
- **Default**: False 8
1965+
- **Unit**: Ry
1966+
1967+
### out_mat_h_vl
1968+
1969+
- **Type**: Boolean \[Integer\](optional)
1970+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
1971+
- **Description**: Whether to print the local pseudopotential matrix $V^L_{\mu\nu}(k) = \langle\phi_\mu|\hat{V}^L|\phi_\nu\rangle(k)$ for each k-point. The output format and file naming (e.g. `vlks1_nao.txt`, `vlks1k1_nao.txt`) follow [`out_mat_hs`](#out_mat_hs).
1972+
- **Default**: False 8
1973+
- **Unit**: Ry
1974+
1975+
### out_mat_h_vnl
1976+
1977+
- **Type**: Boolean \[Integer\](optional)
1978+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
1979+
- **Description**: Whether to print the nonlocal pseudopotential (Kleinman–Bylander) matrix $V^{NL}_{\mu\nu}(k) = \langle\phi_\mu|\hat{V}^{NL}|\phi_\nu\rangle(k)$ for each k-point. The output format and file naming (e.g. `vnlks1_nao.txt`, `vnlks1k1_nao.txt`) follow [`out_mat_hs`](#out_mat_hs).
1980+
- **Default**: False 8
1981+
- **Unit**: Ry
1982+
1983+
### out_mat_h_vh
1984+
1985+
- **Type**: Boolean \[Integer\](optional)
1986+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
1987+
- **Description**: Whether to print the Hartree matrix $V^H_{\mu\nu}(k) = \langle\phi_\mu|\hat{V}^H|\phi_\nu\rangle(k)$ for each k-point. The output format and file naming (e.g. `vhks1_nao.txt`, `vhks1k1_nao.txt`) follow [`out_mat_hs`](#out_mat_hs).
1988+
- **Default**: False 8
1989+
- **Unit**: Ry
1990+
1991+
### out_mat_h_vxc
1992+
1993+
- **Type**: Boolean \[Integer\](optional)
1994+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
1995+
- **Description**: Whether to print the exchange-correlation matrix $V^{XC}_{\mu\nu}(k) = \langle\phi_\mu|\hat{V}^{XC}|\phi_\nu\rangle(k)$ for each k-point. The output format and file naming (e.g. `vxcks1_nao.txt`, `vxcks1k1_nao.txt`) follow [`out_mat_hs`](#out_mat_hs).
1996+
- **Default**: False 8
1997+
- **Unit**: Ry
1998+
1999+
### out_mat_h_exx
2000+
2001+
- **Type**: Boolean \[Integer\](optional)
2002+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4, hybrid functional only)*
2003+
- **Description**: Whether to print the exact-exchange matrix $V^{EXX}_{\mu\nu}(k) = \langle\phi_\mu|\hat{V}^{EXX}|\phi_\nu\rangle(k)$ for each k-point. The output format and file naming (e.g. `vexxks1_nao.txt`, `vexxks1k1_nao.txt`) follow [`out_mat_hs`](#out_mat_hs). Requires a hybrid functional (`cal_exx = true`).
2004+
- **Default**: False 8
2005+
- **Unit**: Ry
2006+
19472007
### out_mat_hs2
19482008

19492009
- **Type**: Boolean \[Integer\](optional)
@@ -1978,27 +2038,90 @@
19782038

19792039
- **Type**: Boolean \[Integer\](optional)
19802040
- **Availability**: *Numerical atomic orbital basis (not gamma-only algorithm)*
1981-
- **Description**: Generate files containing the kinetic energy matrix. The optional second parameter controls text output precision. The format will be the same as the Hamiltonian matrix and overlap matrix as mentioned in out_mat_hs2. The name of the files will be trs1_nao.csr and so on. Also controled by out_freq_ion and out_app_flag.
2041+
- **Description**: Generate files containing the kinetic energy matrix. The optional second parameter controls text output precision. The format will be the same as the Hamiltonian matrix and overlap matrix as mentioned in out_mat_hs2. The name of the files will be trs1_nao.csr and so on. Also controlled by out_freq_ion and out_app_flag.
19822042

19832043
> Note: In the 3.10-LTS version, the file name is data-TR-sparse_SPIN0.csr.
19842044
- **Default**: False 8
19852045
- **Unit**: Ry
19862046

19872047
### out_mat_dh
19882048

1989-
- **Type**: Boolean \[Integer\](optional)
1990-
- **Availability**: *Numerical atomic orbital basis (not gamma-only algorithm)*
1991-
- **Description**: Whether to print files containing the derivatives of the Hamiltonian matrix. The optional second parameter controls text output precision. The format will be the same as the Hamiltonian matrix and overlap matrix as mentioned in out_mat_hs2. The name of the files will be dhrxs1_nao.csr, dhrys1_nao.csr, dhrzs1_nao.csr and so on. Also controled by out_freq_ion and out_app_flag.
1992-
2049+
- **Type**: Integer
2050+
- **Availability**: *Numerical atomic orbital basis*
2051+
- **Description**: Whether to print files containing the derivatives of the Hamiltonian matrix $dH(k)/d\tau_I=d\braket{\phi|\hat{H}|\phi}(k)/d\tau_I$ where $\tau_I$ is the Ith atom position with the dense format as `out_mat_dh`. The names are dhk[x/y/z]_iat[I][_ik]_nao.txt.
2052+
- See also the term-separated output parameters: [`out_mat_dh_t`](#out_mat_dh_t), [`out_mat_dh_vl`](#out_mat_dh_vl), [`out_mat_dh_vnl`](#out_mat_dh_vnl), [`out_mat_dh_vh`](#out_mat_dh_vh), [`out_mat_dh_vxc`](#out_mat_dh_vxc) and [`out_mat_dh_exx`](#out_mat_dh_exx).
2053+
- If not gamma-only, also $\braket{\nabla\phi|\hat{H}\phi}(R)$ of sparse format as `out_mat_hs2` will also be output. The name of the files will be dhrxs1_nao.csr, dhrys1_nao.csr, dhrzs1_nao.csr and so on. Also controlled by out_freq_ion and out_app_flag.
19932054
> Note: In the 3.10-LTS version, the file name is data-dHRx-sparse_SPIN0.csr and so on.
2055+
- **Format**: `<enable> [precision] [iat1 iat2 ...]`
2056+
- The first value (0/1) enables or disables output.
2057+
- The second optional value sets the output precision (number of significant digits, default: 8).
2058+
- Starting from the third value, **1-based atom indices** can be listed to restrict the output to derivatives with respect to those specific atoms only. If no atom indices are given, derivatives are written for all atoms.
2059+
2060+
For example, `out_mat_dh 1 8 1 3` writes dH/dR for atoms 1 and 3 only (1-based indexing).
2061+
2062+
- **Default**: 0 8
2063+
- **Unit**: Ry/Bohr
2064+
2065+
### out_mat_dh_t
2066+
2067+
- **Type**: Integer
2068+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
2069+
- **Description**: Whether to print files containing the kinetic energy contribution to the Hamiltonian derivative, see [`out_mat_dh`](#out_mat_dh) for the same format. Output files: dhk[x/y/z]_iat[I][_ik]_nao.txt.
2070+
2071+
- **Default**: 0 8
2072+
- **Unit**: Ry/Bohr
2073+
2074+
### out_mat_dh_vl
2075+
2076+
- **Type**: Integer
2077+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
2078+
- **Description**: Whether to print files containing the local pseudopotential contribution to the Hamiltonian derivative, see [`out_mat_dh`](#out_mat_dh) for the same format. Output files: dvlk[x/y/z]_iat[I][_ik]_nao.txt.
2079+
2080+
- **Default**: 0 8
2081+
- **Unit**: Ry/Bohr
2082+
2083+
### out_mat_dh_vnl
2084+
2085+
- **Type**: Integer
2086+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
2087+
- **Description**: Whether to print files containing the nonlocal pseudopotential contribution to the Hamiltonian derivative, see [`out_mat_dh`](#out_mat_dh) for the same format. Output files: dvnlk[x/y/z]_iat[I][_ik]_nao.txt.
2088+
2089+
- **Default**: 0 8
2090+
- **Unit**: Ry/Bohr
2091+
2092+
### out_mat_dh_vh
2093+
2094+
- **Type**: Integer
2095+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
2096+
- **Description**: Whether to print files containing the Hartree contribution to the Hamiltonian derivative, see [`out_mat_dh`](#out_mat_dh) for the same format. Output files: dvhk[x/y/z]_iat[I][_ik]_nao.txt.
2097+
2098+
- **Default**: 0 8
2099+
- **Unit**: Ry/Bohr
2100+
2101+
### out_mat_dh_vxc
2102+
2103+
- **Type**: Integer
2104+
- **Availability**: *Numerical atomic orbital basis (nspin ≠ 4)*
2105+
- **Description**: Whether to print files containing the exchange-correlation contribution to the Hamiltonian derivative, see [`out_mat_dh`](#out_mat_dh) for the same format. Output files: dvxck[x/y/z]_iat[I][_ik]_nao.txt.
2106+
2107+
- **Default**: 0 8
2108+
- **Unit**: Ry/Bohr
2109+
2110+
### out_mat_dh_exx
2111+
2112+
- **Type**: Integer
2113+
- **Availability**: *Numerical atomic orbital basis, hybrid functional only (nspin ≠ 4)*
2114+
- Currently only availablewhen compiled with the personal developing branch of LibRI and -DEXX_DEV flag, waiting for the new release of LibRI to remove the flag.
2115+
- **Description**: Whether to print files containing the exact-exchange contribution to the Hamiltonian derivative, see [`out_mat_dh`](#out_mat_dh) for the same format. Output files: dvexxk[x/y/z]_iat[I][_ik]_nao.txt.
2116+
19942117
- **Default**: 0 8
19952118
- **Unit**: Ry/Bohr
19962119

19972120
### out_mat_ds
19982121

19992122
- **Type**: Boolean \[Integer\](optional)
20002123
- **Availability**: *Numerical atomic orbital basis (not gamma-only algorithm)*
2001-
- **Description**: Whether to print files containing the derivatives of the overlap matrix. The optional second parameter controls text output precision. The format will be the same as the overlap matrix as mentioned in out_mat_dh. The name of the files will be dsxrs1_nao.csr and so on. Also controled by out_freq_ion and out_app_flag. This feature can be used with calculation get_s.
2124+
- **Description**: Whether to print files containing the derivatives of the overlap matrix. The optional second parameter controls text output precision. The format will be the same as the overlap matrix as mentioned in out_mat_dh. The name of the files will be dsxrs1_nao.csr and so on. Also controlled by out_freq_ion and out_app_flag. This feature can be used with calculation get_s.
20022125

20032126
> Note: In the 3.10-LTS version, the file name is data-dSRx-sparse_SPIN0.csr and so on.
20042127
- **Default**: False 8

python/pyabacus/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test = ["contourpy","cycler","exceptiongroup","fonttools","importlib-metadata","
3030

3131
[tool.scikit-build]
3232
wheel.expand-macos-universal-tags = true
33-
cmake.verbose = true
33+
build.verbose = true
3434
logging.level = "INFO"
3535

3636
[tool.scikit-build.cmake.define]

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
180180
if(istep == 0)//if the first scf step, readin DMR from file,
181181
{
182182
//calculate or readin the density matrix DMR
183-
if(PARAM.inp.init_chg == "dm")
183+
if(PARAM.inp.init_chg == "dm" || PARAM.inp.init_chg == "dm_no_renormalize")
184184
{
185185
//! 13.1.1) init charge density from density matrix file
186186
LCAO_domain::init_chg_dm<TK>(PARAM.globalv.global_readin_dir, PARAM.inp.nspin,
@@ -546,6 +546,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
546546
PARAM.inp, this->kv, this->pelec, this->dmat.dm, this->pv,
547547
this->gd, this->psi, hamilt_lcao, this->dftu, this->two_center_bundle_,
548548
this->orb_, this->pw_wfc, this->pw_rho, this->pw_big, this->sf,
549+
this->pw_rhod, this->locpp.vloc, this->solvent,
549550
this->rdmft_solver, this->deepks, this->exx_nao,
550551
this->conv_esolver, this->scf_nmax_flag, istep);
551552

source/source_estate/init_scf.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ void init_scf(const UnitCell& ucell,
1717
pelec->charge->set_rho_core(ucell, strucfac, numeric);
1818

1919
//! renormalize the charge density
20-
pelec->charge->renormalize_rho();
20+
if(PARAM.inp.init_chg != "dm_no_renormalize")
21+
{
22+
pelec->charge->renormalize_rho();
23+
}
2124

2225
//! initialize the potential
2326
pelec->pot->init_pot(pelec->charge);

source/source_estate/module_charge/charge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void Charge::set_rhopw(ModulePW::PW_Basis* rhopw_in)
5454
}
5555

5656
// mohan add 2025-12-02
57-
bool Charge::kin_density()
57+
bool Charge::kin_density() const
5858
{
5959
if (XC_Functional::get_ked_flag() || PARAM.inp.out_elf[0] > 0)
6060
{

source/source_estate/module_charge/charge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Charge
8484
const void* wfcpw = nullptr);
8585

8686
// mohan add 2025-12-02
87-
bool kin_density();
87+
bool kin_density() const;
8888

8989
void allocate(const int &nspin_in, const bool kin_den);
9090

source/source_estate/module_pot/potential_new.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ class Potential : public PotBase
179179
{
180180
return this->ucell_;
181181
}
182+
// get the local pseudopotential vloc(it, G) table; used by the dH module (out_mat_dh_vl)
183+
const ModuleBase::matrix* get_vloc() const
184+
{
185+
return this->vloc_;
186+
}
182187
// What about adding a function to get the wfc?
183188
// This is useful for the calculation of the exx energy
184189

source/source_io/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ if(ENABLE_LCAO)
8181
module_mulliken/output_mulliken.cpp
8282
module_ml/io_npz.cpp
8383
module_hs/cal_pLpR.cpp
84+
module_dhs/write_dH.cpp
85+
module_dhs/write_dH_terms.cpp
8486
)
8587
list(APPEND objects_advanced
8688
module_unk/unk_overlap_lcao.cpp
8789
module_hs/write_HS_R.cpp
90+
module_hs/write_H_terms.cpp
8891
module_hs/write_HS_sparse.cpp
8992
module_hs/single_R_io.cpp
9093
module_hs/rr_sparse_writer.cpp

0 commit comments

Comments
 (0)