Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set CVC description consistently #568

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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