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
# 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}

View File

@ -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,6 +145,7 @@ void KimInteractions::do_setup(int narg, char **arg)
if (simulatorModel) {
if (!fixed_types) {
std::string delimiter("");
std::string atom_type_sym_list;
std::string atom_type_num_list;
@ -184,6 +193,11 @@ void KimInteractions::do_setup(int narg, char **arg)
strword = strtok(NULL," \t");
}
delete[] strbuf;
}
else
{
KIM_SimulatorModel_CloseTemplateMap(simulatorModel);
}
// check if units are unchanged
@ -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.

View File

@ -57,6 +57,7 @@
#include <mpi.h>
#include <cstring>
#include <string>
#include <sstream>
#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];
if (split) {
int counter = 1;
std::stringstream ss(value);
std::string token;
varcmd[1] = (char *) "string";
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[] value;