Skip to content

Commit

Permalink
added ABACUS interface for first principle calculations (#433)
Browse files Browse the repository at this point in the history
* delete unnecessary files

* remove ABACUS codes in relabel.py, fix test files.

* Add files via upload

* Add files via upload

Co-authored-by: LiuRenxi <LiuRenxi@MacBook-Air.local>
  • Loading branch information
Liu-RX and LiuRenxi authored Jun 14, 2021
1 parent b57b86e commit 5b54014
Show file tree
Hide file tree
Showing 47 changed files with 2,634 additions and 2 deletions.
95 changes: 95 additions & 0 deletions dpgen/generator/lib/abacus_pw_scf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import numpy as np
bohr2ang = 0.52917721067
def make_abacus_pw_scf_kpt(fp_params):
# Make KPT file for abacus pw scf calculation.
# KPT file is the file containing k points infomation in ABACUS scf calculation.
k_points = [1, 1, 1, 0, 0, 0]
if "k_points" in fp_params:
k_points = fp_params["k_points"]
if len(k_points) != 6:
raise RuntimeError("k_points has to be a list containig 6 integers specifying MP k points generation.")
ret = "K_POINTS\n0\nGamma\n"
for i in range(6):
ret += str(k_points[i]) + " "
return ret

def make_abacus_pw_scf_input(fp_params):
# Make INPUT file for abacus pw scf calculation.
ret = "INPUT_PARAMETERS\n"
assert(fp_params['ntype'] >= 0 and type(fp_params["ntype"]) == int)
ret += "ntype %d\n" % fp_params['ntype']
ret += "pseudo_dir ./\n"
if "ecutwfc" in fp_params:
assert(fp_params["ecutwfc"] >= 0)
ret += "ecutwfc %f\n" % fp_params["ecutwfc"]
if "mixing_type" in fp_params:
assert(fp_params["mixing_type"] in ["plain", "kerker", "pulay", "pulay-kerker", "broyden"])
ret += "mixing_type %s\n" % fp_params["mixing_type"]
if "mixing_beta" in fp_params:
assert(fp_params["mixing_beta"] >= 0 and fp_params["mixing_beta"] < 1)
ret += "mixing_beta %f\n" % fp_params["mixing_beta"]
if "symmetry" in fp_params:
assert(fp_params["symmetry"] == 0 or fp_params["symmetry"] == 1)
ret += "symmetry %d\n" % fp_params["symmetry"]
if "nbands" in fp_params:
assert(fp_params["nbands"] > 0 and type(fp_params["nbands"]) == int)
ret += "nbands %f\n" % fp_params["nbands"]
if "nspin" in fp_params:
assert(fp_params["nspin"] == 1 or fp_params["nspin"] == 2 or fp_params["nspin"] == 4)
ret += "nspin %d\n" % fp_params["nspin"]
if "ks_solver" in fp_params:
assert(fp_params["ks_solver"] in ["cg", "dav", "lapack", "genelpa", "hpseps", "scalapack_gvx"])
ret += "ks_solver %s\n" % fp_params["ks_solver"]
if "smearing" in fp_params:
assert(fp_params["smearing"] in ["gauss", "fd", "fixed", "mp", "mp2", "mv"])
ret += "smearing %s\n" % fp_params["smearing"]
if "sigma" in fp_params:
assert(fp_params["sigma"] >= 0)
ret += "sigma %f\n" % fp_params["sigma"]
ret += "force 1\nstress 1\n"
return ret

def make_abacus_pw_scf_stru(sys_data, fp_pp_files):
atom_names = sys_data['atom_names']
atom_numbs = sys_data['atom_numbs']
assert(len(atom_names) == len(fp_pp_files))
assert(len(atom_names) == len(atom_numbs))
cell = sys_data["cells"][0].reshape([3, 3])
coord = sys_data['coords'][0]
#volume = np.linalg.det(cell)
#lattice_const = np.power(volume, 1/3)
lattice_const = 1/bohr2ang # in Bohr, in this way coord and cell are in Angstrom

ret = "ATOMIC_SPECIES\n"
for iatom in range(len(atom_names)):
ret += atom_names[iatom] + " 1.00 " + fp_pp_files[iatom] + "\n"

ret += "\nLATTICE_CONSTANT\n"
ret += str(lattice_const) + "\n\n"

ret += "LATTICE_VECTORS\n"
for ix in range(3):
for iy in range(3):
ret += str(cell[ix][iy]) + " "
ret += "\n"
ret += "\n"

ret += "ATOMIC_POSITIONS\n"
ret += "Cartesian # Cartesian(Unit is LATTICE_CONSTANT)\n"
natom_tot = 0
for iele in range(len(atom_names)):
ret += atom_names[iele] + "\n"
ret += "0.0\n"
ret += str(atom_numbs[iele]) + "\n"
for iatom in range(atom_numbs[iele]):
ret += "%.12f %.12f %.12f %d %d %d\n" % (coord[natom_tot, 0], coord[natom_tot, 1], coord[natom_tot, 2], 0, 0, 0)
natom_tot += 1
assert(natom_tot == sum(atom_numbs))

return ret


if __name__ == "__main__":
fp_params = {"k_points": [1, 1, 1, 0, 0, 0]}
ret = make_abacus_pw_scf_kpt(fp_params)
print(ret)
99 changes: 99 additions & 0 deletions dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from dpgen.generator.lib.vasp import make_vasp_incar_user_dict
from dpgen.generator.lib.vasp import incar_upper
from dpgen.generator.lib.pwscf import make_pwscf_input
from dpgen.generator.lib.abacus_pw_scf import make_abacus_pw_scf_stru, make_abacus_pw_scf_input, make_abacus_pw_scf_kpt
#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 @@ -1795,6 +1796,41 @@ def make_fp_pwscf(iter_index,
# link pp files
_link_fp_vasp_pp(iter_index, jdata)

def make_fp_abacus_pw_scf(iter_index,
jdata) :
# make config
fp_tasks = _make_fp_vasp_configs(iter_index, jdata)
if len(fp_tasks) == 0 :
return
# make abacus/pw/scf input
iter_name = make_iter_name(iter_index)
work_path = os.path.join(iter_name, fp_name)
fp_pp_files = jdata['fp_pp_files']
if 'user_fp_params' in jdata.keys() :
fp_params = jdata['user_fp_params']
#user_input = True
else:
raise RuntimeError("Key 'user_fp_params' and its value have to be specified in parameter json file.")
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_pw_scf_input(fp_params)
with open('INPUT', 'w') as fp:
fp.write(ret_input)
ret_kpt = make_abacus_pw_scf_kpt(fp_params)
with open("KPT", "w") as fp:
fp.write(ret_kpt)
ret_stru = make_abacus_pw_scf_stru(sys_data, fp_pp_files)
with open("STRU", "w") as fp:
fp.write(ret_stru)

os.chdir(cwd)
# link pp files
_link_fp_vasp_pp(iter_index, jdata)


def make_fp_siesta(iter_index,
jdata) :
Expand Down Expand Up @@ -1918,6 +1954,8 @@ def make_fp (iter_index,
make_fp_vasp(iter_index, jdata)
elif fp_style == "pwscf" :
make_fp_pwscf(iter_index, jdata)
elif fp_style == "abacus/scf" :
make_fp_abacus_pw_scf(iter_index, jdata)
elif fp_style == "siesta" :
make_fp_siesta(iter_index, jdata)
elif fp_style == "gaussian" :
Expand Down Expand Up @@ -1951,6 +1989,16 @@ def _qe_check_fin(ii) :
return False
return True

def _abacus_pw_scf_check_fin(ii) :
if os.path.isfile(os.path.join(ii, 'OUT.ABACUS/running_scf.log')) :
with open(os.path.join(ii, 'OUT.ABACUS/running_scf.log'), 'r') as fp :
content = fp.read()
count = content.count('!FINAL_ETOT_IS')
if count != 1 :
return False
else :
return False
return True

def _siesta_check_fin(ii) :
if os.path.isfile(os.path.join(ii, 'output')) :
Expand Down Expand Up @@ -2061,6 +2109,10 @@ def run_fp (iter_index,
forward_files = ['input'] + fp_pp_files
backward_files = ['output']
run_fp_inner(iter_index, jdata, mdata, forward_files, backward_files, _qe_check_fin, log_file = 'output')
elif fp_style == "abacus/scf":
forward_files = ["INPUT", "STRU", "KPT"] + fp_pp_files
backward_files = ["output", "OUT.ABACUS"]
run_fp_inner(iter_index, jdata, mdata, forward_files, backward_files, _abacus_pw_scf_check_fin, log_file = 'output')
elif fp_style == "siesta":
forward_files = ['input'] + fp_pp_files
backward_files = ['output']
Expand Down Expand Up @@ -2235,6 +2287,51 @@ def post_fp_pwscf (iter_index,
all_sys.to_deepmd_raw(sys_data_path)
all_sys.to_deepmd_npy(sys_data_path, set_size = len(sys_output))

def post_fp_abacus_pw_scf (iter_index,
jdata):
model_devi_jobs = jdata['model_devi_jobs']
assert (iter_index < len(model_devi_jobs))

iter_name = make_iter_name(iter_index)
work_path = os.path.join(iter_name, fp_name)
fp_tasks = glob.glob(os.path.join(work_path, 'task.*'))
fp_tasks.sort()
if len(fp_tasks) == 0 :
return

system_index = []
for ii in fp_tasks :
system_index.append(os.path.basename(ii).split('.')[1])
system_index.sort()
set_tmp = set(system_index)
system_index = list(set_tmp)
system_index.sort()

cwd = os.getcwd()
for ss in system_index :
sys_output = glob.glob(os.path.join(work_path, "task.%s.*"%ss))
sys_input = glob.glob(os.path.join(work_path, "task.%s.*/INPUT"%ss))
sys_output.sort()
sys_input.sort()

flag=True
for ii,oo in zip(sys_input,sys_output) :
if flag:
_sys = dpdata.LabeledSystem(oo, fmt = 'abacus/scf', type_map = jdata['type_map'])
if len(_sys)>0:
all_sys=_sys
flag=False
else:
pass
else:
_sys = dpdata.LabeledSystem(oo, fmt = 'abacus/scf', type_map = jdata['type_map'])
if len(_sys)>0:
all_sys.append(_sys)

sys_data_path = os.path.join(work_path, 'data.%s'%ss)
all_sys.to_deepmd_raw(sys_data_path)
all_sys.to_deepmd_npy(sys_data_path, set_size = len(sys_output))

def post_fp_siesta (iter_index,
jdata):
model_devi_jobs = jdata['model_devi_jobs']
Expand Down Expand Up @@ -2424,6 +2521,8 @@ def post_fp (iter_index,
post_fp_vasp(iter_index, jdata)
elif fp_style == "pwscf" :
post_fp_pwscf(iter_index, jdata)
elif fp_style == "abacus/scf":
post_fp_abacus_pw_scf(iter_index, jdata)
elif fp_style == "siesta":
post_fp_siesta(iter_index, jdata)
elif fp_style == 'gaussian' :
Expand Down
2 changes: 1 addition & 1 deletion dpgen/tools/relabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def create_tasks(target_folder, param_file, output, fp_json, verbose = True, num
copy_pp_files(output, fp_pp_path, fp_pp_files)
make_vasp_incar(fp_params, output)
if fp_style == 'pwscf' :
copy_pp_files(output, fp_pp_path, fp_pp_files)
copy_pp_files(output, fp_pp_path, fp_pp_files)
if fp_style == 'siesta' :
copy_pp_files(output, fp_pp_path, fp_pp_files)
for si in range(numb_sys) :
Expand Down
88 changes: 88 additions & 0 deletions examples/run/dp1.x-lammps-ABACUS-pw/methane/machine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"train":[
{
"machine":{
"machine_type": "slurm",
"host_name": "localhost",
"port": 22,
"username": "",
"work_path": "/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_ABACUS_dpgen_interface/5_dpgen_examples/dpgen-example/run_abacus"
},

"resources":{
"numb_node": 1,
"numb_gpu": 1,
"task_per_node": 1,
"partition": "",
"exclude_list": [],
"mem_limit": 0,
"source_list": ["/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_ABACUS_dpgen_interface/env.sh"],
"module_list": [],
"time_limit": "23:0:0",
"account":"",
"qos": ""
},
"python_path": "/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_dpgen_interface/4_deepmd-kit/dpmd_install/bin/python"
}
],
"model_devi": [
{
"machine": {
"machine_type": "slurm",
"hostname": "localhost",
"port": 22,
"username": "",
"work_path": "/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_ABACUS_dpgen_interface/5_dpgen_examples/dpgen-example/run_abacus"
},
"resources": {
"num_node": 1,
"num_gpu": 0,
"task_per_node": 2,
"partition": "cn-large",
"exclude_list": [],
"mem_limit": 0,
"source_list": ["/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_ABACUS_dpgen_interface/env.sh"],
"module_list": [],
"time_limit": "14:00:00",
"account": "",
"qos": "",
"allow_failure":true
},
"command": "mpirun -n 2 lmp",
"group_size": 6
}
],
"fp": [
{
"machine":{
"machine_type": "slurm",
"hostname": "localhost",
"port": 22,
"username": "",
"work_path": "/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_ABACUS_dpgen_interface/5_dpgen_examples/dpgen-example/run_abacus"
},
"resources": {
"cvasp": false,
"numb_node": 1,
"partition": "cn-large",
"task_per_node": 4,

"numb_gpu": 0,
"exclude_list": [],
"with_mpi": false,
"mem_limit": 0,
"source_list":[
"/home/mhchen_pkuhpc/mhchen_cls/lustre2/5_liurenxi/5_ABACUS_dpgen_interface/env.sh"
],
"module_list":[],
"time_limit": "48:0:0",
"account": "",
"qos": "",
"_comment": "that's all"
},
"command": "mpirun -np 4 ABACUS.mpi.2.1.0",
"group_size": 150
}

]
}
Loading

0 comments on commit 5b54014

Please sign in to comment.