5.3.2. Antechamber#

  1#!/bin/bash
  2
  3set -euo pipefail
  4
  5charge_method="bcc"
  6verbose=2
  7net_charge=0
  8resname="UNL"
  9intermediate_files="yes"
 10
 11usage() {
 12    cat <<EOF
 13Usage: $(basename "$0") [-r RESNAME] [-n NET_CHARGE] ligand.pdb
 14
 15Generate a GAFF2 MOL2 file from a ligand PDB file with AmberTools antechamber.
 16
 17Options:
 18  -r RESNAME      Residue name to write to the MOL2 file (default: UNL)
 19  -n NET_CHARGE   Net molecular charge (default: 0)
 20  -h              Show this help message
 21
 22Examples:
 23  $(basename "$0") ATP.pdb
 24  $(basename "$0") -r ATP -n -4 ATP.pdb
 25EOF
 26}
 27
 28if [ "${1:-}" = "--help" ]; then
 29    usage
 30    exit 0
 31fi
 32
 33while getopts ":r:n:h" opt; do
 34    case "$opt" in
 35        r)
 36            resname="$OPTARG"
 37            ;;
 38        n)
 39            net_charge="$OPTARG"
 40            ;;
 41        h)
 42            usage
 43            exit 0
 44            ;;
 45        :)
 46            echo "ERROR: Option -$OPTARG requires an argument." >&2
 47            usage >&2
 48            exit 1
 49            ;;
 50        \?)
 51            echo "ERROR: Unknown option -$OPTARG." >&2
 52            usage >&2
 53            exit 1
 54            ;;
 55    esac
 56done
 57shift $((OPTIND - 1))
 58
 59if [ "$#" -ne 1 ]; then
 60    echo "ERROR: Requires exactly one ligand PDB file." >&2
 61    usage >&2
 62    exit 1
 63fi
 64
 65ligand=$1
 66
 67case "$ligand" in
 68    *.pdb)
 69        ;;
 70    *)
 71        echo "ERROR: antechamber.sh only accepts PDB input files (*.pdb): $ligand" >&2
 72        exit 1
 73        ;;
 74esac
 75
 76if [ ! -e "$ligand" ]; then
 77    echo "ERROR: Ligand PDB file not found: $ligand" >&2
 78    exit 1
 79fi
 80
 81if [ ! -f "$ligand" ]; then
 82    echo "ERROR: Ligand path is not a regular file: $ligand" >&2
 83    exit 1
 84fi
 85
 86if ! command -v antechamber >/dev/null 2>&1; then
 87    echo "ERROR: antechamber was not found. Load AmberTools before running this script." >&2
 88    exit 1
 89fi
 90
 91filename=$(basename "$ligand")
 92stem=${filename%.pdb}
 93output="${stem}.mol2"
 94
 95antechamber \
 96    -i "$ligand" \
 97    -fi pdb \
 98    -o "$output" \
 99    -fo mol2 \
100    -c "$charge_method" \
101    -s "$verbose" \
102    -nc "$net_charge" \
103    -rn "$resname" \
104    -at gaff2 \
105    -pf "$intermediate_files"
106
107echo "Created $output"
108echo "Next: run parmchk2 -i $output -f mol2 -o ${stem}.frcmod"