Commit 3f3bab4e authored by Ryan S. Elliott's avatar Ryan S. Elliott
Browse files

Create KIM_LAMMPS_PlugIn.h & related changes

parent f089d8d2
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ Syntax from lib dir: python Install.py -b -v version -a kim-name
specify one or more options, order does not matter

  -v = version of KIM API library to use
       default = kim-api-v1.9.4 (current as of Mar 2018)
       default = kim-api-v1.9.4 (current as of Apr 2018)
  -b = download and build base KIM API library with example Models
       this will delete any previous installation in the current folder
  -n = do NOT download and build base KIM API library.
@@ -166,9 +166,6 @@ if pathflag:
    mkfile.write("print_dir:\n")
    mkfile.write("	@printf $(KIM_INSTALL_DIR)\n")

  with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile:
    cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir)

  print("Created %s/Makefile.KIM_DIR\n  using %s" % (thisdir,kimdir))
else:
  kimdir = os.path.join(os.path.abspath(thisdir), "installed-" + version)
@@ -191,9 +188,6 @@ if buildflag:
    mkfile.write("print_dir:\n")
    mkfile.write("	@printf $(KIM_INSTALL_DIR)\n")

  with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile:
    cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir)

  print("Created %s/Makefile.KIM_DIR\n  using %s" % (thisdir,kimdir))

  # download entire kim-api tarball
@@ -247,8 +241,9 @@ if buildflag:
# add single OpenKIM model
if addflag:

  if os.path.isfile(os.path.join(thisdir, "Makefile.KIM_DIR")):
    cmd = 'make -f Makefile.KIM_DIR print_dir'
  makefile_path = os.path.join(thisdir, "Makefile.KIM_DIR")
  if os.path.isfile(makefile_path):
    cmd = 'make --no-print-directory -f %s print_dir' % makefile_path
    kimdir = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)

  if not os.path.isdir(kimdir):
+210 −0
Original line number Diff line number Diff line
// Copyright 2018 Regents of the University of Minnesota
// All rights reserved.
//
// Contributing authors: Ryan S. Elliott

#define KIM_STATUS_OK 1
#define KIM_STATUS_NEIGH_ITER_PAST_END 2
#define KIM_STATUS_NEIGH_ITER_INIT_OK 3
#define KIM_STATUS_NEIGH_INVALID_REQUEST -11
#define KIM_STATUS_NEIGH_INVALID_MODE -6
#define KIM_COMPUTE_FALSE 0
#define KIM_COMPUTE_TRUE 1
#define KIM_STATUS_FAIL 0

#include "dlfcn.h"
#include "error.h"

namespace LAMMPS_NS {

class KIM_LAMMPS_PlugIn {
 public:
  ~KIM_LAMMPS_PlugIn() {};
  KIM_LAMMPS_PlugIn() : library(NULL) {};

  bool setup_kim_api_library(Error * const error);
  bool is_strictly_between_1_5_and_2_0;

  // KIM symbols
  void* library;
  int (*report_error)(int line, const char *, const char *, int);
  void (*setm_compute_by_index)(void *, int *, ...);
  int (*model_compute)(void *);
  int (*model_init)(void *);
  int (*model_reinit)(void *);
  void * (*get_sim_buffer)(void *, int *);
  void * (*get_data_by_index)(void *, int, int *);
  int (*model_destroy)(void *);
  void (*free)(void *, int *);
  int (*string_init)(void *, const char *, const char *);
  int (*is_half_neighbors)(void *, int *);
  int (*get_NBC_method)(void *, const char **);
  int (*get_index)(void *, const char *, int *);
  int (*getm_index)(void *, int *, int, ...);
  int (*get_species_code)(void *, const char *, int *);
  void (*setm_data_by_index)(void *, int *, int, ...);
  int (*set_method_by_index)(void *, int, intptr_t, void (*)());
  void (*set_sim_buffer)(void *, void *, int *);
  int (*set_data_by_index)(void *, int, intptr_t, void *);
  void (*set_compute_by_index)(void *, int, int, int*);
  int (*get_num_params)(void *, int *, int *);
  int (*get_free_parameter)(void *, const int, const char **);
  void * (*get_data)(void *, const char *, int *);
  intptr_t (*get_rank)(void *, const char *, int *);
  intptr_t (*get_shape)(void *, const char *, int *, int *);
  int (*model_info)(void *, const char *);
};


bool KIM_LAMMPS_PlugIn::setup_kim_api_library(Error * error)
{
  if (library == NULL)
  {
#ifdef KIM_INSTALL_DIR
    library = dlopen(KIM_INSTALL_DIR "/lib/libkim-api-v1.so", RTLD_NOW);
#endif

    if (library == NULL)
      library = dlopen("kim-api-v1.so", RTLD_NOW);

    if (library == NULL)
    {
      error->all(FLERR,"KIM API library cannot be found");
      return false;
    }
    else
    {
      // check for version and set is_strictly_between_1_5_and_2_0
      void * ver = dlsym(library, "KIM_API_get_version");
      if (ver == NULL)
        is_strictly_between_1_5_and_2_0 = false;
      else
        is_strictly_between_1_5_and_2_0 = true;

      std::string error_prefix("KIM API library error: ");
      // get symbols
      if (NULL == (report_error =
                   (int (*)(int, const char *, const char *, int))
                   dlsym(library, "KIM_API_report_error")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (setm_compute_by_index =
                   (void (*)(void *, int *, ...))
                   dlsym(library, "KIM_API_setm_compute_by_index")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (model_compute = (int (*)(void *))
                   dlsym(library, "KIM_API_model_compute")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (model_init = (int (*)(void *))
                   dlsym(library, "KIM_API_model_init")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (model_reinit = (int (*)(void *))
                   dlsym(library, "KIM_API_model_reinit")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_sim_buffer = (void * (*)(void *, int *))
                   dlsym(library, "KIM_API_get_sim_buffer")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_data_by_index = (void * (*)(void *, int, int *))
                   dlsym(library, "KIM_API_get_data_by_index")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (model_destroy = (int (*)(void *))
                   dlsym(library, "KIM_API_model_destroy")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (free = (void (*)(void *, int *))
                   dlsym(library, "KIM_API_free")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (string_init =
                   (int (*)(void *, const char *, const char *))
                   dlsym(library, "KIM_API_string_init")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (is_half_neighbors = (int (*)(void *, int *))
                   dlsym(library, "KIM_API_is_half_neighbors")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_NBC_method = (int (*)(void *, const char **))
                   dlsym(library, "KIM_API_get_NBC_method")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_index = (int (*)(void *, const char *, int *))
                   dlsym(library, "KIM_API_get_index")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (getm_index = (int (*)(void *, int *, int, ...))
                   dlsym(library, "KIM_API_getm_index")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_species_code =
                   (int (*)(void *, const char *, int *))
                   dlsym(library, "KIM_API_get_species_code")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (setm_data_by_index =
                   (void (*)(void *, int *, int, ...))
                   dlsym(library, "KIM_API_setm_data_by_index")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (set_method_by_index =
                   (int (*)(void *, int, intptr_t, void (*)()))
                   dlsym(library, "KIM_API_set_method_by_index")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (set_sim_buffer = (void (*)(void *, void *, int *))
                   dlsym(library, "KIM_API_set_sim_buffer")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (set_data_by_index =
                   (int (*)(void *, int, intptr_t, void *))
                   dlsym(library, "KIM_API_set_data_by_index")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (set_compute_by_index =
                   (void (*)(void *, int, int, int*))
                   dlsym(library, "KIM_API_set_compute_by_index")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_num_params = (int (*)(void *, int *, int *))
                   dlsym(library, "KIM_API_get_num_params")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_free_parameter =
                   (int (*)(void *, const int, const char **))
                   dlsym(library, "KIM_API_get_free_parameter")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_data = (void * (*)(void *, const char *, int *))
                   dlsym(library, "KIM_API_get_data")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_rank =
                   (intptr_t (*)(void *, const char *, int *))
                   dlsym(library, "KIM_API_get_rank")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (get_shape =
                   (intptr_t (*)(void *, const char *, int *, int *))
                   dlsym(library, "KIM_API_get_shape")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

      if (NULL == (model_info = (int (*)(void *, const char *))
                   dlsym(library, "KIM_API_model_info")))
        error->all(FLERR,(error_prefix + std::string(dlerror())).c_str());

    return true;
    }
  }
  else
  {
    return true;
  }
}

}  // namespace LAMMPS_NS
+2 −2
Original line number Diff line number Diff line
@@ -18,6 +18,6 @@

include ../../lib/kim/Makefile.KIM_DIR

kim_SYSINC  = -DKIM_INSTALL_DIR=\"${KIM_INSTALL_DIR}\"
kim_SYSLIB  =
kim_SYSINC  = -I../../lib/kim -DKIM_INSTALL_DIR=\"$(KIM_INSTALL_DIR)\"
kim_SYSLIB  = -ldl
kim_SYSPATH =
+5 −4
Original line number Diff line number Diff line
@@ -20,11 +20,11 @@ Instructions:

1. Configure lammps for use with the kim-api library installed in this directory

$ printf "KIM_INSTALL_DIR=${PWD}\n" > ./Makefile.KIM_DIR
# replace X.Y.Z as appropriate here and below
$ printf "KIM_INSTALL_DIR=${PWD}/installed-kim-api-vX.Y.Z\n" > ./Makefile.KIM_DIR

2. Download and unpack the kim-api

# replace X.Y.Z as appropriate here and below
$ wget http://s3.openkim.org/kim-api/kim-api-vX.Y.Z.txz
$ tar zxvf kim-api-vX.Y.Z.txz

@@ -36,6 +36,7 @@ $ ./configure --prefix=${PWD}/../installed-kim-api-vX.Y.Z

$ make
$ make install
$ cd ..

4. Remove source and build files

@@ -45,7 +46,7 @@ $ rm -rf kim-api-vX.Y.Z.txz
5. To add items do the following (replace the kim item name with your
   desired value)

$ source ${PWD}/../kim-api-vX.Y.Z/bin/kim-api-v1-activate
$ source ${PWD}/kim-api-vX.Y.Z/bin/kim-api-v1-activate
$ kim-api-v1-collections-management install system Pair_Johnson_Fe__MO_857282754307_002


@@ -60,4 +61,4 @@ $ make g++ (or whatever target you wish)

Note that the Makefile.lammps and Makefile.KIM_DIR files in this directory
are required to allow the LAMMPS build to find the necessary KIM files.
You should not normally need to edit this file.
You should not normally need to edit these files.

lib/kim/pair-kim.release.info

deleted100644 → 0
+0 −6
Original line number Diff line number Diff line
This package (pair-kim-v1.7.2+1) created from commit

ced1275c5fd5b382cb9bd39e44ed1324c7c85e99

of the pair-kim git repository
By Ryan S. Elliott (relliott@umn.edu) on Mon Feb 22 14:59:53 CST 2016.
Loading