All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DumpProjections.cpp
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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/ActionWithArguments.h"
24 #include "core/ActionRegister.h"
25 #include "tools/File.h"
26 
27 using namespace std;
28 
29 namespace PLMD{
30 namespace generic{
31 
32 //+PLUMEDOC ANALYSIS DUMPPROJECTIONS
33 /*
34 Dump the derivatives with respect to the input parameters for one or more objects (generally CVs, functions or biases).
35 
36 */
37 //+ENDPLUMEDOC
38 
40 public ActionPilot,
42 {
43  string file;
44  string fmt;
46 public:
47  void calculate(){}
49  static void registerKeywords(Keywords& keys);
50  void apply(){}
51  void update();
52  bool checkNeedsGradients()const{return true;}
53  ~DumpProjections();
54 };
55 
56 PLUMED_REGISTER_ACTION(DumpProjections,"DUMPPROJECTIONS")
57 
58 void DumpProjections::registerKeywords(Keywords& keys){
59  Action::registerKeywords(keys);
60  ActionPilot::registerKeywords(keys);
61  ActionWithArguments::registerKeywords(keys);
62  keys.use("ARG");
63  keys.add("compulsory","STRIDE","1","the frequency with which the derivatives should be output");
64  keys.add("compulsory","FILE","the name of the file on which to output the derivatives");
65  keys.add("compulsory","FMT","%15.10f","the format with which the derivatives should be output");
66 }
67 
68 DumpProjections::DumpProjections(const ActionOptions&ao):
69 Action(ao),
70 ActionPilot(ao),
72 fmt("%15.10f")
73 {
74  parse("FILE",file);
75  if( file.length()==0 ) error("filename not specified");
76  parse("FMT",fmt);
77  fmt=" "+fmt;
78  of.open(file);
79  log.printf(" on file %s\n",file.c_str());
80  log.printf(" with format %s\n",fmt.c_str());
81  checkRead();
82 }
83 
84 
86  of.fmtField(" %f").printField("time",getTime());
87  for(unsigned i=0;i<getNumberOfArguments();i++){
88  for(unsigned j=0;j<getNumberOfArguments();j++){
89  of.fmtField(fmt);
91  }
92  }
93  of.printField();
94 }
95 
97 }
98 
99 }
100 
101 
102 }
void calculate()
Calculate an Action.
Log & log
Reference to the log stream.
Definition: Action.h:93
This is used to create PLMD::Action objects that are run with some set frequency. ...
Definition: ActionPilot.h:39
void error(const std::string &msg) const
Crash calculation and print documentation.
Definition: Action.cpp:195
OFile & fmtField(const std::string &)
Set the format for writing double precision fields.
Definition: OFile.cpp:135
void checkRead()
Check if Action was properly read.
Definition: Action.cpp:161
STL namespace.
Value * getPntrToArgument(const unsigned n)
Return a pointer to specific argument.
This is used to create PLMD::Action objects that take the output from some other Action as input...
void parse(const std::string &key, T &t)
Parse one keyword as generic type.
Definition: Action.h:273
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
double getTime() const
Return the present time.
Definition: Action.cpp:173
int printf(const char *fmt,...)
Formatted output with explicit format - a la printf.
Definition: OFile.cpp:82
const std::string & getName() const
Returns the name.
Definition: Action.h:268
Base class for all the input Actions.
Definition: Action.h:60
double getProjection(unsigned i, unsigned j) const
Get the scalar product between the gradients of two variables.
Provides the keyword DUMPPROJECTIONS
bool checkNeedsGradients() const
Check if the action needs gradient.
Class for output files.
Definition: OFile.h:84
OFile & printField(const std::string &, double)
Set the value of a double precision field.
Definition: OFile.cpp:145
void apply()
Apply an Action.
unsigned getNumberOfArguments() const
Returns the number of arguments.
OFile & open(const std::string &name)
Opens the file using automatic append/backup.
Definition: OFile.cpp:264