3dmol / 3Dmol.js

WebGL accelerated JavaScript molecular graphics library
https://3dmol.org/
Other
786 stars 192 forks source link

[BUG?] Complex selections with OR gate #804

Open JavierSanchez-Utges opened 2 weeks ago

JavierSanchez-Utges commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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...