diff --git a/src/Action.cpp b/src/Action.cpp index 2ac3b5bdf0b0fbd3bfd127d3033b4fe206f7ecaf..3da7ff8405417f9c24603cd391f8fed0393451cc 100644 --- a/src/Action.cpp +++ b/src/Action.cpp @@ -109,6 +109,11 @@ void Action::calculateNumericalDerivatives(){ assert(0); } +void Action::prepare(){ + return; +} + + diff --git a/src/Action.h b/src/Action.h index b432074e8d06d3c99ac8f1d10df97ef1d184ca8f..0af1fdf83df93f78313672a21f053c3511c4c54e 100644 --- a/src/Action.h +++ b/src/Action.h @@ -107,6 +107,13 @@ public: PlumedCommunicator& comm; +/// Prepare an Action for calculation +/// This can be used by Action if they need some special preparation +/// before calculation. Typical case is for collective variables +/// which would like to change their list of requested atoms. +/// By default (if not overridden) does nothing. + virtual void prepare(); + /// Calculate an Action. /// This method is called one or more times per step. /// The set of all Actions is calculated in forward order. @@ -114,7 +121,7 @@ public: /// Apply an Action. /// This method is called one time per step. -/// The set of all Actions is applied in backword order. +/// The set of all Actions is applied in backward order. virtual void apply()=0; /// Tell to the Action to flush open files diff --git a/src/PlumedMain.cpp b/src/PlumedMain.cpp index 5df10ce54c76efdbcf0a0fee10c5fd1e9bc84496..cffdd38646d5e36ac441fb7ed8d6996d583f9a93 100644 --- a/src/PlumedMain.cpp +++ b/src/PlumedMain.cpp @@ -373,8 +373,6 @@ void PlumedMain::prepareDependencies(){ atoms.setCollectEnergy(false); -// activate all the actions which are on step -// activation is recursive and enables also the dependencies for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();p++){ (*p)->deactivate(); if(Colvar *c=dynamic_cast<Colvar*>(*p)) { @@ -382,13 +380,19 @@ void PlumedMain::prepareDependencies(){ } } +// activate all the actions which are on step +// activation is recursive and enables also the dependencies for(unsigned i=0;i<pilots.size();++i){ if(pilots[i]->onStep()){ pilots[i]->activate(); active=true; } }; -} + +// allow actions to update their request list before atoms are shared + for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();p++) + if((*p)->isActive()) (*p)->prepare(); + } void PlumedMain::shareData(){ if(active)atoms.share();