|
1 | 1 | #!/usr/bin/python3 |
| 2 | +import glob |
2 | 3 | import os |
3 | 4 |
|
4 | 5 | import dpdata |
@@ -309,23 +310,23 @@ def final_stru(abacus_path): |
309 | 310 | out_stru = bool(line.split()[1]) |
310 | 311 | logf = os.path.join(abacus_path, f"OUT.{suffix}/running_{calculation}.log") |
311 | 312 | if calculation in ["relax", "cell-relax"]: |
312 | | - if not out_stru: |
| 313 | + if os.path.isfile(os.path.join(abacus_path, "OUT.%s/STRU_ION_D" % suffix)): |
313 | 314 | return "OUT.%s/STRU_ION_D" % suffix |
314 | 315 | else: |
315 | | - with open(logf) as f1: |
316 | | - lines = f1.readlines() |
317 | | - for i in range(1, len(lines)): |
318 | | - max_step = "" |
319 | | - if "ALGORITHM --------------- ION=" in lines[-i]: |
320 | | - index_ben = lines[-i].index("ION=") + 4 |
321 | | - index_end = lines[-i].index("ELEC") |
322 | | - max_step = int(lines[-i][index_ben:index_end]) |
323 | | - if max_step < 2: |
324 | | - max_step = "" |
325 | | - else: |
326 | | - max_step -= 2 |
327 | | - break |
328 | | - return f"OUT.{suffix}/STRU_ION{str(max_step)}_D" |
| 316 | + # find the final name by STRU_ION*_D, |
| 317 | + # for abacus version < v3.2.2, there has no STRU_ION_D file but has STRU_ION0_D STRU_ION1_D ... STRU_ION10_D ... |
| 318 | + # so we need to find the last STRU_ION*_D file |
| 319 | + stru_ions = glob.glob( |
| 320 | + os.path.join(abacus_path, f"OUT.{suffix}/STRU_ION*_D") |
| 321 | + ) |
| 322 | + if len(stru_ions) > 0: |
| 323 | + # sort the file name by the number in the file name |
| 324 | + stru_ions.sort(key=lambda x: int(x.split("_")[-2][3:])) |
| 325 | + final_stru_ion = os.path.basename(stru_ions[-1]) |
| 326 | + return f"OUT.{suffix}/{final_stru_ion}" |
| 327 | + else: |
| 328 | + # if there has no STRU_ION_D, return the input STRU |
| 329 | + return "STRU" |
329 | 330 | elif calculation == "md": |
330 | 331 | with open(logf) as f1: |
331 | 332 | lines = f1.readlines() |
|
0 commit comments