LCOV - code coverage report
Current view: top level - analysis - Commit.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 67 69 97.1 %
Date: 2018-12-19 07:49:13 Functions: 11 12 91.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-2018 The plumed team
       3             :    (see the PEOPLE file at the root of the distribution for a list of names)
       4             : 
       5             :    See http://www.plumed.org for more information.
       6             : 
       7             :    This file is part of plumed, version 2.
       8             : 
       9             :    plumed 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             :    plumed 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 plumed.  If not, see <http://www.gnu.org/licenses/>.
      21             : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
      22             : 
      23             : #include "core/ActionPilot.h"
      24             : #include "core/ActionWithArguments.h"
      25             : #include "core/ActionRegister.h"
      26             : #include "core/PlumedMain.h"
      27             : 
      28             : namespace PLMD {
      29             : namespace analysis {
      30             : 
      31             : //+PLUMEDOC PRINTANALYSIS COMMITTOR
      32             : /*
      33             : Does a committor analysis.
      34             : 
      35             : \par Examples
      36             : 
      37             : The following input monitors two torsional angles during a simulation,
      38             : defines two basins (A and B) as a function of the two torsions and
      39             : stops the simulation when it falls in one of the two. In the log
      40             : file will be shown the latest values for the CVs and the basin reached.
      41             : \verbatim
      42             : TORSION ATOMS=1,2,3,4 LABEL=r1
      43             : TORSION ATOMS=2,3,4,5 LABEL=r2
      44             : COMMITTOR ...
      45             :   ARG=r1,r2
      46             :   STRIDE=10
      47             :   BASIN_LL1=0.15,0.20
      48             :   BASIN_UL1=0.25,0.40
      49             :   BASIN_LL2=-0.25,-0.40
      50             :   BASIN_UL2=-0.15,-0.20
      51             : ... COMMITTOR
      52             : \endverbatim
      53             : 
      54             : */
      55             : //+ENDPLUMEDOC
      56             : 
      57           2 : class Committor :
      58             :   public ActionPilot,
      59             :   public ActionWithArguments
      60             : {
      61             : private:
      62             :   std::string file;
      63             :   OFile ofile;
      64             :   std::string fmt;
      65             :   std::vector< std::vector<double> > lowerlimits;
      66             :   std::vector< std::vector<double> > upperlimits;
      67             :   unsigned nbasins;
      68             : public:
      69             :   static void registerKeywords( Keywords& keys );
      70             :   explicit Committor(const ActionOptions&ao);
      71             :   void calculate();
      72          12 :   void apply() {}
      73             : };
      74             : 
      75        2524 : PLUMED_REGISTER_ACTION(Committor,"COMMITTOR")
      76             : 
      77           2 : void Committor::registerKeywords( Keywords& keys ) {
      78           2 :   Action::registerKeywords(keys);
      79           2 :   ActionPilot::registerKeywords(keys);
      80           2 :   ActionWithArguments::registerKeywords(keys);
      81           2 :   keys.use("ARG");
      82           2 :   keys.add("numbered", "BASIN_LL","List of lower limits for basin #");
      83           2 :   keys.add("numbered", "BASIN_UL","List of upper limits for basin #");
      84           2 :   keys.reset_style("BASIN_LL","compulsory"); keys.reset_style("BASIN_UL","compulsory");
      85           2 :   keys.add("compulsory","STRIDE","1","the frequency with which the CVs are analysed");
      86           2 :   keys.add("optional","FILE","the name of the file on which to output the reached basin");
      87           2 :   keys.add("optional","FMT","the format that should be used to output real numbers");
      88           2 : }
      89             : 
      90           1 : Committor::Committor(const ActionOptions&ao):
      91             :   Action(ao),
      92             :   ActionPilot(ao),
      93             :   ActionWithArguments(ao),
      94           1 :   fmt("%f")
      95             : {
      96           1 :   ofile.link(*this);
      97           1 :   parse("FILE",file);
      98           1 :   if(file.length()>0) {
      99           1 :     ofile.open(file);
     100           1 :     log.printf("  on file %s\n",file.c_str());
     101             :   } else {
     102           0 :     log.printf("  on plumed log file\n");
     103           0 :     ofile.link(log);
     104             :   }
     105           1 :   parse("FMT",fmt);
     106           1 :   fmt=" "+fmt;
     107           1 :   log.printf("  with format %s\n",fmt.c_str());
     108             : 
     109           1 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) ofile.setupPrintValue( getPntrToArgument(i) );
     110             : 
     111           4 :   for(unsigned b=1;; ++b ) {
     112             : 
     113           7 :     std::vector<double> tmpl, tmpu;
     114           4 :     parseNumberedVector("BASIN_LL", b, tmpl );
     115           4 :     parseNumberedVector("BASIN_UL", b, tmpu );
     116           4 :     if( tmpl.empty() && tmpu.empty() ) break;
     117           3 :     if( tmpl.size()!=getNumberOfArguments()) error("Wrong number of values for BASIN_LL: they should be equal to the number of arguments");
     118           3 :     if( tmpu.size()!=getNumberOfArguments()) error("Wrong number of values for BASIN_UL: they should be equal to the number of arguments");
     119           3 :     lowerlimits.push_back(tmpl);
     120           3 :     upperlimits.push_back(tmpu);
     121           3 :     nbasins=b;
     122           6 :   }
     123           1 :   checkRead();
     124             : 
     125             : 
     126           4 :   for(unsigned b=0; b<nbasins; b++) {
     127           3 :     log.printf("  BASIN %u definition:\n", b+1);
     128           9 :     for(unsigned i=0; i<getNumberOfArguments(); ++i) {
     129           6 :       if(lowerlimits[b][i]>upperlimits[b][i]) error("COMMITTOR: UPPER bounds must always be greater than LOWER bounds");
     130           6 :       log.printf(" %f - %f\n", lowerlimits[b][i], upperlimits[b][i]);
     131             :     }
     132             :   }
     133           1 : }
     134             : 
     135          12 : void Committor::calculate() {
     136          12 :   std::vector<unsigned> inbasin;
     137          12 :   inbasin.assign (nbasins,1);
     138             : 
     139          48 :   for(unsigned b=0; b<nbasins; ++b) {
     140         108 :     for(unsigned i=0; i<getNumberOfArguments(); ++i) {
     141          72 :       if(getArgument(i)>lowerlimits[b][i]&&getArgument(i)<upperlimits[b][i]) inbasin[b]*=1; else inbasin[b]*=0;
     142             :     }
     143             :   }
     144             : 
     145          48 :   for(unsigned b=0; b<nbasins; ++b) {
     146          36 :     if(inbasin[b]==1) {
     147           1 :       ofile.fmtField(" %f");
     148           1 :       ofile.printField("time",getTime());
     149           3 :       for(unsigned i=0; i<getNumberOfArguments(); i++) {
     150           2 :         ofile.fmtField(fmt);
     151           2 :         ofile.printField( getPntrToArgument(i), getArgument(i) );
     152             :       }
     153           1 :       ofile.printField();
     154           1 :       std::string num; Tools::convert( b+1, num );
     155           2 :       std::string str = "COMMITED TO BASIN " + num;
     156           1 :       ofile.addConstantField(str);
     157           1 :       ofile.printField();
     158           1 :       ofile.flush();
     159           2 :       plumed.stop();
     160             :     }
     161          12 :   }
     162          12 : }
     163             : 
     164             : }
     165        2523 : }

Generated by: LCOV version 1.13