-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
180 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pathlib import Path\n", | ||
"from time import sleep\n", | ||
"from ipywidgets.widgets import FloatRangeSlider\n", | ||
"from ipywidgets import interact\n", | ||
"from rdkit import RDConfig\n", | ||
"import mols2grid\n", | ||
"\n", | ||
"assert Path(RDConfig.RDDocsDir).is_dir(), \"Test data not available!\"\n", | ||
"\n", | ||
"SDF_FILE = f\"{RDConfig.RDDocsDir}/Book/data/solubility.test.sdf\"\n", | ||
"df = mols2grid.sdf_to_dataframe(SDF_FILE)\n", | ||
"\n", | ||
"# setup range slider for the solubility column `SOL`\n", | ||
"sol_range = (df[\"SOL\"].min(), df[\"SOL\"].max())\n", | ||
"slider = FloatRangeSlider(value=sol_range, min=sol_range[0], max=sol_range[1], step=.5)\n", | ||
"\n", | ||
"# generate the grid\n", | ||
"grid = mols2grid.MolGrid(df, size=(120, 100))\n", | ||
"view = grid.display(n_items_per_page=12)\n", | ||
"\n", | ||
"# add interactive callback that filters the grid on slider interaction\n", | ||
"@interact(solubility=slider)\n", | ||
"def filter_grid(solubility):\n", | ||
" results = grid.dataframe.query(\n", | ||
" \"@solubility[0] <= SOL <= @solubility[1]\"\n", | ||
" )\n", | ||
" return grid.filter_by_index(results.index)\n", | ||
"\n", | ||
"# display view\n", | ||
"view" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# manually trigger interactive filtering on solubility.\n", | ||
"# should display mols at index 68, 86, 115... etc. on the cell above\n", | ||
"slider.value = (0, 1)\n", | ||
"# give enough time for the callback and RDKit.js to do their thing\n", | ||
"sleep(3)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.