Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2011-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 : #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 PRINTANALYSIS 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 :
45 : The following input instructs plumed to write a file called forces that contains
46 : the force acting on the distance between atoms 1 and 2.
47 : \verbatim
48 : DISTANCE ATOM=1,2 LABEL=distance
49 : DUMPFORCES ARG=distance STRIDE=1 FILE=forces
50 : \endverbatim
51 :
52 : (See also \ref DISTANCE)
53 :
54 : */
55 : //+ENDPLUMEDOC
56 :
57 : class DumpForces :
58 : public ActionPilot,
59 : public ActionWithArguments
60 : {
61 : string file;
62 : string fmt;
63 : OFile of;
64 : public:
65 348 : void calculate() {}
66 : explicit DumpForces(const ActionOptions&);
67 : static void registerKeywords(Keywords& keys);
68 348 : void apply() {}
69 : void update();
70 : ~DumpForces();
71 : };
72 :
73 2543 : PLUMED_REGISTER_ACTION(DumpForces,"DUMPFORCES")
74 :
75 21 : void DumpForces::registerKeywords(Keywords& keys) {
76 21 : Action::registerKeywords(keys);
77 21 : ActionPilot::registerKeywords(keys);
78 21 : ActionWithArguments::registerKeywords(keys);
79 21 : keys.use("ARG");
80 21 : keys.add("compulsory","STRIDE","1","the frequency with which the forces should be output");
81 21 : keys.add("compulsory","FILE","the name of the file on which to output the forces");
82 21 : keys.add("compulsory","FMT","%15.10f","the format with which the derivatives should be output");
83 21 : keys.use("RESTART");
84 21 : keys.use("UPDATE_FROM");
85 21 : keys.use("UPDATE_UNTIL");
86 21 : }
87 :
88 20 : DumpForces::DumpForces(const ActionOptions&ao):
89 : Action(ao),
90 : ActionPilot(ao),
91 : ActionWithArguments(ao),
92 20 : fmt("%15.10f")
93 : {
94 20 : parse("FILE",file);
95 20 : if( file.length()==0 ) error("name of file was not specified");
96 20 : parse("FMT",fmt);
97 20 : fmt=" "+fmt;
98 20 : of.link(*this);
99 20 : of.open(file);
100 20 : log.printf(" on file %s\n",file.c_str());
101 20 : log.printf(" with format %s\n",fmt.c_str());
102 20 : if( getNumberOfArguments()==0 ) error("no arguments have been specified");
103 20 : checkRead();
104 20 : }
105 :
106 :
107 348 : void DumpForces::update() {
108 348 : of.fmtField(" %f");
109 348 : of.printField("time",getTime());
110 4740 : for(unsigned i=0; i<getNumberOfArguments(); i++) {
111 4392 : of.fmtField(fmt);
112 4392 : of.printField(getPntrToArgument(i)->getName(),getPntrToArgument(i)->getForce());
113 : }
114 348 : of.printField();
115 348 : }
116 :
117 60 : DumpForces::~DumpForces() {
118 60 : }
119 :
120 : }
121 :
122 :
123 2523 : }
|