File size: 3,944 Bytes
4653e06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# bash run.sh Protenix 1

#!/bin/bash
algorithm="$1"
gpu_id="$2"

af3_input_json=./examples/alphafold3_inputs.json 
targets_dir=./examples/targets
output_root_dir="./examples/outputs"
time_log_root_dir="./examples/times"
ground_truth_dir="./examples/ground_truths"
overlay_size=2048


prediction_root_dir="$output_root_dir/prediction"
evaluation_root_dir="$output_root_dir/evaluation"
input_root_dir="$output_root_dir/input"
time_log_dir="$time_log_root_dir"

recalculate=false

while getopts ":r" opt; do
  case $opt in
    r) recalculate=true
    ;;
    \?) echo "Invalid option -$OPTARG" >&2
    ;;
  esac
done
echo "Recalculate all algorithm outputs: $recalculate"

if "$recalculate"; then
    # Clean output dir 
    rm -rf "$prediction_root_dir"
    rm -rf "$evaluation_root_dir"
    rm -rf "$input_root_dir"
    rm -rf "$time_log_dir"
fi

# Create the output directory if it doesn't exist
mkdir -p "$prediction_root_dir"
mkdir -p "$evaluation_root_dir"
mkdir -p "$input_root_dir"
mkdir -p "$time_log_dir"

# start evaluation environment
conda init
. /root/miniconda3/etc/profile.d/conda.sh
conda activate foldbench

# Loop through each algorithm in the algorithms directory
for algorithm_dir in algorithms/*; do

    if [ -d "$algorithm_dir" ] && [ $(basename "$algorithm_dir") != "base" ]; then
        algorithm_name=$(basename "$algorithm_dir")

        # If an algorithm is specified, only continue if algorithm_name matches
        if [ -z "$algorithm" ] || [ "$algorithm_name" == "$algorithm" ]; then

            prediction_dir="$prediction_root_dir/${algorithm_name}"
            time_log_file="$time_log_dir/${algorithm_name}_time.log"
            # Check if the output file does not exist
            # if [ ! -e "$prediction_dir" ]; then
            if [ -e "$prediction_dir" ]; then
                echo "Processing algorithm: $algorithm_name"

                input_dir="$input_root_dir/${algorithm_name}"
                evaluation_dir="$evaluation_root_dir/${algorithm_name}"
                
                # create dirs for prediction, input, evaluation
                mkdir -p "$prediction_dir"
                mkdir -p "$input_dir"
                mkdir -p "$evaluation_dir"

                # Remove an existing container overlay, if any
                rm -rf "algorithms/${algorithm_name}/overlay.img"
                # Create writable overlay for the container
                apptainer overlay create --size $overlay_size --sparse "algorithms/${algorithm_name}/overlay.img"

                # Calculate predictions
                echo "RUN ALGORITHM $algorithm_name"
                { time ( apptainer exec --nv \
                    --overlay "algorithms/${algorithm_name}/overlay.img" \
                    -B $af3_input_json:/algo/alphafold3_inputs.json \
                    -B $output_root_dir:/algo/outputs \
                    "algorithms/${algorithm_name}/container.sif" \
                    bash -c "cd /algo \
                    && ./make_predictions.sh ${af3_input_json} ${input_dir} ${prediction_dir} ${evaluation_dir} ${gpu_id}" 2>&1 ); } 2> "$time_log_file"
                
                echo "EVALUATE PREDICTIONS"
                python evaluate.py --targets_dir ${targets_dir} --prediction_dir ${prediction_dir} --evaluation_dir ${evaluation_dir} --ground_truth_dir ${ground_truth_dir}
                python task_score_summary.py --algorithm_names ${algorithm_name}
                
            else
                echo "Skipping algorithm: $algorithm_name. Output file already exists."

                # Remove an existing container overlay, if any
                # FIXME: mb put this part outside if-else statement? 
                # Now when each dataset has separate container overlays,
                # old dataset overlays must be removed if output file already exists.
                rm -rf "algorithms/${algorithm_name}/overlay.img"
            fi

        fi

    fi
done