File size: 6,308 Bytes
84a242a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
export NCCL_ASYNC_ERROR_HANDLING=1
export TORCH_NCCL_BLOCKING_WAIT=1
export TORCH_NCCL_HEARTBEAT_TIMEOUT_SEC=7200   # or longer
export TORCH_NCCL_ENABLE_MONITORING=0 

#----------------------------------------Model and Benchmark Settings----------------------------------------#
# Devices to use
devices="0 1 2 3 4 5 6 7"

# '0' for training, '1' for testing
test=1

# For test, lightning saved version
# The first of the 5-fold versions to test, e.g., if trained versions are 20,21,22,23,24, set version=20
version=5
# (optional) a previous 5-fold result for comparison
original_version=90

# Benchmark to train/test; choose from:
# benchmark='posex'
# benchmark="astex_posex"
benchmark="moad"
# benchmark="posex_self_docking"
# benchmark="posex_cross_docking"
# benchmark='astex'
# benchmark='posebusters'

# Relaxation setting for the benchmark, 'both' for including both relaxed and unrelaxed poses
relaxation='both' # 'both', 'true', or 'false'

# Model to train
model='MolAS'

# Jump per-fold evaluation and use saved results (can activate after testing once)
jump_eval='false'

seed=42
#------------------------------------------------------------------------------------------------------------#

num_devices=$(echo $devices | wc -w)

declare -A num_classes_both_dict=(
  [posex]=48
  [astex]=48
  [astex_posex]=48
  [moad]=8
  [posex_self_docking]=48
  [posex_cross_docking]=48
  [posebusters]=14
  [posebench]=14
)
declare -A num_classes_dict=(
  [posex]=24
  [astex]=24
  [astex_posex]=24
  [moad]=8
  [posex_self_docking]=24
  [posex_cross_docking]=24
  [posebusters]=7
  [posebench]=7
)
declare -A incl_columns_dict=(
  [posex]='surfdock unimol diffdock diffdock_l gnina autodock glide alphafold3 moe dynamicbind rfaa fabind equibind boltz1x tankbind neuralplexer chai deepdock boltz ifd protenix diffdock_pocket DS interformer'
  [astex]='surfdock unimol diffdock diffdock_l gnina autodock glide alphafold3 moe dynamicbind rfaa fabind equibind boltz1x tankbind neuralplexer chai deepdock boltz ifd protenix diffdock_pocket DS interformer'
  [astex_posex]='surfdock unimol diffdock diffdock_l gnina autodock glide alphafold3 moe dynamicbind rfaa fabind equibind boltz1x tankbind neuralplexer chai deepdock boltz ifd protenix diffdock_pocket DS interformer'
  [moad]=''
  [posex_self_docking]='surfdock unimol diffdock diffdock_l gnina autodock glide alphafold3 moe dynamicbind rfaa fabind equibind boltz1x tankbind neuralplexer chai deepdock boltz ifd protenix diffdock_pocket DS interformer'
  [posex_cross_docking]='surfdock unimol diffdock diffdock_l gnina autodock glide alphafold3 moe dynamicbind rfaa fabind equibind boltz1x tankbind neuralplexer chai deepdock boltz ifd protenix diffdock_pocket DS interformer'
  [posebusters]='deepdock diffdock equibind gold tankbind unimol autodock'
)

echo "Number of classes for benchmark $benchmark: $num_classes"

if [ "$relaxation" == "both" ]; then
  incl_columns=''
  num_classes=${num_classes_both_dict[$benchmark]}
elif [ "$relaxation" == "true" ]; then
  # Add '_relaxation' suffix to each method in incl_columns
  # incl_columns="${incl_columns_dict[$benchmark]}"_relaxation only adds suffix to the last method
  incl_columns=""
  for method in ${incl_columns_dict[$benchmark]}; do
    incl_columns+="${method}_relaxation "
  done
  echo "Included columns with relaxation: $incl_columns"
  num_classes=${num_classes_dict[$benchmark]}
else
  incl_columns="${incl_columns_dict[$benchmark]}"
  num_classes=${num_classes_dict[$benchmark]}
fi

log_root="lightning_logs"
log_name="benchmark_experiment_${benchmark}"

if [ "$model" == "MCGNNASDock" ]; then
  num_node_features=960
else
  num_node_features=1152
fi

if [ "$test" -eq 0 ]; then
  for i in {0..4}; do
    echo "Training with fold $i"
    torchrun --standalone --nproc_per_node=$num_devices main.py \
        --k_folds 5 \
        --fold_num $i \
        --num_node_features $num_node_features \
        --max_epochs 300 \
        --devices $devices \
        --num_classes $num_classes \
        --incl_columns $incl_columns \
        --batch_size 16 \
        --num_workers 0 \
        --lr 1e-3 \
        --benchmark $benchmark \
        --seed $seed \
        --test_size 0.2 \
        --log_root $log_root \
        --log_name $log_name \
        --model $model
  done
else
  original_ckpts=()
  after_ckpts=()
  for i in {0..4}; do
    echo "Testing with fold $i"

    # Detect .ckpt files starting with 'best-epoch=xxx' with largest xxx
    dir="${log_root}/${log_name}/version_${version}/checkpoints"
    original_dir="${log_root}/${log_name}/version_${original_version}/checkpoints"

    # Find all files matching the pattern
    best_ckpt=$(find "$dir" -type f -name 'best-epoch=*-*.ckpt' | \
    grep -oE 'best-epoch=([0-9]+)-[^/]*\.ckpt$' | \
    sed -E 's/^best-epoch=([0-9]+)-.*/\1 &/' | \
    sort -nr | \
    head -n1 | \
    cut -d' ' -f2-)

    original_best_ckpt=$(find "$original_dir" -type f -name 'best-epoch=*-*.ckpt' | \
    grep -oE 'best-epoch=([0-9]+)-[^/]*\.ckpt$' | \
    sed -E 's/^best-epoch=([0-9]+)-.*/\1 &/' | \
    sort -nr | \
    head -n1 | \
    cut -d' ' -f2-)

    best_ckpt_path="$dir/$best_ckpt"
    original_best_ckpt_path="${log_root}/benchmark_experiment_astex_posex/version_${original_version}/checkpoints/$original_best_ckpt"

    original_ckpts+=("$original_best_ckpt_path")
    after_ckpts+=("$best_ckpt_path") 

    # jump_eval='true' to enable jump evaluation
    if [ "$jump_eval" == "false" ]; then
      echo "#---------------------------Testing with checkpoint: $best_ckpt_path---------------------------#"
      python main.py  \
          --k_folds 5 \
          --fold_num $i \
          --num_node_features $num_node_features \
          --devices $devices \
          --num_classes $num_classes \
          --incl_columns $incl_columns \
          --num_workers 1 \
          --benchmark $benchmark \
          --seed $seed \
          --test_size 0.2 \
          --test \
          --ckpt_path $best_ckpt_path \
          --model $model
      echo "Finished testing with checkpoint: $best_ckpt_path"
    fi
    
    version=$((version + 1))
    original_version=$((original_version + 1))
  done
  
  python stats_test.py \
      --original_ckpts "${original_ckpts[@]}" \
      --after_ckpts "${after_ckpts[@]}"
fi