<commit_before>#! /bin/bash
#
# Copyright 2009-2011 The VOTCA Development Team (http://www.votca.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if [[ $1 = "--help" ]]; then
cat <<EOF
${0##*/}, version %version%
This script calcs the density for gromacs

Usage: ${0##*/} outputfile csg_density_options
EOF
   exit 0
fi

[[ -z $1 || -z $2 ]] && die "${0##*/}: Missing argument"
output="$1"
shift

sim_prog="$(csg_get_property cg.inverse.program)"

if [[ $sim_prog = "gromacs" ]]; then
  topol=$(csg_get_property cg.inverse.gromacs.topol_out)
  [[ -f $topol ]] || die "${0##*/}: gromacs topol file '$topol' not found"

  ext=$(csg_get_property cg.inverse.gromacs.traj_type)
  traj="traj.${ext}"
  [[ -f $traj ]] || die "${0##*/}: gromacs traj file '$traj' not found"
else
  die "${0##*/}: Simulation program '$sim_prog' not supported yet"
fi

name=$(csg_get_interaction_property name)

equi_time="$(csg_get_property cg.inverse.gromacs.equi_time)"
first_frame="$(csg_get_property cg.inverse.gromacs.first_frame)"

with_errors=$(csg_get_property cg.inverse.gromacs.density.with_errors)
if [[ ${with_errors} = "yes" ]]; then
  suffix="_with_errors"
else
  suffix=""
fi

if is_done "${name}_density_analysis${suffix}"; then
  echo "density analysis is already done"
  exit 0
fi

if [[ ${with_errors} = "yes" ]]; then
  msg "Calculating density for $name with errors"
  block_length=$(csg_get_property cg.inverse.gromacs.density.block_length)
  critical csg_density --trj "$traj" --top "$topol" --out "${output}.block" --begin "$equi_time" --first-frame "$first_frame" --block-length $block_length "$@"
  #mind the --clean option to avoid ${name}.dist.block_* to fail on the second run
  do_external table average --clean --output "${output}" ${output}.block_*
else
  msg "Calculating density for $name"
  critical csg_density --trj "$traj" --top "$topol" --out "$output" --begin "$equi_time" --first-frame "$first_frame" "$@"
  critical sed -i -e '/nan/d' -e '/inf/d' "$output"
fi
mark_done "${name}_density_analysis${suffix}"
<commit_msg>calc_density_gromacs.sh: handle nan/inf in the case of density with errors<commit_after>#! /bin/bash
#
# Copyright 2009-2011 The VOTCA Development Team (http://www.votca.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

if [[ $1 = "--help" ]]; then
cat <<EOF
${0##*/}, version %version%
This script calcs the density for gromacs

Usage: ${0##*/} outputfile csg_density_options
EOF
   exit 0
fi

[[ -z $1 || -z $2 ]] && die "${0##*/}: Missing argument"
output="$1"
shift

sim_prog="$(csg_get_property cg.inverse.program)"

if [[ $sim_prog = "gromacs" ]]; then
  topol=$(csg_get_property cg.inverse.gromacs.topol_out)
  [[ -f $topol ]] || die "${0##*/}: gromacs topol file '$topol' not found"

  ext=$(csg_get_property cg.inverse.gromacs.traj_type)
  traj="traj.${ext}"
  [[ -f $traj ]] || die "${0##*/}: gromacs traj file '$traj' not found"
else
  die "${0##*/}: Simulation program '$sim_prog' not supported yet"
fi

name=$(csg_get_interaction_property name)

equi_time="$(csg_get_property cg.inverse.gromacs.equi_time)"
first_frame="$(csg_get_property cg.inverse.gromacs.first_frame)"

with_errors=$(csg_get_property cg.inverse.gromacs.density.with_errors)
if [[ ${with_errors} = "yes" ]]; then
  suffix="_with_errors"
else
  suffix=""
fi

if is_done "${name}_density_analysis${suffix}"; then
  echo "density analysis is already done"
  exit 0
fi

if [[ ${with_errors} = "yes" ]]; then
  msg "Calculating density for $name with errors"
  block_length=$(csg_get_property cg.inverse.gromacs.density.block_length)
  critical csg_density --trj "$traj" --top "$topol" --out "${output}.block" --begin "$equi_time" --first-frame "$first_frame" --block-length $block_length "$@"
  #mind the --clean option to avoid ${name}.dist.block_* to fail on the second run
  do_external table average --clean --output "${output}" ${output}.block_*
else
  msg "Calculating density for $name"
  critical csg_density --trj "$traj" --top "$topol" --out "$output" --begin "$equi_time" --first-frame "$first_frame" "$@"
fi
critical sed -i -e '/nan/d' -e '/inf/d' "$output"
mark_done "${name}_density_analysis${suffix}"

{'fraction_non_alphanumeric': 0.15592758419310881, 'fraction_numerical': 0.009343975082733113, 'mean_word_length': 4.572668112798264, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6430400', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1721, 'n_words': 543}