From 65f55e70239722f0280d4747d5b8234f53e5e945 Mon Sep 17 00:00:00 2001 From: sjplimp Date: Thu, 2 Jul 2015 00:39:19 +0000 Subject: [PATCH] git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@13501 f3b2605a-c512-4ea7-a41b-209d697bcdaa --- src/KIM/README | 9 +++- src/KIM/pair_kim.cpp | 115 ++++++++++++++++++++++++++++++++----------- src/KIM/pair_kim.h | 3 ++ 3 files changed, 97 insertions(+), 30 deletions(-) diff --git a/src/KIM/README b/src/KIM/README index df0157e3fd..e450d7dfd1 100644 --- a/src/KIM/README +++ b/src/KIM/README @@ -1,9 +1,14 @@ +-*- fill-column: 70; -*- + This package provides a pair_style kim command which is a wrapper on the Knowledge Base for Interatomic Models (KIM) repository of interatomic potentials, so that they can be used by LAMMPS scripts. Information about the KIM project can be found at https://openkim.org. -It's PIs are Ellad Tadmor and Ryan Elliott (U Minn). +The KIM project is lead by Ellad Tadmor and Ryan Elliott (U Minn) and +James Sethna (Cornell U). Ryan Elliott is the main developer for the +KIM API and he also maintains the code that implements the pair_style +kim command. Using this package requires the KIM library and its models (interatomic potentials) to be downloaded and installed on your @@ -15,6 +20,8 @@ soon be provided to help automate the process. Also see the LAMMPS manual for general information on building LAMMPS with external libraries. The settings in the Makefile.lammps file in lib/kim must be correct for LAMMPS to build correctly with this package installed. +However, the default settings should be correct in most cases and the +Makefile.lammps file usually will not need to be changed. Once you have successfully built LAMMPS with this package and the KIM library you can test it using an input file from the examples dir: diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 082e1ee4bb..9599755a5a 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -27,6 +27,7 @@ // includes from LAMMPS #include "pair_kim.h" +#include "pair_kim_version.h" #include "atom.h" #include "comm.h" #include "force.h" @@ -46,7 +47,7 @@ // support v1.5.0 #define KIM_API_VERSION_MAJOR 1 #define KIM_API_VERSION_MINOR 5 -#define KIM_API_VERSION_PATHC 0 +#define KIM_API_VERSION_PATCH 0 #endif using namespace LAMMPS_NS; @@ -55,6 +56,8 @@ using namespace LAMMPS_NS; PairKIM::PairKIM(LAMMPS *lmp) : Pair(lmp), + settings_call_count(0), + init_style_call_count(0), kim_modelname(0), lmps_map_species_to_unique(0), lmps_unique_elements(0), @@ -258,10 +261,13 @@ void PairKIM::settings(int narg, char **arg) { // This is called when "pair_style kim ..." is read from input // may be called multiple times + ++settings_call_count; + init_style_call_count = 0; - if (narg != 2) error->all(FLERR,"Illegal pair_style command"); + if (narg < 2) error->all(FLERR,"Illegal pair_style command"); // arg[0] is the virial handling option: "LAMMPSvirial" or "KIMvirial" // arg[1] is the KIM Model name + // arg[2] is the print-kim-file flag: 0/1 do-not/do print (default 0) // ensure we are in a clean state for KIM (needed on repeated call) // first time called will do nothing... @@ -300,6 +306,16 @@ void PairKIM::settings(int narg, char **arg) kim_modelname = new char[nmlen+1]; strcpy(kim_modelname, arg[1]); + // set print_kim_file + if ((2 == narg) || ('0' == *(arg[2]))) + { + print_kim_file = false; + } + else + { + print_kim_file = true; + } + return; } @@ -385,6 +401,7 @@ void PairKIM::coeff(int narg, char **arg) void PairKIM::init_style() { // This is called for each "run ...", "minimize ...", etc. read from input + ++init_style_call_count; if (domain->dimension != 3) error->all(FLERR,"PairKIM only works with 3D problems"); @@ -770,6 +787,8 @@ void PairKIM::kim_init() { int kimerror; + // + // determine KIM Model capabilities (used in this function below) set_kim_model_has_flags(); @@ -777,6 +796,11 @@ void PairKIM::kim_init() char* test_descriptor_string = 0; // allocate memory for test_descriptor_string and write descriptor file write_descriptor(&test_descriptor_string); + // print descriptor + if (print_kim_file) + { + error->message(FLERR, test_descriptor_string); + } // initialize KIM model pkim = new KIM_API_model(); @@ -1051,10 +1075,33 @@ void PairKIM::write_descriptor(char** test_descriptor_string) // Write Test name and units strcat(*test_descriptor_string, + "#\n" + "# BEGINNING OF KIM DESCRIPTOR FILE\n" + "#\n" "# This file is automatically generated from LAMMPS pair_style " - "PairKIM command\n" + "kim command\n"); + char tmp_version[100]; + sprintf(tmp_version,"# This is pair-kim-v%i.%i.%i", + PAIR_KIM_VERSION_MAJOR, PAIR_KIM_VERSION_MINOR, + PAIR_KIM_VERSION_PATCH); + strcat(*test_descriptor_string, tmp_version); +#ifdef PAIR_KIM_VERSION_PRERELEASE + sprintf(tmp_version,"-%s", PAIR_KIM_VERSION_PRERELEASE); + strcat(*test_descriptor_string, tmp_version); +#endif +#ifdef PAIR_KIM_VERSION_BUILD_METADATA + sprintf(tmp_version,"+%s", PAIR_KIM_VERSION_BUILD_METADATA); +#endif + strcat(*test_descriptor_string, "\n" -#if KIM_API_VERSION_MAJOR == 1 && KIM_API_VERSON_MINOR == 5 + "# The call number is (pair_style).(init_style): "); + char tmp_num[100]; + sprintf(tmp_num, "%i.%i\n", settings_call_count, init_style_call_count); + strcat(*test_descriptor_string, tmp_num); + strcat(*test_descriptor_string, + "#\n" + "\n" +#if KIM_API_VERSION_MAJOR == 1 && KIM_API_VERSION_MINOR == 5 #else "KIM_API_Version := 1.6.0\n\n" #endif @@ -1111,7 +1158,7 @@ void PairKIM::write_descriptor(char** test_descriptor_string) #else "PARTICLE_SPECIES:\n" #endif - "# Symbol/name Type code\n\n"); + "# Symbol/name Type code\n"); int code=1; char* tmp_line = 0; tmp_line = new char[100]; @@ -1128,7 +1175,7 @@ void PairKIM::write_descriptor(char** test_descriptor_string) strcat(*test_descriptor_string, "\n" "CONVENTIONS:\n" - "# Name Type\n\n" + "# Name Type\n" "ZeroBasedLists flag\n"); // can use iterator or locator neighbor mode, unless in hybrid mode if (lmps_hybrid) @@ -1158,43 +1205,53 @@ void PairKIM::write_descriptor(char** test_descriptor_string) strcat(*test_descriptor_string, "\n" "MODEL_INPUT:\n" - "# Name Type Unit Shape\n\n" - "numberOfParticles integer none []\n\n" - "numberContributingParticles integer none []\n\n" + "# Name Type Unit Shape\n" + "numberOfParticles integer none []\n" + "numberContributingParticles integer none []\n" #if KIM_API_VERSION_MAJOR == 1 && KIM_API_VERSON_MINOR == 5 - "numberParticleTypes integer none []\n\n" + "numberParticleTypes integer none []\n" "particleTypes integer none " #else - "numberOfSpecies integer none []\n\n" + "numberOfSpecies integer none []\n" "particleSpecies integer none " #endif - "[numberOfParticles]\n\n" + "[numberOfParticles]\n" "coordinates double length " - "[numberOfParticles,3]\n\n" - "neighObject pointer none []\n\n" - "get_neigh method none []\n\n"); + "[numberOfParticles,3]\n" + "neighObject pointer none []\n" + "get_neigh method none []\n"); // Write output section strcat(*test_descriptor_string, "\n" "MODEL_OUPUT:\n" - "# Name Type Unit Shape\n\n" - "compute method none []\n\n" - "destroy method none []\n\n" - "cutoff double length []\n\n"); - if (kim_model_has_energy) strcat(*test_descriptor_string, - "energy double energy []\n\n"); - if (kim_model_has_forces) strcat(*test_descriptor_string, + "# Name Type Unit Shape\n" + "compute method none []\n" + "destroy method none []\n" + "cutoff double length []\n"); + if (!kim_model_has_energy) strcat(*test_descriptor_string,"# "); + strcat(*test_descriptor_string, + "energy double energy []\n"); + if (!kim_model_has_forces) strcat(*test_descriptor_string, "# "); + strcat(*test_descriptor_string, "forces double force " - "[numberOfParticles,3]\n\n"); - if (kim_model_has_particleEnergy) strcat(*test_descriptor_string, + "[numberOfParticles,3]\n"); + if (!kim_model_has_particleEnergy) strcat(*test_descriptor_string, "# "); + strcat(*test_descriptor_string, "particleEnergy double energy " - "[numberOfParticles]\n\n"); - if (no_virial_fdotr_compute == 1) strcat(*test_descriptor_string, - "virial double energy [6] \n\n"); - if (kim_model_has_particleVirial) strcat(*test_descriptor_string, + "[numberOfParticles]\n"); + if (no_virial_fdotr_compute != 1) strcat(*test_descriptor_string, "# "); + strcat(*test_descriptor_string, + "virial double energy [6]\n"); + if (!kim_model_has_particleVirial) strcat(*test_descriptor_string, "# "); + strcat(*test_descriptor_string, "particleVirial double energy " - "[numberOfParticles,6] \n\n"); + "[numberOfParticles,6]\n" + "\n"); + strcat(*test_descriptor_string, + "#\n" + "# END OF KIM DESCRIPTOR FILE\n" + "#\n"); return; } diff --git a/src/KIM/pair_kim.h b/src/KIM/pair_kim.h index 0ee748f4ab..a74a7934b2 100644 --- a/src/KIM/pair_kim.h +++ b/src/KIM/pair_kim.h @@ -57,9 +57,12 @@ namespace LAMMPS_NS { // (nearly) all bool flags are not initialized in constructor, but set // explicitly in the indicated function. All other data members are // initialized in constructor + int settings_call_count; + int init_style_call_count; // values set in settings() char* kim_modelname; + bool print_kim_file; // values set in coeff()