diff --git a/src/analysis/WhamHistogram.cpp b/src/analysis/WhamHistogram.cpp new file mode 100644 index 0000000000000000000000000000000000000000..299f13b6ca0b6f785e2aee4bda8fc9e13f343c5b --- /dev/null +++ b/src/analysis/WhamHistogram.cpp @@ -0,0 +1,84 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2012 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed-code.org for more information. + + This file is part of plumed, version 2.0. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see <http://www.gnu.org/licenses/>. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#include "core/ActionShortcut.h" +#include "core/ActionRegister.h" + +namespace PLMD { +namespace analysis { + +//+PLUMEDOC ANALYSIS WHAM_HISTOGRAM +/* +This can be used to output the a histogram using the weighted histogram techinque + +\par Examples + +*/ +//+ENDPLUMEDOC + +class WhamHistogram : public ActionShortcut { +public: + static void registerKeywords( Keywords& keys ); + WhamHistogram( const ActionOptions& ); +}; + +PLUMED_REGISTER_ACTION(WhamHistogram,"WHAM_HISTOGRAM") + +void WhamHistogram::registerKeywords( Keywords& keys ) { + ActionShortcut::registerKeywords( keys ); + keys.add("compulsory","ARG","the arguments that you would like to make the histogram for"); + keys.add("compulsory","BIAS","*.bias","the value of the biases to use when performing WHAM"); + keys.add("compulsory","TEMP","the temperature at which the simulation was run"); + keys.add("compulsory","STRIDE","1","the frequency with which the data should be stored to perform WHAM"); + keys.add("compulsory","GRID_MIN","the minimum to use for the grid"); + keys.add("compulsory","GRID_MAX","the maximum to use for the grid"); + keys.add("compulsory","GRID_BIN","the number of bins to use for the grid"); + keys.add("optional","BANDWIDTH","the bandwidth for kernel density estimation"); +} + + +WhamHistogram::WhamHistogram( const ActionOptions& ao ) : +Action(ao), +ActionShortcut(ao) +{ + // Input for REWEIGHT_WHAM + std::string rew_line = getShortcutLabel() + "_weights: REWEIGHT_WHAM"; + std::string bias; parse("BIAS",bias); rew_line += " ARG=" + bias; + std::string temp; parse("TEMP",temp); rew_line += " TEMP=" + temp; + readInputLine( rew_line ); + // Input for COLLECT_FRAMES + std::string col_line = getShortcutLabel() + "_collect: COLLECT_FRAMES LOGWEIGHTS=" + getShortcutLabel() + "_weights"; + std::string stride; parse("STRIDE",stride); col_line += " STRIDE=" + stride; + std::string arg; parse("ARG",arg); col_line += " ARG=" + arg; + readInputLine( col_line ); + // Input for HISTOGRAM + std::string histo_line = getShortcutLabel() + ": HISTOGRAM ARG=" + getShortcutLabel() + "_collect.*"; + std::string min; parse("GRID_MIN",min); histo_line += " GRID_MIN=" + min; + std::string max; parse("GRID_MAX",max); histo_line += " GRID_MAX=" + max; + std::string bin; parse("GRID_BIN",bin); histo_line += " GRID_BIN=" + bin; + std::string bw=""; parse("BANDWIDTH",bw); + if( bw!="" ) histo_line += " BANDWIDTH=" + bw; + else histo_line += " KERNEL=DISCRETE"; + readInputLine( histo_line ); +} + +} +} diff --git a/src/analysis/WhamWeights.cpp b/src/analysis/WhamWeights.cpp new file mode 100644 index 0000000000000000000000000000000000000000..187626d3aa59585f0ad60b3f8dcd5479940d8ebf --- /dev/null +++ b/src/analysis/WhamWeights.cpp @@ -0,0 +1,75 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2012 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed-code.org for more information. + + This file is part of plumed, version 2.0. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see <http://www.gnu.org/licenses/>. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#include "core/ActionShortcut.h" +#include "core/ActionRegister.h" + +namespace PLMD { +namespace analysis { + +//+PLUMEDOC ANALYSIS WHAM_WEIGHTS +/* +This can be used to output the data that has been stored in an Analysis object. + +\par Examples + +*/ +//+ENDPLUMEDOC + +class WhamWeights : public ActionShortcut { +public: + static void registerKeywords( Keywords& keys ); + WhamWeights( const ActionOptions& ); +}; + +PLUMED_REGISTER_ACTION(WhamWeights,"WHAM_WEIGHTS") + +void WhamWeights::registerKeywords( Keywords& keys ) { + ActionShortcut::registerKeywords( keys ); keys.remove("LABEL"); + keys.add("compulsory","BIAS","*.bias","the value of the biases to use when performing WHAM"); + keys.add("compulsory","TEMP","the temperature at which the simulation was run"); + keys.add("compulsory","STRIDE","1","the frequency with which the bias should be stored to perform WHAM"); + keys.add("compulsory","FILE","the file on which to output the WHAM weights"); + keys.add("optional","FMT","the format to use for the real numbers in the output file"); +} + +WhamWeights::WhamWeights( const ActionOptions& ao ) : +Action(ao), +ActionShortcut(ao) +{ + // Input for REWEIGHT_WHAM + std::string rew_line = getShortcutLabel() + "_weights: REWEIGHT_WHAM"; + std::string bias; parse("BIAS",bias); rew_line += " ARG=" + bias; + std::string temp; parse("TEMP",temp); rew_line += " TEMP=" + temp; + readInputLine( rew_line ); + // Input for COLLECT_FRAMES + std::string col_line = getShortcutLabel() + "_collect: COLLECT_FRAMES LOGWEIGHTS=" + getShortcutLabel() + "_weights"; + std::string stride; parse("STRIDE",stride); col_line += "STRIDE=" + stride; + readInputLine( col_line ); + // Input for line to output data + std::string out_line="OUTPUT_ANALYSIS_DATA_TO_COLVAR USE_OUTPUT_DATA_FROM=" + getShortcutLabel() + "_collect"; + std::string file; parse("FILE",file); out_line += " FILE=" + file; + std::string fmt="%f"; parse("FMT",fmt); out_line += " FMT=" + fmt; + readInputLine( out_line ); +} + +} +} diff --git a/src/core/Action.h b/src/core/Action.h index 7b1db0ae291a2165881c4aa07560c95d47d68103..fe98e6d244e1a8b863262bef16f2007d0ebb9972 100644 --- a/src/core/Action.h +++ b/src/core/Action.h @@ -57,8 +57,8 @@ public: /// Base class for all the input Actions. /// The input Actions are more or less corresponding to the directives /// in the plumed.dat file and are applied in order at each time-step. -class Action -{ +class Action { +friend class ActionShortcut; /// Name of the directive in the plumed.dat file. const std::string name; diff --git a/src/core/ActionShortcut.cpp b/src/core/ActionShortcut.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e401a1704b55521bb14b009e7540bc057d4fd886 --- /dev/null +++ b/src/core/ActionShortcut.cpp @@ -0,0 +1,60 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2011-2018 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed.org for more information. + + This file is part of plumed, version 2. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see <http://www.gnu.org/licenses/>. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#include "ActionShortcut.h" +#include "PlumedMain.h" +#include "ActionSet.h" + +namespace PLMD { + +void ActionShortcut::registerKeywords( Keywords& keys ) { + Action::registerKeywords( keys ); +} + +ActionShortcut::ActionShortcut(const ActionOptions&ao): + Action(ao) +{ + shortcutlabel = label; + std::string s; Tools::convert(plumed.getActionSet().size(),s); + if( shortcutlabel==("@" + s) ) { + std::string t; Tools::convert(plumed.getActionSet().size()+1,t); + shortcutlabel="@" + t; + } else label = ("@" + s); +} + +void ActionShortcut::readInputLine( const std::string& input ) { + std::string f_input = input; + if( update_from!=std::numeric_limits<double>::max() ) { + std::string ufrom; Tools::convert( update_from, ufrom ); f_input += " UPDATE_FROM=" + ufrom; + } + if( update_until!=std::numeric_limits<double>::max() ) { + std::string util; Tools::convert( update_until, util ); f_input += " UPDATE_UNTIL=" + util; + } + if( restart ) f_input += " RESTART=YES"; + if( !restart ) f_input += " RESTART=NO"; + plumed.readInputLine( f_input ); +} + +const std::string & ActionShortcut::getShortcutLabel() const { + return shortcutlabel; +} + +} diff --git a/src/core/ActionShortcut.h b/src/core/ActionShortcut.h new file mode 100644 index 0000000000000000000000000000000000000000..741d899a140573f68989265dd89fc2f2081ea0c9 --- /dev/null +++ b/src/core/ActionShortcut.h @@ -0,0 +1,53 @@ +/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Copyright (c) 2011-2018 The plumed team + (see the PEOPLE file at the root of the distribution for a list of names) + + See http://www.plumed.org for more information. + + This file is part of plumed, version 2. + + plumed is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + plumed is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with plumed. If not, see <http://www.gnu.org/licenses/>. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ +#ifndef __PLUMED_core_ActionShortcut_h +#define __PLUMED_core_ActionShortcut_h + +#include "Action.h" + +namespace PLMD { + +/** +\ingroup MULTIINHERIT +Action used to create a command that expands to multiple PLMD::Action commands when read in during input +*/ +class ActionShortcut : + public virtual Action { +private: + std::string shortcutlabel; +protected: + const std::string & getShortcutLabel() const ; +public: + static void registerKeywords( Keywords& keys ); +/// Constructor + explicit ActionShortcut(const ActionOptions&ao); +/// Read a line of input and create appropriate actions + void readInputLine( const std::string& input ); +/// Do nothing. + void calculate() {} +/// Do nothing. + void apply() {} +}; + +} + +#endif