Last active
June 14, 2023 04:41
-
-
Save coltonbh/58bd14c35604a7bebbc49a5ac2338cb4 to your computer and use it in GitHub Desktop.
A simple shell command to run a TeraChem container as if a local command.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create terachem command to run the container as if a system command | |
export TERACHEM_IMAGE="mtzgroup/terachem:1.9-2021.12-dev-cuda11.4-sm_52-sm_80" | |
export TERACHEM_LICENSE_PATH="" # Add absolute path to license, if you have one. | |
terachem() { | |
# Get the current user's UID and GID | |
uid=$(id -u) | |
gid=$(id -g) | |
# Default port mapping | |
port_mapping="" | |
# Check if -s option is provided with a port number | |
args=("$@") | |
for (( i=0; i<$#; i++ )); do | |
if [[ ${args[$i]} == "-s" ]]; then | |
port=${args[$((i+1))]} | |
port_mapping="-p $port:$port" | |
fi | |
done | |
# Get the path to the input file, which is always the last argument (ok if a port number is provided) | |
input_file_path="${*: -1}" | |
# Attempt to resolve the directory path. If it fails, use the current working directory | |
# Failures caputure terachem -v/--version calls | |
directory_path="$(dirname '$input_file_path' 2>/dev/null || pwd)" | |
absolute_directory_path="$(realpath "$directory_path" 2>/dev/null || echo "$directory_path")" | |
# If TERACHEM_LICENSE_PATH is set, prepare its bind mount | |
if [ -n "$TERACHEM_LICENSE_PATH" ]; then | |
license_bind_mount="-v ${TERACHEM_LICENSE_PATH}:/terachem/license.key" | |
else | |
license_bind_mount="" | |
fi | |
# Prepare Docker command | |
docker_command="docker run --rm --gpus all -u $uid:$gid $port_mapping -v ${absolute_directory_path}:/scratch $license_bind_mount ${TERACHEM_IMAGE} terachem $*" | |
# Run Docker command | |
eval $docker_command | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment