FROM nvidia/cuda:11.4.3-cudnn8-runtime-ubuntu18.04

LABEL authors="Luisa Santus, Athanasios Baltzis, Jose Espinosa-Carrasco, Leila Mansouri" \
    title="nfcore/proteinfold_alphafold2_msa" \
    Version="1.1.0" \
    description="Docker image containing all software requirements to run the RUN_ALPHAFOLD2_MSA module using the nf-core/proteinfold pipeline"

# Use bash to support string substitution.
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Add env variables
ENV LD_LIBRARY_PATH="/conda/lib:/usr/local/cuda-11.4/lib64:$LD_LIBRARY_PATH"
ENV PATH="/conda/bin:$PATH"

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
    build-essential \
    cmake \
    cuda-command-line-tools-11-1 \
    git \
    hmmer \
    kalign \
    tzdata \
    wget \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get autoremove -y \
    && apt-get clean

# Clone AlphaFold2
RUN git clone https://github.com/cbcrg/alphafold.git /app/alphafold && \
    cd /app/alphafold && \
    git checkout 1b3170e9409472ec8ad044f9935c92bedd7b4674 && \
    cd -

# Compile HHsuite from source
RUN git clone --branch v3.3.0 https://github.com/soedinglab/hh-suite.git /tmp/hh-suite \
    && mkdir /tmp/hh-suite/build \
    &&  cd /tmp/hh-suite/build \
    &&  cmake -DCMAKE_INSTALL_PREFIX=/opt/hhsuite -DHAVE_AVX2=1 .. \
    && make -j 4 && make install \
    && ln -s /opt/hhsuite/bin/* /usr/bin \
    && cd - && rm -rf /tmp/hh-suite

# Install Miniconda package manager
RUN wget -q -P /tmp \
    https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
    && bash /tmp/Miniconda3-latest-Linux-x86_64.sh -b -p /conda \
    && rm /tmp/Miniconda3-latest-Linux-x86_64.sh

# Install conda packages
RUN /conda/bin/conda install -y -c conda-forge \
    pip \
    python=3.10 \
    && conda clean --all --force-pkgs-dirs --yes

# Install pip packages
RUN pip3 install --upgrade pip --no-cache-dir \
    && pip3 install -r /app/alphafold/requirements_msa.txt --no-cache-dir
