Skip to content

Commit

Permalink
Addded string-to-kernel helper functions to facilitate GPs from Dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
stevetorr committed Sep 22, 2019
1 parent 5116cbc commit 956e3a3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions flare/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 956e3a3

Please sign in to comment.