Revert "simplify"
This reverts commit 2be20f424f
as this change has been integrated into a different branch
with additional changes.
This commit is contained in:
@ -73,7 +73,6 @@
|
||||
#include "variable.h"
|
||||
#include "utils.h"
|
||||
#include "fix_store_kim.h"
|
||||
#include "fmt/format.h"
|
||||
|
||||
extern "C" {
|
||||
#include "KIM_SimulatorHeaders.h"
|
||||
@ -255,23 +254,33 @@ void KimInteractions::do_setup(int narg, char **arg)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KimInteractions::KIM_SET_TYPE_PARAMETERS(const std::string &input_line) const
|
||||
void KimInteractions::KIM_SET_TYPE_PARAMETERS(char const *const input_line) const
|
||||
{
|
||||
char strbuf[MAXLINE];
|
||||
strcpy(strbuf,input_line);
|
||||
char *cmd, *key, *filename;
|
||||
int nocomment;
|
||||
auto words = utils::split_words(input_line);
|
||||
|
||||
std::string key = words[1];
|
||||
std::string filename = words[2];
|
||||
std::vector<std::string> species(words.begin()+3,words.end());
|
||||
if (species.size() != atom->ntypes)
|
||||
error->one(FLERR,"Incorrect args for KIM_SET_TYPE_PARAMETERS command");
|
||||
cmd = strtok(strbuf," \t");
|
||||
key = strtok(NULL," \t");
|
||||
filename = strtok(NULL," \t");
|
||||
|
||||
FILE *fp;
|
||||
fp = fopen(filename.c_str(),"r");
|
||||
fp = fopen(filename,"r");
|
||||
if (fp == NULL) {
|
||||
error->one(FLERR,"Parameter file not found");
|
||||
}
|
||||
|
||||
char *species1, *species2, *the_rest;
|
||||
std::vector<char *> species;
|
||||
for (int i = 0; i < atom->ntypes; ++i)
|
||||
{
|
||||
char *str;
|
||||
str = strtok(NULL," \t");
|
||||
if (str == NULL)
|
||||
error->one(FLERR,"Incorrect args for KIM_SET_TYPE_PARAMETERS command");
|
||||
species.push_back(str);
|
||||
}
|
||||
|
||||
char line[MAXLINE],*ptr;
|
||||
int n, eof = 0;
|
||||
|
||||
@ -290,29 +299,42 @@ void KimInteractions::KIM_SET_TYPE_PARAMETERS(const std::string &input_line) con
|
||||
|
||||
ptr = line;
|
||||
nocomment = line[0] != '#';
|
||||
char *species1, *species2, *the_rest;
|
||||
|
||||
if(nocomment) {
|
||||
if (key == "pair") {
|
||||
if (strcmp(key,"pair") == 0) {
|
||||
species1 = strtok(ptr," \t");
|
||||
species2 = strtok(NULL," \t");
|
||||
the_rest = strtok(NULL,"\n");
|
||||
|
||||
for (int ia = 0; ia < atom->ntypes; ++ia) {
|
||||
for (int ib = ia; ib < atom->ntypes; ++ib)
|
||||
if (((species[ia] == species1) && (species[ib] == species2))
|
||||
|| ((species[ib] == species1) && (species[ia] == species2)))
|
||||
input->one(fmt::format("pair_coeff {} {} {}",ia+1,ib+1,the_rest));
|
||||
for (int type_a = 0; type_a < atom->ntypes; ++type_a) {
|
||||
for (int type_b = type_a; type_b < atom->ntypes; ++type_b) {
|
||||
if(((strcmp(species[type_a],species1) == 0) &&
|
||||
(strcmp(species[type_b],species2) == 0))
|
||||
||
|
||||
((strcmp(species[type_b],species1) == 0) &&
|
||||
(strcmp(species[type_a],species2) == 0))
|
||||
) {
|
||||
char pair_command[MAXLINE];
|
||||
sprintf(pair_command,"pair_coeff %i %i %s",type_a+1,type_b+1,
|
||||
the_rest);
|
||||
input->one(pair_command);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (key == "charge") {
|
||||
}
|
||||
else if (strcmp(key,"charge") == 0) {
|
||||
species1 = strtok(ptr," \t");
|
||||
the_rest = strtok(NULL,"\n");
|
||||
|
||||
for (int ia = 0; ia < atom->ntypes; ++ia) {
|
||||
if (species[ia] == species1)
|
||||
input->one(fmt::format("set type {} charge {}",ia+1,the_rest));
|
||||
for (int type_a = 0; type_a < atom->ntypes; ++type_a) {
|
||||
if(strcmp(species[type_a],species1) == 0) {
|
||||
char pair_command[MAXLINE];
|
||||
sprintf(pair_command,"set type %i charge %s",type_a+1,the_rest);
|
||||
input->one(pair_command);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else{
|
||||
error->one(FLERR,"Unrecognized KEY for KIM_SET_TYPE_PARAMETERS command");
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ class KimInteractions : protected Pointers {
|
||||
private:
|
||||
void do_setup(int, char **);
|
||||
int species_to_atomic_no(const std::string &species) const;
|
||||
void KIM_SET_TYPE_PARAMETERS(const std::string &input_line) const;
|
||||
void KIM_SET_TYPE_PARAMETERS(char const *const input_line) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user