Skip to content

Commit ca01bd8

Browse files
authored
Merge pull request #200 from deepmodeling/devel
merge devel to master
2 parents 73c3c35 + 6dacfad commit ca01bd8

File tree

80 files changed

+4089
-1065
lines changed

Some content is hidden

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

80 files changed

+4089
-1065
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
language: python
22
python:
3-
- "3.6.3"
4-
- "3.6-dev" # 3.6 development branch
3+
- "3.6"
4+
- "3.7"
55
# command to install dependencies
66
env:
77
matrix:
8-
- PYMATGEN_VERSION=2017.9.1
9-
- PYMATGEN_VERSION=2018.1.19
108
- PYMATGEN_VERSION=2019.1.13
119
- PYMATGEN_VERSION=2019.7.30
1210
before_install:

README.md

Lines changed: 348 additions & 7 deletions
Large diffs are not rendered by default.

dpgen/auto_test/cmpt_00_equi.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,43 @@ def comput_e_shift(poscar, task_name) :
2121
ener_shift += a_natoms[ii] * ener
2222
return ener_shift
2323

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

3430
lmp_path = os.path.join(conf_path, task_name)
3531
log_lammps = os.path.join(lmp_path, 'log.lammps')
3632
if os.path.isfile(log_lammps):
3733
natoms, epa, vpa = lammps.get_nev(log_lammps)
38-
epa = (epa * natoms - ener_shift) / natoms
39-
if write_stable :
34+
if write_shift and len(ele_types)>1:
35+
ener_shift = comput_e_shift(poscar, task_name)
36+
shift = (epa * natoms - ener_shift) / natoms
37+
return natoms,epa,vpa,shift
38+
if len(ele_types)==1:
4039
stable_dir = 'stables'
4140
os.makedirs(stable_dir, exist_ok=True)
4241
name_prefix=os.path.join(stable_dir,'%s.%s' % (ele_types[0], task_name))
4342
open(name_prefix + '.e', 'w').write('%.16f\n' % (epa))
4443
open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa))
45-
return natoms, epa, vpa
44+
return natoms, epa, vpa , None
4645
else :
47-
return None, None, None
46+
return None, None, None, None
47+
48+
def comput_vasp_nev(jdata, conf_dir, write_shift = False) :
4849

49-
def comput_vasp_nev(jdata, conf_dir, write_stable = False) :
50-
5150
conf_path = re.sub('confs', global_equi_name, conf_dir)
5251
conf_path = os.path.abspath(conf_path)
5352
poscar = os.path.join(conf_path, 'POSCAR')
54-
if write_stable :
55-
ele_types = vasp.get_poscar_types(poscar)
56-
if len(ele_types) > 1 :
57-
raise RuntimeError('stable energy and volume only for one element, current you have %s from POSCAR' % str(ele_types))
53+
ele_types = vasp.get_poscar_types(poscar)
5854

5955
if 'relax_incar' in jdata.keys():
6056
vasp_str='vasp-relax_incar'
6157
else:
6258
kspacing = jdata['vasp_params']['kspacing']
6359
vasp_str='vasp-k%.2f' % kspacing
6460

65-
ener_shift = comput_e_shift(poscar, vasp_str)
6661
vasp_path = os.path.join(conf_path, vasp_str)
6762
outcar = os.path.join(vasp_path, 'OUTCAR')
6863
# tag_fin = os.path.join(vasp_path, 'tag_finished')
@@ -72,22 +67,25 @@ def comput_vasp_nev(jdata, conf_dir, write_stable = False) :
7267
warnings.warn("incomplete job "+vasp_path+" use the last frame")
7368
if os.path.isfile(outcar):
7469
natoms, epa, vpa = vasp.get_nev(outcar)
75-
epa = (epa * natoms - ener_shift) / natoms
76-
if write_stable :
70+
if write_shift and len(ele_types)>1:
71+
ener_shift = comput_e_shift(poscar, vasp_str)
72+
shift = (epa * natoms - ener_shift) / natoms
73+
return natoms,epa,vpa,shift
74+
if len(ele_types)==1:
7775
stable_dir = 'stables'
7876
os.makedirs(stable_dir, exist_ok=True)
7977
name_prefix=os.path.join(stable_dir,'%s.'% (ele_types[0])+vasp_str)
8078
open(name_prefix + '.e', 'w').write('%.16f\n' % (epa))
8179
open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa))
82-
return natoms, epa, vpa
80+
return natoms, epa, vpa, None
8381
else :
84-
return None, None, None
82+
return None, None, None, None
8583

8684
def _main():
8785
parser = argparse.ArgumentParser(
8886
description="cmpt 00.equi")
89-
parser.add_argument('TASK', type=str,
90-
choices = ['all', 'vasp', 'deepmd', 'meam'],
87+
parser.add_argument('TASK', type=str,
88+
choices = ['all', 'vasp', 'deepmd', 'meam'],
9189
help='the task of generation, vasp or lammps')
9290
parser.add_argument('PARAM', type=str,
9391
help='the json param')
@@ -120,4 +118,3 @@ def _main():
120118

121119
if __name__ == '__main__' :
122120
_main()
123-

dpgen/auto_test/cmpt_02_elastic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def cmpt_deepmd_lammps(jdata, conf_dir, task_name) :
104104
# et = -et / 1e4
105105
print_et(et)
106106
result = os.path.join(task_path,'result')
107-
result_et(et,conf_dir,task_path)
107+
result_et(et,conf_dir,result)
108108
if 'upload_username' in jdata.keys() and task_name=='deepmd':
109109
upload_username=jdata['upload_username']
110110
util.insert_data('elastic','deepmd',upload_username,result)

dpgen/auto_test/cmpt_03_vacancy.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def comput_e_shift(poscar, task_name) :
2323
ref_e_file = os.path.join('stables', ref_e_file)
2424
ener = float(open(ref_e_file).read())
2525
ener_shift += a_natoms[ii] * ener
26-
return ener_shift
26+
return ener_shift
2727

2828
def cmpt_vasp(jdata, conf_dir, supercell) :
2929

@@ -37,7 +37,7 @@ def cmpt_vasp(jdata, conf_dir, supercell) :
3737
equi_path = os.path.join(equi_path, vasp_str)
3838
equi_path = os.path.abspath(equi_path)
3939
equi_outcar = os.path.join(equi_path, 'OUTCAR')
40-
task_path = re.sub('confs', global_task_name, conf_dir)
40+
task_path = re.sub('confs', global_task_name, conf_dir)
4141
task_path = os.path.join(task_path, vasp_str)
4242
task_path = os.path.abspath(task_path)
4343
print("# ", task_path)
@@ -51,17 +51,23 @@ def cmpt_vasp(jdata, conf_dir, supercell) :
5151
if len(struct_path_list) == 0:
5252
print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
5353
sys.stdout.write ("Structure: \tVac_E(eV) E(eV) equi_E(eV)\n")
54-
for ii in struct_path_list :
55-
struct_poscar = os.path.join(ii, 'POSCAR')
56-
energy_shift = comput_e_shift(struct_poscar, vasp_str)
57-
structure_dir = os.path.basename(ii)
58-
outcar = os.path.join(ii, 'OUTCAR')
59-
natoms, epa, vpa = vasp.get_nev(outcar)
60-
evac = epa * natoms - equi_epa * natoms
61-
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
54+
result = os.path.join(task_path,'result')
55+
with open(result,'w') as fp:
56+
fp.write('conf_dir:%s\n'% (conf_dir))
57+
fp.write("Structure: \tVac_E(eV) E(eV) equi_E(eV)\n")
58+
for ii in struct_path_list :
59+
struct_poscar = os.path.join(ii, 'POSCAR')
60+
#energy_shift = comput_e_shift(struct_poscar, vasp_str)
61+
structure_dir = os.path.basename(ii)
62+
outcar = os.path.join(ii, 'OUTCAR')
63+
natoms, epa, vpa = vasp.get_nev(outcar)
64+
evac = epa * natoms - equi_epa * natoms
65+
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
66+
fp.write("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
67+
fp.close()
6268
# evac = epa * natoms - energy_shift
6369
# sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, energy_shift))
64-
# sys.stdout.write ("%s: %7.3f \n" % (structure_dir, evac))
70+
# sys.stdout.write ("%s: %7.3f \n" % (structure_dir, evac))
6571

6672
def cmpt_deepmd_lammps(jdata, conf_dir, supercell, task_name) :
6773
equi_path = re.sub('confs', global_equi_name, conf_dir)
@@ -82,14 +88,20 @@ def cmpt_deepmd_lammps(jdata, conf_dir, supercell, task_name) :
8288
if len(struct_path_list) == 0:
8389
print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
8490
sys.stdout.write ("Structure: \tVac_E(eV) E(eV) equi_E(eV)\n")
85-
for ii in struct_path_list :
86-
struct_poscar = os.path.join(ii, 'POSCAR')
87-
energy_shift = comput_e_shift(struct_poscar, task_name)
88-
structure_dir = os.path.basename(ii)
89-
lmp_log = os.path.join(ii, 'log.lammps')
90-
natoms, epa, vpa = lammps.get_nev(lmp_log)
91-
evac = epa * natoms - equi_epa * natoms
92-
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
91+
result = os.path.join(task_path,'result')
92+
with open(result,'w') as fp:
93+
fp.write('conf_dir:%s\n'% (conf_dir))
94+
fp.write("Structure: \tVac_E(eV) E(eV) equi_E(eV)\n")
95+
for ii in struct_path_list :
96+
struct_poscar = os.path.join(ii, 'POSCAR')
97+
#energy_shift = comput_e_shift(struct_poscar, task_name)
98+
structure_dir = os.path.basename(ii)
99+
lmp_log = os.path.join(ii, 'log.lammps')
100+
natoms, epa, vpa = lammps.get_nev(lmp_log)
101+
evac = epa * natoms - equi_epa * natoms
102+
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
103+
fp.write("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
104+
fp.close()
93105
# evac = epa * natoms - energy_shift
94106
# sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, energy_shift))
95107
# sys.stdout.write ("%s: %7.3f\n" % (structure_dir, evac))
@@ -112,15 +124,13 @@ def _main() :
112124

113125
# print('# generate %s task with conf %s' % (args.TASK, args.CONF))
114126
if args.TASK == 'vasp':
115-
cmpt_vasp(jdata, args.CONF, args.COPY)
127+
cmpt_vasp(jdata, args.CONF, args.COPY)
116128
elif args.TASK == 'deepmd' :
117129
cmpt_deepmd_lammps(jdata, args.CONF, args.COPY, args.TASK)
118130
elif args.TASK == 'meam' :
119131
cmpt_deepmd_lammps(jdata, args.CONF, args.COPY, args.TASK)
120132
else :
121133
raise RuntimeError("unknow task ", args.TASK)
122-
134+
123135
if __name__ == '__main__' :
124136
_main()
125-
126-

dpgen/auto_test/cmpt_04_interstitial.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,19 @@ def _cmpt_vasp(jdata, conf_dir, supercell, insert_ele) :
4141
struct_path_list.sort()
4242
if len(struct_path_list) == 0:
4343
print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
44-
sys.stdout.write ("Insert_ele-Struct: Inter_E(eV)\n")
45-
for ii in struct_path_list :
46-
structure_dir = os.path.basename(ii)
47-
outcar = os.path.join(ii, 'OUTCAR')
48-
natoms, epa, vpa = vasp.get_nev(outcar)
49-
evac = epa * natoms - equi_epa * natoms
50-
sys.stdout.write ("%s: %7.3f \n" % (structure_dir, evac))
44+
sys.stdout.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
45+
result = os.path.join(task_path,'result')
46+
with open(result,'w') as fp:
47+
fp.write('conf_dir:%s\n'% (conf_dir))
48+
fp.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
49+
for ii in struct_path_list :
50+
structure_dir = os.path.basename(ii)
51+
outcar = os.path.join(ii, 'OUTCAR')
52+
natoms, epa, vpa = vasp.get_nev(outcar)
53+
evac = epa * natoms - equi_epa * natoms
54+
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
55+
fp.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
56+
fp.close()
5157

5258
def cmpt_deepmd_reprod_traj(jdata, conf_dir, supercell, insert_ele, task_name) :
5359
for ii in insert_ele:
@@ -63,7 +69,7 @@ def _cmpt_deepmd_reprod_traj(jdata, conf_dir, supercell, insert_ele, task_name)
6369
conf_path = os.path.abspath(conf_dir)
6470
task_path = re.sub('confs', global_task_name, conf_path)
6571
vasp_path = os.path.join(task_path, vasp_str)
66-
lmps_path = os.path.join(task_path, task_name + vasp_str.replace('vasp',''))
72+
lmps_path = os.path.join(task_path, task_name + vasp_str.replace('vasp',''))
6773
copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2])
6874
struct_widecard = os.path.join(vasp_path, 'struct-%s-%s-*' % (insert_ele,copy_str))
6975
vasp_struct = glob.glob(struct_widecard)
@@ -122,12 +128,18 @@ def _cmpt_deepmd_lammps(jdata, conf_dir, supercell, insert_ele, task_name) :
122128
if len(struct_path_list) == 0:
123129
print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
124130
sys.stdout.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
125-
for ii in struct_path_list :
126-
structure_dir = os.path.basename(ii)
127-
lmp_log = os.path.join(ii, 'log.lammps')
128-
natoms, epa, vpa = lammps.get_nev(lmp_log)
129-
evac = epa * natoms - equi_epa * natoms
130-
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
131+
result = os.path.join(task_path,'result')
132+
with open(result,'w') as fp:
133+
fp.write('conf_dir:%s\n'% (conf_dir))
134+
fp.write ("Insert_ele-Struct: Inter_E(eV) E(eV) equi_E(eV)\n")
135+
for ii in struct_path_list :
136+
structure_dir = os.path.basename(ii)
137+
lmp_log = os.path.join(ii, 'log.lammps')
138+
natoms, epa, vpa = lammps.get_nev(lmp_log)
139+
evac = epa * natoms - equi_epa * natoms
140+
sys.stdout.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
141+
fp.write ("%s: %7.3f %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa * natoms))
142+
fp.close()
131143

132144
def _main() :
133145
parser = argparse.ArgumentParser(
@@ -149,7 +161,7 @@ def _main() :
149161

150162
# print('# generate %s task with conf %s' % (args.TASK, args.CONF))
151163
if args.TASK == 'vasp':
152-
cmpt_vasp(jdata, args.CONF, args.COPY, args.ELEMENT)
164+
cmpt_vasp(jdata, args.CONF, args.COPY, args.ELEMENT)
153165
elif args.TASK == 'deepmd' :
154166
cmpt_deepmd_lammps(jdata, args.CONF, args.COPY, args.ELEMENT, args.TASK)
155167
elif args.TASK == 'deepmd-reprod' :
@@ -160,8 +172,6 @@ def _main() :
160172
cmpt_deepmd_reprod_traj(jdata, args.CONF, args.COPY, args.ELEMENT, args.TASK)
161173
else :
162174
raise RuntimeError("unknow task ", args.TASK)
163-
175+
164176
if __name__ == '__main__' :
165177
_main()
166-
167-

dpgen/auto_test/cmpt_05_surf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def cmpt_deepmd_lammps(jdata, conf_dir, task_name, static = False) :
9696
sys.stdout.write ("%s: \t%7.3f %8.3f %8.3f\n" % (structure_dir, evac, epa, equi_epa))
9797
fp.write("%s:\t %7.3f %8.3f %8.3f\n" % (structure_dir, evac, epa, equi_epa))
9898
fp.close()
99-
if 'upload_username' in jdata.keys() and task_name=='deepm':
99+
if 'upload_username' in jdata.keys() and task_name=='deepmd':
100100
upload_username=jdata['upload_username']
101101
util.insert_data('surf','deepmd',upload_username,result)
102102

0 commit comments

Comments
 (0)