Skip to content
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

change color of specific residue #1022

Open
pooriyapfn opened this issue Feb 7, 2024 · 2 comments
Open

change color of specific residue #1022

pooriyapfn opened this issue Feb 7, 2024 · 2 comments

Comments

@pooriyapfn
Copy link

When I want to change the color for a small portion of the residue or just one of them, it will not change anything. However, when I increase the selection range, it will affect the structure. How can I fix that?

For example:

loadedStructure.addRepresentation("cartoon", {
  sele: `:B`,
  color: color[1],
  aspectRatio: 5.7,
  subdiv: 10,
});
loadedStructure.addRepresentation("cartoon", {
  sele: `:B and (10-12)`,
  color: "red",
  aspectRatio: 5.7,
  subdiv: 10,
});

In this code, it cannot show any red on the structure. However, when we change (10-13), it shows red. Also, I want to change the color of the tenth residue to red, but I can't. Please let me know how I can do that.

@pooriyapfn
Copy link
Author

Also, in this example, if you change the range to (18-20) or make it smaller, it doesn't affect the structure.

@papillot
Copy link
Contributor

papillot commented Feb 8, 2024

In both examples, 2 different representations are created and are superposed.
If what you are looking for is having a part of a cartoon representation in one color and a selection in another color, you should use only one representation and a custom color scheme. See the documentation here for selection based coloring: https://nglviewer.org/ngl/api/manual/coloring.html#selection-based-coloring

Regarding cartoon representations, there is a known limitation that only stretches of 4 residues or more can be represented. This is a limitation from the implementation of the spline algorithm which requires 4 coordinates for the Catmull-Rom interpolation. For this reason sele: ':B and (10-12)' will probably not render anything.

In the codepen example, I guess that what you are trying to achieve is representing the bulk of the protein structure as a transparent cartoon and only the stretch of interest as opaque colored segment. In that case, you would indeed need to use 2 representations because opacity is a global setting. And then you unfortunately have to workaround the 4 residues limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants