Merge pull request from ellio167/kim_match_pairs

Add support for "internal" kim_match_pairs command
This commit is contained in:
Axel Kohlmeyer 2020-04-15 12:43:34 -04:00 committed by GitHub
commit 6bac08322c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 2 deletions

View File

@ -15,6 +15,7 @@
Contributing authors: Axel Kohlmeyer (Temple U),
Ryan S. Elliott (UMN)
Ellad B. Tadmor (UMN)
Ronald Miller (Carleton U)
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
@ -57,8 +58,10 @@
#include "kim_interactions.h"
#include <cstring>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include "error.h"
#include "atom.h"
#include "comm.h"
@ -80,6 +83,8 @@ extern "C" {
using namespace LAMMPS_NS;
#define MAXLINE 1024
/* ---------------------------------------------------------------------- */
void KimInteractions::command(int narg, char **arg)
@ -223,8 +228,27 @@ void KimInteractions::do_setup(int narg, char **arg)
for (int j=0; j < sim_lines; ++j) {
KIM_SimulatorModel_GetSimulatorFieldLine(
simulatorModel,sim_model_idx,j,&sim_value);
input->one(sim_value);
}
char strbuf[MAXLINE];
char * strword;
strcpy(strbuf,sim_value);
strword = strtok(strbuf," \t");
if (0==strcmp(strword,"KIM_MATCH_PAIRS")) {
// Notes regarding the KIM_MATCH_PAIRS command
// * This is an INTERNAL command.
// * It is intended for use only by KIM Simulator Models.
// * It is not possible to use this command outside of the context
// of the kim_interactions command and KIM Simulator Models.
// * The command performs a transformation from symbolic
// string-based atom types to lammps numeric atom types for
// the pair_coeff settings.
// * The command is not documented fully as it is expected to be
// temporary. Eventually it should be replaced by a more
// comprehensive symbolic types support in lammps.
KIM_MATCH_PAIRS(sim_value);
} else {
input->one(sim_value);
}
}
}
}
@ -263,6 +287,73 @@ void KimInteractions::do_setup(int narg, char **arg)
/* ---------------------------------------------------------------------- */
void KimInteractions::KIM_MATCH_PAIRS(char const *const input_line) const
{
char strbuf[MAXLINE];
strcpy(strbuf,input_line);
char *cmd, *filename;
cmd = strtok(strbuf," \t");
filename = strtok(NULL," \t");
FILE *fp;
fp = fopen(filename,"r");
if (fp == NULL) {
error->one(FLERR,"Parameter file not found");
}
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_MATCH_PAIRS command");
species.push_back(str);
}
char line[MAXLINE],*ptr;
int n, eof = 0;
while (1) {
if (comm->me == 0) {
ptr = fgets(line,MAXLINE,fp);
if (ptr == NULL) {
eof = 1;
fclose(fp);
} else n = strlen(line) + 1;
}
MPI_Bcast(&eof,1,MPI_INT,0,world);
if (eof) break;
MPI_Bcast(&n,1,MPI_INT,0,world);
MPI_Bcast(line,n,MPI_CHAR,0,world);
char *species1, *species2, *the_rest;
ptr = line;
species1 = strtok(ptr," \t");
species2 = strtok(NULL," \t");
the_rest = strtok(NULL,"\n");
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);
}
}
}
}
fclose(fp);
}
/* ---------------------------------------------------------------------- */
int KimInteractions::species_to_atomic_no(std::string const species) const
{
if (species == "H") return 1;

View File

@ -15,6 +15,7 @@
Contributing authors: Axel Kohlmeyer (Temple U),
Ryan S. Elliott (UMN)
Ellad B. Tadmor (UMN)
Ronald Miller (Carleton U)
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
@ -76,6 +77,7 @@ class KimInteractions : protected Pointers {
private:
void do_setup(int, char **);
int species_to_atomic_no(std::string const species) const;
void KIM_MATCH_PAIRS(char const *const input_line) const;
void kim_interactions_log_delimiter(std::string const begin_end) const;
};