westlake-repl / SaProt

Saprot: Protein Language Model with Structural Alphabet (AA+3Di)
MIT License
339 stars 32 forks source link

Model use - relative imports #54

Open Hrovatin opened 2 months ago

Hrovatin commented 2 months ago

I cloned the repo yesterday and tried to import from SaProt.model.saprot.base import SaprotBaseModel as per some of the code examples. This failed as the "utils" import in many of the model files was not relative. Would suggest changing it to e.g. from ...utils.metrics import count_f1_max and similar across model scripts.

LTEnjoy commented 2 months ago

Hi,

We have thought about it before but we thought it would make the relation among files to be more complicated and may cause some unexpected errors when your execution directory varies. A simple workaround is to add the root path of this project to sys.path, e.g.:

import sys
sys.path.append("/your/path/to/SaProt")

Then it should work well.

Hrovatin commented 2 months ago

This is not ideal as then it may be unclear if utils should be loaded from SaProt or my own utils directory that is somewhere in the path Best solution would be to just make it a python package so that everything can be imported as SaProt.utils etc

LTEnjoy commented 2 months ago

In real situation it hardly happens that two utils directories conflict as every file in SaProt will load specific functions defined in utils, e.g. utils.metrics import count_f1_max. This would lead the system to the true utils directory. I understand the best solution to pack the SaProt into a individual pacakage but given some coding logics in the repo it might be not easy to implement it. I will add a __init__.py file at the root path that will automatically add the root path to sys.path. This could resolve the import problem from outer directory.

LTEnjoy commented 2 months ago

We have already uploaded a __init__.py for outer import. You can clone the repo again and try it out:)