Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-2021 The VES code team 3 : (see the PEOPLE-VES file at the root of this folder for a list of names) 4 : 5 : See http://www.ves-code.org for more information. 6 : 7 : This file is part of VES code module. 8 : 9 : The VES code module is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : The VES code module is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with the VES code module. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : 23 : #include "CoeffsVector.h" 24 : #include "VesTools.h" 25 : #include "VesBias.h" 26 : 27 : 28 : #include "tools/File.h" 29 : #include "core/ActionRegister.h" 30 : #include "core/PlumedMain.h" 31 : 32 : 33 : namespace PLMD { 34 : namespace ves { 35 : 36 : //+PLUMEDOC VES_UTILS VES_OUTPUT_FES 37 : /* 38 : Tool to output biases and free energy surfaces for VES biases from previously obtained coefficients. 39 : 40 : This action can be used to output to file biases and free energy surfaces for VES biases from 41 : previously obtained coefficients. It should be used through the [driver](driver.md) and 42 : can only be used in post processing. The VES bias needs to be defined in the 43 : exact same way as during the simulation. At the current moment this action does 44 : not support dynamic target distributions (e.g. well-tempered). 45 : 46 : ## Examples 47 : 48 : In the following input we define a VES bias and then read in the coefficient 49 : file coeffs.input.data and output the FES and bias every 500 iterations. 50 : 51 : ```plumed 52 : #SETTINGS INPUTFILES=regtest/ves/rt-output-fes-2d-targetdist/coeffs.input.data INPUTFILELINES=1-14 53 : phi: TORSION ATOMS=5,7,9,15 54 : psi: TORSION ATOMS=7,9,15,17 55 : 56 : bf1: BF_FOURIER ORDER=5 MINIMUM=-pi MAXIMUM=pi 57 : bf2: BF_FOURIER ORDER=5 MINIMUM=-pi MAXIMUM=pi 58 : 59 : VES_LINEAR_EXPANSION ... 60 : ARG=phi,psi 61 : BASIS_FUNCTIONS=bf1,bf2 62 : LABEL=ves1 63 : GRID_BINS=100,100 64 : PROJ_ARG1=phi 65 : PROJ_ARG2=psi 66 : ... VES_LINEAR_EXPANSION 67 : 68 : VES_OUTPUT_FES ... 69 : BIAS=ves1 70 : FES_OUTPUT=500 71 : FES_PROJ_OUTPUT=500 72 : BIAS_OUTPUT=500 73 : COEFFS_INPUT=regtest/ves/rt-output-fes-2d-targetdist/coeffs.input.data 74 : ... VES_OUTPUT_FES 75 : ``` 76 : 77 : This input should be run through the driver by using a command similar to the 78 : following one where the trajectory/configuration file configuration.gro is needed to 79 : correctly define the CVs 80 : 81 : ```plumed 82 : plumed driver --plumed plumed.dat --igro configuration.gro 83 : ``` 84 : 85 : */ 86 : //+ENDPLUMEDOC 87 : 88 : class OutputFesBias : public Action { 89 : 90 : public: 91 : static void registerKeywords(Keywords&); 92 : explicit OutputFesBias(const ActionOptions&); 93 0 : void update() override {} 94 0 : void calculate() override {} 95 0 : void apply() override {} 96 : }; 97 : 98 : 99 : PLUMED_REGISTER_ACTION(OutputFesBias,"VES_OUTPUT_FES") 100 : 101 : 102 5 : void OutputFesBias::registerKeywords(Keywords& keys) { 103 5 : keys.add("compulsory","BIAS","the label of the VES bias for to output the free energy surfaces and the bias files"); 104 5 : keys.add("compulsory","COEFFS_INPUT","the name of input coefficient file"); 105 5 : keys.add("optional","BIAS_OUTPUT","how often the bias(es) should be written out to file. Note that the value is given in terms of coefficient iterations."); 106 5 : keys.add("optional","FES_OUTPUT","how often the FES(s) should be written out to file. Note that the value is given in terms of coefficient iterations."); 107 5 : keys.add("optional","FES_PROJ_OUTPUT","how often the projections of the FES(s) should be written out to file. Note that the value is given in terms of coefficient iterations."); 108 : // 109 5 : } 110 : 111 : 112 3 : OutputFesBias::OutputFesBias(const ActionOptions&ao): 113 3 : Action(ao) { 114 : 115 : std::vector<std::string> bias_labels; 116 6 : parseVector("BIAS",bias_labels); 117 3 : if(bias_labels.size()>1) { 118 0 : plumed_merror(getName()+" only support one VES bias"); 119 : } 120 : 121 3 : std::string error_msg = ""; 122 3 : std::vector<VesBias*> bias_pntrs = VesTools::getPointersFromLabels<VesBias*>(bias_labels,plumed.getActionSet(),error_msg); 123 3 : if(error_msg.size()>0) { 124 0 : plumed_merror("Error in keyword BIAS of "+getName()+": "+error_msg); 125 : } 126 : 127 6 : for(unsigned int i=0; i<bias_pntrs.size(); i++) { 128 3 : if(bias_pntrs[i]->numberOfCoeffsSets()>1) { 129 0 : plumed_merror(getName()+" at the moment supports only VES biases with a single coefficient set"); 130 : } 131 : } 132 : 133 : std::vector<std::string> coeffs_fnames; 134 6 : parseVector("COEFFS_INPUT",coeffs_fnames); 135 3 : if(coeffs_fnames.size()!=bias_pntrs.size()) { 136 0 : plumed_merror(getName()+": there have to be as many coefficient file given in COEFFS_INPUT as VES biases given in BIAS"); 137 : } 138 : 139 3 : unsigned int bias_output_stride = 0; 140 3 : parse("BIAS_OUTPUT",bias_output_stride); 141 : 142 3 : unsigned int fes_output_stride = 0; 143 3 : parse("FES_OUTPUT",fes_output_stride); 144 : 145 3 : unsigned int fesproj_output_stride = 0; 146 3 : parse("FES_PROJ_OUTPUT",fesproj_output_stride); 147 : 148 3 : if(bias_output_stride == 0 && fes_output_stride == 0 && fesproj_output_stride == 0) { 149 0 : plumed_merror(getName()+": you are not telling the action to do anything, you need to use one of the keywords BIAS_OUTPUT, FES_OUTPUT, or FES_PROJ_OUTPUT"); 150 : } 151 : 152 3 : checkRead(); 153 : 154 6 : for(unsigned int i=0; i<bias_pntrs.size(); i++) { 155 : 156 3 : if(bias_pntrs[i]->dynamicTargetDistribution()) { 157 0 : plumed_merror(getName()+" does not support dynamic target distributions at the moment"); 158 : } 159 : 160 3 : if(bias_pntrs[i]->isStaticTargetDistFileOutputActive()) { 161 2 : bias_pntrs[i]->setupTargetDistFileOutput(); 162 2 : bias_pntrs[i]->writeTargetDistToFile(); 163 2 : bias_pntrs[i]->setupTargetDistProjFileOutput(); 164 2 : bias_pntrs[i]->writeTargetDistProjToFile(); 165 : } 166 : 167 : 168 3 : if(bias_output_stride>0) { 169 3 : bias_pntrs[i]->enableBiasFileOutput(); 170 3 : bias_pntrs[i]->setupBiasFileOutput(); 171 : } 172 : 173 3 : if(fes_output_stride>0) { 174 3 : bias_pntrs[i]->enableFesFileOutput(); 175 3 : bias_pntrs[i]->setupFesFileOutput(); 176 : } 177 : 178 3 : if(fesproj_output_stride>0) { 179 1 : bias_pntrs[i]->enableFesProjFileOutput(); 180 1 : bias_pntrs[i]->setupFesProjFileOutput(); 181 : } 182 : 183 3 : bias_pntrs[i]->enableIterationNumberInFilenames(); 184 : 185 3 : IFile ifile; 186 3 : ifile.open(coeffs_fnames[i]); 187 : 188 39 : while(ifile) { 189 : 190 36 : bias_pntrs[i]->resetBiasFileOutput(); 191 36 : bias_pntrs[i]->resetFesFileOutput(); 192 : 193 72 : if(bias_pntrs[i]->getCoeffsPntrs()[0]->readOneSetFromFile(ifile)>0) { 194 33 : unsigned int iteration = bias_pntrs[i]->getCoeffsPntrs()[0]->getIterationCounter(); 195 : 196 33 : if(bias_output_stride>0 && iteration%bias_output_stride==0) { 197 8 : bias_pntrs[i]->writeBiasToFile(); 198 : } 199 : 200 33 : if(fes_output_stride>0 && iteration%fes_output_stride==0) { 201 8 : bias_pntrs[i]->writeFesToFile(); 202 : } 203 : 204 33 : if(fesproj_output_stride>0 && iteration%fesproj_output_stride==0) { 205 3 : bias_pntrs[i]->writeFesProjToFile(); 206 : } 207 : 208 : } 209 : 210 : } 211 : 212 3 : } 213 : 214 3 : log.printf("Stopping"); 215 3 : plumed.stop(); 216 6 : } 217 : 218 : 219 : } 220 : }