diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ec3e29add3..466e04a0c0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -31,6 +31,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) - removed unused functions (#702) Version 2021.2 (released XX.07.21) 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/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/imc_stat_generic.sh b/share/scripts/inverse/imc_stat_generic.sh index b6a44b8bc9..c42e4c702c 100755 --- a/share/scripts/inverse/imc_stat_generic.sh +++ b/share/scripts/inverse/imc_stat_generic.sh @@ -27,11 +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 -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 +56,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/postupd_cibi_correction.sh b/share/scripts/inverse/postupd_cibi_correction.sh index 4ca3dba021..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. @@ -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 100755 index 0000000000..6df168447b --- /dev/null +++ b/share/scripts/inverse/postupd_ibi.sh @@ -0,0 +1,55 @@ +#! /bin/bash +# +# 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. +# 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 <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--){ +# return the index of largest value in an array +sub maxindex { + 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); + +# 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)) { + $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 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)) { $dpot[$i]=log($rdf_cur[$i]/$rdf_aim[$i])*$pref; $flag[$i]="i"; 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..38d98c5461 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. @@ -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..a3187f8c89 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. @@ -703,6 +697,12 @@ 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 diff --git a/src/tools/csg_stat_imc.cc b/src/tools/csg_stat_imc.cc index 2e95f382bb..513949a03d 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();