Correct the token to avoid missing model names

Correct the missing & available strings to match with the rest of query
Add error message when there is no OpenKIM model installed on the system
Correct the header file inlcusion order
This commit is contained in:
Yaser Afshar
2021-03-16 16:23:54 -05:00
parent c81610a3e8
commit 0e8f64251e

View File

@ -62,10 +62,6 @@
#include "fix_store_kim.h"
#include "info.h"
#include "input.h"
extern "C" {
#include "KIM_Collections.h"
#include "KIM_CollectionItemType.h"
}
#include "modify.h"
#include "utils.h"
#include "variable.h"
@ -82,6 +78,11 @@ extern "C" {
#include <curl/curl.h>
#endif
extern "C" {
#include "KIM_Collections.h"
#include "KIM_CollectionItemType.h"
}
using namespace LAMMPS_NS;
#if defined(LMP_KIM_CURL)
@ -191,33 +192,44 @@ void KimQuery::command(int narg, char **arg)
"=======\n");
// trim list of models to those that are installed on the system
if (query_function == "get_available_models") {
ValueTokenizer vals(value, ",");
ValueTokenizer vals(value, ", \"");
std::string available;
std::string missing;
KIM_Collections * col;
if (KIM_Collections_Create(&col)) {
KIM_Collections * collections;
KIM_CollectionItemType typ;
if (KIM_Collections_Create(&collections)) {
delete [] value;
error->all(FLERR, fmt::format("Unable to create KIM_Collections object"));
error->all(FLERR,
fmt::format("Unable to access KIM Collections to find Model"));
}
auto logID = fmt::format("{}_Collections", comm->me);
KIM_Collections_SetLogID(collections, logID.c_str());
while (vals.has_next()) {
auto svalue = vals.next_string();
KIM_CollectionItemType typ;
if (KIM_Collections_GetItemType(col, svalue.c_str(), &typ))
missing += fmt::format("{} ", svalue);
if (KIM_Collections_GetItemType(collections, svalue.c_str(), &typ))
missing += fmt::format("{}, ", svalue);
else
available += fmt::format("{} ", svalue);
available += fmt::format("{}, ", svalue);
}
KIM_Collections_Destroy(&col);
KIM_Collections_Destroy(&collections);
input->write_echo(
fmt::format("# Missing OpenKIM models: {}\n\n", missing));
if (available.empty())
error->all(FLERR,
fmt::format("There is no OpenKIM model installed on the system"));
input->write_echo(
fmt::format("# Installed OpenKIM models: {}\n\n", available));
input->write_echo(fmt::format("# Installed OpenKIM models: {}\n", available));
input->write_echo(fmt::format("# Missing OpenKIM models: {}\n", missing));
// replace results with available
strcpy(value, available.c_str()); // available guaranteed to fit
};
ValueTokenizer values(value, ",");
if (format_arg == "split") {
int counter = 1;