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 sufficient.
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 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 \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 coefficients. In this case the coefficients should be
147 : read in from the coefficient 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 coefficients
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 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 : \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 coefficients 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 : bool all_values_inside;
291 : std::vector<double> bf_values;
292 : bool bf_values_set;
293 : public:
294 : explicit VesLinearExpansion(const ActionOptions&);
295 : ~VesLinearExpansion();
296 : void calculate();
297 : void update();
298 : void updateTargetDistributions();
299 : void restartTargetDistributions();
300 : //
301 : void setupBiasFileOutput();
302 : void writeBiasToFile();
303 : void resetBiasFileOutput();
304 : //
305 : void setupFesFileOutput();
306 : void writeFesToFile();
307 : void resetFesFileOutput();
308 : //
309 : void setupFesProjFileOutput();
310 : void writeFesProjToFile();
311 : //
312 : void writeTargetDistToFile();
313 : void writeTargetDistProjToFile();
314 : //
315 : double calculateReweightFactor() const;
316 : //
317 : static void registerKeywords( Keywords& keys );
318 : };
319 :
320 7520 : PLUMED_REGISTER_ACTION(VesLinearExpansion,"VES_LINEAR_EXPANSION")
321 :
322 83 : void VesLinearExpansion::registerKeywords( Keywords& keys ) {
323 83 : VesBias::registerKeywords(keys);
324 : //
325 83 : VesBias::useInitialCoeffsKeywords(keys);
326 83 : VesBias::useTargetDistributionKeywords(keys);
327 83 : VesBias::useBiasCutoffKeywords(keys);
328 83 : VesBias::useGridBinKeywords(keys);
329 83 : VesBias::useProjectionArgKeywords(keys);
330 : //
331 166 : keys.use("ARG");
332 332 : keys.add("compulsory","BASIS_FUNCTIONS","the label of the one dimensional basis functions that should be used.");
333 332 : keys.addOutputComponent("force2","default","the instantaneous value of the squared force due to this bias potential.");
334 83 : }
335 :
336 82 : VesLinearExpansion::VesLinearExpansion(const ActionOptions&ao):
337 : PLUMED_VES_VESBIAS_INIT(ao),
338 : nargs_(getNumberOfArguments()),
339 : basisf_pntrs_(0),
340 : bias_expansion_pntr_(NULL),
341 : valueForce2_(NULL),
342 : all_values_inside(true),
343 : bf_values(0),
344 164 : bf_values_set(false)
345 : {
346 82 : std::vector<std::string> basisf_labels;
347 164 : parseMultipleValues("BASIS_FUNCTIONS",basisf_labels,nargs_);
348 82 : checkRead();
349 :
350 82 : std::string error_msg = "";
351 246 : basisf_pntrs_ = VesTools::getPointersFromLabels<BasisFunctions*>(basisf_labels,plumed.getActionSet(),error_msg);
352 82 : if(error_msg.size()>0) {plumed_merror("Error in keyword BASIS_FUNCTIONS of "+getName()+": "+error_msg);}
353 : //
354 :
355 82 : std::vector<Value*> args_pntrs = getArguments();
356 : // check arguments and basis functions
357 : // this is done to avoid some issues with integration of target distribution
358 : // and periodic CVs, needs to be fixed later on.
359 479 : for(unsigned int i=0; i<args_pntrs.size(); i++) {
360 271 : if(args_pntrs[i]->isPeriodic() && !(basisf_pntrs_[i]->arePeriodic()) ) {
361 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");
362 : }
363 254 : else if(!(args_pntrs[i]->isPeriodic()) && basisf_pntrs_[i]->arePeriodic() ) {
364 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());
365 : }
366 : }
367 :
368 82 : addCoeffsSet(args_pntrs,basisf_pntrs_);
369 82 : ncoeffs_ = numberOfCoeffs();
370 82 : bool coeffs_read = readCoeffsFromFiles();
371 :
372 82 : checkThatTemperatureIsGiven();
373 164 : bias_expansion_pntr_ = new LinearBasisSetExpansion(getLabel(),getBeta(),comm,args_pntrs,basisf_pntrs_,getCoeffsPntr());
374 82 : bias_expansion_pntr_->linkVesBias(this);
375 246 : bias_expansion_pntr_->setGridBins(this->getGridBins());
376 : //
377 164 : bf_values.assign(ncoeffs_,0.0);
378 :
379 :
380 :
381 82 : if(getNumberOfTargetDistributionPntrs()==0) {
382 42 : log.printf(" using an uniform target distribution: \n");
383 42 : bias_expansion_pntr_->setupUniformTargetDistribution();
384 : disableStaticTargetDistFileOutput();
385 : }
386 40 : else if(getNumberOfTargetDistributionPntrs()==1) {
387 46 : if(biasCutoffActive()) {getTargetDistributionPntrs()[0]->setupBiasCutoff();}
388 120 : bias_expansion_pntr_->setupTargetDistribution(getTargetDistributionPntrs()[0]);
389 240 : log.printf(" using target distribution of type %s with label %s \n",getTargetDistributionPntrs()[0]->getName().c_str(),getTargetDistributionPntrs()[0]->getLabel().c_str());
390 : }
391 : else {
392 0 : plumed_merror("problem with the TARGET_DISTRIBUTION keyword, either give no label or just one label.");
393 : }
394 164 : setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
395 : //
396 86 : if(coeffs_read && biasCutoffActive()) {
397 1 : updateTargetDistributions();
398 : }
399 : //
400 82 : if(coeffs_read) {
401 4 : setupBiasFileOutput();
402 4 : writeBiasToFile();
403 : }
404 :
405 246 : addComponent("force2"); componentIsNotPeriodic("force2");
406 164 : valueForce2_=getPntrToComponent("force2");
407 82 : }
408 :
409 :
410 246 : VesLinearExpansion::~VesLinearExpansion() {
411 82 : if(bias_expansion_pntr_!=NULL) {
412 82 : delete bias_expansion_pntr_;
413 : }
414 164 : }
415 :
416 :
417 1662 : void VesLinearExpansion::calculate() {
418 :
419 1662 : std::vector<double> cv_values(nargs_);
420 1662 : std::vector<double> forces(nargs_);
421 :
422 5912 : for(unsigned int k=0; k<nargs_; k++) {
423 4250 : cv_values[k]=getArgument(k);
424 : }
425 :
426 1662 : all_values_inside = true;
427 3324 : double bias = bias_expansion_pntr_->getBiasAndForces(cv_values,all_values_inside,forces,bf_values);
428 1662 : if(biasCutoffActive()) {
429 63 : applyBiasCutoff(bias,forces,bf_values);
430 63 : bf_values[0]=1.0;
431 : }
432 : double totalForce2 = 0.0;
433 5912 : for(unsigned int k=0; k<nargs_; k++) {
434 4250 : setOutputForce(k,forces[k]);
435 2125 : totalForce2 += forces[k]*forces[k];
436 : }
437 :
438 1662 : setBias(bias);
439 1662 : valueForce2_->set(totalForce2);
440 :
441 1662 : bf_values_set = true;
442 1662 : }
443 :
444 :
445 1662 : void VesLinearExpansion::update() {
446 1662 : if(!bf_values_set) {
447 0 : warning("VesLinearExpansion::update() is being called without calling VesLinearExpansion::calculate() first to calculate the basis function values. This can lead to incorrect behavior.");
448 : }
449 1662 : if(all_values_inside && bf_values_set) {
450 1473 : addToSampledAverages(bf_values);
451 : }
452 3324 : std::fill(bf_values.begin(), bf_values.end(), 0.0);
453 1662 : bf_values_set = false;
454 1662 : }
455 :
456 :
457 :
458 :
459 :
460 :
461 331 : void VesLinearExpansion::updateTargetDistributions() {
462 331 : bias_expansion_pntr_->updateTargetDistribution();
463 662 : setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
464 331 : }
465 :
466 :
467 8 : void VesLinearExpansion::restartTargetDistributions() {
468 24 : bias_expansion_pntr_->readInRestartTargetDistribution(getCurrentTargetDistOutputFilename());
469 8 : bias_expansion_pntr_->restartTargetDistribution();
470 16 : setTargetDistAverages(bias_expansion_pntr_->TargetDistAverages());
471 8 : }
472 :
473 :
474 83 : void VesLinearExpansion::setupBiasFileOutput() {
475 83 : bias_expansion_pntr_->setupBiasGrid(true);
476 83 : }
477 :
478 :
479 165 : void VesLinearExpansion::writeBiasToFile() {
480 165 : bias_expansion_pntr_->updateBiasGrid();
481 660 : OFile* ofile_pntr = getOFile(getCurrentBiasOutputFilename(),useMultipleWalkers());
482 165 : bias_expansion_pntr_->writeBiasGridToFile(*ofile_pntr);
483 165 : ofile_pntr->close(); delete ofile_pntr;
484 165 : if(biasCutoffActive()) {
485 5 : bias_expansion_pntr_->updateBiasWithoutCutoffGrid();
486 20 : OFile* ofile_pntr2 = getOFile(getCurrentBiasOutputFilename("without-cutoff"),useMultipleWalkers());
487 5 : bias_expansion_pntr_->writeBiasWithoutCutoffGridToFile(*ofile_pntr2);
488 5 : ofile_pntr2->close(); delete ofile_pntr2;
489 : }
490 165 : }
491 :
492 :
493 36 : void VesLinearExpansion::resetBiasFileOutput() {
494 36 : bias_expansion_pntr_->resetStepOfLastBiasGridUpdate();
495 36 : }
496 :
497 :
498 79 : void VesLinearExpansion::setupFesFileOutput() {
499 79 : bias_expansion_pntr_->setupFesGrid();
500 79 : }
501 :
502 :
503 161 : void VesLinearExpansion::writeFesToFile() {
504 161 : bias_expansion_pntr_->updateFesGrid();
505 644 : OFile* ofile_pntr = getOFile(getCurrentFesOutputFilename(),useMultipleWalkers());
506 161 : bias_expansion_pntr_->writeFesGridToFile(*ofile_pntr);
507 161 : ofile_pntr->close(); delete ofile_pntr;
508 161 : }
509 :
510 :
511 36 : void VesLinearExpansion::resetFesFileOutput() {
512 36 : bias_expansion_pntr_->resetStepOfLastFesGridUpdate();
513 36 : }
514 :
515 :
516 17 : void VesLinearExpansion::setupFesProjFileOutput() {
517 17 : if(getNumberOfProjectionArguments()>0) {
518 8 : bias_expansion_pntr_->setupFesProjGrid();
519 : }
520 17 : }
521 :
522 :
523 36 : void VesLinearExpansion::writeFesProjToFile() {
524 36 : bias_expansion_pntr_->updateFesGrid();
525 108 : for(unsigned int i=0; i<getNumberOfProjectionArguments(); i++) {
526 : std::string suffix;
527 36 : Tools::convert(i+1,suffix);
528 72 : suffix = "proj-" + suffix;
529 108 : OFile* ofile_pntr = getOFile(getCurrentFesOutputFilename(suffix),useMultipleWalkers());
530 36 : std::vector<std::string> args = getProjectionArgument(i);
531 36 : bias_expansion_pntr_->writeFesProjGridToFile(args,*ofile_pntr);
532 36 : ofile_pntr->close(); delete ofile_pntr;
533 : }
534 36 : }
535 :
536 :
537 72 : void VesLinearExpansion::writeTargetDistToFile() {
538 216 : OFile* ofile1_pntr = getOFile(getCurrentTargetDistOutputFilename(),useMultipleWalkers());
539 216 : OFile* ofile2_pntr = getOFile(getCurrentTargetDistOutputFilename("log"),useMultipleWalkers());
540 72 : bias_expansion_pntr_->writeTargetDistGridToFile(*ofile1_pntr);
541 72 : bias_expansion_pntr_->writeLogTargetDistGridToFile(*ofile2_pntr);
542 72 : ofile1_pntr->close(); delete ofile1_pntr;
543 72 : ofile2_pntr->close(); delete ofile2_pntr;
544 72 : }
545 :
546 :
547 13 : void VesLinearExpansion::writeTargetDistProjToFile() {
548 53 : for(unsigned int i=0; i<getNumberOfProjectionArguments(); i++) {
549 : std::string suffix;
550 20 : Tools::convert(i+1,suffix);
551 40 : suffix = "proj-" + suffix;
552 40 : OFile* ofile_pntr = getOFile(getCurrentTargetDistOutputFilename(suffix),useMultipleWalkers());
553 20 : std::vector<std::string> args = getProjectionArgument(i);
554 20 : bias_expansion_pntr_->writeTargetDistProjGridToFile(args,*ofile_pntr);
555 20 : ofile_pntr->close(); delete ofile_pntr;
556 : }
557 13 : }
558 :
559 :
560 0 : double VesLinearExpansion::calculateReweightFactor() const {
561 0 : return bias_expansion_pntr_->calculateReweightFactor();
562 : }
563 :
564 :
565 : }
566 5517 : }
|