LCOV - code coverage report
Current view: top level - ves - VesLinearExpansion.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 142 148 95.9 %
Date: 2025-12-04 11:19:34 Functions: 18 21 85.7 %

          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 "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             : $$
      49             : V(s_{1};\boldsymbol{\alpha}) = \sum_{i_{1}} \alpha_{i_{1}} \, f_{i_{1}}(s_{1}),
      50             : $$
      51             : while for two CVs it is written as
      52             : $$
      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             : $$
      55             : where $\boldsymbol{\alpha}$ 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             : $$
      60             : V(\mathbf{s}) = - F(\mathbf{s}) - \frac{1}{\beta} \log p(\mathbf{s}).
      61             : $$
      62             : where $p(\mathbf{s})$ is the target distribution that is employed in the VES simulation.
      63             : 
      64             : ## Basis Functions
      65             : 
      66             : Various one-dimensional basis functions are available in the VES code,
      67             : see the complete list go to [the module page](module_ves.md) and select VES_BIAS from the tags dropdown.
      68             : At the current moment we recommend to use Legendre polynomials ([BF_LEGENDRE](BF_LEGENDRE.md))
      69             : for non-periodic CVs and Fourier basis functions ([BF_FOURIER](BF_FOURIER.md))
      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             : ## Target Distributions
      78             : 
      79             : Various target distributions $p(\mathbf{s})$ are available in the VES code,
      80             : see the complete list go to [the module page](module_ves.md) and select VES_TARGETDIST from the tags dropdown.
      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 ([TD_WELLTEMPERED](TD_WELLTEMPERED.md)),
      89             : are dynamic and need to be iteratively updated during the optimization.
      90             : 
      91             : ## 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 go to [the module page](module_ves.md) and select VES_OPTIMIZER from the tags dropdown. At the current moment we recommend to
      96             : use the averaged stochastic gradient decent optimizer ([OPT_AVERAGED_SGD](OPT_AVERAGED_SGD.md)).
      97             : 
      98             : The optimizer should be defined after the VES_LINEAR_EXPANSION action.
      99             : 
     100             : ## 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 sufficient.
     107             : 
     108             : ## 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 ves_optimizer (see the section before last for more details) 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 specify 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 post processing
     140             : by using the [VES_OUTPUT_FES](VES_OUTPUT_FES.md) action. However, be aware that this action
     141             : does does not support dynamic target distribution (e.g. well-tempered).
     142             : 
     143             : ## Static Bias
     144             : 
     145             : It is also possible to use VES_LINEAR_EXPANSION as a static bias that uses
     146             : previously obtained coefficients. In this case the coefficients should be
     147             : read in from the coefficient file given in the COEFFS keyword.
     148             : 
     149             : ## Bias Cutoff
     150             : 
     151             : It is possible to impose a cutoff on the bias potential using the procedure
     152             : introduced in the paper cited below 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 $1/(1+e^{\lambda x})$
     157             : where the parameter $\lambda$ controls how sharply the switchingfunction goes to zero.
     158             : The default value is $\lambda=10$ but this can be changed by using the
     159             : BIAS_CUTOFF_FERMI_LAMBDA keyword.
     160             : 
     161             : ## Examples
     162             : 
     163             : In the following example we run a VES_LINEAR_EXPANSION for one CV using
     164             : a Legendre basis functions ([BF_LEGENDRE](BF_LEGENDRE.md)) and a uniform target
     165             : distribution as no target distribution is specified. The coefficients
     166             : are optimized using averaged stochastic gradient descent optimizer
     167             : ([OPT_AVERAGED_SGD](OPT_AVERAGED_SGD.md)). Within the optimizer we specify that the
     168             : FES should be outputted to file every 500 coefficients iterations (the
     169             : FES_OUTPUT keyword).
     170             : Parameters that are very specific 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 step size used
     173             : in the optimizer, are left unfilled.
     174             : 
     175             : ```plumed
     176             : bf1: BF_LEGENDRE ORDER=_FILL_ MINIMUM=_FILL_ MAXIMUM=_FILL_
     177             : 
     178             : VES_LINEAR_EXPANSION ...
     179             :  ARG=d1
     180             :  BASIS_FUNCTIONS=bf1
     181             :  TEMP=_FILL_
     182             :  GRID_BINS=200
     183             :  LABEL=b1
     184             : ... VES_LINEAR_EXPANSION
     185             : 
     186             : OPT_AVERAGED_SGD ...
     187             :  BIAS=b1
     188             :  STRIDE=1000
     189             :  LABEL=o1
     190             :  STEPSIZE=_FILL_
     191             :  FES_OUTPUT=500
     192             :  COEFFS_OUTPUT=10
     193             : ... OPT_AVERAGED_SGD
     194             : ```
     195             : 
     196             : In the following example we employ VES_LINEAR_EXPANSION for two CVs,
     197             : The first CV is periodic and therefore we employ a Fourier basis functions
     198             : ([BF_LEGENDRE](BF_LEGENDRE.md)) while the second CV is non-periodic so we employ a
     199             : Legendre polynomials as in the previous example. For the target distribution
     200             : we employ a well-tempered target distribution ([TD_WELLTEMPERED](TD_WELLTEMPERED.md)), which is
     201             : dynamic and needs to be iteratively updated with a stride that is given
     202             : using the TARGETDIST_STRIDE within the optimizer.
     203             : 
     204             : ```plumed
     205             : bf1: BF_FOURIER  ORDER=_FILL_ MINIMUM=_FILL_ MAXIMUM=_FILL_
     206             : bf2: BF_LEGENDRE ORDER=_FILL_ MINIMUM=_FILL_ MAXIMUM=_FILL_
     207             : 
     208             : td_wt: TD_WELLTEMPERED BIASFACTOR=10.0
     209             : 
     210             : VES_LINEAR_EXPANSION ...
     211             :  ARG=cv1,cv2
     212             :  BASIS_FUNCTIONS=bf1,bf2
     213             :  TEMP=_FILL_
     214             :  GRID_BINS=100
     215             :  LABEL=b1
     216             :  TARGET_DISTRIBUTION=td_wt
     217             : ... VES_LINEAR_EXPANSION
     218             : 
     219             : OPT_AVERAGED_SGD ...
     220             :  BIAS=b1
     221             :  STRIDE=1000
     222             :  LABEL=o1
     223             :  STEPSIZE=_FILL_
     224             :  FES_OUTPUT=500
     225             :  COEFFS_OUTPUT=10
     226             :  TARGETDIST_STRIDE=500
     227             : ... OPT_AVERAGED_SGD
     228             : ```
     229             : 
     230             : 
     231             : In the following example we employ a bias cutoff such that the bias
     232             : only fills the free energy landscape up a certain level. In this case
     233             : the target distribution is also dynamic and needs to iteratively updated.
     234             : 
     235             : ```plumed
     236             : bf1: BF_LEGENDRE ORDER=_FILL_ MINIMUM=_FILL_ MAXIMUM=_FILL_
     237             : bf2: BF_LEGENDRE ORDER=_FILL_ MINIMUM=_FILL_ MAXIMUM=_FILL_
     238             : 
     239             : VES_LINEAR_EXPANSION ...
     240             :  ARG=cv1,cv2
     241             :  BASIS_FUNCTIONS=bf1,bf2
     242             :  TEMP=_FILL_
     243             :  GRID_BINS=100
     244             :  LABEL=b1
     245             :  BIAS_CUTOFF=20.0
     246             : ... VES_LINEAR_EXPANSION
     247             : 
     248             : OPT_AVERAGED_SGD ...
     249             :  BIAS=b1
     250             :  STRIDE=1000
     251             :  LABEL=o1
     252             :  STEPSIZE=_FILL_
     253             :  FES_OUTPUT=500
     254             :  COEFFS_OUTPUT=10
     255             :  TARGETDIST_STRIDE=500
     256             : ... OPT_AVERAGED_SGD
     257             : ```
     258             : 
     259             : The optimized bias potential can then be used as a static bias for obtaining
     260             : kinetics. For this you need read in the final coefficients from file
     261             : (e.g. coeffs_final.data in this case) by using the
     262             : COEFFS keyword (also, no optimizer should be defined in the input)
     263             : 
     264             : ```plumed
     265             : bf1: BF_LEGENDRE ORDER=_FILL_ MINIMUM=_FILL_ MAXIMUM=_FILL_
     266             : bf2: BF_LEGENDRE ORDER=_FILL_ MINIMUM=_FILL_ MAXIMUM=_FILL_
     267             : 
     268             : VES_LINEAR_EXPANSION ...
     269             :  ARG=cv1,cv2
     270             :  BASIS_FUNCTIONS=bf1,bf2
     271             :  TEMP=_FILL_
     272             :  GRID_BINS=100
     273             :  LABEL=b1
     274             :  BIAS_CUTOFF=20.0
     275             :  COEFFS=coeffs_final.data
     276             : ... VES_LINEAR_EXPANSION
     277             : ```
     278             : 
     279             : 
     280             : 
     281             : */
     282             : //+ENDPLUMEDOC
     283             : 
     284             : 
     285             : class VesLinearExpansion : public VesBias {
     286             : private:
     287             :   unsigned int nargs_;
     288             :   std::vector<BasisFunctions*> basisf_pntrs_;
     289             :   std::unique_ptr<LinearBasisSetExpansion> bias_expansion_pntr_;
     290             :   size_t ncoeffs_;
     291             :   Value* valueForce2_;
     292             :   bool all_values_inside;
     293             :   std::vector<double> bf_values;
     294             :   bool bf_values_set;
     295             : public:
     296             :   explicit VesLinearExpansion(const ActionOptions&);
     297             :   ~VesLinearExpansion();
     298             :   void calculate() override;
     299             :   void update() override;
     300             :   void updateTargetDistributions() override;
     301             :   void restartTargetDistributions() override;
     302             :   //
     303             :   void setupBiasFileOutput() override;
     304             :   void writeBiasToFile() override;
     305             :   void resetBiasFileOutput() override;
     306             :   //
     307             :   void setupFesFileOutput() override;
     308             :   void writeFesToFile() override;
     309             :   void resetFesFileOutput() override;
     310             :   //
     311             :   void setupFesProjFileOutput() override;
     312             :   void writeFesProjToFile() override;
     313             :   //
     314             :   void writeTargetDistToFile() override;
     315             :   void writeTargetDistProjToFile() override;
     316             :   //
     317             :   double calculateReweightFactor() const override;
     318             :   //
     319             :   static void registerKeywords( Keywords& keys );
     320             : };
     321             : 
     322             : PLUMED_REGISTER_ACTION(VesLinearExpansion,"VES_LINEAR_EXPANSION")
     323             : 
     324          92 : void VesLinearExpansion::registerKeywords( Keywords& keys ) {
     325          92 :   VesBias::registerKeywords(keys);
     326             :   //
     327          92 :   VesBias::useInitialCoeffsKeywords(keys);
     328          92 :   VesBias::useTargetDistributionKeywords(keys);
     329          92 :   VesBias::useBiasCutoffKeywords(keys);
     330          92 :   VesBias::useGridBinKeywords(keys);
     331          92 :   VesBias::useProjectionArgKeywords(keys);
     332             :   //
     333          92 :   keys.add("compulsory","BASIS_FUNCTIONS","the label of the one dimensional basis functions that should be used.");
     334          92 :   keys.add("compulsory","GRID_FMT","%14.9f","the format to use when outputting the numbers in the grids");
     335         184 :   keys.addOutputComponent("force2","default","scalar","the instantaneous value of the squared force due to this bias potential.");
     336          92 :   keys.addDOI("10.1103/PhysRevLett.115.070601");
     337          92 : }
     338             : 
     339          90 : VesLinearExpansion::VesLinearExpansion(const ActionOptions&ao):
     340             :   PLUMED_VES_VESBIAS_INIT(ao),
     341          90 :   nargs_(getNumberOfArguments()),
     342          90 :   basisf_pntrs_(0),
     343          90 :   valueForce2_(NULL),
     344          90 :   all_values_inside(true),
     345          90 :   bf_values(0),
     346          90 :   bf_values_set(false) {
     347             :   std::vector<std::string> basisf_labels;
     348          90 :   parseMultipleValues("BASIS_FUNCTIONS",basisf_labels,nargs_);
     349             : 
     350          90 :   std::string error_msg = "";
     351         180 :   basisf_pntrs_ = VesTools::getPointersFromLabels<BasisFunctions*>(basisf_labels,plumed.getActionSet(),error_msg);
     352          90 :   if(error_msg.size()>0) {
     353           0 :     plumed_merror("Error in keyword BASIS_FUNCTIONS of "+getName()+": "+error_msg);
     354             :   }
     355             :   //
     356             : 
     357          90 :   std::vector<Value*> args_pntrs = getArguments();
     358             :   // check arguments and basis functions
     359             :   // this is done to avoid some issues with integration of target distribution
     360             :   // and periodic CVs, needs to be fixed later on.
     361         207 :   for(unsigned int i=0; i<args_pntrs.size(); i++) {
     362         117 :     if(args_pntrs[i]->isPeriodic() && !(basisf_pntrs_[i]->arePeriodic()) ) {
     363           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");
     364         117 :     } else if(!(args_pntrs[i]->isPeriodic()) && basisf_pntrs_[i]->arePeriodic() ) {
     365           1 :       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());
     366             :     }
     367             :   }
     368             : 
     369          90 :   addCoeffsSet(args_pntrs,basisf_pntrs_);
     370          90 :   ncoeffs_ = numberOfCoeffs();
     371          90 :   bool coeffs_read = readCoeffsFromFiles();
     372             : 
     373          90 :   checkThatTemperatureIsGiven();
     374             :   std::string fmt;
     375         180 :   parse("GRID_FMT",fmt);
     376         180 :   bias_expansion_pntr_ = Tools::make_unique<LinearBasisSetExpansion>(getLabel(),getBeta(),comm,args_pntrs,basisf_pntrs_,getCoeffsPntr());
     377             :   bias_expansion_pntr_->setGridFMT(fmt);
     378          90 :   bias_expansion_pntr_->linkVesBias(this);
     379          90 :   bias_expansion_pntr_->setGridBins(this->getGridBins());
     380             :   //
     381          90 :   bf_values.assign(ncoeffs_,0.0);
     382             : 
     383             : 
     384             : 
     385          90 :   if(getNumberOfTargetDistributionPntrs()==0) {
     386          45 :     log.printf("  using an uniform target distribution: \n");
     387          45 :     bias_expansion_pntr_->setupUniformTargetDistribution();
     388             :     disableStaticTargetDistFileOutput();
     389          45 :   } else if(getNumberOfTargetDistributionPntrs()==1) {
     390          45 :     if(biasCutoffActive()) {
     391           6 :       getTargetDistributionPntrs()[0]->setupBiasCutoff();
     392             :     }
     393          45 :     bias_expansion_pntr_->setupTargetDistribution(getTargetDistributionPntrs()[0]);
     394          90 :     log.printf("  using target distribution of type %s with label %s \n",getTargetDistributionPntrs()[0]->getName().c_str(),getTargetDistributionPntrs()[0]->getLabel().c_str());
     395             :   } else {
     396           0 :     plumed_merror("problem with the TARGET_DISTRIBUTION keyword, either give no label or just one label.");
     397             :   }
     398          90 :   setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
     399             :   //
     400          90 :   if(coeffs_read && biasCutoffActive()) {
     401           1 :     VesLinearExpansion::updateTargetDistributions();
     402             :   }
     403             :   //
     404          90 :   if(coeffs_read) {
     405           4 :     VesLinearExpansion::setupBiasFileOutput();
     406           4 :     VesLinearExpansion::writeBiasToFile();
     407             :   }
     408             : 
     409         180 :   addComponent("force2");
     410          90 :   componentIsNotPeriodic("force2");
     411          90 :   valueForce2_=getPntrToComponent("force2");
     412          90 : }
     413             : 
     414             : 
     415         180 : VesLinearExpansion::~VesLinearExpansion() {
     416         270 : }
     417             : 
     418             : 
     419       23750 : void VesLinearExpansion::calculate() {
     420             : 
     421       23750 :   std::vector<double> cv_values(nargs_);
     422       23750 :   std::vector<double> forces(nargs_);
     423             : 
     424       60967 :   for(unsigned int k=0; k<nargs_; k++) {
     425       37217 :     cv_values[k]=getArgument(k);
     426             :   }
     427             : 
     428       23750 :   all_values_inside = true;
     429       23750 :   double bias = bias_expansion_pntr_->getBiasAndForces(cv_values,all_values_inside,forces,bf_values);
     430       23750 :   if(biasCutoffActive()) {
     431          63 :     applyBiasCutoff(bias,forces,bf_values);
     432          63 :     bf_values[0]=1.0;
     433             :   }
     434             :   double totalForce2 = 0.0;
     435       23750 :   if(all_values_inside) {
     436       60408 :     for(unsigned int k=0; k<nargs_; k++) {
     437       36852 :       setOutputForce(k,forces[k]);
     438       36852 :       totalForce2 += forces[k]*forces[k];
     439             :     }
     440             :   }
     441             : 
     442       23750 :   setBias(bias);
     443       23750 :   valueForce2_->set(totalForce2);
     444             : 
     445       23750 :   bf_values_set = true;
     446       23750 : }
     447             : 
     448             : 
     449       23750 : void VesLinearExpansion::update() {
     450       23750 :   if(!bf_values_set) {
     451           0 :     warning("VesLinearExpansion::update() is being called without calling VesLinearExpansion::calculate() first to calculate the basis function values. This can lead to incorrect behavior.");
     452             :   }
     453       23750 :   if(all_values_inside && bf_values_set) {
     454       23556 :     addToSampledAverages(bf_values);
     455             :   }
     456             :   std::fill(bf_values.begin(), bf_values.end(), 0.0);
     457       23750 :   bf_values_set = false;
     458       23750 : }
     459             : 
     460             : 
     461             : 
     462             : 
     463             : 
     464             : 
     465         355 : void VesLinearExpansion::updateTargetDistributions() {
     466         355 :   bias_expansion_pntr_->updateTargetDistribution();
     467         355 :   setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
     468         355 : }
     469             : 
     470             : 
     471           8 : void VesLinearExpansion::restartTargetDistributions() {
     472          16 :   bias_expansion_pntr_->readInRestartTargetDistribution(getCurrentTargetDistOutputFilename());
     473           8 :   bias_expansion_pntr_->restartTargetDistribution();
     474           8 :   setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
     475           8 : }
     476             : 
     477             : 
     478          87 : void VesLinearExpansion::setupBiasFileOutput() {
     479          87 :   bias_expansion_pntr_->setupBiasGrid(true);
     480          87 : }
     481             : 
     482             : 
     483         173 : void VesLinearExpansion::writeBiasToFile() {
     484         173 :   bias_expansion_pntr_->updateBiasGrid();
     485         519 :   auto ofile_pntr = getOFile(getCurrentBiasOutputFilename(),useMultipleWalkers());
     486         173 :   bias_expansion_pntr_->writeBiasGridToFile(*ofile_pntr);
     487         173 :   if(biasCutoffActive()) {
     488           5 :     bias_expansion_pntr_->updateBiasWithoutCutoffGrid();
     489          15 :     auto ofile_pntr2 = getOFile(getCurrentBiasOutputFilename("without-cutoff"),useMultipleWalkers());
     490           5 :     bias_expansion_pntr_->writeBiasWithoutCutoffGridToFile(*ofile_pntr2);
     491           5 :   }
     492         173 : }
     493             : 
     494             : 
     495          36 : void VesLinearExpansion::resetBiasFileOutput() {
     496             :   bias_expansion_pntr_->resetStepOfLastBiasGridUpdate();
     497          36 : }
     498             : 
     499             : 
     500          83 : void VesLinearExpansion::setupFesFileOutput() {
     501          83 :   bias_expansion_pntr_->setupFesGrid();
     502          83 : }
     503             : 
     504             : 
     505         169 : void VesLinearExpansion::writeFesToFile() {
     506         169 :   bias_expansion_pntr_->updateFesGrid();
     507         507 :   auto ofile_pntr = getOFile(getCurrentFesOutputFilename(),useMultipleWalkers());
     508         169 :   bias_expansion_pntr_->writeFesGridToFile(*ofile_pntr);
     509         169 : }
     510             : 
     511             : 
     512          36 : void VesLinearExpansion::resetFesFileOutput() {
     513             :   bias_expansion_pntr_->resetStepOfLastFesGridUpdate();
     514          36 : }
     515             : 
     516             : 
     517          17 : void VesLinearExpansion::setupFesProjFileOutput() {
     518          17 :   if(getNumberOfProjectionArguments()>0) {
     519           8 :     bias_expansion_pntr_->setupFesProjGrid();
     520             :   }
     521          17 : }
     522             : 
     523             : 
     524          36 : void VesLinearExpansion::writeFesProjToFile() {
     525          36 :   bias_expansion_pntr_->updateFesGrid();
     526          72 :   for(unsigned int i=0; i<getNumberOfProjectionArguments(); i++) {
     527             :     std::string suffix;
     528          36 :     Tools::convert(i+1,suffix);
     529          36 :     suffix = "proj-" + suffix;
     530          72 :     auto ofile_pntr = getOFile(getCurrentFesOutputFilename(suffix),useMultipleWalkers());
     531             :     std::vector<std::string> args = getProjectionArgument(i);
     532          36 :     bias_expansion_pntr_->writeFesProjGridToFile(args,*ofile_pntr);
     533          36 :   }
     534          36 : }
     535             : 
     536             : 
     537          82 : void VesLinearExpansion::writeTargetDistToFile() {
     538         164 :   auto ofile1_pntr = getOFile(getCurrentTargetDistOutputFilename(),useMultipleWalkers());
     539         164 :   auto ofile2_pntr = getOFile(getCurrentTargetDistOutputFilename("log"),useMultipleWalkers());
     540          82 :   bias_expansion_pntr_->writeTargetDistGridToFile(*ofile1_pntr);
     541          82 :   bias_expansion_pntr_->writeLogTargetDistGridToFile(*ofile2_pntr);
     542          82 : }
     543             : 
     544             : 
     545          13 : void VesLinearExpansion::writeTargetDistProjToFile() {
     546          33 :   for(unsigned int i=0; i<getNumberOfProjectionArguments(); i++) {
     547             :     std::string suffix;
     548          20 :     Tools::convert(i+1,suffix);
     549          20 :     suffix = "proj-" + suffix;
     550          40 :     auto ofile_pntr = getOFile(getCurrentTargetDistOutputFilename(suffix),useMultipleWalkers());
     551             :     std::vector<std::string> args = getProjectionArgument(i);
     552          20 :     bias_expansion_pntr_->writeTargetDistProjGridToFile(args,*ofile_pntr);
     553          20 :   }
     554          13 : }
     555             : 
     556             : 
     557           0 : double VesLinearExpansion::calculateReweightFactor() const {
     558           0 :   return bias_expansion_pntr_->calculateReweightFactor();
     559             : }
     560             : 
     561             : 
     562             : }
     563             : }

Generated by: LCOV version 1.16