Skip to content

Instantly share code, notes, and snippets.

@coltonbh
Last active June 14, 2023 04:41
Show Gist options
  • Save coltonbh/58bd14c35604a7bebbc49a5ac2338cb4 to your computer and use it in GitHub Desktop.
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.
# 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