# Adapted from the official dockerfile: https://github.com/google-deepmind/alphafold3/blob/main/docker/Dockerfile
rm -rf /content/sample_data

# /app/alphafold - alphafold3 git repo checkout
mkdir /app
cd /app
git clone https://github.com/google-deepmind/alphafold3.git alphafold
cd alphafold
git checkout $ALPHAFOLD3_VERSION
cd -
apt-get install --yes --quiet python3.12 python3-pip python3.12-venv python3.12-dev git wget gcc g++ make zlib1g-dev zstd

# /alphafold3_venv - pip environment for alphafold3 dependancies
python3 -m venv /alphafold3_venv
source /alphafold3_venv/bin/activate

# /hmmer - build hmmer from source & custom patch
mkdir /hmmer_build /hmmer
wget http://eddylab.org/software/hmmer/hmmer-3.4.tar.gz --directory-prefix /hmmer_build
cd /hmmer_build && echo "ca70d94fd0cf271bd7063423aabb116d42de533117343a9b27a65c17ff06fbf3 hmmer-3.4.tar.gz" | sha256sum --check
cd /hmmer_build && tar zxf hmmer-3.4.tar.gz && rm hmmer-3.4.tar.gz

cp /app/alphafold/docker/jackhmmer_seq_limit.patch /hmmer_build/
cd /hmmer_build && patch -p0 < jackhmmer_seq_limit.patch

cd /hmmer_build/hmmer-3.4 && ./configure --prefix /hmmer
cd /hmmer_build/hmmer-3.4 && make -j
cd /hmmer_build/hmmer-3.4 && make install
cd /hmmer_build/hmmer-3.4/easel && make install
rm -R /hmmer_build

# build pip dependencies & ligand dictionary
cd /app/alphafold
pip3 install --no-cache-dir setuptools
pip3 install --no-cache-dir -r dev-requirements.txt
pip3 install --no-cache-dir --no-deps .
build_data
