Skip to content

Commit 3f312e8

Browse files
linpeizePeizeLin
andauthored
refactor Exx_Opt_Orb (#6378)
Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
1 parent 012c216 commit 3f312e8

File tree

16 files changed

+298
-248
lines changed

16 files changed

+298
-248
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ These variables are used to control general system parameters.
512512
- get_wf: obtain real space wave functions (for LCAO basis only). See `out_wfc_norm` and `out_wfc_re_im` for more information
513513
- get_s: obtain the overlap matrix formed by localized orbitals (for LCAO basis with multiple k points). the file name is `SR.csr` with file format being the same as that generated by [out_mat_hs2](#out_mat_hs2). Note: in the 3.10-LTS version, the command was named `get_S`
514514
- gen_bessel: generates projectors, i.e., a series of Bessel functions, for the DeePKS method (for LCAO basis only); see also keywords `bessel_descriptor_lmax`, `bessel_descriptor_rcut` and `bessel_descriptor_tolerence`. A file named `jle.orb` will be generated which contains the projectors. An example is provided in examples/H2O-deepks-pw
515+
- gen_opt_abfs: generate opt-ABFs as discussed in this [article](https://pubs.acs.org/doi/abs/10.1021/acs.jpclett.0c00481).
515516
- test_memory: obtain a rough estimation of memory consuption for the calculation
516517
- test_neighbour: obtain information of neighboring atoms (for LCAO basis only), please specify a positive [search_radius](#search_radius) manually
517518
- **Default**: scf
@@ -540,7 +541,7 @@ These variables are used to control general system parameters.
540541
- **Default**:
541542
- 0:
542543
- if [calculation](#calculation)==md/nscf/get_pchg/get_wf/get_s or [gamma_only](#gamma_only)==True;
543-
- If ([dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0/opt_orb or [rpa](#rpa)==True).
544+
- If ([dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0 or [rpa](#rpa)==True).
544545
- If [efield_flag](#efield_flag)==1
545546
- 1: else
546547

@@ -763,7 +764,7 @@ These variables are used to control parameters related to input files.
763764
- **Availability**: Used only when numerical atomic orbitals are employed as basis set.
764765
- **Description**: If [restart_save](#restart_save) is set to true and an electronic iteration is finished, calculations can be restarted from the charge density file, which are saved in the former calculation. Please ensure [read_file_dir](#read_file_dir) is correct, and the charge density file exist.
765766

766-
If EXX(exact exchange) is calculated (i.e. *[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0/opt_orb* or *[rpa](#rpa)==True*), the Hexx(R) files in the same folder for each processor will also be read.
767+
If EXX(exact exchange) is calculated (i.e. *[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0* or *[rpa](#rpa)==True*), the Hexx(R) files in the same folder for each processor will also be read.
767768
- **Default**: False
768769

769770
### wannier_card
@@ -1057,7 +1058,6 @@ calculations.
10571058

10581059
Furthermore, the old INPUT parameter exx_hybrid_type for hybrid functionals has been absorbed into dft_functional. Options are `hf` (pure Hartree-Fock), `pbe0`(PBE0), `hse` (Note: in order to use HSE functional, LIBXC is required). Note also that HSE has been tested while PBE0 has NOT been fully tested yet, and the maximum CPU cores for running exx in parallel is $N(N+1)/2$, with N being the number of atoms.
10591060

1060-
If set to `opt_orb`, the program will not perform hybrid functional calculation. Instead, it is going to generate opt-ABFs as discussed in this [article](https://pubs.acs.org/doi/abs/10.1021/acs.jpclett.0c00481).
10611061
- **Default**: Used the same as DFT functional as specified in the pseudopotential files.
10621062

10631063
### xc_temperature
@@ -1645,7 +1645,7 @@ These variables are used to control the output of properties.
16451645
---
16461646
The circle order of the charge density on real space grids is: x is the outer loop, then y and finally z (z is moving fastest).
16471647

1648-
In EXX(exact exchange) calculations, (i.e. *[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0/opt_orb* or *[rpa](#rpa)==True*), the Hexx(R) files will be output in the folder `OUT.${suffix}` too, which can be read in NSCF calculation.
1648+
In EXX(exact exchange) calculations, (i.e. *[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0* or *[rpa](#rpa)==True*), the Hexx(R) files will be output in the folder `OUT.${suffix}` too, which can be read in NSCF calculation.
16491649

16501650
In molecular dynamics simulations, the output frequency is controlled by [out_interval](#out_interval).
16511651
- **Default**: 0 3
@@ -1965,7 +1965,7 @@ These variables are used to control the output of properties.
19651965
- auto: These files are saved in folder `OUT.${suffix}/restart/`;
19661966
- other: These files are saved in folder `${read_file_dir}/restart/`.
19671967

1968-
If EXX(exact exchange) is calculated (i.e. *[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0/opt_orb* or *[rpa](#rpa)==True*), the Hexx(R) files for each processor will also be saved in the above folder, which can be read in EXX calculation with *[restart_load](#restart_load)==True*.
1968+
If EXX(exact exchange) is calculated (i.e. *[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0* or *[rpa](#rpa)==True*), the Hexx(R) files for each processor will also be saved in the above folder, which can be read in EXX calculation with *[restart_load](#restart_load)==True*.
19691969
- **Default**: False
19701970

19711971
### rpa (Under Development Feature)
@@ -2927,22 +2927,22 @@ These variables are relevant when using hybrid functionals with *[basis_type](#b
29272927
### exx_opt_orb_lmax
29282928

29292929
- **Type**: Integer
2930-
- **Availability**: *[dft_functional](#dft_functional)==opt_orb*
2930+
- **Availability**: *[calculation](#calculation)==gen_opt_abfs*
29312931
- **Description**: The maximum l of the spherical Bessel functions, when the radial part of opt-ABFs are generated as linear combinations of spherical Bessel functions. A reasonable choice is 2.
29322932
- **Default**: 0
29332933

29342934
### exx_opt_orb_ecut
29352935

29362936
- **Type**: Real
2937-
- **Availability**: *[dft_functional](#dft_functional)==opt_orb*
2937+
- **Availability**: *[calculation](#calculation)==gen_opt_abfs*
29382938
- **Description**: The cut-off of plane wave expansion, when the plane wave basis is used to optimize the radial ABFs. A reasonable choice is 60.
29392939
- **Default**: 0
29402940
- **Unit**: Ry
29412941

29422942
### exx_opt_orb_tolerence
29432943

29442944
- **Type**: Real
2945-
- **Availability**: *[dft_functional](#dft_functional)==opt_orb*
2945+
- **Availability**: *[calculation](#calculation)==gen_opt_abfs*
29462946
- **Description**: The threshold when solving for the zeros of spherical Bessel functions. A reasonable choice is 1e-12.
29472947
- **Default**: 0
29482948

@@ -2975,7 +2975,7 @@ These variables are relevant when using hybrid functionals with *[basis_type](#b
29752975
### exx_symmetry_realspace
29762976

29772977
- **Type**: Boolean
2978-
- **Availability**: *[symmetry](#symmetry)==1* and exx calculation (*[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0/opt_orb* or *[rpa](#rpa)==True*)
2978+
- **Availability**: *[symmetry](#symmetry)==1* and exx calculation (*[dft_fuctional](#dft_functional)==hse/hf/pbe0/scan0* or *[rpa](#rpa)==True*)
29792979
- **Description**:
29802980
- False: only rotate k-space density matrix D(k) from irreducible k-points to accelerate diagonalization
29812981
- True: rotate both D(k) and Hexx(R) to accelerate both diagonalization and EXX calculation

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
#include "source_lcao/hamilt_lcao.h"
5959
#include "source_hsolver/hsolver_lcao.h"
6060

61+
#ifdef __EXX
62+
#include "../source_lcao/module_ri/exx_opt_orb.h"
63+
#endif
64+
6165
// test RDMFT
6266
#include "source_lcao/module_rdmft/rdmft.h"
6367

@@ -132,6 +136,17 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
132136
two_center_bundle_,
133137
orb_);
134138

139+
if (PARAM.inp.calculation == "gen_opt_abfs")
140+
{
141+
#ifdef __EXX
142+
Exx_Opt_Orb exx_opt_orb;
143+
exx_opt_orb.generate_matrix(GlobalC::exx_info.info_opt_abfs, this->kv, ucell, this->orb_);
144+
#else
145+
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::before_all_runners", "calculation=gen_opt_abfs must compile __EXX");
146+
#endif
147+
return;
148+
}
149+
135150
// 4) initialize electronic wave function psi
136151
if (this->psi == nullptr)
137152
{

source/source_esolver/lcao_others.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
7474
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "testing neighbour");
7575
return;
7676
}
77+
else if (cal_type == "gen_opt_abfs")
78+
{
79+
return;
80+
}
7781

7882
// 1. prepare HS matrices, prepare grid integral
7983
// (1) Find adjacent atoms for each atom.

source/source_hamilt/module_xc/exx_info.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ struct Exx_Info
7777
};
7878
Exx_Info_RI info_ri;
7979

80+
struct Exx_Info_Opt_ABFs
81+
{
82+
int abfs_Lmax = 0; // tmp
83+
double ecut_exx = 60;
84+
double tolerence = 1E-2;
85+
double kmesh_times = 4;
86+
};
87+
Exx_Info_Opt_ABFs info_opt_abfs;
88+
8089
Exx_Info() : info_lip(this->info_global), info_ri(this->info_global)
8190
{
8291
}

source/source_io/input_conv.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ void Input_Conv::Convert()
271271
ModuleBase::GlobalFunc::MAKE_DIR(GlobalC::restart.folder);
272272
if (dft_functional_lower == "hf" || dft_functional_lower == "pbe0"
273273
|| dft_functional_lower == "hse"
274-
|| dft_functional_lower == "opt_orb"
275274
|| dft_functional_lower == "scan0") {
276275
GlobalC::restart.info_save.save_charge = true;
277276
GlobalC::restart.info_save.save_H = true;
@@ -297,7 +296,6 @@ void Input_Conv::Convert()
297296
GlobalC::restart.folder = PARAM.globalv.global_readin_dir + "restart/";
298297
if (dft_functional_lower == "hf" || dft_functional_lower == "pbe0"
299298
|| dft_functional_lower == "hse"
300-
|| dft_functional_lower == "opt_orb"
301299
|| dft_functional_lower == "scan0"
302300
|| dft_functional_lower == "lc_pbe"
303301
|| dft_functional_lower == "lc_wpbe"
@@ -422,13 +420,6 @@ void Input_Conv::Convert()
422420
}
423421
}
424422
}
425-
#ifdef __EXX
426-
else if (dft_functional_lower == "opt_orb")
427-
{
428-
GlobalC::exx_info.info_global.cal_exx = false;
429-
Exx_Abfs::Jle::generate_matrix = true;
430-
}
431-
#endif
432423
else
433424
{
434425
GlobalC::exx_info.info_global.cal_exx = false;
@@ -456,7 +447,6 @@ void Input_Conv::Convert()
456447

457448
if (GlobalC::exx_info.info_global.cal_exx
458449
#ifdef __EXX
459-
|| Exx_Abfs::Jle::generate_matrix
460450
|| PARAM.inp.rpa
461451
#endif
462452
)
@@ -483,11 +473,9 @@ void Input_Conv::Convert()
483473
GlobalC::exx_info.info_ri.ccp_rmesh_times = std::stod(PARAM.inp.exx_ccp_rmesh_times);
484474
GlobalC::exx_info.info_ri.exx_symmetry_realspace = PARAM.inp.exx_symmetry_realspace;
485475

486-
#ifdef __EXX
487-
Exx_Abfs::Jle::Lmax = PARAM.inp.exx_opt_orb_lmax;
488-
Exx_Abfs::Jle::Ecut_exx = PARAM.inp.exx_opt_orb_ecut;
489-
Exx_Abfs::Jle::tolerence = PARAM.inp.exx_opt_orb_tolerence;
490-
#endif
476+
GlobalC::exx_info.info_opt_abfs.abfs_Lmax = PARAM.inp.exx_opt_orb_lmax;
477+
GlobalC::exx_info.info_opt_abfs.ecut_exx = PARAM.inp.exx_opt_orb_ecut;
478+
GlobalC::exx_info.info_opt_abfs.tolerence = PARAM.inp.exx_opt_orb_tolerence;
491479

492480
// EXX does not support symmetry for nspin==4
493481
if (PARAM.inp.calculation != "nscf" && PARAM.inp.symmetry == "1" && PARAM.inp.nspin == 4 && PARAM.inp.basis_type == "lcao")

source/source_io/read_input_item_system.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void ReadInput::item_system()
6262
}
6363
{
6464
Input_Item item("calculation");
65-
item.annotation = "test; scf; relax; nscf; get_wf; get_pchg";
65+
item.annotation = "scf; relax; md; cell-relax; nscf; get_s; get_wf; get_pchg; gen_bessel; gen_opt_abfs; test_memory; test_neighbour";
6666
item.read_value = [](const Input_Item& item, Parameter& para) {
6767
para.input.calculation = strvalue;
6868
std::string& calculation = para.input.calculation;
@@ -73,13 +73,14 @@ void ReadInput::item_system()
7373
"relax",
7474
"md",
7575
"cell-relax",
76-
"test_memory",
77-
"test_neighbour",
7876
"nscf",
7977
"get_s",
8078
"get_wf",
8179
"get_pchg",
82-
"gen_bessel"};
80+
"gen_bessel",
81+
"gen_opt_abfs",
82+
"test_memory",
83+
"test_neighbour"};
8384
if (std::find(callist.begin(), callist.end(), calculation) == callist.end())
8485
{
8586
const std::string warningstr = nofound_str(callist, "calculation");

source/source_lcao/module_ri/Exx_LRI_interface.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "Exx_LRI_interface.h"
66
#include "source_lcao/module_ri/exx_abfs-jle.h"
7-
#include "source_lcao/module_ri/exx_opt_orb.h"
87
#include "source_lcao/hamilt_lcao.h"
98
#include "source_lcao/module_operator_lcao/op_exx_lcao.h"
109
#include "source_base/parallel_common.h"
@@ -183,15 +182,6 @@ void Exx_LRI_Interface<T, Tdata>::exx_beforescf(const int istep,
183182
this->cal_exx_ions(ucell,PARAM.inp.out_ri_cv);
184183
}
185184

186-
if (Exx_Abfs::Jle::generate_matrix)
187-
{
188-
//program should be stopped after this judgement
189-
Exx_Opt_Orb exx_opt_orb;
190-
exx_opt_orb.generate_matrix(kv, ucell,orb);
191-
ModuleBase::timer::tick("ESolver_KS_LCAO", "beforescf");
192-
return;
193-
}
194-
195185
// set initial parameter for mix_DMk_2D
196186
if(GlobalC::exx_info.info_global.cal_exx)
197187
{

source/source_lcao/module_ri/Matrix_Orbs22.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ void Matrix_Orbs22::init(const int mode,
5555
Lmax = 2 * Lmax + 1;
5656

5757
ModuleBase::timer::tick("Matrix_Orbs22", "init");
58-
std::cout << "Matrix_Orbs22::init()::done" << std::endl;
5958
}
6059

6160
void Matrix_Orbs22::init_radial(const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>>& orb_A1,

source/source_lcao/module_ri/exx_abfs-construct_orbs.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,7 @@ std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> Exx_Abfs::Construct_
4545
}
4646
}
4747

48-
for (int T = 0; T < orbs.size() ; T++)
49-
{
50-
for (int L=orbs[T].size()-1; L >= 0 ; L--)
51-
{
52-
if (orbs[T][L].size()>0)
53-
break;
54-
else
55-
orbs[T].resize(L);
56-
}
57-
}
48+
Exx_Abfs::Construct_Orbs::filter_empty_orbs(orbs);
5849
return orbs;
5950
}
6051

@@ -548,4 +539,18 @@ std::vector<double> Exx_Abfs::Construct_Orbs::get_Rcut(const std::vector<std::ve
548539
}
549540

550541
return Rcut;
551-
}
542+
}
543+
544+
void Exx_Abfs::Construct_Orbs::filter_empty_orbs(std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> &orbs)
545+
{
546+
for (int T=0; T<orbs.size(); ++T)
547+
{
548+
for (int L=orbs[T].size()-1; L>=0 ; --L)
549+
{
550+
if (orbs[T][L].size()>0)
551+
{ break; }
552+
else
553+
{ orbs[T].resize(L); }
554+
}
555+
}
556+
}

source/source_lcao/module_ri/exx_abfs-construct_orbs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class Exx_Abfs::Construct_Orbs
5757
return get_Rmax(rcut);
5858
}
5959

60+
static void filter_empty_orbs(
61+
std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> &orbs);
62+
6063
private:
6164
static std::vector<std::vector<std::vector<std::vector<double>>>> psi_mult_psi(
6265
const std::vector<std::vector<std::vector<Numerical_Orbital_Lm>>> &lcaos );

0 commit comments

Comments
 (0)