ipymolstar
ipymolstar copied to clipboard
Setting representations
I would like to be able to drag a slider and change the representation of the residue selected by the slide. Py3dmol example here: https://colab.research.google.com/drive/1Mr-HfKB-OwSNOYl6kZjlyPt2qVhLo4xN#scrollTo=098rZ2rd2hhM
Is that possible? I can't figure out how I can set a sphere representation.
Even better would be to be able to click a residue and then change it to sphere representation.
Hi, afaik there is no sphere representation in PDBeMolstar. You can use 'spacefill' to get a similar effect. Here is an example with click interactions:
# clicking a residue to set the c-alpha atom to spacefill
view = PDBeMolstar(
hide_controls_icon=True,
hide_expand_icon=True,
hide_settings_icon=True,
hide_selection_icon=True,
hide_water=True,
molecule_id="1qyn",
select_interaction=False, # dont show local interactions on click
click_focus=False, # dont zoom on click
)
def on_click(event):
view = event["owner"]
event_data = event["new"]
data = {}
data["struct_asym_id"] = event_data["label_asym_id"]
data["residue_number"] = event_data["residueNumber"]
data |= {
"atoms": ["CA"],
"representation": "spacefill",
"representationColor": "#ff00ff",
}
color_data = {
"data": [data]
}
view.color_data = color_data
view.observe(on_click, names="click_event")
view
MolViewSpec does support spheres but doesnt have a click interaction support (yet)
Perfect, thank you! Works very well in a jupyter notebook!
Do you perhaps have any idea, why it does not work inside a marimo notebook?
I'm not sure, it looks like there is an issue with the css loading (buttons look funny), also the highlight on hover doesnt seem to work.
Perhaps you can open a separate issue for this? I dont know how to fix it though
Sounds good. Should I open the issue in this repo, or the marimo repo?
I guess this is where the magic happens?
I think its a marimo issue, I suspect its related to marimo placing output in a shadow dom
There is a similar issue here: https://github.com/marimo-team/marimo/issues/1165 We experienced something similar earlier with the panel implementation of ipymolstar: https://github.com/Jhsmit/ipymolstar/pull/13)
The code you reference is indeed where the listeners are attached but I don't think the issue is there.