nglviewer / nglview

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

add_component 404 GET error. local filename? #697

Closed gph82 closed 7 years ago

gph82 commented 7 years ago

nglview 1.02b ipywidgets 7.0.1

iwd = nglview.show_structure_file(os.path.abs('file1.pdb'))
iwd

works, however:

iwd.add_component(os.path.abspath('file1.pdb'))
iwd

will just produce the already instantiated widget, but without the second structure. In the console, it will complain with:

Error: NetworkStreamer._read: status code 404

which, in the terminal is more verbose, telling me that it's trying to read the file /notebooks/file1.pdb. However, it is elsewhere. show_structure() seems to be able to deal with it, but not add_component()

[W 15:41:00.523 NotebookApp] 404 GET /notebooks/file1.pdb (::1) 1.22ms referer=http://localhost:8888/notebooks/Figure_summary.ipynb
hainm commented 7 years ago

Thanks, sounds like a bug. Will investigate tonight.

hainm commented 7 years ago

Can you post your notebook version too?

hainm commented 7 years ago

Can you post your notebook version too?

gph82 commented 7 years ago

5.0.0

hainm commented 7 years ago

And if you does not use abspath, will that work?

gph82 commented 7 years ago

no no, it does not work either. I just added it because I did not want to obscure things

gph82 commented 7 years ago

Seems to me that somewhere an os.path.basame is being done on the filename

gph82 commented 7 years ago

I'll work around it in the meantime with ad-hoc symlinks. I'm forced to use add_structure instead of add_component because I still parse read bfactors/radius-arrays to the worm representation

gph82 commented 7 years ago

where would the /notebooks/ folder be in my FS?

hainm commented 7 years ago

So here is the logic: There are two ways to send data to NGL, sending text blob (using file handler) or let NGL read the file path directly. The latter is much faster but it requires your file is in subfolder of your current working path.

I am not sure about your case, need to teat myself first.

gph82 commented 7 years ago

ok. I just updated the original issue, there was some inconsistencies in the issue

hainm commented 7 years ago

The show_structure_file works because it always read your file content first (python) then send that to ngl (JavaScript).

hainm commented 7 years ago

uhm, I can not reproduce yours.

screen shot 2017-09-29 at 11 12 18 pm
hainm commented 7 years ago
screen shot 2017-09-29 at 11 15 28 pm
hainm commented 7 years ago

@gph82 any response on this? thanks.

gph82 commented 7 years ago

Hi @hainm . Not really sure your example reproduces mine.... screenshot_20171004_163202

gph82 commented 7 years ago

Meanwhile, on the terminal...

[W 16:30:04.845 NotebookApp] 404 GET /notebooks/1U19.pdb (::1): No such file or directory: 1U19.pdb

but the file exists on the home directory for sure

hainm commented 7 years ago

how can you get two structures in that display?

Can you just try one?

hainm commented 7 years ago

what's the output of

!pwd

os.path.abspath("1U19.pdb")
gph82 commented 7 years ago

Okay i'll make a more comprehensive notebook, I think we're talking past each other

hainm commented 7 years ago

would be great. If possible, please share your troublesome files too. thanks.

On Wed, Oct 4, 2017 at 10:46 AM, Guillermo Pérez-Hernández < notifications@github.com> wrote:

Okay i'll make a more comprehensive notebook, I think we're talking past each other

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

gph82 commented 7 years ago

Here we go 3CAP.zip 1U19.zip Untitled.zip

hainm commented 7 years ago

work fine to me after editing.

screen shot 2017-10-04 at 10 11 57 pm

PS: Your command is not correct

file2 = '1U19.pdb'
print(os.path.exists(file2), os.path.abspath(file2))
geom2 = md.load(file2)
iwd = nglview.show_mdtraj(geom1)
iwd = iwd.add_trajectory(geom2) # why overwrite `iwd`?
iwd
hainm commented 7 years ago

I don't get any 404 error:

screen shot 2017-10-04 at 10 13 54 pm
hainm commented 7 years ago

oops, by the way, I am testing with nglview 1.0.b4

hainm commented 7 years ago

fine with 1.0.b2 too.

@arose can you try again? Here is the updated notebook that correct the command. (change .txt to .ipynb)

Untitled.txt

hainm commented 7 years ago

@gph82 I guess you need to play around with realpath and abspath in this code: https://github.com/arose/nglview/blob/master/nglview/utils/py_utils.py#L196-L197

May be try to change:

return os.path.relpath(self.src)

to

return os.path.relpath(os.path.realpath(self.src))

or print out to see what happens.

gph82 commented 7 years ago

Untitled.zip Thanks for pointing out that one mistake. That was a "typo" of writing up the example notebook quickly (see attached updated version).

In any case, the FileManager class was calling the

 self._remote_call(
           "loadFile", target='Stage', args=args, kwargs=kwargs2)

with the filename-string instead of the already parsed string with the actual structure. Was that intended? You can try running the updated notebook with this branch (or just copy the "for debugging" to yours): https://github.com/arose/nglview/compare/master...gph82:abs_path_file_obj_reading?expand=1

I'm trying to play around with it but still no luck

hainm commented 7 years ago

Was that intended?

Yes, I explained here: https://github.com/arose/nglview/issues/697#issuecomment-333134655

In the worse case, use FileStructure

fs = nv.FileStructure('your.pdb')
view.add_component(fs)

I think this should work :D

gph82 commented 7 years ago

I'll try that, thanks. Regarding your https://github.com/arose/nglview/issues/697#issuecomment-333134655 I understood that, but even if the abspath is parsed to the server, it fails... screenshot_20171005_144343

hainm commented 7 years ago

yes, absolute path will be failed, that's the way WWW works for security reason.

hainm commented 7 years ago

uhm, I am afraid that you need to figure out by yourself in this case since I can not reproduce your issue. :( good luck, man.

gph82 commented 7 years ago

I understand. Thanks a lot, man. Your workaround worked, BTW! Keep up the good work!

hainm commented 7 years ago

Your workaround worked,

In this case, just FYI: https://github.com/arose/nglview#notes