pymbar
pymbar copied to clipboard
Key error due to high nbins
Used the Umbrella sampling example with my data. Gave me the following when the nbins where higher than an particular value:
File ~/opt/anaconda3/envs/pymbar/lib/python3.10/site-packages/pymbar/fes.py:1470 in FES._get_fes_histogram(self, x, reference_point, fes_reference, uncertainty_method)
-> bin_label = histogram_data["bin_label"][tuple(l)]
KeyError: (56,)
Can be solved by change the bin_label = histogram_data["bin_label"][tuple(l)]
to (atleast in case 1D)
try:
bin_label = histogram_data["bin_label"][tuple(l)]
except KeyError:
if np.all(l[0] < bin_label_keys): # out of key below
fx_vals[i] = np.nan
dfx_vals[i] = np.nan
continue
if np.all(l[0] >= bin_label_keys): # out of key above
fx_vals[i] = np.nan
dfx_vals[i] = np.nan
continue