Modifying the parameters of the Tersoff model driver without recompiling

Hi,

I would like to use the model driver for the Tersoff potential (Tersoff_LAMMPS__MD_077075034781_001) to do some parameter optimization.

I can adjust the parameters of the accompanied model by modifying the “.params”-file and recompile the model, however recompiling every
time a parameter is updated is of course problematic during a parameter search.

What would be the best way (hack or otherwise) to modify the parameters of the Tersoff model driver without recompiling?

Best,

Jacob

Hi Jakob,

This is a nice question. In fact, we are currently working on this issue along a number of fronts. We have implemented an interface in the potfit package for using KIM models. It has not yet been released, as we are still doing some testing, but I think we could share a beta version with anyone who is interested at this point.

We are also in the beginning stages of developing a similar potential fitting tool that will eventually become a part of the openkim.org system and allow for the easy specification of training sets, testing sets, and the like based on the content in openkim.org.

Finally, and more directly to your question I suspect, the KIM API provides a programmatic mechanism for changing a model's parameters, when the model developer has implemented such support.

You can look at, say, Three_Body_Stillinger_Weber__MD_335816936951_001, for instance to see an example that provides PARAM_FREE_* type parameters as listed in the .kim.tpl file.

See the file "standard.kim" under the MODEL_PARAMETERS section the documentation in KIM_API_Description.txt for these api calls:

   KIM_API_get_num_params
   KIM_API_get_parameter
   KIM_API_get_num_free_params
   KIM_API_get_free_parameter
   KIM_API_get_num_fixed_params
   KIM_API_get_fixed_parameter

   KIM_API_model_reinit

Unfortunately, the Tersoff_LAMMPS__MD_077075034781_001 model driver does not implement this support.

You might try contacting Tobias Brink, who contributed the Tersoff model driver, and see if he is interested/willing to implement these feature and/or interested in collaborating on such an implementation.

I hope this is all helpful information.

Cheers,

Ryan

Hi Jakob, hi Ryan!

This feature should in fact be already implemented but I didn't submit it to the official KIM repo, yet. It should be in my private repo at

https://github.com/t-brink/kim-tersoff

I'm still not 100% sure if I like the way I implemented it, so please let me know if you hit any roadblocks. If it works for you it may be time to push the improvements to the official KIM site.

Tobias

Hi Ryan and Tobias,

Thank you both for the fast responses!

I will try the new version of the Tersoff model as soon as possible.

The reason that it might take a little while is that I’m using the ASAP simulator, and free parameters are not yet implemented for OpenKIM models.
However, we will look into implementing this feature for ASAP next week, and I will make sure to report back after testing the new version of the Tersoff model.

Best,

Jacob

Hi,

I am currently trying to implement the free parameters in Asap. It is reasonably straight-forward, except that I am in doubt if I am understanding the KIM API correctly, and also have a question about accessing the type of a parameter.

I assume to read the parameters from the model, I have to do something like this:

* Get the number of parameters using KIM_API_get_num_free_params()

* For each parameters:
  * Get its name with KIM_API_get_free_parameter().
  * Get size of array using KIM_API_get_rank() and KIM_API_get_size() — I assume a scalar has rank 0.
  * Get the type of the data using ??? QUESTION: How do I see if it is integer or double?
  * Get a pointer to the actual data using KIM_API_get_data()
  * Copy the data into a suitable Python object.

Is this correct? And how do I get the data type?

Best regards

Jakob

Hi Jakob,

* Get the number of parameters using KIM_API_get_num_free_params()

Yes.

* For each parameters:
  * Get its name with KIM_API_get_free_parameter().

Yes

  * Get size of array using KIM_API_get_rank() and KIM_API_get_size()

Yes

        — I assume a scalar has rank 0.

Yes

  * Get the type of the data using ??? QUESTION: How do I see if it is integer or double?

Ha!!! Why would you want to do that? :wink:

You've identified a real deficiency. There is no direct way (but there should be.) I'll have to add an api routine for this...

In the meantime, the only way you can do this at run time is to use KIM_API_get_model_kim_str() and parse it to find the parameter and its type... (What a pain! Sorry about that...)

  * Get a pointer to the actual data using KIM_API_get_data()

Yes.

  * Copy the data into a suitable Python object.

Yes; I guess (unless you can just wrap the pointer in some way).

In addition.

Once you have made any changes to the parameters (and copied them back into the actual data locations, if necessary), you need to execute KIM_API_model_reinit() before calling KIM_API_model_compute().

Cheers,

Ryan

Dear Ryan,

Thanks for the quick answer.

  * Get the type of the data using ??? QUESTION: How do I see if it is integer or double?

Ha!!! Why would you want to do that? :wink:

You've identified a real deficiency. There is no direct way (but there should be.) I'll have to add an api routine for this...

In the meantime, the only way you can do this at run time is to use KIM_API_get_model_kim_str() and parse it to find the parameter and its type... (What a pain! Sorry about that…)

I think that for now I will opt for the simpler solution: Assume it is of type double. After all, how many models have integer parameters? … checking … oops, quite a number, but they are all fixed parameters, so less likely to cause disasters.

I guess I will implement it without type check for now, and add a type check once it is in the API.

  * Copy the data into a suitable Python object.

Yes; I guess (unless you can just wrap the pointer in some way).

I could perhaps wrap it into a read-only numpy array (so the user does not modify the parameter without calling reinit), but then I have to worry about the script deallocating the calculator before the array. A copy seems simpler.

Thanks for the help. I will try to implement it today.

Best regards

Jakob

Thanks again for your help, Ryan!

It looks like I got it up and running. :slight_smile:

Hi Jakob,

That's correct. Use the pointer returned by kim_api_get_data and set the values directly in that memory space.

Cheers,

Ryan