Skip to content

[WIP] cli json inspection #1055

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions openfecli/commands/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from typing import Callable, Literal
import warnings

from openfe.protocols.openmm_rfe.equil_rfe_methods import RelativeHybridTopologyProtocolResult as rfe_result
from openfe.protocols import openmm_rfe
from openfecli import OFECommandPlugin
from openfecli.clicktypes import HyphenAwareChoice

Expand Down Expand Up @@ -204,6 +202,8 @@ def _parse_raw_units(results: dict) -> list[tuple]:

def _get_ddgs(legs:dict, error_on_missing=True):
import numpy as np
from openfe.protocols.openmm_rfe.equil_rfe_methods import RelativeHybridTopologyProtocolResult as rfe_result

DDGs = []
for ligpair, vals in sorted(legs.items()):
set_vals = set(vals)
Expand Down
36 changes: 36 additions & 0 deletions openfecli/commands/peek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import click
import os
import pathlib

from openfecli import OFECommandPlugin

# Copied from gather.py - should live in utils but is slow to import right now.
def load_results(fpath:os.PathLike|str)->dict:
"""Load the data from a results JSON into a dict

Parameters
----------
fpath : os.PathLike | str
The path to deserialized results.

Returns
-------
dict
A dict containing data from the results JSON.
"""

import json
from gufe.tokenization import JSON_HANDLER
return json.load(open(fpath, 'r'), cls=JSON_HANDLER.decoder)

@click.command('peek', short_help="Print the reduced contents (omitting large data) of a results JSON.")
@click.argument('json', type=click.Path(dir_okay=False, file_okay=True, path_type=pathlib.Path), required=True)
def peek(json:pathlib.Path):

data = load_results(json)
click.echo(data.keys())

PLUGIN = OFECommandPlugin(command=peek,
section="Miscellaneous",
requires_ofe=(1,0)
)
26 changes: 26 additions & 0 deletions openfecli/tests/commands/test_peek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
from importlib import resources
import pathlib
import json
from click.testing import CliRunner

from openfecli.commands.peek import peek
from gufe.tokenization import JSON_HANDLER


@pytest.fixture
def json_file():
with resources.files('openfecli.tests.data') as d:
json_file = str(d / 'transformation.json')

return json_file

def test_peek(json_file):

runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(peek, json_file)
assert result.exit_code == 0
assert "name" in result.output


Loading