5.3.4. parmchk2.sh#

 1#!/bin/bash
 2
 3set -euo pipefail
 4
 5usage() {
 6    cat <<EOF
 7Usage: $(basename "$0") ligand[.mol2]
 8
 9Generate an frcmod file from a ligand MOL2 file with AmberTools parmchk2.
10
11The ligand argument can be either a MOL2 file or a ligand name. If a name is
12provided, this script looks for <name>.mol2.
13
14Examples:
15  $(basename "$0") ATP.mol2
16  $(basename "$0") ATP
17EOF
18}
19
20if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
21    usage
22    exit 0
23fi
24
25if [ "$#" -ne 1 ]; then
26    echo "ERROR: Requires exactly one ligand MOL2 file or ligand name." >&2
27    usage >&2
28    exit 1
29fi
30
31ligand=$1
32
33case "$ligand" in
34    *.mol2)
35        mol2_file=$ligand
36        ;;
37    *.*)
38        stem=${ligand%.*}
39        mol2_file="${stem}.mol2"
40        ;;
41    *)
42        mol2_file="${ligand}.mol2"
43        ;;
44esac
45
46if [ ! -e "$mol2_file" ]; then
47    echo "ERROR: MOL2 file not found: $mol2_file" >&2
48    exit 1
49fi
50
51if [ ! -f "$mol2_file" ]; then
52    echo "ERROR: MOL2 path is not a regular file: $mol2_file" >&2
53    exit 1
54fi
55
56if ! command -v parmchk2 >/dev/null 2>&1; then
57    echo "ERROR: parmchk2 was not found. Load AmberTools before running this script." >&2
58    exit 1
59fi
60
61frcmod_file="${mol2_file%.mol2}.frcmod"
62
63if [ -f "$frcmod_file" ]; then
64    echo "Found frcmod file: $frcmod_file"
65    echo "Skipping parmchk2."
66    exit 0
67fi
68
69parmchk2 -i "$mol2_file" -f mol2 -o "$frcmod_file"
70
71echo "Created $frcmod_file"