Skip to content

Commit 25269cf

Browse files
Liu-RXLiuRenxiamcadmus
authored
Add ABACUS/lcao deepks interface to dpgen init and run. (#705)
* add abacus+lcao+dpks interface for dpgen init and run. * fix test abacus make input bug. * Update requirements.txt add dpdata==0.2.6 to requirements. * Update setup.py update dpdata to 0.2.6 * fix bugs concerning abacus in README * update abacus example files to dpmd 2.x and dpdispatcher new version. Co-authored-by: LiuRenxi <liurenxi@LiuRenxideMacBook-Pro.local> Co-authored-by: Han Wang <amcadmus@gmail.com>
1 parent 37df129 commit 25269cf

File tree

51 files changed

+1656
-2878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1656
-2878
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ The bold notation of key (such aas **type_map**) means that it's a necessary key
614614
| *fp_style == cp2k*
615615
| **user_fp_params** | Dict | |Parameters for cp2k calculation. find detail in manual.cp2k.org. only the kind section must be set before use. we assume that you have basic knowledge for cp2k input.
616616
| **external_input_path** | String | | Conflict with key:user_fp_params, use the template input provided by user, some rules should be followed, read the following text in detail.
617+
| *fp_style == ABACUS*
618+
| **user_fp_params** | Dict | |Parameters for ABACUS INPUT. find detail [Here](https://github.com/deepmodeling/abacus-develop/blob/develop/docs/input-main.md#out-descriptor). If `deepks_model` is set, the model file should be in the pseudopotential directory.
619+
| **fp_orb_files** | List | |List of atomic orbital files. The files should be in pseudopotential directory.
620+
| **fp_dpks_descriptor** | String | |DeePKS descriptor file name. The file should be in pseudopotential directory.
617621

618622
One can choose the model-deviation engine by specifying the key `model_devi_engine`. If `model_devi_engine` is not specified, the default model-deviation engine will be LAMMPS.
619623

dpgen/data/gen.py

Lines changed: 106 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,28 @@ def stru_ele(supercell_stru, stru_out, eles, natoms, jdata, path_work):
136136
for iatom in range(natoms[iele]):
137137
supercell_stru["types"].append(iele)
138138
pp_file_names = [os.path.basename(a) for a in jdata['potcars']]
139+
orb_file_names = None
140+
dpks_descriptor_name = None
141+
if 'orb_files' in jdata:
142+
orb_file_names = [os.path.basename(a) for a in jdata['orb_files']]
143+
if 'dpks_descriptor' in jdata:
144+
dpks_descriptor_name = os.path.basename(jdata['dpks_descriptor'])
139145
supercell_stru["atom_masses"] = jdata["atom_masses"]
140146
supercell_stru["atom_names"] = eles
141-
stru_text = make_abacus_scf_stru(supercell_stru, pp_file_names)
147+
stru_text = make_abacus_scf_stru(supercell_stru, pp_file_names, orb_file_names, dpks_descriptor_name)
142148
with open(stru_out, "w") as f:
143149
f.write(stru_text)
144150
absolute_pp_file_path = [os.path.abspath(a) for a in jdata["potcars"]]
151+
if 'orb_files' in jdata:
152+
absolute_orb_file_path = [os.path.abspath(a) for a in jdata['orb_files']]
153+
if 'dpks_descriptor' in jdata:
154+
absolute_dpks_descriptor_path = os.path.abspath(jdata['dpks_descriptor'])
145155
for ipp, pp_file in enumerate(absolute_pp_file_path):
146156
os.symlink(pp_file, os.path.join(path_work, pp_file_names[ipp]))
147-
157+
if 'orb_files' in jdata:
158+
os.symlink(absolute_orb_file_path[ipp], os.path.join(path_work, orb_file_names[ipp]))
159+
if 'dpks_descriptor' in jdata:
160+
os.symlink(absolute_dpks_descriptor_path, os.path.join(path_work, dpks_descriptor_name))
148161

149162
def poscar_natoms(lines) :
150163
numb_atoms = 0
@@ -217,7 +230,14 @@ def poscar_scale_abacus(poscar_in, poscar_out, scale, jdata):
217230
stru["cells"] *= scale
218231
stru["coords"] *= scale
219232
pp_files = [os.path.basename(a) for a in jdata['potcars']]
220-
ret = make_abacus_scf_stru(stru, pp_files)
233+
orb_file_names = None
234+
dpks_descriptor_name = None
235+
if 'orb_files' in jdata:
236+
orb_file_names = [os.path.basename(a) for a in jdata['orb_files']]
237+
if 'dpks_descriptor' in jdata:
238+
dpks_descriptor_name = os.path.basename(jdata['dpks_descriptor'])
239+
ret = make_abacus_scf_stru(stru, pp_files, orb_file_names, dpks_descriptor_name)
240+
#ret = make_abacus_scf_stru(stru, pp_files)
221241
with open(poscar_out, "w") as fp:
222242
fp.write(ret)
223243

@@ -351,7 +371,13 @@ def make_super_cell_STRU(jdata) :
351371
from_struct=get_abacus_STRU(from_file, n_ele=len(jdata["elements"]))
352372
from_struct = make_supercell_abacus(from_struct, super_cell)
353373
pp_file_names = [os.path.basename(a) for a in jdata['potcars']]
354-
stru_text = make_abacus_scf_stru(from_struct, pp_file_names)
374+
orb_file_names = None
375+
dpks_descriptor_name = None
376+
if 'orb_files' in jdata:
377+
orb_file_names = [os.path.basename(a) for a in jdata['orb_files']]
378+
if 'dpks_descriptor' in jdata:
379+
dpks_descriptor_name = os.path.basename(jdata['dpks_descriptor'])
380+
stru_text = make_abacus_scf_stru(from_struct, pp_file_names, orb_file_names, dpks_descriptor_name)
355381
with open(to_file, "w") as fp:
356382
fp.write(stru_text)
357383
# if kspacing is specified in json file, use kspacing to generate KPT (rather than directly using specified KPT).
@@ -372,12 +398,20 @@ def make_super_cell_STRU(jdata) :
372398
create_path(path_work)
373399
cwd = os.getcwd()
374400
absolute_pp_file_path = [os.path.abspath(a) for a in jdata['potcars']]
401+
if 'orb_files' in jdata:
402+
absolute_orb_file_path = [os.path.abspath(a) for a in jdata['orb_files']]
403+
if 'dpks_descriptor' in jdata:
404+
absolute_dpks_descriptor_path = os.path.abspath(jdata['dpks_descriptor'])
375405
to_file = os.path.abspath(to_file)
376406
os.chdir(path_work)
377407
try:
378408
os.symlink(os.path.relpath(to_file), 'STRU')
379409
for ipp, pp_file in enumerate(absolute_pp_file_path):
380410
os.symlink(pp_file, pp_file_names[ipp]) # create pseudo-potential files
411+
if 'orb_files' in jdata:
412+
os.symlink(absolute_orb_file_path[ipp], orb_file_names[ipp])
413+
if 'dpks_descriptor' in jdata:
414+
os.symlink(absolute_dpks_descriptor_path, dpks_descriptor_name)
381415
except FileExistsError:
382416
pass
383417
os.chdir(cwd)
@@ -528,6 +562,13 @@ def make_abacus_relax (jdata, mdata) :
528562
jdata['relax_kpt'] = os.path.relpath(jdata['relax_kpt'])
529563
shutil.copy2( jdata['relax_kpt'],
530564
os.path.join(work_dir, 'KPT'))
565+
566+
if "dpks_model" in jdata:
567+
dpks_model_absolute_path = os.path.abspath(jdata["dpks_model"])
568+
assert(os.path.isfile(dpks_model_absolute_path))
569+
dpks_model_name = os.path.basename(jdata["dpks_model"])
570+
shutil.copy2( dpks_model_absolute_path,
571+
os.path.join(work_dir, dpks_model_name))
531572

532573
os.chdir(work_dir)
533574

@@ -536,9 +577,13 @@ def make_abacus_relax (jdata, mdata) :
536577
os.chdir(ss)
537578
ln_src = os.path.relpath(os.path.join(work_dir,'INPUT'))
538579
kpt_src = os.path.relpath(os.path.join(work_dir,'KPT'))
580+
if "dpks_model" in jdata:
581+
ksmd_src = os.path.relpath(os.path.join(work_dir,dpks_model_name))
539582
try:
540583
os.symlink(ln_src, 'INPUT')
541584
os.symlink(kpt_src, 'KPT')
585+
if "dpks_model" in jdata:
586+
os.symlink(ksmd_src, dpks_model_name)
542587
except FileExistsError:
543588
pass
544589
os.chdir(work_dir)
@@ -624,6 +669,12 @@ def pert_scaled(jdata) :
624669
pert_atom = jdata['pert_atom']
625670
pert_numb = jdata['pert_numb']
626671
pp_file = [os.path.basename(a) for a in jdata['potcars']]
672+
orb_file_names = None
673+
dpks_descriptor_name = None
674+
if 'orb_files' in jdata:
675+
orb_file_names = [os.path.basename(a) for a in jdata['orb_files']]
676+
if 'dpks_descriptor' in jdata:
677+
dpks_descriptor_name = os.path.basename(jdata['dpks_descriptor'])
627678
from_poscar = False
628679
if 'from_poscar' in jdata :
629680
from_poscar = jdata['from_poscar']
@@ -671,7 +722,7 @@ def pert_scaled(jdata) :
671722
stru_in = get_abacus_STRU(pos_in)
672723
stru_out = shuffle_stru_data(stru_in)
673724
with open(pos_out, "w") as fp:
674-
fp.write(make_abacus_scf_stru(stru_out, pp_file))
725+
fp.write(make_abacus_scf_stru(stru_out, pp_file, orb_file_names, dpks_descriptor_name))
675726
else :
676727
shutil.copy2(pos_in, pos_out)
677728
os.remove(pos_in)
@@ -693,7 +744,7 @@ def pert_scaled(jdata) :
693744
stru_in = get_abacus_STRU(pos_in)
694745
stru_out = shuffle_stru_data(stru_in)
695746
with open(pos_out, "w") as fp:
696-
fp.write(make_abacus_scf_stru(stru_out, pp_file))
747+
fp.write(make_abacus_scf_stru(stru_out, pp_file, orb_file_names, dpks_descriptor_name))
697748
else :
698749
shutil.copy2(pos_in, pos_out)
699750
os.chdir(cwd)
@@ -790,6 +841,28 @@ def make_abacus_md(jdata, mdata) :
790841
if 'md_kpt' in jdata:
791842
shutil.copy2(jdata['md_kpt'],
792843
os.path.join(path_md, 'KPT'))
844+
orb_file_names = None
845+
orb_file_abspath = None
846+
dpks_descriptor_name = None
847+
dpks_descriptor_abspath = None
848+
dpks_model_name = None
849+
dpks_model_abspath = None
850+
if 'orb_files' in jdata:
851+
orb_file_names = [os.path.basename(a) for a in jdata['orb_files']]
852+
orb_file_abspath = [os.path.abspath(a) for a in jdata['orb_files']]
853+
for iorb, orb_file in enumerate(orb_file_names):
854+
shutil.copy2(orb_file_abspath[iorb],
855+
os.path.join(path_md, orb_file))
856+
if 'dpks_descriptor' in jdata:
857+
dpks_descriptor_name = os.path.basename(jdata['dpks_descriptor'])
858+
dpks_descriptor_abspath = os.path.abspath(jdata['dpks_descriptor'])
859+
shutil.copy2(dpks_descriptor_abspath,
860+
os.path.join(path_md, dpks_descriptor_name))
861+
if 'dpks_model' in jdata:
862+
dpks_model_name = os.path.basename(jdata['dpks_model'])
863+
dpks_model_abspath = os.path.abspath(jdata['dpks_model'])
864+
shutil.copy2(dpks_model_abspath,
865+
os.path.join(path_md, dpks_model_name))
793866
for pp_file in jdata['potcars']:
794867
shutil.copy2(pp_file,
795868
os.path.join(path_md, os.path.basename(pp_file)))
@@ -829,6 +902,13 @@ def make_abacus_md(jdata, mdata) :
829902
try:
830903
for pp_file in [os.path.basename(a) for a in jdata['potcars']]:
831904
os.symlink(os.path.relpath(os.path.join(path_md, pp_file)), pp_file)
905+
if 'orb_files' in jdata:
906+
for orb_file in orb_file_names:
907+
os.symlink(os.path.relpath(os.path.join(path_md, orb_file)), orb_file)
908+
if 'dpks_model' in jdata:
909+
os.symlink(os.path.relpath(os.path.join(path_md, dpks_model_name)), dpks_model_name)
910+
if 'dpks_descriptor' in jdata:
911+
os.symlink(os.path.relpath(os.path.join(path_md, dpks_descriptor_name)), dpks_descriptor_name)
832912
except FileExistsError:
833913
pass
834914

@@ -1049,7 +1129,16 @@ def run_abacus_relax(jdata, mdata):
10491129
#machine_type = mdata['fp_machine']['machine_type']
10501130
work_dir = os.path.join(jdata['out_dir'], global_dirname_02)
10511131
pp_files = [os.path.basename(a) for a in jdata["potcars"]]
1052-
forward_files = ["STRU", "INPUT", "KPT"] + pp_files
1132+
orb_file_names = []
1133+
dpks_descriptor_name = []
1134+
dpks_model_name = []
1135+
if 'orb_files' in jdata:
1136+
orb_file_names = [os.path.basename(a) for a in jdata['orb_files']]
1137+
if 'dpks_descriptor' in jdata:
1138+
dpks_descriptor_name = [os.path.basename(jdata['dpks_descriptor'])]
1139+
if 'dpks_model' in jdata:
1140+
dpks_model_name = [os.path.basename(jdata['dpks_model'])]
1141+
forward_files = ["STRU", "INPUT", "KPT"] + pp_files + orb_file_names + dpks_descriptor_name + dpks_model_name
10531142
user_forward_files = mdata.get("fp" + "_user_forward_files", [])
10541143
forward_files += [os.path.basename(file) for file in user_forward_files]
10551144
backward_files = ["OUT.ABACUS"]
@@ -1174,7 +1263,16 @@ def run_abacus_md(jdata, mdata):
11741263
pert_numb = jdata['pert_numb']
11751264
md_nstep = jdata['md_nstep']
11761265

1177-
forward_files = ["STRU", "INPUT", "KPT"]
1266+
orb_file_names = []
1267+
dpks_descriptor_name = []
1268+
dpks_model_name = []
1269+
if 'orb_files' in jdata:
1270+
orb_file_names = [os.path.basename(a) for a in jdata['orb_files']]
1271+
if 'dpks_descriptor' in jdata:
1272+
dpks_descriptor_name = [os.path.basename(jdata['dpks_descriptor'])]
1273+
if 'dpks_model' in jdata:
1274+
dpks_model_name = [os.path.basename(jdata['dpks_model'])]
1275+
forward_files = ["STRU", "INPUT", "KPT"] + orb_file_names + dpks_descriptor_name + dpks_model_name
11781276
for pp_file in [os.path.basename(a) for a in jdata['potcars']]:
11791277
forward_files.append(pp_file)
11801278
user_forward_files = mdata.get("fp" + "_user_forward_files", [])

dpgen/data/tools/create_random_disturb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def create_disturbs_abacus_dev(fin, nfile, dmax=1.0, etmax=0.1, ofmt="abacus", d
220220
# Writing it
221221
fout = fin + str(fid) + '.' + ofmt
222222
print("Creating %s ..." % fout)
223-
ret = make_abacus_scf_stru(stru_d, stru_d['pp_files'])
223+
ret = make_abacus_scf_stru(stru_d, stru_d['pp_files'], stru_d['orb_files'], stru_d['dpks_descriptor'])
224224
with open(fout, "w") as fp:
225225
fp.write(ret)
226226
if write_d:

0 commit comments

Comments
 (0)