From 40abc2dd74f18f93724369ab8d1ae320a790fe8c Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Wed, 23 Jun 2021 08:57:10 +0200 Subject: [PATCH 01/13] better way to exclude interactions from imc --- share/doc/methods.rst | 10 +++++----- share/scripts/inverse/imc_stat_generic.sh | 21 ++------------------- share/scripts/inverse/prepare_imc.sh | 19 ++++++++++++------- share/scripts/inverse/update_imc.sh | 11 ++++------- share/scripts/inverse/update_imc_single.sh | 9 +++++++-- share/xml/csg_defaults.xml.in | 8 +------- src/tools/csg_stat_imc.cc | 4 +++- 7 files changed, 34 insertions(+), 48 deletions(-) diff --git a/share/doc/methods.rst b/share/doc/methods.rst index acdb644a2b..d3017ff39a 100644 --- a/share/doc/methods.rst +++ b/share/doc/methods.rst @@ -663,17 +663,17 @@ unregularized version of IMC is applied. Internal degrees of freedom ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -For internal degrees of freedom, one can apply the IBI method. In that case, -one also has to provide a setting_nonbonded file, which will be used to -calculate the IMC matrix only from the nonbonded interactions. +For internal degrees of freedom, one can apply the IBI method as a post update +method. .. code:: xml - ibi - settings-nonbonded.xml + none + 0 + ibi Iterative Integral Equation methods diff --git a/share/scripts/inverse/imc_stat_generic.sh b/share/scripts/inverse/imc_stat_generic.sh index b6a44b8bc9..0c93295f36 100755 --- a/share/scripts/inverse/imc_stat_generic.sh +++ b/share/scripts/inverse/imc_stat_generic.sh @@ -28,10 +28,6 @@ fi sim_prog="$(csg_get_property cg.inverse.program)" [[ -n $(csg_get_property --allow-empty cg.bonded.name) ]] && has_bonds=true || has_bonds=false -bonded_method="$(csg_get_property cg.inverse.imc.bonded_method)" -if [[ $has_bonds == true && $bonded_method == "ibi" ]]; then - settings_nonbonded="$(csg_get_property cg.inverse.imc.settings_nonbonded)" -fi topol=$(csg_get_property --allow-empty cg.inverse.$sim_prog.imc.topol) [[ -z $topol ]] && topol=$(csg_get_property cg.inverse.$sim_prog.topol) @@ -61,21 +57,8 @@ else #copy+resample all target dist in $this_dir for_all "non-bonded bonded" do_external resample target '$(csg_get_interaction_property inverse.target)' '$(csg_get_interaction_property name).dist.tgt' - if [[ $has_bonds == true ]]; then - if [[ $bonded_method == "imc" ]]; then - die "using IMC for bonded potentials is not implemented yet" - elif [[ $bonded_method == "ibi" ]]; then - msg "calculating regular distributions for ibi bonded upates" - critical csg_stat --options "$CSGXMLFILE" --top "$topol" --trj "$traj" \ - --begin $equi_time --first-frame $first_frame --nt $tasks - msg "calculating correlations for imc updates" - critical csg_stat --do-imc --options "$settings_nonbonded" --top "$topol" --trj "$traj" \ - --begin $equi_time --first-frame $first_frame --nt $tasks - fi - else - critical csg_stat --do-imc --options "$CSGXMLFILE" --top "$topol" --trj "$traj" \ - --begin $equi_time --first-frame $first_frame --nt $tasks - fi + critical csg_stat --do-imc --options "$CSGXMLFILE" --top "$topol" --trj "$traj" \ + --begin $equi_time --first-frame $first_frame --nt $tasks mark_done "imc_analysis" fi diff --git a/share/scripts/inverse/prepare_imc.sh b/share/scripts/inverse/prepare_imc.sh index ddb0caf808..c584729485 100755 --- a/share/scripts/inverse/prepare_imc.sh +++ b/share/scripts/inverse/prepare_imc.sh @@ -32,12 +32,17 @@ if [[ ${#names[@]} -gt 1 ]]; then msg --color blue "####################################################" fi - -[[ -n $(csg_get_property --allow-empty cg.bonded.name) ]] && has_bonds=true || has_bonds=false -bonded_method="$(csg_get_property cg.inverse.imc.bonded_method)" - -if [[ $has_bonds == true && $bonded_method == "imc" ]]; then - die "using IMC for bonded potentials is not implemented yet" -fi +check_bonded_update() { + local do_potential=$(csg_get_interaction_property inverse.do_potential) + local imc_group=$(csg_get_interaction_property inverse.imc.group) + if [[ $do_potential != 0 ]] || [[ $imc_group != "none" ]]; then + die_msg="using IMC for bonded potentials is not implemented yet.\n"\ +"Make sure to set update_potential to 0 and imc.group to 'none' for\n"\ +"each bonded interaction. You can still use post_update ibi." + die "$die_msg" + fi +} +export -f check_bonded_update +for_all "bonded" check_bonded_update do_external prepare generic diff --git a/share/scripts/inverse/update_imc.sh b/share/scripts/inverse/update_imc.sh index 7b7f38fa18..85398d5174 100755 --- a/share/scripts/inverse/update_imc.sh +++ b/share/scripts/inverse/update_imc.sh @@ -32,20 +32,17 @@ do_external imc_stat $sim_prog default_reg=$(csg_get_property cg.inverse.imc.default_reg) is_num "${default_reg}" || die "${0##*/}: value of cg.inverse.imc.default_reg should be a number" -[[ -n $(csg_get_property --allow-empty cg.bonded.name) ]] && has_bonds=true || has_bonds=false -bonded_method="$(csg_get_property cg.inverse.imc.bonded_method)" - imc_groups=$(csg_get_interaction_property --all inverse.imc.group) imc_groups=$(remove_duplicate $imc_groups) [[ -z ${imc_groups} ]] && die "${0##*/}: No imc groups defined" for group in $imc_groups; do + if [[ $group == "none" ]]; then + continue + fi reg="$(csg_get_property cg.inverse.imc.${group}.reg ${default_reg})" #filter me away is_num "${reg}" || die "${0##*/}: value of cg.inverse.imc.${group}.reg should be a number" msg "solving linear equations for imc group '$group' (regularization ${reg})" critical csg_imc_solve --imcfile "${group}.imc" --gmcfile "${group}.gmc" --idxfile "${group}.idx" --regularization "${reg}" done -for_all "non-bonded" do_external update imc_single -if [[ $has_bonds == true && $bonded_method == "ibi" ]]; then - for_all "bonded" do_external update ibi_single -fi +for_all "non-bonded bonded" do_external update imc_single diff --git a/share/scripts/inverse/update_imc_single.sh b/share/scripts/inverse/update_imc_single.sh index 70f82d2578..dd6754995f 100755 --- a/share/scripts/inverse/update_imc_single.sh +++ b/share/scripts/inverse/update_imc_single.sh @@ -30,8 +30,14 @@ step_nr=$(get_current_step_nr) scheme=( $(csg_get_interaction_property inverse.do_potential) ) scheme_nr=$(( ( $step_nr - 1 ) % ${#scheme[@]} )) name=$(csg_get_interaction_property name) +group=$(csg_get_interaction_property inverse.imc.group) -if [ "${scheme[$scheme_nr]}" = 1 ]; then +if [[ $group == "none" ]] && [[ "${scheme[$scheme_nr]}" == 1 ]]; then + die_msg="for interaction $name the imc group is 'none' but\n"\ +"update_potential is non-zero. No imc update was calculated, so no update\n"\ +"can be made." + die "$die_msg" +elif [ "${scheme[$scheme_nr]}" = 1 ]; then echo "Update potential ${name} : yes" kBT=$(csg_get_property cg.inverse.kBT) is_num "${kBT}" || die "${0##*/}: cg.inverse.kBT should be a number, but found '$kBT'" @@ -46,4 +52,3 @@ else step=$(csg_get_interaction_property step) do_external table dummy "${min}:${step}:${max}" "${name}.dpot.new" fi - diff --git a/share/xml/csg_defaults.xml.in b/share/xml/csg_defaults.xml.in index c982601495..58889f23fb 100644 --- a/share/xml/csg_defaults.xml.in +++ b/share/xml/csg_defaults.xml.in @@ -263,12 +263,6 @@ 0 default magnitude for regularization parameter if not given for the group explicitly, default =0 - ibi - method for calculating updates on the bonded interactions. ibi or imc (not implemented), default=ibi - - imc - settings file to be used with csg_stat --do-imc. only needed if bonded_method=ibi - general lammps specific options @@ -605,7 +599,7 @@ section containing inverse monte carlo specific options. - Group of interaction. Cross-correlations of all members of a group are taken into account for calculating the update. If no cross correlations should be calculated, interactions have to be put into different groups. + Group of interaction. Cross-correlations of all members of a group are taken into account for calculating the update. If no cross correlations should be calculated, interactions have to be put into different groups. Group 'none' is completely ignored and update_potential needs to be zero for the respective interactions. diff --git a/src/tools/csg_stat_imc.cc b/src/tools/csg_stat_imc.cc index fa044e225c..0c39916b27 100644 --- a/src/tools/csg_stat_imc.cc +++ b/src/tools/csg_stat_imc.cc @@ -196,7 +196,9 @@ Imc::interaction_t *Imc::AddInteraction(tools::Property *p, bool is_bonded) { std::make_pair(name, std::make_unique())); interaction_t *i = success.first->second.get(); i->_index = index; - getGroup(group)->_interactions.push_back(i); + if (group != "none") { + getGroup(group)->_interactions.push_back(i); + } i->_is_bonded = is_bonded; i->_step = p->get("step").as(); From 4ee555ba26aca1e6dff7e3d0e8a19f89c61fbd25 Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Wed, 23 Jun 2021 08:57:34 +0200 Subject: [PATCH 02/13] fix in iie prepare --- share/scripts/inverse/prepare_iie.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/share/scripts/inverse/prepare_iie.sh b/share/scripts/inverse/prepare_iie.sh index acaa95e76b..1500e14ff7 100755 --- a/share/scripts/inverse/prepare_iie.sh +++ b/share/scripts/inverse/prepare_iie.sh @@ -28,13 +28,7 @@ fi sim_prog="$(csg_get_property cg.inverse.program)" method="$(csg_get_property cg.inverse.method)" initial_guess_method="$(csg_get_property "cg.inverse.${method}.initial_guess.method")" -main_dir=$(get_main_dir) -nb_interactions=$(csg_get_property --allow-empty cg.non-bonded.name) -kBT="$(csg_get_property cg.inverse.kBT)" -densities="$(csg_get_property cg.inverse.iie.densities)" -n_intra="$(csg_get_property cg.inverse.iie.n_intra)" verbose=$(csg_get_property cg.inverse.iie.verbose) -cut_off="$(csg_get_property cg.inverse.iie.cut_off)" if [ "${verbose}" == 'true' ]; then verbose_flag="--verbose" @@ -52,6 +46,12 @@ case "$initial_guess_method" in for_all "bonded non-bonded" do_external prepare_single generic --use-bi ;; "ie") + main_dir=$(get_main_dir) + nb_interactions=$(csg_get_property --allow-empty cg.non-bonded.name) + kBT="$(csg_get_property cg.inverse.kBT)" + densities="$(csg_get_property cg.inverse.iie.densities)" + n_intra="$(csg_get_property cg.inverse.iie.n_intra)" + cut_off="$(csg_get_property cg.inverse.iie.cut_off)" # only for IE initial_guess_closure=$(csg_get_property "cg.inverse.${method}.initial_guess.closure") initial_guess_ignore_intra=$(csg_get_property "cg.inverse.${method}.initial_guess.ignore_intramolecular_correlation") From 1135653fddab01126f1b2074ab52a1f5fb80b505 Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Wed, 23 Jun 2021 11:05:19 +0200 Subject: [PATCH 03/13] post update ibi --- share/scripts/inverse/csg_table | 1 + .../inverse/postupd_cibi_correction.sh | 2 +- share/scripts/inverse/postupd_ibi.sh | 55 +++++++++++++++++++ .../inverse/postupd_kbibi_correction.sh | 2 +- share/xml/csg_defaults.xml.in | 6 ++ 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 share/scripts/inverse/postupd_ibi.sh diff --git a/share/scripts/inverse/csg_table b/share/scripts/inverse/csg_table index dd3f5c6555..139a162212 100644 --- a/share/scripts/inverse/csg_table +++ b/share/scripts/inverse/csg_table @@ -82,6 +82,7 @@ postupd tag tag_file.sh postupd extrapolate postupd_extrapolate.sh postupd kbibi postupd_kbibi_correction.sh postupd cibi postupd_cibi_correction.sh +postupd ibi postupd_ibi.sh # post add post add post_add.sh diff --git a/share/scripts/inverse/postupd_cibi_correction.sh b/share/scripts/inverse/postupd_cibi_correction.sh index 4ca3dba021..d13f713e75 100755 --- a/share/scripts/inverse/postupd_cibi_correction.sh +++ b/share/scripts/inverse/postupd_cibi_correction.sh @@ -25,7 +25,7 @@ C-IBI: Targeting cumulative coordination within an iterative protocol to derive coarse-grained models of (multi-component) complex fluids, J. Chem. Phys. (in press). -Usage: ${0##*/} +Usage: ${0##*/} infile outfile EOF exit 0 fi diff --git a/share/scripts/inverse/postupd_ibi.sh b/share/scripts/inverse/postupd_ibi.sh new file mode 100644 index 0000000000..4332fdcb32 --- /dev/null +++ b/share/scripts/inverse/postupd_ibi.sh @@ -0,0 +1,55 @@ +#! /bin/bash +# +# Copyright 2009-2017 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 <Number of point to calculate the average from for the extrapolation + + Contains all options of the IBI post-update script + 1 + Update cycle for the IBI post-update (1 do, 0 do not). To do the post-update every third step specify "0 0 1", similar to do_potential + + Contains all options of the Kirkwood-Buff ramp corrections scripts 1 From 8f32dc386083acfb6c8be8ec2bd7632d76188713 Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Wed, 23 Jun 2021 13:27:01 +0200 Subject: [PATCH 04/13] bash improvements --- share/scripts/inverse/postupd_ibi.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/share/scripts/inverse/postupd_ibi.sh b/share/scripts/inverse/postupd_ibi.sh index 4332fdcb32..0a5ba868cb 100644 --- a/share/scripts/inverse/postupd_ibi.sh +++ b/share/scripts/inverse/postupd_ibi.sh @@ -30,9 +30,9 @@ name=$(csg_get_interaction_property name) bondtype="$(csg_get_interaction_property bondtype)" step_nr=$(get_current_step_nr) scheme=( $(csg_get_interaction_property inverse.do_potential) ) -scheme_nr=$(( ($step_nr - 1 ) % ${#scheme[@]} )) +scheme_nr=$(( (step_nr - 1 ) % ${#scheme[@]} )) postibi=( $(csg_get_interaction_property inverse.post_update_options.ibi.do) ) -postibi_nr=$(( ($step_nr - 1 ) % ${#postibi[@]} )) +postibi_nr=$(( (step_nr - 1 ) % ${#postibi[@]} )) if [[ ${postibi[$postibi_nr]} = 1 ]]; then @@ -47,8 +47,8 @@ post-updates! You might want to set do_potential to 0." do_external resample target "$(csg_get_interaction_property inverse.target)" "${name}.dist.tgt" kBT="$(csg_get_property cg.inverse.kBT)" is_num "${kBT}" || die "${0##*/}: cg.inverse.kBT should be a number, but found '$kBT'" - do_external update ibi_pot ${name}.dist.tgt ${name}.dist.new ${name}.pot.cur ${name}.dpot.pure_ibi "${kBT}" - do_external potential shift --type "${bondtype}" ${name}.dpot.pure_ibi "$2" + do_external update ibi_pot "${name}.dist.tgt" "${name}.dist.new" "${name}.pot.cur" "${name}.dpot.pure_ibi" "${kBT}" + do_external potential shift --type "${bondtype}" "${name}.dpot.pure_ibi" "$2" else echo "No ibi post-update for interaction ${name}" do_external postupd dummy "$1" "$2" From 79463917b91bbb551e6f7040ef2350a1ff9dc376 Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Wed, 23 Jun 2021 13:28:23 +0200 Subject: [PATCH 05/13] make postupd_ibi.sh executable --- share/scripts/inverse/postupd_ibi.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 share/scripts/inverse/postupd_ibi.sh diff --git a/share/scripts/inverse/postupd_ibi.sh b/share/scripts/inverse/postupd_ibi.sh old mode 100644 new mode 100755 From f9f27fe0098eb52a4af1fc8841944d0b81396bec Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Wed, 23 Jun 2021 16:31:23 +0000 Subject: [PATCH 06/13] Format code using clang-format version 12.0.0 (Fedora 12.0.0-2.fc34) --- src/tools/csg_stat_imc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/csg_stat_imc.cc b/src/tools/csg_stat_imc.cc index 4198c2a535..513949a03d 100644 --- a/src/tools/csg_stat_imc.cc +++ b/src/tools/csg_stat_imc.cc @@ -197,7 +197,7 @@ Imc::interaction_t *Imc::AddInteraction(tools::Property *p, bool is_bonded) { interaction_t *i = success.first->second.get(); i->index_ = index; if (group != "none") { - getGroup(group)->interactions_.push_back(i); + getGroup(group)->interactions_.push_back(i); } i->is_bonded_ = is_bonded; From 6af62796750149c4b4ace1da4ea686ef5859743f Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Thu, 24 Jun 2021 21:40:53 +0000 Subject: [PATCH 07/13] Update CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c4ddd9fdae..e1504bf2b1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -30,6 +30,7 @@ Version 2022-dev - use ndim vector instead of std::vector (#689) - adapted tokenizer api (#693) - made membervariable format consistent (#694) +- add ability to run ibi as a postupd method (#696) Version 2021.1 (released XX.03.21) ================================== From 9b2210813b3d3ff487e4741ba16ff0d81b6a2e83 Mon Sep 17 00:00:00 2001 From: Votca Bot Date: Thu, 24 Jun 2021 23:04:34 +0000 Subject: [PATCH 08/13] Update copyright --- share/scripts/inverse/postupd_cibi_correction.sh | 2 +- share/scripts/inverse/postupd_ibi.sh | 2 +- share/scripts/inverse/postupd_kbibi_correction.sh | 2 +- share/scripts/inverse/update_imc_single.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/share/scripts/inverse/postupd_cibi_correction.sh b/share/scripts/inverse/postupd_cibi_correction.sh index d13f713e75..e0bd2a49e8 100755 --- a/share/scripts/inverse/postupd_cibi_correction.sh +++ b/share/scripts/inverse/postupd_cibi_correction.sh @@ -1,6 +1,6 @@ #! /bin/bash # -# Copyright 2009-2017 The VOTCA Development Team (http://www.votca.org) +# Copyright 2009-2021 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. diff --git a/share/scripts/inverse/postupd_ibi.sh b/share/scripts/inverse/postupd_ibi.sh index 0a5ba868cb..6df168447b 100755 --- a/share/scripts/inverse/postupd_ibi.sh +++ b/share/scripts/inverse/postupd_ibi.sh @@ -1,6 +1,6 @@ #! /bin/bash # -# Copyright 2009-2017 The VOTCA Development Team (http://www.votca.org) +# Copyright 2009-2021 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. diff --git a/share/scripts/inverse/postupd_kbibi_correction.sh b/share/scripts/inverse/postupd_kbibi_correction.sh index 33f72aadce..b8e53fe625 100755 --- a/share/scripts/inverse/postupd_kbibi_correction.sh +++ b/share/scripts/inverse/postupd_kbibi_correction.sh @@ -1,6 +1,6 @@ #! /bin/bash # -# Copyright 2009-2017 The VOTCA Development Team (http://www.votca.org) +# Copyright 2009-2021 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. diff --git a/share/scripts/inverse/update_imc_single.sh b/share/scripts/inverse/update_imc_single.sh index dd6754995f..40d4d05f48 100755 --- a/share/scripts/inverse/update_imc_single.sh +++ b/share/scripts/inverse/update_imc_single.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright 2009-2019 The VOTCA Development Team (http://www.votca.org) +# Copyright 2009-2021 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. From 3fdce852955275c0586081ee50637ddb528d3f07 Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Fri, 16 Jul 2021 14:19:49 +0200 Subject: [PATCH 09/13] better bash --- share/scripts/inverse/update_imc_single.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/share/scripts/inverse/update_imc_single.sh b/share/scripts/inverse/update_imc_single.sh index 40d4d05f48..38d98c5461 100755 --- a/share/scripts/inverse/update_imc_single.sh +++ b/share/scripts/inverse/update_imc_single.sh @@ -32,12 +32,12 @@ scheme_nr=$(( ( $step_nr - 1 ) % ${#scheme[@]} )) name=$(csg_get_interaction_property name) group=$(csg_get_interaction_property inverse.imc.group) -if [[ $group == "none" ]] && [[ "${scheme[$scheme_nr]}" == 1 ]]; then +if [[ $group == "none" ]] && [[ ${scheme[$scheme_nr]} == 1 ]]; then die_msg="for interaction $name the imc group is 'none' but\n"\ "update_potential is non-zero. No imc update was calculated, so no update\n"\ "can be made." die "$die_msg" -elif [ "${scheme[$scheme_nr]}" = 1 ]; then +elif [[ ${scheme[$scheme_nr]} == 1 ]]; then echo "Update potential ${name} : yes" kBT=$(csg_get_property cg.inverse.kBT) is_num "${kBT}" || die "${0##*/}: cg.inverse.kBT should be a number, but found '$kBT'" From 0cc6ff0564ea7da7287afe40660ebc8ea76ae8da Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Fri, 23 Jul 2021 15:34:23 +0200 Subject: [PATCH 10/13] fix constant extrapolation in both directions for ibi update --- share/scripts/inverse/update_ibi_pot.pl | 34 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/share/scripts/inverse/update_ibi_pot.pl b/share/scripts/inverse/update_ibi_pot.pl index af4b06625c..cae05fded3 100755 --- a/share/scripts/inverse/update_ibi_pot.pl +++ b/share/scripts/inverse/update_ibi_pot.pl @@ -56,17 +56,43 @@ (readin_table($cur_pot_file,@pot_r_cur,@pot_cur,@pot_flags_cur)) || die "$progname: error at readin_table\n"; #should never happen due to resample, but better check -die "Different grids \n" if (($r_aim[1]-$r_aim[0]-$r_cur[1]+$r_cur[0])>0.0001); +die "Different grids \n" if (($r_aim[1]-$r_aim[0]-$r_cur[1]+$r_cur[0]) > 0.0001); die "Different start potential point \n" if (($r_aim[0]-$r_cur[0]) > 0.0001); die "Different end potential point \n" if ( $#r_aim != $#r_cur ); my $outfile="$ARGV[3]"; my @dpot; my @flag; -my $value=0.0; -#start from the end to make the begining have the last value -for (my $i=$#r_aim;$i>=0;$i--){ +sub maxindex { + my( $aref, $idx_max ) = ( shift, 0 ); + $aref->[$idx_max] > $aref->[$_] or $idx_max = $_ for 1 .. $#{$aref}; + return $idx_max; +} +my $ndx_max_rdf_cur = maxindex(\@rdf_cur); + +#start from the middle and make the outside regions have the last valid value +# go to end +my $value=0.0; +for (my $i=$ndx_max_rdf_cur;$i<=$#r_aim;$i++){ + if (($rdf_aim[$i] > 1e-10) && ($rdf_cur[$i] > 1e-10)) { + $dpot[$i]=log($rdf_cur[$i]/$rdf_aim[$i])*$pref; + $flag[$i]="i"; + } else { + $dpot[$i]=$value; + $flag[$i]="o"; + } + if($pot_flags_cur[$i] =~ /[u]/) { + $dpot[$i]=$value; + $flag[$i]="o"; + } + else { + $value=$dpot[$i]; + } +} +# go to beginning +$value=0.0; +for (my $i=$ndx_max_rdf_cur-1;$i>=0;$i--){ if (($rdf_aim[$i] > 1e-10) && ($rdf_cur[$i] > 1e-10)) { $dpot[$i]=log($rdf_cur[$i]/$rdf_aim[$i])*$pref; $flag[$i]="i"; From 7bc89c062154848b22a6e48714dfc11c23a5a057 Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Fri, 23 Jul 2021 15:42:51 +0200 Subject: [PATCH 11/13] rm has_bonds --- share/scripts/inverse/imc_stat_generic.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/share/scripts/inverse/imc_stat_generic.sh b/share/scripts/inverse/imc_stat_generic.sh index 0c93295f36..c42e4c702c 100755 --- a/share/scripts/inverse/imc_stat_generic.sh +++ b/share/scripts/inverse/imc_stat_generic.sh @@ -27,7 +27,6 @@ EOF fi sim_prog="$(csg_get_property cg.inverse.program)" -[[ -n $(csg_get_property --allow-empty cg.bonded.name) ]] && has_bonds=true || has_bonds=false topol=$(csg_get_property --allow-empty cg.inverse.$sim_prog.imc.topol) [[ -z $topol ]] && topol=$(csg_get_property cg.inverse.$sim_prog.topol) From 99a247e640c6b72cc683455538d2c4765ef88c2b Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Mon, 26 Jul 2021 17:43:18 +0200 Subject: [PATCH 12/13] better comments, simpler maxindex() --- share/scripts/inverse/update_ibi_pot.pl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/share/scripts/inverse/update_ibi_pot.pl b/share/scripts/inverse/update_ibi_pot.pl index cae05fded3..56f9da8ea4 100755 --- a/share/scripts/inverse/update_ibi_pot.pl +++ b/share/scripts/inverse/update_ibi_pot.pl @@ -65,14 +65,20 @@ my @flag; sub maxindex { - my( $aref, $idx_max ) = ( shift, 0 ); - $aref->[$idx_max] > $aref->[$_] or $idx_max = $_ for 1 .. $#{$aref}; - return $idx_max; + my $index = 0; + my $max = 0.0; + for my $i (0 .. $#_) { + if ($_[$i] > $max) { + $max = $_[$i]; + $index = $i; + } + } + return $index; } -my $ndx_max_rdf_cur = maxindex(\@rdf_cur); -#start from the middle and make the outside regions have the last valid value -# go to end +my $ndx_max_rdf_cur = maxindex(@rdf_cur); + +# go from ndx_max_rdf to end of table and fill the end with the last valid value encountered my $value=0.0; for (my $i=$ndx_max_rdf_cur;$i<=$#r_aim;$i++){ if (($rdf_aim[$i] > 1e-10) && ($rdf_cur[$i] > 1e-10)) { @@ -90,7 +96,7 @@ sub maxindex { $value=$dpot[$i]; } } -# go to beginning +# go from ndx_max_rdf to beginning of table and fill the end with the last valid value encountered $value=0.0; for (my $i=$ndx_max_rdf_cur-1;$i>=0;$i--){ if (($rdf_aim[$i] > 1e-10) && ($rdf_cur[$i] > 1e-10)) { From 5dc23c4db58555c058b3749f147a620cde3beb9a Mon Sep 17 00:00:00 2001 From: marvinbernhardt Date: Mon, 26 Jul 2021 17:51:54 +0200 Subject: [PATCH 13/13] added comment --- share/scripts/inverse/update_ibi_pot.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/share/scripts/inverse/update_ibi_pot.pl b/share/scripts/inverse/update_ibi_pot.pl index 56f9da8ea4..aec21c7c95 100755 --- a/share/scripts/inverse/update_ibi_pot.pl +++ b/share/scripts/inverse/update_ibi_pot.pl @@ -64,6 +64,7 @@ my @dpot; my @flag; +# return the index of largest value in an array sub maxindex { my $index = 0; my $max = 0.0;