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
9 changes: 8 additions & 1 deletion dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3710,6 +3710,10 @@ def make_fp_siesta(iter_index, jdata):
iter_name = make_iter_name(iter_index)
work_path = os.path.join(iter_name, fp_name)
fp_pp_files = jdata["fp_pp_files"]
type_map = jdata["type_map"]
if len(type_map) != len(fp_pp_files):
raise RuntimeError("fp_pp_files must correspond one-to-one with type_map")
pp_by_element = dict(zip(type_map, fp_pp_files))
if "user_fp_params" in jdata.keys():
fp_params = jdata["user_fp_params"]
user_input = True
Expand All @@ -3720,7 +3724,10 @@ def make_fp_siesta(iter_index, jdata):
for ii in fp_tasks:
os.chdir(ii)
sys_data = dpdata.System("POSCAR").data
ret = make_siesta_input(sys_data, fp_pp_files, fp_params)
# A workflow may share a global type map while an individual system
# contains only a subset of those elements.
task_pp_files = [pp_by_element[name] for name in sys_data["atom_names"]]
ret = make_siesta_input(sys_data, task_pp_files, fp_params)
with open("input", "w") as fp:
fp.write(ret)
os.chdir(cwd)
Expand Down
36 changes: 36 additions & 0 deletions tests/generator/test_make_fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,42 @@ def test_make_fp_siesta(self):
_check_potcar(self, 0, jdata["fp_pp_path"], jdata["fp_pp_files"])
shutil.rmtree("iter.000000")

def test_make_fp_siesta_with_element_subset(self):
"""Each SIESTA input should select PPs for its present elements."""
setUpModule()
if os.path.isdir("iter.000000"):
shutil.rmtree("iter.000000")
with open(param_siesta_file) as fp:
jdata = json.load(fp)
md_descript = []
for _ in range(2):
system_deviations = []
for _ in range(3):
system_deviations.append(np.arange(0, 0.29, 0.29 / 10))
md_descript.append(system_deviations)

try:
_make_fake_md(0, md_descript, [0] * 6, jdata["type_map"])
make_fp(0, jdata, {})

tasks = glob.glob(os.path.join("iter.000000", "02.fp", "task.*"))
self.assertGreater(len(tasks), 0)
for task in tasks:
with open(os.path.join(task, "input")) as fp:
input_text = fp.read()
self.assertIn("NumberOfSpecies 1", input_text)
species_block = input_text.split(
"%block Chemical_Species_label\n", maxsplit=1
)[1].split("%endblock Chemical_Species_label", maxsplit=1)[0]
species_lines = [
line for line in species_block.splitlines() if line.strip()
]
self.assertEqual(1, len(species_lines))
self.assertEqual("C", species_lines[0].split()[-1])
finally:
if os.path.isdir("iter.000000"):
shutil.rmtree("iter.000000")


class TestMakeFPVasp(unittest.TestCase):
def test_make_fp_vasp(self):
Expand Down