BootStrap: docker
From: registry.scicore.unibas.ch/schwede/promod3:3.4.2-OST2.9.1-jammy
%post
##############################################################################
# POST
##############################################################################


# CHANGE DASH TO BASH
rm /bin/sh
ln -sf /bin/bash /bin/sh


# INSTALL SYSTEM DEPS
#####################
apt-get update -y && apt-get install -y ipython3 jupyter python3-pip
pip3 install ipywidgets==8.1.1
pip3 install nglview \
             six

# SET LOCALE
############
echo "LC_ALL=en_US.UTF-8" >> /etc/environment
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
locale-gen en_US.UTF-8

# SETUP IPYTHON / JUPYTER
#########################
export JUPYTER_PATH="/usr/local/share/jupyter"
mkdir -p $JUPYTER_PATH
mkdir -p $JUPYTER_PATH/kernels/ost-kernel
cat > $JUPYTER_PATH/kernels/ost-kernel/kernel.json <<EOF
{
  "display_name": "OST",
  "language": "python",
  "argv": [
    "python",
    "-m", "ipykernel",
        "-f", "{connection_file}",
    "--InteractiveShellApp.exec_PYTHONSTARTUP=False",
    "--InteractiveShellApp.exec_files=/usr/local/lib64/python3.10/site-packages/ost/ost_startup.py"
  ],
  "env": {
  }
}
EOF


%environment
##############################################################################
# ENVIRONMENT
##############################################################################
export TEMP="/tmp"
export TEMPDIR="/tmp"
export TMPDIR="/tmp"
export TMP="/tmp"
export JUPYTER_PATH="/usr/local/share/jupyter"


%apprun ChemdictTool
##############################################################################
# CHEMDICT TOOL APP
##############################################################################
$OST_ROOT/bin/chemdict_tool "$@"


%apprun lDDT
##############################################################################
# lDDT APP
##############################################################################
$OST_ROOT/bin/lddt "$@"

%apphelp lDDT
The Local Distance Difference Test.

Usage:

    singularity run --app lDDT <IMAGE> [options] <mod1> [mod1 [mod2]] <re1>[,ref2,ref3]

Options:
    -s         selection performed on ref
    -c         use Calphas only
    -f         perform structural checks and filter input data
    -t         fault tolerant parsing
    -p <file>  use specified parmeter file. Mandatory
    -v <level> verbosity level (0=results only,1=problems reported, 2=full report)
    -b <value> tolerance in stddevs for bonds
    -a <value> tolerance in stddevs for angles
    -r <value> distance inclusion radius
    -i <value> sequence separation
    -e         print version
    -x         ignore residue name consistency checks


%apprun Molck
##############################################################################
# MOLCK APP
##############################################################################
$OST_ROOT/bin/molck "$@"

%apphelp Molck
This is molck - the molecule checker

Usage:
    singularity run --app Molck <IMAGE> [options] file1.pdb [file2.pdb [...]]

Options:
    --complib=path    location of the compound library file. If not provided, the 
      following locations are searched in this order: 
      1. Working directory, 2. OpenStructure standard library location (if the 
      executable is part of a standard OpenStructure installation) 
    --rm=<a>,<b>      remove atoms and residues matching some criteria 
      zeroocc - Remove atoms with zero occupancy 
      hyd - Remove hydrogen atoms 
      oxt - Remove terminal oxygens 
      nonstd - Remove all residues not one of the 20 standard amino acids 
      unk - Remove unknown and atoms not following the nomenclature
    --fix-ele         clean up element column
    --stdout          write cleaned file(s) to stdout 
    --out=filename    write cleaned file(s) to disk. % characters in the filename are 
      replaced with the basename of the input file without extension. 
      Default: %-molcked.pdb 
    --color=auto|on|off 
      whether output should be colored
    --map-nonstd   maps modified residues back to the parent amino acid, for example
      MSE -> MET, SEP -> SER.


%apprun OST
##############################################################################
# OST APP
##############################################################################
$OST_ROOT/bin/ost "$@"

%apphelp OST
The OST app exposes the OpenStructure executable and can be used to run an 
interactive shell, scripts and OpenStructure actions. 
ProMod3 modules can be imported as any other Python module.

Usage:
    singularity run --app OST <IMAGE> [options] (script | action)
    [parameters]

Options:
    -i, --interactive     start interpreter interactively (must be first
                          parameter, ignored otherwise)
    -h, --help            show this help message and exit
    -v VLEVEL, --verbosity_level=VLEVEL
                          sets the verbosity level [default: 2]

To list all available actions:
    singularity run --app OST <IMAGE> --help

If script requires some external files eg. PDBs, they have to be located in the
path accessible via mounted volumes. By default Singularity mounts $HOME and
goes to CWD. Thus this sould work as expected out of the box.


%apprun PM
##############################################################################
# PM APP
##############################################################################
$PROMOD_ROOT/bin/pm "$@"

%apphelp PM
The PM app exposes the ProMod3 executable and can be used to run scripts and
predefined modelling "actions".

Usage:
    singularity run --app PM <IMAGE> [options] (script | action)
    [parameters]

Options:
    -h, --help            show this help message and exit
    -v VLEVEL, --verbosity_level=VLEVEL
                          sets the verbosity level [default: 2]

To list all available actions:
    singularity run --app PM <IMAGE> help


If script/action requires some external files eg. PDBs, they have to be located 
in the path accessible via mounted volumes. By default Singularity mounts $HOME 
and goes to CWD. Thus this sould work as expected out of the box.


%appenv IPython
##############################################################################
# NOTEBOOK ENV
##############################################################################
export DNG_ROOT=$OST_ROOT
export DNG_INITDIR=${DNG_ROOT}/lib64/python3.10/site-packages/ost


%apprun IPython
##############################################################################
# OST IPYTON APP
##############################################################################
ipython3 -i $DNG_INITDIR/ost_startup.py "$@"

%apphelp IPython
OST-powered iPython shell where ProMod3 modules can be imported as any other
Python module.

Usage:
    
    singularity run --app IPython <IMAGE> [options]

Detailed help:

    singularity run --app IPython <IMAGE> --help


%appenv Notebook
##############################################################################
# NOTEBOOK ENV
##############################################################################
export BIN_DIR=$OST_ROOT/bin
export XDG_RUNTIME_DIR=""
. $OST_ROOT/libexec/openstructure/ost_config


%apprun Notebook
##############################################################################
# NOTEBOOK APP
##############################################################################
jupyter notebook --NotebookApp.iopub_data_rate_limit=10000000 --no-browser "$@"

%apphelp Notebook
A Jupyter notebook playground with OST, ProMod3 and nglview.

Usage:

    singularity run --app Notebook <IMAGE> [options]

The Jupyter notebook is run by default with `--NotebookApp.iopub_data_rate_limit=10000000`
and `--no-browser` options.

Useful options when running on remote server:
    --ip=<Unicode> (NotebookApp.ip)
        Default: 'localhost'
        The IP address the notebook server will listen on.
    --port=<Integer> (NotebookApp.port)
        Default: 8888
        The port the notebook server will listen on.

Copy the URL to the browser and launch the notebook with OST kernel. This will
load all necessary OST/ProMod3 components just like in the OST shell. We also enabled
the nglview widget to interactively view molecular structures and trajectories.
For more details on how to use nglview see http://nglviewer.org/nglview/latest/.

To list of all available options:

    singularity run --app Notebook <IMAGE> --help


%runscript
##############################################################################
# RUNSCRIPT
##############################################################################
cat << EOF
Singularity container for OST $OPENSTRUCTURE_VERSION and ProMod3 $PROMOD_VERSION.

This container includes the following apps:
 * OST - OpenStructure executable
 * PM - ProMod3 executable
 * IPython - OST-powered iPython shell
 * Notebook - A Jupyter notebook playground with OST, ProMod3 and nglview
 * lDDT - The Local Distance Difference Test
 * Molck - Molecular checker
 * ChemdictTool - Creating or update a compound library

To see the help for each individual app run:

    singularity help --app <APP NAME> <IMAGE NAME>
EOF

%help
Singularity container for OST and ProMod3.

This container includes the following apps:
 * OST - OpenStructure executable
 * PM - ProMod3 executable
 * IPython - OST-powered iPython shell
 * Notebook - A Jupyter notebook palyground with OST and nglview
 * lDDT - The Local Distance Difference Test
 * Molck - Molecular checker
 * ChemdictTool - Creating or update a compound library

To see the help for each individual app run:

    singularity help --app <APP NAME> <IMAGE NAME>
