source: utils/Python/generate_bondtable.sh.in@ 802a9d

Candidate_v1.7.1 stable
Last change on this file since 802a9d was 802a9d, checked in by Frederik Heber <frederik.heber@…>, 6 weeks ago

Adds scripts to generate a bond table.

  • one python script for the computation and a bash script to call it. With this split, we can easily parallelize the computations to make use of JobMarket's multiple workers.
  • Property mode set to 100644
File size: 3.1 KB
Line 
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
7test ! -z "$3" || { echo "Usage: $0 -H <server address> -p <server port> -o <bond table file> [-b <basis set>]"; exit 255; }
8
9POSITIONAL_ARGS=()
10
11while [[ $# -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
46done
47
48# default values for command-line options
49BASISSET="${BASISSET_CMD:-6-31G}"
50
51# constants
52DIR=`dirname $0`
53PREFIX="bondtable-$(date "+%Y-%m-%d_%H-%M-%S").csv"
54JOBS="8"
55FOLDER="computation"
56
57# state options
58echo "Using server at $SERVER_ADDRESS:$SERVER_PORT."
59echo "Using $BASISSET as basis set."
60echo "Output bond table to $BONDTABLEFILE."
61
62# array of elements: without noble gases (and metals that take longer to compute)
63elements=("H" "Li" "Be" "B" "C" "N" "O" "F" "Na" "Mg" "Al" "Si" "P" "S" "Cl" "K" "Ca")
64
65### generate pairs and fill string
66element_pairs=""
67for ((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
77done
78
79### go through all ordered pairs using gnu parallel
80echo -e $element_pairs | \
81parallel \
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
95rm -f "$BONDTABLEFILE"
96for ((i=0;i<${#elements[*]};i++)); do
97 echo -n -e "\t\"${elements[$i]}\"" >>"$BONDTABLEFILE"
98done
99echo -e -n "\n" >>"$BONDTABLEFILE"
100for ((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"
116done
117
Note: See TracBrowser for help on using the repository browser.