Skip to content

Commit c9c0189

Browse files
dyzhengdyzheng
and
dyzheng
authored
Feature: DFT+U for noncollinear spin calculation with PW base (deepmodeling#5703)
* Feature: DFT+U for noncollinear spin calculation with PW base * add test case for DFT+U in PW base * Fix: bug of cmakelist * Fix: error in CI * Fix: GPU error in CI --------- Co-authored-by: dyzheng <[email protected]>
1 parent 5280bd4 commit c9c0189

File tree

88 files changed

+5847
-652
lines changed

Some content is hidden

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

88 files changed

+5847
-652
lines changed

CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -711,17 +711,17 @@ target_link_libraries(
711711
esolver
712712
vdw
713713
device
714-
container)
714+
container
715+
dftu
716+
deltaspin)
715717
if(ENABLE_LCAO)
716718
target_link_libraries(
717719
${ABACUS_BIN_NAME}
718720
hamilt_lcao
719721
tddft
720722
orb
721723
gint
722-
dftu
723724
hcontainer
724-
deltaspin
725725
numerical_atomic_orbitals
726726
lr
727727
rdmft)

docs/advanced/input_files/input-main.md

+6
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,12 @@ Note: In new angle mixing, you should set `mixing_beta_mag >> mixing_beta`. The
12351235
- **Description**: To determine the number of old iterations' `drho` used in slope calculations.
12361236
- **Default**: `mixing_ndim`
12371237

1238+
### sc_os_ndim
1239+
1240+
- **Type**: int
1241+
- **Description**: To determine the number of old iterations to judge oscillation, it occured, more accurate lambda with DeltaSpin method would be calculated, only for PW base.
1242+
- **Default**: 5
1243+
12381244
### chg_extrap
12391245

12401246
- **Type**: String

python/pyabacus/src/ModuleNAO/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ list(APPEND _naos
1212
${NAO_PATH}/two_center_bundle.cpp
1313
${NAO_PATH}/two_center_integrator.cpp
1414
${NAO_PATH}/two_center_table.cpp
15-
${NAO_PATH}/projgen.cpp
1615
# dependency
1716
${ABACUS_SOURCE_DIR}/module_base/kernels/math_op.cpp
1817
# ${ABACUS_SOURCE_DIR}/module_psi/kernels/psi_memory_op.cpp

source/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ list(APPEND device_srcs
4747

4848
module_hamilt_pw/hamilt_pwdft/kernels/force_op.cpp
4949
module_hamilt_pw/hamilt_pwdft/kernels/stress_op.cpp
50+
module_hamilt_pw/hamilt_pwdft/kernels/onsite_op.cpp
5051
module_hamilt_pw/hamilt_pwdft/kernels/wf_op.cpp
5152
module_hamilt_pw/hamilt_pwdft/kernels/vnl_op.cpp
5253
module_base/kernels/math_op.cpp
@@ -60,6 +61,7 @@ if(USE_CUDA)
6061
module_hamilt_pw/hamilt_pwdft/kernels/cuda/ekinetic_op.cu
6162
module_hamilt_pw/hamilt_pwdft/kernels/cuda/meta_op.cu
6263
module_hamilt_pw/hamilt_stodft/kernels/cuda/hpsi_norm_op.cu
64+
module_hamilt_pw/hamilt_pwdft/kernels/cuda/onsite_op.cu
6365
module_basis/module_pw/kernels/cuda/pw_op.cu
6466
module_hsolver/kernels/cuda/dngvd_op.cu
6567
module_hsolver/kernels/cuda/math_kernel_op.cu
@@ -83,6 +85,7 @@ if(USE_ROCM)
8385
module_hamilt_pw/hamilt_pwdft/kernels/rocm/veff_op.hip.cu
8486
module_hamilt_pw/hamilt_pwdft/kernels/rocm/ekinetic_op.hip.cu
8587
module_hamilt_pw/hamilt_pwdft/kernels/rocm/meta_op.hip.cu
88+
module_hamilt_pw/hamilt_pwdft/kernels/rocm/onsite_op.hip.cu
8689
module_hamilt_pw/hamilt_stodft/kernels/rocm/hpsi_norm_op.hip.cu
8790
module_basis/module_pw/kernels/rocm/pw_op.hip.cu
8891
module_hsolver/kernels/rocm/dngvd_op.hip.cu

source/Makefile.Objects

+9-2
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,13 @@ OBJS_SRCPW=H_Ewald_pw.o\
635635
forces_nl.o\
636636
forces_cc.o\
637637
forces_scc.o\
638+
forces_onsite.o\
639+
onsite_proj_pw.o\
638640
fs_nonlocal_tools.o\
639641
fs_kin_tools.o\
640642
force_op.o\
641643
stress_op.o\
644+
onsite_op.o\
642645
wf_op.o\
643646
vnl_op.o\
644647
global.o\
@@ -663,6 +666,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
663666
stress_func_loc.o\
664667
stress_func_nl.o\
665668
stress_func_us.o\
669+
stress_func_onsite.o\
666670
stress_pw.o\
667671
of_stress_pw.o\
668672
symmetry_rho.o\
@@ -673,7 +677,9 @@ OBJS_SRCPW=H_Ewald_pw.o\
673677
elecond.o\
674678
sto_tool.o\
675679
sto_elecond.o\
676-
sto_dos.o
680+
sto_dos.o\
681+
onsite_projector.o\
682+
onsite_proj_tools.o
677683

678684
OBJS_VDW=vdw.o\
679685
vdwd2_parameters.o\
@@ -691,7 +697,8 @@ OBJS_DFTU=dftu.o\
691697
dftu_io.o\
692698
dftu_tools.o\
693699
dftu_occup.o\
694-
dftu_hamilt.o
700+
dftu_hamilt.o\
701+
dftu_pw.o
695702

696703
OBJS_DELTASPIN=basic_funcs.o\
697704
cal_mw_from_lambda.o\

source/module_base/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ add_library(
5454
spherical_bessel_transformer.cpp
5555
cubic_spline.cpp
5656
parallel_2d.cpp
57+
projgen.cpp
5758
module_mixing/mixing_data.cpp
5859
module_mixing/mixing.cpp
5960
module_mixing/plain_mixing.cpp

source/module_basis/module_nao/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ if(ENABLE_LCAO)
1414
two_center_table.cpp
1515
two_center_integrator.cpp
1616
two_center_bundle.cpp
17-
projgen.cpp
1817
)
1918

2019
if(ENABLE_COVERAGE)

source/module_basis/module_nao/atomic_radials.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// FIXME: should update with pyabacus
88
// #include "module_io/orb_io.h"
99

10-
#include "projgen.h"
10+
#include "module_base/projgen.h"
1111

1212
#include <fstream>
1313
#include <iostream>

source/module_basis/module_nao/test/CMakeLists.txt

-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ AddTest(
1414
../atomic_radials.cpp
1515
../radial_set.cpp
1616
../numerical_radial.cpp
17-
../projgen.cpp
1817
../../module_ao/ORB_atomic_lm.cpp
1918
../../module_ao/ORB_atomic.cpp
2019
../../../module_io/orb_io.cpp
@@ -84,7 +83,6 @@ AddTest(
8483
../pswfc_radials.cpp
8584
../radial_set.cpp
8685
../numerical_radial.cpp
87-
../projgen.cpp
8886
../sphbes_radials.cpp
8987
../../module_ao/ORB_atomic_lm.cpp
9088
../../module_ao/ORB_atomic.cpp
@@ -104,7 +102,6 @@ AddTest(
104102
../pswfc_radials.cpp
105103
../sphbes_radials.cpp
106104
../radial_set.cpp
107-
../projgen.cpp
108105
../numerical_radial.cpp
109106
../two_center_bundle.cpp
110107
../two_center_integrator.cpp
@@ -131,7 +128,6 @@ AddTest(
131128
../real_gaunt_table.cpp
132129
../radial_collection.cpp
133130
../atomic_radials.cpp
134-
../projgen.cpp
135131
../beta_radials.cpp
136132
../hydrogen_radials.cpp
137133
../pswfc_radials.cpp
@@ -158,7 +154,6 @@ AddTest(
158154
../pswfc_radials.cpp
159155
../sphbes_radials.cpp
160156
../radial_set.cpp
161-
../projgen.cpp
162157
../numerical_radial.cpp
163158
../../../module_io/orb_io.cpp
164159
LIBS parameter ${math_libs} device base container orb
@@ -179,7 +174,6 @@ AddTest(
179174
../pswfc_radials.cpp
180175
../sphbes_radials.cpp
181176
../radial_set.cpp
182-
../projgen.cpp
183177
../numerical_radial.cpp
184178
../../../module_io/orb_io.cpp
185179
LIBS parameter ${math_libs} device base container orb

source/module_basis/module_nao/test/projgen_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "module_basis/module_nao/projgen.h"
1+
#include "module_base/projgen.h"
22
#include "gtest/gtest.h"
33

44
#include "module_base/math_integral.h"

source/module_cell/read_atoms.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn
455455
}
456456
else if(PARAM.inp.basis_type == "pw")
457457
{
458-
if ((PARAM.inp.psi_initializer)&&(PARAM.inp.init_wfc.substr(0, 3) == "nao"))
458+
if ((PARAM.inp.psi_initializer)&&(PARAM.inp.init_wfc.substr(0, 3) == "nao") || PARAM.inp.onsite_radius > 0.0)
459459
{
460460
std::string orbital_file = PARAM.inp.orbital_dir + orbital_fn[it];
461461
this->read_orb_file(it, orbital_file, ofs_running, &(atoms[it]));

source/module_cell/unitcell.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ UnitCell::UnitCell() {
6464
atom_mass = nullptr;
6565
pseudo_fn = new std::string[1];
6666
pseudo_type = new std::string[1];
67-
orbital_fn = new std::string[1];
6867

6968
set_atom_flag = false;
7069
}
@@ -114,6 +113,15 @@ void UnitCell::bcast_unitcell() {
114113
Parallel_Common::bcast_int(lc[1]);
115114
Parallel_Common::bcast_int(lc[2]);
116115

116+
if(this->orbital_fn == nullptr)
117+
{
118+
this->orbital_fn = new std::string[ntype];
119+
}
120+
for (int i = 0; i < ntype; i++)
121+
{
122+
Parallel_Common::bcast_string(orbital_fn[i]);
123+
}
124+
117125
// distribute lattice vectors.
118126
Parallel_Common::bcast_double(a1.x);
119127
Parallel_Common::bcast_double(a1.y);

source/module_cell/unitcell.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class UnitCell {
216216
std::string* pseudo_fn;
217217
std::string* pseudo_type; // pseudopotential types for each elements,
218218
// sunliang added 2022-09-15.
219-
std::string* orbital_fn; // filenames of orbitals, liuyu add 2022-10-19
219+
std::string* orbital_fn = nullptr; // filenames of orbitals, liuyu add 2022-10-19
220220
std::string
221221
descriptor_file; // filenames of descriptor_file, liuyu add 2023-04-06
222222

source/module_elecstate/elecstate.h

-2
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ class ElecState
151151
return 0.0;
152152
}
153153

154-
#ifdef __LCAO
155154
double get_dftu_energy();
156-
#endif
157155

158156
#ifdef __DEEPKS
159157
double get_deepks_E_delta();

source/module_elecstate/elecstate_energy.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ void ElecState::cal_energies(const int type)
287287
}
288288

289289
//! spin constrained energy
290-
#ifdef __LCAO
291290
if (PARAM.inp.sc_mag_switch)
292291
{
293292
this->f_en.escon = get_spin_constrain_energy();
@@ -298,7 +297,6 @@ void ElecState::cal_energies(const int type)
298297
{
299298
this->f_en.edftu = get_dftu_energy();
300299
}
301-
#endif
302300

303301
#ifdef __DEEPKS
304302
// energy from deepks

source/module_elecstate/elecstate_energy_terms.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ double ElecState::get_solvent_model_Acav()
3434
return GlobalC::solvent_model.Acav;
3535
}
3636

37-
#ifdef __LCAO
3837
double ElecState::get_dftu_energy()
3938
{
4039
return GlobalC::dftu.get_energy();
4140
}
42-
#endif
4341

4442
#ifdef __DEEPKS
4543
double ElecState::get_deepks_E_delta()

source/module_esolver/esolver_ks_lcao.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
193193
// 7) initialize DFT+U
194194
if (PARAM.inp.dft_plus_u)
195195
{
196-
GlobalC::dftu.init(ucell, &this->pv, this->kv.get_nks(), orb_);
196+
auto* dftu = ModuleDFTU::DFTU::get_instance();
197+
dftu->init(ucell, &this->pv, this->kv.get_nks(), &orb_);
197198
}
198199

199200
// 8) initialize ppcell
@@ -1140,7 +1141,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
11401141
//! Perform Mulliken charge analysis
11411142
if (PARAM.inp.out_mul)
11421143
{
1143-
ModuleIO::cal_mag(&(this->pv), this->p_hamilt, this->kv, this->pelec, ucell, istep, true);
1144+
ModuleIO::cal_mag(&(this->pv), this->p_hamilt, this->kv, this->pelec, this->two_center_bundle_, this->orb_, ucell, istep, true);
11441145
}
11451146
}
11461147

0 commit comments

Comments
 (0)