|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "7fbf1482-25ca-427b-a881-af88a983461c", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import numpy as np\n", |
| 11 | + "import glob\n", |
| 12 | + "import json\n", |
| 13 | + "import csv\n", |
| 14 | + "from gufe.tokenization import JSON_HANDLER" |
| 15 | + ] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "code", |
| 19 | + "execution_count": 2, |
| 20 | + "id": "ac321210-9974-46e1-ab85-e1a2f0eaa721", |
| 21 | + "metadata": {}, |
| 22 | + "outputs": [], |
| 23 | + "source": [ |
| 24 | + "def load_results(f):\n", |
| 25 | + " # path to deserialized results\n", |
| 26 | + " with open(f, \"r\") as fd:\n", |
| 27 | + " result = json.load(fd, cls=JSON_HANDLER.decoder)\n", |
| 28 | + " return result" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": 3, |
| 34 | + "id": "d6ea9187-6a47-4438-9e2b-2a06c9c7c657", |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [], |
| 37 | + "source": [ |
| 38 | + "def extract(results_0, results_1, results_2, output):\n", |
| 39 | + " files_0 = glob.glob(f\"{results_0}/*.json\")\n", |
| 40 | + " files_1 = glob.glob(f\"{results_1}/*.json\")\n", |
| 41 | + " files_2 = glob.glob(f\"{results_2}/*.json\")\n", |
| 42 | + " with open(output, 'w', newline='') as csvfile:\n", |
| 43 | + " writer = csv.writer(\n", |
| 44 | + " csvfile,\n", |
| 45 | + " delimiter=\"\\t\",\n", |
| 46 | + " lineterminator=\"\\n\", # to exactly reproduce previous, prefer \"\\r\\n\"\n", |
| 47 | + " )\n", |
| 48 | + " writer.writerow([\"ligand\", \"DG(i->j) (kcal/mol)\",\n", |
| 49 | + " \"uncertainty (kcal/mol)\"])\n", |
| 50 | + " for file in files_0:\n", |
| 51 | + " json_0 = load_results(file)\n", |
| 52 | + " dg_0 = json_0[\"estimate\"].magnitude\n", |
| 53 | + " try:\n", |
| 54 | + " file_1 = f\"{results_1}/{file.split(\"/\")[-1]}\"\n", |
| 55 | + " file_2 = f\"{results_2}/{file.split(\"/\")[-1]}\"\n", |
| 56 | + " json_1 = load_results(file_1)\n", |
| 57 | + " json_2 = load_results(file_2)\n", |
| 58 | + " dg_1 = json_1[\"estimate\"].magnitude\n", |
| 59 | + " dg_2 = json_2[\"estimate\"].magnitude\n", |
| 60 | + " dgs = [dg_0, dg_1, dg_2]\n", |
| 61 | + " dg = np.mean(dgs)\n", |
| 62 | + " dg_error = np.std(dgs)\n", |
| 63 | + " writer.writerow([file.split('/')[-1].split('.')[0], round(dg, 2), round(dg_error, 2)])\n", |
| 64 | + " except FileNotFoundError:\n", |
| 65 | + " continue" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "code", |
| 70 | + "execution_count": null, |
| 71 | + "id": "6d553fd5-3f4a-4a2d-ad7d-542b31b4f9fa", |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [ |
| 74 | + { |
| 75 | + "name": "stderr", |
| 76 | + "output_type": "stream", |
| 77 | + "text": [ |
| 78 | + "/Users/hannahbaumann/miniforge3/envs/septop/lib/python3.12/site-packages/Bio/Application/__init__.py:39: BiopythonDeprecationWarning: The Bio.Application modules and modules relying on it have been deprecated.\n", |
| 79 | + "\n", |
| 80 | + "Due to the on going maintenance burden of keeping command line application\n", |
| 81 | + "wrappers up to date, we have decided to deprecate and eventually remove these\n", |
| 82 | + "modules.\n", |
| 83 | + "\n", |
| 84 | + "We instead now recommend building your command line and invoking it directly\n", |
| 85 | + "with the subprocess module.\n", |
| 86 | + " warnings.warn(\n" |
| 87 | + ] |
| 88 | + } |
| 89 | + ], |
| 90 | + "source": [ |
| 91 | + "extract('results_0', 'results_1', 'results_2', 'ddg.tsv')" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": null, |
| 97 | + "id": "9cb87ef5-eca0-42bd-9265-e8b4d3d9f7a0", |
| 98 | + "metadata": {}, |
| 99 | + "outputs": [], |
| 100 | + "source": [] |
| 101 | + } |
| 102 | + ], |
| 103 | + "metadata": { |
| 104 | + "kernelspec": { |
| 105 | + "display_name": "Python 3 (ipykernel)", |
| 106 | + "language": "python", |
| 107 | + "name": "python3" |
| 108 | + }, |
| 109 | + "language_info": { |
| 110 | + "codemirror_mode": { |
| 111 | + "name": "ipython", |
| 112 | + "version": 3 |
| 113 | + }, |
| 114 | + "file_extension": ".py", |
| 115 | + "mimetype": "text/x-python", |
| 116 | + "name": "python", |
| 117 | + "nbconvert_exporter": "python", |
| 118 | + "pygments_lexer": "ipython3", |
| 119 | + "version": "3.12.10" |
| 120 | + } |
| 121 | + }, |
| 122 | + "nbformat": 4, |
| 123 | + "nbformat_minor": 5 |
| 124 | +} |
0 commit comments