Minimal model and driver template files for kim-api-v2

The kim-api does not provide access to this. You need to keep track of these codes within our own code. If you need to have persistant data between the various model routines (model_compute, model_refresh, model_destroy, model_compute_arguments_create, model_compute_arguments_destroy) you should change the model_buffer_type to include the data needed.

Ryan

Ryan,

I almost finished the neural network driver for energy calculations (it does not have forces yet). Now, in order to make it more modular, I would like to use external modules (e.g. “cutoffs.F90”) and subroutines in the driver (instead of having them inside the script “toy_model_driver.F90”). Do you know where I should place those external modules and subroutines, and if I need to change any line either in “toy_model_driver.F90” or “Makefile” to locate them?

Thanks and regards,
Alireza

Hello,

You can just add the additional files to the "LOCALOBJ" variable in the make file.

Ryan

Thanks Ryan! Sorry, I am disturbing you, but I am almost done, and a few minor issues are remaining. I came across the following questions:

1- Is there a simple way to include an atom itself also in the neighbor list? For example, say the neighbors of atom index 1 are atoms 3 and 5. Is there a simple way to get [1, 3, 5] as the neighbors, and not [3, 5]? I am suspected to neighbor_list_index, what is that?

2- What is the difference between “double precision” and “real(c_double)” type? Which one should I use? The same for “integer” and “integer(c_int)”?

3- What are influence_distance, padding_neighbor_hints, and half_list_hints?

Thanks and regards,
Alireza

One more thing I forgot to ask:

4- How should I add forces to my simulator and model driver? I added the following line to the simulator, but it gives error:

call kim_compute_arguments_set_argument_pointer(compute_arguments_handle, &

kim_compute_argument_name_partial_forces, forces, ierr2)

ierr = ierr + ierr2

Also, should I change the input to the kim_model_create subroutine? What lines should be added to the toy_dimer_simulator you provided me with a while ago (I reattached it to this email).

Thanks and regards,
Alireza

toy_dimer_simulator.txz (3.21 KB)

Thanks Ryan! Sorry, I am disturbing you, but I am almost done, and a few
minor issues are remaining. I came across the following questions:

1- Is there a simple way to include an atom itself also in the neighbor
list? For example, say the neighbors of atom index 1 are atoms 3 and 5. Is
there a simple way to get [1, 3, 5] as the neighbors, and not [3, 5]? I am
suspected to neighbor_list_index, what is that?

No this is not allowed.

The "neighbor_list_index" is for when the model uses multiple neighbor lists. it is the index labeling each such list.

2- What is the difference between "double precision" and "real(c_double)"
type? Which one should I use? The same for "integer" and "integer(c_int)"?

real(c_double) is guaranteed to be the same as "double" in C.
integer(c_int) is guaranteed to be the same as "int" in C.

These should be used to make sure that fortran in interoperable with C and C++.

3- What are influence_distance, padding_neighbor_hints, and half_list_hints?

influence_distance is described here : https://openkim.org/kim-api/docs/theory.html

padding_neighbor_hints, and half_list_hints are described here :
https://openkim.org/kim-api/docs/implementation.html#neighbor_list_hints

however, recent interactions and work have caused us to change this part of the kim api. Most everything else is unchanged. We will be making a new beta release in the next few days.

Ryan

I suggest you study the "ex_model_driver_P_LJ" example model driver to discover these details.

Cheers,

Ryan

Ryan,

I followed the example model driver “ex_model_driver_P_LJ”, and did

call kim_model_compute_arguments_get_argument_pointer( &

model_compute_arguments_handle, &

kim_compute_argument_name_partial_forces, 3, num_atoms, forces, ierr2)

ierr = ierr + ierr2

to get argument pointers, and also

call kim_model_compute_arguments_create_set_argument_support_status( &

model_compute_arguments_create_handle, &

kim_compute_argument_name_partial_forces, &

kim_support_status_required, ierr2)

ierr = ierr + ierr2

to register forces. But when installing the model driver it gives error:

toy_model_driver.F90:159.74:

kim_compute_argument_name_partial_forces, 3, num_atoms, forces, ierr2)

1

Error: There is no specific subroutine for the generic ‘kim_model_compute_arguments_get_argument_pointer’ at (1)

I suspect something might have been updated since “ex_model_driver_P_LJ”?

Regards,
Alireza

I suppect your 'forces' variable is not of the correct type. It must be declared as:

real(c_double), pointer :: forces(:,:slight_smile:

Ryan

Thanks Ryan! That solved the issue. Next (probably the final step) is calling “toy_parametrized_model” from lammps input with

pair_style kim KIMvirial toy_parameterized_model

but it gives the following error:

LAMMPS (8 Mar 2018)

Lattice spacing in x,y,z = 1.5 1.5 1.5

Created orthogonal box = (0 0 0) to (15 15 15)

1 by 1 by 1 MPI processor grid

Created 4000 atoms

Time spent = 0.000464201 secs

The Model shared library file is not readable for Model name: ‘toy_parameterized_model’.

  • Error: at line 1038 in …/pair_kim.cpp

Message: KIM initialization failed

KIM_STATUS_MSG: unsuccessful completion

ERROR: Internal KIM error (…/pair_kim.cpp:1038)

Last command: run 0

I got the same error with “LennardJones612_UniversalShifted__MO_959249795837_003” model, so it does not seem to be an issue with the “toy_parameterized_model”. Maybe an issue with API v2??

LAMMPS (8 Mar 2018)

Lattice spacing in x,y,z = 1.5 1.5 1.5

Created orthogonal box = (0 0 0) to (15 15 15)

1 by 1 by 1 MPI processor grid

Created 4000 atoms

Time spent = 0.000476122 secs

The Model shared library file is not readable for Model name: ‘LennardJones612_UniversalShifted__MO_959249795837_003’.

  • Error: at line 1038 in …/pair_kim.cpp

Message: KIM initialization failed

KIM_STATUS_MSG: unsuccessful completion

ERROR: Internal KIM error (…/pair_kim.cpp:1038)

Last command: run 0

Regards,
Alireza

Hi,

To use lammps with kim-api-v2, for the moment you would need to use the development branch of my lammps github repo:

https://github.com/ellio167/lammps/tree/kim-v2-update

This is in active development and we will not really be able to provide much support while it is in this state. But, if you want to try it out you are welcome.

We are working hard to complete the kim-api-v2 lammps support (and a bunch of other new kim features) and we hope to have it officially released as soon as possbile.

Cheers,

Ryan

Thanks Ryan for letting me know! Do you have an estimate of when lammps will support kim-api-v2, like in a month or in six months or a year from now?

BTW, how should periodicity be controlled in the simulator, i.e. how can I switch from a non-periodic system to a periodic system in say the x-direction?

Regards,
Alireza

Thanks Ryan for letting me know! Do you have an estimate of when lammps
will support kim-api-v2, like in a month or in six months or a year from
now?

I really hope it will be one month; we'll need to see how the start of the academic semester goes...

BTW, how should periodicity be controlled in the simulator, i.e. how can I
switch from a non-periodic system to a periodic system in say the
x-direction?

That is something that is essentially fully controlled by the simulator. The simulator must use non-contributing particles with kim-api models to emulate periodic-boundary-conditions. So, to simulate non-periodic BC's in one direction it would just not provide non-contributing particles surrounding the contributing particles in that direction. Each simulator will generally have its own way for the user to set the BCs in the various directions.

Ryan

Hi Ryan,

Thanks! I just uninstalled the previous version of lammps and installed your lammps github repository. Now “which lmp_mpi” gives

lammps-ryan/src/lmp_mpi

But the same error still happens:

$ lmp_mpi < in.kim

LAMMPS (16 Aug 2018)

Lattice spacing in x,y,z = 1.5 1.5 1.5

Created orthogonal box = (0 0 0) to (15 15 15)

1 by 1 by 1 MPI processor grid

Created 4000 atoms

Time spent = 0.000505924 secs

The Model shared library file is not readable for Model name: ‘LennardJones612_UniversalShifted__MO_959249795837_003’.

  • Error: at line 1037 in …/pair_kim.cpp

Message: KIM initialization failed

KIM_STATUS_MSG: unsuccessful completion

ERROR: Internal KIM error (…/pair_kim.cpp:1037)

Last command: run 0

So it does not seem to work out. The other way is that I downgrade my model and model driver to kim-v1. Do you think I should do that?

Thanks and regards,
Alireza

You are likely still on the master branch. You need the kim-v2-update branch

Okey! I tried the kim-v2-update branch. It seems to have a bug: When I do “make mpi” inside /lammps-v2-update/src/, it gives the following error:

…/pair_kim.cpp: In member function ‘virtual void LAMMPS_NS::PairKIM::kim_init()’:

…/pair_kim.cpp:719:63: error: no matching function for call to ‘KIM::Model::GetNeighborListPointers(int*, const double**, const int**)’

&modelWillNotRequestNeighborsOfNoncontributingParticles);

^

…/pair_kim.cpp:719:63: note: candidate is:

In file included from /usr/local/lib/kim-api-v2/include/KIM_SimulatorHeaders.hpp:38:0,

from …/pair_kim.h:68,

from …/pair_kim.cpp:60:

/usr/local/lib/kim-api-v2/include/KIM_Model.hpp:76:8: note: void KIM::Model::GetNeighborListPointers(int*, const double**, const int**, const int**) const

void GetNeighborListPointers(int * const numberOfNeighborLists,

^

/usr/local/lib/kim-api-v2/include/KIM_Model.hpp:76:8: note: candidate expects 4 arguments, 3 provided

make[1]: *** [pair_kim.o] Error 1

make[1]: Leaving directory `/home/vagrant/lammps-kim-v2-update/src/Obj_mpi’

make: *** [mpi] Error 2

Regards,
Alireza

Ryan,

My apologies for discussing this here, but I could not find a bug-reporting place in the https://github.com/ellio167/lammps/tree/kim-v2-update repository. There seems to be a bug in Line 719 of https://github.com/ellio167/lammps/blob/kim-v2-update/src/KIM/pair_kim.cpp:

pkim->GetNeighborListPointers(
&kim_number_of_neighbor_lists,
&kim_cutoff_values,
&modelWillNotRequestNeighborsOfNoncontributingParticles);

has three inputs but it is expected to have four inputs according to Line 76 of https://openkim.org/kim-api/docs/_k_i_m___model_8hpp_source.html:

void GetNeighborListPointers(int * const numberOfNeighborLists,
77 double const ** const cutoffs,
78 int const ** const paddingNeighborHints,
79 int const ** const halfListHints) const;

I removed the last input from KIM_Model.hpp, so that both have three inputs when calling GetNeighborListPointers. But then it gives error when I do “make mpi” to build kim-v2 for lammps:

pair_kim.o: In function `LAMMPS_NS::PairKIM::kim_init()’:

/home/vagrant/lammps-kim-v2-update/src/Obj_mpi/…/pair_kim.cpp:719: undefined reference to `KIM::Model::GetNeighborListPointers(int*, double const**, int const**) const’

collect2: error: ld returned 1 exit status

make[1]: *** […/lmp_mpi] Error 1

make[1]: Leaving directory `/home/vagrant/lammps-kim-v2-update/src/Obj_mpi’

make: *** [mpi] Error 2

Unfortunately it doesn’t seem that I have the knowledge to fix this. So I will stop trying to use kim-v2 with lammps, and take the second route: downgrading my neural network model and model driver to kim-v1 version. Is there any fortran model for kim-v1 so I can look at and see how I should downgrade?

Thanks and regards,
Alireza

Hi Alireza,

The kim-ckim-v2-update branch of the ellio167/lammps repo is current with the 'devel-v2' branch of the openkim/kim-api repo. So, you'll need to switch from the beta.1 release to the latest kim-api code in the git repo.

There we have switched to a cmake build. You will want to do something like this (which is what I do on my macOS):

cd kim\-api mkdir build
cd build CC=gcc-8 CXX=g++-8 FC=gfortran-8 cmake ../ -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=\{HOME\}/local \-DKIM\_API\_BUILD\_MODELS\_AND\_DRIVERS=ON make -j4
$ make install

Then things should be similar to what you've been working with from beta.1

Cheers,

Ryan

Thanks Ryan! As per your instruction, I am trying to switch to dev-2 version of kim-api. I could install it with some try and error. Now I get

$ kim-api-v2-collections-management list

Knowledgebase of Interatomic Models (KIM) — Model Collections Listing

Hi Alireza,

I needed to make an update to the lammps code so it can find the kim-api library (using the pkg-config utility instead of the old build-config utility).

I've pushed the change to my lammps repo. Please pull and try again.

Cheers,

Ryan