diff --git a/regtest/analysis/rt-wham/fes.dat.reference b/regtest/analysis/rt-wham/fes.0.dat.reference similarity index 100% rename from regtest/analysis/rt-wham/fes.dat.reference rename to regtest/analysis/rt-wham/fes.0.dat.reference diff --git a/regtest/analysis/rt-wham/plumed.dat b/regtest/analysis/rt-wham/plumed.dat index e5e86194885999ad2fdc61696c7cde924b831b65..e189bc5ad7c0e1d5b3f2d3c738a15e87191f2009 100644 --- a/regtest/analysis/rt-wham/plumed.dat +++ b/regtest/analysis/rt-wham/plumed.dat @@ -46,7 +46,9 @@ REWEIGHT_WHAM ... PRINT ARG=phi,psi FILE=colvar #PRINT ARG=rp0.bias,rp1.bias,rp2.bias,rp3.bias,rp4.bias,rp5.bias,rp6.bias,rp7.bias,rp8.bias,rp9.bias,rp10.bias,rp11.bias,rp12.bias,rp13.bias,rp14.bias,rp15.bias,rp16.bias,rp17.bias,rp18.bias,rp19.bias,rp20.bias,rp21.bias,rp22.bias,rp23.bias,rp24.bias,rp25.bias,rp26.bias,rp27.bias,rp28.bias,rp29.bias,rp30.bias,rp31.bias FILE=bias +weig: COLLECT_FRAMES STRIDE=1 LOGWEIGHTS=ww ff: COLLECT_FRAMES ARG=phi STRIDE=1 LOGWEIGHTS=ww +OUTPUT_ANALYSIS_DATA_TO_COLVAR USE_OUTPUT_DATA_FROM=weig FILE=wham-weights FMT=%8.4f hh: HISTOGRAM ARG=ff.phi GRID_MIN=-pi GRID_MAX=pi GRID_BIN=50 KERNEL=DISCRETE fes: CONVERT_TO_FES GRID=hh TEMP=300 diff --git a/regtest/analysis/rt-wham/wham-weights.0.reference b/regtest/analysis/rt-wham/wham-weights.0.reference new file mode 100644 index 0000000000000000000000000000000000000000..1ce4fb58925b425667be972a061c650ed2ac6fb9 --- /dev/null +++ b/regtest/analysis/rt-wham/wham-weights.0.reference @@ -0,0 +1,352 @@ +#! FIELDS weight + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0002 + 0.0021 + 0.0003 + 0.0000 + 0.0018 + 0.0001 + 0.0006 + 0.0002 + 0.0021 + 0.0000 + 0.0000 + 0.0000 + 0.0005 + 0.0000 + 0.0091 + 0.0005 + 0.0001 + 0.0015 + 0.0119 + 0.0012 + 0.0006 + 0.0301 + 0.0108 + 0.0136 + 0.0158 + 0.0040 + 0.0130 + 0.0199 + 0.0139 + 0.0250 + 0.0113 + 0.0276 + 0.0000 + 0.0187 + 0.0153 + 0.0114 + 0.0116 + 0.0082 + 0.0270 + 0.0262 + 0.0228 + 0.0285 + 0.0299 + 0.0301 + 0.0017 + 0.0122 + 0.0272 + 0.0283 + 0.0021 + 0.0015 + 0.0164 + 0.0024 + 0.0054 + 0.0052 + 0.0000 + 0.0001 + 0.0001 + 0.0004 + 0.0008 + 0.0001 + 0.0114 + 0.0002 + 0.0040 + 0.0044 + 0.0004 + 0.0301 + 0.0000 + 0.0001 + 0.0024 + 0.0000 + 0.0005 + 0.0003 + 0.0000 + 0.0006 + 0.0000 + 0.0004 + 0.0000 + 0.0000 + 0.0002 + 0.0001 + 0.0000 + 0.0000 + 0.0000 + 0.0013 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0301 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 + 0.0000 diff --git a/src/analysis/OutputColvarFile.cpp b/src/analysis/OutputColvarFile.cpp index c88b01b594538d773b96a5c82a780320c6f023ed..6b951aba784edbd802e31140480895916061fe6c 100644 --- a/src/analysis/OutputColvarFile.cpp +++ b/src/analysis/OutputColvarFile.cpp @@ -47,6 +47,8 @@ class OutputColvarFile : public AnalysisBase { private: std::string fmt; std::string filename; + bool output_for_all_replicas; + std::vector<unsigned> preps; std::vector<std::string> req_vals; public: static void registerKeywords( Keywords& keys ); @@ -60,6 +62,7 @@ PLUMED_REGISTER_ACTION(OutputColvarFile,"OUTPUT_ANALYSIS_DATA_TO_COLVAR") void OutputColvarFile::registerKeywords( Keywords& keys ) { AnalysisBase::registerKeywords( keys ); keys.use("ARG"); keys.add("compulsory","FILE","the name of the file to output to"); + keys.add("compulsory","REPLICA","0","the replicas for which you would like to output this information"); keys.add("compulsory","STRIDE","0","the frequency with which to perform the required analysis and to output the data. The default value of 0 tells plumed to use all the data"); keys.add("optional","FMT","the format to output the data using"); } @@ -67,7 +70,8 @@ void OutputColvarFile::registerKeywords( Keywords& keys ) { OutputColvarFile::OutputColvarFile( const ActionOptions& ao ): Action(ao), AnalysisBase(ao), - fmt("%f") + fmt("%f"), + output_for_all_replicas(false) { parse("FILE",filename); parse("FMT",fmt); if( !getRestart() ) { OFile ofile; ofile.link(*this); ofile.setBackupString("analysis"); ofile.backupAllFiles(filename); } @@ -78,13 +82,33 @@ OutputColvarFile::OutputColvarFile( const ActionOptions& ao ): } else { req_vals.resize( getArguments().size() ); for(unsigned i=0; i<req_vals.size(); ++i) req_vals[i]=getPntrToArgument(i)->getName(); } - plumed_assert( req_vals.size()>0 ); - log.printf(" outputting %s", req_vals[0].c_str() ); - for(unsigned i=1; i<req_vals.size(); ++i) log.printf(",", req_vals[i].c_str() ); - log.printf("\n"); + if( req_vals.size()==0 ) { + log.printf(" outputting weights from input action \n"); + } else { + log.printf(" outputting %s", req_vals[0].c_str() ); + for(unsigned i=1; i<req_vals.size(); ++i) log.printf(",", req_vals[i].c_str() ); + log.printf("\n"); + } + std::vector<std::string> rep_data; parseVector("REPLICA",rep_data); + if( rep_data.size()==1 ) { + if( rep_data[0]=="all" ) output_for_all_replicas=true; + else { + preps.resize(1); Tools::convert( rep_data[0], preps[0] ); + } + } else { + preps.resize( rep_data.size() ); + for(unsigned i=0;i<rep_data.size();++i) Tools::convert( rep_data[i], preps[i] ); + } } void OutputColvarFile::performAnalysis() { + if( !output_for_all_replicas ) { + bool found=false; unsigned myrep=plumed.multi_sim_comm.Get_rank(); + for(unsigned i=0;i<preps.size();++i) { + if( myrep==preps[i] ) { found=true; break; } + } + if( !found ) return; + } // Output the embedding as long lists of data OFile gfile; gfile.link(*this); gfile.setBackupString("analysis"); diff --git a/src/analysis/ReadAnalysisFrames.cpp b/src/analysis/ReadAnalysisFrames.cpp index 54f9c0b7dfb35099f98b472d77ef59373cf3e602..478abdab9a7e6b0785b4f92bda65118ac0736e55 100644 --- a/src/analysis/ReadAnalysisFrames.cpp +++ b/src/analysis/ReadAnalysisFrames.cpp @@ -80,7 +80,8 @@ ReadAnalysisFrames::ReadAnalysisFrames( const ActionOptions& ao ): } if( wwstr.size()>0 ) { log.printf("\n"); - wham_pointer = dynamic_cast<bias::ReweightWham*>( weight_vals[0]->getPntrToAction() ); + wham_pointer = dynamic_cast<bias::ReweightBase*>( weight_vals[0]->getPntrToAction() ); + if( !wham_pointer->buildsWeightStore() ) wham_pointer = NULL; if( wham_pointer && weight_vals.size()!=1 ) error("can only extract weights from one wham object"); } else log.printf(" weights are all equal to one\n"); requestArguments( arg ); diff --git a/src/analysis/ReadAnalysisFrames.h b/src/analysis/ReadAnalysisFrames.h index 1248669dd13109bb1b973eb445f5affb14654c0e..8e8f7618cbbd43fbb36cdeabde21fa1b8a202402 100644 --- a/src/analysis/ReadAnalysisFrames.h +++ b/src/analysis/ReadAnalysisFrames.h @@ -23,7 +23,7 @@ #define __PLUMED_analysis_ReadAnalysisFrames_h #include "AnalysisBase.h" -#include "bias/ReweightWham.h" +#include "bias/ReweightBase.h" namespace PLMD { namespace analysis { @@ -40,7 +40,7 @@ private: /// The biases we are using in reweighting and the args we store them separately std::vector<Value*> weight_vals; /// The object that calculates weights using WHAM - bias::ReweightWham* wham_pointer; + bias::ReweightBase* wham_pointer; /// The weights of all the data points bool weights_calculated; std::vector<double> logweights, weights; diff --git a/src/bias/ReweightBase.h b/src/bias/ReweightBase.h index 099e317a0f5191492274ed263882b62fe89aa6f4..4ef2e6c0008cf6e043de79dd08d85638e300d0b6 100644 --- a/src/bias/ReweightBase.h +++ b/src/bias/ReweightBase.h @@ -39,8 +39,12 @@ public: static void registerKeywords(Keywords&); explicit ReweightBase(const ActionOptions&ao); unsigned getNumberOfDerivatives() { return 0; } + virtual bool buildsWeightStore() const { return false; } void calculate(); + virtual void calculateWeights( const unsigned& nframes ){} virtual double getLogWeight() = 0; + virtual double getWeight( const unsigned& iweight ) const { plumed_error(); } + virtual void clearData() {} void apply() {} }; diff --git a/src/bias/ReweightWham.cpp b/src/bias/ReweightWham.cpp index 7a049fc91d0c2ecf32ab0fa83379e56ac48fed8d..f30a486c50eabcc67921cfb8e86e7d739173211c 100644 --- a/src/bias/ReweightWham.cpp +++ b/src/bias/ReweightWham.cpp @@ -19,7 +19,7 @@ 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 "ReweightWham.h" +#include "ReweightBase.h" #include "core/ActionRegister.h" #include "tools/Communicator.h" @@ -34,6 +34,24 @@ namespace PLMD { namespace bias { +class ReweightWham : public ReweightBase { +private: + double thresh; + unsigned nreplicas; + unsigned maxiter; + bool weightsCalculated; + std::vector<double> stored_biases; + std::vector<double> final_weights; +public: + static void registerKeywords(Keywords&); + explicit ReweightWham(const ActionOptions&ao); + bool buildsWeightStore() const { return true; } + void calculateWeights( const unsigned& nframes ); + void clearData(); + double getLogWeight(); + double getWeight( const unsigned& iweight ) const ; +}; + PLUMED_REGISTER_ACTION(ReweightWham,"REWEIGHT_WHAM") void ReweightWham::registerKeywords(Keywords& keys ) { @@ -69,6 +87,11 @@ void ReweightWham::clearData() { stored_biases.resize(0); } +double ReweightWham::getWeight( const unsigned& iweight ) const { + plumed_dbg_assert( weightsCalculated && iweight<final_weights.size() ); + return final_weights[iweight]; +} + void ReweightWham::calculateWeights( const unsigned& nframes ) { if( stored_biases.size()!=nreplicas*nframes ) error("wrong number of weights stored"); // Get the minimum value of the bias diff --git a/src/bias/ReweightWham.h b/src/bias/ReweightWham.h deleted file mode 100644 index a64ce787daec240e1b7bbfcdf3c4ac01ba0cdecd..0000000000000000000000000000000000000000 --- a/src/bias/ReweightWham.h +++ /dev/null @@ -1,55 +0,0 @@ -/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - Copyright (c) 2011-2016 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_bias_ReweightWham_h -#define __PLUMED_bias_ReweightWham_h - -#include "ReweightBase.h" - -namespace PLMD { -namespace bias { - -class ReweightWham : public ReweightBase { -private: - double thresh; - unsigned nreplicas; - unsigned maxiter; - bool weightsCalculated; - std::vector<double> stored_biases; - std::vector<double> final_weights; -public: - static void registerKeywords(Keywords&); - explicit ReweightWham(const ActionOptions&ao); - void calculateWeights( const unsigned& nframes ); - void clearData(); - double getLogWeight(); - double getWeight( const unsigned& iweight ) const ; -}; - -inline -double ReweightWham::getWeight( const unsigned& iweight ) const { - plumed_dbg_assert( weightsCalculated && iweight<final_weights.size() ); - return final_weights[iweight]; -} - -} -} -#endif diff --git a/src/gridtools/GridPrintingBase.cpp b/src/gridtools/GridPrintingBase.cpp index 89e55eb2b6db76238b0b7f1fe317fa831ddfd69c..bbccb1ff395c260f8e24a28b62162823b07a2103 100644 --- a/src/gridtools/GridPrintingBase.cpp +++ b/src/gridtools/GridPrintingBase.cpp @@ -33,13 +33,15 @@ void GridPrintingBase::registerKeywords( Keywords& keys ) { keys.add("compulsory","STRIDE","0","the frequency with which the grid should be output to the file. The default " "value of 0 ensures that the grid is only output at the end of the trajectory"); keys.add("compulsory","FILE","density","the file on which to write the grid."); + keys.add("compulsory","REPLICA","0","the replicas for which you would like to output this information"); keys.add("optional","FMT","the format that should be used to output real numbers"); } GridPrintingBase::GridPrintingBase(const ActionOptions&ao): Action(ao), ActionPilot(ao), - fmt("%f") + fmt("%f"), + output_for_all_replicas(false) { std::string mlab; parse("GRID",mlab); vesselbase::ActionWithVessel* mves= plumed.getActionSet().selectWithLabel<vesselbase::ActionWithVessel*>(mlab); @@ -60,9 +62,26 @@ GridPrintingBase::GridPrintingBase(const ActionOptions&ao): } else { log.printf("\n"); } + std::vector<std::string> rep_data; parseVector("REPLICA",rep_data); + if( rep_data.size()==1 ) { + if( rep_data[0]=="all" ) output_for_all_replicas=true; + else { + preps.resize(1); Tools::convert( rep_data[0], preps[0] ); + } + } else { + preps.resize( rep_data.size() ); + for(unsigned i=0;i<rep_data.size();++i) Tools::convert( rep_data[i], preps[i] ); + } } void GridPrintingBase::update() { + if( !output_for_all_replicas ) { + bool found=false; unsigned myrep=plumed.multi_sim_comm.Get_rank(); + for(unsigned i=0;i<preps.size();++i) { + if( myrep==preps[i] ) { found=true; break; } + } + if( !found ) return; + } if( getStep()==0 || getStride()==0 ) return ; OFile ofile; ofile.link(*this); @@ -71,6 +90,13 @@ void GridPrintingBase::update() { } void GridPrintingBase::runFinalJobs() { + if( !output_for_all_replicas ) { + bool found=false; unsigned myrep=plumed.multi_sim_comm.Get_rank(); + for(unsigned i=0;i<preps.size();++i) { + if( myrep==preps[i] ) { found=true; break; } + } + if( !found ) return; + } if( getStride()>0 ) return; OFile ofile; ofile.link(*this); diff --git a/src/gridtools/GridPrintingBase.h b/src/gridtools/GridPrintingBase.h index 2b97194c44840ec4b0f5814bc7c5608d781223db..1e9ac6c6106ea8d29090cd9e263f1d8bafcbdb2d 100644 --- a/src/gridtools/GridPrintingBase.h +++ b/src/gridtools/GridPrintingBase.h @@ -33,6 +33,8 @@ class GridPrintingBase : public ActionPilot { protected: GridVessel* ingrid; std::string fmt, filename; + bool output_for_all_replicas; + std::vector<unsigned> preps; public: static void registerKeywords( Keywords& keys ); explicit GridPrintingBase(const ActionOptions&ao); diff --git a/src/vesselbase/ActionWithAveraging.cpp b/src/vesselbase/ActionWithAveraging.cpp index 9d3816e0a24356ce505c4da70cd0798e7080741e..79ad58b18d8024f03c2df7ad34a623f5094ee5cb 100644 --- a/src/vesselbase/ActionWithAveraging.cpp +++ b/src/vesselbase/ActionWithAveraging.cpp @@ -24,7 +24,7 @@ #include "analysis/ReadAnalysisFrames.h" #include "core/PlumedMain.h" #include "core/ActionSet.h" -#include "bias/ReweightWham.h" +#include "bias/ReweightBase.h" namespace PLMD { namespace vesselbase { @@ -81,8 +81,8 @@ ActionWithAveraging::ActionWithAveraging( const ActionOptions& ao ): for(unsigned i=0; i<wwstr.size(); ++i) { ActionWithValue* val = plumed.getActionSet().selectWithLabel<ActionWithValue*>(wwstr[i]); if( !val ) error("could not find value named"); - bias::ReweightWham* iswham=dynamic_cast<bias::ReweightWham*>( val ); - if( iswham ) error("to use wham you must gather data using COLLECT_FRAMES"); + bias::ReweightBase* iswham=dynamic_cast<bias::ReweightBase*>( val ); + if( iswham->buildsWeightStore() ) error("to use wham you must gather data using COLLECT_FRAMES"); weights.push_back( val->copyOutput(val->getLabel()) ); arg.push_back( val->copyOutput(val->getLabel()) ); log.printf("%s ",wwstr[i].c_str() );