Skip to content

Commit

Permalink
Rewritten code for getting the descriptions of values so that we get …
Browse files Browse the repository at this point in the history
…keywords in a way that will work with LOAD
  • Loading branch information
Gareth Aneurin Tribello committed May 22, 2024
1 parent 2434e5c commit 9da68cb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/cltools/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "core/ActionWithValue.h"
#include "core/ActionWithVirtualAtom.h"
#include "core/ActionShortcut.h"
#include "core/ActionRegister.h"
#include "tools/Communicator.h"
#include "tools/Random.h"
#include "tools/Pbc.h"
Expand Down Expand Up @@ -788,7 +787,7 @@ int Driver<real>::main(FILE* in,FILE*out,Communicator& pc) {
}
ActionWithValue* av=dynamic_cast<ActionWithValue*>(pp.get());
if( av && av->getNumberOfComponents()>0 ) {
Keywords keys; actionRegister().getKeywords( av->getName(), keys );
Keywords keys; p.getKeywordsForAction( av->getName(), keys );
if( firsta ) { valuefile.printf(" \"%s\" : {\n \"action\" : \"%s\"", av->getLabel().c_str(), keys.getDisplayName().c_str() ); firsta=false; }
else valuefile.printf(",\n \"%s\" : {\n \"action\" : \"%s\"", av->getLabel().c_str(), keys.getDisplayName().c_str() );
for(unsigned i=0; i<av->getNumberOfComponents(); ++i) {
Expand All @@ -808,7 +807,7 @@ int Driver<real>::main(FILE* in,FILE*out,Communicator& pc) {

if( firsta ) { valuefile.printf(" \"shortcut_%s\" : {\n \"action\" : \"%s\"", as->getShortcutLabel().c_str(), as->getName().c_str() ); firsta=false; }
else valuefile.printf(",\n \"shortcut_%s\" : {\n \"action\" : \"%s\"", as->getShortcutLabel().c_str(), as->getName().c_str() );
Keywords keys; actionRegister().getKeywords( as->getName(), keys );
Keywords keys; p.getKeywordsForAction( as->getName(), keys );
for(unsigned i=0; i<cnames.size(); ++i) {
ActionWithValue* av2=p.getActionSet().selectWithLabel<ActionWithValue*>( cnames[i] );
if( !av2 ) plumed_merror("could not find value created by shortcut with name " + cnames[i] );
Expand Down
4 changes: 4 additions & 0 deletions src/core/ActionRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ bool ActionRegister::getKeywords(const std::string& action, Keywords& keys) {
return false;
}

void ActionRegister::getKeywords(const std::vector<void*> & images, const std::string& action, Keywords& keys) {
auto content=get(images,action); keys.thisactname = action; content.keys(keys);
}

}
1 change: 1 addition & 0 deletions src/core/ActionRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ActionRegister:
bool printManual(const std::string& action, const bool& vimout, const bool& spellout);
/// Retrieve a keywords object for a particular action
bool getKeywords( const std::string& action, Keywords& keys );
void getKeywords(const std::vector<void*> & images, const std::string& action, Keywords& keys);
/// Print out a template command for an action
bool printTemplate(const std::string& action, bool include_optional);
std::vector<std::string> getActionNames() const;
Expand Down
4 changes: 4 additions & 0 deletions src/core/PlumedMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,10 @@ bool PlumedMain::parseOnlyMode() const {
return doParseOnly;
}

void PlumedMain::getKeywordsForAction( const std::string& action, Keywords& keys ) const {
actionRegister().getKeywords( dlloader.getHandles(), action, keys );
}

#ifdef __PLUMED_HAS_PYTHON
// This is here to stop cppcheck throwing an error
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/core/PlumedMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class FileBase;
class TypesafePtr;
class IFile;
class Units;
class Keywords;
class DataPassingTools;

/**
Expand Down Expand Up @@ -523,6 +524,8 @@ class PlumedMain:
void plumedQuantityToMD( const std::string& unit, const double& eng, const TypesafePtr & m) const ;
/// Take a typesafe pointer from the MD code and convert it to a double
double MDQuantityToPLUMED( const std::string& unit, const TypesafePtr & m) const ;
/// Get the keywords for a particular action
void getKeywordsForAction( const std::string& action, Keywords& keys ) const ;
};

/////
Expand Down

0 comments on commit 9da68cb

Please sign in to comment.