Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dpgen/data/surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ def make_super_cell_pymatgen(jdata):

if from_poscar:
from_poscar_path = jdata["from_poscar_path"]
poscar_name = os.path.basename(from_poscar_path)
ss = Structure.from_file(poscar_name)
ss = Structure.from_file(from_poscar_path)
else:
from_path = path_uc
from_file = os.path.join(from_path, "POSCAR.unit")
Expand Down
21 changes: 18 additions & 3 deletions tests/data/test_gen_surf_poscar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import shutil
import sys
import tempfile
import unittest

from pymatgen.core import Element, Structure
Expand Down Expand Up @@ -34,6 +35,10 @@ def setUp(self):
]
with open(param_file) as fp:
jdata = json.load(fp)
self.input_dir = tempfile.mkdtemp()
from_poscar_path = os.path.join(self.input_dir, "nested.POSCAR")
shutil.copy2("POSCAR", from_poscar_path)
jdata["from_poscar_path"] = from_poscar_path
out_dir = out_dir_name(jdata)
jdata["out_dir"] = out_dir
self.root_dir = out_dir
Expand All @@ -47,13 +52,16 @@ def setUp(self):

def tearDown(self):
shutil.rmtree(self.root_dir)
shutil.rmtree(self.input_dir)

def test(self):
surfs = glob.glob("POSCAR.01x01x01/01.scale_pert/surf*")
surfs = glob.glob(os.path.join(self.root_dir, "01.scale_pert", "surf*"))
surfs = [ii.split("/")[-1] for ii in surfs]
surfs.sort()
self.assertEqual(surfs, self.surfs)
poscars = glob.glob("POSCAR.01x01x01/00.place_ele/surf*/sys*/POSCAR")
poscars = glob.glob(
os.path.join(self.root_dir, "00.place_ele", "surf*", "sys*", "POSCAR")
)
for poscar in poscars:
surf = poscar.split("/")[-3]
st1 = Structure.from_file(surf + ".POSCAR")
Expand All @@ -63,7 +71,14 @@ def test(self):

for surf in self.surfs:
elongs = glob.glob(
"POSCAR.01x01x01/01.scale_pert/" + surf + "/sys-*/scale-1.000/el*"
os.path.join(
self.root_dir,
"01.scale_pert",
surf,
"sys-*",
"scale-1.000",
"el*",
)
)
elongs = [ii.split("/")[-1] for ii in elongs]
elongs.sort()
Expand Down