Skip to content

Commit f1a815c

Browse files
committed
BUG FIX: handle exception of UnboundLocalError when parsing gaussian log
1 parent 4839328 commit f1a815c

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

dpgen/generator/run.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def make_train (iter_index,
407407
jinput['model']['fitting_net']['activation_function'] = model_devi_activation_func[ii][1]
408408
if len(np.array(model_devi_activation_func).shape) == 1 : # for backward compatibility, 1-dim list, not net-resolved
409409
jinput['model']['descriptor']['activation_function'] = model_devi_activation_func[ii]
410-
jinput['model']['descriptor']['activation_function'] = model_devi_activation_func[ii]
410+
jinput['model']['fitting_net']['activation_function'] = model_devi_activation_func[ii]
411411
# dump the input.json
412412
with open(os.path.join(task_path, train_input_file), 'w') as outfile:
413413
json.dump(jinput, outfile, indent = 4)
@@ -2524,18 +2524,22 @@ def post_fp_gaussian (iter_index,
25242524
sys_output = glob.glob(os.path.join(work_path, "task.%s.*/output"%ss))
25252525
sys_output.sort()
25262526
for idx,oo in enumerate(sys_output) :
2527-
sys = dpdata.LabeledSystem(oo, fmt = 'gaussian/log')
2528-
if len(sys) > 0:
2529-
sys.check_type_map(type_map = jdata['type_map'])
2530-
if jdata.get('use_atom_pref', False):
2531-
sys.data['atom_pref'] = np.load(os.path.join(os.path.dirname(oo), "atom_pref.npy"))
2532-
if idx == 0:
2533-
if jdata.get('use_clusters', False):
2534-
all_sys = dpdata.MultiSystems(sys, type_map = jdata['type_map'])
2527+
# TODO : UnboundLocalError sometimes occurs and I cannot figure it out.
2528+
try:
2529+
sys = dpdata.LabeledSystem(oo, fmt = 'gaussian/log')
2530+
if len(sys) > 0:
2531+
sys.check_type_map(type_map = jdata['type_map'])
2532+
if jdata.get('use_atom_pref', False):
2533+
sys.data['atom_pref'] = np.load(os.path.join(os.path.dirname(oo), "atom_pref.npy"))
2534+
if idx == 0:
2535+
if jdata.get('use_clusters', False):
2536+
all_sys = dpdata.MultiSystems(sys, type_map = jdata['type_map'])
2537+
else:
2538+
all_sys = sys
25352539
else:
2536-
all_sys = sys
2537-
else:
2538-
all_sys.append(sys)
2540+
all_sys.append(sys)
2541+
except UnboundLocalError as e:
2542+
pass
25392543
sys_data_path = os.path.join(work_path, 'data.%s'%ss)
25402544
all_sys.to_deepmd_raw(sys_data_path)
25412545
all_sys.to_deepmd_npy(sys_data_path, set_size = len(sys_output))

0 commit comments

Comments
 (0)