From 98fb5a2910d7c29c0487c5a83d84666cb7f5693e Mon Sep 17 00:00:00 2001
From: Carlo Camilloni <carlo.camilloni@gmail.com>
Date: Wed, 8 Feb 2017 14:32:04 +0100
Subject: [PATCH] PBMETAD: default names for GRID files

---
 CHANGES/v2.4.txt     | 3 ++-
 src/bias/PBMetaD.cpp | 9 ++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/CHANGES/v2.4.txt b/CHANGES/v2.4.txt
index 17a7dd146..7a6a6df6f 100644
--- a/CHANGES/v2.4.txt
+++ b/CHANGES/v2.4.txt
@@ -6,6 +6,7 @@ This page contains changes that will end up in 2.4
 
 Changes from version 2.3 which are relevant for users:
   - \ref PBMETAD : multiple walkers using files (thanks to Marco De La Pierre).
-  - \ref PBMETAD : adaptive gaussians 
+  - \ref PBMETAD : adaptive gaussians
+  - \ref PBMETAD : default names for GRID and FILE (usefull with many collective variables) 
   - \ref IMPLICIT : EEF1-SB implicit solvent solvation energy
 */
diff --git a/src/bias/PBMetaD.cpp b/src/bias/PBMetaD.cpp
index cbe34fde4..14a988dd5 100644
--- a/src/bias/PBMetaD.cpp
+++ b/src/bias/PBMetaD.cpp
@@ -286,15 +286,15 @@ void PBMetaD::registerKeywords(Keywords& keys){
   keys.use("ARG");
   keys.add("compulsory","SIGMA","the widths of the Gaussian hills");
   keys.add("compulsory","PACE","the frequency for hill addition, one for all biases");
-  keys.add("optional","FILE","files in which the lists of added hills are stored");
+  keys.add("optional","FILE","files in which the lists of added hills are stored, default names are assigned using arguments if FILE is not found");
   keys.add("optional","HEIGHT","the height of the Gaussian hills, one for all biases. Compulsory unless TAU, TEMP and BIASFACTOR are given");
   keys.add("optional","FMT","specify format for HILLS files (useful for decrease the number of digits in regtests)");
   keys.add("optional","BIASFACTOR","use well tempered metadynamics with this biasfactor, one for all biases.  Please note you must also specify temp");
   keys.add("optional","TEMP","the system temperature - this is only needed if you are doing well-tempered metadynamics");
   keys.add("optional","TAU","in well tempered metadynamics, sets height to (kb*DeltaT*pace*timestep)/tau");
   keys.add("optional","GRID_RFILES", "read grid for the bias");
-  keys.add("optional","GRID_WFILES", "dump grid for the bias");
   keys.add("optional","GRID_WSTRIDE", "frequency for dumping the grid");
+  keys.add("optional","GRID_WFILES", "dump grid for the bias, default names are used if GRID_WSTRIDE is used without GRID_WFILES.");
   keys.add("optional","GRID_MIN","the lower bounds for the grid");
   keys.add("optional","GRID_MAX","the upper bounds for the grid");
   keys.add("optional","GRID_BIN","the number of bins for the grid");
@@ -449,12 +449,15 @@ isFirstStep(true)
   parseFlag("WALKERS_MPI",walkers_mpi);
 
   // Grid file
+  parse("GRID_WSTRIDE",wgridstride_);
   vector<string> gridfilenames_;
   parseVector("GRID_WFILES",gridfilenames_);
-  parse("GRID_WSTRIDE",wgridstride_);
   if (wgridstride_ == 0 && gridfilenames_.size() > 0) {
     error("frequency with which to output grid not specified use GRID_WSTRIDE");
   }
+  if(gridfilenames_.size()==0 && wgridstride_ > 0) {
+    for(unsigned i=0;i<getNumberOfArguments();i++) gridfilenames_.push_back("GRID."+getPntrToArgument(i)->getName());
+  } 
   if(gridfilenames_.size() > 0 && hillsfname.size() > 0 && gridfilenames_.size() != hillsfname.size()) 
     error("number of GRID_WFILES arguments does not match number of HILLS files");
 
-- 
GitLab