Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmake/Modules/Packages/KIM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@ endif()
option(DOWNLOAD_KIM "Download KIM-API from OpenKIM instead of using an already installed one" ${DOWNLOAD_KIM_DEFAULT})
if(DOWNLOAD_KIM)
message(STATUS "KIM-API download requested - we will build our own")
if(NOT KIM-API_FOUND)
message(WARNING "KIM-API was not found, and DOWNLOAD_KIM is on, "
"so we will download and build our own. "
"If you intend to use LAMMPS with a pre-installed KIM-API, "
"you may need to set PKG_CONFIG_PATH, or run the command "
"'source kim-api-activate', then re-run CMake.")
else()
message(WARNING "KIM-API was was found, but DOWNLOAD_KIM is on, "
"so we will download and build our own. If you intend "
"to use LAMMPS with your pre-installed KIM-API, you "
"should disable DOWNLOAD_KIM and re-run CMake.")
endif()
include(ExternalProject)
enable_language(C)
enable_language(Fortran)
set(KIM_URL "https://s3.openkim.org/kim-api/kim-api-2.2.1.txz" CACHE STRING "URL for KIM tarball")
set(KIM_MD5 "ae1ddda2ef7017ea07934e519d023dca" CACHE STRING "MD5 checksum of KIM tarball")
set(KIM_URL "https://s3.openkim.org/kim-api/kim-api-2.4.2.txz" CACHE STRING "URL for KIM tarball")
set(KIM_MD5 "bd51faa7edfaab437047aea0c25a5dfb" CACHE STRING "MD5 checksum of KIM tarball")
mark_as_advanced(KIM_URL)
mark_as_advanced(KIM_MD5)
ExternalProject_Add(kim_build
Expand Down
33 changes: 15 additions & 18 deletions doc/src/Build_extras.rst
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,12 @@ option in preparations to run on Aurora system at Argonne.
KIM package
---------------------

To build with this package, the KIM library with API v2 must be downloaded
and built on your system. It must include the KIM models that you want to
use with LAMMPS.
To build with this package, the KIM API v2.0+ must be downloaded
and built on your system. See
`Obtaining KIM Models <https://openkim.org/doc/usage/obtaining-models>`_ to
learn how to install the KIM API, as well as how to install any models you
wish to use afterward.
See the list of all KIM models here: https://openkim.org/browse/models

If you would like to use the :doc:`kim query <kim_commands>`
command, you also need to have libcurl installed with the matching
Expand All @@ -404,16 +407,6 @@ channel as ``conda install kim-property`` if LAMMPS is built in Conda. More
detailed information is available at:
`kim-property installation <https://github.com/openkim/kim-property#installing-kim-property>`_.

In addition to installing the KIM API, it is also necessary to install the
library of KIM models (interatomic potentials).
See `Obtaining KIM Models <https://openkim.org/doc/usage/obtaining-models>`_ to
learn how to install a pre-build binary of the OpenKIM Repository of Models.
See the list of all KIM models here: https://openkim.org/browse/models

(Also note that when downloading and installing from source
the KIM API library with all its models, may take a long time (tens of
minutes to hours) to build. Of course you only need to do that once.)

.. tabs::

.. tab:: CMake build
Expand All @@ -430,11 +423,15 @@ minutes to hours) to build. Of course you only need to do that once.)
# value = no (default) or yes

If ``DOWNLOAD_KIM`` is set to ``yes`` (or ``on``), the KIM API library
will be downloaded and built inside the CMake build directory. If
will be downloaded and built inside the CMake build directory. Note that
in most cases it is recommended that you do not use this option, and instead
provide a KIM API installation yourself before building LAMMPS. If
the KIM library is already installed on your system (in a location
where CMake cannot find it), you may need to set the
``PKG_CONFIG_PATH`` environment variable so that libkim-api can be
found, or run the command ``source kim-api-activate``.
found, or run the command ``source kim-api-activate``. If CMake cannot find
the KIM API when configuring for the first time (or after clearing the
CMake cache), the default value of the ``DOWNLOAD_KIM`` option will be ``yes``.

Extra unit tests can only be available if they are explicitly requested
(``KIM_EXTRA_UNITTESTS`` is set to ``yes`` (or ``on``)) and the prerequisites
Expand Down Expand Up @@ -495,9 +492,9 @@ Enabling the extra unit tests have some requirements,
`kim-property installation <https://github.com/openkim/kim-property#installing-kim-property>`_.
* It is also necessary to install the following KIM models:

* ``EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000``
* ``EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005``
* ``LennardJones612_UniversalShifted__MO_959249795837_003``
* ``EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_001``
* ``EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_006``
* ``LennardJones612_UniversalShifted__MO_959249795837_003`` (this model is an example model automatically built with the API unless explicitly disabled)

See `Obtaining KIM Models <https://openkim.org/doc/usage/obtaining-models>`_
to learn how to install a pre-built binary of the OpenKIM Repository of
Expand Down
9 changes: 8 additions & 1 deletion doc/src/kim_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ Using OpenKIM Web Queries in LAMMPS (*kim query*)

The *kim query* command performs a web query to retrieve the predictions of an
IM set by *kim init* for material properties archived in
`OpenKIM <https://openkim.org>`_.
`OpenKIM <https://openkim.org>`_, or to obtain a list of available models
that support a given set of atomic species.

Syntax
------
Expand Down Expand Up @@ -483,6 +484,12 @@ and format of their values depend on the query function used. The current list
of query functions is available on the OpenKIM webpage at
`https://openkim.org/doc/usage/kim-query <https://openkim.org/doc/usage/kim-query/>`_.

.. note::

The *get_available_models* function's output is post-processed by LAMMPS so that
only the names of models that are currently installed are stored in the variable.
Matching models that are not installed are instead written to the LAMMPS log file.

.. note::

All query functions, except *get_available_models*, require the
Expand Down
35 changes: 20 additions & 15 deletions unittest/commands/test_kim_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ using LAMMPS_NS::utils::split_words;

namespace LAMMPS_NS {
using ::testing::StrEq;
using ::testing::DoubleNear;
using ::testing::Eq;

class KimCommandsTest : public LAMMPSTest {
protected:
Expand Down Expand Up @@ -577,14 +579,14 @@ TEST_F(KimCommandsTest, kim_query)
command("clear");
command("kim query latconst_1 get_lattice_constant_cubic "
"crystal=[fcc] species=[Al] units=[angstrom] "
"model=[EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005]");
"model=[EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_006]");
END_HIDE_OUTPUT();

ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349"));
ASSERT_THAT(std::stod(variable->retrieve("latconst_1")), DoubleNear(4.032082033157349, 1.e-2));

BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal");
command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_006 metal");
command("kim query latconst_1 get_lattice_constant_cubic crystal=[fcc] species=[Al] "
"units=[angstrom]");

Expand All @@ -593,50 +595,53 @@ TEST_F(KimCommandsTest, kim_query)
"model=[LennardJones612_UniversalShifted__MO_959249795837_003]");
END_HIDE_OUTPUT();

ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("4.032082033157349"));
ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("3.328125931322575"));
ASSERT_THAT(std::stod(variable->retrieve("latconst_1")), DoubleNear(4.032082033157349, 1.e-2));
ASSERT_THAT(std::stod(variable->retrieve("latconst_2")), DoubleNear(3.328125931322575, 1.e-2));

BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal");
command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_001 metal");

command("kim query latconst split get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] "
"units=[angstrom]");
END_HIDE_OUTPUT();

ASSERT_THAT(variable->retrieve("latconst_1"), StrEq("3.234055244384789"));
ASSERT_THAT(variable->retrieve("latconst_2"), StrEq("5.167650199630013"));
ASSERT_THAT(std::stod(variable->retrieve("latconst_1")), DoubleNear(3.208725140430033, 1.e-2));
ASSERT_THAT(std::stod(variable->retrieve("latconst_2")), DoubleNear(5.239826212595919, 1.e-2));

BEGIN_HIDE_OUTPUT();
command("clear");

command("kim query latconst index get_lattice_constant_hexagonal "
"crystal=[hcp] species=[Zr] units=[angstrom] "
"model=[EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000]");
"model=[EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_001]");
END_HIDE_OUTPUT();
ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789"));
ASSERT_THAT(std::stod(variable->retrieve("latconst")), DoubleNear(3.208725140430033, 1.e-2));

BEGIN_HIDE_OUTPUT();
command("variable latconst delete");
command("clear");
command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_000 metal");
command("kim init EAM_Dynamo_MendelevAckland_2007v3_Zr__MO_004835508849_001 metal");

command("kim query latconst list get_lattice_constant_hexagonal crystal=[hcp] species=[Zr] "
"units=[angstrom]");
END_HIDE_OUTPUT();

ASSERT_THAT(variable->retrieve("latconst"), StrEq("3.234055244384789 5.167650199630013"));
std::vector<std::string> latconsts = utils::split_words(variable->retrieve("latconst"));
ASSERT_THAT(latconsts.size(), Eq(2));
ASSERT_THAT(std::stod(latconsts[0]), DoubleNear(3.208725140430033, 1.e-2));
ASSERT_THAT(std::stod(latconsts[1]), DoubleNear(5.239826212595919, 1.e-2));

BEGIN_HIDE_OUTPUT();
command("clear");
command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_005 metal");
command("kim init EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_006 metal");

command("kim query alpha get_linear_thermal_expansion_coefficient_cubic "
"crystal=[fcc] species=[Al] units=[1/K] temperature=[293.15] "
"temperature_units=[K]");
END_HIDE_OUTPUT();

ASSERT_THAT(variable->retrieve("alpha"), StrEq("1.656579473023212e-05"));
ASSERT_THAT(std::stod(variable->retrieve("alpha")), DoubleNear(1.658279376744496e-05, 1e-7));

BEGIN_HIDE_OUTPUT();
command("clear");
Expand All @@ -645,7 +650,7 @@ TEST_F(KimCommandsTest, kim_query)
END_HIDE_OUTPUT();

std::string model_list = variable->retrieve("model_list");
auto n = model_list.find("EAM_Dynamo_LiuErcolessiAdams_2004_Al__MO_051157671505_000");
auto n = model_list.find("EAM_Dynamo_ErcolessiAdams_1994_Al__MO_123629422045_006");
ASSERT_TRUE(n != std::string::npos);

BEGIN_HIDE_OUTPUT();
Expand Down