choderalab / pymbar

Python implementation of the multistate Bennett acceptance ratio (MBAR)
http://pymbar.readthedocs.io
MIT License
240 stars 93 forks source link

Verbose=True with MBAR results in an error for alternative input types of u_kn #538

Closed jaclark5 closed 2 months ago

jaclark5 commented 2 months ago

A small improvement in consistency within pymbar would improve usability in alchemlyb.

Backgound

Although the input, u_kn, for MBAR is defined to be a np.ndarray, it is converted to an array in line 239 with: self.u_kn = np.array(u_kn, dtype=np.float64) Packages (i.e., alchemlyb) then instead will pass a pd.DataFrame and find that all works as expected due to this conversion.

Problem

When MBAR.fit(verbose=True) is used, there is an indexing error if the provided u_kn is a pd.DataFrame. This is because of line 296: uzero = u_kn[k, indices] - u_kn[l, indices] where u_kn is used instead of self.u_kn.

Solution

If self.u_kn were used in this line instead of u_kn, the users of alchemlyb would be able to benefit from the option, verbose=True.