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 \ref driver 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 : \par 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 : \plumedfile 52 : phi: TORSION ATOMS=5,7,9,15 53 : psi: TORSION ATOMS=7,9,15,17 54 : 55 : bf1: BF_FOURIER ORDER=5 MINIMUM=-pi MAXIMUM=pi 56 : bf2: BF_FOURIER ORDER=5 MINIMUM=-pi MAXIMUM=pi 57 : 58 : VES_LINEAR_EXPANSION ... 59 : ARG=phi,psi 60 : BASIS_FUNCTIONS=bf1,bf2 61 : LABEL=ves1 62 : GRID_BINS=100,100 63 : PROJ_ARG1=phi 64 : PROJ_ARG2=psi 65 : ... VES_LINEAR_EXPANSION 66 : 67 : VES_OUTPUT_FES ... 68 : BIAS=ves1 69 : FES_OUTPUT=500 70 : FES_PROJ_OUTPUT=500 71 : BIAS_OUTPUT=500 72 : COEFFS_INPUT=coeffs.input.data 73 : ... VES_OUTPUT_FES 74 : \endplumedfile 75 : 76 : The header of coeffs.input.data should look like the following: 77 : 78 : \auxfile{coeffs.input.data} 79 : #! FIELDS idx_phi idx_psi ves1.coeffs ves1.aux_coeffs index 80 : #! SET time 100.000000 81 : #! SET iteration 10 82 : #! SET type LinearBasisSet 83 : #! SET ndimensions 2 84 : #! SET ncoeffs_total 121 85 : #! SET shape_phi 11 86 : #! SET shape_psi 11 87 : \endauxfile 88 : 89 : This input should be run through the driver by using a command similar to the 90 : following one where the trajectory/configuration file configuration.gro is needed to 91 : correctly define the CVs 92 : \verbatim 93 : plumed driver --plumed plumed.dat --igro configuration.gro 94 : \endverbatim 95 : 96 : */ 97 : //+ENDPLUMEDOC 98 : 99 : class OutputFesBias : public Action { 100 : 101 : public: 102 : static void registerKeywords(Keywords&); 103 : explicit OutputFesBias(const ActionOptions&); 104 0 : void update() override {} 105 0 : void calculate() override {} 106 0 : void apply() override {} 107 : }; 108 : 109 : 110 : PLUMED_REGISTER_ACTION(OutputFesBias,"VES_OUTPUT_FES") 111 : 112 : 113 5 : void OutputFesBias::registerKeywords(Keywords& keys) { 114 5 : keys.add("compulsory","BIAS","the label of the VES bias for to output the free energy surfaces and the bias files"); 115 5 : keys.add("compulsory","COEFFS_INPUT","the name of input coefficient file"); 116 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."); 117 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."); 118 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."); 119 : // 120 5 : } 121 : 122 : 123 3 : OutputFesBias::OutputFesBias(const ActionOptions&ao): 124 3 : Action(ao) { 125 : 126 : std::vector<std::string> bias_labels; 127 6 : parseVector("BIAS",bias_labels); 128 3 : if(bias_labels.size()>1) { 129 0 : plumed_merror(getName()+" only support one VES bias"); 130 : } 131 : 132 3 : std::string error_msg = ""; 133 3 : std::vector<VesBias*> bias_pntrs = VesTools::getPointersFromLabels<VesBias*>(bias_labels,plumed.getActionSet(),error_msg); 134 3 : if(error_msg.size()>0) { 135 0 : plumed_merror("Error in keyword BIAS of "+getName()+": "+error_msg); 136 : } 137 : 138 6 : for(unsigned int i=0; i<bias_pntrs.size(); i++) { 139 3 : if(bias_pntrs[i]->numberOfCoeffsSets()>1) { 140 0 : plumed_merror(getName()+" at the moment supports only VES biases with a single coefficient set"); 141 : } 142 : } 143 : 144 : std::vector<std::string> coeffs_fnames; 145 6 : parseVector("COEFFS_INPUT",coeffs_fnames); 146 3 : if(coeffs_fnames.size()!=bias_pntrs.size()) { 147 0 : plumed_merror(getName()+": there have to be as many coefficient file given in COEFFS_INPUT as VES biases given in BIAS"); 148 : } 149 : 150 3 : unsigned int bias_output_stride = 0; 151 3 : parse("BIAS_OUTPUT",bias_output_stride); 152 : 153 3 : unsigned int fes_output_stride = 0; 154 3 : parse("FES_OUTPUT",fes_output_stride); 155 : 156 3 : unsigned int fesproj_output_stride = 0; 157 3 : parse("FES_PROJ_OUTPUT",fesproj_output_stride); 158 : 159 3 : if(bias_output_stride == 0 && fes_output_stride == 0 && fesproj_output_stride == 0) { 160 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"); 161 : } 162 : 163 3 : checkRead(); 164 : 165 6 : for(unsigned int i=0; i<bias_pntrs.size(); i++) { 166 : 167 3 : if(bias_pntrs[i]->dynamicTargetDistribution()) { 168 0 : plumed_merror(getName()+" does not support dynamic target distributions at the moment"); 169 : } 170 : 171 3 : if(bias_pntrs[i]->isStaticTargetDistFileOutputActive()) { 172 2 : bias_pntrs[i]->setupTargetDistFileOutput(); 173 2 : bias_pntrs[i]->writeTargetDistToFile(); 174 2 : bias_pntrs[i]->setupTargetDistProjFileOutput(); 175 2 : bias_pntrs[i]->writeTargetDistProjToFile(); 176 : } 177 : 178 : 179 3 : if(bias_output_stride>0) { 180 3 : bias_pntrs[i]->enableBiasFileOutput(); 181 3 : bias_pntrs[i]->setupBiasFileOutput(); 182 : } 183 : 184 3 : if(fes_output_stride>0) { 185 3 : bias_pntrs[i]->enableFesFileOutput(); 186 3 : bias_pntrs[i]->setupFesFileOutput(); 187 : } 188 : 189 3 : if(fesproj_output_stride>0) { 190 1 : bias_pntrs[i]->enableFesProjFileOutput(); 191 1 : bias_pntrs[i]->setupFesProjFileOutput(); 192 : } 193 : 194 3 : bias_pntrs[i]->enableIterationNumberInFilenames(); 195 : 196 3 : IFile ifile; 197 3 : ifile.open(coeffs_fnames[i]); 198 : 199 39 : while(ifile) { 200 : 201 36 : bias_pntrs[i]->resetBiasFileOutput(); 202 36 : bias_pntrs[i]->resetFesFileOutput(); 203 : 204 72 : if(bias_pntrs[i]->getCoeffsPntrs()[0]->readOneSetFromFile(ifile)>0) { 205 33 : unsigned int iteration = bias_pntrs[i]->getCoeffsPntrs()[0]->getIterationCounter(); 206 : 207 33 : if(bias_output_stride>0 && iteration%bias_output_stride==0) { 208 8 : bias_pntrs[i]->writeBiasToFile(); 209 : } 210 : 211 33 : if(fes_output_stride>0 && iteration%fes_output_stride==0) { 212 8 : bias_pntrs[i]->writeFesToFile(); 213 : } 214 : 215 33 : if(fesproj_output_stride>0 && iteration%fesproj_output_stride==0) { 216 3 : bias_pntrs[i]->writeFesProjToFile(); 217 : } 218 : 219 : } 220 : 221 : } 222 : 223 3 : } 224 : 225 3 : log.printf("Stopping"); 226 3 : plumed.stop(); 227 6 : } 228 : 229 : 230 : } 231 : }