Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
thangckt committed May 27, 2024
1 parent 7315d77 commit be33545
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 7 additions & 0 deletions dpdata/plugins/ase.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from __future__ import annotations

from typing import TYPE_CHECKING, Generator
Expand Down Expand Up @@ -313,6 +314,9 @@ def to_system(self, data, file_name: str = "confs.traj", **kwargs) -> None:
file_name : str
path to file
"""
if os.path.isfile(file_name):
os.remove(file_name)

list_atoms = ASEStructureFormat().to_system(data, **kwargs)
traj = Trajectory(file_name, "a")
_ = [traj.write(atom) for atom in list_atoms]
Expand All @@ -329,6 +333,9 @@ def to_labeled_system(
file_name : str
path to file
"""
if os.path.isfile(file_name):
os.remove(file_name)

list_atoms = ASEStructureFormat().to_labeled_system(data, *args, **kwargs)
traj = Trajectory(file_name, "a")
_ = [traj.write(atom) for atom in list_atoms]
Expand Down
14 changes: 6 additions & 8 deletions tests/test_ase_traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ def setUp(self):
@unittest.skipIf(skip_ase, "skip ase related test. install ase to fix")
class TestASEtraj4(unittest.TestCase, CompSys, IsPBC):
def setUp(self):
system_1 = dpdata.System("ase_traj/MoS2", fmt="deepmd")
system_1.to(file_name="tmp.traj", fmt="ase/traj")
self.system_2 = dpdata.System("tmp.traj", fmt="ase/traj")
self.system_1 = system_1
self.system_1 = dpdata.System("ase_traj/MoS2", fmt="deepmd")
self.system_1.to(file_name="ase_traj/tmp.traj", fmt="ase/traj")
self.system_2 = dpdata.System("ase_traj/tmp.traj", fmt="ase/traj")
self.places = 6
self.e_places = 6
self.f_places = 6
Expand All @@ -83,10 +82,9 @@ def setUp(self):
@unittest.skipIf(skip_ase, "skip ase related test. install ase to fix")
class TestASEtraj4Labeled(unittest.TestCase, CompLabeledSys, IsPBC):
def setUp(self):
system_1 = dpdata.LabeledSystem("ase_traj/MoS2", fmt="deepmd")
system_1.to(file_name="tmp1.traj", fmt="ase/traj")
self.system_2 = dpdata.LabeledSystem("tmp1.traj", fmt="ase/traj")
self.system_1 = system_1
self.system_1 = dpdata.LabeledSystem("ase_traj/MoS2", fmt="deepmd")
self.system_1.to(file_name="ase_traj/tmp1.traj", fmt="ase/traj")
self.system_2 = dpdata.LabeledSystem("ase_traj/tmp1.traj", fmt="ase/traj")
self.places = 6
self.e_places = 6
self.f_places = 6
Expand Down

0 comments on commit be33545

Please sign in to comment.