Skip to content

Commit

Permalink
Set CVC description consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
jhenin committed Aug 19, 2023
1 parent 33a96fd commit 9d0f7da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/colvarcomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ colvar::cvc::cvc(std::string const &conf)
}


int colvar::cvc::update_description()
{
if (name.size() > 0) {
description = "cvc " + name;
} else {
description = "unnamed cvc";
}
if (function_type.size() > 0) {
description += " of type \"" + function_type + "\"";
} else {
description += " of unset type";
}
return COLVARS_OK;
}


int colvar::cvc::set_function_type(std::string const &type)
{
function_type = type;
Expand All @@ -53,6 +69,8 @@ int colvar::cvc::set_function_type(std::string const &type)
function_types.push_back(function_type);
}
}
update_description();

for (size_t i = function_types.size()-1; i > 0; i--) {
cvm::main()->cite_feature(function_types[i]+" colvar component"+
" (derived from "+function_types[i-1]+")");
Expand All @@ -74,18 +92,14 @@ int colvar::cvc::init(std::string const &conf)
}

if (get_keyval(conf, "name", name, name)) {
if (name.size() > 0) {
description = "cvc \"" + name + "\" of type " + function_type;
} else {
description = "unnamed cvc";
}
if ((name != old_name) && (old_name.size() > 0)) {
cvm::error("Error: cannot rename component \""+old_name+
"\" after initialization (new name = \""+name+"\")",
COLVARS_INPUT_ERROR);
name = old_name;
}
}
update_description();

get_keyval(conf, "componentCoeff", sup_coeff, sup_coeff);
get_keyval(conf, "componentExp", sup_np, sup_np);
Expand Down Expand Up @@ -314,7 +328,7 @@ int colvar::cvc::init_dependencies() {

int colvar::cvc::setup()
{
description = "cvc " + name;
update_description();
return COLVARS_OK;
}

Expand Down
3 changes: 3 additions & 0 deletions src/colvarcomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ class colvar::cvc

protected:

/// Update the description string based on name and type
int update_description();

/// Record the type of this class as well as those it is derived from
std::vector<std::string> function_types;

Expand Down

0 comments on commit 9d0f7da

Please sign in to comment.