Skip to content

Commit

Permalink
Merge pull request #366 from KosinskiLab/rearange-backend-initialisation
Browse files Browse the repository at this point in the history
Rearange backend initialisation
  • Loading branch information
dingquanyu authored Jun 14, 2024
2 parents 0e3af95 + 03fc096 commit a5d3f74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/github_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ jobs:
pip install -e alphafold --no-deps
export PYTHONPATH=$PWD/AlphaLink2:$PYTHONPATH
# install dependencies for AlphaLink backend
pip install torch==1.13.0+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
pip install setuptools==69.5.1 # Downgrade setuptools to avoid crashes when installing unicore
git clone https://github.com/dptech-corp/Uni-Core.git
cd Uni-Core
python setup.py install --disable-cuda-ext
cd ../
# pip install torch==1.13.0+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
# pip install setuptools==69.5.1 # Downgrade setuptools to avoid crashes when installing unicore
# git clone https://github.com/dptech-corp/Uni-Core.git
# cd Uni-Core
# python setup.py install --disable-cuda-ext
# cd .
python test/test_python_imports.py
- if: matrix.install-type == 'developer'
run: |
Expand Down Expand Up @@ -124,4 +124,4 @@ jobs:
context: .
file: ./docker/analysis.dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/fold_analysis:${{ github.event.release.tag_name }}
tags: ${{ secrets.DOCKER_USERNAME }}/fold_analysis:${{ github.event.release.tag_name }}
27 changes: 20 additions & 7 deletions alphapulldown/folding_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
Copyright (c) 2023 European Molecular Biology Laboratory
Author: Valentin Maurer <valentin.maurer@embl-hamburg.de>
Dingquan Yu <dingquan.yu@embl-hamburg.de>
"""

from typing import Dict, List

from absl import logging
from .alphafold_backend import AlphaFoldBackend
from .alphalink_backend import AlphaLinkBackend
from .unifold_backend import UnifoldBackend

logging.set_verbosity(logging.INFO)

class FoldingBackendManager:
"""
Expand All @@ -31,14 +30,28 @@ class FoldingBackendManager:

def __init__(self):
self._BACKEND_REGISTRY = {
"alphafold": AlphaFoldBackend,
"unifold": UnifoldBackend,
"alphalink": AlphaLinkBackend
"alphafold": AlphaFoldBackend
}
self.import_backends()
self._backend_name = "alphafold"
self._backend = self._BACKEND_REGISTRY[self._backend_name]()
self._backend_args = {}

def import_backends(self) -> None:
"""Import all available backends"""
try:
from .alphalink_backend import AlphaLinkBackend
self._BACKEND_REGISTRY.update({"alphalink": AlphaLinkBackend})
except Exception as e:
logging.warning("Failed to import AlphaLinkBackend. Perhaps you haven't installed all the required dependencies.")

try:
from .unifold_backend import UnifoldBackend
self._BACKEND_REGISTRY.update({"unifold": UnifoldBackend})

except Exception as e:
logging.warning("Failed to import UnifoldBackend. Perhaps you haven't installed all the required dependencies.")

def __repr__(self):
return f"<BackendManager: using {self._backend_name}>"

Expand Down
5 changes: 2 additions & 3 deletions test/test_python_imports.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from alphapulldown.utils import *
from alphapulldown.folding_backend import *
import io
import warnings
import subprocess
Expand All @@ -13,8 +12,8 @@
from typing import Dict, List
from os.path import exists, join

from alphapulldown.folding_backend import backend
from alphapulldown.objects import MultimericObject
from alphapulldown.folding_backend import FoldingBackendManager
from alphapulldown.objects import MultimericObject, MonomericObject
from alphapulldown.utils.modelling_setup import create_interactors
from absl import logging
logging.set_verbosity(logging.INFO)
Expand Down

0 comments on commit a5d3f74

Please sign in to comment.