Skip to content

Commit 06e5959

Browse files
authored
Remove catching UnboundLocalError & refine code
1 parent 0f2f86e commit 06e5959

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

dpgen/generator/run.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def dump_to_deepmd_raw(dump, deepmd_raw, type_map, fmt='gromacs/gro', charge=Non
187187
system = dpdata.System(dump, fmt = fmt, type_map = type_map)
188188
system.to_deepmd_raw(deepmd_raw)
189189
if charge is not None:
190-
with open(os.path.join(deepmd_raw, "charge"), 'w+') as f:
190+
with open(os.path.join(deepmd_raw, "charge"), 'w') as f:
191191
f.write(str(charge))
192192

193193

@@ -1101,16 +1101,13 @@ def _make_model_devi_native_gromacs(iter_index, jdata, mdata, conf_systems):
11011101
else:
11021102
model_devi_dt = jdata['model_devi_dt']
11031103
nsteps = cur_job.get("nsteps", None)
1104-
lambdas = cur_job.get("lambdas", [])
1105-
temps = cur_job.get("temps", [])
1106-
if not lambdas:
1107-
lambdas = [1.0]
1108-
else:
1109-
for ll in lambdas:
1110-
if ll > 1:
1111-
raise RuntimeError("lambda is larger than 1.0")
1112-
if not temps:
1113-
temps = [298.0]
1104+
lambdas = cur_job.get("lambdas", [1.0])
1105+
temps = cur_job.get("temps", [298.0])
1106+
1107+
for ll in lambdas:
1108+
if ll > 1:
1109+
raise RuntimeError("lambda is larger than 1.0")
1110+
11141111
if nsteps is None:
11151112
raise RuntimeError("nsteps is None, you should set nsteps in model_devi_jobs!")
11161113
# Currently Gromacs engine is not supported for different temperatures!
@@ -2534,22 +2531,19 @@ def post_fp_gaussian (iter_index,
25342531
sys_output = glob.glob(os.path.join(work_path, "task.%s.*/output"%ss))
25352532
sys_output.sort()
25362533
for idx,oo in enumerate(sys_output) :
2537-
# TODO : UnboundLocalError sometimes occurs and I cannot figure it out.
2538-
try:
2539-
sys = dpdata.LabeledSystem(oo, fmt = 'gaussian/log')
2540-
if len(sys) > 0:
2541-
sys.check_type_map(type_map = jdata['type_map'])
2542-
if jdata.get('use_atom_pref', False):
2543-
sys.data['atom_pref'] = np.load(os.path.join(os.path.dirname(oo), "atom_pref.npy"))
2544-
if idx == 0:
2545-
if jdata.get('use_clusters', False):
2546-
all_sys = dpdata.MultiSystems(sys, type_map = jdata['type_map'])
2547-
else:
2548-
all_sys = sys
2534+
# TODO : UnboundLocalError sometimes occurs when parsing gaussian log
2535+
sys = dpdata.LabeledSystem(oo, fmt = 'gaussian/log')
2536+
if len(sys) > 0:
2537+
sys.check_type_map(type_map = jdata['type_map'])
2538+
if jdata.get('use_atom_pref', False):
2539+
sys.data['atom_pref'] = np.load(os.path.join(os.path.dirname(oo), "atom_pref.npy"))
2540+
if idx == 0:
2541+
if jdata.get('use_clusters', False):
2542+
all_sys = dpdata.MultiSystems(sys, type_map = jdata['type_map'])
25492543
else:
2550-
all_sys.append(sys)
2551-
except UnboundLocalError as e:
2552-
pass
2544+
all_sys = sys
2545+
else:
2546+
all_sys.append(sys)
25532547
sys_data_path = os.path.join(work_path, 'data.%s'%ss)
25542548
all_sys.to_deepmd_raw(sys_data_path)
25552549
all_sys.to_deepmd_npy(sys_data_path, set_size = len(sys_output))

0 commit comments

Comments
 (0)