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

Example: Plot drug binding hotspots w/ NGLView #62

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

dwhswenson
Copy link
Owner

Consider drug binding. I thought it might be interesting to visualize the per-residue contact frequency on the protein itself, using NGLView.

Per-residue coloring had been hidden API in NGLView, and had changed since the last time I used it. So after finding the fix (nglviewer/nglview#491 (comment)), I asked @hainm if it could join the public API and he said that he'd make it a priority! (Thanks!)

This PR will be updated once the official NGLView API is in place. I mainly want it up so that @hainm can see my use case. I may add other functions to the main code to facilitate this, as well, or we might leave it as an advanced example (I've heavily commented the fancier bits of code that would perhaps be moved to a function).

With the GSK3B trajectory that we already have in the repo, the results are kind of dull (and maybe viridis isn't the best color map):

GSK3B_contacts

Maybe I should ask for one of those DE Shaw trajectories -- not to put in the repo, but it might make a nice example for the paper!

@hainm
Copy link

hainm commented Aug 1, 2019

Unfortunately, the NGLView widget (which allows you to rotate the molecule, run the trajectory, zoom in, etc.) can't be converted to HTML.

This is not true anymore. :D

You can use the latest version, and either use

So that you can view a snapshot of the live notebook in nbviewer: https://nbviewer.jupyter.org/github/arose/nglview/blob/master/notebooks/gui.ipynb

Related issues:

@dwhswenson
Copy link
Owner Author

Cool! Thanks, and I'll try that out! (I'll also have to check through some of the OpenPathSampling examples, which I think will also benefit from that.)

@hainm
Copy link

hainm commented Aug 2, 2019

Should be available in v2.6.7: nglviewer/nglview#839
(there's still one outstanding issue with embedding html: nglviewer/nglview#840)

cheers.

@hainm
Copy link

hainm commented Aug 2, 2019

The selection scheme does not work with color as integer, so you might want to convert to hex.

Screen Shot 2019-08-02 at 2 13 45 AM

Added a few new functions; need to clean up and write tests
@hainm
Copy link

hainm commented Aug 2, 2019

I have additional comments while playing with your notebook:

  • Use default=False to avoid initial repr
view = nv.show_mdtraj(traj, default=False)
view.center()
# view.clear() # don't need this anymore
view.add_cartoon(selection='protein', color="contacts")
view
  • You might try to use view.gui_style = 'ngl' which turns on the nice GUI in NGL (http://nglviewer.org/ngl/)

  • you might want to superpose and smooth the traj (mdtraj has it).
    cheers.

@dwhswenson dwhswenson changed the title [WIP] Example: Plot drug binding hotspots w/ NGLView Example: Plot drug binding hotspots w/ NGLView Aug 3, 2019
@dwhswenson
Copy link
Owner Author

@hainm : Could you glance over the text in the notebook section "Creating the NGLView color mapping"? I just want to be sure that I'm accurately describing things. (And thanks for the other suggestions -- in particular, I hadn't been aware of default=False; that will be useful for a lot of things!)

@sroet : This is ready for review. I think I prefer to leave this as "make the user do the conversion", because (1) it's about 7 lines of code; (2) it is only relevant if you're looking at contacts with just 1 residue (this would not work for visualizing protein-protein interfaces); and (3) it goes to the narrative I'm always pushing about a scientific software ecosystem, where it is easy to get the pieces to talk to each other.

A quick summary of what's in this PR:

  • new example notebook showing how to visualize the frequency each residue is in contact with a drug molecule on an image of the protein itself, by interfacing with NGLView
  • new plotting helper functions to get colors and associated unit tests (I really wish that these functions were matplotlib built-ins)
  • updates to docs configuration so that nbsphinx can show the NGLView widget (and CSS fixes that were needed after)

Still desired: a way to get nbsphinx to include some NGLView output when it generates PDF output. It might be possible by editing notebook metadata -- I haven't tried that yet.

Note: when merging this one, please squash commits. Every notebook save took a lot of space.

@dwhswenson dwhswenson requested a review from sroet August 3, 2019 10:41
@hainm
Copy link

hainm commented Aug 3, 2019

Could you glance over the text in the notebook section "Creating the NGLView color mapping"? I just want to be sure that I'm accurately describing things.

Looks good to me.

Per "where color_* are colors that can be names ('red', 'blue') or can be web-formatted hexadecimal values ('#FF0000', '#0000FF'),", the color can be a predefined scheme too (e.g: atomindex, https://github.com/arose/ngl/blob/master/examples/scripts/color/selection.js)

Copy link
Collaborator

@sroet sroet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small doc change requested.

Also, you might want to reference the command jupyter-nbextension enable nglview --py --sys-prefix at the end of the notebook as a trouble shooting tip (as it took me a bit of effort finding that command after my conda install)

LGTM otherwise

interpreted as ``Normalize(0, 1)``, meaning that the data is already
mapped to the correct values. A tuple should be a 2-tuple of (vmin,
vmax).
bytes : bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add slightly more documentation to this keyword (as it was relatively difficult to find in the matplotlib documentation as well)

@jbloom
Copy link

jbloom commented Feb 8, 2020

Unfortunately, the NGLView widget (which allows you to rotate the molecule, run the trajectory, zoom in, etc.) can't be converted to HTML.

This is not true anymore. :D

You can use the latest version, and either use

So that you can view a snapshot of the live notebook in nbviewer: https://nbviewer.jupyter.org/github/arose/nglview/blob/master/notebooks/gui.ipynb

Related issues:

@hainm: This embedding works almost perfectly for me. The one thing that I've noticed is that the orientation of the camera is not saved in the HTML embeddings. Is that possible to fix?

@hainm
Copy link

hainm commented Feb 8, 2020

hi @jbloom, it might be fixed according to this issue but I have not tried to fix that in nglview yet.

nglviewer/ngl#687

For the time being, you might want to update the orientation in html file. cheers.

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

Successfully merging this pull request may close these issues.

4 participants