LCOV - code coverage report
Current view: top level - generic - DumpProjections.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 39 40 97.5 %
Date: 2026-03-30 11:13:23 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             :   std::string file;
      54             :   std::string fmt;
      55             :   OFile of;
      56             : public:
      57           3 :   void calculate() override {}
      58             :   explicit DumpProjections(const ActionOptions&);
      59             :   static void registerKeywords(Keywords& keys);
      60           3 :   void apply() override {}
      61             :   void update() override;
      62           3 :   bool checkNeedsGradients()const override {
      63           3 :     return true;
      64             :   }
      65             :   ~DumpProjections();
      66             : };
      67             : 
      68             : PLUMED_REGISTER_ACTION(DumpProjections,"DUMPPROJECTIONS")
      69             : 
      70           5 : void DumpProjections::registerKeywords(Keywords& keys) {
      71           5 :   Action::registerKeywords(keys);
      72           5 :   ActionPilot::registerKeywords(keys);
      73           5 :   ActionWithArguments::registerKeywords(keys);
      74           5 :   keys.use("ARG");
      75          10 :   keys.add("compulsory","STRIDE","1","the frequency with which the derivatives should be output");
      76          10 :   keys.add("compulsory","FILE","the name of the file on which to output the derivatives");
      77          10 :   keys.add("compulsory","FMT","%15.10f","the format with which the derivatives should be output");
      78           5 :   keys.use("RESTART");
      79           5 :   keys.use("UPDATE_FROM");
      80           5 :   keys.use("UPDATE_UNTIL");
      81           5 : }
      82             : 
      83           1 : DumpProjections::DumpProjections(const ActionOptions&ao):
      84             :   Action(ao),
      85             :   ActionPilot(ao),
      86             :   ActionWithArguments(ao),
      87           1 :   fmt("%15.10f") {
      88           2 :   parse("FILE",file);
      89           1 :   if( file.length()==0 ) {
      90           0 :     error("filename not specified");
      91             :   }
      92           1 :   parse("FMT",fmt);
      93           1 :   fmt=" "+fmt;
      94           1 :   of.open(file);
      95           1 :   log.printf("  on file %s\n",file.c_str());
      96           1 :   log.printf("  with format %s\n",fmt.c_str());
      97           1 :   checkRead();
      98             : 
      99           3 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) {
     100           2 :     (getPntrToArgument(i)->getPntrToAction())->turnOnDerivatives();
     101             :   }
     102           1 : }
     103             : 
     104             : 
     105           3 : void DumpProjections::update() {
     106           6 :   of.fmtField(" %f").printField("time",getTime());
     107           9 :   for(unsigned i=0; i<getNumberOfArguments(); i++) {
     108          18 :     for(unsigned j=0; j<getNumberOfArguments(); j++) {
     109          12 :       of.fmtField(fmt);
     110          24 :       of.printField(getPntrToArgument(i)->getName()+"-"+getPntrToArgument(j)->getName(),getProjection(i,j));
     111             :     }
     112             :   }
     113           3 :   of.printField();
     114           3 : }
     115             : 
     116           2 : DumpProjections::~DumpProjections() {
     117           2 : }
     118             : 
     119             : }
     120             : 
     121             : 
     122             : }

Generated by: LCOV version 1.16