Skip to content
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

test: update abacus input parameters for test_make_fp.py #836

Merged
merged 15 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 33 additions & 3 deletions dpgen/generator/lib/abacus_scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ def make_abacus_scf_input(fp_params):
ret += "calculation scf\n"
for key in fp_params:
if key == 'ntype':
if type(fp_params["ntype"])==str:
fp_params["ntype"] = int(fp_params["ntype"])
hongriTianqi marked this conversation as resolved.
Show resolved Hide resolved
assert(fp_params['ntype'] >= 0 and type(fp_params["ntype"]) == int), "'ntype' should be a positive integer."
ret += "ntype %d\n" % fp_params['ntype']
#ret += "pseudo_dir ./\n"
elif key == "ecutwfc":
if type(fp_params["ecutwfc"])==str:
fp_params["ecutwfc"] = float(fp_params["ecutwfc"])
assert(fp_params["ecutwfc"] >= 0) , "'ntype' should be non-negative."
ret += "ecutwfc %f\n" % fp_params["ecutwfc"]
elif key == "scf_thr":
if type(fp_params["scf_thr"])==str:
fp_params["scf_thr"] = float(fp_params["scf_thr"])
ret += "scf_thr %e\n" % fp_params["scf_thr"]
elif key == "scf_nmax":
if type(fp_params["scf_nmax"])==str:
fp_params["scf_nmax"] = int(fp_params["scf_nmax"])
assert(fp_params['scf_nmax'] >= 0 and type(fp_params["scf_nmax"])== int), "'scf_nmax' should be a positive integer."
ret += "scf_nmax %d\n" % fp_params["scf_nmax"]
elif key == "basis_type":
Expand All @@ -39,21 +47,30 @@ def make_abacus_scf_input(fp_params):
elif key == "dft_functional":
ret += "dft_functional %s\n" % fp_params["dft_functional"]
elif key == "gamma_only":
#assert(fp_params["gamma_only"] ==1 ) , "'gamma_only' should be 1. Multi-k algorithm will be supported after the KPT generator is completed."
if type(fp_params["gamma_only"])==str:
fp_params["gamma_only"] = int(eval(fp_params["gamma_only"]))
ret+= "gamma_only %d\n" % fp_params["gamma_only"]
elif key == "mixing_type":
assert(fp_params["mixing_type"] in ["plain", "kerker", "pulay", "pulay-kerker", "broyden"])
ret += "mixing_type %s\n" % fp_params["mixing_type"]
elif key == "mixing_beta":
if type(fp_params["mixing_beta"])==str:
fp_params["mixing_beta"] = float(fp_params["mixing_beta"])
assert(fp_params["mixing_beta"] >= 0 and fp_params["mixing_beta"] < 1), "'mixing_beta' should between 0 and 1."
ret += "mixing_beta %f\n" % fp_params["mixing_beta"]
elif key == "symmetry":
if type(fp_params["symmetry"])==str:
fp_params["symmetry"] = int(eval(fp_params["symmetry"]))
assert(fp_params["symmetry"] == 0 or fp_params["symmetry"] == 1), "'symmetry' should be either 0 or 1."
ret += "symmetry %d\n" % fp_params["symmetry"]
elif key == "nbands":
if type(fp_params["nbands"])==str:
fp_params["nbands"] = int(fp_params["nbands"])
assert(fp_params["nbands"] > 0 and type(fp_params["nbands"]) == int), "'nbands' should be a positive integer."
ret += "nbands %d\n" % fp_params["nbands"]
elif key == "nspin":
if type(fp_params["nspin"])==str:
fp_params["nspin"] = int(fp_params["nspin"])
assert(fp_params["nspin"] == 1 or fp_params["nspin"] == 2 or fp_params["nspin"] == 4), "'nspin' can anly take 1, 2 or 4"
ret += "nspin %d\n" % fp_params["nspin"]
elif key == "ks_solver":
Expand All @@ -63,27 +80,39 @@ def make_abacus_scf_input(fp_params):
assert(fp_params["smearing_method"] in ["gaussian", "fd", "fixed", "mp", "mp2", "mv"]), "'smearing_method' should in 'gaussian', 'fd', 'fixed', 'mp', 'mp2', 'mv'. "
ret += "smearing_method %s\n" % fp_params["smearing_method"]
elif key == "smearing_sigma":
if type(fp_params["smearing_sigma"])==str:
fp_params["smearing_sigma"] = float(fp_params["smearing_sigma"])
assert(fp_params["smearing_sigma"] >= 0), "'smearing_sigma' should be non-negative."
ret += "smearing_sigma %f\n" % fp_params["smearing_sigma"]
elif key == "force":
elif key == "cal_force":
if type(fp_params["cal_force"])==str:
fp_params["cal_force"] = int(eval(fp_params["cal_force"]))
assert(fp_params["cal_force"] == 0 or fp_params["cal_force"] == 1), "'cal_force' should be either 0 or 1."
ret += "cal_force %d\n" % fp_params["cal_force"]
elif key == "cal_stress":
if type(fp_params["cal_stress"])==str:
fp_params["cal_stress"] = int(eval(fp_params["cal_stress"]))
assert(fp_params["cal_stress"] == 0 or fp_params["cal_stress"] == 1), "'cal_stress' should be either 0 or 1."
ret += "cal_stress %d\n" % fp_params["cal_stress"]
#paras for deepks
elif key == "deepks_out_labels":
if type(fp_params["deepks_out_labels"])==str:
fp_params["deepks_out_labels"] = int(eval(fp_params["deepks_out_labels"]))
assert(fp_params["deepks_out_labels"] == 0 or fp_params["deepks_out_labels"] == 1), "'deepks_out_labels' should be either 0 or 1."
ret += "deepks_out_labels %d\n" % fp_params["deepks_out_labels"]
elif key == "deepks_descriptor_lmax":
if type(fp_params["deepks_descriptor_lmax"])==str:
fp_params["deepks_descriptor_lmax"] = int(fp_params["deepks_descriptor_lmax"])
assert(fp_params["deepks_descriptor_lmax"] >= 0), "'deepks_descriptor_lmax' should be a positive integer."
ret += "deepks_descriptor_lmax %d\n" % fp_params["deepks_descriptor_lmax"]
elif key == "deepks_scf":
if type(fp_params["deepks_scf"])==str:
fp_params["deepks_scf"] = int(eval(fp_params["deepks_scf"]))
assert(fp_params["deepks_scf"] == 0 or fp_params["deepks_scf"] == 1), "'deepks_scf' should be either 0 or 1."
ret += "deepks_scf %d\n" % fp_params["deepks_scf"]
elif key == "deepks_model":
ret += "deepks_model %s\n" % fp_params["deepks_model"]
elif key != "k_points": # "k_points key is used to generate KPT file."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This elif is necessary. The k_points is also specified in fp_params, but can not be written in INPUT file.

Copy link
Contributor Author

@hongriTianqi hongriTianqi Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This k_points tag has been upgraded to the same level as 'user_fp_param'. Users may also use 'fp_kpt_file' to read KPT file now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got that. I have no other questions.

else:
ret += "%s %s\n" % (key, str(fp_params[key]))
return ret

Expand Down Expand Up @@ -153,6 +182,7 @@ def get_abacus_input_parameters(INPUT):
parameter_name = line.split()[0]
parameter_value = line.split()[1]
input_parameters[parameter_name] = parameter_value
fp.close()
return input_parameters

def get_mass_from_STRU(geometry_inlines, inlines, atom_names):
Expand Down
26 changes: 22 additions & 4 deletions dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from dpgen.generator.lib.vasp import incar_upper
from dpgen.generator.lib.pwscf import make_pwscf_input
from dpgen.generator.lib.abacus_scf import make_abacus_scf_stru, make_abacus_scf_input, make_abacus_scf_kpt
from dpgen.generator.lib.abacus_scf import get_abacus_input_parameters
#from dpgen.generator.lib.pwscf import cvt_1frame
from dpgen.generator.lib.pwmat import make_pwmat_input_dict
from dpgen.generator.lib.pwmat import write_input_dict
Expand Down Expand Up @@ -2561,7 +2562,8 @@ def make_fp_abacus_scf(iter_index,
fp_pp_files = jdata['fp_pp_files']
fp_orb_files = None
fp_dpks_descriptor = None
assert('user_fp_params' in jdata.keys())
# get paramters for writting INPUT file
fp_params = {}
if 'user_fp_params' in jdata.keys() :
fp_params = jdata['user_fp_params']
# for lcao
Expand All @@ -2574,18 +2576,34 @@ def make_fp_abacus_scf(iter_index,
assert('fp_dpks_descriptor' in jdata and type(jdata['fp_dpks_descriptor']) == str)
fp_dpks_descriptor = jdata['fp_dpks_descriptor']
#user_input = True
ret_input = make_abacus_scf_input(fp_params)
elif 'fp_incar' in jdata.keys():
fp_input_path = jdata['fp_incar']
assert(os.path.exists(fp_input_path))
fp_input_path = os.path.abspath(fp_input_path)
fp_params = get_abacus_input_parameters(fp_input_path)
ret_input = make_abacus_scf_input(fp_params)
else:
raise RuntimeError("Key 'user_fp_params' and its value have to be specified in parameter json file.")
raise RuntimeError("Set 'user_fp_params' or 'fp_incar' in json file to make INPUT of ABACUS")
# get paramters for writting KPT file
if 'k_points' in jdata.keys() :
ret_kpt = make_abacus_scf_kpt(jdata['k_points'])
elif 'fp_kpt_file' in jdata.keys():
fp_kpt_path = jdata['fp_kpt_file']
assert(os.path.exists(fp_kpt_path))
fp_kpt_path = os.path.abspath(fp_kpt_path)
fk = open(fp_kpt_path)
ret_kpt = fk.read()
fk.close()

cwd = os.getcwd()
for ii in fp_tasks:
os.chdir(ii)
sys_data = dpdata.System('POSCAR').data
if 'mass_map' in jdata:
sys_data['atom_masses'] = jdata['mass_map']
ret_input = make_abacus_scf_input(fp_params)
with open('INPUT', 'w') as fp:
fp.write(ret_input)
ret_kpt = make_abacus_scf_kpt(fp_params)
with open("KPT", "w") as fp:
fp.write(ret_kpt)
ret_stru = make_abacus_scf_stru(sys_data, fp_pp_files, fp_orb_files, fp_dpks_descriptor, fp_params)
Expand Down
22 changes: 22 additions & 0 deletions tests/generator/abacus/INPUT.diy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ntype 2
ecutwfc 80
scf_thr 1e-7
scf_nmax 50
basis_type pw
gamma_only 1
dft_functional pbe
mixing_type pulay
mixing_beta 0.4
symmetry 1
nbands 5
nspin 1
ks_solver cg
smearing_method fixed
smearing_sigma 0.001
cal_force 1
cal_stress 1
deepks_out_labels 0
deepks_descriptor_lmax 0
deepks_scf 0
deepks_model model.ptg

4 changes: 4 additions & 0 deletions tests/generator/abacus/KPT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
K_POINTS
0
Gamma
1 1 1 0 0 0
1 change: 1 addition & 0 deletions tests/generator/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
param_pwmat_file = 'param-pyridine-pwmat.json'
param_abacus_file = 'param-pyridine-abacus.json'
param_abacus_post_file = 'param-methane-abacus.json'
param_diy_abacus_post_file = 'param-methane-abacus-diy.json'
param_amber_file = "param-amber.json"
param_multiple_trust_file = 'param-mg-vasp-multi-trust.json'

Expand Down
137 changes: 137 additions & 0 deletions tests/generator/param-methane-abacus-diy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"type_map": ["H", "C"],
"mass_map": [1.0, 12.0],

"_comment": "initial data set for Training and the number of frames in each training batch",
"init_data_prefix": "/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_ABACUS_dpgen_interface/5_dpgen_examples/dpgen-example/run_abacus/",
"init_data_sys": [
"abacus_init_data"
],
"init_batch_size": [
8
],

"_comment": "configurations for starting MD in Exploration and batch sizes when traning snapshots derived from these configs (if they were selected)",
"sys_configs_prefix": "/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_ABACUS_dpgen_interface/5_dpgen_examples/dpgen-example/run",
"sys_configs": [
[
"CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale-1.000/000000/POSCAR",
"CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale-1.000/000001/POSCAR",
"CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale-1.000/00000[2-9]/POSCAR"
],
[
"CH4.POSCAR.01x01x01/01.scale_pert/sys-0004-0001/scale-1.000/00001*/POSCAR"
]
],
"sys_batch_size": [
8,
8
],

"_comment": " 00.train ",
"numb_models": 4,

"default_training_param": {
"model": {
"type_map": ["H","C"],
"descriptor": {
"type": "se_a",
"sel": [16,4],
"rcut_smth": 0.5,
"rcut": 5.0,
"neuron": [10,20,40],
"resnet_dt": false,
"axis_neuron": 12,
"seed": 0
},
"fitting_net": {
"neuron": [120,120,120],
"resnet_dt": true,
"coord_norm": true,
"type_fitting_net": false,
"seed": 0
}
},
"loss": {
"start_pref_e": 0.02,
"limit_pref_e": 2,
"start_pref_f": 1000,
"limit_pref_f": 1,
"start_pref_v": 0,
"limit_pref_v": 0
},
"learning_rate": {
"type": "exp",
"start_lr": 0.001,
"decay_steps": 180,
"decay_rate": 0.95
},
"training": {
"systems": [],
"set_prefix": "set",
"stop_batch": 36000,
"batch_size": 1,
"seed": 1,
"_comment": "frequencies counted in batch",
"disp_file": "lcurve.out",
"disp_freq": 1000,
"numb_test": 4,
"save_freq": 1000,
"save_ckpt": "model.ckpt",
"load_ckpt": "model.ckpt",
"disp_training": true,
"time_training": true,
"profiling": false,
"profiling_file": "timeline.json"
}
},

"_comment": " 01.model_devi ",
"model_devi_dt": 0.002,
"model_devi_skip": 0,
"model_devi_f_trust_lo": 0.05,
"model_devi_f_trust_hi": 0.15,
"model_devi_clean_traj": false,
"model_devi_jobs": [
{
"sys_idx": [
0
],
"temps": [
50
],
"press": [
1
],
"trj_freq": 10,
"nsteps": 1000,
"ensemble": "nvt",
"_idx": "00"
},
{
"sys_idx": [
1
],
"temps": [
50
],
"press": [
1
],
"trj_freq": 10,
"nsteps": 3000,
"ensemble": "nvt",
"_idx": "01"
}
],

"_comment": " 02.fp ",
"fp_style": "abacus/scf",
"shuffle_poscar": false,
"fp_task_max": 30,
"fp_task_min": 8,
"fp_pp_path": ".",
"fp_pp_files": [ "./H_HSCV_PBE-1.0.UPF","./C_HSCV_PBE-1.0.UPF"],
"fp_incar": "abacus/INPUT.diy",
"k_points": [1, 1, 1, 0, 0, 0]
}
5 changes: 3 additions & 2 deletions tests/generator/param-methane-abacus.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,16 @@
"fp_task_min": 8,
"fp_pp_path": ".",
"fp_pp_files": [ "./H_HSCV_PBE-1.0.UPF","./C_HSCV_PBE-1.0.UPF"],
"fp_kpt_file": "./abacus/KPT",
"user_fp_params":{
"ntype": 2,
"ecutwfc": 80,
"scf_thr": 1e-7,
"scf_nmax": 50,
"basis_type": "pw",
"gamma_only": true,
"gamma_only": 1,
"dft_functional": "pbe",
"mixing_type": "pulay",
"mixing_type": "pulay",
"mixing_beta": 0.4,
"symmetry": 1,
"nbands": 5,
Expand Down
Loading