1#!/usr/local/bin/bash 2# 3# Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18show_help () { 19 cat <<EOF 20${0##*/}, version %version% 21This script extrapolates a potential in the correct way depending on its type. 22 23Usage: ${0##*/} [options] input output 24 25Allowed options: 26 --help show this help 27 --clean remove all intermediate temp files 28 --type TYPE type of the potential 29 possible: ${pot_types} 30 --lfct FCT type of the left extrapolation function 31 possible: ${fct_type} 32 default: exponential(non-bonded), linear (bonded) 33 --rfct FCT type of the right extrapolation function 34 possible: ${fct_types} 35 default: constant(non-bonded), periodic(dihedral), linear (bonded) 36 --avg-points INT number of average points 37 default: $avg_points 38 39EOF 40} 41 42clean="no" 43lfct= 44rfct= 45fct_types="constant linear quadratic exponential sasha" 46pot_type= 47pot_types="non-bonded bond angle dihedral" 48avg_points=3 49 50### begin parsing options 51shopt -s extglob 52while [[ ${1} = --* ]]; do 53 case $1 in 54 --clean) 55 clean="yes" 56 shift ;; 57 --type) 58 pot_type="$2" 59 shift 2;; 60 --[rl]fct) 61 is_part "${2}" "${fct_types}" || die "${0##*/}: given function type ($2) is not in the list of functions (${fct_types})" 62 eval "${1#--}"="$2" 63 shift 2;; 64 --avg-points) 65 avg_points="$2"; 66 is_int "$2" || die "${0##*/}: argument of --avg-point should be int" 67 shift 2;; 68 --help) 69 show_help 70 exit 0;; 71 *) 72 die "Unknown option '$1'";; 73 esac 74done 75### end parsing options 76 77[[ -z $pot_type ]] && die "${0##*/}: please specify add potential type (--type options) from: ${pot_types}" 78is_part "${pot_type}" "${pot_types}" || die "${0##*/}: given potential type($pot_type) is not in the list of types (${pot_types})" 79 80[[ -z $1 || -z $2 ]] && die "${0##*/}: Missing arguments" 81 82input="$1" 83[[ -f $input ]] || die "${0##*/}: Could not find input file '$input'" 84 85output="$2" 86 87echo "Extrapolate $input to $output" 88 89intermediate="$(critical mktemp "${input}.onlyleft.XXXXX")" 90if [[ $pot_type = "non-bonded" ]]; then 91 do_external table extrapolate --function "${lfct:-exponential}" --avgpoints "$avg_points" --region left "${input}" "${intermediate}" 92 do_external table extrapolate --function "${rfct:-constant}" --avgpoints 1 --region right "${intermediate}" "${output}" 93elif [[ $pot_type = "bond" || $pot_type = "angle" ]]; then 94 do_external table extrapolate --function "${lfct:-linear}" --avgpoints "$avg_points" --region left "${input}" "${intermediate}" 95 do_external table extrapolate --function "${rfct:-linear}" --avgpoints "$avg_points" --region right "${intermediate}" "${output}" 96elif [[ $pot_type = "dihedral" ]]; then 97 do_external table extrapolate --function "${lfct:-linear}" --avgpoints "$avg_points" --region left "${input}" "${intermediate}" 98 do_external table extrapolate --function "${rfct:-periodic}" --avgpoints "$avg_points" --region right "${intermediate}" "${output}" 99else 100 die "${0##*/}: I don't know how to extraploate potential type '$pot_type', go and implement it!" 101fi 102 103if [[ $clean = "yes" ]]; then 104 rm -f "${intermediate}" 105fi 106