Skip to content

Commit 98f4541

Browse files
refactor(abacus): link the pp/orb files defined in STRU not jdata (#1127)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 418e0ce commit 98f4541

File tree

3 files changed

+54
-33
lines changed

3 files changed

+54
-33
lines changed

dpgen/generator/lib/abacus_scf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ def get_additional_from_STRU(geometry_inlines, nele):
342342
if orb_file_kw == geometry_inlines[iline].split()[0]:
343343
orb_file = []
344344
for iele in range(nele):
345-
orb_file.append(geometry_inlines[iline + iele + 1].rstrip())
345+
orb_file.append(geometry_inlines[iline + iele + 1].strip())
346346
if dpks_descriptor_kw == geometry_inlines[iline].split()[0]:
347-
dpks_descriptor = geometry_inlines[iline + 1].rstrip()
347+
dpks_descriptor = geometry_inlines[iline + 1].strip()
348348
return orb_file, dpks_descriptor
349349

350350

dpgen/generator/run.py

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
make_abacus_scf_input,
6969
make_abacus_scf_kpt,
7070
)
71-
from dpgen.generator.lib.abacus_scf import get_abacus_input_parameters
71+
from dpgen.generator.lib.abacus_scf import get_abacus_input_parameters, get_abacus_STRU
7272

7373
# from dpgen.generator.lib.pwscf import cvt_1frame
7474
from dpgen.generator.lib.pwmat import make_pwmat_input_dict
@@ -3000,41 +3000,65 @@ def sys_link_fp_vasp_pp(iter_index, jdata):
30003000
os.chdir(cwd)
30013001

30023002

3003-
def _link_fp_abacus_orb_descript(iter_index, jdata):
3004-
# assume lcao orbital files, numerical descrptors and model for dpks are all in fp_pp_path.
3005-
fp_pp_path = jdata["fp_pp_path"]
3006-
3007-
fp_orb_files = jdata["fp_orb_files"]
3008-
assert os.path.exists(fp_pp_path)
3009-
fp_dpks_descriptor = None
3010-
fp_dpks_model = None
3011-
if "fp_dpks_descriptor" in jdata:
3012-
fp_dpks_descriptor = jdata["fp_dpks_descriptor"]
3013-
if "user_fp_params" in jdata:
3014-
if "deepks_model" in jdata["user_fp_params"]:
3015-
fp_dpks_model = jdata["user_fp_params"]["deepks_model"]
3016-
3017-
fp_pp_path = os.path.abspath(fp_pp_path)
3003+
def _link_fp_abacus_pporb_descript(iter_index, jdata):
3004+
# assume pp orbital files, numerical descrptors and model for dpks are all in fp_pp_path.
3005+
fp_pp_path = os.path.abspath(jdata["fp_pp_path"])
30183006

30193007
iter_name = make_iter_name(iter_index)
30203008
work_path = os.path.join(iter_name, fp_name)
3021-
30223009
fp_tasks = glob.glob(os.path.join(work_path, "task.*"))
30233010
fp_tasks.sort()
30243011
if len(fp_tasks) == 0:
30253012
return
3013+
30263014
cwd = os.getcwd()
30273015
for ii in fp_tasks:
30283016
os.chdir(ii)
3029-
for jj in fp_orb_files:
3030-
orb_file = os.path.join(fp_pp_path, jj)
3031-
os.symlink(orb_file, jj)
3032-
if fp_dpks_descriptor is not None:
3033-
descrptor = os.path.join(fp_pp_path, fp_dpks_descriptor)
3034-
os.symlink(descrptor, fp_dpks_descriptor)
3035-
if fp_dpks_model is not None:
3036-
dpks_model = os.path.join(fp_pp_path, fp_dpks_model)
3037-
os.symlink(dpks_model, fp_dpks_model)
3017+
3018+
# get value of 'deepks_model' from INPUT
3019+
input_param = get_abacus_input_parameters("INPUT")
3020+
fp_dpks_model = input_param.get("deepks_model", None)
3021+
if fp_dpks_model != None:
3022+
model_file = os.path.join(fp_pp_path, fp_dpks_model)
3023+
assert os.path.isfile(model_file), (
3024+
"Can not find the deepks model file %s, which is defined in %s/INPUT"
3025+
% (model_file, ii)
3026+
)
3027+
os.symlink(model_file, fp_dpks_model)
3028+
3029+
# get pp, orb, descriptor filenames from STRU
3030+
stru_param = get_abacus_STRU("STRU")
3031+
pp_files = stru_param.get("pp_files", [])
3032+
orb_files = stru_param.get("orb_files", [])
3033+
descriptor_file = stru_param.get("dpks_descriptor", None)
3034+
pp_files = [] if pp_files == None else pp_files
3035+
orb_files = [] if orb_files == None else orb_files
3036+
3037+
for jj in pp_files:
3038+
ifile = os.path.join(fp_pp_path, jj)
3039+
assert os.path.isfile(ifile), (
3040+
"Can not find the pseudopotential file %s, which is defined in %s/STRU"
3041+
% (ifile, ii)
3042+
)
3043+
os.symlink(ifile, jj)
3044+
3045+
for jj in orb_files:
3046+
ifile = os.path.join(fp_pp_path, jj)
3047+
assert os.path.isfile(
3048+
ifile
3049+
), "Can not find the orbital file %s, which is defined in %s/STRU" % (
3050+
ifile,
3051+
ii,
3052+
)
3053+
os.symlink(ifile, jj)
3054+
3055+
if descriptor_file != None:
3056+
ifile = os.path.join(fp_pp_path, descriptor_file)
3057+
assert os.path.isfile(ifile), (
3058+
"Can not find the deepks descriptor file %s, which is defined in %s/STRU"
3059+
% (ifile, ii)
3060+
)
3061+
os.symlink(ifile, descriptor_file)
30383062
os.chdir(cwd)
30393063

30403064

@@ -3248,11 +3272,8 @@ def make_fp_abacus_scf(iter_index, jdata):
32483272
fp.write(ret_stru)
32493273

32503274
os.chdir(cwd)
3251-
# link pp files
3252-
_link_fp_vasp_pp(iter_index, jdata)
3253-
if "basis_type" in fp_params:
3254-
if fp_params["basis_type"] == "lcao":
3255-
_link_fp_abacus_orb_descript(iter_index, jdata)
3275+
# link pp and orbital files
3276+
_link_fp_abacus_pporb_descript(iter_index, jdata)
32563277

32573278

32583279
def make_fp_siesta(iter_index, jdata):

tests/generator/model.ptg

Whitespace-only changes.

0 commit comments

Comments
 (0)