Skip to content

Commit ff43ca7

Browse files
authored
Merge branch 'develop' into feat/issue-7726-dftu-pw-nspin-fixes
2 parents 6630a2b + be4f130 commit ff43ca7

133 files changed

Lines changed: 2136 additions & 1243 deletions

File tree

Some content is hidden

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

docs/advanced/input_files/input-main.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@
653653
### bndpar
654654

655655
- **Type**: Integer
656-
- **Description**: Divide all processors into bndpar groups, and bands (only stochastic orbitals now) will be distributed among each group. It should be larger than 0.
656+
- **Description**: Divide all processors into bndpar groups for SDFT or the BPCG solver. bndpar must be positive, no greater than the number of MPI processes, and kpar * bndpar must divide the number of MPI processes exactly.
657657
- **Default**: 1
658658

659659
### latname
@@ -1265,7 +1265,7 @@
12651265
- **Description**: The number of spin components of wave functions.
12661266
- 1: Spin degeneracy
12671267
- 2: Collinear spin polarized.
1268-
- 4: For the case of noncollinear polarized, nspin will be automatically set to 4 without being specified by the user.
1268+
- 4: Noncollinear or spin-orbit calculations. Set nspin to 4 explicitly when noncolin or lspinorb is enabled.
12691269
- **Default**: 1
12701270

12711271
### smearing_method
@@ -1469,7 +1469,7 @@
14691469
- **Type**: Boolean
14701470
- **Description**: Whether to consider spin-orbit coupling (SOC) effect in the calculation.
14711471
- True: Consider spin-orbit coupling effect. When enabled:
1472-
- nspin is automatically set to 4 (noncollinear spin representation)
1472+
- nspin must be explicitly set to 4 (noncollinear spin representation)
14731473
- Symmetry is automatically disabled (SOC breaks inversion symmetry)
14741474
- Requires full-relativistic pseudopotentials with has_so=true in the UPF header
14751475
- False: Do not consider spin-orbit coupling effect.
@@ -1481,7 +1481,7 @@
14811481
- **Type**: Boolean
14821482
- **Description**: Whether to allow non-collinear magnetic moments, where magnetization can point in arbitrary directions (x, y, z components) rather than being constrained to the z-axis.
14831483
- True: Allow non-collinear polarization. When enabled:
1484-
- nspin is automatically set to 4
1484+
- nspin must be explicitly set to 4
14851485
- Wave function dimension is doubled (npol=2), and the number of occupied states is doubled
14861486
- Charge density has 4 components (Pauli spin matrices)
14871487
- Cannot be used with gamma_only=true
@@ -1535,8 +1535,8 @@
15351535
- **Type**: Integer or string
15361536
- **Availability**: *esolver_type = sdft*
15371537
- **Description**: The number of stochastic orbitals
1538-
- > 0: Perform stochastic DFT. Increasing the number of bands improves accuracy and reduces stochastic errors; To perform mixed stochastic-deterministic DFT, you should set nbands, which represents the number of KS orbitals.
1539-
- 0: Perform Kohn-Sham DFT.
1538+
- 1-1000000: Perform stochastic DFT. Increasing the number of bands improves accuracy and reduces stochastic errors; To perform mixed stochastic-deterministic DFT, you should set nbands, which represents the number of KS orbitals.
1539+
- 0: Invalid. Use all for the complete-basis SDFT mode.
15401540
- all: All complete basis sets are used to replace stochastic orbitals with the Chebyshev method (CT), resulting in the same results as KSDFT without stochastic errors.
15411541
- **Default**: 256
15421542

docs/advanced/scf/spin.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ If **"nupdown"** is set to non-zero, number of spin-up and spin-down electrons w
3030

3131
## Noncollinear Spin Polarized Calculations
3232
The spin non-collinear polarization calculation corresponds to setting **"noncolin 1"**, in which case the coupling between spin up and spin down will be taken into account.
33-
In this case, nspin is automatically set to 4, which is usually not required to be specified manually.
33+
In this case, **"nspin 4"** must also be specified. ABACUS reports an input error instead of silently changing an incompatible or omitted nspin value.
3434
The weight of each band will not change, but the number of occupied states will be double.
3535
If the nbands parameter is set manually, it is generally set to twice what it would be when nspin<4.
3636

37-
In general, non-collinear magnetic moment settings are often used in calculations considering [SOC effects](#soc-effects). When **"lspinorb 1"** in INPUT file, "nspin" is also automatically set to 4.
37+
In general, non-collinear magnetic moment settings are often used in calculations considering [SOC effects](#soc-effects). When **"lspinorb 1"** is set in INPUT, **"nspin 4"** is also required.
3838

3939
Note: different settings for "noncolin" and "lspinorb" correspond to different calculations:
4040

@@ -119,22 +119,22 @@ Example from a full-relativistic UPF file:
119119
- **PseudoDOJO**: Provides both scalar and full-relativistic versions
120120
- **ABACUS official**: [abacus.ustc.edu.cn](http://abacus.ustc.edu.cn/pseudo/list.htm)
121121

122-
## Automatic Parameter Settings
122+
## Parameter Requirements and Automatic Settings
123123

124-
When using SOC or non-collinear calculations, ABACUS automatically adjusts several parameters:
124+
When using SOC or non-collinear calculations, set the required spin representation explicitly. ABACUS still derives internal spin state and some related settings after validating the input:
125125

126126
### When `lspinorb=true`:
127-
1. **nspin**: Automatically set to 4 (noncollinear spin representation)
127+
1. **nspin**: Must be explicitly set to 4 (noncollinear spin representation)
128128
2. **Symmetry**: Automatically disabled (`symm_flag=-1`) because SOC breaks inversion symmetry
129129
3. **Magnetization**: NOT automatically set when `noncolin=0` (implies non-magnetic material with SOC)
130130

131131
### When `noncolin=true`:
132-
1. **nspin**: Automatically set to 4
132+
1. **nspin**: Must be explicitly set to 4
133133
2. **npol**: Set to 2 (wave function has two spinor components)
134134
3. **Magnetization**: Automatically set if user provides zero values (unless `lspinorb=1` and `noncolin=0`)
135135

136136
### Important Notes:
137-
- You do NOT need to manually set `nspin=4` when using `lspinorb=1` or `noncolin=1`
137+
- You must set `nspin=4` when using `lspinorb=1` or `noncolin=1`; missing or incompatible values are rejected during input validation
138138
- Symmetry operations are incompatible with SOC, so they are automatically turned off
139139
- For `lspinorb=1, noncolin=0`: This is a special case for non-magnetic materials with SOC, where magnetization is not initialized
140140

@@ -172,7 +172,7 @@ basis_type pw
172172
ecutwfc 50
173173
lspinorb 1 # Enable SOC
174174
noncolin 0 # No non-collinear magnetism
175-
# nspin will be automatically set to 4
175+
nspin 4 # Required spinor representation
176176
# symmetry will be automatically disabled
177177
```
178178

@@ -185,7 +185,7 @@ calculation scf
185185
basis_type lcao
186186
lspinorb 0 # No SOC
187187
noncolin 1 # Enable non-collinear magnetism
188-
# nspin will be automatically set to 4
188+
nspin 4 # Required spinor representation
189189
# Magnetization directions should be specified in STRU file
190190
```
191191

@@ -199,7 +199,7 @@ basis_type pw
199199
ecutwfc 60
200200
lspinorb 1 # Enable SOC
201201
noncolin 1 # Enable non-collinear magnetism
202-
# nspin will be automatically set to 4
202+
nspin 4 # Required spinor representation
203203
# symmetry will be automatically disabled
204204
# Magnetization directions should be specified in STRU file
205205
```
@@ -213,6 +213,7 @@ calculation scf
213213
basis_type pw
214214
ecutwfc 50
215215
lspinorb 1 # Enable SOC
216+
nspin 4 # Required spinor representation
216217
soc_lambda 0.5 # 50% SOC strength
217218
# Useful when full SOC overestimates or underestimates experimental results
218219
```

docs/community/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ To perform SOC calculations in ABACUS, follow these steps:
5050
2. **Use full-relativistic pseudopotentials**: SOC calculations require pseudopotentials with `has_so=true` in the UPF header
5151
- Download full-relativistic versions of SG15_ONCV pseudopotentials from [quantum-simulation.org](http://quantum-simulation.org/potentials/sg15_oncv/upf/)
5252
- Check the UPF file header for `relativistic="full"` and `has_so="T"`
53-
3. **Verify automatic settings**: When `lspinorb=1` is set, `nspin` is automatically set to 4 and symmetry is automatically disabled
53+
3. **Set the spin representation**: When `lspinorb=1` is set, explicitly set `nspin=4`; symmetry is automatically disabled
5454

5555
**Basis set support**: Both `basis_type=pw` (plane wave) and `basis_type=lcao` (numerical atomic orbitals) support SOC calculations for both SCF and NSCF.
5656

docs/parameters.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ parameters:
108108
category: System variables
109109
type: Integer
110110
description: |
111-
Divide all processors into bndpar groups, and bands (only stochastic orbitals now) will be distributed among each group. It should be larger than 0.
111+
Divide all processors into bndpar groups for SDFT or the BPCG solver. bndpar must be positive, no greater than the number of MPI processes, and kpar * bndpar must divide the number of MPI processes exactly.
112112
default_value: "1"
113113
unit: ""
114114
availability: ""
@@ -661,7 +661,7 @@ parameters:
661661
The number of spin components of wave functions.
662662
* 1: Spin degeneracy
663663
* 2: Collinear spin polarized.
664-
* 4: For the case of noncollinear polarized, nspin will be automatically set to 4 without being specified by the user.
664+
* 4: Noncollinear or spin-orbit calculations. Set nspin to 4 explicitly when noncolin or lspinorb is enabled.
665665
default_value: "1"
666666
unit: ""
667667
availability: ""
@@ -906,7 +906,7 @@ parameters:
906906
description: |
907907
Whether to consider spin-orbit coupling (SOC) effect in the calculation.
908908
* True: Consider spin-orbit coupling effect. When enabled:
909-
* nspin is automatically set to 4 (noncollinear spin representation)
909+
* nspin must be explicitly set to 4 (noncollinear spin representation)
910910
* Symmetry is automatically disabled (SOC breaks inversion symmetry)
911911
* Requires full-relativistic pseudopotentials with has_so=true in the UPF header
912912
* False: Do not consider spin-orbit coupling effect.
@@ -920,7 +920,7 @@ parameters:
920920
description: |
921921
Whether to allow non-collinear magnetic moments, where magnetization can point in arbitrary directions (x, y, z components) rather than being constrained to the z-axis.
922922
* True: Allow non-collinear polarization. When enabled:
923-
* nspin is automatically set to 4
923+
* nspin must be explicitly set to 4
924924
* Wave function dimension is doubled (npol=2), and the number of occupied states is doubled
925925
* Charge density has 4 components (Pauli spin matrices)
926926
* Cannot be used with gamma_only=true
@@ -2198,8 +2198,8 @@ parameters:
21982198
type: Integer or string
21992199
description: |
22002200
The number of stochastic orbitals
2201-
* > 0: Perform stochastic DFT. Increasing the number of bands improves accuracy and reduces stochastic errors; To perform mixed stochastic-deterministic DFT, you should set nbands, which represents the number of KS orbitals.
2202-
* 0: Perform Kohn-Sham DFT.
2201+
* 1-1000000: Perform stochastic DFT. Increasing the number of bands improves accuracy and reduces stochastic errors; To perform mixed stochastic-deterministic DFT, you should set nbands, which represents the number of KS orbitals.
2202+
* 0: Invalid. Use all for the complete-basis SDFT mode.
22032203
* all: All complete basis sets are used to replace stochastic orbitals with the Chebyshev method (CT), resulting in the same results as KSDFT without stochastic errors.
22042204
default_value: "256"
22052205
unit: ""

examples/21_deepks/03_lcao_CsPbI3/INPUT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ deepks_model model.ptg
2929

3030
#Parameters (7.SOC)
3131
lspinorb 1
32+
nspin 4
3233

3334

3435

source/Makefile.Objects

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,28 @@ OBJS_HAMILT_OF=kedf_tf.o\
343343
OBJS_HAMILT_LCAO=hamilt_lcao.o\
344344
operator_lcao.o\
345345
ekinetic.o\
346+
ekinetic_fs.o\
347+
ekinetic_dh.o\
346348
nonlocal.o\
349+
nonlocal_dh.o\
350+
nonlocal_fs.o\
347351
overlap.o\
352+
overlap_fs.o\
348353
td_ekinetic_lcao.o\
349354
td_nonlocal_lcao.o\
350355
td_pot_hybrid.o\
356+
td_pot_hybrid_fs.o\
351357
veff_lcao.o\
358+
veff_dh.o\
352359
meta_lcao.o\
353360
op_dftu_lcao.o\
354361
deepks_lcao.o\
355362
op_exx_lcao.o\
356363
dspin_lcao.o\
364+
dspin_fs.o\
357365
dftu_lcao.o\
366+
dftu_fs.o\
367+
operator_fs_utils.o\
358368

359369
OBJS_HCONTAINER=base_matrix.o\
360370
atom_pair.o\
@@ -721,7 +731,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
721731
setup_pwrho.o\
722732
setup_pwwfc.o\
723733
update_cell_pw.o\
724-
dftu_pw.o\
734+
setup_dftu_pw.o\
725735
deltaspin_pw.o\
726736
forces.o\
727737
forces_us.o\
@@ -793,7 +803,7 @@ OBJS_DFTU=dftu.o\
793803
dftu_tools.o\
794804
dftu_occup.o\
795805
dftu_hamilt.o\
796-
dftu_pw.o
806+
setup_dftu_pw.o
797807

798808
OBJS_DELTASPIN=basic_funcs.o\
799809
cal_mw_from_lambda.o\

source/source_esolver/esolver_double_xc.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "esolver_double_xc.h"
22

33
#include "source_hamilt/module_ewald/H_Ewald_pw.h"
4-
#include "source_hamilt/module_vdw/vdw.h"
54
#include "source_hamilt/module_xc/xc_functional.h"
65
#ifdef __MLALGO
76
#include "source_lcao/module_deepks/LCAO_deepks.h"
@@ -121,13 +120,9 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
121120
ESolver_KS_LCAO<TK, TR>::before_scf(ucell, istep);
122121

123122
//----------------------------------------------------------
124-
//! calculate D2 or D3 vdW
123+
//! Reuse the vdW correction prepared by ESolver_FP::before_scf.
125124
//----------------------------------------------------------
126-
auto vdw_solver = vdw::make_vdw(ucell, PARAM.inp, &(GlobalV::ofs_running));
127-
if (vdw_solver != nullptr)
128-
{
129-
this->pelec_base->f_en.evdw = vdw_solver->get_energy();
130-
}
125+
this->pelec_base->f_en.evdw = this->pelec->f_en.evdw;
131126

132127
//----------------------------------------------------------
133128
//! calculate ewald energy
@@ -398,6 +393,7 @@ void ESolver_DoubleXC<TK, TR>::cal_force(BaseCell& basecell, ModuleBase::matrix&
398393
this->deepks.dpks_out_type = "base"; // for deepks method
399394

400395
fsl.getForceStress(ucell,
396+
this->get_vdw_result(),
401397
PARAM.inp.cal_force,
402398
PARAM.inp.cal_stress,
403399
PARAM.inp.test_force,

source/source_esolver/esolver_fp.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,18 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
190190
GlobalV::ofs_running, GlobalV::ofs_warning);
191191
}
192192

193-
//! calculate D2 or D3 vdW
193+
//! Evaluate the vdW correction once for this ionic configuration.
194+
this->vdw_result_.reset();
194195
auto vdw_solver = vdw::make_vdw(ucell, PARAM.inp, &(GlobalV::ofs_running));
195196
if (vdw_solver != nullptr)
196197
{
197-
this->pelec->f_en.evdw = vdw_solver->get_energy();
198+
const vdw::VdwRequest request(PARAM.inp.cal_force, PARAM.inp.cal_stress);
199+
this->vdw_result_.reset(new vdw::VdwResult(vdw_solver->evaluate(request)));
200+
this->pelec->f_en.evdw = this->vdw_result_->energy;
201+
}
202+
else
203+
{
204+
this->pelec->f_en.evdw = 0.0;
198205
}
199206

200207
//! calculate ewald energy

source/source_esolver/esolver_fp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#include "source_pw/module_pwdft/vl_pw.h" // local pseudopotential
1313

1414
#include <fstream>
15+
#include <memory>
16+
17+
namespace vdw
18+
{
19+
struct VdwResult;
20+
}
1521

1622
//! The First-Principles (FP) Energy Solver Class
1723
/**
@@ -42,6 +48,11 @@ class ESolver_FP : public ESolver
4248

4349
virtual void iter_finish(UnitCell& ucell, const int istep, int& iter, bool& conv_esolver);
4450

51+
const vdw::VdwResult* get_vdw_result() const { return this->vdw_result_.get(); }
52+
53+
//! vdW correction evaluated once for the current ionic configuration.
54+
std::unique_ptr<const vdw::VdwResult> vdw_result_;
55+
4556
//! These pointers will be deleted in the free_pointers() function every ion step.
4657
elecstate::ElecState* pelec = nullptr; ///< Electronic states
4758

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "source_lcao/module_deltaspin/spin_constrain.h"
66
#include "source_lcao/module_deltaspin/deltaspin_lcao.h"
77
#include "source_lcao/dftu_lcao.h"
8-
#include "source_lcao/hs_matrix_k.hpp" // there may be multiple definitions if using hpp
8+
#include "source_hamilt/hs_matrix_k.h"
99
#include "source_estate/module_charge/symmetry_rho.h"
1010
#include "source_lcao/LCAO_domain.h" // need DeePKS_init
1111
#include "source_lcao/FORCE_STRESS.h"
@@ -248,7 +248,7 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(BaseCell& basecell, ModuleBase::matrix&
248248

249249
deepks.dpks_out_type = "tot"; // for deepks method
250250

251-
fsl.getForceStress(ucell, PARAM.inp.cal_force, PARAM.inp.cal_stress,
251+
fsl.getForceStress(ucell, this->get_vdw_result(), PARAM.inp.cal_force, PARAM.inp.cal_stress,
252252
PARAM.inp.test_force, PARAM.inp.test_stress,
253253
this->gd, this->pv, this->pelec, this->dmat, this->psi,
254254
two_center_bundle_, orb_, force, this->scs,

0 commit comments

Comments
 (0)