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

Add text to a view #626

Closed
hainm opened this issue Jun 26, 2017 · 18 comments · Fixed by #627
Closed

Add text to a view #626

hainm opened this issue Jun 26, 2017 · 18 comments · Fixed by #627

Comments

@hainm
Copy link
Collaborator

hainm commented Jun 26, 2017

cc @kain88-de

@hainm hainm mentioned this issue Jun 27, 2017
@satary
Copy link
Contributor

satary commented Feb 26, 2019

Hello @hainm !
This way works if you want to have "rotatable" text, but what if I need to overlay some text "in front" of the view? Are there any relatively simple ways to do that?
edited:
It looks like it is certainly possible, as atom name is displayed at the upper left corner while picking atoms.

@hainm
Copy link
Collaborator Author

hainm commented Feb 26, 2019

@arose: any idea? Thanks.

@arose
Copy link
Collaborator

arose commented Feb 26, 2019

To some extent you can use the zOffset parameter. If that is larger than the bounding radius of your models then all text will be rendered in front.

@hainm
Copy link
Collaborator Author

hainm commented Feb 26, 2019

and may be view.shape.add_text is another option if I understand the issue correctly.
https://github.com/arose/nglview/blob/b15ccc9d49ad191888be3f2ff3921b79ae647020/nglview/shape.py#L114

@satary
Copy link
Contributor

satary commented Mar 5, 2019

@arose Sorry for the late reply.
The idea is not to just place the label in front of the molecule. The idea is to overlay the text onto the widget itself (to add title and legend, for example).
Something like the atom label at the left corner of this screenshot.
nglview_screenshot

Another question is why this atom label (I mean at the left corner of the screenshot) is not rendered if I want to save the image?

@arose
Copy link
Collaborator

arose commented Mar 5, 2019

The label is not rendered in screenshots because its is not part of the 3d scene but a simple html element. As far as I know there is no API to add html to the widget but maybe @hainm has an idea.

Btw. Is that structure in the PDB archive? The protein look interestingly symmetric.

@satary
Copy link
Contributor

satary commented Mar 5, 2019

@arose Ok, got it.
That is a part of the nucleosome (1kx5 pdbID), its got a two-fold symmetry axis =)

@hainm
Copy link
Collaborator Author

hainm commented Mar 5, 2019

There is no API to add HTML yet, but there's a hacky way to do it by using view._execute_js_code
#768

code = """
$("<div></div>")
            .css("position", "absolute")
            .css("top", "5%")
            .css("left", "3%")
            .css("background-color", "white")
            .css("padding", "2px 5px 2px 5px")
            .css("opacity", "0.7")
            .appendTo(this.$container);
"""
view._execute_js_code(code)

You need to play around with this to add your own text. good luck.

@arose
Copy link
Collaborator

arose commented Mar 5, 2019

That is a part of the nucleosome (1kx5 pdbID), its got a two-fold symmetry axis =)

Thank, looks like there is local C2 symmetry, made a snapshot https://molstar.org/viewer/?snapshot-url=https%3A%2F%2Fwebchem.ncbr.muni.cz%2Fmolstar-state%2Fget%2F5de7da28-c560-4dc0-8c31-fce8f383348b

nucleosome

@hainm
Copy link
Collaborator Author

hainm commented Mar 7, 2019

screen shot 2019-03-07 at 12 07 50 am

@satary
Copy link
Contributor

satary commented Mar 7, 2019

@hainm Thanks for the great example!

@scottwsides
Copy link

Any progress on a 'add_title' method? The above did not work for me.

@hainm
Copy link
Collaborator Author

hainm commented Aug 2, 2022

Any progress on a 'add_title' method? The above did not work for me.

have you tried in the traditional notebook yet?

@scottwsides
Copy link

I havent... but I'm never going to use the trad notebook. I've drunk the jupyterlab kool-aid ;-)

@hainm
Copy link
Collaborator Author

hainm commented Aug 2, 2022

jupyterlab was not pleasure to work with in 2017 when this topic was opened, so we have not revisited the lab yet.

@scottwsides
Copy link

scottwsides commented Aug 2, 2022

Understood. But my feeling is that jupyterlab is definitely the weapon of choice for most. Its the logical progression through the years of

python cmd line ---> ipython cmd line ---> jupyter notebook ---> jupyterlab notebook.

I dont think there's any going back. I'd love NGLView to have better integration because Chemistream leans heavily on your great library, and Chemistream is exclusively jupyterlab for UI

@hainm
Copy link
Collaborator Author

hainm commented Aug 2, 2022

I dont think there's any going back. I'd love NGLView to have better integration because Chemistream leans heavily on your great library, and Chemistream is exclusively jupyterlab for UI

yeah, I agree with you about jupyterlab. I had more free time when I was a postdocs to work on nglview than nowadays.

@scottwsides
Copy link

Copy that... I hear ya brother ;-)

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 a pull request may close this issue.

4 participants