Skip to content

Commit 8725264

Browse files
committed
Merge branch 'develop' of https://github.com/deepmodeling/abacus-develop into hotfix
2 parents 790313a + dd862ea commit 8725264

File tree

66 files changed

+2527
-558
lines changed

Some content is hidden

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

66 files changed

+2527
-558
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ ABACUS (Atomic-orbital Based Ab-initio Computation at UStc) is an open-source pa
1616

1717
# Online Documentation
1818
For detailed documentation, please refer to [our documentation website](https://abacus.deepmodeling.com/).
19+
20+
See our [Github Pages](https://mcresearch.github.io/abacus-user-guide/) for more tutorials and developer guides.

docs/advanced/input_files/input-main.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@
243243
- [exx\_opt\_orb\_ecut](#exx_opt_orb_ecut)
244244
- [exx\_opt\_orb\_tolerence](#exx_opt_orb_tolerence)
245245
- [exx\_real\_number](#exx_real_number)
246-
- [exx\_symmetry\_realspace](#exx_symmetry_realspace)
247246
- [rpa\_ccp\_rmesh\_times](#rpa_ccp_rmesh_times)
247+
- [exx\_symmetry\_realspace](#exx_symmetry_realspace)
248248
- [out\_ri\_cv](#out_ri_cv)
249249
- [Molecular dynamics](#molecular-dynamics)
250250
- [md\_type](#md_type)
@@ -273,6 +273,9 @@
273273
- [lj\_epsilon](#lj_epsilon)
274274
- [lj\_sigma](#lj_sigma)
275275
- [pot\_file](#pot_file)
276+
- [dp\_rescaling](#dp_rescaling)
277+
- [dp\_fparam](#dp_fparam)
278+
- [dp\_aparam](#dp_aparam)
276279
- [msst\_direction](#msst_direction)
277280
- [msst\_vel](#msst_vel)
278281
- [msst\_vis](#msst_vis)
@@ -422,11 +425,12 @@
422425
- [nocc](#nocc)
423426
- [nvirt](#nvirt)
424427
- [lr\_nstates](#lr_nstates)
428+
- [lr\_unrestricted](#lr_unrestricted)
425429
- [abs\_wavelen\_range](#abs_wavelen_range)
426430
- [out\_wfc\_lr](#out_wfc_lr)
427431
- [abs\_broadening](#abs_broadening)
428432
- [ri\_hartree\_benchmark](#ri_hartree_benchmark)
429-
- [aims_nbasis](#aims_nbasis)
433+
- [aims\_nbasis](#aims_nbasis)
430434

431435
[back to top](#full-list-of-input-keywords)
432436
## System variables
@@ -2908,46 +2912,38 @@ These variables are used to control vdW-corrected related parameters.
29082912
- **Type**: String
29092913
- **Description**: Specifies the method used for Van der Waals (VdW) correction. Available options are:
29102914
- `d2`: [Grimme's D2](https://onlinelibrary.wiley.com/doi/abs/10.1002/jcc.20495) dispersion correction method
2911-
- `d3_0`: [Grimme's DFT-D3(0)](https://aip.scitation.org/doi/10.1063/1.3382344) dispersion correction method
2912-
- `d3_bj`: [Grimme's DFTD3(BJ)](https://onlinelibrary.wiley.com/doi/abs/10.1002/jcc.21759) dispersion correction method
2915+
- `d3_0`: [Grimme's DFT-D3(0)](https://aip.scitation.org/doi/10.1063/1.3382344) dispersion correction method (zero-damping)
2916+
- `d3_bj`: [Grimme's DFTD3(BJ)](https://onlinelibrary.wiley.com/doi/abs/10.1002/jcc.21759) dispersion correction method (BJ-damping)
29132917
- `none`: no vdW correction
29142918
- **Default**: none
2919+
- **Note**: ABACUS supports automatic setting on DFT-D3 parameters for common functionals after version 3.8.3 (and several develop versions earlier). To benefit from this feature, please specify the parameter `dft_functional` explicitly (for more details on this parameter, please see [dft_functional](#dft_functional)), otherwise the autoset procedure will crash with error message like `cannot find DFT-D3 parameter for XC(***)`. If not satisfied with those in-built parameters, any manually setting on `vdw_s6`, `vdw_s8`, `vdw_a1` and `vdw_a2` will overwrite.
2920+
- **Special**: There are special cases for functional family wB97 (Omega-B97): if want to use the functional wB97X-D3BJ, one needs to specify the `dft_functional` as `HYB_GGA_WB97X_V` and `vdw_method` as `d3_bj`. If want to use the functional wB97X-D3, specify `dft_functional` as `HYB_GGA_WB97X_D3` and `vdw_method` as `d3_0`.
29152921

29162922
### vdw_s6
29172923

29182924
- **Type**: Real
29192925
- **Availability**: `vdw_method` is set to `d2`, `d3_0`, or `d3_bj`
2920-
- **Description**: This scale factor is used to optimize the interaction energy deviations in van der Waals (vdW) corrected calculations. The recommended values of this parameter are dependent on the chosen vdW correction method and the DFT functional being used. For DFT-D2, the recommended values are 0.75 (PBE), 1.2 (BLYP), 1.05 (B-P86), 1.0 (TPSS), and 1.05 (B3LYP). For DFT-D3, recommended values with different DFT functionals can be found on the [here](https://www.chemiebn.uni-bonn.de/pctc/mulliken-center/software/dft-d3/dft-d3). The default value of this parameter in ABACUS is set to be the recommended value for PBE.
2926+
- **Description**: This scale factor is used to optimize the interaction energy deviations in van der Waals (vdW) corrected calculations. The recommended values of this parameter are dependent on the chosen vdW correction method and the DFT functional being used. For DFT-D2, the recommended values are 0.75 (PBE), 1.2 (BLYP), 1.05 (B-P86), 1.0 (TPSS), and 1.05 (B3LYP). If not set, will use values of PBE functional. For DFT-D3, recommended values with different DFT functionals can be found on the [here](https://github.com/dftd3/simple-dftd3/blob/main/assets/parameters.toml). If not set, will search in ABACUS built-in dataset based on the `dft_functional` keywords. User set value will overwrite the searched value.
29212927
- **Default**:
29222928
- 0.75: if `vdw_method` is set to `d2`
2923-
- 1.0: if `vdw_method` is set to `d3_0` or `d3_bj`
29242929

29252930
### vdw_s8
29262931

29272932
- **Type**: Real
29282933
- **Availability**: `vdw_method` is set to `d3_0` or `d3_bj`
2929-
- **Description**: This scale factor is relevant for D3(0) and D3(BJ) van der Waals (vdW) correction methods. The recommended values of this parameter with different DFT functionals can be found on the [webpage](https://www.chemiebn.uni-bonn.de/pctc/mulliken-center/software/dft-d3/dft-d3). The default value of this parameter in ABACUS is set to be the recommended value for PBE.
2930-
- **Default**:
2931-
- 0.722: if `vdw_method` is set to `d3_0`
2932-
- 0.7875: if `vdw_method` is set to `d3_bj`
2934+
- **Description**: This scale factor is relevant for D3(0) and D3(BJ) van der Waals (vdW) correction methods. The recommended values of this parameter with different DFT functionals can be found on the [webpage](https://github.com/dftd3/simple-dftd3/blob/main/assets/parameters.toml). If not set, will search in ABACUS built-in dataset based on the `dft_functional` keywords. User set value will overwrite the searched value.
29332935

29342936
### vdw_a1
29352937

29362938
- **Type**: Real
29372939
- **Availability**: `vdw_method` is set to `d3_0` or `d3_bj`
2938-
- **Description**: This damping function parameter is relevant for D3(0) and D3(BJ) van der Waals (vdW) correction methods. The recommended values of this parameter with different DFT functionals can be found on the [webpage](https://www.chemiebn.uni-bonn.de/pctc/mulliken-center/software/dft-d3/dft-d3). The default value of this parameter in ABACUS is set to be the recommended value for PBE.
2939-
- **Default**:
2940-
- 1.217: if `vdw_method` is set to `d3_0`
2941-
- 0.4289: if `vdw_method` is set to `d3_bj`
2940+
- **Description**: This damping function parameter is relevant for D3(0) and D3(BJ) van der Waals (vdW) correction methods. The recommended values of this parameter with different DFT functionals can be found on the [webpage](https://github.com/dftd3/simple-dftd3/blob/main/assets/parameters.toml). If not set, will search in ABACUS built-in dataset based on the `dft_functional` keywords. User set value will overwrite the searched value.
29422941

29432942
### vdw_a2
29442943

29452944
- **Type**: Real
29462945
- **Availability**: `vdw_method` is set to `d3_0` or `d3_bj`
2947-
- **Description**: This damping function parameter is only relevant for D3(0) and D3(BJ) van der Waals (vdW) correction methods. The recommended values of this parameter with different DFT functionals can be found on the [webpage](https://www.chemiebn.uni-bonn.de/pctc/mulliken-center/software/dft-d3/dft-d3). The default value of this parameter in ABACUS is set to be the recommended value for PBE.
2948-
- **Default**:
2949-
- 1.0: if `vdw_method` is set to `d3_0`
2950-
- 4.4407: if `vdw_method` is set to `d3_bj`
2946+
- **Description**: This damping function parameter is only relevant for D3(0) and D3(BJ) van der Waals (vdW) correction methods. The recommended values of this parameter with different DFT functionals can be found on the [webpage](https://github.com/dftd3/simple-dftd3/blob/main/assets/parameters.toml). If not set, will search in ABACUS built-in dataset based on the `dft_functional` keywords. User set value will overwrite the searched value.
29512947

29522948
### vdw_d
29532949

@@ -3925,7 +3921,7 @@ Currently supported: `RPA`, `LDA`, `PBE`, `HSE`, `HF`.
39253921

39263922
- **Type**: String
39273923
- **Description**: The method to solve the Casida equation $AX=\Omega X$ in LR-TDDFT under Tamm-Dancoff approximation (TDA), where $A_{ai,bj}=(\epsilon_a-\epsilon_i)\delta_{ij}\delta_{ab}+(ai|f_{Hxc}|bj)+\alpha_{EX}(ab|ij)$ is the particle-hole excitation matrix and $X$ is the transition amplitude.
3928-
- `dav`: Construct $AX$ and diagonalize the Hamiltonian matrix iteratively with Davidson algorithm.
3924+
- `dav`/`dav_subspace`/ `cg`: Construct $AX$ and diagonalize the Hamiltonian matrix iteratively with Davidson/Non-ortho-Davidson/CG algorithm.
39293925
- `lapack`: Construct the full $A$ matrix and directly diagonalize with LAPACK.
39303926
- `spectrum`: Calculate absorption spectrum only without solving Casida equation. The `OUT.${suffix}/` directory should contain the
39313927
files for LR-TDDFT eigenstates and eigenvalues, i.e. `Excitation_Energy.dat` and `Excitation_Amplitude_${processor_rank}.dat`

python/pyabacus/examples/diago_matrix.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ def load_mat(mat_file):
1010
return h_mat, nbasis, nband
1111

1212
def calc_eig_pyabacus(mat_file, method):
13-
algo = {
13+
dav = {
1414
'dav_subspace': hsolver.dav_subspace,
1515
'davidson': hsolver.davidson
1616
}
17+
cg = {
18+
'cg': hsolver.cg
19+
}
1720

1821
h_mat, nbasis, nband = load_mat(mat_file)
1922

@@ -22,25 +25,27 @@ def calc_eig_pyabacus(mat_file, method):
2225
diag_elem = np.where(np.abs(diag_elem) < 1e-8, 1e-8, diag_elem)
2326
precond = 1.0 / np.abs(diag_elem)
2427

25-
def mm_op(x):
28+
def mvv_op(x):
2629
return h_mat.dot(x)
2730

28-
e, _ = algo[method](
29-
mm_op,
30-
v0,
31-
nbasis,
32-
nband,
33-
precond,
34-
dav_ndim=8,
35-
tol=1e-8,
36-
max_iter=1000
37-
)
31+
if method in dav:
32+
algo = dav[method]
33+
# args: mvvop, init_v, dim, num_eigs, precondition, dav_ndim, tol, max_iter
34+
args = (mvv_op, v0, nbasis, nband, precond, 8, 1e-12, 5000)
35+
elif method in cg:
36+
algo = cg[method]
37+
# args: mvvop, init_v, dim, num_eigs, precondition, tol, max_iter
38+
args = (mvv_op, v0, nbasis, nband, precond, 1e-12, 5000)
39+
else:
40+
raise ValueError(f"Method {method} not available")
41+
42+
e, _ = algo(*args)
3843

3944
print(f'eigenvalues calculated by pyabacus-{method} is: \n', e)
4045

4146
return e
4247

43-
def calc_eig_scipy(mat_file):
48+
def calc_eigsh(mat_file):
4449
h_mat, _, nband = load_mat(mat_file)
4550
e, _ = scipy.sparse.linalg.eigsh(h_mat, k=nband, which='SA', maxiter=1000)
4651
e = np.sort(e)
@@ -50,13 +55,12 @@ def calc_eig_scipy(mat_file):
5055

5156
if __name__ == '__main__':
5257
mat_file = './Si2.mat'
53-
method = ['dav_subspace', 'davidson']
58+
method = ['dav_subspace', 'davidson', 'cg']
5459

5560
for m in method:
5661
print(f'\n====== Calculating eigenvalues using {m} method... ======')
5762
e_pyabacus = calc_eig_pyabacus(mat_file, m)
58-
e_scipy = calc_eig_scipy(mat_file)
63+
e_scipy = calc_eigsh(mat_file)
5964

6065
print('eigenvalues difference: \n', e_pyabacus - e_scipy)
61-
62-
66+

python/pyabacus/src/hsolver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
list(APPEND _diago
33
${HSOLVER_PATH}/diago_dav_subspace.cpp
44
${HSOLVER_PATH}/diago_david.cpp
5+
${HSOLVER_PATH}/diago_cg.cpp
56
${HSOLVER_PATH}/diag_const_nums.cpp
67
${HSOLVER_PATH}/diago_iter_assist.cpp
78

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#ifndef PYTHON_PYABACUS_SRC_PY_DIAGO_CG_HPP
2+
#define PYTHON_PYABACUS_SRC_PY_DIAGO_CG_HPP
3+
4+
#include <complex>
5+
#include <functional>
6+
7+
#include <pybind11/pybind11.h>
8+
#include <pybind11/complex.h>
9+
#include <pybind11/functional.h>
10+
#include <pybind11/numpy.h>
11+
#include <pybind11/stl.h>
12+
13+
#include <ATen/core/tensor.h>
14+
#include <ATen/core/tensor_map.h>
15+
#include <ATen/core/tensor_types.h>
16+
17+
#include "module_hsolver/diago_cg.h"
18+
#include "module_base/module_device/memory_op.h"
19+
20+
namespace py = pybind11;
21+
22+
namespace py_hsolver
23+
{
24+
25+
class PyDiagoCG
26+
{
27+
public:
28+
PyDiagoCG(int dim, int num_eigs) : dim{dim}, num_eigs{num_eigs} { }
29+
PyDiagoCG(const PyDiagoCG&) = delete;
30+
PyDiagoCG& operator=(const PyDiagoCG&) = delete;
31+
PyDiagoCG(PyDiagoCG&& other)
32+
{
33+
psi = other.psi;
34+
other.psi = nullptr;
35+
36+
eig = other.eig;
37+
other.eig = nullptr;
38+
}
39+
40+
~PyDiagoCG()
41+
{
42+
if (psi != nullptr)
43+
{
44+
delete psi;
45+
psi = nullptr;
46+
}
47+
48+
if (eig != nullptr)
49+
{
50+
delete eig;
51+
eig = nullptr;
52+
}
53+
}
54+
55+
void init_eig()
56+
{
57+
eig = new ct::Tensor(ct::DataType::DT_DOUBLE, {num_eigs});
58+
eig->zero();
59+
}
60+
61+
py::array_t<double> get_eig()
62+
{
63+
py::array_t<double> eig_out(eig->NumElements());
64+
py::buffer_info eig_buf = eig_out.request();
65+
double* eig_out_ptr = static_cast<double*>(eig_buf.ptr);
66+
67+
if (eig == nullptr) {
68+
throw std::runtime_error("eig is not initialized");
69+
}
70+
double* eig_ptr = eig->data<double>();
71+
72+
std::copy(eig_ptr, eig_ptr + eig->NumElements(), eig_out_ptr);
73+
return eig_out;
74+
}
75+
76+
void set_psi(py::array_t<std::complex<double>> psi_in)
77+
{
78+
py::buffer_info psi_buf = psi_in.request();
79+
std::complex<double>* psi_ptr = static_cast<std::complex<double>*>(psi_buf.ptr);
80+
81+
psi = new ct::TensorMap(
82+
psi_ptr,
83+
ct::DataType::DT_COMPLEX_DOUBLE,
84+
ct::DeviceType::CpuDevice,
85+
ct::TensorShape({num_eigs, dim})
86+
);
87+
}
88+
89+
py::array_t<std::complex<double>> get_psi()
90+
{
91+
py::array_t<std::complex<double>> psi_out({num_eigs, dim});
92+
py::buffer_info psi_buf = psi_out.request();
93+
std::complex<double>* psi_out_ptr = static_cast<std::complex<double>*>(psi_buf.ptr);
94+
95+
if (psi == nullptr) {
96+
throw std::runtime_error("psi is not initialized");
97+
}
98+
std::complex<double>* psi_ptr = psi->data<std::complex<double>>();
99+
100+
std::copy(psi_ptr, psi_ptr + psi->NumElements(), psi_out_ptr);
101+
return psi_out;
102+
}
103+
104+
void set_prec(py::array_t<double> prec_in)
105+
{
106+
py::buffer_info prec_buf = prec_in.request();
107+
double* prec_ptr = static_cast<double*>(prec_buf.ptr);
108+
109+
prec = new ct::TensorMap(
110+
prec_ptr,
111+
ct::DataType::DT_DOUBLE,
112+
ct::DeviceType::CpuDevice,
113+
ct::TensorShape({dim})
114+
);
115+
}
116+
117+
void diag(
118+
std::function<py::array_t<std::complex<double>>(py::array_t<std::complex<double>>)> mm_op,
119+
int diag_ndim,
120+
double tol,
121+
bool need_subspace,
122+
bool scf_type,
123+
int nproc_in_pool = 1
124+
) {
125+
const std::string basis_type = "pw";
126+
const std::string calculation = scf_type ? "scf" : "nscf";
127+
128+
auto hpsi_func = [mm_op] (const ct::Tensor& psi_in, ct::Tensor& hpsi_out) {
129+
const auto ndim = psi_in.shape().ndim();
130+
REQUIRES_OK(ndim <= 2, "dims of psi_in should be less than or equal to 2");
131+
const int nvec = ndim == 1 ? 1 : psi_in.shape().dim_size(0);
132+
const int ld_psi = ndim == 1 ? psi_in.NumElements() : psi_in.shape().dim_size(1);
133+
134+
// Note: numpy's py::array_t is row-major, and
135+
// our tensor-array is row-major
136+
py::array_t<std::complex<double>> psi({ld_psi, nvec});
137+
py::buffer_info psi_buf = psi.request();
138+
std::complex<double>* psi_ptr = static_cast<std::complex<double>*>(psi_buf.ptr);
139+
std::copy(psi_in.data<std::complex<double>>(), psi_in.data<std::complex<double>>() + nvec * ld_psi, psi_ptr);
140+
141+
py::array_t<std::complex<double>> hpsi = mm_op(psi);
142+
143+
py::buffer_info hpsi_buf = hpsi.request();
144+
std::complex<double>* hpsi_ptr = static_cast<std::complex<double>*>(hpsi_buf.ptr);
145+
std::copy(hpsi_ptr, hpsi_ptr + nvec * ld_psi, hpsi_out.data<std::complex<double>>());
146+
};
147+
148+
auto subspace_func = [] (const ct::Tensor& psi_in, ct::Tensor& psi_out) { /*do nothing*/ };
149+
150+
auto spsi_func = [this] (const ct::Tensor& psi_in, ct::Tensor& spsi_out) {
151+
const auto ndim = psi_in.shape().ndim();
152+
REQUIRES_OK(ndim <= 2, "dims of psi_in should be less than or equal to 2");
153+
const int nrow = ndim == 1 ? psi_in.NumElements() : psi_in.shape().dim_size(1);
154+
const int nbands = ndim == 1 ? 1 : psi_in.shape().dim_size(0);
155+
syncmem_z2z_h2h_op()(
156+
this->ctx,
157+
this->ctx,
158+
spsi_out.data<std::complex<double>>(),
159+
psi_in.data<std::complex<double>>(),
160+
static_cast<size_t>(nrow * nbands)
161+
);
162+
};
163+
164+
cg = std::make_unique<hsolver::DiagoCG<std::complex<double>, base_device::DEVICE_CPU>>(
165+
basis_type,
166+
calculation,
167+
need_subspace,
168+
subspace_func,
169+
tol,
170+
diag_ndim,
171+
nproc_in_pool
172+
);
173+
174+
cg->diag(hpsi_func, spsi_func, *psi, *eig, *prec);
175+
}
176+
177+
private:
178+
base_device::DEVICE_CPU* ctx = {};
179+
180+
int dim;
181+
int num_eigs;
182+
183+
ct::Tensor* psi = nullptr;
184+
ct::Tensor* eig = nullptr;
185+
ct::Tensor* prec = nullptr;
186+
187+
std::unique_ptr<hsolver::DiagoCG<std::complex<double>, base_device::DEVICE_CPU>> cg;
188+
};
189+
190+
} // namespace py_hsolver
191+
192+
#endif

0 commit comments

Comments
 (0)