Skip to content

abacus: fix bug of finding the final relax STRU #1344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 31, 2023
Merged
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
31 changes: 16 additions & 15 deletions dpgen/auto_test/lib/abacus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python3
import glob
import os

import dpdata
Expand Down Expand Up @@ -309,23 +310,23 @@ def final_stru(abacus_path):
out_stru = bool(line.split()[1])
logf = os.path.join(abacus_path, f"OUT.{suffix}/running_{calculation}.log")
if calculation in ["relax", "cell-relax"]:
if not out_stru:
if os.path.isfile(os.path.join(abacus_path, "OUT.%s/STRU_ION_D" % suffix)):
return "OUT.%s/STRU_ION_D" % suffix
else:
with open(logf) as f1:
lines = f1.readlines()
for i in range(1, len(lines)):
max_step = ""
if "ALGORITHM --------------- ION=" in lines[-i]:
index_ben = lines[-i].index("ION=") + 4
index_end = lines[-i].index("ELEC")
max_step = int(lines[-i][index_ben:index_end])
if max_step < 2:
max_step = ""
else:
max_step -= 2
break
return f"OUT.{suffix}/STRU_ION{str(max_step)}_D"
# find the final name by STRU_ION*_D,
# for abacus version < v3.2.2, there has no STRU_ION_D file but has STRU_ION0_D STRU_ION1_D ... STRU_ION10_D ...
# so we need to find the last STRU_ION*_D file
stru_ions = glob.glob(
os.path.join(abacus_path, f"OUT.{suffix}/STRU_ION*_D")
)
if len(stru_ions) > 0:
# sort the file name by the number in the file name
stru_ions.sort(key=lambda x: int(x.split("_")[-2][3:]))
final_stru_ion = os.path.basename(stru_ions[-1])
return f"OUT.{suffix}/{final_stru_ion}"
else:
# if there has no STRU_ION_D, return the input STRU
return "STRU"
elif calculation == "md":
with open(logf) as f1:
lines = f1.readlines()
Expand Down
9 changes: 6 additions & 3 deletions dpgen/data/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,16 @@ def make_scale_ABACUS(jdata):
assert os.path.isfile(pos_src)
else:
try:
pos_src = os.path.join(
os.path.join(init_path, ii), "OUT.ABACUS/STRU_ION_D"
from dpgen.auto_test.lib.abacus import (
final_stru as abacus_final_stru,
)

pos_src = abacus_final_stru(os.path.join(init_path, ii))
pos_src = os.path.join(init_path, ii, pos_src)
assert os.path.isfile(pos_src)
except Exception:
raise RuntimeError(
"not file %s, vasp relaxation should be run before scale poscar"
"Can not find STRU_ION_D in OUT.ABACUS!!!\nABACUS relaxation should be run before scale poscar"
)
scale_path = os.path.join(work_path, ii)
scale_path = os.path.join(scale_path, "scale-%.3f" % jj)
Expand Down
1 change: 1 addition & 0 deletions tests/auto_test/test_abacus_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def test_make_property_elastic(self):
os.remove(
os.path.realpath(os.path.join(self.equi_path, "OUT.ABACUS", "STRU_ION_D"))
)
os.remove(os.path.realpath(os.path.join(self.equi_path, "STRU")))
with self.assertRaises(RuntimeError):
elastic.make_confs(work_path, self.equi_path, refine=False)

Expand Down