Add fixed_types to kim_init & split to kim_query

This commit is contained in:
Ryan S. Elliott
2019-07-08 17:46:47 -05:00
parent bb5a1c5205
commit 1f47da6c51
3 changed files with 95 additions and 52 deletions

View File

@ -4,8 +4,9 @@
# lattice constant for a specific test used for a specific model and then # lattice constant for a specific test used for a specific model and then
# assigns it to the variable 'latconst' # assigns it to the variable 'latconst'
units metal kim_init EAM_CubicNaturalSpline_ErcolessiAdams_1994_Al__MO_800509458712_002 metal
info variables out log 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 info variables out log
lattice fcc ${latconst} lattice fcc ${latconst_1}
lattice fcc ${latconst_2}

View File

@ -115,8 +115,16 @@ void KimInteractions::kim_interactions_log_delimiter(
void KimInteractions::do_setup(int narg, char **arg) 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"); error->all(FLERR,"Illegal kim_interactions command");
}
else {
fixed_types = false;
}
char *model_name = NULL; char *model_name = NULL;
KIM_SimulatorModel *simulatorModel(NULL); KIM_SimulatorModel *simulatorModel(NULL);
@ -137,54 +145,60 @@ void KimInteractions::do_setup(int narg, char **arg)
if (simulatorModel) { if (simulatorModel) {
std::string delimiter(""); if (!fixed_types) {
std::string atom_type_sym_list; std::string delimiter("");
std::string atom_type_num_list; 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]; KIM_SimulatorModel_CloseTemplateMap(simulatorModel);
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;
// check if units are unchanged // check if units are unchanged
int sim_fields, sim_lines; int sim_fields, sim_lines;
@ -223,6 +237,10 @@ void KimInteractions::do_setup(int narg, char **arg)
} else { } else {
// not a simulator model. issue pair_style and pair_coeff commands. // 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() // NOTE: all references to arg must appear before calls to input->one()
// as that will reset the argument vector. // as that will reset the argument vector.

View File

@ -57,6 +57,7 @@
#include <mpi.h> #include <mpi.h>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <sstream>
#include "kim_query.h" #include "kim_query.h"
#include "comm.h" #include "comm.h"
#include "error.h" #include "error.h"
@ -104,6 +105,13 @@ void KimQuery::command(int narg, char **arg)
varname = arg[0]; 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]; function = arg[1];
#if defined(LMP_KIM_CURL) #if defined(LMP_KIM_CURL)
@ -123,11 +131,27 @@ void KimQuery::command(int narg, char **arg)
} }
char **varcmd = new char*[3]; char **varcmd = new char*[3];
varcmd[0] = varname; if (split) {
varcmd[1] = (char *) "string"; int counter = 1;
varcmd[2] = value; 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<char *>(splitname.str().c_str());
varcmd[2] = const_cast<char *>(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[] varcmd;
delete[] value; delete[] value;