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