All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DumpForces.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 DUMPFORCES
33 /*
34 Dump the force acting on one of a values in a file.
35 
36 For a CV this command will dump
37 the force on the CV itself. Be aware that in order to have the forces on the atoms
38 you should multiply the output from this argument by the output from DUMPDERIVATIVES.
39 Furthermore, also note that you can output the forces on multiple quantities simultaneously
40 by specifying more than one argument. You can control the buffering of output using the \ref FLUSH keyword.
41 
42 
43 \par Examples
44 The following input instructs plumed to write a file called forces that contains
45 the force acting on the distance between atoms 1 and 2.
46 \verbatim
47 DISTANCE ATOM=1,2 LABEL=distance
48 DUMPFORCES ARG=distance STRIDE=1 FILE=forces
49 \endverbatim
50 
51 (See also \ref DISTANCE)
52 
53 */
54 //+ENDPLUMEDOC
55 
56 class DumpForces :
57 public ActionPilot,
59 {
60  string file;
62 public:
63  void calculate(){}
64  DumpForces(const ActionOptions&);
65  static void registerKeywords(Keywords& keys);
66  void apply(){}
67  void update();
68  ~DumpForces();
69 };
70 
71 PLUMED_REGISTER_ACTION(DumpForces,"DUMPFORCES")
72 
73 void DumpForces::registerKeywords(Keywords& keys){
74  Action::registerKeywords(keys);
75  ActionPilot::registerKeywords(keys);
76  ActionWithArguments::registerKeywords(keys);
77  keys.use("ARG");
78  keys.add("compulsory","STRIDE","1","the frequency with which the forces should be output");
79  keys.add("compulsory","FILE","the name of the file on which to output the forces");
80 }
81 
82 DumpForces::DumpForces(const ActionOptions&ao):
83 Action(ao),
84 ActionPilot(ao),
86 {
87  parse("FILE",file);
88  if( file.length()==0 ) error("name of file was not specified");
89  of.link(*this);
90  of.open(file);
91  log.printf(" on file %s\n",file.c_str());
92  if( getNumberOfArguments()==0 ) error("no arguments have been specified");
93  checkRead();
94 }
95 
96 
98  of.fmtField(" %f");
99  of.printField("time",getTime());
100  for(unsigned i=0;i<getNumberOfArguments();i++){
101  of.fmtField(" %15.10f").printField(getPntrToArgument(i)->getName(),getPntrToArgument(i)->getForce());
102  }
103  of.printField();
104 }
105 
107 }
108 
109 }
110 
111 
112 }
Log & log
Reference to the log stream.
Definition: Action.h:93
void apply()
Apply an Action.
Definition: DumpForces.cpp:66
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
OFile & link(OFile &)
Allows linking this OFile to another one.
Definition: OFile.cpp:71
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
void calculate()
Calculate an Action.
Definition: DumpForces.cpp:63
const std::string & getName() const
Returns the name.
Definition: Action.h:268
Base class for all the input Actions.
Definition: Action.h:60
Provides the keyword DUMPFORCES
Definition: DumpForces.cpp:56
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
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