Skip to content

Commit

Permalink
cli: add --report raw option to gather
Browse files Browse the repository at this point in the history
this reports the unit estimates individually
  • Loading branch information
richardjgowers committed Nov 9, 2023
1 parent f99bec8 commit c7c251d
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions openfecli/commands/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ def _generate_bad_legs_error_message(set_vals, ligpair):
return msg


def _parse_raw_units(results: dict) -> list[tuple]:
# grab individual unit results from master results dict
# returns list of (estimate, uncertainty) tuples
pus = list(results['unit_results'].values())
return [(pu['outputs']['unit_estimate'],
pu['outputs']['unit_estimate_error'])
for pu in pus]


def _get_ddgs(legs, error_on_missing=True):
import numpy as np
DDGs = []
Expand Down Expand Up @@ -181,6 +190,21 @@ def _write_ddg(legs, writer, allow_partial):
writer.writerow([ligA, ligB, DDGhyd, hyd_unc])


def _write_raw(legs, writer):
writer.writerow(["leg", "ligand_i", "ligand_j", "DG(i->j) (kcal/mol)",
"uncertainty (kcal/mol)"])

for ligpair, vals in sorted(legs.items()):
for simtype, repeats in sorted(vals.items()):
for m, u in repeats:
if m is None:
m, u = 'NaN', 'NaN'
else:
m, u = format_estimate_uncertainty(m.m, u.m)

writer.writerow([simtype, *ligpair, m, u])


def _write_dg_raw(legs, writer, allow_partial):
writer.writerow(["leg", "ligand_i", "ligand_j", "DG(i->j) (kcal/mol)",
"uncertainty (kcal/mol)"])
Expand Down Expand Up @@ -255,7 +279,8 @@ def _write_dg_mle(legs, writer, allow_partial):
required=True)
@click.option(
'--report',
type=HyphenAwareChoice(['dg', 'ddg', 'dg-raw'], case_sensitive=False),
type=HyphenAwareChoice(['dg', 'ddg', 'dg-raw', 'raw'],
case_sensitive=False),
default="dg", show_default=True,
help=(
"What data to report. 'dg' gives maximum-likelihood estimate of "
Expand Down Expand Up @@ -325,7 +350,10 @@ def gather(rootdir, output, report, allow_partial):
except KeyError:
simtype = legacy_get_type(result_fn)

legs[names][simtype] = result['estimate'], result['uncertainty']
if report.lower() == 'raw':
legs[names][simtype] = _parse_raw_units(result)
else:
legs[names][simtype] = result['estimate'], result['uncertainty']

writer = csv.writer(
output,
Expand All @@ -340,6 +368,7 @@ def gather(rootdir, output, report, allow_partial):
'dg': _write_dg_mle,
'ddg': _write_ddg,
'dg-raw': _write_dg_raw,
'raw': _write_raw,
}[report.lower()]
writing_func(legs, writer, allow_partial)

Expand Down

0 comments on commit c7c251d

Please sign in to comment.