Skip to content

Commit d0e0915

Browse files
mohanchenabacus_fixer
andauthored
Add the framework of DFPT in plane wave basis (#7356)
* add dfpt codes * DFPT-PW: Add plane-wave DFPT energy solver framework This commit adds the complete framework for a Density Functional Perturbation Theory (DFPT) solver for plane-wave basis set in ABACUS. New files added: - source/source_pw/module_dfpt/dfpt_pw.h/cpp - Main DFPT-PW interface (Pimpl pattern) - source/source_pw/module_dfpt/dfpt_pw_data.h/cpp - PW-specific data container - source/source_pw/module_dfpt/dfpt_pert.h/cpp - Perturbation construction - source/source_pw/module_dfpt/dfpt_stern.h/cpp - Sternheimer equation solver - source/source_pw/module_dfpt/dfpt_rho.h/cpp - First-order density handling - source/source_pw/module_dfpt/dfpt_phon.h/cpp - Phonon/dynamical matrix - source/source_pw/module_dfpt/dfpt_q0.h/cpp - q=0 special handling (dielectric, Born) - source/source_pw/module_dfpt/dfpt_metal.h/cpp - Metal system handling - source/source_pw/module_dfpt/CMakeLists.txt - Module build configuration - source/source_pw/module_dfpt/README.md - Module documentation - source/source_cell/qlist.h/cpp - q-point management - source/source_esolver/esolver_dfpt_pw.h/cpp - DFPT energy solver Modified files: - CMakeLists.txt - Added module_dfpt to target_link_libraries - source/source_pw/CMakeLists.txt - Added module_dfpt subdirectory - source/source_cell/CMakeLists.txt - Added qlist.cpp and qlist.h - source/source_esolver/CMakeLists.txt - Added esolver_dfpt_pw.cpp Note: This code is in design phase and has not been put into production yet. All implementation classes contain stub implementations that need to be filled in. * update notes * update --------- Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
1 parent 6320309 commit d0e0915

29 files changed

Lines changed: 1578 additions & 0 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ target_link_libraries(
856856
module_pwdft
857857
module_ofdft
858858
module_stodft
859+
module_dfpt
859860
psi
860861
psi_initializer
861862
psi_overall_init
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
INPUT_PARAMETERS
2+
#Parameters (1.General)
3+
suffix Si_nhc_nvt
4+
calculation md
5+
nbands 20
6+
symmetry 0
7+
pseudo_dir ../../../tests/PP_ORB
8+
orbital_dir ../../../tests/PP_ORB
9+
10+
#Parameters (2.Iteration)
11+
ecutwfc 10
12+
scf_thr 1e-5
13+
scf_nmax 100
14+
15+
#Parameters (3.Basis)
16+
basis_type lcao
17+
ks_solver genelpa
18+
gamma_only 1
19+
20+
#Parameters (4.Smearing)
21+
smearing_method gaussian
22+
smearing_sigma 0.001
23+
24+
#Parameters (5.Mixing)
25+
mixing_type broyden
26+
mixing_beta 0.3
27+
chg_extrap second-order
28+
29+
#Parameters (6.MD)
30+
md_type nvt
31+
md_nstep 10
32+
md_dt 1
33+
md_tfirst 300
34+
md_tfreq 1
35+
md_tchain 1
36+
37+
dft_functional hse
38+
restart_save 1

examples/18_md/02_lcao_output/KPT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
K_POINTS
2+
0
3+
Gamma
4+
1 1 1 0 0 0

examples/18_md/02_lcao_output/STRU

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ATOMIC_SPECIES
2+
Si 28.085 Si_ONCV_PBE-1.0.upf
3+
4+
NUMERICAL_ORBITAL
5+
Si_gga_8au_60Ry_2s2p1d.orb
6+
7+
LATTICE_CONSTANT
8+
1.8897270 # 1 Angstrom = 1.8897270 bohr
9+
10+
LATTICE_VECTORS
11+
5.43090 0.00000 0.00000
12+
0.00000 5.43090 0.00000
13+
0.00000 0.00000 5.43090
14+
15+
ATOMIC_POSITIONS
16+
Direct
17+
18+
Si
19+
0.0
20+
2
21+
0.000 0.000 0.000 1 1 1
22+
0.5 0.5 0.5 1 1 1

source/source_cell/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ add_library(
3030
k_vector_utils.cpp
3131
sep.cpp
3232
sep_cell.cpp
33+
qlist.cpp
34+
qlist.h
3335
)
3436

3537
if(ENABLE_COVERAGE)

source/source_cell/qlist.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// ============================================================
2+
// This code is added by Mohan Chen on 2026-05-18.
3+
// This code is currently in the design phase and has not been
4+
// put into production yet. It may change in the future.
5+
// Please use this code with caution. Only developers who know
6+
// what they are doing should use this code.
7+
// ============================================================
8+
9+
#include "qlist.h"
10+
11+
namespace ModuleCell {
12+
13+
QList::QList() {}
14+
15+
QList::~QList() {}
16+
17+
void QList::generate_mesh(UnitCell& ucell, ModuleSymmetry::Symmetry& symm,
18+
const std::vector<int>& mp_grid, bool use_irreps) {
19+
(void)ucell;
20+
(void)symm;
21+
(void)mp_grid;
22+
(void)use_irreps;
23+
24+
nq_ = 1;
25+
qvec_.resize(nq_);
26+
qvec_[0] = ModuleBase::Vector3<double>(0.0, 0.0, 0.0);
27+
28+
nirr_.resize(nq_);
29+
nirr_[0] = 1;
30+
31+
irrep_modes_.resize(nq_);
32+
irrep_modes_[0].resize(1);
33+
}
34+
35+
void QList::read_from_file(const std::string& filename, UnitCell& ucell) {
36+
(void)filename;
37+
(void)ucell;
38+
}
39+
40+
std::vector<int> QList::get_irrep_modes(int q_idx, int irrep_idx) const {
41+
(void)q_idx;
42+
(void)irrep_idx;
43+
return std::vector<int>();
44+
}
45+
46+
void QList::reduce(UnitCell& ucell, ModuleSymmetry::Symmetry& symm) {
47+
(void)ucell;
48+
(void)symm;
49+
}
50+
51+
void QList::get_irreps(UnitCell& ucell, ModuleSymmetry::Symmetry& symm) {
52+
(void)ucell;
53+
(void)symm;
54+
}
55+
56+
} // namespace ModuleCell

source/source_cell/qlist.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// ============================================================
2+
// This code is added by Mohan Chen on 2026-05-18.
3+
// This code is currently in the design phase and has not been
4+
// put into production yet. It may change in the future.
5+
// Please use this code with caution. Only developers who know
6+
// what they are doing should use this code.
7+
// ============================================================
8+
9+
#ifndef QLIST_H
10+
#define QLIST_H
11+
12+
#include "source_base/vector3.h"
13+
#include "module_symmetry/symmetry.h"
14+
#include "unitcell.h"
15+
#include <vector>
16+
17+
namespace ModuleCell {
18+
19+
class QList {
20+
public:
21+
QList();
22+
~QList();
23+
24+
void generate_mesh(UnitCell& ucell, ModuleSymmetry::Symmetry& symm,
25+
const std::vector<int>& mp_grid, bool use_irreps);
26+
27+
void read_from_file(const std::string& filename, UnitCell& ucell);
28+
29+
int get_nq() const { return nq_; }
30+
31+
ModuleBase::Vector3<double> get_q(int idx) const { return qvec_[idx]; }
32+
33+
int get_nirr(int idx) const { return nirr_[idx]; }
34+
35+
std::vector<int> get_irrep_modes(int q_idx, int irrep_idx) const;
36+
37+
private:
38+
int nq_ = 0;
39+
std::vector<ModuleBase::Vector3<double>> qvec_;
40+
std::vector<int> nirr_;
41+
std::vector<std::vector<std::vector<int>>> irrep_modes_;
42+
43+
void reduce(UnitCell& ucell, ModuleSymmetry::Symmetry& symm);
44+
45+
void get_irreps(UnitCell& ucell, ModuleSymmetry::Symmetry& symm);
46+
};
47+
48+
} // namespace ModuleCell
49+
50+
#endif // QLIST_H

source/source_esolver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ list(APPEND objects
1313
esolver_of_interface.cpp
1414
esolver_of_tool.cpp
1515
pw_others.cpp
16+
esolver_dfpt_pw.cpp
1617
)
1718
if(ENABLE_LCAO)
1819
list(APPEND objects
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// ============================================================
2+
// This code is added by Mohan Chen on 2026-05-18.
3+
// This code is currently in the design phase and has not been
4+
// put into production yet. It may change in the future.
5+
// Please use this code with caution. Only developers who know
6+
// what they are doing should use this code.
7+
// ============================================================
8+
9+
#include "esolver_dfpt_pw.h"
10+
#include "source_base/tool_quit.h"
11+
12+
namespace ModuleESolver {
13+
14+
ESolver_DFPT_PW::ESolver_DFPT_PW() {
15+
this->classname = "ESolver_DFPT_PW";
16+
this->basisname = "PW";
17+
gs_done_ = false;
18+
dfpt_ = nullptr;
19+
}
20+
21+
ESolver_DFPT_PW::~ESolver_DFPT_PW() {
22+
if (dfpt_ != nullptr) {
23+
delete dfpt_;
24+
dfpt_ = nullptr;
25+
}
26+
}
27+
28+
void ESolver_DFPT_PW::before_all_runners(UnitCell& ucell, const Input_para& inp) {
29+
ModuleBase::TITLE("ESolver_DFPT_PW", "before_all_runners");
30+
31+
ESolver_KS_PW<std::complex<double>, base_device::DEVICE_CPU>::before_all_runners(ucell, inp);
32+
33+
init_dfpt(ucell);
34+
}
35+
36+
void ESolver_DFPT_PW::runner(UnitCell& ucell, const int istep) {
37+
ModuleBase::TITLE("ESolver_DFPT_PW", "runner");
38+
39+
if (!gs_done_) {
40+
run_gs(ucell);
41+
gs_done_ = true;
42+
}
43+
44+
if (dfpt_ != nullptr) {
45+
dfpt_->run();
46+
}
47+
48+
run_post_process(ucell);
49+
}
50+
51+
void ESolver_DFPT_PW::after_all_runners(UnitCell& ucell) {
52+
ModuleBase::TITLE("ESolver_DFPT_PW", "after_all_runners");
53+
54+
ESolver_KS_PW<std::complex<double>, base_device::DEVICE_CPU>::after_all_runners(ucell);
55+
}
56+
57+
void ESolver_DFPT_PW::run_gs(UnitCell& ucell) {
58+
ModuleBase::TITLE("ESolver_DFPT_PW", "run_gs");
59+
60+
ESolver_KS_PW<std::complex<double>, base_device::DEVICE_CPU>::runner(ucell, 0);
61+
}
62+
63+
void ESolver_DFPT_PW::init_dfpt(UnitCell& ucell) {
64+
ModuleBase::TITLE("ESolver_DFPT_PW", "init_dfpt");
65+
66+
dfpt_ = new ModuleDFPT::DFPT_PW();
67+
68+
// dfpt_->init(ucell, *this->stp.psi, this->pelec->nelec, PARAM.inp.ecutwfc);
69+
70+
dfpt_->set_parameters("dfpt.in");
71+
72+
dfpt_->set_qmesh(1, 1, 1);
73+
74+
dfpt_->set_conv_thr(1e-8);
75+
dfpt_->set_max_iter(100);
76+
}
77+
78+
void ESolver_DFPT_PW::run_post_process(UnitCell& ucell) {
79+
ModuleBase::TITLE("ESolver_DFPT_PW", "run_post_process");
80+
}
81+
82+
} // namespace ModuleESolver
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ============================================================
2+
// This code is added by Mohan Chen on 2026-05-18.
3+
// This code is currently in the design phase and has not been
4+
// put into production yet. It may change in the future.
5+
// Please use this code with caution. Only developers who know
6+
// what they are doing should use this code.
7+
// ============================================================
8+
9+
#ifndef ESOLVER_DFPT_PW_H
10+
#define ESOLVER_DFPT_PW_H
11+
12+
#include "esolver_ks_pw.h"
13+
#include "source_pw/module_dfpt/dfpt_pw.h"
14+
15+
namespace ModuleESolver {
16+
17+
class ESolver_DFPT_PW : public ESolver_KS_PW<std::complex<double>, base_device::DEVICE_CPU> {
18+
public:
19+
ESolver_DFPT_PW();
20+
~ESolver_DFPT_PW();
21+
22+
void before_all_runners(UnitCell& ucell, const Input_para& inp) override;
23+
void runner(UnitCell& ucell, const int istep) override;
24+
void after_all_runners(UnitCell& ucell) override;
25+
26+
protected:
27+
ModuleDFPT::DFPT_PW* dfpt_ = nullptr;
28+
29+
bool gs_done_ = false;
30+
31+
void run_gs(UnitCell& ucell);
32+
33+
void init_dfpt(UnitCell& ucell);
34+
35+
void run_post_process(UnitCell& ucell);
36+
};
37+
38+
} // namespace ModuleESolver
39+
40+
#endif // ESOLVER_DFPT_PW_H

0 commit comments

Comments
 (0)