OpenKim Model Drivers to utilize Neural Network Potentials in ASE

Hi all,

I’m interested in using the PANNA__MD_805652781592_000 model driver within the ASE code to run some simulations. I’ve installed the libkim-api-model-driver shared object, and I have the required network files to generate a model, but I’m at a loss for how to use my data within an ASE calculator object. I apologize for my ignorance, but I can’t seem to find any documentation. I guess I just don’t understand how model drivers work.

Thank you for your time,
Ray

Hi Ray,

If you’ve followed the instructions in the driver’s README file (https://openkim.org/files/MD_805652781592_000/README) then the next step is to create the CMakeLists.txt file and build/install your Model.

What are the names of the network files you have? I’ll try to mockup a CMakeLists.txt file for them and provide additional instructions.

Thanks for your quick reply! I’ve successfully created the portable model with the this Cmake file:

cmake_minimum_required(VERSION 3.10)
list(APPEND CMAKE_PREFIX_PATH ENV{KIM_API_CMAKE_PREFIX_DIR}) find_package(KIM-API-ITEMS 2.2 REQUIRED CONFIG) kim_api_items_setup_before_project(ITEM_TYPE "portableModel") project(BTBT_128_32) kim_api_items_setup_after_project(ITEM_TYPE "portableModel") add_kim_api_model_library( NAME {PROJECT_NAME}
DRIVER_NAME “PANNA__MD_805652781592_000”
PARAMETER_FILES “networks_metadata.json”
)

I then run ‘make’ and ‘make install’ and the shared object gets copied here:
/lib/x86_64-linux-gnu/kim-api/portable-models/BTBT_128_32/libkim-api-portable-model.so

But, when I attempt to load the portable model in python3 via the ASE (see below)

from ase.calculators.kim import KIM
calc = KIM(“BTBT_128_32”, debug=True)

I get an error like so:
/home/ray/.local/lib/python3.8/site-packages/ase/calculators/kim/kimpy_wrappers.py", line 24, in check_call
return f(*args, **kwargs)
RuntimeError: Unable to create a new KIM-API Model object!

Also, in my current working directory, I get a kim.log file with the following contents:

2021-11-12:10:48:38EST * 0 * information * 0x5648b5409250 * KIM_LogImplementation.cpp:110 * Log object created. Default verbosity level is ‘information’.
2021-11-12:10:48:38EST * 1 * information * 0x5648b5409250 * KIM_LogImplementation.cpp:120 * Log object destroyed.
2021-11-12:10:48:38EST * 0 * information * 0x5648b5409250 * KIM_LogImplementation.cpp:110 * Log object created. Default verbosity level is ‘information’.
2021-11-12:10:48:38EST * 0 * information * 0x5648b52aba00 * KIM_LogImplementation.cpp:110 * Log object created. Default verbosity level is ‘information’.
2021-11-12:10:48:38EST * 1 * information * 0x5648b52aba00 * KIM_LogImplementation.cpp:242 * Log object renamed. ID changed to ‘0x5648b5409250_Collections’.
2021-11-12:10:48:38EST * 2 * information * 0x5648b5409250_Collections * KIM_LogImplementation.cpp:246 * Log object renamed. ID changed from ‘0x5648b52aba00’.
2021-11-12:10:48:38EST * 1 * warning * 0x5648b5409250 * KIM_ModelImplementation.cpp:874 * Use of the GetParameterFileName(0, 0x5648b54c7c40). function is deprecated. Please use GetParameterFileBasename() instead.
2021-11-12:10:49:13EST * 0 * error * 0x5648b5409250 * KIM_SharedLibrary.cpp:348 * SharedLibrary not open.
2021-11-12:10:49:13EST * 0 * information * 0x5648b5409250_Collections * KIM_LogImplementation.cpp:120 * Log object destroyed.
2021-11-12:10:49:13EST * 1 * error * 0x5648b5409250 * KIM_ModelImplementation.cpp:2343 * Model supplied Create() routine did not set SpeciesCode.
2021-11-12:10:49:13EST * 2 * information * 0x5648b5409250 * KIM_LogImplementation.cpp:120 * Log object destroyed.

Is this as simple as setting the appropriate paths?

Thanks again,
Ray

Hi Ray,

There should be a “.in” file and one or more “.dat” files. The .in file lists the network architecture details and the .dat files give the weights and biases.

The CMakeLists.txt file should look something like:

cmake_minimum_required(VERSION 3.10)

list(APPEND CMAKE_PREFIX_PATH $ENV{KIM_API_CMAKE_PREFIX_DIR})
find_package(KIM-API-ITEMS 2.2 REQUIRED CONFIG)

kim_api_items_setup_before_project(ITEM_TYPE "portableModel")
project(BTBT_128_32)
kim_api_items_setup_after_project(ITEM_TYPE "portableModel")

add_kim_api_model_library(
  NAME            ${PROJECT_NAME}
  DRIVER_NAME     "PANNA__MD_805652781592_000"
  PARAMETER_FILES "panna.in"
                  "weights_X.dat"
                  "weights_Y.dat"
  )

where ‘X’ and ‘Y’ would be the species that your model works with.

If I’m not mistaken, the networks_metadata.json file is the only parameter file I need. Here are its contents:

{“verison”: “v0”, “scaffold_type”: “PANNA”, “networks_type”: [“a2ff”, “a2ff”, “a2ff”], “networks_layers_size”: [[128, 32, 1], [128, 32, 1], [128, 32, 1]], “networks_feature_size”: [240, 240, 240], “networks_layers_activation”: [[1, 1, 0], [1, 1, 0], [1, 1, 0]], “networks_layers_trainable”: [[true, true, true], [true, true, true], [true, true, true]], “networks_species”: [“H”, “S”, “C”], “networks_offset”: [0.0, 0.0, 0.0], “networks_files”: [[[“species_H_layer_0_weights_240x128.npy”, “species_H_layer_0_biases_128.npy”], [“species_H_layer_1_weights_128x32.npy”, “species_H_layer_1_biases_32.npy”], [“species_H_layer_2_weights_32x1.npy”, “species_H_layer_2_biases_1.npy”]], [[“species_S_layer_0_weights_240x128.npy”, “species_S_layer_0_biases_128.npy”], [“species_S_layer_1_weights_128x32.npy”, “species_S_layer_1_biases_32.npy”], [“species_S_layer_2_weights_32x1.npy”, “species_S_layer_2_biases_1.npy”]], [[“species_C_layer_0_weights_240x128.npy”, “species_C_layer_0_biases_128.npy”], [“species_C_layer_1_weights_128x32.npy”, “species_C_layer_1_biases_32.npy”], [“species_C_layer_2_weights_32x1.npy”, “species_C_layer_2_biases_1.npy”]]], “gvect_params”: {“eta_rad”: 16.0, “Rc_rad”: 6.0, “Rs0_rad”: 0.5, “RsN_rad”: 16, “Rsst_rad”: 0.34375, “eta_ang”: 6.0, “Rc_ang”: 6.0, “Rs0_ang”: 0.5, “RsN_ang”: 4, “Rsst_ang”: 0.65, “zeta”: 50.0, “ThetasN”: 8}}

All of these files are in the build directory with the above CMakeLists.txt file. I see several errors in the kim.log file:

2021-11-15:19:18:41EST * 0 * information * 0x2d64ee0 * KIM_LogImplementation.cpp:110 * Log object created. Default verbosity level is ‘information’.
2021-11-15:19:18:41EST * 1 * information * 0x2d64ee0 * KIM_LogImplementation.cpp:120 * Log object destroyed.
2021-11-15:19:18:41EST * 0 * information * 0x2d64ee0 * KIM_LogImplementation.cpp:110 * Log object created. Default verbosity level is ‘information’.
2021-11-15:19:18:41EST * 0 * information * 0x2d0a7d0 * KIM_LogImplementation.cpp:110 * Log object created. Default verbosity level is ‘information’.
2021-11-15:19:18:41EST * 1 * information * 0x2d0a7d0 * KIM_LogImplementation.cpp:242 * Log object renamed. ID changed to ‘0x2d64ee0_Collections’.
2021-11-15:19:18:41EST * 2 * information * 0x2d64ee0_Collections * KIM_LogImplementation.cpp:246 * Log object renamed. ID changed from ‘0x2d0a7d0’.
2021-11-15:19:18:41EST * 1 * warning * 0x2d64ee0 * KIM_ModelImplementation.cpp:874 * Use of the GetParameterFileName(0, 0x2e25de0). function is deprecated. Please use GetParameterFileBasename() instead.
2021-11-15:19:19:14EST * 0 * error * 0x2d64ee0 * KIM_SharedLibrary.cpp:348 * SharedLibrary not open.
2021-11-15:19:19:14EST * 0 * information * 0x2d64ee0_Collections * KIM_LogImplementation.cpp:120 * Log object destroyed.
2021-11-15:19:19:14EST * 1 * error * 0x2d64ee0 * KIM_ModelImplementation.cpp:2343 * Model supplied Create() routine did not set SpeciesCode.
2021-11-15:19:19:14EST * 2 * information * 0x2d64ee0 * KIM_LogImplementation.cpp:120 * Log object destroyed.

I’m not familiar with the Kim api, but I’m assuming the shared library errors aren’t good. Any thoughts? Sorry for the wall of text but I’m a new user so I can’t upload files!

Hi Ray,

I think there are probably two issues. One is getting the shared library built and installed correctly and the other is related to the parameter files that the driver expects.

For the first issue, I think it might be simplest to try to have a live interaction to see what is happening on your system. Please contact us at [email protected] and we’ll coordinate a zoom meeting.

For the second issue, the PANNA Model Driver README (https://openkim.org/files/MD_805652781592_000/README) says you need to use the extract_weights.py script (panna/extract_weights.py · master · PANNAdevs / PANNA · GitLab) to create the .in and .dat files. So, it will be helpful to try to generate those files.

Thanks,
Ryan

Hi Ryan,

I used the extract_weights.py script to generate the network_metadata.json file and the associated *.npy files which contain the weights and biases of the network. I’ll reach out to setup a zoom meeting. Thanks again for all your help.

Ray

Hi all,

Posting an update here to share the solution to my problem.The key is to change the output type from “PANNA” to “LAMMPS” in the configuration file when using the extract_weights.py script. For example:

[IO_INFORMATION]
train_dir = ./tutorial_train
step_number = 100000
output_dir = ./saved_weights
output_type = LAMMPS
train_input = train1.ini
gvector_input = gvect_sample.ini

Then, specify the panna.in and the weights_*.data as parameter files for the CMakeLists.txt file. This will give you a usable portable model!

Ray