Skip to content

Commit 5cb41f8

Browse files
abacus: fix bug in reading nspin2 results (#758)
fix #757 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced handling of magnetic moments and forces to ensure consistent three-dimensional vector representation. - Updated input parameters for calculation configuration to reflect changes in naming conventions and spin configurations. - **Tests** - Introduced a new test method to validate behavior with the updated input file, improving test coverage and ensuring accuracy in results. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: root <pxlxingliang> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 5916b4f commit 5cb41f8

File tree

4 files changed

+610
-4
lines changed

4 files changed

+610
-4
lines changed

dpdata/abacus/scf.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,20 @@ def get_mag_force(outlines):
478478
j = i + 2
479479
mag = []
480480
while "-------------------------" not in outlines[j]:
481-
mag.append([float(ii) for ii in outlines[j].split()[1:]])
481+
imag = [float(ii) for ii in outlines[j].split()[1:]]
482+
if len(imag) == 1:
483+
imag = [0, 0, imag[0]]
484+
mag.append(imag)
482485
j += 1
483486
mags.append(mag)
484487
if "Magnetic force (eV/uB)" in line:
485488
j = i + 2
486489
magforce = []
487490
while "-------------------------" not in outlines[j]:
488-
magforce.append([float(ii) for ii in outlines[j].split()[1:]])
491+
imagforce = [float(ii) for ii in outlines[j].split()[1:]]
492+
if len(imagforce) == 1:
493+
imagforce = [0, 0, imagforce[0]]
494+
magforce.append(imagforce)
489495
j += 1
490496
magforces.append(magforce)
491497
return np.array(mags), np.array(magforces)

tests/abacus.spin/INPUT renamed to tests/abacus.spin/INPUT.scf.nspin2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
INPUT_PARAMETERS
2-
suffix ABACUS
2+
suffix ABACUS-nspin2
33
calculation scf
44
ecutwfc 100
55
scf_thr 1e-07
@@ -14,7 +14,7 @@ basis_type lcao
1414
symmetry 0
1515
noncolin 1
1616
lspinorb 0
17-
nspin 4
17+
nspin 2
1818
out_mul true
1919
sc_mag_switch 1
2020
decay_grad_switch 1

0 commit comments

Comments
 (0)