Skip to content

Commit

Permalink
Added ModelAngelo to cmake and added weights download attempt during …
Browse files Browse the repository at this point in the history
…cmake configure time.
  • Loading branch information
dkimanius committed Sep 25, 2023
1 parent f61d7c2 commit 237a297
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ list(APPEND RELION_PYTHON_WRAPPERS
python_blush
python_dynamight
python_topaz
python_modelangelo
python_fetch_weights
python_tomo_import
python_tomo_exclude_tilt_images
python_tomo_align_tilt_series
Expand All @@ -472,6 +474,21 @@ foreach (SCRIPT_FILE ${RELION_PYTHON_WRAPPERS})
)
endforeach()

message(STATUS "Will attempts to download model weights for dependent packages...")

execute_process(
COMMAND bash ${CMAKE_BINARY_DIR}/bin/relion_python_fetch_weights
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
RESULT_VARIABLE SCRIPT_RESULT
)

# Check the result of the script execution
if(SCRIPT_RESULT EQUAL 0)
message(STATUS "Successfully downloaded model weights")
else()
message(WARNING "Failed to download model weights: ${SCRIPT_RESULT}")
endif()

# ----------------------------------------------------------------------COPY SCRIPTS--

if(FORCE_OWN_FFTW)
Expand Down
5 changes: 5 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ dependencies:
- fastcluster==1.2.6
- seaborn==0.12.2
- dill==0.3.7
- pyhmmer>=0.10.1
- fair-esm
- einops
- scipy
- git+https://github.com/3dem/relion-classranker@b6e751e5cb4205d8e9b36d0ae38c3687b3395acb
- git+https://github.com/3dem/relion-blush
- git+https://github.com/3dem/DynaMight
- git+https://github.com/3dem/topaz
- git+https://github.com/3dem/model-angelo
- ".[vis]"


46 changes: 46 additions & 0 deletions scripts/python_fetch_weights.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Get the directory of the currently executing script
script_dir="$(dirname "$0")"

# Call Class Ranker weight download ##############################################
echo "Attempting to download weights for class ranker..."

target_path="$script_dir/relion_python_classranker"

if [ -x "$target_path" ]; then
# Execute the target binary
"$target_path"
else
echo "Error: $target_binary not found or not executable in $script_dir."
exit 1
fi

# Call Blush weight download #####################################################
echo "Attempting to download weights for Blush..."

target_path="$script_dir/relion_python_blush"

if [ -x "$target_path" ]; then
# Execute the target binary
"$target_path"
else
echo "Error: $target_binary not found or not executable in $script_dir."
exit 1
fi

# ModelAngelo weight download ####################################################
echo "Attempting to download weights for ModelAngelo..."
target_path="$script_dir/relion_python_modelangelo"

if [ -x "$target_path" ]; then
# Execute the target binary
"$target_path"
else
echo "Error: $target_binary not found or not executable in $script_dir."
exit 1
fi

# Exit
exit 0

46 changes: 46 additions & 0 deletions scripts/python_modelangelo.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

print_error() {
echo "
---------------------------------- PYTHON ERROR ---------------------------------
Has RELION been provided a Python interpreter with the correct environment?
The interpreter can be passed to RELION either during Cmake configuration by
using the Cmake flag -DPYTHON_EXE_PATH=<path/to/python/interpreter>.
NOTE: For some modules TORCH_HOME needs to be set to find pretrained models
---------------------------------------------------------------------------------
Using python executable: $1
"
}

# Set the Python executable path
python_executable="@PYTHON_EXE_PATH@"
torch_home="@TORCH_HOME_PATH@"

# Check if the python executable exists
if [ ! -x "$python_executable" ]; then
# Check for default python executable
python_executable=$(command -v python)

if [ -z "$python_executable" ]; then
print_error "$python_executable"
exit 1
fi
fi

# Run the Python script with forwarded arguments
if [ -n "$torch_home" ]; then
TORCH_HOME="$torch_home" "$python_executable" -c "from model_angelo.__main__ import main; exit(main())" "$@"
else
"$python_executable" -c "from model_angelo.__main__ import main; exit(main())" "$@"
fi

# Check the return status of the python command
if [ $? -ne 0 ]; then
print_error "$python_executable"
exit 2
fi

# Exit
exit 0

0 comments on commit 237a297

Please sign in to comment.