From 4bb2fb1c556ae9ce569b8f638c579f03c07f13b6 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Mon, 5 Dec 2011 11:19:35 +0100 Subject: [PATCH] Added virtual method update() to Action Small change in the mani flow. Now, after the backward loop to apply forces, there is another forward loop calling "update()". update() should be used to dump/analyse data, and/or to modify a biasing potential (e.g. in metadynamics or tamd). Also, since it is called after full calculation, analysis tools could access to more quantities (e.g.: forces on a specific CV have been already computed and could be dumped). --- src/Action.h | 5 +++++ src/GenericDumpAtoms.cpp | 5 +++-- src/GenericDumpDerivatives.cpp | 5 +++-- src/GenericPrint.cpp | 5 +++-- src/PlumedMain.cpp | 4 ++++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Action.h b/src/Action.h index 288b5b634..d24a4ccc5 100644 --- a/src/Action.h +++ b/src/Action.h @@ -128,6 +128,11 @@ public: /// The set of all Actions is applied in backward order. virtual void apply()=0; +/// Update. +/// This method is called one time per step. +/// The set of all Actions is updated in forward order. + virtual void update(){}; + /// Tell to the Action to flush open files void fflush(); diff --git a/src/GenericDumpAtoms.cpp b/src/GenericDumpAtoms.cpp index e10a56a49..a622dca2e 100644 --- a/src/GenericDumpAtoms.cpp +++ b/src/GenericDumpAtoms.cpp @@ -34,7 +34,8 @@ public: GenericDumpAtoms(const ActionOptions&); ~GenericDumpAtoms(); void calculate(){}; - void apply(); + void apply(){}; + void update(); }; PLUMED_REGISTER_ACTION(GenericDumpAtoms,"DUMPATOMS") @@ -54,7 +55,7 @@ GenericDumpAtoms::GenericDumpAtoms(const ActionOptions&ao): requestAtoms(atoms); } -void GenericDumpAtoms::apply(){ +void GenericDumpAtoms::update(){ fprintf(fp,"%d\n",getNatoms()); const Tensor & t(getPbc().getBox()); if(getPbc().isOrthorombic()){ diff --git a/src/GenericDumpDerivatives.cpp b/src/GenericDumpDerivatives.cpp index ee140a421..99ba01660 100644 --- a/src/GenericDumpDerivatives.cpp +++ b/src/GenericDumpDerivatives.cpp @@ -47,7 +47,8 @@ public ActionWithArguments public: void calculate(){}; GenericDumpDerivatives(const ActionOptions&); - void apply(); + void apply(){}; + void update(); ~GenericDumpDerivatives(); }; @@ -81,7 +82,7 @@ fp(NULL) } -void GenericDumpDerivatives::apply(){ +void GenericDumpDerivatives::update(){ if(comm.Get_rank()!=0)return; const std::vector<Value*>& arguments(getArguments()); unsigned npar=arguments[0]->getDerivatives().size(); diff --git a/src/GenericPrint.cpp b/src/GenericPrint.cpp index 5f47bc2ff..8dab95392 100644 --- a/src/GenericPrint.cpp +++ b/src/GenericPrint.cpp @@ -58,7 +58,8 @@ public: void calculate(){}; void prepare(); GenericPrint(const ActionOptions&); - void apply(); + void apply(){}; + void update(); ~GenericPrint(); }; @@ -123,7 +124,7 @@ void GenericPrint::prepare(){ ///////////////////////////////////////// } -void GenericPrint::apply(){ +void GenericPrint::update(){ if(comm.Get_rank()!=0)return; if(!fp){ log.printf("PRINT:"); diff --git a/src/PlumedMain.cpp b/src/PlumedMain.cpp index b368b912c..c4936347c 100644 --- a/src/PlumedMain.cpp +++ b/src/PlumedMain.cpp @@ -471,6 +471,10 @@ void PlumedMain::justApply(){ // this is updating the MD copy of the forces atoms.updateForces(); +// update step (for statistics, etc) + for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();++p){ + if((*p)->isActive()) (*p)->update(); + } } void PlumedMain::load(std::vector<std::string> & words){ -- GitLab