michellab / bssccpbiosim2022

Material for the BioSimSpace workshop at the upcoming 2022 CCPBioSim Training Week
GNU General Public License v3.0
9 stars 3 forks source link

analyse_RBFE import error #16

Closed jmichel80 closed 2 years ago

jmichel80 commented 2 years ago

When executing thte 1st cell of this notebook I can get an import error for networkanalysis. Consequently the rest of the notebook cannot be executed.

image

This may be because the folder 'workshop/freenrgworkflows' is empty. There may be an issue with the way the workshop materials are pushed onto the image.

freenrgworkflows at https://github.com/michellab/bssccpbiosim2022 is actually a link to another github repo

Can we introduce this dependency differently so it is easier to package and distribute the tutorial ?

lohedges commented 2 years ago

It looks like you are providing freenrgworkflows as a git submodule? How are you cloning the workshop material to the image? Have you forgotten to do this recursively so that the submodule is loaded. (Or activated the submodules afterwords.)

I would strongly advise against monkeying with the system path to import the submodule, as is currently done in the notebook. Assuming the folder is there, you should just be able to do:

from ..freenrgworkflows import networkanalysis
annamherz commented 2 years ago

It looks like you are providing freenrgworkflows as a git submodule?

Hello, yep I added it as a git submodule and this worked okay locally with the sys.path.insert, but I guess not the image. I've just tried copying it entirely (which I think should solve the need to recursively copy) and using :

from ..freenrgworkflows.networkanalysis import networkanalysis
from ..freenrgworkflows.networkanalysis import experiments
from ..freenrgworkflows.networkanalysis import stats

however I get the following error ImportError: attempted relative import with no known parent package

I'm not really sure how to get it to work without the sys.path.insert(1, '../freenrgworkflows/networkanalysis/') ?

lohedges commented 2 years ago

Ah, sorry about that, I forgot that you aren't importing it as part of another package, rather from a notebook directly. For this purpose, adding to the system search path is probably the easiest solution for now. Is the sys.path.insert(1, '../freenrgworkflows/networkanalysis/') approach still not working having copied oaver the missing files?

lohedges commented 2 years ago

Quick thought, for the purposes of the workshop can you not just pip install freenrgworkflows into the environment? It's pure Python so shouldn't affect anything else. That way you can import it directly.

(Obviously having a conda package is the ideal long-term solution if we want to use it as a dependency.)

jmichel80 commented 2 years ago

If that works that’s a good short term fix.

longer term we would like to use https://github.com/OpenFreeEnergy/cinnabar and are hoping to work with OpenFE to make sure the package supports the functionality we have been relying on in freenrgworkfows

annamherz commented 2 years ago

Quick thought, for the purposes of the workshop can you not just pip install freenrgworkflows into the environment? It's pure Python so shouldn't affect anything else. That way you can import it directly.

If this is possible that would be the best way I think!

Is the sys.path.insert(1, '../freenrgworkflows/networkanalysis/') approach still not working having copied oaver the missing files?

It works now that I've just added freenergworkflows as a directory and removed all the git stuff from it. It currently is able to imported like this for the workshop, so I think that's okay now!