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