-
Notifications
You must be signed in to change notification settings - Fork 136
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 about nglview: Please ask here first [3] #948
Comments
Hi! Thanks for your great work on the NGL Viewer - highly appreciated! In this minimal example, I have two point clouds that I have added each with Is there a way to rename these "shape" labels (to e.g. "blue cloud" and "cyan cloud")? Here my minimal code example: https://gist.github.com/dominiquesydow/0cc044a9936836bd3ceb096697307870 FYI: I am using The documentation for
Is there maybe another argument that I can pass here to add a name? If so, I have not found the right keyword, yet. |
hi @dominiquesydow, that name is hard coded. You can to hack the JS code: CODEview._js('''
var params = {
'position1': [0, 0, 0],
'position2': [1, 1, 1],
'color': [1, 0, 0],
'color2' :[0, 1, 0],
'radius': [1],}
var shape = new NGL.Shape("abc");
var buffer = new NGL.ConeBuffer(params);
shape.addBuffer(buffer);
var shapeComp = this.stage.addComponentFromObject(shape);
shapeComp.addRepresentation("buffer");
'''
) |
Hi @haim, thanks a lot for your super quick help - it works perfectly! |
Hi @hainm, do you know how to select atoms using their atom types as implemented in lammps? Many thanks, Tai |
Hi, no I don’t. |
@taidbui Any way, you can use this: https://nglviewer.org/ngl/api/manual/usage/selection-language.html |
@hainm, thanks a lot for sharing this. It's very helpful. |
Is it possible to display all models simultaneously in nglview? In ngl this is the default, but I can't figure it out in nglview. Example multi-model structure: |
@sbliven Please see this thread: #765 (comment) |
How is the initial
|
hi @enricogandini: The value comes from Line 367 in a2bac8c
https://github.com/nglviewer/ngl/blob/963b4fecde843fdf80c580e8f7bd55989db6a6f6/src/controls/viewer-controls.ts#L110 |
Thank you @hainm! |
How would I go about monitoring a "loaded" signal for a large surface representation so that I could put a little loading symbol into the webpage while the surface representation was loading? Basically I would like an equivalent of stage.signals.clicked.add(function() {....}) that fires when my surface representation (e.g. surfaceRep) finishes loading instead of when the stage is clicked. |
hi @wavy007: Please ask the question in |
Thanks, I've just posted there. I'm using NGL! Sorry about that! |
Topology changing with timeHello, I am trying to make a movie with NGLView with reactions. I want to display a trajectory for which the name of atoms changes with time. Is it possible to have the topology change per frame? Minimal example in which "Na" at time 0 becomes "O" at time 1: (nice chemistry O_o ) file.xyz
file.pdb
I tried loading with mdtraj but realized the topology is fixed. Then saw issue #620 but cannot manage to adapt it to my use-case. |
hi @dlesnicki |
Thank you @hainm for your help! Unfortunately it did not solve my case. As you can see on my screenshot, the structures for frame 0 and 1 have both the correct coordinates but frame 1 has a wrong atom name. Should I change something in get_structure_string()? |
hi @dlesnicki: You need to write your own |
How to display a trajectory that I have in form of a numpy array?I have a trajectory generated directly in python and I don't want to write it to disk. What is the easiest and/or most straightforward way to display this trajectory with nglview? |
hi @marvinbernhardt: You can use |
Hey hainm! Thank you for your answer, that is certainly one way to achieve what I asked for. What I need this for is teaching. I have modified MIND to save the trajectory (LJ liquid) directly in a numpy array. Now I am looking for a (as simple as possible) way for students to look at their trajectory, directly from python. So creating and loading a pdb file is not ideal. If you have any idea, please let me know. I looked at some of the backends, but they mostly are made for loading files. |
hi @marvinbernhardt: You still need to provide something (e.g: pdb, sdf, mol2 ...file) to create a topology for your structure so You can use this code to make your own Trajectory reader to feed to Lines 340 to 368 in b1d50de
|
I ended up using mdtraj, which is flexible enough to not use any files. Here is my wrapper function in case anyone is interested def show_numpy_trajectory(traj, box, aspect_ratio=5):
"""Show Numpy trajectory with constant box.
All atoms will be shown as argon atoms.
Keyword arguments:
traj -- Numpy array with shape (n_steps, 3, n_atoms) containing positions in nm
box -- Numpy array with shape (3) in nm
aspect_ratio -- parameter chaning the sphere size
Returns:
nglview.widget.NGLWidget
"""
# create an argon topology
top = md.Topology()
chain = top.add_chain()
for i in range(traj.shape[2]):
residue = top.add_residue('AR', chain)
top.add_atom('Ar', md.element.argon, residue)
# create trajectory
n_frames = len(traj)
t = md.Trajectory(traj.swapaxes(1, 2), topology=top,
unitcell_lengths=np.repeat(box[np.newaxis, ...], n_frames, axis=0),
unitcell_angles=np.ones((n_frames, 3))*90.0)
# create view and show trajectory
view = nv.show.show_mdtraj(t)
view.clear_representations()
view.add_representation('ball+stick', aspectRatio=aspect_ratio)
view.add_unitcell()
return view |
I think this has been asked before and answered with NO. When using iwd.display(gui=True), is there any way to programatically collapse a given component's menu, or the individual representation menus? I'm asking for the equivalent to hitting the "collapseAll"/minus sign icon. Thanks! |
hi @gph82 The naive GUI with |
Hi @hainm, yeah I had noticed, that's great, and has actually made me us nglviewer much more lately. Anyway, I know why the question sounded familiar, I myself (:facepalm: ) had followed-up on a similar question here, without success: nglviewer/ngl#745 |
How to get the unit cell vectors from different frames?Hi! How can be the unit cell vectors from different frames be obtained? For example, working with the demo trajectory, the coordinates from a given frame (3, for instance) can be obtained this way:
Is there a way to get the unit cell vectors for frame 3 from the nglview.NGLWidget object? The pbc box in 'nv.datafiles.XTC' is not constant in time. Thanks in advance! |
hi @dprada No, there is no way. Can you get that from
PS: |
Ok. Thanks for the tip! I will use view[0] from now on. |
Hi. |
@khoroshyy: do the structures have the same topology with different coordinates? |
Yes, they are the same molecules in different conformations. 10 conformation per file. |
But if there is a way to load different molecules I would be interested also. |
@khoroshyy: You can try one of the supported packages here (e.g: Here is an example from
|
|
@hainm Thanks, I was wondering how to load files without making FF topology for it. |
Thank you so much for this excellent application. I am also struggling to represent multiple bonds. Was there ever any resolution to this question? |
hi @cadalyjr, I don't think so. |
Is it possible to apply the workaround to the Chrome/Linux NGL (nglviewer/ngl#525) background bug in nglview? In the upstream issue |
hi @krassowski, please try |
Thank you @hainm, it does something, though it does not fix it view._execute_js_code('this.stage.viewer.renderer.setClearColor(0xffffff, 0.01);this.stage.viewer.requestRender();') When I change the second argument I finally get a different background colour but the I get blinking and model disappearing unless actively being rotated. |
hi @krassowski Would be best to ask |
This is very silly question, but is there a simple way to display a single chain using |
Show the whole structure and use selection language?
yeah, just ignore it. I don't recall either. :D |
So as a naive user I thought that maybe I could just pass a query as a keyword argument to |
I think user need to pass the Line 189 in c265da5
I am not sure, this will populate all the selection keys in the link I sent you. Thanks. |
New thread: #1000 |
hi @davidRFB, unfortunately I don't think there is a way to do that. Cheers. |
@davidRFB - When you pick atoms, they're added to a global instance of DihedralRepresentation, which takes parameters Alternatively, if your'e building a figure, you can add an explicit DihedralRepresentation (again, not sure if this is exposed through the nglview API? It's a representation of type "dihedral") |
@fredludlow unfortunately it's not exposed to
|
For any questions relating to how/why/ ... Or anything you don't know where to ask.
For bug, suggestion or anything you want to ask separately, please open seperate issue
Previous Q&As
Or click the
Q&A
label.The text was updated successfully, but these errors were encountered: