Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 26, 2024
1 parent e0e6ae2 commit 9eb7227
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dpdata/abacus/scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
5 changes: 1 addition & 4 deletions dpdata/vasp/poscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_abacus_stru_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ 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"))
self.system.to("abacus/stru", "STRU_tmp")
assert os.path.isfile("STRU_tmp")
with open("STRU_tmp") as f:
c = f.read()

stru_ref = """O
0.0
1
Expand All @@ -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
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_vasp_poscar_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
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 @@ -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))
Expand Down

0 comments on commit 9eb7227

Please sign in to comment.