diff --git a/README.md b/README.md index 8225401..a16a829 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,29 @@ view = PDBeMolstar(molecule_id='1qyn', theme='light', hide_water=True) view ``` +Loading local data, hiding the buttons: + +```python +from pathlib import Path +fpth = Path().resolve() / 'assets' / '6vsb.bcif' +custom_data = { + 'data': fpth.read_bytes(), + 'format': 'cif', + 'binary': True, + } +view = PDBeMolstar( + custom_data=custom_data, + hide_controls_icon=True, + hide_expand_icon=True, + hide_settings_icon=True, + hide_selection_icon=True, + hide_animation_icon=True, + hide_water=True, + hide_carbs=True, +) +view +``` + See the example notebook for more advanced usage. Solara example code can be found [here](https://github.com/Jhsmit/ploomber-solara-ipymolstar) diff --git a/assets/6vsb.bcif b/assets/6vsb.bcif new file mode 100644 index 0000000..cfb259a Binary files /dev/null and b/assets/6vsb.bcif differ diff --git a/example.ipynb b/example.ipynb index f8eacda..f3d3b76 100644 --- a/example.ipynb +++ b/example.ipynb @@ -12,7 +12,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ "view = PDBeMolstar(\n", @@ -25,6 +27,28 @@ "view" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# load local files via custom_data\n", + "from pathlib import Path \n", + "fpth = Path().resolve() / 'assets' / '6vsb.bcif'\n", + "custom_data = {\n", + " 'data': fpth.read_bytes(),\n", + " 'format': 'cif',\n", + " 'binary': True,\n", + " }\n", + "view = PDBeMolstar(\n", + " custom_data=custom_data, \n", + " hide_water=True,\n", + " hide_carbs=True,\n", + ")\n", + "view" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/src/ipymolstar/widget.js b/src/ipymolstar/widget.js index 0bcb8b2..862b461 100644 --- a/src/ipymolstar/widget.js +++ b/src/ipymolstar/widget.js @@ -76,10 +76,22 @@ function getHideCanvasControls(model) { return hideCanvasControls; } +function getCustomData(model) { + var customData = model.get("custom_data"); + + if (customData && 'data' in customData) { + var url = URL.createObjectURL(new Blob([customData.data])); + customData.url = url; + delete customData.data; + } + + return customData; +} + function getOptions(model) { var options = { moleculeId: model.get("molecule_id"), - customData: model.get("custom_data"), + customData: getCustomData(model), assemblyId: model.get("assembly_id"), defaultPreset: model.get("default_preset"), ligandView: model.get("ligand_view"), @@ -184,7 +196,6 @@ function render({ model, el }) { viewerInstance.events.loadComplete.subscribe(() => { // trigger callabacks which need to be called after loading - console.log("load complete"); Object.values(callbacksLoadComplete).forEach((callback) => callback()); }); diff --git a/tests/test_notebook.ipynb b/tests/test_notebook.ipynb index d68ff26..2519019 100644 --- a/tests/test_notebook.ipynb +++ b/tests/test_notebook.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -29,25 +29,9 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c716fd207a7642c3a8148d6429c0f456", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "VBox(children=(PDBeMolstar(bg_color='#F7F7F7', height='200px', molecule_id='1qyn'), PDBeMolstar(bg_color='#F7F…" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "\n", "v1 = PDBeMolstar(molecule_id='1qyn', height=\"200px\")\n", @@ -65,25 +49,9 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f20a9b627be1495a8680c6deb41aecfc", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "PDBeMolstar(bg_color='#F7F7F7', height='150px', molecule_id='1qyn')" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "v = PDBeMolstar(molecule_id='1qyn', height='150px')\n", "v" @@ -91,7 +59,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -108,25 +76,9 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "81d95973cf31465eac4767d2043a203f", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "PDBeMolstar(bg_color='#F7F7F7', custom_data={'url': 'https://www.ebi.ac.uk/pdbe/model-server/v1/1cbs/atoms?lab…" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "custom_data = dict(url='https://www.ebi.ac.uk/pdbe/model-server/v1/1cbs/atoms?label_entity_id=1&auth_asym_id=A&encoding=bcif', format='cif', binary=True)\n", "v = PDBeMolstar(custom_data=custom_data, height='150px')\n", @@ -135,12 +87,12 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "new_custom_data = dict(url='https://www.ebi.ac.uk/pdbe/model-server/v1/1qyn/atoms?label_entity_id=1&auth_asym_id=A&encoding=bcif', format='cif', binary=True)\n", - "v.cumstom_data = new_custom_data" + "v.custom_data = new_custom_data" ] }, { @@ -148,7 +100,26 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "from pathlib import Path \n", + "fpth = Path().resolve().parent / 'assets' / '6vsb.bcif'\n", + "custom_data = {\n", + " 'data': fpth.read_bytes(),\n", + " 'format': 'cif',\n", + " 'binary': True,\n", + " }\n", + "view = PDBeMolstar(\n", + " custom_data=custom_data, \n", + " hide_controls_icon=True, \n", + " hide_expand_icon=True, \n", + " hide_settings_icon=True, \n", + " hide_selection_icon=True, \n", + " hide_animation_icon=True,\n", + " hide_water=True,\n", + " hide_carbs=True,\n", + ")\n", + "view" + ] } ], "metadata": {