version 1.5 | version 1.6 |
---|
| |
| |
if (argc < 2) { | if (argc < 2) { |
result = help_string(); | result = help_string(); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
std::string cmd = argv[1]; | std::string cmd = argv[1]; |
| |
| int error_code = COLVARS_OK; |
| |
if (cmd == "colvar") { | if (cmd == "colvar") { |
return proc_colvar(argc-1, &(argv[1])); | return proc_colvar(argc-1, &(argv[1])); |
} | } |
| |
| |
if (cmd == "version") { | if (cmd == "version") { |
result = COLVARS_VERSION; | result = COLVARS_VERSION; |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (cmd == "reset") { | if (cmd == "reset") { |
/// Delete every child object | /// Delete every child object |
colvars->reset(); | colvars->reset(); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (cmd == "delete") { | if (cmd == "delete") { |
colvars->reset(); | |
// Note: the delete bit may be ignored by some backends | // Note: the delete bit may be ignored by some backends |
// it is mostly useful in VMD | // it is mostly useful in VMD |
colvars->set_error_bits(DELETE_COLVARS); | colvars->set_error_bits(DELETE_COLVARS); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (cmd == "update") { | if (cmd == "update") { |
colvars->calc(); | error_code |= proxy->update_input(); |
return COLVARSCRIPT_OK; | error_code |= colvars->calc(); |
| error_code |= proxy->update_output(); |
| if (error_code) { |
| result += "Error updating the colvars module.\n"; |
| } |
| return error_code; |
} | } |
| |
if (cmd == "list") { | if (cmd == "list") { |
| |
++cvi) { | ++cvi) { |
result += (cvi == colvars->colvars.begin() ? "" : " ") + (*cvi)->name; | result += (cvi == colvars->colvars.begin() ? "" : " ") + (*cvi)->name; |
} | } |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} else if (argc == 3 && !strcmp(argv[2], "biases")) { | } else if (argc == 3 && !strcmp(argv[2], "biases")) { |
for (std::vector<colvarbias *>::iterator bi = colvars->biases.begin(); | for (std::vector<colvarbias *>::iterator bi = colvars->biases.begin(); |
bi != colvars->biases.end(); | bi != colvars->biases.end(); |
++bi) { | ++bi) { |
result += (bi == colvars->biases.begin() ? "" : " ") + (*bi)->name; | result += (bi == colvars->biases.begin() ? "" : " ") + (*bi)->name; |
} | } |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} else { | } else { |
result = "Wrong arguments to command \"list\"\n" + help_string(); | result = "Wrong arguments to command \"list\"\n" + help_string(); |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
| |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
} | } |
if (colvars->read_config_file(argv[2]) == COLVARS_OK) { | if (colvars->read_config_file(argv[2]) == COLVARS_OK) { |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} else { | } else { |
result = "Error parsing configuration file"; | result = "Error parsing configuration file"; |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
| |
} | } |
std::string conf = argv[2]; | std::string conf = argv[2]; |
if (colvars->read_config_string(conf) == COLVARS_OK) { | if (colvars->read_config_string(conf) == COLVARS_OK) { |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} else { | } else { |
result = "Error parsing configuration string"; | result = "Error parsing configuration string"; |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
| |
result = "Missing arguments\n" + help_string(); | result = "Missing arguments\n" + help_string(); |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
} | } |
proxy->input_prefix_str = argv[2]; | proxy->input_prefix() = argv[2]; |
if (colvars->setup_input() == COLVARS_OK) { | if (colvars->setup_input() == COLVARS_OK) { |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} else { | } else { |
result = "Error loading state file"; | result = "Error loading state file"; |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
| |
int error = 0; | int error = 0; |
error |= colvars->setup_output(); | error |= colvars->setup_output(); |
error |= colvars->write_output_files(); | error |= colvars->write_output_files(); |
return error ? COLVARSCRIPT_ERROR : COLVARSCRIPT_OK; | return error ? COLVARSCRIPT_ERROR : COLVARS_OK; |
} | } |
| |
/// Print the values that would go on colvars.traj | /// Print the values that would go on colvars.traj |
| |
std::ostringstream os; | std::ostringstream os; |
colvars->write_traj_label(os); | colvars->write_traj_label(os); |
result = os.str(); | result = os.str(); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
if (cmd == "printframe") { | if (cmd == "printframe") { |
std::ostringstream os; | std::ostringstream os; |
colvars->write_traj(os); | colvars->write_traj(os); |
result = os.str(); | result = os.str(); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (cmd == "frame") { | if (cmd == "frame") { |
if (argc == 2) { | if (argc == 2) { |
int f = proxy->frame(); | long int f; |
if (f >= 0) { | int error = proxy->get_frame(f); |
| if (error == COLVARS_OK) { |
result = cvm::to_str(f); | result = cvm::to_str(f); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} else { | } else { |
result = "Frame number is not available"; | result = "Frame number is not available"; |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
} | } |
} else if (argc == 3) { | } else if (argc == 3) { |
// Failure of this function does not trigger an error, but | // Failure of this function does not trigger an error, but |
// returns the plain result to let scripts detect available frames | // returns nonzero, to let scripts detect available frames |
long int f = proxy->frame(strtol(argv[2], NULL, 10)); | int error = proxy->set_frame(strtol(argv[2], NULL, 10)); |
colvars->it = proxy->frame(); | result = cvm::to_str(error == COLVARS_OK ? 0 : -1); |
result = cvm::to_str(f); | return COLVARS_OK; |
return COLVARSCRIPT_OK; | |
} else { | } else { |
result = "Wrong arguments to command \"frame\"\n" + help_string(); | result = "Wrong arguments to command \"frame\"\n" + help_string(); |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
| |
| |
if (subcmd == "value") { | if (subcmd == "value") { |
result = (cv->value()).to_simple_string(); | result = (cv->value()).to_simple_string(); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "width") { | if (subcmd == "width") { |
result = cvm::to_str(cv->width, 0, cvm::cv_prec); | result = cvm::to_str(cv->width, 0, cvm::cv_prec); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "type") { | if (subcmd == "type") { |
result = cv->value().type_desc(cv->value().value_type); | result = cv->value().type_desc(cv->value().value_type); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "update") { | if (subcmd == "update") { |
cv->calc(); | cv->calc(); |
cv->update(); | cv->update_forces_energy(); |
result = (cv->value()).to_simple_string(); | result = (cv->value()).to_simple_string(); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "delete") { | if (subcmd == "delete") { |
| |
delete cv; | delete cv; |
// TODO this could be done by the destructors | // TODO this could be done by the destructors |
colvars->write_traj_label(colvars->cv_traj_os); | colvars->write_traj_label(colvars->cv_traj_os); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "getconfig") { | if (subcmd == "getconfig") { |
result = cv->get_config(); | result = cv->get_config(); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
| } |
| |
| if (subcmd == "getappliedforce") { |
| result = (cv->applied_force()).to_simple_string(); |
| return COLVARS_OK; |
| } |
| |
| if (subcmd == "getsystemforce") { |
| // TODO warning here |
| result = (cv->total_force()).to_simple_string(); |
| return COLVARS_OK; |
| } |
| |
| if (subcmd == "gettotalforce") { |
| result = (cv->total_force()).to_simple_string(); |
| return COLVARS_OK; |
} | } |
| |
if (subcmd == "addforce") { | if (subcmd == "addforce") { |
| |
} | } |
cv->add_bias_force(force); | cv->add_bias_force(force); |
result = force.to_simple_string(); | result = force.to_simple_string(); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "cvcflags") { | if (subcmd == "cvcflags") { |
| |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
} | } |
result = "0"; | result = "0"; |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
| } |
| |
| if (subcmd == "state") { |
| cv->print_state(); |
| return COLVARS_OK; |
} | } |
| |
result = "Syntax error\n" + help_string(); | result = "Syntax error\n" + help_string(); |
| |
| |
if (subcmd == "energy") { | if (subcmd == "energy") { |
result = cvm::to_str(b->get_energy()); | result = cvm::to_str(b->get_energy()); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "update") { | if (subcmd == "update") { |
b->update(); | b->update(); |
result = cvm::to_str(b->get_energy()); | result = cvm::to_str(b->get_energy()); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "getconfig") { | if (subcmd == "getconfig") { |
result = b->get_config(); | result = b->get_config(); |
return COLVARSCRIPT_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(); |
result = cvm::to_str(r); | result = cvm::to_str(r); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "binnum") { | if (subcmd == "binnum") { |
| |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
} | } |
result = cvm::to_str(r); | result = cvm::to_str(r); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (subcmd == "share") { | if (subcmd == "share") { |
| |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
} | } |
result = cvm::to_str(r); | result = cvm::to_str(r); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
// End commands for MW ABF | // End commands for MW ABF |
| |
| |
delete b; | delete b; |
// TODO this could be done by the destructors | // TODO this could be done by the destructors |
colvars->write_traj_label(colvars->cv_traj_os); | colvars->write_traj_label(colvars->cv_traj_os); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
if (argc >= 4) { | if (argc >= 4) { |
| |
return COLVARSCRIPT_ERROR; | return COLVARSCRIPT_ERROR; |
} | } |
result = cvm::to_str(b->bin_count(index)); | result = cvm::to_str(b->bin_count(index)); |
return COLVARSCRIPT_OK; | return COLVARS_OK; |
} | } |
| |
result = "Syntax error\n" + help_string(); | result = "Syntax error\n" + help_string(); |
| |
list biases -- return a list of all biases\n\ | list biases -- return a list of all biases\n\ |
load <file name> -- load a state file (requires configuration)\n\ | load <file name> -- load a state file (requires configuration)\n\ |
save <file name> -- save a state file (requires configuration)\n\ | save <file name> -- save a state file (requires configuration)\n\ |
update -- recalculate colvars and biases based\n\ | update -- recalculate colvars and biases\n\ |
printframe -- return a summary of the current frame\n\ | printframe -- return a summary of the current frame\n\ |
printframelabels -- return labels to annotate printframe's output\n"; | printframelabels -- return labels to annotate printframe's output\n"; |
| |
if (proxy->frame() != COLVARS_NOT_IMPLEMENTED) { | long int tmp; |
| if (proxy->get_frame(tmp) != COLVARS_NOT_IMPLEMENTED) { |
buf += "\ | buf += "\ |
frame -- return current frame number\n\ | frame -- return current frame number\n\ |
frame <new_frame> -- set frame number\n"; | frame <new_frame> -- set frame number\n"; |