From 956e3a38199f757abfde0398cdde9f533608ab0f Mon Sep 17 00:00:00 2001 From: Steven T Date: Sun, 22 Sep 2019 18:47:34 -0400 Subject: [PATCH] Addded string-to-kernel helper functions to facilitate GPs from Dicts --- flare/kernels.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/flare/kernels.py b/flare/kernels.py index 888e8515b..7171dfbe6 100644 --- a/flare/kernels.py +++ b/flare/kernels.py @@ -869,3 +869,34 @@ def triplet_force_en_kernel(ci1, ci2, ri1, ri2, ri3, rj1, rj2, rj3, print(kern_finite_diff) print(kern_analytical) assert(np.isclose(kern_finite_diff, kern_analytical, atol=tol)) + +_str_to_kernel = {'two_body': two_body, + 'two_body_en': two_body_en, + 'two_body_force_en': two_body_force_en, + 'three_body': three_body, + 'three_body_en': three_body_en, + 'three_body_force_en': three_body_force_en, + 'two_plus_three_body': two_plus_three_body, + 'two_plus_three_en': two_plus_three_en, + 'two_plus_three_force_en': two_plus_three_force_en + } + + +def str_to_kernel(string: str, include_grad: bool=False): + + if string not in _str_to_kernel.keys(): + raise ValueError("Kernel {} not found in list of available " + "kernels{}:".format(string,_str_to_kernel.keys())) + + if not include_grad: + return _str_to_kernel[string] + else: + if 'two' in string and 'three' in string: + return _str_to_kernel[string], two_plus_three_body_grad + elif 'two' in string and 'three' not in string: + return _str_to_kernel[string], two_body_grad + elif 'two' not in string and 'three' in string: + return _str_to_kernel[string], three_body_grad + else: + raise ValueError("Gradient callable for {} not found".format( + string))