diff --git a/example.ipynb b/example.ipynb index 13e42e3..34f5188 100644 --- a/example.ipynb +++ b/example.ipynb @@ -2,149 +2,97 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e372fdbd91934f4b973c43d1c7a1eb5a", + "model_id": "898f20dddae440c8aa41c8197975bef7", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "PDBeMolstar(molecule_id='1onf')" + "PDBeMolstar(bg_color='#111111', hide_water=True, lighting='metallic', loading_overlay=True, molecule_id='1qyn'…" ] }, - "execution_count": 2, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from ipymolstar import PDBeMolstar\n", - "import pathlib\n", - "import anywidget\n", - "import traitlets\n", "\n", - "c = PDBeMolstar(molecule_id='1onf')\n", - "c" + "view = PDBeMolstar(molecule_id='1qyn', theme='dark', \n", + " hide_water=True, visual_style='cartoon',\n", + " lighting='metallic',hide_expand_icon=False,hide_controls_icon=False,\n", + " hide_controls=False, sequence_panel=True, pdbe_link=False, \n", + " loading_overlay=True, expanded=False,\n", + " )\n", + "\n", + "view" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "\t\tmoleculeId: model.get('molecule_id')" + "data = [{\n", + " 'entity_id': '1',\n", + " 'struct_asym_id': 'A',\n", + " 'start_residue_number': 10,\n", + " 'end_residue_number': 15\n", + "}]\n", + "\n", + "view.focus(data)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "data_dict = {\n", + " 'data': [{\n", + " 'entity_id': '1',\n", + " 'struct_asym_id': 'A',\n", + " 'start_residue_number': 10,\n", + " 'end_residue_number': 15\n", + " }]\n", + "}\n", + "\n", + "view.highlight(data_dict)" + ] }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 4, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@import url('https://www.ebi.ac.uk/pdbe/pdb-component-library/css/pdbe-molstar-light-3.1.3.css');\n", - "\n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "c52928444c8840f1b178d284843f787c", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "PDBeMolstar(custom_data={'url': 'http://localhost:8888/files/assets/1qyn.pdb?_xsrf=2%7Cc1810e12%7C8a144937b5ea…" - ] - }, - "execution_count": 90, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "import pathlib\n", - "\n", - "import anywidget\n", - "import traitlets\n", - "from pathlib import Path\n", - "\n", - "\n", - "__file__ = Path().resolve() / 'src' / 'ipymolstar' / 'script.py'\n", - "\n", - "custom_data = { \"url\": \"http://localhost:8888/files/assets/1qyn.pdb?_xsrf=2%7Cc1810e12%7C8a144937b5ea77b35b1a4a393c7ee119%7C1707130076\", \"format\": \"pdb\" }\n", - "\n", - "class PDBeMolstar(anywidget.AnyWidget):\n", - " _esm = pathlib.Path(__file__).parent / \"widget.js\"\n", - " _css = pathlib.Path(__file__).parent / \"widget.css\"\n", - " value = traitlets.Int(0).tag(sync=True)\n", - "\n", - " molecule_id = traitlets.Unicode().tag(sync=True)\n", - " custom_data = traitlets.Dict().tag(sync=True)\n", - "\n", - " bg_color = traitlets.Unicode(\"#F7F7F7\").tag(sync=True)\n", - "\n", - " spin = traitlets.Bool(False).tag(sync=True)\n", - "\n", - " hide_polymer = traitlets.Bool(False).tag(sync=True)\n", - " hide_water = traitlets.Bool(False).tag(sync=True)\n", - " hide_heteroatoms = traitlets.Bool(False).tag(sync=True)\n", - " hide_carbs = traitlets.Bool(False).tag(sync=True)\n", - " hide_non_standard = traitlets.Bool(False).tag(sync=True)\n", - " hide_coarse = traitlets.Bool(False).tag(sync=True)\n", - "\n", - " _select = traitlets.Dict().tag(sync=True)\n", - "\n", - " # def __init__(self, *args, **kwargs):\n", - " # print(self._css)\n", - " # _css = (pathlib.Path(__file__).parent / \"widget.css\").read_text()\n", - " # super().__init__(*args, _css=_css, **kwargs)\n", - " \n", - " def color(self, data, non_selected_color=None):\n", - " \"\"\"\n", - " Alias for PDBE Molstar's `select` method.\n", - "\n", - " See https://github.com/molstar/pdbe-molstar/wiki/3.-Helper-Methods for parameter\n", - " details\n", - " \"\"\"\n", - "\n", - " self._select = {\"data\": data, \"nonSelectedColor\": non_selected_color}\n", - "\n", - "\n", - "view = PDBeMolstar(custom_data=custom_data, hide_water=True)\n", - "view" + "view.clear_highlight()" ] }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "data = [{\n", - " 'start_residue_number': 10,\n", - " 'end_residue_number': 150,\n", + " 'start_residue_number': 0,\n", + " 'end_residue_number': 200,\n", " 'struct_asym_id': 'A',\n", - " 'color': {'r': 255, 'g': 215, 'b': 0},\n", + " 'color': {'r': 100, 'g': 150, 'b': 120},\n", " 'focus': False,\n", " },\n", " {\n", " 'start_residue_number': 30,\n", - " 'end_residue_number': 200,\n", + " 'end_residue_number': 190,\n", " 'struct_asym_id': 'B',\n", " 'color': {'r': 213, 'g': 52, 'b': 235},\n", " 'focus': False,\n", @@ -155,7 +103,93 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'1.28.0'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import solara\n", + "solara.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "view.visual_style='cartoon'" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'molecular-surface'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "view.visual_style" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'plastic'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "view.lighting " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "view.lighting = 'metallic'" + ] + }, + { + "cell_type": "code", + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -164,11 +198,25 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ - "view.spin = True" + "view.spin = False" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "data = [{\n", + " 'entity_id': '1',\n", + " 'struct_asym_id': 'A',\n", + " 'start_residue_number': 10,\n", + " 'end_residue_number': 15\n", + "}]\n" ] }, { @@ -188,7 +236,7 @@ } ], "source": [ - "view.spin" + "view.spin = True" ] }, {