mirror of
https://github.com/OpenFreeEnergy/openfe.git
synced 2026-06-04 14:14:22 +08:00
Update fetch results (#779)
* update rbfe_results.tar.gz for new settings schema * re-enable test_gather tests * devscript for updating rbfe_results.tar.gz * cli: gather: rework raw gather to work off protocol_result dict this allows us to later deduplicate and remove the unit_results key from results dicts * cli: gather: update expected gather results current raw results are only one replicate, should probably have multiple repeats to test raw output * cli: gather: use \t escape code in gather raw test could instead normalise the whitespace to be more permissive... * Apply suggestions from code review Co-authored-by: Mike Henry <11765982+mikemhenry@users.noreply.github.com> * rerun ci --------- Co-authored-by: Mike Henry <11765982+mikemhenry@users.noreply.github.com>
This commit is contained in:
57
devtools/data/fix_rbfe_results.py
Normal file
57
devtools/data/fix_rbfe_results.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""A script to fix up rbfe_results.tar.gz
|
||||
|
||||
Useful if Settings are ever changed in a backwards-incompatible way
|
||||
|
||||
Will expect "rbfe_results.tar.gz" in this directory, will overwrite this file
|
||||
"""
|
||||
from gufe.tokenization import JSON_HANDLER
|
||||
import glob
|
||||
import json
|
||||
from openfe.protocols import openmm_rfe
|
||||
import os.path
|
||||
import tarfile
|
||||
|
||||
|
||||
def untar(fn):
|
||||
"""extract tarfile called *fn*"""
|
||||
with tarfile.open(fn) as f:
|
||||
f.extractall()
|
||||
|
||||
|
||||
def retar(loc, name):
|
||||
"""create tar.gz called *name* of directory *loc*"""
|
||||
with tarfile.open(name, mode='w:gz') as f:
|
||||
f.add(loc, arcname=os.path.basename(loc))
|
||||
|
||||
|
||||
def replace_settings(fn, new_settings):
|
||||
"""replace settings instances in *fn* with *new_settings*"""
|
||||
with open(fn, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
for k in data['protocol_result']['data']:
|
||||
data['protocol_result']['data'][k][0]['inputs']['settings'] = new_settings
|
||||
|
||||
for k in data['unit_results']:
|
||||
data['unit_results'][k]['inputs']['settings'] = new_settings
|
||||
|
||||
with open(fn, 'w') as f:
|
||||
json.dump(data, f, cls=JSON_HANDLER.encoder)
|
||||
|
||||
|
||||
def fix_rbfe_results():
|
||||
untar('rbfe_results.tar.gz')
|
||||
|
||||
# generate valid settings as defaults
|
||||
new_settings = openmm_rfe.RelativeHybridTopologyProtocol.default_settings()
|
||||
|
||||
# walk over all result jsons
|
||||
for fn in glob.glob('./results/*json'):
|
||||
# replace instances of settings within with valid settings
|
||||
replace_settings(fn, new_settings)
|
||||
|
||||
retar('results', 'rbfe_results.tar.gz')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
fix_rbfe_results()
|
||||
Reference in New Issue
Block a user