lab-cosmo / chemiscope

An interactive structure/property explorer for materials and molecules
http://chemiscope.org
BSD 3-Clause "New" or "Revised" License
121 stars 29 forks source link

Considering the pyodide_kernel interpreter in the _is_running_in_notebook #281

Closed agoscinski closed 1 year ago

agoscinski commented 1 year ago

jupyterlite is using pyodide_kernel interpreter to run python code in the browser, we add this so chemiscope can be run within jupyterlite

From jupyterlite image try out https://agoscinski.github.io/jupyterlite-playground/lab/index.html (adding example currently, might need 20 minutes till it is on the homepage) EDIT: okay works now, use the cosmo.ipynb

I added this change to the code and it worked out for me

Luthaf commented 1 year ago

This looks good, although I could not understand where the javascript part of the extension is loaded from. Removing most of the code in your example notebook, I just patched this function with chemiscope.jupyter._is_running_in_notebook = lambda : True, and it worked.

However, I'm not sure if it loads the JS from: github-pages, through piplite (and some kind of in-memory FS) or from npm? Do you know how this work?

agoscinski commented 1 year ago

I think its on the github server of the page, because if I don't install chemiscope by specifying it in the requirements.txt https://github.com/agoscinski/jupyterlite-playground/actions/runs/4849978532/jobs/8642471828 (see Install dependencies), it does not work.

Luthaf commented 1 year ago

ok, but then why do you need the piplite.install call?

agoscinski commented 1 year ago

I don't fully understand this either.

My impression is that you need to install chemiscope in the building to install the javascript part of chemiscope (otherwise you get a javascript error running the widget). And you need to install again the python part of chemiscope for the pyodide kernel, because in the building it is just installed as a regular python package. The pyodide package installation happens when it is run in the browser, but I think it could be also installed during building by putting the dependency in some other file, but I haven't figured it out yet.

EDIT: As far as I understand, the pyodide kernel is run on the client site, therefore an installation on the server site does not work.