1#!/usr/local/bin/bash
2#
3# Copyright 2009-2011 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
18if [[ $1 = "--help" ]]; then
19cat <<EOF
20${0##*/}, version %version%
21
22This script generates a mapping for the reference mapping from the parameters of the active in input state using the mapping template
23
24Usage: ${0##*/} input
25EOF
26  exit 0
27fi
28
29[[ -z $1 ]] && die "${0##*/}: missing argument"
30input="$1"
31[[ -f $input ]] || die "${0##*/}: Could not read $input"
32
33name="$(csg_get_interaction_property name)"
34if [[ $(csg_get_interaction_property inverse.optimizer.mapping.change) = no ]]; then
35  echo "Interaction $name does not change the reference mapping"
36  exit 0
37fi
38
39line="$(critical sed -n '/active$/{=;q}' "$input")"
40[[ -z $line ]] && die "${0##*/}: not could find a active line in $input"
41is_int "$line" || die "${0##*/}: Strange - $line should be a number"
42values=( $(sed -n "${line}p" "$input") )
43
44parameters=( $(csg_get_interaction_property --all inverse.optimizer.parameters) )
45[[ $(( ${#values[@]} - 2 )) -ne ${#parameters[@]} ]] && die "${0##*/}: length of parameter string (${#values[@]}) does not match number of interactions (${#parameters[@]})"
46what=$(has_duplicate "${parameters[@]}") && die "${0##*/}: the parameter $what appears twice"
47
48template="$(csg_get_interaction_property inverse.optimizer.mapping.template)"
49output="$(csg_get_interaction_property inverse.optimizer.mapping.output)"
50cp_from_main_dir --rename "${template}" "${output}"
51
52for ((i=0;i<${#parameters[@]};i++)); do
53  echo "Replacing @${parameters[$i]}@ with ${values[$i]} in $output"
54  critical sed -i -e "s/@${parameters[$i]}@/${values[$i]}/g" "${output}"
55done
56