Skip to content

Commit 08aefba

Browse files
authored
merge devel to master to release v0.2.24 (#808)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Updated developer tooling configurations to use a newer linting hook version. - **Refactor** - Streamlined structure processing so that magnetic data is included only when defined, resulting in cleaner output. - Optimized coordinate adjustments with vectorized operations for improved performance. - **Tests** - Cleaned up test data by removing redundant magnetic moment fields from atomic position entries. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 35a0af0 + a96b305 commit 08aefba

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
# Python
2222
- repo: https://github.com/astral-sh/ruff-pre-commit
2323
# Ruff version.
24-
rev: v0.9.6
24+
rev: v0.11.0
2525
hooks:
2626
- id: ruff
2727
args: ["--fix"]

dpdata/abacus/stru.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
362362

363363
ntype = len(atom_names)
364364
line_idx = 1 # starting line of first element
365+
define_atom_mag = False
365366
for it in range(ntype):
366367
atom_name = coords_lines[line_idx].split()[0]
367368
if atom_name != atom_names[it]:
@@ -390,6 +391,9 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
390391
mag = [0, 0, atom_type_mag]
391392
mags.append(mag)
392393

394+
if imagmom is not None:
395+
define_atom_mag = True
396+
393397
line_idx += 1
394398
coords = np.array(coords) # need transformation!!!
395399

@@ -409,7 +413,11 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
409413
if all([i is None for i in lambda_]):
410414
lambda_ = []
411415

412-
mags = np.array(mags)
416+
# here return the magnetic moment only when the atom magnetic moment is specified.
417+
if not define_atom_mag:
418+
mags = []
419+
else:
420+
mags = np.array(mags)
413421

414422
return atom_numbs, coords, move, mags, velocity, sc, lambda_
415423

@@ -438,10 +446,13 @@ def get_frame_from_stru(stru):
438446
439447
"cells": list of cell vectors,
440448
"coords": list of atomic coordinates,
441-
"spins": list of magnetic moments,
449+
"spins": list of magnetic moments, # return only when set "mag xxx" for each atom in STRU file
442450
"moves": list of move flags,
443451
}
444452
For some keys, if the information is not provided in the STRU file, then it will not be included in the dictionary.
453+
"spins" is designed for delta spin calculation, and when dpdata.System is write to lmp format, the spin will be written as magmom.
454+
But we should note that this file format is valid only for a spin lammps job, not for a normal job.
455+
If you want to use dpgen to run the non-spin job, then you should not define "mag x x x" in the STRU file.
445456
"""
446457
if not os.path.isfile(stru):
447458
raise FileNotFoundError(f"ABACUS STRU file {stru} not found!!!")
@@ -472,8 +483,9 @@ def get_frame_from_stru(stru):
472483
"pp_files": pp_files,
473484
"cells": np.array([cell]),
474485
"coords": np.array([coords]),
475-
"spins": np.array([mags]),
476486
}
487+
if len(mags) > 0:
488+
data["spins"] = np.array([mags])
477489
if len(orb_files) > 0:
478490
data["orb_files"] = orb_files
479491
if len(dpks_descriptor) > 0:

dpdata/system.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,7 @@ def affine_map(self, trans, f_idx: int | numbers.Integral = 0):
710710

711711
@post_funcs.register("shift_orig_zero")
712712
def _shift_orig_zero(self):
713-
for ff in self.data["coords"]:
714-
for ii in ff:
715-
ii = ii - self.data["orig"]
713+
self.data["coords"] = self.data["coords"] - self.data["orig"]
716714
self.data["orig"] = self.data["orig"] - self.data["orig"]
717715
assert (np.zeros([3]) == self.data["orig"]).all()
718716

tests/abacus.scf/stru_test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Cartesian # Cartesian(Unit is LATTICE_CONSTANT)
2222
C
2323
0.0
2424
1
25-
5.192682633809 4.557725978258 4.436846615358 1 1 1 mag 0.000000000000 0.000000000000 0.000000000000
25+
5.192682633809 4.557725978258 4.436846615358 1 1 1
2626
H
2727
0.0
2828
4
29-
5.416431453540 4.011298860305 3.511161492417 0 0 0 mag 0.000000000000 0.000000000000 0.000000000000
30-
4.131588222365 4.706745191323 4.431136645083 1 0 1 mag 0.000000000000 0.000000000000 0.000000000000
31-
5.630930319126 5.521640894956 4.450356541303 1 0 1 mag 0.000000000000 0.000000000000 0.000000000000
32-
5.499851012568 4.003388899277 5.342621842622 0 1 1 mag 0.000000000000 0.000000000000 0.000000000000
29+
5.416431453540 4.011298860305 3.511161492417 0 0 0
30+
4.131588222365 4.706745191323 4.431136645083 1 0 1
31+
5.630930319126 5.521640894956 4.450356541303 1 0 1
32+
5.499851012568 4.003388899277 5.342621842622 0 1 1

0 commit comments

Comments
 (0)