From 9eb72275e64cde164fb3c8db9c52462ffa917d42 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 26 Oct 2024 06:25:02 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/abacus/scf.py | 2 +- dpdata/vasp/poscar.py | 5 +---- tests/test_abacus_stru_dump.py | 16 ++++++++-------- tests/test_vasp_poscar_dump.py | 4 ++-- tests/test_vasp_poscar_to_system.py | 2 +- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/dpdata/abacus/scf.py b/dpdata/abacus/scf.py index d2e4cf36..60ea7a24 100644 --- a/dpdata/abacus/scf.py +++ b/dpdata/abacus/scf.py @@ -669,7 +669,7 @@ def ndarray2list(i): if mag is None and data.get("spins") is not None and len(data["spins"]) > 0: mag = data["spins"][frame_idx] - + if move is None and data.get("move", None) is not None and len(data["move"]) > 0: move = data["move"] diff --git a/dpdata/vasp/poscar.py b/dpdata/vasp/poscar.py index 7ece2535..5b73b71b 100644 --- a/dpdata/vasp/poscar.py +++ b/dpdata/vasp/poscar.py @@ -113,10 +113,7 @@ 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 len(move) > 0: move_flags = move[idx] - if ( - isinstance(move_flags, list) - and len(move_flags) == 3 - ): + if isinstance(move_flags, list) and len(move_flags) == 3: line += " " + " ".join(["T" if flag else "F" for flag in move_flags]) elif isinstance(move_flags, (int, float, bool)): line += " " + " ".join(["T" if move_flags else "F"] * 3) diff --git a/tests/test_abacus_stru_dump.py b/tests/test_abacus_stru_dump.py index c3940e9c..2b0859fe 100644 --- a/tests/test_abacus_stru_dump.py +++ b/tests/test_abacus_stru_dump.py @@ -102,7 +102,7 @@ def test_dump_spin(self): 5.499851012568 4.003388899277 5.342621842622 0 0 0 mag 3.000000000000 3.000000000000 3.000000000000 """ self.assertTrue(stru_ref in c) - + def test_dump_move_from_vasp(self): self.system = dpdata.System() self.system.from_vasp_poscar(os.path.join("poscars", "POSCAR.oh.c")) @@ -110,7 +110,7 @@ def test_dump_move_from_vasp(self): assert os.path.isfile("STRU_tmp") with open("STRU_tmp") as f: c = f.read() - + stru_ref = """O 0.0 1 @@ -121,12 +121,14 @@ def test_dump_move_from_vasp(self): 1.262185604418 0.701802783513 0.551388341420 0 0 0 """ self.assertTrue(stru_ref in c) - - self.system.to("abacus/stru", "STRU_tmp", move=[[True, False, True], [False, True, False]]) + + self.system.to( + "abacus/stru", "STRU_tmp", move=[[True, False, True], [False, True, False]] + ) assert os.path.isfile("STRU_tmp") with open("STRU_tmp") as f: c = f.read() - + stru_ref = """O 0.0 1 @@ -137,9 +139,7 @@ def test_dump_move_from_vasp(self): 1.262185604418 0.701802783513 0.551388341420 0 1 0 """ self.assertTrue(stru_ref in c) - - - + class TestABACUSParseStru(unittest.TestCase): def test_parse_stru_post(self): diff --git a/tests/test_vasp_poscar_dump.py b/tests/test_vasp_poscar_dump.py index c04023fd..d5522811 100644 --- a/tests/test_vasp_poscar_dump.py +++ b/tests/test_vasp_poscar_dump.py @@ -40,10 +40,10 @@ def test_dump_move_flags(self): tmp_system.to_vasp_poscar("tmp.POSCAR") self.system = dpdata.System() self.system.from_vasp_poscar("tmp.POSCAR") - with open("tmp.POSCAR", "r") as f: + with open("tmp.POSCAR") as f: content = f.read() - stru_ref = f"""Cartesian + stru_ref = """Cartesian 0.0000000000 0.0000000000 0.0000000000 T T F 1.2621856044 0.7018027835 0.5513883414 F F F """ diff --git a/tests/test_vasp_poscar_to_system.py b/tests/test_vasp_poscar_to_system.py index 3e43afdf..745c0bb7 100644 --- a/tests/test_vasp_poscar_to_system.py +++ b/tests/test_vasp_poscar_to_system.py @@ -13,7 +13,7 @@ class TestPOSCARCart(unittest.TestCase, TestPOSCARoh): def setUp(self): self.system = dpdata.System() self.system.from_vasp_poscar(os.path.join("poscars", "POSCAR.oh.c")) - + def test_move_flags(self): expected = np.array([[True, True, False], [False, False, False]]) self.assertTrue(np.array_equal(self.system["move"], expected))