Skip to content

Commit 5f92f5e

Browse files
committed
fix: preserve surface POSCAR input paths
Fixes #1912 Coding-Agent: Codex Codex-Version: codex-cli 0.149.0 Model: gpt-5.6-sol Reasoning-Effort: xhigh
1 parent d5ce577 commit 5f92f5e

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

dpgen/data/surf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ def make_super_cell_pymatgen(jdata):
229229

230230
if from_poscar:
231231
from_poscar_path = jdata["from_poscar_path"]
232-
poscar_name = os.path.basename(from_poscar_path)
233-
ss = Structure.from_file(poscar_name)
232+
ss = Structure.from_file(from_poscar_path)
234233
else:
235234
from_path = path_uc
236235
from_file = os.path.join(from_path, "POSCAR.unit")

tests/data/test_gen_surf_poscar.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import shutil
55
import sys
6+
import tempfile
67
import unittest
78

89
from pymatgen.core import Element, Structure
@@ -34,6 +35,10 @@ def setUp(self):
3435
]
3536
with open(param_file) as fp:
3637
jdata = json.load(fp)
38+
self.input_dir = tempfile.mkdtemp()
39+
from_poscar_path = os.path.join(self.input_dir, "nested.POSCAR")
40+
shutil.copy2("POSCAR", from_poscar_path)
41+
jdata["from_poscar_path"] = from_poscar_path
3742
out_dir = out_dir_name(jdata)
3843
jdata["out_dir"] = out_dir
3944
self.root_dir = out_dir
@@ -47,13 +52,16 @@ def setUp(self):
4752

4853
def tearDown(self):
4954
shutil.rmtree(self.root_dir)
55+
shutil.rmtree(self.input_dir)
5056

5157
def test(self):
52-
surfs = glob.glob("POSCAR.01x01x01/01.scale_pert/surf*")
58+
surfs = glob.glob(os.path.join(self.root_dir, "01.scale_pert", "surf*"))
5359
surfs = [ii.split("/")[-1] for ii in surfs]
5460
surfs.sort()
5561
self.assertEqual(surfs, self.surfs)
56-
poscars = glob.glob("POSCAR.01x01x01/00.place_ele/surf*/sys*/POSCAR")
62+
poscars = glob.glob(
63+
os.path.join(self.root_dir, "00.place_ele", "surf*", "sys*", "POSCAR")
64+
)
5765
for poscar in poscars:
5866
surf = poscar.split("/")[-3]
5967
st1 = Structure.from_file(surf + ".POSCAR")
@@ -63,7 +71,14 @@ def test(self):
6371

6472
for surf in self.surfs:
6573
elongs = glob.glob(
66-
"POSCAR.01x01x01/01.scale_pert/" + surf + "/sys-*/scale-1.000/el*"
74+
os.path.join(
75+
self.root_dir,
76+
"01.scale_pert",
77+
surf,
78+
"sys-*",
79+
"scale-1.000",
80+
"el*",
81+
)
6782
)
6883
elongs = [ii.split("/")[-1] for ii in elongs]
6984
elongs.sort()

0 commit comments

Comments
 (0)