00001 // -*- c++ -*- 00002 00003 // This file is part of the Collective Variables module (Colvars). 00004 // The original version of Colvars and its updates are located at: 00005 // https://github.com/Colvars/colvars 00006 // Please update all Colvars source files before making any changes. 00007 // If you wish to distribute your changes, please submit them to the 00008 // Colvars repository at GitHub. 00009 00010 #include <sstream> 00011 #include <iostream> 00012 #include <algorithm> 00013 00014 #include "colvarmodule.h" 00015 #include "colvarvalue.h" 00016 #include "colvarparams.h" 00017 00018 00019 00020 colvarparams::colvarparams() 00021 {} 00022 00023 00024 colvarparams::~colvarparams() 00025 {} 00026 00027 00028 void colvarparams::register_param(std::string const ¶m_name, 00029 void *param_ptr) 00030 { 00031 param_map[param_name] = param_ptr; 00032 } 00033 00034 00035 void colvarparams::register_param_grad(std::string const ¶m_name, 00036 colvarvalue *param_grad_ptr) 00037 { 00038 param_grad_map[param_name] = param_grad_ptr; 00039 } 00040 00041 00042 int colvarparams::param_exists(std::string const ¶m_name) 00043 { 00044 if (param_map.count(param_name) > 0) { 00045 return COLVARS_OK; 00046 } 00047 return COLVARS_INPUT_ERROR; 00048 } 00049 00050 00051 std::vector<std::string> colvarparams::get_param_names() 00052 { 00053 std::vector<std::string> result; 00054 for (std::map<std::string, void const *>::const_iterator elem = 00055 param_map.begin(); elem != param_map.end(); elem++) { 00056 result.push_back(elem->first); 00057 } 00058 return result; 00059 } 00060 00061 00062 std::vector<std::string> colvarparams::get_param_grad_names() 00063 { 00064 std::vector<std::string> result; 00065 for (std::map<std::string, colvarvalue const *>::const_iterator elem = 00066 param_grad_map.begin(); elem != param_grad_map.end(); elem++) { 00067 result.push_back(elem->first); 00068 } 00069 return result; 00070 } 00071 00072 00073 void const *colvarparams::get_param_ptr(std::string const ¶m_name) 00074 { 00075 if (param_map.count(param_name) > 0) { 00076 return param_map[param_name]; 00077 } 00078 cvm::error("Error: parameter \""+param_name+"\" not found.\n", COLVARS_INPUT_ERROR); 00079 return NULL; 00080 } 00081 00082 00083 void const *colvarparams::get_param_grad_ptr(std::string const ¶m_name) 00084 { 00085 if (param_grad_map.count(param_name) > 0) { 00086 return param_grad_map[param_name]; 00087 } 00088 cvm::error("Error: gradient of parameter \""+param_name+"\" not found.\n", 00089 COLVARS_INPUT_ERROR); 00090 return NULL; 00091 } 00092 00093 00094 cvm::real colvarparams::get_param(std::string const ¶m_name) 00095 { 00096 cvm::real const *ptr = 00097 reinterpret_cast<cvm::real const *>(get_param_ptr(param_name)); 00098 return ptr != NULL ? *ptr : 0.0; 00099 } 00100 00101 00102 int colvarparams::set_param(std::string const ¶m_name, 00103 void const * /* new_value */) 00104 { 00105 if (param_map.count(param_name) > 0) { 00106 return cvm::error("Error: parameter \""+param_name+"\" cannot be " 00107 "modified.\n", COLVARS_NOT_IMPLEMENTED); 00108 } 00109 return cvm::error("Error: parameter \""+param_name+"\" not found.\n", 00110 COLVARS_INPUT_ERROR); 00111 }