LCOV - code coverage report
Current view: top level - generic - DumpProjections.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 38 38 100.0 %
Date: 2024-10-18 14:00:25 Functions: 8 10 80.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2023 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             : #include "core/ActionPilot.h"
      23             : #include "core/ActionWithValue.h"
      24             : #include "core/ActionWithArguments.h"
      25             : #include "core/ActionRegister.h"
      26             : #include "tools/File.h"
      27             : 
      28             : namespace PLMD {
      29             : namespace generic {
      30             : 
      31             : //+PLUMEDOC PRINTANALYSIS DUMPPROJECTIONS
      32             : /*
      33             : Dump the derivatives with respect to the input parameters for one or more objects (generally CVs, functions or biases).
      34             : 
      35             : \par Examples
      36             : 
      37             : Compute the distance between two groups and write on a file the
      38             : derivatives of this distance with respect to all the atoms of the two groups
      39             : 
      40             : \plumedfile
      41             : x1: CENTER ATOMS=1-10
      42             : x2: CENTER ATOMS=11-20
      43             : d: DISTANCE ATOMS=x1,x2
      44             : DUMPPROJECTIONS ARG=d FILE=proj STRIDE=20
      45             : \endplumedfile
      46             : 
      47             : */
      48             : //+ENDPLUMEDOC
      49             : 
      50             : class DumpProjections :
      51             :   public ActionPilot,
      52             :   public ActionWithArguments
      53             : {
      54             :   std::string file;
      55             :   std::string fmt;
      56             :   OFile of;
      57             : public:
      58           3 :   void calculate() override {}
      59             :   explicit DumpProjections(const ActionOptions&);
      60             :   static void registerKeywords(Keywords& keys);
      61           3 :   void apply() override {}
      62             :   void update() override;
      63           3 :   bool checkNeedsGradients()const override {return true;}
      64             :   ~DumpProjections();
      65             : };
      66             : 
      67             : PLUMED_REGISTER_ACTION(DumpProjections,"DUMPPROJECTIONS")
      68             : 
      69           3 : void DumpProjections::registerKeywords(Keywords& keys) {
      70           3 :   Action::registerKeywords(keys);
      71           3 :   ActionPilot::registerKeywords(keys);
      72           3 :   ActionWithArguments::registerKeywords(keys);
      73           3 :   keys.use("ARG");
      74           6 :   keys.add("compulsory","STRIDE","1","the frequency with which the derivatives should be output");
      75           6 :   keys.add("compulsory","FILE","the name of the file on which to output the derivatives");
      76           6 :   keys.add("compulsory","FMT","%15.10f","the format with which the derivatives should be output");
      77           3 :   keys.use("RESTART");
      78           3 :   keys.use("UPDATE_FROM");
      79           3 :   keys.use("UPDATE_UNTIL");
      80           3 : }
      81             : 
      82           1 : DumpProjections::DumpProjections(const ActionOptions&ao):
      83             :   Action(ao),
      84             :   ActionPilot(ao),
      85             :   ActionWithArguments(ao),
      86           1 :   fmt("%15.10f")
      87             : {
      88           2 :   parse("FILE",file);
      89           1 :   if( file.length()==0 ) error("filename not specified");
      90           1 :   parse("FMT",fmt);
      91           1 :   fmt=" "+fmt;
      92           1 :   of.open(file);
      93           1 :   log.printf("  on file %s\n",file.c_str());
      94           1 :   log.printf("  with format %s\n",fmt.c_str());
      95           1 :   checkRead();
      96             : 
      97           3 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
      98           2 :     (getPntrToArgument(i)->getPntrToAction())->turnOnDerivatives();
      99             :   }
     100           1 : }
     101             : 
     102             : 
     103           3 : void DumpProjections::update() {
     104           6 :   of.fmtField(" %f").printField("time",getTime());
     105           9 :   for(unsigned i=0; i<getNumberOfArguments(); i++) {
     106          18 :     for(unsigned j=0; j<getNumberOfArguments(); j++) {
     107          12 :       of.fmtField(fmt);
     108          24 :       of.printField(getPntrToArgument(i)->getName()+"-"+getPntrToArgument(j)->getName(),getProjection(i,j));
     109             :     }
     110             :   }
     111           3 :   of.printField();
     112           3 : }
     113             : 
     114           2 : DumpProjections::~DumpProjections() {
     115           2 : }
     116             : 
     117             : }
     118             : 
     119             : 
     120             : }

Generated by: LCOV version 1.16