Skip to content

[BUG?] Complex selections with OR gate #804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JavierSanchez-Utges opened this issue Aug 27, 2024 · 5 comments
Closed

[BUG?] Complex selections with OR gate #804

JavierSanchez-Utges opened this issue Aug 27, 2024 · 5 comments
Labels

Comments

@JavierSanchez-Utges
Copy link

Hi, I am dealing with multiple models and complex selections and I think something is not working as expected, possibly due to the way I build my selections.

First a general question about selections:

I have generated many selections like so, and they all seemed to work so far, selecting the correct residues in the right chains in the specific model.

sel = {model: activeModel, resi: protResi, chain: protChain, resn: protResn};

Now, I am playing with AND and OR gates to do more detailed selections and I just wondered: is this first selection the same as this second one?

sel = {and:[{model: activeModel}, {resi: protResi}, {chain: protChain}, {resn: protResn}]};

The issue I have is that when I apply the model to the union of those selections I generated in the loop like so:

viewer.addStyle({or:ligandSitesHash[activeModel][ligNam]}, {cartoon:{hidden: false, color: ligColor}, stick: {hidden: false, color: ligColor, radius: stickRadius}});

The style is also applied to another model, which is unexpected, as in each one of the selections in ligandSitesHash[activeModel][ligNam] I specify the model: activeModel.

This is the array containing the different selections:

Screenshot 2024-08-27 at 10 21 47

and somehow the style is applied to another model (not 96) too.

Thanks a lot!

@JavierSanchez-Utges
Copy link
Author

I have noticed that when I pass
{model: 96, resi: 49, chain: 'A', resn: 'LEU'}
directly as the selection, the styles apply only to model 96. However, when I include multiple selections with OR like so: {or:[{model: 96, resi: 49, chain: 'A', resn: 'LEU'}, {model: 96, resi: 51, chain: 'A', resn: 'THR'}]}
or even just the one using OR:
{or:[{model: 96, resi: 49, chain: 'A', resn: 'LEU'}]}
the styles apply to my other model too. This made me think that perhaps there is an issue with the way the logic is implemented for the OR gate.

Help is much appreciated!

@JavierSanchez-Utges
Copy link
Author

I have solved it by specifying again the model directly in the selection:

viewer.addStyle({or:ligandSitesHash[activeModel][ligNam], model: activeModel}, {cartoon:{hidden: false, color: ligColor}, stick: {hidden: false, color: ligColor, radius: stickRadius}});

But I am still confused of why the OR of different selections, all of the same model, ends up including a different model...

dkoes added a commit that referenced this issue Jun 1, 2025
Issue #804.  Model selection was only being processed at the top level
when the selection was dispatched to the models in the viewer.  Now
process in the model as well to properly handle model selection in
nested statements like or/and.

This requires giving models access to their viewer and so I've put in
some minor api breakage where model methods no longer need to be passed
a viewer.
@dkoes
Copy link
Contributor

dkoes commented Jun 1, 2025

The reason this wasn't working is model selections were only parsed at the top level, as they are used to dispatch the selection to the respective models. I've now add model checking within the selection inside the model so they work recursively (e.g., inside an or statement).

https://3dmol.org/tests/auto/generate_test.cgi?test=orsel

@JavierSanchez-Utges
Copy link
Author

Great, thanks a lot!

@dkoes
Copy link
Contributor

dkoes commented Jun 3, 2025

In 2.5

@dkoes dkoes closed this as completed Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants