Skip to content

Commit

Permalink
add option to load E0s from json
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyes319 committed Aug 8, 2024
1 parent 475a0ce commit b76a2a9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mace/tools/scripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,17 @@ def get_atomic_energies(E0s, train_collection, z_table) -> dict:
f"Could not compute average E0s if no training xyz given, error {e} occured"
) from e
else:
try:
atomic_energies_dict = ast.literal_eval(E0s)
assert isinstance(atomic_energies_dict, dict)
except Exception as e:
raise RuntimeError(f"E0s specified invalidly, error {e} occured") from e
if E0s.endswith(".json"):
logging.info(f"Loading atomic energies from {E0s}")
atomic_energies_dict = json.load(open(E0s, "r"))
else:
try:
atomic_energies_dict = ast.literal_eval(E0s)
assert isinstance(atomic_energies_dict, dict)
except Exception as e:
raise RuntimeError(
f"E0s specified invalidly, error {e} occured"
) from e
else:
raise RuntimeError(
"E0s not found in training file and not specified in command line"
Expand Down

0 comments on commit b76a2a9

Please sign in to comment.