|
23 | 23 | "outputs": [], |
24 | 24 | "source": [ |
25 | 25 | "import numpy as np\n", |
26 | | - "import glob\n", |
27 | | - "import json\n", |
28 | | - "import csv\n", |
29 | 26 | "import os\n", |
30 | 27 | "import pathlib\n", |
31 | | - "from typing import Literal, List\n", |
| 28 | + "from typing import List\n", |
32 | 29 | "from gufe.tokenization import JSON_HANDLER\n", |
33 | 30 | "import pandas as pd\n", |
34 | 31 | "from openff.units import unit\n", |
|
219 | 216 | { |
220 | 217 | "cell_type": "code", |
221 | 218 | "execution_count": 6, |
| 219 | + "id": "30faf828", |
| 220 | + "metadata": {}, |
| 221 | + "outputs": [], |
| 222 | + "source": [ |
| 223 | + "def error_std(r):\n", |
| 224 | + " \"\"\"\n", |
| 225 | + " Calculate the error of the estimate as the std of the repeats\n", |
| 226 | + " \"\"\"\n", |
| 227 | + " return np.std([v[0].m for v in r[\"overall\"]])\n", |
| 228 | + "\n", |
| 229 | + "def error_mbar(r):\n", |
| 230 | + " \"\"\"\n", |
| 231 | + " Calculate the error of the estimate using the reported MBAR errors.\n", |
| 232 | + "\n", |
| 233 | + " This also takes into account that repeats may have been run for this edge by using the average MBAR error\n", |
| 234 | + " \"\"\"\n", |
| 235 | + " complex_errors = [x[1].m for x in r[\"complex\"]]\n", |
| 236 | + " solvent_errors = [x[1].m for x in r[\"solvent\"]]\n", |
| 237 | + " return math.sqrt(np.mean(complex_errors)**2 + np.mean(solvent_errors)**2)" |
| 238 | + ] |
| 239 | + }, |
| 240 | + { |
| 241 | + "cell_type": "code", |
| 242 | + "execution_count": 7, |
222 | 243 | "id": "411fe035-2ae2-4f98-9bab-19764af724ce", |
223 | 244 | "metadata": {}, |
224 | 245 | "outputs": [], |
|
232 | 253 | " Dict of legs to write out.\n", |
233 | 254 | " \"\"\"\n", |
234 | 255 | " data = []\n", |
| 256 | + " # check the type of error which should be used based on the number of repeats\n", |
| 257 | + " repeats = {len(v['overall']) for v in legs.values()}\n", |
| 258 | + " error_func = error_mbar if 1 in repeats else error_std\n", |
235 | 259 | " for ligpair, results in sorted(legs.items()):\n", |
236 | 260 | " ddg = np.mean([v[0].m for v in results[\"overall\"]])\n", |
237 | | - " # Use standard deviation as error when more than 1 repeat\n", |
238 | | - " if len(results[\"overall\"]) > 1:\n", |
239 | | - " error = np.std([v[0].m for v in results[\"overall\"]])\n", |
240 | | - " if len(results[\"overall\"]) == 1:\n", |
241 | | - " complex_error = results[\"complex\"][0][1].m\n", |
242 | | - " solvent_error = results[\"solvent\"][0][1].m\n", |
243 | | - " error = math.sqrt(complex_error**2 + solvent_error**2)\n", |
| 261 | + " error = error_func(results)\n", |
244 | 262 | " m, u = format_estimate_uncertainty(ddg, error, unc_prec=2)\n", |
245 | 263 | " data.append((ligpair[0], ligpair[1], m, u))\n", |
246 | 264 | "\n", |
|
250 | 268 | }, |
251 | 269 | { |
252 | 270 | "cell_type": "code", |
253 | | - "execution_count": 7, |
| 271 | + "execution_count": 8, |
254 | 272 | "id": "213f1c7b-185f-403b-a98c-22d31a5e60e5", |
255 | 273 | "metadata": {}, |
256 | 274 | "outputs": [], |
|
263 | 281 | " legs : dict\n", |
264 | 282 | " Dict of legs to write out.\n", |
265 | 283 | " \"\"\"\n", |
266 | | - " import networkx as nx\n", |
267 | | - " import numpy as np\n", |
268 | | - " from cinnabar.stats import mle\n", |
269 | 284 | "\n", |
270 | 285 | " DDGs = _generate_ddg(legs)\n", |
271 | 286 | " fe_results = []\n", |
|
296 | 311 | }, |
297 | 312 | { |
298 | 313 | "cell_type": "code", |
299 | | - "execution_count": 8, |
| 314 | + "execution_count": 9, |
300 | 315 | "id": "24dfaef3-92ac-4602-85d4-400b8e6bd4cf", |
301 | 316 | "metadata": {}, |
302 | 317 | "outputs": [], |
|
322 | 337 | }, |
323 | 338 | { |
324 | 339 | "cell_type": "code", |
325 | | - "execution_count": 9, |
| 340 | + "execution_count": 10, |
326 | 341 | "id": "3b81c26b-4e3d-4bca-bfb1-4f72c75ec1bf", |
327 | 342 | "metadata": {}, |
328 | 343 | "outputs": [ |
329 | 344 | { |
330 | 345 | "name": "stderr", |
331 | 346 | "output_type": "stream", |
332 | 347 | "text": [ |
333 | | - "/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", |
| 348 | + "/Users/joshua/mambaforge/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", |
334 | 349 | "\n", |
335 | 350 | "Due to the on going maintenance burden of keeping command line application\n", |
336 | 351 | "wrappers up to date, we have decided to deprecate and eventually remove these\n", |
|
360 | 375 | }, |
361 | 376 | { |
362 | 377 | "cell_type": "code", |
363 | | - "execution_count": 10, |
| 378 | + "execution_count": 11, |
364 | 379 | "id": "46996a74-709c-41f2-ac39-0f77fb33371e", |
365 | 380 | "metadata": {}, |
366 | 381 | "outputs": [], |
|
371 | 386 | }, |
372 | 387 | { |
373 | 388 | "cell_type": "code", |
374 | | - "execution_count": 11, |
375 | | - "id": "d1a6ad61-1e5a-4d8a-9067-9ed428ef145c", |
| 389 | + "execution_count": 12, |
| 390 | + "id": "b2b6fdf0", |
376 | 391 | "metadata": {}, |
377 | 392 | "outputs": [ |
378 | 393 | { |
|
414 | 429 | " <th>1</th>\n", |
415 | 430 | " <td>1</td>\n", |
416 | 431 | " <td>7a</td>\n", |
417 | | - " <td>0.65</td>\n", |
418 | | - " <td>0.86</td>\n", |
| 432 | + " <td>0.6</td>\n", |
| 433 | + " <td>1.5</td>\n", |
419 | 434 | " </tr>\n", |
420 | 435 | " <tr>\n", |
421 | 436 | " <th>2</th>\n", |
422 | 437 | " <td>1</td>\n", |
423 | 438 | " <td>7b</td>\n", |
424 | | - " <td>0.15</td>\n", |
425 | | - " <td>0.42</td>\n", |
| 439 | + " <td>0.1</td>\n", |
| 440 | + " <td>1.5</td>\n", |
426 | 441 | " </tr>\n", |
427 | 442 | " <tr>\n", |
428 | 443 | " <th>3</th>\n", |
429 | 444 | " <td>7a</td>\n", |
430 | 445 | " <td>7b</td>\n", |
431 | 446 | " <td>1.9</td>\n", |
432 | | - " <td>2.1</td>\n", |
| 447 | + " <td>1.5</td>\n", |
433 | 448 | " </tr>\n", |
434 | 449 | " </tbody>\n", |
435 | 450 | "</table>\n", |
|
438 | 453 | "text/plain": [ |
439 | 454 | " ligand_i ligand_j DDG(i->j) (kcal/mol) uncertainty (kcal/mol)\n", |
440 | 455 | "0 1 25 2.0 1.6\n", |
441 | | - "1 1 7a 0.65 0.86\n", |
442 | | - "2 1 7b 0.15 0.42\n", |
443 | | - "3 7a 7b 1.9 2.1" |
| 456 | + "1 1 7a 0.6 1.5\n", |
| 457 | + "2 1 7b 0.1 1.5\n", |
| 458 | + "3 7a 7b 1.9 1.5" |
444 | 459 | ] |
445 | 460 | }, |
446 | | - "execution_count": 11, |
| 461 | + "execution_count": 12, |
447 | 462 | "metadata": {}, |
448 | 463 | "output_type": "execute_result" |
449 | 464 | } |
|
464 | 479 | }, |
465 | 480 | { |
466 | 481 | "cell_type": "code", |
467 | | - "execution_count": 12, |
| 482 | + "execution_count": 13, |
468 | 483 | "id": "22e25226-0073-40a4-9cbc-da802a29fc25", |
469 | 484 | "metadata": {}, |
470 | 485 | "outputs": [], |
|
475 | 490 | }, |
476 | 491 | { |
477 | 492 | "cell_type": "code", |
478 | | - "execution_count": 13, |
479 | | - "id": "519a7e3a-f092-4dc3-ab61-5697091954cd", |
| 493 | + "execution_count": 14, |
| 494 | + "id": "cda55931", |
480 | 495 | "metadata": {}, |
481 | 496 | "outputs": [ |
482 | 497 | { |
|
509 | 524 | " <tr>\n", |
510 | 525 | " <th>0</th>\n", |
511 | 526 | " <td>1</td>\n", |
512 | | - " <td>-0.636553</td>\n", |
513 | | - " <td>0.462091</td>\n", |
| 527 | + " <td>-0.675</td>\n", |
| 528 | + " <td>0.664267</td>\n", |
514 | 529 | " </tr>\n", |
515 | 530 | " <tr>\n", |
516 | 531 | " <th>1</th>\n", |
517 | 532 | " <td>25</td>\n", |
518 | | - " <td>1.363447</td>\n", |
519 | | - " <td>1.222100</td>\n", |
| 533 | + " <td>1.325</td>\n", |
| 534 | + " <td>1.311964</td>\n", |
520 | 535 | " </tr>\n", |
521 | 536 | " <tr>\n", |
522 | 537 | " <th>2</th>\n", |
523 | 538 | " <td>7a</td>\n", |
524 | | - " <td>-0.319831</td>\n", |
525 | | - " <td>0.720921</td>\n", |
| 539 | + " <td>-0.875</td>\n", |
| 540 | + " <td>0.903466</td>\n", |
526 | 541 | " </tr>\n", |
527 | 542 | " <tr>\n", |
528 | 543 | " <th>3</th>\n", |
529 | 544 | " <td>7b</td>\n", |
530 | | - " <td>-0.407063</td>\n", |
531 | | - " <td>0.535312</td>\n", |
| 545 | + " <td>0.225</td>\n", |
| 546 | + " <td>0.903466</td>\n", |
532 | 547 | " </tr>\n", |
533 | 548 | " </tbody>\n", |
534 | 549 | "</table>\n", |
535 | 550 | "</div>" |
536 | 551 | ], |
537 | 552 | "text/plain": [ |
538 | 553 | " ligand DG (kcal/mol) uncertainty (kcal/mol)\n", |
539 | | - "0 1 -0.636553 0.462091\n", |
540 | | - "1 25 1.363447 1.222100\n", |
541 | | - "2 7a -0.319831 0.720921\n", |
542 | | - "3 7b -0.407063 0.535312" |
| 554 | + "0 1 -0.675 0.664267\n", |
| 555 | + "1 25 1.325 1.311964\n", |
| 556 | + "2 7a -0.875 0.903466\n", |
| 557 | + "3 7b 0.225 0.903466" |
543 | 558 | ] |
544 | 559 | }, |
545 | | - "execution_count": 13, |
| 560 | + "execution_count": 14, |
546 | 561 | "metadata": {}, |
547 | 562 | "output_type": "execute_result" |
548 | 563 | } |
|
561 | 576 | }, |
562 | 577 | { |
563 | 578 | "cell_type": "code", |
564 | | - "execution_count": 14, |
| 579 | + "execution_count": 15, |
565 | 580 | "id": "8b2c1dd8-ffa3-4585-94a7-4a1ed1454f30", |
566 | 581 | "metadata": {}, |
567 | 582 | "outputs": [], |
|
572 | 587 | }, |
573 | 588 | { |
574 | 589 | "cell_type": "code", |
575 | | - "execution_count": 15, |
| 590 | + "execution_count": 16, |
576 | 591 | "id": "08b72901-9c71-460b-b5da-9fb4a35e07f7", |
577 | 592 | "metadata": {}, |
578 | 593 | "outputs": [ |
|
975 | 990 | "35 0.0 " |
976 | 991 | ] |
977 | 992 | }, |
978 | | - "execution_count": 15, |
| 993 | + "execution_count": 16, |
979 | 994 | "metadata": {}, |
980 | 995 | "output_type": "execute_result" |
981 | 996 | } |
982 | 997 | ], |
983 | 998 | "source": [ |
984 | 999 | "df_raw" |
985 | 1000 | ] |
986 | | - }, |
987 | | - { |
988 | | - "cell_type": "code", |
989 | | - "execution_count": null, |
990 | | - "id": "ae092ba5-3263-4e39-bc7d-82e8f1e1f58c", |
991 | | - "metadata": {}, |
992 | | - "outputs": [], |
993 | | - "source": [] |
994 | 1001 | } |
995 | 1002 | ], |
996 | 1003 | "metadata": { |
997 | 1004 | "kernelspec": { |
998 | | - "display_name": "Python 3 (ipykernel)", |
| 1005 | + "display_name": "septop", |
999 | 1006 | "language": "python", |
1000 | 1007 | "name": "python3" |
1001 | 1008 | }, |
|
1009 | 1016 | "name": "python", |
1010 | 1017 | "nbconvert_exporter": "python", |
1011 | 1018 | "pygments_lexer": "ipython3", |
1012 | | - "version": "3.12.10" |
| 1019 | + "version": "3.12.11" |
1013 | 1020 | } |
1014 | 1021 | }, |
1015 | 1022 | "nbformat": 4, |
|
0 commit comments