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

Usage questions: Please ask here first #589

Open
hainm opened this Issue Mar 9, 2017 · 167 comments

Comments

Projects
None yet
@hainm
Collaborator

hainm commented Mar 9, 2017

For any questions relating to how/why/ ... Or anything you don't know where to ask.

For bug, suggestion, ... please open seperate issue

@gph82

This comment has been minimized.

Show comment
Hide comment
@gph82

gph82 Mar 10, 2017

Hi, I notice a bunch of tempfiles in my /tmp directory after using nglviewer, containing essentially the molecular coordinates in pdb format. Do they stay there because of abrupt termination of nglivew or something?

gph82 commented Mar 10, 2017

Hi, I notice a bunch of tempfiles in my /tmp directory after using nglviewer, containing essentially the molecular coordinates in pdb format. Do they stay there because of abrupt termination of nglivew or something?

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Mar 10, 2017

Collaborator

@gph82 I guess we did not do great job in cleaning those files. No, nglview do not need them to be there all the times.

updated: remove expired link.

Collaborator

hainm commented Mar 10, 2017

@gph82 I guess we did not do great job in cleaning those files. No, nglview do not need them to be there all the times.

updated: remove expired link.

@kain88-de

This comment has been minimized.

Show comment
Hide comment
@kain88-de

kain88-de Mar 21, 2017

Contributor

Hi is there a way to access and manipulate the rotation and zoom independently in the view object. NGL seems to support this. arose/ngl#240 (comment)

I know about view.orientation but it handles zoom and rotation and at the same time and not separately.

Contributor

kain88-de commented Mar 21, 2017

Hi is there a way to access and manipulate the rotation and zoom independently in the view object. NGL seems to support this. arose/ngl#240 (comment)

I know about view.orientation but it handles zoom and rotation and at the same time and not separately.

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Mar 21, 2017

Collaborator

Hi, can you open a new issue so we can make it in our todo list. thx.

Collaborator

hainm commented Mar 21, 2017

Hi, can you open a new issue so we can make it in our todo list. thx.

@lorenzoFabbri

This comment has been minimized.

Show comment
Hide comment
@lorenzoFabbri

lorenzoFabbri Mar 25, 2017

Hi all. I would like to do the following thing: each cell of my iPython notebook should contain only a "portion" of the entire protein. I explain: in each cell I would like to make visible only the portion of the protein that corresponds to a particular sequence. Is this possible? Is it possible to at least highlight in some way some portions of a protein using a sequence of amino acids as input? Thank you.

lorenzoFabbri commented Mar 25, 2017

Hi all. I would like to do the following thing: each cell of my iPython notebook should contain only a "portion" of the entire protein. I explain: in each cell I would like to make visible only the portion of the protein that corresponds to a particular sequence. Is this possible? Is it possible to at least highlight in some way some portions of a protein using a sequence of amino acids as input? Thank you.

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Mar 25, 2017

Collaborator

@lorenzoFabbri

: in each cell I would like to make visible only the portion of the protein that corresponds to a particular sequence. Is this possible?

No it's not possible. You can can always create 3 views and display them.

views = [nglview.show_structure_file('my.pdb') for _ in range(3)]

# views[0]: do something
views[0]

# another cell
# views[1]: do something
views[1]
...

Is it possible to at least highlight in some way some portions of a protein using a sequence of amino acids as input? Thank you.

May be just adding representations for given residue selection if you know where they are?
http://arose.github.io/ngl/api/tutorial-selection-language.html

PR is welcome if you think those utils useful for you and others. Cheers.
Ping @arose here in case you have different answers.

Collaborator

hainm commented Mar 25, 2017

@lorenzoFabbri

: in each cell I would like to make visible only the portion of the protein that corresponds to a particular sequence. Is this possible?

No it's not possible. You can can always create 3 views and display them.

views = [nglview.show_structure_file('my.pdb') for _ in range(3)]

# views[0]: do something
views[0]

# another cell
# views[1]: do something
views[1]
...

Is it possible to at least highlight in some way some portions of a protein using a sequence of amino acids as input? Thank you.

May be just adding representations for given residue selection if you know where they are?
http://arose.github.io/ngl/api/tutorial-selection-language.html

PR is welcome if you think those utils useful for you and others. Cheers.
Ping @arose here in case you have different answers.

@hainm hainm changed the title from Usage questions to Usage questions: Please ask here first Mar 25, 2017

@hainm hainm added the Q&A label Mar 25, 2017

@kain88-de

This comment has been minimized.

Show comment
Hide comment
@kain88-de

kain88-de Mar 25, 2017

Contributor

In a notebook I recently viewed two structures in different notebook cells. That worked fine.

Contributor

kain88-de commented Mar 25, 2017

In a notebook I recently viewed two structures in different notebook cells. That worked fine.

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Mar 25, 2017

Collaborator

In a notebook I recently viewed two structures in different notebook cells. That worked fine.

Yes, you can create as many views as you want.

Collaborator

hainm commented Mar 25, 2017

In a notebook I recently viewed two structures in different notebook cells. That worked fine.

Yes, you can create as many views as you want.

@kbsezginel

This comment has been minimized.

Show comment
Hide comment
@kbsezginel

kbsezginel Mar 30, 2017

Hi, is there a way to assign color to a given atom type in ball and stick model? It seems like other than common atoms in organic chemistry the rest of the atoms are represented with white color which makes it hard to distinguish with hydrogen atoms. Is there a way use something like CPK coloring? Thanks!

kbsezginel commented Mar 30, 2017

Hi, is there a way to assign color to a given atom type in ball and stick model? It seems like other than common atoms in organic chemistry the rest of the atoms are represented with white color which makes it hard to distinguish with hydrogen atoms. Is there a way use something like CPK coloring? Thanks!

@kain88-de

This comment has been minimized.

Show comment
Hide comment
@kain88-de

kain88-de Mar 30, 2017

Contributor

Is there a way to install a development version as a isolated environment? I found using a different conda environment screws with the javascript in my root environment.

Contributor

kain88-de commented Mar 30, 2017

Is there a way to install a development version as a isolated environment? I found using a different conda environment screws with the javascript in my root environment.

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Mar 30, 2017

Collaborator

@kbsezginel can you please provide screenshot?

Ping @arose

Collaborator

hainm commented Mar 30, 2017

@kbsezginel can you please provide screenshot?

Ping @arose

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Mar 30, 2017

Owner

is there a way to assign color to a given atom type in ball and stick model

There is CPK coloring based on the element. So if everything is white there is likely an error in determining the element. I would need an example file to look into that.

Owner

arose commented Mar 30, 2017

is there a way to assign color to a given atom type in ball and stick model

There is CPK coloring based on the element. So if everything is white there is likely an error in determining the element. I would need an example file to look into that.

@kbsezginel

This comment has been minimized.

Show comment
Hide comment
@kbsezginel

kbsezginel Mar 30, 2017

When I create a list of different atoms such as this:
atom_names = ['C', 'H', 'O', 'N', 'F', 'Cl', 'Br', 'Li', 'Zn', 'Cu', 'Pd', 'Co']
separate them 4 angstroms apart and save to a pdb file, this is what I see with nglview:

nglview_atoms

When I load the same pdb file using a molecular graphics software this is what I get:
mercury-atoms

As you can see only a handful of atoms are colored and their radii are all the same as well.

I attached the jupyter notebook and pdb file below:
atom-color.zip

kbsezginel commented Mar 30, 2017

When I create a list of different atoms such as this:
atom_names = ['C', 'H', 'O', 'N', 'F', 'Cl', 'Br', 'Li', 'Zn', 'Cu', 'Pd', 'Co']
separate them 4 angstroms apart and save to a pdb file, this is what I see with nglview:

nglview_atoms

When I load the same pdb file using a molecular graphics software this is what I get:
mercury-atoms

As you can see only a handful of atoms are colored and their radii are all the same as well.

I attached the jupyter notebook and pdb file below:
atom-color.zip

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Mar 30, 2017

Owner

The issue are non all-upper-case atom names. Fixed in the ngl development version. Will take some time to go into nglview. Workaround is providing all-upper-case atom names.

screenshot 42

Owner

arose commented Mar 30, 2017

The issue are non all-upper-case atom names. Fixed in the ngl development version. Will take some time to go into nglview. Workaround is providing all-upper-case atom names.

screenshot 42

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Mar 30, 2017

Collaborator

Will take some time to go into nglview

if you push to npm, will be available tonight :D

Collaborator

hainm commented Mar 30, 2017

Will take some time to go into nglview

if you push to npm, will be available tonight :D

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Mar 30, 2017

Owner

if you push to npm, will be available tonight :D

there are some issues with the current version... ;)

Owner

arose commented Mar 30, 2017

if you push to npm, will be available tonight :D

there are some issues with the current version... ;)

@kbsezginel

This comment has been minimized.

Show comment
Hide comment
@kbsezginel

kbsezginel Mar 31, 2017

Thanks a lot! It seems like the radii are all the same though, is that also fixed in the ngl development version?

kbsezginel commented Mar 31, 2017

Thanks a lot! It seems like the radii are all the same though, is that also fixed in the ngl development version?

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Apr 1, 2017

Owner

It seems like the radii are all the same though

that is just due to the default parameters of the ball+stick representation. Have a look at the radiusType parameter (http://arose.github.io/ngldev/api/global.html#StructureRepresentationParameters)

Owner

arose commented Apr 1, 2017

It seems like the radii are all the same though

that is just due to the default parameters of the ball+stick representation. Have a look at the radiusType parameter (http://arose.github.io/ngldev/api/global.html#StructureRepresentationParameters)

@kbsezginel

This comment has been minimized.

Show comment
Hide comment
@kbsezginel

kbsezginel Apr 13, 2017

Hi again! I run into this problem that in ball and stick model the bonds are not displayed after a certain number of atoms. Is there a way to force calculation of the bonds or does it just skip that when there is too many atoms?

Here with approximately 300 atoms:

12-linkers

Here with approximately 500 atoms:

24-linkers

Thanks!

kbsezginel commented Apr 13, 2017

Hi again! I run into this problem that in ball and stick model the bonds are not displayed after a certain number of atoms. Is there a way to force calculation of the bonds or does it just skip that when there is too many atoms?

Here with approximately 300 atoms:

12-linkers

Here with approximately 500 atoms:

24-linkers

Thanks!

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Apr 13, 2017

Owner

@kbsezginel Can you please provide the file you are loading. Thanks!

Owner

arose commented Apr 13, 2017

@kbsezginel Can you please provide the file you are loading. Thanks!

@kbsezginel

This comment has been minimized.

Show comment
Hide comment
@kbsezginel

kbsezginel Apr 13, 2017

Here, I attached the pdb files. Thanks!

n_atoms.zip

kbsezginel commented Apr 13, 2017

Here, I attached the pdb files. Thanks!

n_atoms.zip

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Apr 13, 2017

Owner

You assign the same group/residue number to all molecules. If you give every molecule its own number the bond calculation will work fine.

Owner

arose commented Apr 13, 2017

You assign the same group/residue number to all molecules. If you give every molecule its own number the bond calculation will work fine.

@kbsezginel

This comment has been minimized.

Show comment
Hide comment
@kbsezginel

kbsezginel Apr 13, 2017

Thanks, that seems to get the bond calculation working however now I am seeing incorrect assignments of the bonds for some molecules:
600_atoms_group

When I visualize the same file without groups I see no bonds as expected:
600_atoms_no_group

I also tried with a smaller number of molecules:
Group:
4_mol_group

No group:
4_mol_no_group

Any idea why that's the case?
Thanks!

Attached pdb files here:
mol_grouping.zip

kbsezginel commented Apr 13, 2017

Thanks, that seems to get the bond calculation working however now I am seeing incorrect assignments of the bonds for some molecules:
600_atoms_group

When I visualize the same file without groups I see no bonds as expected:
600_atoms_no_group

I also tried with a smaller number of molecules:
Group:
4_mol_group

No group:
4_mol_no_group

Any idea why that's the case?
Thanks!

Attached pdb files here:
mol_grouping.zip

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Apr 14, 2017

Owner

I haven't looked at it but my hunch is that it will work if you give each group its own distinct three letter name instead of calling them all MOL. For efficiency reasons, NGL tries to reuse calculated bonds for identical groups. However the identity calculation seem wrong here.

Owner

arose commented Apr 14, 2017

I haven't looked at it but my hunch is that it will work if you give each group its own distinct three letter name instead of calling them all MOL. For efficiency reasons, NGL tries to reuse calculated bonds for identical groups. However the identity calculation seem wrong here.

@kbsezginel

This comment has been minimized.

Show comment
Hide comment
@kbsezginel

kbsezginel Apr 14, 2017

Thanks, that worked perfectly!

30_linkers

kbsezginel commented Apr 14, 2017

Thanks, that worked perfectly!

30_linkers

@morpholin

This comment has been minimized.

Show comment
Hide comment
@morpholin

morpholin Apr 16, 2017

I wanted to ask, if it is possible to also display external densities, extracted e.g. from a Gaussian Cube file?

morpholin commented Apr 16, 2017

I wanted to ask, if it is possible to also display external densities, extracted e.g. from a Gaussian Cube file?

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Jul 21, 2018

Collaborator

For some reason, I can view certain .pdb files and also mdtraj trajectories but others not. And I don't really see a difference between the general structure of the files. I attached one pdb file which works and one which doesn't work. The widget is there but it has an empty view for the not working ones.

@kuenzeln

I (or @arose ) will have a look once I have a chance. cheers.

Collaborator

hainm commented Jul 21, 2018

For some reason, I can view certain .pdb files and also mdtraj trajectories but others not. And I don't really see a difference between the general structure of the files. I attached one pdb file which works and one which doesn't work. The widget is there but it has an empty view for the not working ones.

@kuenzeln

I (or @arose ) will have a look once I have a chance. cheers.

@ArtVoro

This comment has been minimized.

Show comment
Hide comment
@ArtVoro

ArtVoro Jul 24, 2018

  • is there a way to reset the camera view (center + rotate) to the initial view? so far i only found out how to center the view, but not how to reset the angle
  • when you load in trajectory, the secondary motifs are taken from the first frame (i guess). is there a function to reinitialize the secondary motifs to another frame from the trajectory maybe?

ArtVoro commented Jul 24, 2018

  • is there a way to reset the camera view (center + rotate) to the initial view? so far i only found out how to center the view, but not how to reset the angle
  • when you load in trajectory, the secondary motifs are taken from the first frame (i guess). is there a function to reinitialize the secondary motifs to another frame from the trajectory maybe?
@songkevinc

This comment has been minimized.

Show comment
Hide comment
@songkevinc

songkevinc Jul 31, 2018

Hi, sort of a silly question, but we're trying to visualize a protein that unfolds over time, but the fog parameter (I think?) is making the parts that are in the back look more transparent. Is there a way to get rid of depth cueing entirely?? Thanks in advance!

songkevinc commented Jul 31, 2018

Hi, sort of a silly question, but we're trying to visualize a protein that unfolds over time, but the fog parameter (I think?) is making the parts that are in the back look more transparent. Is there a way to get rid of depth cueing entirely?? Thanks in advance!

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 1, 2018

Collaborator

@ArtVoro

is there a way to reset the camera view (center + rotate) to the initial view? so far i only found out how to center the view, but not how to reset the angle

nglview saves the camera orientation in view._camera_orientation, rotate the molecule, save the orientation; update it v._set_camera_orientation(v._camera_orientation)

e.g: try below

import nglview as nv

v = nv.demo()
v

# another cell
arr = [-2.1935031754759238,
 -34.64566871888894,
 49.022025444945214,
 0,
 -13.88147466448076,
 48.01787971362964,
 33.31487182672994,
 0,
 -58.401934906672686,
 -10.112055315961655,
 -9.759771120696222,
 0,
 -37.284461975097656,
 -42.47041130065918,
 -44.55349826812744,
 1]

v._set_camera_orientation(arr)
Collaborator

hainm commented Aug 1, 2018

@ArtVoro

is there a way to reset the camera view (center + rotate) to the initial view? so far i only found out how to center the view, but not how to reset the angle

nglview saves the camera orientation in view._camera_orientation, rotate the molecule, save the orientation; update it v._set_camera_orientation(v._camera_orientation)

e.g: try below

import nglview as nv

v = nv.demo()
v

# another cell
arr = [-2.1935031754759238,
 -34.64566871888894,
 49.022025444945214,
 0,
 -13.88147466448076,
 48.01787971362964,
 33.31487182672994,
 0,
 -58.401934906672686,
 -10.112055315961655,
 -9.759771120696222,
 0,
 -37.284461975097656,
 -42.47041130065918,
 -44.55349826812744,
 1]

v._set_camera_orientation(arr)
@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 1, 2018

Collaborator

when you load in trajectory, the secondary motifs are taken from the first frame (i guess). is there a function to reinitialize the secondary motifs to another frame from the trajectory maybe?

unfortunately no :(

@arose any idea?

Collaborator

hainm commented Aug 1, 2018

when you load in trajectory, the secondary motifs are taken from the first frame (i guess). is there a function to reinitialize the secondary motifs to another frame from the trajectory maybe?

unfortunately no :(

@arose any idea?

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 1, 2018

Collaborator

Hi, sort of a silly question, but we're trying to visualize a protein that unfolds over time, but the fog parameter (I think?) is making the parts that are in the back look more transparent. Is there a way to get rid of depth cueing entirely?? Thanks in advance!

@songkevinc

uhm, I am not sure. Can you try to play with the fog parameters (fog_near, fog_far, ...)

v.stage.set_parameters(fog_near=0)

(For interactive, you can try the super simple GUI)

import nglview as nv

v = nv.demo(gui=True)
v

(Click "Preference" button).
screen shot 2018-07-31 at 10 21 16 pm

cc @arose in case you have another comment.

Collaborator

hainm commented Aug 1, 2018

Hi, sort of a silly question, but we're trying to visualize a protein that unfolds over time, but the fog parameter (I think?) is making the parts that are in the back look more transparent. Is there a way to get rid of depth cueing entirely?? Thanks in advance!

@songkevinc

uhm, I am not sure. Can you try to play with the fog parameters (fog_near, fog_far, ...)

v.stage.set_parameters(fog_near=0)

(For interactive, you can try the super simple GUI)

import nglview as nv

v = nv.demo(gui=True)
v

(Click "Preference" button).
screen shot 2018-07-31 at 10 21 16 pm

cc @arose in case you have another comment.

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Aug 1, 2018

Owner

when you load in trajectory, the secondary motifs are taken from the first frame (i guess). is there a function to reinitialize the secondary motifs to another frame from the trajectory maybe?

no, sorry, that is not supported

Owner

arose commented Aug 1, 2018

when you load in trajectory, the secondary motifs are taken from the first frame (i guess). is there a function to reinitialize the secondary motifs to another frame from the trajectory maybe?

no, sorry, that is not supported

@saadraza128

This comment has been minimized.

Show comment
Hide comment
@saadraza128

saadraza128 Aug 3, 2018

Hi, I can not get licorice representation to change its color with the function ccc._set_color_by_residue(colors,component_index=0,repr_index=0) , the default secondary structure representation does change color according to color values. Which function should I use to change the color according to my list of colors for licorice representation?

saadraza128 commented Aug 3, 2018

Hi, I can not get licorice representation to change its color with the function ccc._set_color_by_residue(colors,component_index=0,repr_index=0) , the default secondary structure representation does change color according to color values. Which function should I use to change the color according to my list of colors for licorice representation?

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 3, 2018

Collaborator

can you post code example + pdb file to reproduce?

Collaborator

hainm commented Aug 3, 2018

can you post code example + pdb file to reproduce?

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 3, 2018

Collaborator

btw, may be

view.clear()
view.add_licorice() # to make repr_index of 0.

view._set_color_by_residue(...)
Collaborator

hainm commented Aug 3, 2018

btw, may be

view.clear()
view.add_licorice() # to make repr_index of 0.

view._set_color_by_residue(...)
@saadraza128

This comment has been minimized.

Show comment
Hide comment
@saadraza128

saadraza128 Aug 6, 2018

The following code will only color the cartoon representation but not the surface or licorice

import nglview

view = nglview.NGLWidget()
c = view.add_pdbid('1tsu')
colors=['0xFF0000','0x0000FF']*50
view.clear_representations()
view.add_cartoon('protein')
view.add_surface('protein', opacity=0.3) # sol
view.add_licorice('protein')
view._set_color_by_residue(colors,component_index=0,repr_index=0)
view

saadraza128 commented Aug 6, 2018

The following code will only color the cartoon representation but not the surface or licorice

import nglview

view = nglview.NGLWidget()
c = view.add_pdbid('1tsu')
colors=['0xFF0000','0x0000FF']*50
view.clear_representations()
view.add_cartoon('protein')
view.add_surface('protein', opacity=0.3) # sol
view.add_licorice('protein')
view._set_color_by_residue(colors,component_index=0,repr_index=0)
view

@saadraza128

This comment has been minimized.

Show comment
Hide comment
@saadraza128

saadraza128 Aug 6, 2018

Sorry, I got it change the rep_index

saadraza128 commented Aug 6, 2018

Sorry, I got it change the rep_index

@saadraza128

This comment has been minimized.

Show comment
Hide comment
@saadraza128

saadraza128 Aug 6, 2018

Does NGLview has anything similar to within selection command of vmd or zone function of chimera?

saadraza128 commented Aug 6, 2018

Does NGLview has anything similar to within selection command of vmd or zone function of chimera?

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 6, 2018

Collaborator

Does NGLview has anything similar to within selection command of vmd or zone function of chimera?

cc @arose

Collaborator

hainm commented Aug 6, 2018

Does NGLview has anything similar to within selection command of vmd or zone function of chimera?

cc @arose

@arose

This comment has been minimized.

Show comment
Hide comment
@arose

arose Aug 6, 2018

Owner

Does NGLview has anything similar to within selection command of vmd or zone function of chimera?

no, see arose/ngl#91

Owner

arose commented Aug 6, 2018

Does NGLview has anything similar to within selection command of vmd or zone function of chimera?

no, see arose/ngl#91

@ArtVoro

This comment has been minimized.

Show comment
Hide comment
@ArtVoro

ArtVoro Aug 15, 2018

can i change and select the color of protein chains? i know there is the color_by() function, but what if i want to set e.g. chain A to red and chain B to blue?

ArtVoro commented Aug 15, 2018

can i change and select the color of protein chains? i know there is the color_by() function, but what if i want to set e.g. chain A to red and chain B to blue?

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 15, 2018

Collaborator

can i change and select the color of protein chains? i know there is the color_by() function, but what if i want to set e.g. chain A to red and chain B to blue?

uhm, I don't think so. I bet you should add new representation with chain A: http://nglviewer.org/ngl/api/manual/selection-language.html

view.add_cartoon(your_selection, ...)
Collaborator

hainm commented Aug 15, 2018

can i change and select the color of protein chains? i know there is the color_by() function, but what if i want to set e.g. chain A to red and chain B to blue?

uhm, I don't think so. I bet you should add new representation with chain A: http://nglviewer.org/ngl/api/manual/selection-language.html

view.add_cartoon(your_selection, ...)
@alexrd

This comment has been minimized.

Show comment
Hide comment
@alexrd

alexrd Aug 21, 2018

Hi and thanks for the great work! I'm trying to add a text label to the visualization that updates as the trajectory plays. Specifically, each trajectory frame has a weight, which is saved in an array, and I'd like a label (e.g. "weight = X") to be displayed somewhere on the screen. I can add a label like so:

label_pos = list(10*xyz_align[0].mean(axis=0) + [20,20,20])
label_rgb = [0.2,0.2,0.2]
label_size = 10
view.shape.add_label(label_pos,label_rgb,label_size,
                     "Weight: {0:.3e}".format(weights[view.frame]))

but this needs to be updated manually after the frame is changed. Is there a way to do this automatically?

alexrd commented Aug 21, 2018

Hi and thanks for the great work! I'm trying to add a text label to the visualization that updates as the trajectory plays. Specifically, each trajectory frame has a weight, which is saved in an array, and I'd like a label (e.g. "weight = X") to be displayed somewhere on the screen. I can add a label like so:

label_pos = list(10*xyz_align[0].mean(axis=0) + [20,20,20])
label_rgb = [0.2,0.2,0.2]
label_size = 10
view.shape.add_label(label_pos,label_rgb,label_size,
                     "Weight: {0:.3e}".format(weights[view.frame]))

but this needs to be updated manually after the frame is changed. Is there a way to do this automatically?

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 22, 2018

Collaborator

@alexrd Unfortunately there is no way to do that right now. nglview does not expose removing a given shape yet, so if you update the label for each frame, a lot of labels will be written on screen.
screen shot 2018-08-21 at 11 00 26 pm

If nglview did have that "remove" function, I think we can have a workaround for your issue by writing a small function that will be triggered by frame changed.

A desired example would be like this

def on_change_frame(change):
    frame = change['new']
    view.shape.remove_label(...) # does not exists yet
    view.shape.add_label(...)

view.observe(on_change_frame, 'frame')

Let give me sometimes to add the "remove" or "update" function (if NGL has that).

Collaborator

hainm commented Aug 22, 2018

@alexrd Unfortunately there is no way to do that right now. nglview does not expose removing a given shape yet, so if you update the label for each frame, a lot of labels will be written on screen.
screen shot 2018-08-21 at 11 00 26 pm

If nglview did have that "remove" function, I think we can have a workaround for your issue by writing a small function that will be triggered by frame changed.

A desired example would be like this

def on_change_frame(change):
    frame = change['new']
    view.shape.remove_label(...) # does not exists yet
    view.shape.add_label(...)

view.observe(on_change_frame, 'frame')

Let give me sometimes to add the "remove" or "update" function (if NGL has that).

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 22, 2018

Collaborator

ah ah, I think I already have a workaround now.

screen shot 2018-08-21 at 11 17 18 pm

Code

def on_change_frame(change):
    view._remote_call(
    'removeComponent', target='Stage', args=[
        1, # given that you have only one trajectory and the "buffer" is the 2nd component.
    ])
    frame = change['new']
    label_pos = [-10, 1, 1]
    label_rgb = [0.2,0.2,0.2]
    label_size = 20

    labels = list('abc')*100
    view.shape.add_label(label_pos, label_rgb, label_size, labels[frame])

view.observe(on_change_frame, 'frame')

PS: It's a workaround and might not work with different nglview version.

Collaborator

hainm commented Aug 22, 2018

ah ah, I think I already have a workaround now.

screen shot 2018-08-21 at 11 17 18 pm

Code

def on_change_frame(change):
    view._remote_call(
    'removeComponent', target='Stage', args=[
        1, # given that you have only one trajectory and the "buffer" is the 2nd component.
    ])
    frame = change['new']
    label_pos = [-10, 1, 1]
    label_rgb = [0.2,0.2,0.2]
    label_size = 20

    labels = list('abc')*100
    view.shape.add_label(label_pos, label_rgb, label_size, labels[frame])

view.observe(on_change_frame, 'frame')

PS: It's a workaround and might not work with different nglview version.

@alexrd

This comment has been minimized.

Show comment
Hide comment
@alexrd

alexrd Aug 22, 2018

Worked for me! Thanks a ton!

image

alexrd commented Aug 22, 2018

Worked for me! Thanks a ton!

image

@ArtVoro

This comment has been minimized.

Show comment
Hide comment
@ArtVoro

ArtVoro Aug 23, 2018

where are the coordinates saved?
im using both MDAnalysis and NGLview together, since NGLview can fetch structures from pdb database i wondered if i could load the structure and then create a MDAnalysis.Universe with that information.

ArtVoro commented Aug 23, 2018

where are the coordinates saved?
im using both MDAnalysis and NGLview together, since NGLview can fetch structures from pdb database i wondered if i could load the structure and then create a MDAnalysis.Universe with that information.

@jbarnoud

This comment has been minimized.

Show comment
Hide comment
@jbarnoud

jbarnoud Aug 23, 2018

@ArtVoro I do not know if you can build a MDAnalysis Universe from NGLview, but you can fetch a structure from the PDB with MDAnalysis: u = mda.fetch_mmtf("1BTA").

jbarnoud commented Aug 23, 2018

@ArtVoro I do not know if you can build a MDAnalysis Universe from NGLview, but you can fetch a structure from the PDB with MDAnalysis: u = mda.fetch_mmtf("1BTA").

@ArtVoro

This comment has been minimized.

Show comment
Hide comment
@ArtVoro

ArtVoro Aug 23, 2018

thanks! thats even better.

ArtVoro commented Aug 23, 2018

thanks! thats even better.

@ArtVoro

This comment has been minimized.

Show comment
Hide comment
@ArtVoro

ArtVoro Aug 24, 2018

@hainm can you tell me where certain information is stored in nglview, e.g. how is component_0 build up, how many residues does it have, what are the names, what are the positions of each atom/residue/etc.

ArtVoro commented Aug 24, 2018

@hainm can you tell me where certain information is stored in nglview, e.g. how is component_0 build up, how many residues does it have, what are the names, what are the positions of each atom/residue/etc.

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 24, 2018

Collaborator

@ArtVoro You can't do much thing from nglview's component. Please use the bakend (mdanalysis) for your work.

The component is just a simple viewer of each structure you added to the master view.
https://github.com/arose/nglview/blob/master/nglview/component.py

Collaborator

hainm commented Aug 24, 2018

@ArtVoro You can't do much thing from nglview's component. Please use the bakend (mdanalysis) for your work.

The component is just a simple viewer of each structure you added to the master view.
https://github.com/arose/nglview/blob/master/nglview/component.py

@ArtVoro

This comment has been minimized.

Show comment
Hide comment
@ArtVoro

ArtVoro Aug 24, 2018

thanks, I was just asking out of curiousity. ofcourse im using the backend, but i just wondered since some information has to be stored somewhere :) otherwise i have no clue how you can for example use selection syntax when creating any representation.

ArtVoro commented Aug 24, 2018

thanks, I was just asking out of curiousity. ofcourse im using the backend, but i just wondered since some information has to be stored somewhere :) otherwise i have no clue how you can for example use selection syntax when creating any representation.

@hainm

This comment has been minimized.

Show comment
Hide comment
@hainm

hainm Aug 24, 2018

Collaborator

nglview is using NGL for visualizing, so all the information is stored in its (NGL) objects (e.g: http://nglviewer.org/ngl/api/classes/component.html)

nglview can certainly get the data from NGL but it's not usually helpful (:D).

Collaborator

hainm commented Aug 24, 2018

nglview is using NGL for visualizing, so all the information is stored in its (NGL) objects (e.g: http://nglviewer.org/ngl/api/classes/component.html)

nglview can certainly get the data from NGL but it's not usually helpful (:D).

@melomcr

This comment has been minimized.

Show comment
Hide comment
@melomcr

melomcr Oct 9, 2018

ah ah, I think I already have a workaround now.

screen shot 2018-08-21 at 11 17 18 pm

Code

def on_change_frame(change):
    view._remote_call(
    'removeComponent', target='Stage', args=[
        1, # given that you have only one trajectory and the "buffer" is the 2nd component.
    ])
    frame = change['new']
    label_pos = [-10, 1, 1]
    label_rgb = [0.2,0.2,0.2]
    label_size = 20

    labels = list('abc')*100
    view.shape.add_label(label_pos, label_rgb, label_size, labels[frame])

view.observe(on_change_frame, 'frame')

PS: It's a workaround and might not work with different nglview version.

Just wanted to register my "+1" to adding a "remove_shape" interface. Would be super useful, but the work-around seems to still be effective.

melomcr commented Oct 9, 2018

ah ah, I think I already have a workaround now.

screen shot 2018-08-21 at 11 17 18 pm

Code

def on_change_frame(change):
    view._remote_call(
    'removeComponent', target='Stage', args=[
        1, # given that you have only one trajectory and the "buffer" is the 2nd component.
    ])
    frame = change['new']
    label_pos = [-10, 1, 1]
    label_rgb = [0.2,0.2,0.2]
    label_size = 20

    labels = list('abc')*100
    view.shape.add_label(label_pos, label_rgb, label_size, labels[frame])

view.observe(on_change_frame, 'frame')

PS: It's a workaround and might not work with different nglview version.

Just wanted to register my "+1" to adding a "remove_shape" interface. Would be super useful, but the work-around seems to still be effective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment