From c854f0a1a16ca3d62db1e5a4cbc0117292e6d2b2 Mon Sep 17 00:00:00 2001
From: Rafal Gumienny <guma44@gmail.com>
Date: Thu, 15 Feb 2018 09:09:43 +0100
Subject: [PATCH] feat: Dockerize OST

---
 docker/Dockerfile     | 103 ++++++++++++++++++++++++++++++++++++++++++
 docker/README.rst     |  30 ++++++++++++
 docker/run_docker_ost |  23 ++++++++++
 docker/test_docker.py |  17 +++++++
 4 files changed, 173 insertions(+)
 create mode 100644 docker/Dockerfile
 create mode 100644 docker/README.rst
 create mode 100755 docker/run_docker_ost
 create mode 100644 docker/test_docker.py

diff --git a/docker/Dockerfile b/docker/Dockerfile
new file mode 100644
index 000000000..7c0b521d3
--- /dev/null
+++ b/docker/Dockerfile
@@ -0,0 +1,103 @@
+FROM ubuntu:16.04
+
+RUN apt-get update -y
+# basic packages
+
+RUN apt-get install -y cmake \
+                       sip-dev \
+                       libtiff-dev \
+                       libfftw3-dev \
+                       libeigen3-dev \
+                       libpng-dev \
+                       python-all \
+                       python2.7 \
+                       python-qt4 \
+                       libboost-all-dev \
+                       qt4-qtconfig \
+                       qt4-qmake \
+                       libqt4-dev \
+                       libpng-dev \
+                       wget \
+                       git \
+                       gfortran \
+                       libeigen3-dev \
+                       python-pip
+
+# Install miniconda - to get useful binaries
+RUN wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
+RUN bash Miniconda2-latest-Linux-x86_64.sh -p /opt/miniconda2 -b -f
+RUN rm Miniconda2-latest-Linux-x86_64.sh
+
+# Install ClustalW and MSMS
+RUN /opt/miniconda2/bin/conda install -y -c bioconda clustalw=2.1 msms=2.6.1
+
+# Install OpenMM
+RUN /opt/miniconda2/bin/conda install -y -c omnia openmm=7.1.1=py27_0
+
+# Install DSSP
+RUN /opt/miniconda2/bin/conda install -y -c salilab dssp=3.0.0
+
+# Install some python packages
+RUN pip install --upgrade pip && pip install numpy==1.14.0 \
+                                             scipy==1.0.0 \
+                                             pandas==0.22.0 \
+                                             jupyter==1.0.0
+
+# copy ost release
+WORKDIR /opt/ost
+
+RUN git clone https://git.scicore.unibas.ch/schwede/openstructure.git /opt/ost
+
+# compile ost
+RUN cmake . -DPYTHON_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython2.7.so \
+            -DOPTIMIZE=ON \
+            -DENABLE_MM=ON \
+            -DCOMPILE_TMTOOLS=1 \
+            -DUSE_NUMPY=1 \
+            -DOPEN_MM_LIBRARY=/opt/miniconda2/pkgs/openmm-7.1.1-py27_0/lib/libOpenMM.so \
+            -DOPEN_MM_INCLUDE_DIR=/opt/miniconda2/pkgs/openmm-7.1.1-py27_0/include/ \
+            -DOPEN_MM_PLUGIN_DIR=/opt/miniconda2/pkgs/openmm-7.1.1-py27_0/lib/plugins
+
+# Build chemdict_tool
+RUN make -j4 chemdict_tool
+
+# get the compound library
+RUN wget ftp://ftp.wwpdb.org/pub/pdb/data/monomers/components.cif.gz
+RUN stage/bin/chemdict_tool create components.cif.gz compounds.chemlib pdb
+RUN stage/bin/chemdict_tool update modules/conop/data/charmm.cif compounds.chemlib charmm
+
+# Reconfigure OST
+RUN cmake . -DPYTHON_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython2.7.so \
+            -DOPTIMIZE=ON \
+            -DENABLE_MM=ON \
+            -DOPEN_MM_LIBRARY=/opt/miniconda2/pkgs/openmm-7.1.1-py27_0/lib/libOpenMM.so \
+            -DOPEN_MM_INCLUDE_DIR=/opt/miniconda2/pkgs/openmm-7.1.1-py27_0/include/ \
+            -DOPEN_MM_PLUGIN_DIR=/opt/miniconda2/pkgs/openmm-7.1.1-py27_0/lib/plugins \
+            -DCOMPOUND_LIB=/opt/ost/compounds.chemlib
+
+# Build OST
+RUN make -j4
+#RUN make check
+
+# go back home
+WORKDIR /home
+
+# Get the example
+RUN wget https://files.rcsb.org/view/5X28.pdb
+
+# Set the environment
+# - for GUI
+ENV QT_X11_NO_MITSHM 1
+# - for Python
+ENV PYTHONPATH="/opt/ost/stage/lib64/python2.7/site-packages:${PYTHONPATH}"
+# - for PATH
+ENV PATH="/opt/ost/stage/bin:${PATH}"
+
+# Link binaries
+RUN ln -s /opt/miniconda2/pkgs/clustalw*/bin/* /usr/bin
+RUN ln -s /opt/miniconda2/pkgs/dssp*/bin/* /usr/bin
+RUN ln -s /opt/miniconda2/pkgs/msms*/bin/* /usr/bin
+
+ENTRYPOINT ["ost"]
+CMD ["-i"]
+
diff --git a/docker/README.rst b/docker/README.rst
new file mode 100644
index 000000000..633bd4cc8
--- /dev/null
+++ b/docker/README.rst
@@ -0,0 +1,30 @@
+OST Docker
+==========
+
+Build Docker image
+------------------
+
+In order to build OST image:
+```
+cd <OST ROOT>/docker
+(sudo) docker build --tag <TAG> .
+```
+
+One can chose any tag eg. ost.
+
+Run script with OST
+-------------------
+
+In order to run OST script do:
+```
+(sudo) docker run --rm -v <PATH TO SCRIPT DIR>:/home <IMAGE NAME> /home/<SCRIPT NAME> [OPTIONS]
+```
+
+Run GUI
+-------
+
+In order to run GUI do (tested on linux machine):
+```
+xhost +local:docker
+(sudo) docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --entrypoint dng <IMAGE NAME>
+```
\ No newline at end of file
diff --git a/docker/run_docker_ost b/docker/run_docker_ost
new file mode 100755
index 000000000..c8f83be09
--- /dev/null
+++ b/docker/run_docker_ost
@@ -0,0 +1,23 @@
+#! /bin/bash
+
+# end when error
+set -e
+
+image_name=$1
+script_path=$2
+
+if [[ ${#@} -lt 1 ]]; then
+    echo "Usage: (sudo) run_docker_ost <IMAGE_NAME> [<SCRIPT_PATH>]"
+    exit 1
+fi
+
+if [[ ${script_path} -eq "" ]]; then
+    docker run -ti --rm ${image_name}
+else
+    abspath=$(readlink -f $script_path)
+    dirpath=$(dirname $abspath)
+    name=$(basename $script_path)
+    docker run --rm -v ${dirpath}:/home ${image_name} /home/${name} ${@:3}
+fi
+
+
diff --git a/docker/test_docker.py b/docker/test_docker.py
new file mode 100644
index 000000000..450e8fa1d
--- /dev/null
+++ b/docker/test_docker.py
@@ -0,0 +1,17 @@
+import ost
+from ost.mol.alg import qsscoring
+
+# load two biounits to compare
+ent_full = ost.io.LoadPDB('3ia3', remote=True)
+ent_1 = ent_full.Select('cname=A,D')
+ent_2 = ent_full.Select('cname=B,C')
+# get score
+ost.PushVerbosityLevel(3)
+try:
+    qs_scorer = qsscoring.QSscorer(ent_1, ent_2)
+    ost.LogScript('QSscore:', str(qs_scorer.global_score))
+    ost.LogScript('Chain mapping used:', str(qs_scorer.chain_mapping))
+except qsscoring.QSscoreError as ex:
+    # default handling: report failure and set score to 0
+    ost.LogError('QSscore failed:', str(ex))
+    qs_score = 0
-- 
GitLab