jgreener64 / Bio3DView.jl

A Julia package to view macromolecular structures in the REPL, in a Jupyter notebook/JupyterLab or in Pluto
Other
33 stars 7 forks source link

Unit cell not displaying in Pluto #8

Closed eahenle closed 3 years ago

eahenle commented 3 years ago

Great tool! I am building a UI in Pluto for a project with @CorySimon and have found that the unit cell box does not display when using viewfile. The same code and input files produce the correct result in Jupyter, oddly enough.

jgreener64 commented 3 years ago

I can reproduce this with:

viewfile("IRMOF-1.xyz", "xyz", isosurface=IsoSurface("IRMOF-1.cube", -5.0), vtkcell="IRMOF-1.vtk")

It works in Jupyter but not in Pluto. I don't know why, sadly, and won't have time to look in detail.

diegozea commented 3 years ago

Hi!

I could not understand the problem, but it looks related to how Pluto is executing the JavaScript. For these lines (files are in the example folder of this repo):

using Bio3DView

isosurface = IsoSurface("SBMOF-1.cube", 100.0, wireframe=true,
                color="green") # contours at -5 kJ/mol

viewfile("SBMOF-1.xyz", "xyz"; isosurface=isosurface, vtkcell="SBMOF-1.vtk",
            axes=Axes(5, 0.3), cameraangle=CameraAngle(0, 0, 0, 0, 0, 0, 0, 1))

The error in the JavaScript console is:

image

That's related to this part on Plutos' js code:

image

My JavaScript knowledge isn't good enough to understand what is going on here. But, maybe @fonsp can give us a hint :)

Cheers

jgreener64 commented 3 years ago

Thanks for having a look Diego. Possibly a scoping issue.

fonsp commented 3 years ago

What is the question exactly?

eahenle commented 3 years ago

@fonsp we are trying to determine why the code:

using Bio3DView

box = Box([0.0, 0.0, 0.0], [6.0, 6.0, 6.0])

viewfile("benzene.sdf", "sdf", box=box)

Produces a different result in Pluto vs. Jupyter. Side-by-side:

2020-12-01

The box is missing in Pluto :(

@diegozea noticed Uncaught ReferenceErrors in the JS console. I guess the question really is: does the fix for this exist on Bio3DView's end, or Pluto's?

fonsp commented 3 years ago

Can you take this screenshot again but without cropping?

eahenle commented 3 years ago

Not much else to see: image

Complete output text: localhost-1606835271833.log

diegozea commented 3 years ago

Hi! I was looking into this problem, and I found that the Uncaught ReferenceError: $3Dmol is not defined error only appears when we do:

js_3dmol = read(path_3dmol, String)
"<script type='text/javascript'>$js_3dmol</script>"

If we change that to using an online source, the problem disappears, i.e.:

"<script type='text/javascript' src='https://3Dmol.org/build/3Dmol-min.js'></script>"

So, I tried using src and a relative URL to the local file, e.g.:

"<script type='text/javascript' src='$path_3dmol'></script>"

But this doesn't work as Pluto is looking for the file at http://localhost:1234 (that looks related to this Pluto issue: https://github.com/fonsp/Pluto.jl/issues/171)

image

@fonsp Do you have an idea about what could be the difference between including the js code inside the script tag or using it with a source URL? However, we also include the JQuery code inside a script tag without problems, so maybe there is something strange with the 3Dmol code. Also, do you know how we can reference a local javascript located at this Julia repo? I guess that could solve this problem. Thanks in advance,

Cheers,