diff --git a/examples/kim/in.query b/examples/kim/in.query index 33272dc298..72e739fb52 100644 --- a/examples/kim/in.query +++ b/examples/kim/in.query @@ -4,8 +4,9 @@ # lattice constant for a specific test used for a specific model and then # assigns it to the variable 'latconst' -units metal +kim_init EAM_CubicNaturalSpline_ErcolessiAdams_1994_Al__MO_800509458712_002 metal info variables out log -kim_query latconst get_test_result test=TE_156715955670 species=["Al"] model=MO_800509458712 prop=structure-cubic-crystal-npt keys=["a"] units=["angstrom"] +kim_query latconst split get_test_result test=TE_156715955670 species=["Al"] prop=structure-cubic-crystal-npt keys=["a","a"] units=["angstrom","angstrom"] info variables out log -lattice fcc ${latconst} +lattice fcc ${latconst_1} +lattice fcc ${latconst_2} diff --git a/src/KIM/kim_interactions.cpp b/src/KIM/kim_interactions.cpp index 355df9c3be..d0fbb809d2 100644 --- a/src/KIM/kim_interactions.cpp +++ b/src/KIM/kim_interactions.cpp @@ -115,8 +115,16 @@ void KimInteractions::kim_interactions_log_delimiter( void KimInteractions::do_setup(int narg, char **arg) { - if (narg != atom->ntypes) + bool fixed_types; + if ((narg == 1) && (0 == strcmp("fixed_types",arg[0]))) { + fixed_types = true; + } + else if (narg != atom->ntypes) { error->all(FLERR,"Illegal kim_interactions command"); + } + else { + fixed_types = false; + } char *model_name = NULL; KIM_SimulatorModel *simulatorModel(NULL); @@ -137,54 +145,60 @@ void KimInteractions::do_setup(int narg, char **arg) if (simulatorModel) { - std::string delimiter(""); - std::string atom_type_sym_list; - std::string atom_type_num_list; + if (!fixed_types) { + std::string delimiter(""); + std::string atom_type_sym_list; + std::string atom_type_num_list; - for (int i = 0; i < narg; i++) + for (int i = 0; i < narg; i++) + { + atom_type_sym_list += delimiter + arg[i]; + atom_type_num_list += delimiter + SNUM(species_to_atomic_no(arg[i])); + delimiter = " "; + } + + KIM_SimulatorModel_AddTemplateMap( + simulatorModel,"atom-type-sym-list",atom_type_sym_list.c_str()); + KIM_SimulatorModel_AddTemplateMap( + simulatorModel,"atom-type-num-list",atom_type_num_list.c_str()); + KIM_SimulatorModel_CloseTemplateMap(simulatorModel); + + int len = strlen(atom_type_sym_list.c_str())+1; + char *strbuf = new char[len]; + char *strword; + + // validate species selection + + int sim_num_species; + bool species_is_supported; + char const *sim_species; + KIM_SimulatorModel_GetNumberOfSupportedSpecies( + simulatorModel,&sim_num_species); + strcpy(strbuf,atom_type_sym_list.c_str()); + strword = strtok(strbuf," \t"); + while (strword) { + species_is_supported = false; + if (strcmp(strword,"NULL") == 0) continue; + for (int i=0; i < sim_num_species; ++i) { + KIM_SimulatorModel_GetSupportedSpecies(simulatorModel,i,&sim_species); + if (strcmp(sim_species,strword) == 0) + species_is_supported = true; + } + if (!species_is_supported) { + std::string msg("Species '"); + msg += strword; + msg += "' is not supported by this KIM Simulator Model"; + error->all(FLERR,msg.c_str()); + } + strword = strtok(NULL," \t"); + } + delete[] strbuf; + } + else { - atom_type_sym_list += delimiter + arg[i]; - atom_type_num_list += delimiter + SNUM(species_to_atomic_no(arg[i])); - delimiter = " "; + KIM_SimulatorModel_CloseTemplateMap(simulatorModel); } - KIM_SimulatorModel_AddTemplateMap( - simulatorModel,"atom-type-sym-list",atom_type_sym_list.c_str()); - KIM_SimulatorModel_AddTemplateMap( - simulatorModel,"atom-type-num-list",atom_type_num_list.c_str()); - KIM_SimulatorModel_CloseTemplateMap(simulatorModel); - - int len = strlen(atom_type_sym_list.c_str())+1; - char *strbuf = new char[len]; - char *strword; - - // validate species selection - - int sim_num_species; - bool species_is_supported; - char const *sim_species; - KIM_SimulatorModel_GetNumberOfSupportedSpecies( - simulatorModel,&sim_num_species); - strcpy(strbuf,atom_type_sym_list.c_str()); - strword = strtok(strbuf," \t"); - while (strword) { - species_is_supported = false; - if (strcmp(strword,"NULL") == 0) continue; - for (int i=0; i < sim_num_species; ++i) { - KIM_SimulatorModel_GetSupportedSpecies(simulatorModel,i,&sim_species); - if (strcmp(sim_species,strword) == 0) - species_is_supported = true; - } - if (!species_is_supported) { - std::string msg("Species '"); - msg += strword; - msg += "' is not supported by this KIM Simulator Model"; - error->all(FLERR,msg.c_str()); - } - strword = strtok(NULL," \t"); - } - delete[] strbuf; - // check if units are unchanged int sim_fields, sim_lines; @@ -223,6 +237,10 @@ void KimInteractions::do_setup(int narg, char **arg) } else { // not a simulator model. issue pair_style and pair_coeff commands. + + if (fixed_types) + error->all(FLERR,"fixed_types cannot be used with a KIM Portable Model"); + // NOTE: all references to arg must appear before calls to input->one() // as that will reset the argument vector. diff --git a/src/KIM/kim_query.cpp b/src/KIM/kim_query.cpp index 2bb404ec26..cf4efc2b12 100644 --- a/src/KIM/kim_query.cpp +++ b/src/KIM/kim_query.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include "kim_query.h" #include "comm.h" #include "error.h" @@ -104,6 +105,13 @@ void KimQuery::command(int narg, char **arg) varname = arg[0]; + bool split = false; + if (0 == strcmp("split",arg[1])) { + if (narg == 2) error->all(FLERR,"Illegal kim_query command"); + split = true; + arg++; + narg--; + } function = arg[1]; #if defined(LMP_KIM_CURL) @@ -123,11 +131,27 @@ void KimQuery::command(int narg, char **arg) } char **varcmd = new char*[3]; - varcmd[0] = varname; - varcmd[1] = (char *) "string"; - varcmd[2] = value; + if (split) { + int counter = 1; + std::stringstream ss(value); + std::string token; + varcmd[1] = (char *) "string"; - input->variable->set(3,varcmd); + while(std::getline(ss, token, ',')) { + std::stringstream splitname; + splitname << varname << "_" << counter++; + varcmd[0] = const_cast(splitname.str().c_str()); + varcmd[2] = const_cast(token.c_str()); + input->variable->set(3,varcmd); + } + } + else { + varcmd[0] = varname; + varcmd[1] = (char *) "string"; + varcmd[2] = value; + + input->variable->set(3,varcmd); + } delete[] varcmd; delete[] value;