Skip to content

Commit

Permalink
opt code
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-Jia committed Oct 28, 2024
1 parent e0eeb35 commit d0a85d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions dpdata/vasp/poscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ def from_system_data(system, f_idx=0, skip_zeros=True):
line = f"{ii_posi[0]:15.10f} {ii_posi[1]:15.10f} {ii_posi[2]:15.10f}"
if move is not None and len(move) > 0:
move_flags = move[idx]
if isinstance(move_flags, list) and len(move_flags) == 3:
line += " " + " ".join(["T" if flag else "F" for flag in move_flags])
else:
if not isinstance(move_flags, list) or len(move_flags) != 3:
raise RuntimeError(
f"Invalid move flags: {move_flags}, should be a list of 3 bools"
)
line += " " + " ".join("T" if flag else "F" for flag in move_flags)

posi_list.append(line)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_vasp_poscar_to_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_move_flags(self):
self.assertTrue(np.array_equal(self.system["move"], expected))


class TestPOSCARCart(unittest.TestCase):
class TestPOSCARMoveFlags(unittest.TestCase):
def test_move_flags_error1(self):
with self.assertRaisesRegex(RuntimeError, "Invalid move flags.*?"):
dpdata.System().from_vasp_poscar(os.path.join("poscars", "POSCAR.oh.err1"))
Expand Down

0 comments on commit d0a85d4

Please sign in to comment.