Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1104 gather check json files #1112

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions openfecli/commands/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def is_results_json(fpath:os.PathLike|str)->bool:
return 'estimate' in open(fpath, 'r').read(20)


def load_results(fpath:os.PathLike|str)->dict:
def load_and_check_result(fpath:os.PathLike|str)->dict:
"""Load the data from a results JSON into a dict

Parameters
Expand All @@ -96,8 +96,25 @@ def load_results(fpath:os.PathLike|str)->dict:
import json
from gufe.tokenization import JSON_HANDLER

return json.load(open(fpath, 'r'), cls=JSON_HANDLER.decoder)
try:
result = json.load(open(fpath, 'r'), cls=JSON_HANDLER.decoder)
except FileNotFoundError:
click.echo(f"Error: {fpath} does not exist. Skipping.")
return None

if "unit_results" not in result.keys():
click.echo(f"{fpath}: No 'unit_results' found, assuming to be a failed simulation.", err=True)

if all('exception' in u for u in result['unit_results'].values()):
click.echo(f"{fpath}: Exception found in 'unit_results', assuming to be a failed simulation.", err=True)

if result['estimate'] is None:
click.echo(f"No{fpath}: No 'estimate' found, assuming to be a failed simulation", err=True)
atravitz marked this conversation as resolved.
Show resolved Hide resolved

if result['uncertainty'] is None:
click.echo(f"{fpath}: No 'uncertainty' found, assuming to be a failed simulation", err=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an edge has failed this will print all of these messages for that edge? It would be best to have a single message per edge indicating if it has failed.


return result

def get_names(result:dict) -> tuple[str, str]:
"""Get the ligand names from a unit's results data.
Expand Down Expand Up @@ -397,12 +414,9 @@ def gather(rootdir:os.PathLike|str,
legs = defaultdict(lambda: defaultdict(list))

for result_fn in result_fns:
result = load_results(result_fn)
result = load_and_check_result(result_fn)
if result is None:
continue
elif result['estimate'] is None or result['uncertainty'] is None:
click.echo(f"WARNING: Calculations for {result_fn} did not finish successfully!",
err=True)

try:
names = get_names(result)
Expand Down
Loading