From 418902a630a804c18a6b4513a6e2500c7787fbab Mon Sep 17 00:00:00 2001 From: Gareth Aneurin Tribello Date: Sun, 2 Jun 2024 10:35:02 +0100 Subject: [PATCH] Fix for passing of timestep If a person implementing an interface with an MD code calls setMDTimeUnits after the call to setTimestep then the timestep will not be in the correct units. This fix resolves that problem. --- src/core/Action.cpp | 8 ++++++-- src/core/Action.h | 3 +++ src/core/PlumedMain.cpp | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/Action.cpp b/src/core/Action.cpp index 27e3bb8272..0e1e24c8a4 100644 --- a/src/core/Action.cpp +++ b/src/core/Action.cpp @@ -79,8 +79,7 @@ Action::Action(const ActionOptions&ao): keywords(ao.keys) { // Retrieve the timestep and save it - ActionWithValue* ts = plumed.getActionSet().selectWithLabel("timestep"); - if( ts ) timestep = (ts->copyOutput(0))->get(); + resetStoredTimestep(); line.erase(line.begin()); if( !keywords.exists("NO_ACTION_LOG") ) { @@ -116,6 +115,11 @@ Action::Action(const ActionOptions&ao): } } +void Action::resetStoredTimestep() { + ActionWithValue* ts = plumed.getActionSet().selectWithLabel("timestep"); + if( ts ) timestep = (ts->copyOutput(0))->get(); +} + Action::~Action() { if(files.size()!=0) { std::cerr<<"WARNING: some files open in action "+getLabel()+" where not properly closed. This could lead to data loss!!\n"; diff --git a/src/core/Action.h b/src/core/Action.h index eb6ba11b65..08a5172190 100644 --- a/src/core/Action.h +++ b/src/core/Action.h @@ -329,6 +329,9 @@ class Action { /// Get the defaults std::string getDefaultString() const ; +/// Set the timestep that is stored in the action to the correct value + void resetStoredTimestep(); + /// Get the info on what to calculate virtual std::string writeInGraph() const ; /// Specialized casts, to make PlumedMain run faster diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp index 487650bd65..a5f888088d 100644 --- a/src/core/PlumedMain.cpp +++ b/src/core/PlumedMain.cpp @@ -1406,6 +1406,7 @@ void PlumedMain::setUnits( const bool& natural, const Units& u ) { passtools->usingNaturalUnits = natural; passtools->units=u; std::vector idata = actionSet.select(); for(const auto & ip : idata) ip->updateUnits( passtools.get() ); + for(const auto & p : actionSet ) p->resetStoredTimestep(); } void PlumedMain::startStep() {