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

Color by b-factor #53

Open
halg3 opened this issue Jul 12, 2024 · 2 comments
Open

Color by b-factor #53

halg3 opened this issue Jul 12, 2024 · 2 comments

Comments

@halg3
Copy link

halg3 commented Jul 12, 2024

Hello!

I had taken a look through the vignette, and I did not see a function that allows users to color 3D models by the b-factor found within a pdb file (eg. coloring models produced by AlphaFold by pLDDT scores, as stored in the b-factor field). I was wondering if such a function does exist, or if there is a way that I could achieve this.

Thank you so much for such a useful package!

@swsoyee
Copy link
Owner

swsoyee commented Jul 12, 2024

Hello,
thank you for using r3dmol.

I'm not familiar with this area of research, so I'm unsure about what a B factor is. As far as I remember, such a function hasn't been developed in our tool.

You might want to check the official documentation for 3dmol.js to see if there's a built-in function for coloring based on B factors. If there's any mention of it in the documentation, a similar approach should be feasible in r3dmol as well.

If you find the documentation but are unsure how to implement it, feel free to share the link with me, and I'll take a look.
I believe coloring based on a specific series of positions should achieve this goal.

@jvolkening
Copy link

Hi @halg3,

I happened to be looking for the same functionality today. With guidance from this Gist I was able to do it with cartoon rendering by using the colorfunc property, e.g. the following will color from white to blue over the range 20-100:

library(dplyr)
library(r3dmol)

pdb <- get_pdb_data_somehow()

color_by_b <- "function(atom) {
        var scale = d3.scaleLinear().domain([20,100]).range(['white','blue']);
        var c = scale(atom.b);
        return d3.rgb(c).hex();
}"

r3dmol() %>%
    m_add_model(pdb, format='pdb') %>%
    m_set_style(style = m_style_cartoon(colorfunc = color_by_b)) %>%
    m_zoom_to()

This uses D3, so you also need to include that javascript library in your final document (e.g. with include: if you're using RMarkdown).

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

3 participants