ipymolstar icon indicating copy to clipboard operation
ipymolstar copied to clipboard

Setting representations

Open ajasja opened this issue 7 months ago • 5 comments

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.

Image

ajasja avatar Apr 18 '25 11:04 ajasja

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)

Jhsmit avatar Apr 18 '25 12:04 Jhsmit

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?

Image

ajasja avatar Apr 18 '25 13:04 ajasja

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

Jhsmit avatar Apr 18 '25 14:04 Jhsmit

Sounds good. Should I open the issue in this repo, or the marimo repo?

I guess this is where the magic happens? Image

ajasja avatar Apr 18 '25 14:04 ajasja

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.

Jhsmit avatar Apr 18 '25 15:04 Jhsmit