| 1 | #!/usr/bin/env bash
|
|---|
| 2 | #
|
|---|
| 3 | # Generates a bond table file by using the python script compute_pair_bondlength.py
|
|---|
| 4 | # on a given pair of elements
|
|---|
| 5 |
|
|---|
| 6 | # get options
|
|---|
| 7 | test ! -z "$3" || { echo "Usage: $0 -H <server address> -p <server port> -o <bond table file> [-b <basis set>]"; exit 255; }
|
|---|
| 8 |
|
|---|
| 9 | POSITIONAL_ARGS=()
|
|---|
| 10 |
|
|---|
| 11 | while [[ $# -gt 0 ]]; do
|
|---|
| 12 | case $1 in
|
|---|
| 13 | -H|--server-address)
|
|---|
| 14 | SERVER_ADDRESS="$2"
|
|---|
| 15 | shift # past argument
|
|---|
| 16 | shift # past value
|
|---|
| 17 | ;;
|
|---|
| 18 | -p|--server-port)
|
|---|
| 19 | SERVER_PORT="$2"
|
|---|
| 20 | shift # past argument
|
|---|
| 21 | shift # past value
|
|---|
| 22 | ;;
|
|---|
| 23 | -o|--output-file)
|
|---|
| 24 | BONDTABLEFILE="$2"
|
|---|
| 25 | shift # past argument
|
|---|
| 26 | shift # past value
|
|---|
| 27 | ;;
|
|---|
| 28 | -b|--basis-set)
|
|---|
| 29 | BASISSET_CMD="$2"
|
|---|
| 30 | shift # past argument
|
|---|
| 31 | shift # past value
|
|---|
| 32 | ;;
|
|---|
| 33 | --default)
|
|---|
| 34 | DEFAULT=YES
|
|---|
| 35 | shift # past argument
|
|---|
| 36 | ;;
|
|---|
| 37 | -*|--*)
|
|---|
| 38 | echo "Unknown option $1"
|
|---|
| 39 | exit 1
|
|---|
| 40 | ;;
|
|---|
| 41 | *)
|
|---|
| 42 | POSITIONAL_ARGS+=("$1") # save positional arg
|
|---|
| 43 | shift # past argument
|
|---|
| 44 | ;;
|
|---|
| 45 | esac
|
|---|
| 46 | done
|
|---|
| 47 |
|
|---|
| 48 | # default values for command-line options
|
|---|
| 49 | BASISSET="${BASISSET_CMD:-6-31G}"
|
|---|
| 50 |
|
|---|
| 51 | # constants
|
|---|
| 52 | DIR=`dirname $0`
|
|---|
| 53 | PREFIX="bondtable-$(date "+%Y-%m-%d_%H-%M-%S").csv"
|
|---|
| 54 | JOBS="8"
|
|---|
| 55 | FOLDER="computation"
|
|---|
| 56 |
|
|---|
| 57 | # state options
|
|---|
| 58 | echo "Using server at $SERVER_ADDRESS:$SERVER_PORT."
|
|---|
| 59 | echo "Using $BASISSET as basis set."
|
|---|
| 60 | echo "Output bond table to $BONDTABLEFILE."
|
|---|
| 61 |
|
|---|
| 62 | # array of elements: without noble gases (and metals that take longer to compute)
|
|---|
| 63 | elements=("H" "Li" "Be" "B" "C" "N" "O" "F" "Na" "Mg" "Al" "Si" "P" "S" "Cl" "K" "Ca")
|
|---|
| 64 |
|
|---|
| 65 | ### generate pairs and fill string
|
|---|
| 66 | element_pairs=""
|
|---|
| 67 | for ((i=0;i<${#elements[*]};i++)); do
|
|---|
| 68 | elem1="${elements[$i]}"
|
|---|
| 69 | for ((j=i;j<${#elements[*]};j++)); do
|
|---|
| 70 | elem2="${elements[$j]}"
|
|---|
| 71 | if test -z "$element_pairs"; then
|
|---|
| 72 | element_pairs="$elem1\n$elem2"
|
|---|
| 73 | else
|
|---|
| 74 | element_pairs="${element_pairs}\n$elem1\n$elem2"
|
|---|
| 75 | fi
|
|---|
| 76 | done
|
|---|
| 77 | done
|
|---|
| 78 |
|
|---|
| 79 | ### go through all ordered pairs using gnu parallel
|
|---|
| 80 | echo -e $element_pairs | \
|
|---|
| 81 | parallel \
|
|---|
| 82 | -P $JOBS \
|
|---|
| 83 | --nice 10 \
|
|---|
| 84 | -N 2 \
|
|---|
| 85 | --silent \
|
|---|
| 86 | --results "$FOLDER" \
|
|---|
| 87 | ./"$DIR"/compute_pair_bondlength \
|
|---|
| 88 | --server-address "$SERVER_ADDRESS" \
|
|---|
| 89 | --server-port "$SERVER_PORT" \
|
|---|
| 90 | --output-prefix "$PREFIX" \
|
|---|
| 91 | --basis-set "$BASISSET" \
|
|---|
| 92 | --elements {} >/dev/null
|
|---|
| 93 |
|
|---|
| 94 | ### analyse distances from log files and create bond table file
|
|---|
| 95 | rm -f "$BONDTABLEFILE"
|
|---|
| 96 | for ((i=0;i<${#elements[*]};i++)); do
|
|---|
| 97 | echo -n -e "\t\"${elements[$i]}\"" >>"$BONDTABLEFILE"
|
|---|
| 98 | done
|
|---|
| 99 | echo -e -n "\n" >>"$BONDTABLEFILE"
|
|---|
| 100 | for ((i=0;i<${#elements[*]};i++)); do
|
|---|
| 101 | elem1="${elements[$i]}"
|
|---|
| 102 | echo -n -e "\"$elem1\"" >>"$BONDTABLEFILE"
|
|---|
| 103 | for ((j=0;j<${#elements[*]};j++)); do
|
|---|
| 104 | elem2="${elements[$j]}"
|
|---|
| 105 | LOGFILENAME="$FOLDER/1/$elem1/1/$elem2/stdout"
|
|---|
| 106 | if test ! -f "$LOGFILENAME"; then
|
|---|
| 107 | LOGFILENAME="$FOLDER/1/$elem2/1/$elem1/stdout"
|
|---|
| 108 | fi
|
|---|
| 109 | distance=$(grep "DISTANCE:" "$LOGFILENAME" | sed -e "s#DISTANCE:\s*[A-Za-z]\+\s\+[A-Za-z]\+:\s*\(.*\)#\1#" | awk '{print int($1*100)/100}')
|
|---|
| 110 | if test $? != 0; then
|
|---|
| 111 | distance="-1"
|
|---|
| 112 | fi
|
|---|
| 113 | echo -e -n "\t$distance" >>"$BONDTABLEFILE"
|
|---|
| 114 | done
|
|---|
| 115 | echo -e -n "\n" >>"$BONDTABLEFILE"
|
|---|
| 116 | done
|
|---|
| 117 |
|
|---|