molstar / molstar

A comprehensive macromolecular library
https://molstar.org
MIT License
599 stars 140 forks source link

How does one convert an object `ref` into a `Loci` selection? #1133

Closed rtviii closed 3 weeks ago

rtviii commented 4 weeks ago

I'm trying to do something really basic: trigger a selection of a whole structure. I can't figure a way to either construct an MS query or convert a Ref to Loci. (I still don't really know how to conceptualize the state tree)

Let's say i have a structure, 5AFI loaded into the viewer. I can select/focus/highlight its individual chains no problem:

// Say, chain `A1`
    const ctx  = window.molstar_plugin;
    const data = ctx.managers.structure.hierarchy.current.structures[0]?.cell.obj?.data;
    const sel = Script.getStructureSelection(Q => Q.struct.generator.atomGroups({
        'chain-test': Q.core.rel.eq([Q.struct.atomProperty.macromolecular.auth_asym_id(), `A1`]),
    }), data);

    let loci = StructureSelection.toLociWithSourceUnits(sel);
    plugin.managers.interactivity.lociHighlights.highlight({ loci });

But what if i wanted to select a whole structure? I'm not:

Thanks a ton

rtviii commented 4 weeks ago

1000

arose commented 4 weeks ago

try with Q.struct.generator.all()

rtviii commented 4 weeks ago

Thanks! What if i have two structures in the tree? Say, 5AFI and 3J7Z. How do i go about selecting just the 5AFI? Best

dsehnal commented 3 weeks ago

Thanks! What if i have two structures in the tree? Say, 5AFI and 3J7Z. How do i go about selecting just the 5AFI?

One way would be to iterate over ctx.managers.structure.hierarchy.current.structures , e.g.

for (const s of plugin.managers.structure.hierarchy.current.structures) {
    const model = s.model?.cell.obj?.data;
    // check model.entry / entryId (it depends how you originally loaded your data)
}

Another ways:

rtviii commented 3 weeks ago

Got it. Thanks a lot!