LCOV - code coverage report
Current view: top level - ves - VesLinearExpansion.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 141 145 97.2 %
Date: 2020-11-18 11:20:57 Functions: 22 25 88.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-2018 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 "VesBias.h"
      24             : #include "LinearBasisSetExpansion.h"
      25             : #include "CoeffsVector.h"
      26             : #include "CoeffsMatrix.h"
      27             : #include "BasisFunctions.h"
      28             : #include "Optimizer.h"
      29             : #include "TargetDistribution.h"
      30             : #include "VesTools.h"
      31             : 
      32             : #include "bias/Bias.h"
      33             : #include "core/ActionRegister.h"
      34             : #include "core/ActionSet.h"
      35             : #include "core/PlumedMain.h"
      36             : 
      37             : 
      38             : namespace PLMD {
      39             : namespace ves {
      40             : 
      41             : //+PLUMEDOC VES_BIAS VES_LINEAR_EXPANSION
      42             : /*
      43             : Linear basis set expansion bias.
      44             : 
      45             : This VES bias action takes the bias potential to be a linear expansion
      46             : in some basis set that is written as a product of one-dimensional basis functions.
      47             : For example, for one CV the bias would be written as
      48             : \f[
      49             : V(s_{1};\boldsymbol{\alpha}) = \sum_{i_{1}} \alpha_{i_{1}} \, f_{i_{1}}(s_{1}),
      50             : \f]
      51             : while for two CVs it is written as
      52             : \f[
      53             : V(s_{1},s_{2};\boldsymbol{\alpha}) = \sum_{i_{1},i_{2}} \alpha_{i_{1},i_{2}} \, f_{i_{1}}(s_{1}) \, f_{i_{2}}(s_{2})
      54             : \f]
      55             : where \f$\boldsymbol{\alpha}\f$ is the set of expansion coefficients that
      56             : are optimized within VES. With an appropriate choice of the basis functions
      57             : it is possible to represent any generic free energy surface.
      58             : The relationship between the bias and the free energy surface is given by
      59             : \f[
      60             : V(\mathbf{s}) = - F(\mathbf{s}) - \frac{1}{\beta} \log p(\mathbf{s}).
      61             : \f]
      62             : where \f$p(\mathbf{s})\f$ is the target distribution that is employed in the VES simulation.
      63             : 
      64             : \par Basis Functions
      65             : 
      66             : Various one-dimensional basis functions are available in the VES code,
      67             : see the complete list \ref ves_basisf "here".
      68             : At the current moment we recommend to use Legendre polynomials (\ref BF_LEGENDRE)
      69             : for non-periodic CVs and Fourier basis functions (\ref BF_FOURIER)
      70             : for periodic CV (e.g. dihedral angles).
      71             : 
      72             : To use basis functions within VES_LINEAR_EXPANSION you first need to
      73             : define them in the input file before the VES_LINEAR_EXPANSION action and
      74             : then give their labels using the BASIS_FUNCTIONS keyword.
      75             : 
      76             : 
      77             : \par Target Distributions
      78             : 
      79             : Various target distributions \f$p(\mathbf{s})\f$ are available in the VES code,
      80             : see the complete list \ref ves_targetdist "here".
      81             : 
      82             : To use a target distribution within VES_LINEAR_EXPANSION you first need to
      83             : define it in the input file before the VES_LINEAR_EXPANSION action and
      84             : then give its label using the TARGET_DISTRIBUTION keyword.
      85             : The default behavior if no TARGET_DISTRIBUTION is given is to
      86             : employ a uniform target distribution.
      87             : 
      88             : Some target distribution, like the well-tempered one (\ref TD_WELLTEMPERED),
      89             : are dynamic and need to be iteratively updated during the optimization.
      90             : 
      91             : \par Optimizer
      92             : 
      93             : In order to optimize the coefficients you will need to use VES_LINEAR_EXPANSION
      94             : in combination with an optimizer, see the list of optimizers available in the
      95             : VES code \ref ves_optimizer "here". At the current moment we recommend to
      96             : use the averaged stochastic gradient decent optimizer (\ref OPT_AVERAGED_SGD).
      97             : 
      98             : The optimizer should be defined after the VES_LINEAR_EXPANSION action.
      99             : 
     100             : \par Grid
     101             : 
     102             : Internally the code uses grids to calculate the basis set averages
     103             : over the target distribution that is needed for the gradient. The same grid is
     104             : also used for the output files (see next section).
     105             : The size of the grid is determined by the GRID_BINS keyword. By default it has
     106             : 100 grid points in each dimension, and generally this value should be sufficent.
     107             : 
     108             : \par Outputting Free Energy Surfaces and Other Files
     109             : 
     110             : It is possible to output on-the-fly during the simulation the free energy surface
     111             : estimated from the bias potential. How often this is done is specified within
     112             : the \ref ves_optimizer "optimizer" by using the FES_OUTPUT keyword. The filename
     113             : is specified by the FES_FILE keyword, but by default is it fes.LABEL.data,
     114             : with an added suffix indicating
     115             : the iteration number (iter-#).
     116             : 
     117             : For multi-dimensional case is it possible to also output projections of the
     118             : free energy surfaces. The arguments for which to do these projections is
     119             : specified using the numbered PROJ_ARG keywords. For these files a suffix
     120             : indicating the projection (proj-#) will be added to the filenames.
     121             : You will also need to specfiy the frequency of the output by using the
     122             : FES_PROJ_OUTPUT keyword within the optimizer.
     123             : 
     124             : It is also possible to output the bias potential itself, for this the relevant
     125             : keyword is BIAS_OUTPUT within the optimizer. The filename
     126             : is specified by the BIAS_FILE keyword, but by default is it bias.LABEL.data,
     127             : with an added suffix indicating the iteration number (iter-#).
     128             : 
     129             : Furthermore is it possible to output the target distribution, and its projections
     130             : (i.e. marginal distributions). The filenames of these files are specified with
     131             : the TARGETDIST_FILE, but by default is it targetdist.LABEL.data. The
     132             : logarithm of the target distribution will also be outputted to file that has the
     133             : added suffix log. For static target distribution these files will be outputted in
     134             : the beginning of the
     135             : simulation while for dynamic ones you will need to specify the frequency
     136             : of the output by using the TARGETDIST_OUTPUT and TARGETDIST_PROJ_OUTPUT
     137             : keywords within the optimizer.
     138             : 
     139             : It is also possible to output free energy surfaces and bias in postprocessing
     140             : by using the \ref VES_OUTPUT_FES action. However, be aware that this action
     141             : does does not support dynamic target distribution (e.g. well-tempered).
     142             : 
     143             : \par Static Bias
     144             : 
     145             : It is also possible to use VES_LINEAR_EXPANSION as a static bias that uses
     146             : previously obtained coefficents. In this case the coefficents should be
     147             : read in from the coefficent file given in the COEFFS keyword.
     148             : 
     149             : \par Bias Cutoff
     150             : 
     151             : It is possible to impose a cutoff on the bias potential using the procedure
     152             : introduced in \cite McCarty-PRL-2015 such that the free energy surface
     153             : is only flooded up to a certain value. The bias that results from this procedure
     154             : can then be used as a static bias for obtaining kinetic rates.
     155             : The value of the cutoff is given by the BIAS_CUTOFF keyword.
     156             : To impose the cutoff the code uses a Fermi switching function \f$1/(1+e^{\lambda x})\f$
     157             : where the parameter \f$\lambda\f$ controls how sharply the switchingfunction goes to zero.
     158             : The default value is \f$\lambda=10\f$ but this can be changed by using the
     159             : BIAS_CUTOFF_FERMI_LAMBDA keyword.
     160             : 
     161             : \par Examples
     162             : 
     163             : In the following example we run a VES_LINEAR_EXPANSION for one CV using
     164             : a Legendre basis functions (\ref BF_LEGENDRE) and a uniform target
     165             : distribution as no target distribution is specified. The coefficents
     166             : are optimized using averaged stochastic gradient descent optimizer
     167             : (\ref OPT_AVERAGED_SGD). Within the optimizer we specify that the
     168             : FES should be outputted to file every 500 coefficents iterations (the
     169             : FES_OUTPUT keyword).
     170             : Parameters that are very specfic to the problem at hand, like the
     171             : order of the basis functions, the interval on which the
     172             : basis functions are defined, and the stepsize used
     173             : in the optimizer, are left unfilled.
     174             : \plumedfile
     175             : bf1: BF_LEGENDRE ORDER=__ MINIMUM=__ MAXIMUM=__
     176             : 
     177             : VES_LINEAR_EXPANSION ...
     178             :  ARG=d1
     179             :  BASIS_FUNCTIONS=bf1
     180             :  TEMP=__
     181             :  GRID_BINS=200
     182             :  LABEL=b1
     183             : ... VES_LINEAR_EXPANSION
     184             : 
     185             : OPT_AVERAGED_SGD ...
     186             :  BIAS=b1
     187             :  STRIDE=1000
     188             :  LABEL=o1
     189             :  STEPSIZE=__
     190             :  FES_OUTPUT=500
     191             :  COEFFS_OUTPUT=10
     192             : ... OPT_AVERAGED_SGD
     193             : \endplumedfile
     194             : 
     195             : In the following example we employ VES_LINEAR_EXPANSION for two CVs,
     196             : The first CV is periodic and therefore we employ a Fourier basis functions
     197             : (\ref BF_LEGENDRE) while the second CV is non-periodic so we employ a
     198             : Legendre polynomials as in the previous example. For the target distribution
     199             : we employ a well-tempered target distribution (\ref TD_WELLTEMPERED), which is
     200             : dynamic and needs to be iteratively updated with a stride that is given
     201             : using the TARGETDIST_STRIDE within the optimizer.
     202             : 
     203             : \plumedfile
     204             : bf1: BF_FOURIER  ORDER=__ MINIMUM=__ MAXIMUM=__
     205             : bf2: BF_LEGENDRE ORDER=__ MINIMUM=__ MAXIMUM=__
     206             : 
     207             : td_wt: TD_WELLTEMPERED BIASFACTOR=10.0
     208             : 
     209             : VES_LINEAR_EXPANSION ...
     210             :  ARG=cv1,cv2
     211             :  BASIS_FUNCTIONS=bf1,bf2
     212             :  TEMP=__
     213             :  GRID_BINS=100
     214             :  LABEL=b1
     215             :  TARGET_DISTRIBUTION=td_wt
     216             : ... VES_LINEAR_EXPANSION
     217             : 
     218             : OPT_AVERAGED_SGD ...
     219             :  BIAS=b1
     220             :  STRIDE=1000
     221             :  LABEL=o1
     222             :  STEPSIZE=__
     223             :  FES_OUTPUT=500
     224             :  COEFFS_OUTPUT=10
     225             :  TARGETDIST_STRIDE=500
     226             : ... OPT_AVERAGED_SGD
     227             : \endplumedfile
     228             : 
     229             : 
     230             : In the following example we employ a bias cutoff such that the bias
     231             : only fills the free energy landscape up a certain level. In this case
     232             : the target distribution is also dynamic and needs to iteratively updated.
     233             : 
     234             : \plumedfile
     235             : bf1: BF_LEGENDRE ORDER=__ MINIMUM=__ MAXIMUM=__
     236             : bf2: BF_LEGENDRE ORDER=__ MINIMUM=__ MAXIMUM=__
     237             : 
     238             : VES_LINEAR_EXPANSION ...
     239             :  ARG=cv1,cv2
     240             :  BASIS_FUNCTIONS=bf1,bf2
     241             :  TEMP=__
     242             :  GRID_BINS=100
     243             :  LABEL=b1
     244             :  BIAS_CUTOFF=20.0
     245             : ... VES_LINEAR_EXPANSION
     246             : 
     247             : OPT_AVERAGED_SGD ...
     248             :  BIAS=b1
     249             :  STRIDE=1000
     250             :  LABEL=o1
     251             :  STEPSIZE=__
     252             :  FES_OUTPUT=500
     253             :  COEFFS_OUTPUT=10
     254             :  TARGETDIST_STRIDE=500
     255             : ... OPT_AVERAGED_SGD
     256             : \endplumedfile
     257             : 
     258             : The optimized bias potential can then be used as a static bias for obtaining
     259             : kinetics. For this you need read in the final coefficents from file
     260             : (e.g. coeffs_final.data in this case) by using the
     261             : COEFFS keyword (also, no optimizer should be defined in the input)
     262             : \plumedfile
     263             : bf1: BF_LEGENDRE ORDER=__ MINIMUM=__ MAXIMUM=__
     264             : bf2: BF_LEGENDRE ORDER=__ MINIMUM=__ MAXIMUM=__
     265             : 
     266             : VES_LINEAR_EXPANSION ...
     267             :  ARG=cv1,cv2
     268             :  BASIS_FUNCTIONS=bf1,bf2
     269             :  TEMP=__
     270             :  GRID_BINS=100
     271             :  LABEL=b1
     272             :  BIAS_CUTOFF=20.0
     273             :  COEFFS=coeffs_final.data
     274             : ... VES_LINEAR_EXPANSION
     275             : \endplumedfile
     276             : 
     277             : 
     278             : 
     279             : */
     280             : //+ENDPLUMEDOC
     281             : 
     282             : 
     283             : class VesLinearExpansion : public VesBias {
     284             : private:
     285             :   unsigned int nargs_;
     286             :   std::vector<BasisFunctions*> basisf_pntrs_;
     287             :   LinearBasisSetExpansion* bias_expansion_pntr_;
     288             :   size_t ncoeffs_;
     289             :   Value* valueForce2_;
     290             : public:
     291             :   explicit VesLinearExpansion(const ActionOptions&);
     292             :   ~VesLinearExpansion();
     293             :   void calculate();
     294             :   void updateTargetDistributions();
     295             :   void restartTargetDistributions();
     296             :   //
     297             :   void setupBiasFileOutput();
     298             :   void writeBiasToFile();
     299             :   void resetBiasFileOutput();
     300             :   //
     301             :   void setupFesFileOutput();
     302             :   void writeFesToFile();
     303             :   void resetFesFileOutput();
     304             :   //
     305             :   void setupFesProjFileOutput();
     306             :   void writeFesProjToFile();
     307             :   //
     308             :   void writeTargetDistToFile();
     309             :   void writeTargetDistProjToFile();
     310             :   //
     311             :   double calculateReweightFactor() const;
     312             :   //
     313             :   static void registerKeywords( Keywords& keys );
     314             : };
     315             : 
     316        6534 : PLUMED_REGISTER_ACTION(VesLinearExpansion,"VES_LINEAR_EXPANSION")
     317             : 
     318          83 : void VesLinearExpansion::registerKeywords( Keywords& keys ) {
     319          83 :   VesBias::registerKeywords(keys);
     320             :   //
     321          83 :   VesBias::useInitialCoeffsKeywords(keys);
     322          83 :   VesBias::useTargetDistributionKeywords(keys);
     323          83 :   VesBias::useBiasCutoffKeywords(keys);
     324          83 :   VesBias::useGridBinKeywords(keys);
     325          83 :   VesBias::useProjectionArgKeywords(keys);
     326             :   //
     327         166 :   keys.use("ARG");
     328         332 :   keys.add("compulsory","BASIS_FUNCTIONS","the label of the one dimensional basis functions that should be used.");
     329         332 :   keys.addOutputComponent("force2","default","the instantaneous value of the squared force due to this bias potential.");
     330          83 : }
     331             : 
     332          82 : VesLinearExpansion::VesLinearExpansion(const ActionOptions&ao):
     333             :   PLUMED_VES_VESBIAS_INIT(ao),
     334             :   nargs_(getNumberOfArguments()),
     335             :   basisf_pntrs_(0),
     336             :   bias_expansion_pntr_(NULL),
     337         164 :   valueForce2_(NULL)
     338             : {
     339          82 :   std::vector<std::string> basisf_labels;
     340         164 :   parseMultipleValues("BASIS_FUNCTIONS",basisf_labels,nargs_);
     341          82 :   checkRead();
     342             : 
     343          82 :   std::string error_msg = "";
     344         246 :   basisf_pntrs_ = VesTools::getPointersFromLabels<BasisFunctions*>(basisf_labels,plumed.getActionSet(),error_msg);
     345          82 :   if(error_msg.size()>0) {plumed_merror("Error in keyword BASIS_FUNCTIONS of "+getName()+": "+error_msg);}
     346             :   //
     347             : 
     348          82 :   std::vector<Value*> args_pntrs = getArguments();
     349             :   // check arguments and basis functions
     350             :   // this is done to avoid some issues with integration of target distribution
     351             :   // and periodic CVs, needs to be fixed later on.
     352         479 :   for(unsigned int i=0; i<args_pntrs.size(); i++) {
     353         271 :     if(args_pntrs[i]->isPeriodic() && !(basisf_pntrs_[i]->arePeriodic()) ) {
     354           0 :       plumed_merror("argument "+args_pntrs[i]->getName()+" is periodic while the basis functions " + basisf_pntrs_[i]->getLabel()+ " are not. You need to use the COMBINE action to remove the periodicity of the argument if you want to use these basis functions");
     355             :     }
     356         254 :     else if(!(args_pntrs[i]->isPeriodic()) && basisf_pntrs_[i]->arePeriodic() ) {
     357           3 :       log.printf("  warning: argument %s is not periodic while the basis functions %s used for it are periodic\n",args_pntrs[i]->getName().c_str(),basisf_pntrs_[i]->getLabel().c_str());
     358             :     }
     359             :   }
     360             : 
     361          82 :   addCoeffsSet(args_pntrs,basisf_pntrs_);
     362          82 :   ncoeffs_ = numberOfCoeffs();
     363          82 :   bool coeffs_read = readCoeffsFromFiles();
     364             : 
     365          82 :   checkThatTemperatureIsGiven();
     366         164 :   bias_expansion_pntr_ = new LinearBasisSetExpansion(getLabel(),getBeta(),comm,args_pntrs,basisf_pntrs_,getCoeffsPntr());
     367          82 :   bias_expansion_pntr_->linkVesBias(this);
     368         246 :   bias_expansion_pntr_->setGridBins(this->getGridBins());
     369             :   //
     370             : 
     371             : 
     372             : 
     373          82 :   if(getNumberOfTargetDistributionPntrs()==0) {
     374          42 :     log.printf("  using an uniform target distribution: \n");
     375          42 :     bias_expansion_pntr_->setupUniformTargetDistribution();
     376             :     disableStaticTargetDistFileOutput();
     377             :   }
     378          40 :   else if(getNumberOfTargetDistributionPntrs()==1) {
     379          46 :     if(biasCutoffActive()) {getTargetDistributionPntrs()[0]->setupBiasCutoff();}
     380         120 :     bias_expansion_pntr_->setupTargetDistribution(getTargetDistributionPntrs()[0]);
     381         240 :     log.printf("  using target distribution of type %s with label %s \n",getTargetDistributionPntrs()[0]->getName().c_str(),getTargetDistributionPntrs()[0]->getLabel().c_str());
     382             :   }
     383             :   else {
     384           0 :     plumed_merror("problem with the TARGET_DISTRIBUTION keyword, either give no label or just one label.");
     385             :   }
     386         164 :   setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
     387             :   //
     388          86 :   if(coeffs_read && biasCutoffActive()) {
     389           1 :     updateTargetDistributions();
     390             :   }
     391             :   //
     392          82 :   if(coeffs_read) {
     393           4 :     setupBiasFileOutput();
     394           4 :     writeBiasToFile();
     395             :   }
     396             : 
     397         246 :   addComponent("force2"); componentIsNotPeriodic("force2");
     398         164 :   valueForce2_=getPntrToComponent("force2");
     399          82 : }
     400             : 
     401             : 
     402         246 : VesLinearExpansion::~VesLinearExpansion() {
     403          82 :   if(bias_expansion_pntr_!=NULL) {
     404          82 :     delete bias_expansion_pntr_;
     405             :   }
     406         164 : }
     407             : 
     408             : 
     409        1662 : void VesLinearExpansion::calculate() {
     410             : 
     411        1662 :   std::vector<double> cv_values(nargs_);
     412        1662 :   std::vector<double> forces(nargs_);
     413        1662 :   std::vector<double> coeffsderivs_values(ncoeffs_);
     414             : 
     415        5912 :   for(unsigned int k=0; k<nargs_; k++) {
     416        4250 :     cv_values[k]=getArgument(k);
     417             :   }
     418             : 
     419        1662 :   bool all_inside = true;
     420        3324 :   double bias = bias_expansion_pntr_->getBiasAndForces(cv_values,all_inside,forces,coeffsderivs_values);
     421        1662 :   if(biasCutoffActive()) {
     422          63 :     applyBiasCutoff(bias,forces,coeffsderivs_values);
     423          63 :     coeffsderivs_values[0]=1.0;
     424             :   }
     425             :   double totalForce2 = 0.0;
     426        5912 :   for(unsigned int k=0; k<nargs_; k++) {
     427        4250 :     setOutputForce(k,forces[k]);
     428        2125 :     totalForce2 += forces[k]*forces[k];
     429             :   }
     430             : 
     431        1662 :   setBias(bias);
     432        1662 :   valueForce2_->set(totalForce2);
     433        1662 :   if(all_inside) {
     434        1473 :     addToSampledAverages(coeffsderivs_values);
     435             :   }
     436        1662 : }
     437             : 
     438             : 
     439         331 : void VesLinearExpansion::updateTargetDistributions() {
     440         331 :   bias_expansion_pntr_->updateTargetDistribution();
     441         662 :   setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
     442         331 : }
     443             : 
     444             : 
     445           8 : void VesLinearExpansion::restartTargetDistributions() {
     446          24 :   bias_expansion_pntr_->readInRestartTargetDistribution(getCurrentTargetDistOutputFilename());
     447           8 :   bias_expansion_pntr_->restartTargetDistribution();
     448          16 :   setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
     449           8 : }
     450             : 
     451             : 
     452          83 : void VesLinearExpansion::setupBiasFileOutput() {
     453          83 :   bias_expansion_pntr_->setupBiasGrid(true);
     454          83 : }
     455             : 
     456             : 
     457         165 : void VesLinearExpansion::writeBiasToFile() {
     458         165 :   bias_expansion_pntr_->updateBiasGrid();
     459         660 :   OFile* ofile_pntr = getOFile(getCurrentBiasOutputFilename(),useMultipleWalkers());
     460         165 :   bias_expansion_pntr_->writeBiasGridToFile(*ofile_pntr);
     461         165 :   ofile_pntr->close(); delete ofile_pntr;
     462         165 :   if(biasCutoffActive()) {
     463           5 :     bias_expansion_pntr_->updateBiasWithoutCutoffGrid();
     464          20 :     OFile* ofile_pntr2 = getOFile(getCurrentBiasOutputFilename("without-cutoff"),useMultipleWalkers());
     465           5 :     bias_expansion_pntr_->writeBiasWithoutCutoffGridToFile(*ofile_pntr2);
     466           5 :     ofile_pntr2->close(); delete ofile_pntr2;
     467             :   }
     468         165 : }
     469             : 
     470             : 
     471          36 : void VesLinearExpansion::resetBiasFileOutput() {
     472          36 :   bias_expansion_pntr_->resetStepOfLastBiasGridUpdate();
     473          36 : }
     474             : 
     475             : 
     476          79 : void VesLinearExpansion::setupFesFileOutput() {
     477          79 :   bias_expansion_pntr_->setupFesGrid();
     478          79 : }
     479             : 
     480             : 
     481         161 : void VesLinearExpansion::writeFesToFile() {
     482         161 :   bias_expansion_pntr_->updateFesGrid();
     483         644 :   OFile* ofile_pntr = getOFile(getCurrentFesOutputFilename(),useMultipleWalkers());
     484         161 :   bias_expansion_pntr_->writeFesGridToFile(*ofile_pntr);
     485         161 :   ofile_pntr->close(); delete ofile_pntr;
     486         161 : }
     487             : 
     488             : 
     489          36 : void VesLinearExpansion::resetFesFileOutput() {
     490          36 :   bias_expansion_pntr_->resetStepOfLastFesGridUpdate();
     491          36 : }
     492             : 
     493             : 
     494          17 : void VesLinearExpansion::setupFesProjFileOutput() {
     495          17 :   if(getNumberOfProjectionArguments()>0) {
     496           8 :     bias_expansion_pntr_->setupFesProjGrid();
     497             :   }
     498          17 : }
     499             : 
     500             : 
     501          36 : void VesLinearExpansion::writeFesProjToFile() {
     502          36 :   bias_expansion_pntr_->updateFesGrid();
     503         108 :   for(unsigned int i=0; i<getNumberOfProjectionArguments(); i++) {
     504             :     std::string suffix;
     505          36 :     Tools::convert(i+1,suffix);
     506          72 :     suffix = "proj-" + suffix;
     507         108 :     OFile* ofile_pntr = getOFile(getCurrentFesOutputFilename(suffix),useMultipleWalkers());
     508          36 :     std::vector<std::string> args = getProjectionArgument(i);
     509          36 :     bias_expansion_pntr_->writeFesProjGridToFile(args,*ofile_pntr);
     510          36 :     ofile_pntr->close(); delete ofile_pntr;
     511             :   }
     512          36 : }
     513             : 
     514             : 
     515          72 : void VesLinearExpansion::writeTargetDistToFile() {
     516         216 :   OFile* ofile1_pntr = getOFile(getCurrentTargetDistOutputFilename(),useMultipleWalkers());
     517         216 :   OFile* ofile2_pntr = getOFile(getCurrentTargetDistOutputFilename("log"),useMultipleWalkers());
     518          72 :   bias_expansion_pntr_->writeTargetDistGridToFile(*ofile1_pntr);
     519          72 :   bias_expansion_pntr_->writeLogTargetDistGridToFile(*ofile2_pntr);
     520          72 :   ofile1_pntr->close(); delete ofile1_pntr;
     521          72 :   ofile2_pntr->close(); delete ofile2_pntr;
     522          72 : }
     523             : 
     524             : 
     525          13 : void VesLinearExpansion::writeTargetDistProjToFile() {
     526          53 :   for(unsigned int i=0; i<getNumberOfProjectionArguments(); i++) {
     527             :     std::string suffix;
     528          20 :     Tools::convert(i+1,suffix);
     529          40 :     suffix = "proj-" + suffix;
     530          40 :     OFile* ofile_pntr = getOFile(getCurrentTargetDistOutputFilename(suffix),useMultipleWalkers());
     531          20 :     std::vector<std::string> args = getProjectionArgument(i);
     532          20 :     bias_expansion_pntr_->writeTargetDistProjGridToFile(args,*ofile_pntr);
     533          20 :     ofile_pntr->close(); delete ofile_pntr;
     534             :   }
     535          13 : }
     536             : 
     537             : 
     538           0 : double VesLinearExpansion::calculateReweightFactor() const {
     539           0 :   return bias_expansion_pntr_->calculateReweightFactor();
     540             : }
     541             : 
     542             : 
     543             : }
     544        4839 : }

Generated by: LCOV version 1.13