Skip to content

Commit

Permalink
Modified the way the documentation is got when you output the value d…
Browse files Browse the repository at this point in the history
…ictionary in driver so that you can use action labels that have dots in them

Also added a warning to try to stop people from using dots in the labels for actions as it is not a great idea
  • Loading branch information
Gareth Aneurin Tribello committed May 22, 2024
1 parent 9da68cb commit 43c263d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/cltools/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,13 @@ int Driver<real>::main(FILE* in,FILE*out,Communicator& pc) {
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) {
Value* myval = av->copyOutput(i); std::string compname = myval->getName(), description; std::size_t dot=compname.find(".");
if( dot!=std::string::npos ) {
std::string cname = compname.substr(dot+1); description = av->getOutputComponentDescription( cname, keys );
} else description = keys.getOutputComponentDescription(".#!value");
Value* myval = av->copyOutput(i); std::string compname = myval->getName(), description;
if( av->getLabel()==compname ) {
description = keys.getOutputComponentDescription(".#!value");
} else {
std::size_t dot=compname.find(av->getLabel() + "."); std::string cname = compname.substr(dot + av->getLabel().length() + 1);
description = av->getOutputComponentDescription( cname, keys );
}
if( description.find("\\")!=std::string::npos ) error("found invalid backslash character in documentation for component " + compname + " in action " + av->getName() + " with label " + av->getLabel() );
valuefile.printf(",\n \"%s\" : { \"type\": \"%s\", \"description\": \"%s\" }", myval->getName().c_str(), myval->getValueType().c_str(), description.c_str() );
}
Expand All @@ -819,10 +822,13 @@ int Driver<real>::main(FILE* in,FILE*out,Communicator& pc) {
valuefile.printf(",\n \"%s\" : { \"type\": \"%s\", \"description\": \"%s\" }", myval->getName().c_str(), myval->getValueType().c_str(), description.c_str() );
} else {
for(unsigned j=0; j<av2->getNumberOfComponents(); ++j) {
Value* myval = av2->copyOutput(j); std::string compname = myval->getName(), description; std::size_t dot=compname.find(".");
if( dot!=std::string::npos ) {
std::string cname = compname.substr(dot+1); description = av2->getOutputComponentDescription( cname, keys );
} else plumed_merror("should not be outputting description of value from action when using shortcuts");
Value* myval = av2->copyOutput(j); std::string compname = myval->getName(), description;
if( av2->getLabel()==compname ) {
plumed_merror("should not be outputting description of value from action when using shortcuts");
} else {
std::size_t dot=compname.find(av2->getLabel() + "."); std::string cname = compname.substr(dot+av2->getLabel().length() + 1);
description = av2->getOutputComponentDescription( cname, keys );
}
if( description.find("\\")!=std::string::npos ) error("found invalid backslash character in documentation for component " + compname + " in action " + av2->getName() + " with label " + av2->getLabel() );
valuefile.printf(",\n \"%s\" : { \"type\": \"%s\", \"description\": \"%s\" }", myval->getName().c_str(), myval->getValueType().c_str(), description.c_str() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Action::Action(const ActionOptions&ao):
if(label.length()==0) {
std::string s; Tools::convert(plumed.getActionSet().size()-plumed.getActionSet().select<ActionForInterface*>().size(),s);
label="@"+s;
}
} else if ( label.find(".")!=std::string::npos ) warning("using full stop in an action label should be avaoided as . has a special meaning in PLUMED action labels");
if( plumed.getActionSet().selectWithLabel<Action*>(label) ) error("label " + label + " has been already used");
if( !keywords.exists("NO_ACTION_LOG") ) log.printf(" with label %s\n",label.c_str());
if ( keywords.exists("UPDATE_FROM") ) parse("UPDATE_FROM",update_from);
Expand Down

0 comments on commit 43c263d

Please sign in to comment.