FROM rockylinux/rockylinux:8

RUN yum -y update \
 && yum -y install dnf-plugins-core \
 && dnf config-manager --set-enabled powertools \
 && yum -y group install "Development Tools" \
 && yum -y install environment-modules gawk vim wget \
 lapack-devel blas-devel zlib-devel gsl-devel fftw-devel openmpi-devel boost-devel \
 openssl-devel libffi-devel 

RUN useradd -ms /bin/bash plumed
#These are needed for installing python

USER plumed
WORKDIR /home/plumed

#Install python with --embedded enabled
RUN PYVERSION="3.9.16" \
 && curl -LO https://www.python.org/ftp/python/${PYVERSION}/Python-${PYVERSION}.tgz \
 && tar xzf Python-${PYVERSION}.tgz \
 && cd Python-${PYVERSION} \
 && ./configure --enable-shared --prefix=$HOME/.local \
 && make -j 4 \
 && make install \
 && echo "export LD_LIBRARY_PATH=$HOME/.local/lib/${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" >> "$HOME/.bashrc"

RUN . ./.bashrc \                
 && pip3 install --user -U pip \
 && pip3 install --user pillow \
 && pip3 install --user Cython \
 && pip3 install --user pandas \
 && pip3 install --user mdtraj     \
 && pip3 install --user MDAnalysis

# import plumed code.
# assumes a file plumed2.tgz is present in the Dockerfile directory
COPY plumed2.tgz /home/plumed

# build and test plumed (no install)
RUN . ./.bashrc \
 && module load mpi \
 && export OMPI_MCA_btl_base_warn_component_unused=0 \
 && export OMPI_MCA_btl_base_verbose=0 \
 && export OMPI_MCA_plm=isolated \
 && export OMPI_MCA_btl_vader_single_copy_mechanism=none \
 && export OMPI_MCA_rmaps_base_oversubscribe=yes \
 && export PATH=$HOME/opt/bin:$PATH \
 && export CPATH=$HOME/opt/include:$CPATH \
 && export INCLUDE=$HOME/opt/include:$INCLUDE \
 && export LIBRARY_PATH=$HOME/opt/lib:$LIBRARY_PATH \
 && export LD_LIBRARY_PATH=$HOME/opt/lib:$LD_LIBRARY_PATH \
 && tar xzf plumed2.tgz \
 && cd plumed2 \
 && export PYTHONPATH=$PWD/python:$PYTHONPATH \
 && export PYTHON_BIN=python3 \
 && ./configure --enable-modules=all --enable-boost_serialization \
 && make -j 4 \
 && make check
