Skip to content

Commit

Permalink
Merge pull request #200 from deepmodeling/devel
Browse files Browse the repository at this point in the history
merge devel to master
  • Loading branch information
amcadmus authored Jan 10, 2020
2 parents 73c3c35 + 6dacfad commit ca01bd8
Show file tree
Hide file tree
Showing 80 changed files with 4,089 additions and 1,065 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: python
python:
- "3.6.3"
- "3.6-dev" # 3.6 development branch
- "3.6"
- "3.7"
# command to install dependencies
env:
matrix:
- PYMATGEN_VERSION=2017.9.1
- PYMATGEN_VERSION=2018.1.19
- PYMATGEN_VERSION=2019.1.13
- PYMATGEN_VERSION=2019.7.30
before_install:
Expand Down
355 changes: 348 additions & 7 deletions README.md

Large diffs are not rendered by default.

45 changes: 21 additions & 24 deletions dpgen/auto_test/cmpt_00_equi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,43 @@ def comput_e_shift(poscar, task_name) :
ener_shift += a_natoms[ii] * ener
return ener_shift

def comput_lmp_nev(conf_dir, task_name, write_stable = False) :
def comput_lmp_nev(conf_dir, task_name,write_shift = False) :
conf_path = re.sub('confs', global_equi_name, conf_dir)
conf_path = os.path.abspath(conf_path)
poscar = os.path.join(conf_path, 'POSCAR')
if write_stable :
ele_types = vasp.get_poscar_types(poscar)
if len(ele_types) > 1 :
raise RuntimeError('stable energy and volume only for one element, current you have %s from POSCAR' % str(ele_types))
ener_shift = comput_e_shift(poscar, task_name)
ele_types = vasp.get_poscar_types(poscar)

lmp_path = os.path.join(conf_path, task_name)
log_lammps = os.path.join(lmp_path, 'log.lammps')
if os.path.isfile(log_lammps):
natoms, epa, vpa = lammps.get_nev(log_lammps)
epa = (epa * natoms - ener_shift) / natoms
if write_stable :
if write_shift and len(ele_types)>1:
ener_shift = comput_e_shift(poscar, task_name)
shift = (epa * natoms - ener_shift) / natoms
return natoms,epa,vpa,shift
if len(ele_types)==1:
stable_dir = 'stables'
os.makedirs(stable_dir, exist_ok=True)
name_prefix=os.path.join(stable_dir,'%s.%s' % (ele_types[0], task_name))
open(name_prefix + '.e', 'w').write('%.16f\n' % (epa))
open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa))
return natoms, epa, vpa
return natoms, epa, vpa , None
else :
return None, None, None
return None, None, None, None

def comput_vasp_nev(jdata, conf_dir, write_shift = False) :

def comput_vasp_nev(jdata, conf_dir, write_stable = False) :

conf_path = re.sub('confs', global_equi_name, conf_dir)
conf_path = os.path.abspath(conf_path)
poscar = os.path.join(conf_path, 'POSCAR')
if write_stable :
ele_types = vasp.get_poscar_types(poscar)
if len(ele_types) > 1 :
raise RuntimeError('stable energy and volume only for one element, current you have %s from POSCAR' % str(ele_types))
ele_types = vasp.get_poscar_types(poscar)

if 'relax_incar' in jdata.keys():
vasp_str='vasp-relax_incar'
else:
kspacing = jdata['vasp_params']['kspacing']
vasp_str='vasp-k%.2f' % kspacing

ener_shift = comput_e_shift(poscar, vasp_str)
vasp_path = os.path.join(conf_path, vasp_str)
outcar = os.path.join(vasp_path, 'OUTCAR')
# tag_fin = os.path.join(vasp_path, 'tag_finished')
Expand All @@ -72,22 +67,25 @@ def comput_vasp_nev(jdata, conf_dir, write_stable = False) :
warnings.warn("incomplete job "+vasp_path+" use the last frame")
if os.path.isfile(outcar):
natoms, epa, vpa = vasp.get_nev(outcar)
epa = (epa * natoms - ener_shift) / natoms
if write_stable :
if write_shift and len(ele_types)>1:
ener_shift = comput_e_shift(poscar, vasp_str)
shift = (epa * natoms - ener_shift) / natoms
return natoms,epa,vpa,shift
if len(ele_types)==1:
stable_dir = 'stables'
os.makedirs(stable_dir, exist_ok=True)
name_prefix=os.path.join(stable_dir,'%s.'% (ele_types[0])+vasp_str)
open(name_prefix + '.e', 'w').write('%.16f\n' % (epa))
open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa))
return natoms, epa, vpa
return natoms, epa, vpa, None
else :
return None, None, None
return None, None, None, None

def _main():
parser = argparse.ArgumentParser(
description="cmpt 00.equi")
parser.add_argument('TASK', type=str,
choices = ['all', 'vasp', 'deepmd', 'meam'],
parser.add_argument('TASK', type=str,
choices = ['all', 'vasp', 'deepmd', 'meam'],
help='the task of generation, vasp or lammps')
parser.add_argument('PARAM', type=str,
help='the json param')
Expand Down Expand Up @@ -120,4 +118,3 @@ def _main():

if __name__ == '__main__' :
_main()

2 changes: 1 addition & 1 deletion dpgen/auto_test/cmpt_02_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def cmpt_deepmd_lammps(jdata, conf_dir, task_name) :
# et = -et / 1e4
print_et(et)
result = os.path.join(task_path,'result')
result_et(et,conf_dir,task_path)
result_et(et,conf_dir,result)
if 'upload_username' in jdata.keys() and task_name=='deepmd':
upload_username=jdata['upload_username']
util.insert_data('elastic','deepmd',upload_username,result)
Expand Down
56 changes: 33 additions & 23 deletions dpgen/auto_test/cmpt_03_vacancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def comput_e_shift(poscar, task_name) :
ref_e_file = os.path.join('stables', ref_e_file)
ener = float(open(ref_e_file).read())
ener_shift += a_natoms[ii] * ener
return ener_shift
return ener_shift

def cmpt_vasp(jdata, conf_dir, supercell) :

Expand All @@ -37,7 +37,7 @@ def cmpt_vasp(jdata, conf_dir, supercell) :
equi_path = os.path.join(equi_path, vasp_str)
equi_path = os.path.abspath(equi_path)
equi_outcar = os.path.join(equi_path, 'OUTCAR')
task_path = re.sub('confs', global_task_name, conf_dir)
task_path = re.sub('confs', global_task_name, conf_dir)
task_path = os.path.join(task_path, vasp_str)
task_path = os.path.abspath(task_path)
print("# ", task_path)
Expand All @@ -51,17 +51,23 @@ def cmpt_vasp(jdata, conf_dir, supercell) :
if len(struct_path_list) == 0:
print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
sys.stdout.write ("Structure: \tVac_E(eV) E(eV) equi_E(eV)\n")
for ii in struct_path_list :
struct_poscar = os.path.join(ii, 'POSCAR')
energy_shift = comput_e_shift(struct_poscar, vasp_str)
structure_dir = os.path.basename(ii)
outcar = os.path.join(ii, 'OUTCAR')
natoms, epa, vpa = vasp.get_nev(outcar)
evac = epa * natoms - equi_epa * natoms
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
result = os.path.join(task_path,'result')
with open(result,'w') as fp:
fp.write('conf_dir:%s\n'% (conf_dir))
fp.write("Structure: \tVac_E(eV) E(eV) equi_E(eV)\n")
for ii in struct_path_list :
struct_poscar = os.path.join(ii, 'POSCAR')
#energy_shift = comput_e_shift(struct_poscar, vasp_str)
structure_dir = os.path.basename(ii)
outcar = os.path.join(ii, 'OUTCAR')
natoms, epa, vpa = vasp.get_nev(outcar)
evac = epa * natoms - equi_epa * natoms
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
fp.write("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
fp.close()
# evac = epa * natoms - energy_shift
# sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, energy_shift))
# sys.stdout.write ("%s: %7.3f \n" % (structure_dir, evac))
# sys.stdout.write ("%s: %7.3f \n" % (structure_dir, evac))

def cmpt_deepmd_lammps(jdata, conf_dir, supercell, task_name) :
equi_path = re.sub('confs', global_equi_name, conf_dir)
Expand All @@ -82,14 +88,20 @@ def cmpt_deepmd_lammps(jdata, conf_dir, supercell, task_name) :
if len(struct_path_list) == 0:
print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
sys.stdout.write ("Structure: \tVac_E(eV) E(eV) equi_E(eV)\n")
for ii in struct_path_list :
struct_poscar = os.path.join(ii, 'POSCAR')
energy_shift = comput_e_shift(struct_poscar, task_name)
structure_dir = os.path.basename(ii)
lmp_log = os.path.join(ii, 'log.lammps')
natoms, epa, vpa = lammps.get_nev(lmp_log)
evac = epa * natoms - equi_epa * natoms
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
result = os.path.join(task_path,'result')
with open(result,'w') as fp:
fp.write('conf_dir:%s\n'% (conf_dir))
fp.write("Structure: \tVac_E(eV) E(eV) equi_E(eV)\n")
for ii in struct_path_list :
struct_poscar = os.path.join(ii, 'POSCAR')
#energy_shift = comput_e_shift(struct_poscar, task_name)
structure_dir = os.path.basename(ii)
lmp_log = os.path.join(ii, 'log.lammps')
natoms, epa, vpa = lammps.get_nev(lmp_log)
evac = epa * natoms - equi_epa * natoms
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
fp.write("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
fp.close()
# evac = epa * natoms - energy_shift
# sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, energy_shift))
# sys.stdout.write ("%s: %7.3f\n" % (structure_dir, evac))
Expand All @@ -112,15 +124,13 @@ def _main() :

# print('# generate %s task with conf %s' % (args.TASK, args.CONF))
if args.TASK == 'vasp':
cmpt_vasp(jdata, args.CONF, args.COPY)
cmpt_vasp(jdata, args.CONF, args.COPY)
elif args.TASK == 'deepmd' :
cmpt_deepmd_lammps(jdata, args.CONF, args.COPY, args.TASK)
elif args.TASK == 'meam' :
cmpt_deepmd_lammps(jdata, args.CONF, args.COPY, args.TASK)
else :
raise RuntimeError("unknow task ", args.TASK)

if __name__ == '__main__' :
_main()


46 changes: 28 additions & 18 deletions dpgen/auto_test/cmpt_04_interstitial.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ def _cmpt_vasp(jdata, conf_dir, supercell, insert_ele) :
struct_path_list.sort()
if len(struct_path_list) == 0:
print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
sys.stdout.write ("Insert_ele-Struct: Inter_E(eV)\n")
for ii in struct_path_list :
structure_dir = os.path.basename(ii)
outcar = os.path.join(ii, 'OUTCAR')
natoms, epa, vpa = vasp.get_nev(outcar)
evac = epa * natoms - equi_epa * natoms
sys.stdout.write ("%s: %7.3f \n" % (structure_dir, evac))
sys.stdout.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
result = os.path.join(task_path,'result')
with open(result,'w') as fp:
fp.write('conf_dir:%s\n'% (conf_dir))
fp.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
for ii in struct_path_list :
structure_dir = os.path.basename(ii)
outcar = os.path.join(ii, 'OUTCAR')
natoms, epa, vpa = vasp.get_nev(outcar)
evac = epa * natoms - equi_epa * natoms
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
fp.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
fp.close()

def cmpt_deepmd_reprod_traj(jdata, conf_dir, supercell, insert_ele, task_name) :
for ii in insert_ele:
Expand All @@ -63,7 +69,7 @@ def _cmpt_deepmd_reprod_traj(jdata, conf_dir, supercell, insert_ele, task_name)
conf_path = os.path.abspath(conf_dir)
task_path = re.sub('confs', global_task_name, conf_path)
vasp_path = os.path.join(task_path, vasp_str)
lmps_path = os.path.join(task_path, task_name + vasp_str.replace('vasp',''))
lmps_path = os.path.join(task_path, task_name + vasp_str.replace('vasp',''))
copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2])
struct_widecard = os.path.join(vasp_path, 'struct-%s-%s-*' % (insert_ele,copy_str))
vasp_struct = glob.glob(struct_widecard)
Expand Down Expand Up @@ -122,12 +128,18 @@ def _cmpt_deepmd_lammps(jdata, conf_dir, supercell, insert_ele, task_name) :
if len(struct_path_list) == 0:
print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
sys.stdout.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
for ii in struct_path_list :
structure_dir = os.path.basename(ii)
lmp_log = os.path.join(ii, 'log.lammps')
natoms, epa, vpa = lammps.get_nev(lmp_log)
evac = epa * natoms - equi_epa * natoms
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
result = os.path.join(task_path,'result')
with open(result,'w') as fp:
fp.write('conf_dir:%s\n'% (conf_dir))
fp.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
for ii in struct_path_list :
structure_dir = os.path.basename(ii)
lmp_log = os.path.join(ii, 'log.lammps')
natoms, epa, vpa = lammps.get_nev(lmp_log)
evac = epa * natoms - equi_epa * natoms
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
fp.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
fp.close()

def _main() :
parser = argparse.ArgumentParser(
Expand All @@ -149,7 +161,7 @@ def _main() :

# print('# generate %s task with conf %s' % (args.TASK, args.CONF))
if args.TASK == 'vasp':
cmpt_vasp(jdata, args.CONF, args.COPY, args.ELEMENT)
cmpt_vasp(jdata, args.CONF, args.COPY, args.ELEMENT)
elif args.TASK == 'deepmd' :
cmpt_deepmd_lammps(jdata, args.CONF, args.COPY, args.ELEMENT, args.TASK)
elif args.TASK == 'deepmd-reprod' :
Expand All @@ -160,8 +172,6 @@ def _main() :
cmpt_deepmd_reprod_traj(jdata, args.CONF, args.COPY, args.ELEMENT, args.TASK)
else :
raise RuntimeError("unknow task ", args.TASK)

if __name__ == '__main__' :
_main()


2 changes: 1 addition & 1 deletion dpgen/auto_test/cmpt_05_surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def cmpt_deepmd_lammps(jdata, conf_dir, task_name, static = False) :
sys.stdout.write ("%s: \t%7.3f %8.3f %8.3f\n" % (structure_dir, evac, epa, equi_epa))
fp.write("%s:\t %7.3f %8.3f %8.3f\n" % (structure_dir, evac, epa, equi_epa))
fp.close()
if 'upload_username' in jdata.keys() and task_name=='deepm':
if 'upload_username' in jdata.keys() and task_name=='deepmd':
upload_username=jdata['upload_username']
util.insert_data('surf','deepmd',upload_username,result)

Expand Down
Loading

0 comments on commit ca01bd8

Please sign in to comment.