You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
dyzheng
committed
Fix(xc): fix libxc gga_grad branching for nspin=4 GGA
The gga_grad=3 path (default for nspin=4) incorrectly used the
collinear approximation (gga_grad=1) within libxc instead of the
Scalmani-Frisch gradient method (gga_grad=2). This caused inconsistent
results for noncollinear GGA calculations.
Fix: extend libxc_pot.cpp and libxc_tools.cpp gga_grad==2 checks
to also match gga_grad==3, routing both through the SF gradient path.
Also fix input_parameter.h: restore out_hsr/out_hsk/out_hsr_npz_compat
members removed during cherry-pick that were present in newer develop.
Copy file name to clipboardExpand all lines: docs/advanced/scf/spin.md
+265Lines changed: 265 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,224 @@ If **"ocp=1"** and **"ocp_set"** is set in INPUT file, the occupations of states
28
28
2.**"nupdown"**
29
29
If **"nupdown"** is set to non-zero, number of spin-up and spin-down electrons will be fixed, and Fermi energy level will split to E_Fermi_up and E_Fermi_down. By the way, total magnetization will also be fixed, and will be the value of **"nupdown"**.
30
30
31
+
## DeltaSpin (Spin-Constrained DFT)
32
+
33
+
DeltaSpin is a spin-constrained DFT method that allows users to constrain the magnetic moments on individual atoms to target values during self-consistent field (SCF) calculations. This is useful for studying magnetic excitations, non-collinear magnetic structures, and systems where the magnetic ground state is not known a priori.
34
+
35
+
The theoretical foundation and implementation details can be found in:
36
+
37
+
- Cai Z, Wang K, Xu Y, et al., "A self-adaptive first-principles approach for magnetic excited states," *Quantum Frontiers* 2.1 (2023): 21. [DOI: 10.1007/s44214-023-00050-z](https://doi.org/10.1007/s44214-023-00050-z)
38
+
- Zheng D, Peng X, Huang Y, et al., "Integrating deep-learning-based magnetic model and non-collinear spin-constrained method: methodology, implementation and application," *npj Computational Materials* (2026).
39
+
40
+
### Enabling DeltaSpin
41
+
42
+
Set `sc_mag_switch 1` in the INPUT file. DeltaSpin is supported for both PW (`basis_type = pw`) and LCAO (`basis_type = lcao`) basis sets, with `nspin = 2` (collinear) or `nspin = 4` (non-collinear).
43
+
44
+
### Specifying Target Magnetic Moments in STRU
45
+
46
+
Target magnetic moments and constraint flags are specified per atom in the `ATOMIC_POSITIONS` section of the STRU file, using the `mag` (or `magmom`), `sc`, `lambda`, `angle1`, and `angle2` keywords after the atomic coordinates.
47
+
48
+
#### Collinear (nspin=2)
49
+
50
+
For collinear spin, only the z-component of the magnetic moment is constrained:
51
+
52
+
```
53
+
ATOMIC_POSITIONS
54
+
Direct
55
+
56
+
Fe
57
+
0.0
58
+
2
59
+
0.00 0.00 0.00 mag 2.0 sc 1
60
+
0.51 0.51 0.51 mag -2.0 sc 1
61
+
```
62
+
63
+
-`mag 2.0`: target magnetic moment of 2.0 $\mu_B$ along z-axis
|`decay_grad_switch`| Boolean | False | Enable gradient-based early exit |
132
+
133
+
For full parameter details, see the [Spin-Constrained DFT](../input_files/input-main.md#spin-constrained-dft) section of the input keyword list.
134
+
135
+
### Lambda Update Strategies
136
+
137
+
The `sc_lambda_strategy` parameter controls how the Lagrange multipliers $\lambda$ are updated during the lambda loop:
138
+
139
+
-**`bfgs`** (default): BFGS quasi-Newton method with line search. Robust and well-tested for both PW and LCAO. Uses `alpha_trial` and `sccut` to control step size.
140
+
141
+
-**`linear_response`**: Linear response method (Scheme B). Estimates the magnetic susceptibility $\chi$ from the history of $(\lambda, M)$ pairs and performs a one-step Newton-like update: $\Delta\lambda = \beta (M_{\text{target}} - M) / \chi$, where $\beta$ is a mixing parameter.
142
+
143
+
-**`augmented_lagrangian`**: Augmented Lagrangian method (Scheme C). Uses a penalty parameter $\mu$ that grows over iterations: $\lambda_{\text{new}} = \lambda + \mu (M - M_{\text{target}})$. The penalty increases until convergence is achieved.
144
+
145
+
-**`hybrid_delayed`**: Hybrid delayed update (Scheme D). Two-phase approach: in the early phase (SCF not yet converged), lambda updates are gentle; in the late phase (SCF nearly converged), augmented Lagrangian updates are applied.
146
+
147
+
### Direction-Only Mode
148
+
149
+
When `sc_direction_only 1` is set, only the **direction** of the magnetic moment is constrained to match the target, while the magnitude is allowed to vary freely. This is useful for:
150
+
151
+
- Studying magnetic anisotropy energy surfaces
152
+
- Cases where the moment magnitude is determined by the electronic structure
153
+
- Converging to the easy-axis direction without fixing the moment size
154
+
155
+
In this mode, the lambda vector is projected to be perpendicular to the target moment direction at each iteration, ensuring it can only rotate the magnetization, not stretch it.
156
+
157
+
### Combining DeltaSpin with DFT+U
158
+
159
+
DeltaSpin can be combined with DFT+U for strongly correlated systems. When both `sc_mag_switch` and `dft_plus_u` are enabled:
160
+
161
+
1. DFT+U occupation update runs first in each SCF iteration
162
+
2. DeltaSpin lambda loop runs after, constraining the magnetic moments
163
+
3. The DFT+U-corrected Hamiltonian is used by the lambda loop
164
+
165
+
Example INPUT for PW DFT+U + DeltaSpin:
166
+
167
+
```
168
+
INPUT_PARAMETERS
169
+
calculation scf
170
+
basis_type pw
171
+
ecutwfc 50
172
+
nspin 2
173
+
dft_plus_u 1
174
+
orbital_corr -1 2
175
+
hubbard_u 0.0 4.0
176
+
sc_mag_switch 1
177
+
sc_thr 1.0e-6
178
+
sc_scf_thr 1.0e-4
179
+
sc_lambda_strategy bfgs
180
+
```
181
+
182
+
### Example: Collinear antiferromagnetic Fe
183
+
184
+
INPUT file:
185
+
186
+
```
187
+
INPUT_PARAMETERS
188
+
calculation scf
189
+
basis_type pw
190
+
ecutwfc 50
191
+
nspin 2
192
+
sc_mag_switch 1
193
+
sc_thr 1.0e-6
194
+
```
195
+
196
+
STRU file:
197
+
198
+
```
199
+
ATOMIC_SPECIES
200
+
Fe 55.845 Fe.upf
201
+
202
+
LATTICE_CONSTANT
203
+
8.190
204
+
205
+
LATTICE_VECTORS
206
+
1.00 0.50 0.50
207
+
0.50 1.00 0.50
208
+
0.50 0.50 1.00
209
+
210
+
ATOMIC_POSITIONS
211
+
Direct
212
+
213
+
Fe
214
+
0.0
215
+
2
216
+
0.00 0.00 0.00 mag 2.0 sc 1
217
+
0.51 0.51 0.51 mag -2.0 sc 1
218
+
```
219
+
220
+
### Example: Non-collinear constrained moments
221
+
222
+
INPUT file:
223
+
224
+
```
225
+
INPUT_PARAMETERS
226
+
calculation scf
227
+
basis_type pw
228
+
ecutwfc 50
229
+
nspin 4
230
+
noncolin 1
231
+
sc_mag_switch 1
232
+
sc_direction_only 1
233
+
sc_lambda_strategy bfgs
234
+
```
235
+
236
+
STRU file:
237
+
238
+
```
239
+
ATOMIC_POSITIONS
240
+
Direct
241
+
242
+
Fe
243
+
0.0
244
+
2
245
+
0.00 0.00 0.00 mag 2.0 0.0 0.0 sc 1 1 0
246
+
0.51 0.51 0.51 mag 0.0 0.0 2.0 sc 1 1 0
247
+
```
248
+
31
249
## Noncollinear Spin Polarized Calculations
32
250
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
251
In this case, nspin is automatically set to 4, which is usually not required to be specified manually.
@@ -48,6 +266,53 @@ Note: different settings for "noncolin" and "lspinorb" correspond to different c
48
266
49
267
**Special case**: `noncolin=0, lspinorb=1` is commonly used for non-magnetic materials with SOC effects (e.g., topological insulators, semiconductors with spin-orbit splitting). In this case, the magnetization is NOT automatically set, implying no magnetic moments in the system.
50
268
269
+
### Choosing gga_grad for Noncollinear Calculations
270
+
271
+
When performing noncollinear spin calculations (`nspin=4`), the `gga_grad` parameter controls how the gradient of the magnetization is computed in GGA exchange-correlation functionals. This is critical for obtaining correct magnetic anisotropy energies and spin-orbit coupling effects.
272
+
273
+
#### Available Options
274
+
275
+
| gga_grad | Gradient Method | Description | When to Use |
| 0 | Standard | Conventional GGA gradient (collinear approximation) | Collinear calculations only (`nspin<4`) |
278
+
| 1 | $\nabla\|\mathbf{m}\|$ | Gradient of magnetization magnitude | Noncollinear with SOC, when only magnitude variation matters |
279
+
| 2 | $\nabla\hat{\mathbf{m}}$ | Gradient of magnetization direction (default for `nspin=4`) |**Recommended** for most noncollinear calculations with SOC |
280
+
| 3 | Built-in SF | Special functional for noncollinear SOC (requires `v_xc_ncgga_sf_builtin`) | Advanced noncollinear SOC calculations |
281
+
282
+
#### Recommendations
283
+
284
+
**For noncollinear calculations with SOC (`lspinorb=1`)**:
285
+
-**Use `gga_grad=2`** (default when `nspin=4`): This computes the gradient of the magnetization direction unit vector $\hat{\mathbf{m}}$, which is physically correct for spin-orbit coupling effects.
286
+
- This is automatically set when you specify `nspin=4` or `lspinorb=1`, but you can explicitly set it to be clear.
287
+
288
+
**For noncollinear calculations without SOC (`noncolin=1`, `lspinorb=0`)**:
289
+
-**Use `gga_grad=2`** for spin spiral calculations or frustrated magnetic systems
290
+
- The gradient of the magnetization direction is still important even without SOC
291
+
292
+
**For collinear calculations (`nspin=1` or `nspin=2`)**:
293
+
-**Use `gga_grad=0`** (default): Standard collinear GGA gradient
294
+
- Do NOT use `gga_grad=1`, `2`, or `3` for collinear calculations
295
+
296
+
#### Example INPUT for Noncollinear SOC
297
+
298
+
```
299
+
INPUT_PARAMETERS
300
+
calculation scf
301
+
basis_type pw
302
+
ecutwfc 50
303
+
nspin 4
304
+
noncolin 1
305
+
lspinorb 1
306
+
gga_grad 2
307
+
```
308
+
309
+
#### Important Notes
310
+
311
+
1.**Automatic setting**: When `nspin=4`, ABACUS automatically sets `gga_grad=2` if not explicitly specified
312
+
2.**Physical correctness**: Using the wrong `gga_grad` value can lead to incorrect magnetic anisotropy energies and spin textures
313
+
3.**Compatibility**: `gga_grad=3` requires the built-in special functional and may not be available for all XC functionals
314
+
4.**Performance**: `gga_grad=2` has similar computational cost to `gga_grad=0` for most systems
315
+
51
316
## For the continuation job
52
317
- Continuation job for "nspin 1" need file "SPIN1_CHG.cube" which is generated by setting "out_chg=1" in task before. By setting "init_chg file" in new job's INPUT file, charge density will start from file but not atomic.
53
318
- Continuation job for "nspin 2" need files "SPIN1_CHG.cube" and "SPIN2_CHG.cube" which are generated by "out_chg 1" with "nspin 2", and refer to spin-up and spin-down charge densities respectively. It should be note that reading "SPIN1_CHG.cube" only for the continuation target magnetic moment job is not supported now.
0 commit comments