nglviewer / nglview

Jupyter widget to interactively view molecular structures and trajectories
http://nglviewer.org/nglview/latest/
Other
820 stars 134 forks source link

volume viewer GUI #561

Closed hainm closed 5 years ago

hainm commented 7 years ago
jbarnoud commented 7 years ago

Until such gui is implemented, is there a way to set the value to use for the isovolume?

hainm commented 7 years ago

hi, in which context? (update_surface?)

hainm commented 7 years ago

@arose

jbarnoud commented 7 years ago

I calculated a 3D density grid. I can display that grid as an isosurface around my molecule of interest, but I would like to choose what density value to use to draw the isosurface.

arose commented 7 years ago

Are you loading it with view.add_component('my.ccp4')?

@hainm after loading such a component, how can you add representations to it?

hainm commented 7 years ago
view.add_surface(..., component=0) # or 1, 2,

# or
view.component_0.add_surface(...)
arose commented 7 years ago

so view.component_0.add_surface(threshold=1.0) should work, I think

hainm commented 7 years ago

also update current surface repr.

view.component_0.update_surface(threshold=1.0)
jbarnoud commented 7 years ago

It works, indeed. Thanks.

Is there a mailing list somewhere to ask questions without polluting the bug tracker?

hainm commented 7 years ago

Is there a mailing list somewhere to ask questions without polluting the bug tracker?

we don't mind about this. I myself prefer to use github issue here. Just create a topic for posting random + usage questions: https://github.com/arose/nglview/issues/589

arose commented 7 years ago

The amount of questions is not that high, so just having them as separate issues marked as question if fine with me

hainm commented 7 years ago

go back to the original issue: demo from @arose

https://codepen.io/arose/full/oWOQMg/

satary commented 5 years ago

Hi @hainm, Hi @arose ! I wonder if it is possible to color a structure (cartoon, surface and other atomic representations) by volume data (loaded with ccp4 or dx). I see that there is a volumeColormaker but I don't get how to use it. I guess that volume is loaded as a separate component, so can it be done?

hainm commented 5 years ago

@arose Can you please provide a code spinet for this so I could introduce to nglview? thanks.

hainm commented 5 years ago

hi @satary,

It turns out that nglview has not supported that feature yet. But fortunately, you can use the workaround (taken from: https://github.com/arose/ngl/blob/master/examples/scripts/color/volume.js)

Notebook: volume_color.ipynb.txt

Screen Shot 2019-03-30 at 12 33 41 AM
satary commented 5 years ago

Hi @hainm! Thanks for the suggestion, I will try to use it and report!

satary commented 5 years ago

~Hi @hainm, am I missing something, or method _execute_js_code() is not in the current release?~ OK, my bad, solved that one. BTW, for jupyterlab users you have to jupyter-labextension install nglview-js-widgets both in environment jupyterlab is started in and in the environment, where they use nglview, why so? Your example does not work, for some reason, I have just an empty widget.

Hm, I guess I found an error, but I have no Idea how to solve it, I can not add any component as file is not found for some reason image

edit. Now I found out that it is jupyterlab specific issue. as it works in a plain notebook =( that's sad (

hainm commented 5 years ago

I think it is in 1.1.9

Hai

On Wed, Apr 17, 2019 at 7:34 AM Grigoriy Armeev notifications@github.com wrote:

Hi @hainm https://github.com/hainm, am I missing something, or method _execute_js_code() is not in the current release?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/arose/nglview/issues/561#issuecomment-484046354, or mute the thread https://github.com/notifications/unsubscribe-auth/ABB645O2BW2YAX62F6HCWX3PQ4DLNANCNFSM4C4D7UCQ .

satary commented 5 years ago

@hainm It looks like nothing happens on _execute_js_code(), is there any simple way to know if it works?

hainm commented 5 years ago

Have you tried my attached notebook above yet? It works for me.

I will post another example soon, not at my computer right now.

Hai

On Wed, Apr 17, 2019 at 9:02 AM Grigoriy Armeev notifications@github.com wrote:

@hainm https://github.com/hainm It looks like nothing happens on _execute_js_code(), is there any simple way to know if it works?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/arose/nglview/issues/561#issuecomment-484074778, or mute the thread https://github.com/notifications/unsubscribe-auth/ABB645LGT57OEGSWAMIOLQ3PQ4NVHANCNFSM4C4D7UCQ .

satary commented 5 years ago

Yeap, I've tried it. No color change for me =(

hainm commented 5 years ago

Uhm

I just saw your editted comment (it would be better if you can post a new post so I can get notification): can you summarize again what doesn’t work and in which environment?

Just try with notebook first. Jupyterlab is not that stable (in my opinion).

To make sure the _execute_js_code work, just try a simple JavaScript code

code = “”” console.log(‘hello’) “””

Call the method and open the JavaScript console to see the ‘hello’ word.

(Right click -> Inspection (or similar))

On Wed, Apr 17, 2019 at 9:09 AM Grigoriy Armeev notifications@github.com wrote:

Yeap, I've tried it. No color change for me =(

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/arose/nglview/issues/561#issuecomment-484077490, or mute the thread https://github.com/notifications/unsubscribe-auth/ABB645ICKTYHAI5YVQGUB3LPQ4ORPANCNFSM4C4D7UCQ .

satary commented 5 years ago

Thanks for the reply! In jupyter notebook (run from jupyter hub) I tested your code snippet and nothing seems to be in the console output. But! There is an info message widget_ngl.js:1010 can not create func for execute_code image

satary commented 5 years ago

As for the jupyterlab support there is a bug, I believe as it can not load any files with add_component method.

satary commented 5 years ago

Update, I've managed to get Hello in the console, It was due to some mismatch in js extension and python extension. Gosh, it is a bit messy. Now I can color the surface! Will attach my example later! Thank you!

hainm commented 5 years ago

image

satary commented 5 years ago

To recap for the Google bots: My task was to color molecular surface according to electostatic potential map (calculated by APBS) loaded from .dx file. Here is a code snippet for that.

view=nv.show_structure_file('1KX5.pdb')
view.add_component('resources/pot.dx')
view

code = """
var ms = this.stage.compList[0];
var potential = this.stage.compList[1];

ms.addRepresentation('surface', {
    colorVolume: potential.volume,
    colorScheme: 'volume',
    colorScale: 'rwb',
    colorReverse: false,
    colorDomain: [ 0, 1500 ]
})

"""
view.component_1.clear_representations()
view.component_0.clear_representations()
view._execute_js_code(code)

image

hainm commented 5 years ago

great. Thanks.

hainm commented 5 years ago

I wonder if it is possible to color a structure (cartoon, surface and other atomic representations) by volume data (loaded with ccp4 or dx).

hi @satary, this feature is added in #804

satary commented 5 years ago

Hello @hainm ! Great news and thank you a lot!