| version 1.7 | version 1.8 |
|---|
| |
| // -*- c++ -*- | // -*- c++ -*- |
| | |
| | // This file is part of the Collective Variables module (Colvars). |
| | // The original version of Colvars and its updates are located at: |
| | // https://github.com/colvars/colvars |
| | // Please update all Colvars source files before making any changes. |
| | // If you wish to distribute your changes, please submit them to the |
| | // Colvars repository at GitHub. |
| | |
| #include <cstdlib> | #include <cstdlib> |
| #include <stdlib.h> | #include <stdlib.h> |
| #include <string.h> | #include <string.h> |
| | |
| #include "colvarscript.h" | #include "colvarscript.h" |
| | #include "colvardeps.h" |
| | |
| | |
| colvarscript::colvarscript(colvarproxy *p) | colvarscript::colvarscript(colvarproxy *p) |
| |
| } | } |
| | |
| if (subcmd == "delete") { | if (subcmd == "delete") { |
| if (cv->biases.size() > 0) { | size_t i; |
| result = "Cannot delete a colvar currently used by biases, delete those biases first"; | for (i = 0; i < cv->biases.size(); i++) { |
| return COLVARSCRIPT_ERROR; | delete cv->biases[i]; |
| } | } |
| | cv->biases.resize(0); |
| // colvar destructor is tasked with the cleanup | // colvar destructor is tasked with the cleanup |
| delete cv; | delete cv; |
| // TODO this could be done by the destructors | // TODO this could be done by the destructors |
| |
| return COLVARS_OK; | return COLVARS_OK; |
| } | } |
| | |
| if (subcmd == "state") { | if ((subcmd == "get") || (subcmd == "set") || (subcmd == "state")) { |
| cv->print_state(); | return proc_features(cv, argc, argv); |
| return COLVARS_OK; | |
| } | } |
| | |
| result = "Syntax error\n" + help_string(); | result = "Syntax error\n" + help_string(); |
| |
| return COLVARS_OK; | return COLVARS_OK; |
| } | } |
| | |
| if (subcmd == "state") { | |
| b->print_state(); | |
| return COLVARS_OK; | |
| } | |
| | |
| // Subcommands for MW ABF | // Subcommands for MW ABF |
| if (subcmd == "bin") { | if (subcmd == "bin") { |
| int r = b->current_bin(); | int r = b->current_bin(); |
| |
| return COLVARS_OK; | return COLVARS_OK; |
| } | } |
| | |
| | if ((subcmd == "get") || (subcmd == "set") || (subcmd == "state")) { |
| | return proc_features(b, argc, argv); |
| | } |
| | |
| if (argc >= 4) { | if (argc >= 4) { |
| std::string param = argv[3]; | std::string param = argv[3]; |
| if (subcmd == "count") { | if (subcmd == "count") { |
| |
| } | } |
| | |
| | |
| | int colvarscript::proc_features(colvardeps *obj, |
| | int argc, char const *argv[]) { |
| | // size was already checked before calling |
| | std::string subcmd = argv[2]; |
| | |
| | if (argc == 3) { |
| | if (subcmd == "state") { |
| | // TODO make this returned as result? |
| | obj->print_state(); |
| | return COLVARS_OK; |
| | } |
| | |
| | // get and set commands require more arguments |
| | result = "Syntax error\n" + help_string(); |
| | return COLVARSCRIPT_ERROR; |
| | } |
| | |
| | if ((subcmd == "get") || (subcmd == "set")) { |
| | std::vector<colvardeps::feature *> &features = obj->features(); |
| | std::string const req_feature(argv[3]); |
| | colvardeps::feature *f = NULL; |
| | int fid = 0; |
| | for (fid = 0; fid < int(features.size()); fid++) { |
| | if (features[fid]->description == |
| | colvarparse::to_lower_cppstr(req_feature)) { |
| | f = features[fid]; |
| | break; |
| | } |
| | } |
| | |
| | if (f == NULL) { |
| | |
| | result = "Error: feature \""+req_feature+"\" does not exist.\n"; |
| | return COLVARSCRIPT_ERROR; |
| | |
| | } else { |
| | |
| | if (! obj->is_available(fid)) { |
| | result = "Error: feature \""+req_feature+"\" is unavailable.\n"; |
| | return COLVARSCRIPT_ERROR; |
| | } |
| | |
| | if (subcmd == "get") { |
| | result = cvm::to_str(obj->is_enabled(fid) ? 1 : 0); |
| | return COLVARS_OK; |
| | } |
| | |
| | if (subcmd == "set") { |
| | if (argc == 5) { |
| | std::string const yesno = |
| | colvarparse::to_lower_cppstr(std::string(argv[4])); |
| | if ((yesno == std::string("yes")) || |
| | (yesno == std::string("on")) || |
| | (yesno == std::string("1"))) { |
| | obj->enable(fid); |
| | return COLVARS_OK; |
| | } else if ((yesno == std::string("no")) || |
| | (yesno == std::string("off")) || |
| | (yesno == std::string("0"))) { |
| | // TODO disable() function does not exist yet, |
| | // dependencies will not be resolved |
| | // obj->disable(fid); |
| | obj->feature_states[fid]->enabled = false; |
| | return COLVARS_OK; |
| | } |
| | } |
| | result = "Syntax error\n" + help_string(); |
| | return COLVARSCRIPT_ERROR; |
| | } |
| | } |
| | } |
| | |
| | result = "Syntax error\n" + help_string(); |
| | return COLVARSCRIPT_ERROR; |
| | } |
| | |
| | |
| std::string colvarscript::help_string() | std::string colvarscript::help_string() |
| { | { |
| std::string buf; | std::string buf; |
| |
| colvar <name> addforce <F> -- apply given force on colvar <name>\n\ | colvar <name> addforce <F> -- apply given force on colvar <name>\n\ |
| colvar <name> getconfig -- return config string of colvar <name>\n\ | colvar <name> getconfig -- return config string of colvar <name>\n\ |
| colvar <name> cvcflags <fl> -- enable or disable cvcs according to 0/1 flags\n\ | colvar <name> cvcflags <fl> -- enable or disable cvcs according to 0/1 flags\n\ |
| | colvar <name> get <f> -- get the value of the colvar feature <f>\n\ |
| | colvar <name> set <f> <val> -- set the value of the colvar feature <f>\n\ |
| \n\ | \n\ |
| Accessing biases:\n\ | Accessing biases:\n\ |
| bias <name> energy -- return the current energy of bias <name>\n\ | bias <name> energy -- return the current energy of bias <name>\n\ |
| bias <name> update -- recalculate bias <name>\n\ | bias <name> update -- recalculate bias <name>\n\ |
| bias <name> delete -- delete bias <name>\n\ | bias <name> delete -- delete bias <name>\n\ |
| bias <name> getconfig -- return config string of bias <name>\n"; | bias <name> getconfig -- return config string of bias <name>\n\ |
| | bias <name> get <f> -- get the value of the bias feature <f>\n\ |
| | bias <name> set <f> <val> -- set the value of the bias feature <f>\n\ |
| | "; |
| | |
| return buf; | return buf; |
| } | } |