Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

post update ibi #696

Merged
merged 15 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
==================================
Expand Down
10 changes: 5 additions & 5 deletions share/doc/methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

<inverse>
<imc>
<bonded_method>ibi</bonded_method>
<settings_nonbonded>settings-nonbonded.xml</settings_nonbonded>
<group>none</group>
</imc>
<do_potential>0</do_potential>
<post_update>ibi</post_update>
</inverse>

Iterative Integral Equation methods
Expand Down
1 change: 1 addition & 0 deletions share/scripts/inverse/csg_table
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 2 additions & 20 deletions share/scripts/inverse/imc_stat_generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions share/scripts/inverse/postupd_cibi_correction.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
55 changes: 55 additions & 0 deletions share/scripts/inverse/postupd_ibi.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
${0##*/}, version %version%
This script implemtents the function post update with the Inverse Boltzmann
Method. This one is not like other post update methods in that the infile is ignored.

Usage: ${0##*/} infile outfile
EOF
exit 0
fi

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[@]} ))
postibi=( $(csg_get_interaction_property inverse.post_update_options.ibi.do) )
postibi_nr=$(( (step_nr - 1 ) % ${#postibi[@]} ))

if [[ ${postibi[$postibi_nr]} = 1 ]]; then

if [[ "${scheme[$scheme_nr]}" == 1 ]]; then
msg --color blue "WARNING: the potential ${name} has already been updated.
This ibi post-update will overwrite the original update and all previous
post-updates! You might want to set do_potential to 0."
fi

#update ibi
echo "Apply ibi post-update for interaction ${name}"
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"
else
echo "No ibi post-update for interaction ${name}"
do_external postupd dummy "$1" "$2"
fi
4 changes: 2 additions & 2 deletions share/scripts/inverse/postupd_kbibi_correction.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -24,7 +24,7 @@ P. Ganguly, D. Mukherji, C. Junghans, N. F. A. van der Vegt,
Kirkwood-Buff coarse-grained force fields for aqueous solutions,
J. Chem. Theo. Comp., 8, 1802 (2012), doi:10.1021/ct3000958

Usage: ${0##*/}
Usage: ${0##*/} infile outfile
EOF
exit 0
fi
Expand Down
12 changes: 6 additions & 6 deletions share/scripts/inverse/prepare_iie.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down
19 changes: 12 additions & 7 deletions share/scripts/inverse/prepare_imc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 30 additions & 4 deletions share/scripts/inverse/update_ibi_pot.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
junghans marked this conversation as resolved.
Show resolved Hide resolved
my( $aref, $idx_max ) = ( shift, 0 );
$aref->[$idx_max] > $aref->[$_] or $idx_max = $_ for 1 .. $#{$aref};
junghans marked this conversation as resolved.
Show resolved Hide resolved
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
junghans marked this conversation as resolved.
Show resolved Hide resolved
# 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";
Expand Down
11 changes: 4 additions & 7 deletions share/scripts/inverse/update_imc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions share/scripts/inverse/update_imc_single.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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'"
Expand All @@ -46,4 +52,3 @@ else
step=$(csg_get_interaction_property step)
do_external table dummy "${min}:${step}:${max}" "${name}.dpot.new"
fi

14 changes: 7 additions & 7 deletions share/xml/csg_defaults.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,6 @@
<default_reg>0
<DESC> default magnitude for regularization parameter if not given for the group explicitly, default =0</DESC>
</default_reg>
<bonded_method>ibi
<DESC> method for calculating updates on the bonded interactions. ibi or imc (not implemented), default=ibi </DESC>
</bonded_method>
<settings_nonbonded>imc
<DESC> settings file to be used with csg_stat --do-imc. only needed if bonded_method=ibi</DESC>
</settings_nonbonded>
junghans marked this conversation as resolved.
Show resolved Hide resolved
</imc>
<lammps>
<DESC> general lammps specific options </DESC>
Expand Down Expand Up @@ -605,7 +599,7 @@
<imc>
<DESC>section containing inverse monte carlo specific options.</DESC>
<group>
<DESC>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.</DESC>
<DESC>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.</DESC>
</group>
</imc>
<lammps>
Expand Down Expand Up @@ -703,6 +697,12 @@
<DESC>Number of point to calculate the average from for the extrapolation</DESC>
</points>
</extrapolate>
<ibi>
<DESC>Contains all options of the IBI post-update script</DESC>
<do>1
<DESC>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</DESC>
</do>
</ibi>
<kbibi>
<DESC>Contains all options of the Kirkwood-Buff ramp corrections scripts</DESC>
<do>1
Expand Down
4 changes: 3 additions & 1 deletion src/tools/csg_stat_imc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ Imc::interaction_t *Imc::AddInteraction(tools::Property *p, bool is_bonded) {
std::make_pair(name, std::make_unique<interaction_t>()));
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<double>();
Expand Down