Skip to content

Commit cd81c72

Browse files
authored
ABACUS: rotate to fit right hand rule when reading STRU (#841)
1 parent 5b53f84 commit cd81c72

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

dpdata/abacus/stru.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,25 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
422422
return atom_numbs, coords, move, mags, velocity, sc, lambda_
423423

424424

425+
def right_hand_rule(
426+
cell: np.ndarray, coord: np.ndarray
427+
) -> tuple[np.ndarray, np.ndarray]:
428+
"""Rotate the cell and coord to make the cell fit the right-hand rule.
429+
430+
Args:
431+
cell (np.ndarray): the cell vectors.
432+
coord (np.ndarray): the atomic coordinates in cartesian.
433+
434+
Returns
435+
-------
436+
tuple: the rotated cell and coord.
437+
"""
438+
if np.linalg.det(cell) < 0:
439+
cell = -cell
440+
coord = -coord
441+
return cell, coord
442+
443+
425444
def get_frame_from_stru(stru):
426445
"""Read the ABACUS STRU file and return the dpdata frame.
427446
@@ -473,6 +492,7 @@ def get_frame_from_stru(stru):
473492
blocks["ATOMIC_POSITIONS"], atom_names, celldm, cell
474493
)
475494

495+
cell, coords = right_hand_rule(cell, coords)
476496
data = {
477497
"atom_names": atom_names,
478498
"atom_numbs": atom_numbs,

0 commit comments

Comments
 (0)