From dab5eac5490e0b039348a878ea487e190ee96368 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Mon, 24 Aug 2020 16:36:39 +0100 Subject: [PATCH 01/16] mbar overlap matrix --- docs/visualisation.rst | 28 +++++++ ...hemlyb.visualisation.plot_mbar_omatrix.rst | 16 ++++ src/alchemlyb/estimators/mbar_.py | 4 + src/alchemlyb/tests/test_visualisation.py | 17 ++++ src/alchemlyb/visualisation/__init__.py | 1 + src/alchemlyb/visualisation/mbar_martix.py | 78 +++++++++++++++++++ 6 files changed, 144 insertions(+) create mode 100644 docs/visualisation.rst create mode 100644 docs/visualisation/alchemlyb.visualisation.plot_mbar_omatrix.rst create mode 100644 src/alchemlyb/tests/test_visualisation.py create mode 100644 src/alchemlyb/visualisation/__init__.py create mode 100644 src/alchemlyb/visualisation/mbar_martix.py diff --git a/docs/visualisation.rst b/docs/visualisation.rst new file mode 100644 index 00000000..c84cfcae --- /dev/null +++ b/docs/visualisation.rst @@ -0,0 +1,28 @@ +Visualisation of the results +============================ +It is quite often that the user want to visualise the results to gain +confidence on the computed free energy. **alchemlyb** provides various +visualisation tools to help user to judge the estimate. + +.. _plot_overlap_matrix: +Overlap Matrix of the MBAR +-------------------------- +The accuracy of the :class:`~alchemlyb.estimators.MBAR` estimator depends on +the overlap between different lambda states. The overlap matrix from the +:class:`~alchemlyb.estimators.MBAR` estimator could be plotted to check +the degree of overlap. It is recommended that there should be at least +**0.05** overlap between neighboring states. :: + + >>> import pandas as pd + >>> from alchemtest.gmx import load_benzene + >>> from alchemlyb.parsing.gmx import extract_u_nk + >>> from alchemlyb.estimators import MBAR + + >>> bz = load_benzene().data + >>> u_nk_coul = pd.concat([extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]) + >>> mbar_coul = MBAR() + >>> mbar_coul.fit(u_nk_coul) + + >>> from alchemlyb.visualisation.mbar_martix import plot_mbar_omatrix + >>> ax = plot_mbar_omatrix(mbar_coul.overlap_maxtrix) + >>> ax.figure.savefig('O_MBAR.pdf', bbox_inches='tight', pad_inches=0.0) diff --git a/docs/visualisation/alchemlyb.visualisation.plot_mbar_omatrix.rst b/docs/visualisation/alchemlyb.visualisation.plot_mbar_omatrix.rst new file mode 100644 index 00000000..ccdaa6af --- /dev/null +++ b/docs/visualisation/alchemlyb.visualisation.plot_mbar_omatrix.rst @@ -0,0 +1,16 @@ +Plot Overlap Matrix from MBar +============================= + +The function :func:`~alchemlyb.visualisation.plot_mbar_omatrix` allows the user +to plot the overlap matrix from +:attr:`~alchemlyb.estimators.MBAR.overlap_maxtrix`. The user can pass +:class:`matplotlib.axes.Axes` into the function to have the overlap maxtrix +drawn on a specific axes. The user could also specify a list of lambda states +to be skipped when labelling the states. + +Please check :ref:`How to plot MBAR overlap matrix ` for +usage. + +API Reference +------------- +.. autofunction:: alchemlyb.visualisation.plot_mbar_omatrix \ No newline at end of file diff --git a/src/alchemlyb/estimators/mbar_.py b/src/alchemlyb/estimators/mbar_.py index 6d3b4e36..171429f6 100644 --- a/src/alchemlyb/estimators/mbar_.py +++ b/src/alchemlyb/estimators/mbar_.py @@ -45,6 +45,9 @@ class MBAR(BaseEstimator): states_ : list Lambda states for which free energy differences were obtained. + overlap_maxtrix: DataFrame + The overlap matrix. + """ def __init__(self, maximum_iterations=10000, relative_tolerance=1.0e-7, @@ -85,6 +88,7 @@ def fit(self, u_nk): verbose=self.verbose) self.states_ = u_nk.columns.values.tolist() + self.overlap_maxtrix = self._mbar.computeOverlap()['matrix'] # set attributes out = self._mbar.getFreeEnergyDifferences(return_theta=True) diff --git a/src/alchemlyb/tests/test_visualisation.py b/src/alchemlyb/tests/test_visualisation.py new file mode 100644 index 00000000..ec3771af --- /dev/null +++ b/src/alchemlyb/tests/test_visualisation.py @@ -0,0 +1,17 @@ + +def test_plot_mbar_omatrix(): + '''Just test if the plot runs''' + import pandas as pd + from alchemtest.gmx import load_benzene + from alchemlyb.parsing.gmx import extract_u_nk + from alchemlyb.estimators import MBAR + + bz = load_benzene().data + u_nk_coul = pd.concat([extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]) + mbar_coul = MBAR() + mbar_coul.fit(u_nk_coul) + + from alchemlyb.visualisation.mbar_martix import plot_mbar_omatrix + plot_mbar_omatrix(mbar_coul.overlap_maxtrix) + plot_mbar_omatrix(mbar_coul.overlap_maxtrix, [1,]) + diff --git a/src/alchemlyb/visualisation/__init__.py b/src/alchemlyb/visualisation/__init__.py new file mode 100644 index 00000000..f8cc4c2a --- /dev/null +++ b/src/alchemlyb/visualisation/__init__.py @@ -0,0 +1 @@ +from .mbar_martix import plot_mbar_omatrix \ No newline at end of file diff --git a/src/alchemlyb/visualisation/mbar_martix.py b/src/alchemlyb/visualisation/mbar_martix.py new file mode 100644 index 00000000..6676c739 --- /dev/null +++ b/src/alchemlyb/visualisation/mbar_martix.py @@ -0,0 +1,78 @@ +"""Functions for Plotting the overlay matrix for the Mbar estimator. + +""" +import matplotlib.pyplot as plt +import numpy as np +def plot_mbar_omatrix(matrix, skip_lambda_index=[], ax=None): + '''Plot the MBar overlap matrix. + + Parameters + ---------- + matrix : DataFrame + DataFrame of the overlap matrix obtained from + :attr:`~alchemlyb.estimators.MABR.overlap_maxtrix` + skip_lambda_index : List + list of lambda indices to be omitted from plotting process. + Default: []. + ax : matplotlib.axes.Axes + Matplotlib axes object where the plot will be drawn on. If ax=None, + a new axes will be generated. + + Returns + ------- + matplotlib.axes.Axes + An axes with the overlap matrix drawn. + ''' + # Compute the size of the figure, if ax is not given. + max_prob = matrix.max() + size = len(matrix) + if ax is None: + fig, ax = plt.subplots(figsize=(size / 2, size / 2)) + ax.set_xticks([]) + ax.set_yticks([]) + ax.axis('off') + for i in range(size): + if i != 0: + ax.axvline(x=i, ls='-', lw=0.5, color='k', alpha=0.25) + ax.axhline(y=i, ls='-', lw=0.5, color='k', alpha=0.25) + for j in range(size): + if matrix[j, i] < 0.005: + ii = '' + elif matrix[j, i] > 0.995: + ii = '1.00' + else: + ii = ("{:.2f}".format(matrix[j, i])[1:]) + alf = matrix[j, i] / max_prob + ax.fill_between([i, i + 1], [size - j, size - j], [size - (j + 1), size - (j + 1)], color='k', alpha=alf) + ax.annotate(ii, xy=(i, j), xytext=(i + 0.5, size - (j + 0.5)), size=8, textcoords='data', va='center', + ha='center', color=('k' if alf < 0.5 else 'w')) + + if skip_lambda_index: + ks = [int(l) for l in skip_lambda_index] + ks = np.delete(np.arange(size + len(ks)), ks) + else: + ks = range(size) + for i in range(size): + ax.annotate(ks[i], xy=(i + 0.5, 1), xytext=(i + 0.5, size + 0.5), size=10, textcoords=('data', 'data'), + va='center', ha='center', color='k') + ax.annotate(ks[i], xy=(-0.5, size - (size - 0.5)), xytext=(-0.5, size - (i + 0.5)), size=10, textcoords=('data', 'data'), + va='center', ha='center', color='k') + ax.annotate('$\lambda$', xy=(-0.5, size - (size - 0.5)), xytext=(-0.5, size + 0.5), size=10, textcoords=('data', 'data'), + va='center', ha='center', color='k') + ax.plot([0, size], [0, 0], 'k-', lw=4.0, solid_capstyle='butt') + ax.plot([size, size], [0, size], 'k-', lw=4.0, solid_capstyle='butt') + ax.plot([0, 0], [0, size], 'k-', lw=2.0, solid_capstyle='butt') + ax.plot([0, size], [size, size], 'k-', lw=2.0, solid_capstyle='butt') + + cx = np.repeat(range(size + 1), 2) + cy = sorted(np.repeat(range(size + 1), 2), reverse=True) + ax.plot(cx[2:-1], cy[1:-2], 'k-', lw=2.0) + ax.plot(np.array(cx[2:-3]) + 1, cy[1:-4], 'k-', lw=2.0) + ax.plot(cx[1:-2], np.array(cy[:-3]) - 1, 'k-', lw=2.0) + ax.plot(cx[1:-4], np.array(cy[:-5]) - 2, 'k-', lw=2.0) + + ax.set_xlim(-1, size) + ax.set_ylim(0, size + 1) + return ax + + From b99bda90d8ab13b637ca736a9a4a1eb4b99f8097 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Mon, 24 Aug 2020 16:45:00 +0100 Subject: [PATCH 02/16] depedency --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0e3e3531..eb689366 100755 --- a/setup.py +++ b/setup.py @@ -29,5 +29,5 @@ license='BSD', long_description=open('README.rst').read(), tests_require = ['pytest', 'alchemtest'], - install_requires=['numpy', 'pandas>=0.23.0', 'pymbar>=3.0.5', 'scipy', 'scikit-learn'] + install_requires=['numpy', 'pandas>=0.23.0', 'pymbar>=3.0.5', 'scipy', 'scikit-learn', 'matplotlib'] ) From 6111a8ede979cef02b9e32aaf1605f4204a98efc Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Mon, 24 Aug 2020 16:53:12 +0100 Subject: [PATCH 03/16] py2 compatibility --- src/alchemlyb/visualisation/mbar_martix.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/alchemlyb/visualisation/mbar_martix.py b/src/alchemlyb/visualisation/mbar_martix.py index 6676c739..889902ed 100644 --- a/src/alchemlyb/visualisation/mbar_martix.py +++ b/src/alchemlyb/visualisation/mbar_martix.py @@ -1,6 +1,7 @@ """Functions for Plotting the overlay matrix for the Mbar estimator. """ +from __future__ import division import matplotlib.pyplot as plt import numpy as np def plot_mbar_omatrix(matrix, skip_lambda_index=[], ax=None): From bf80720420af898fbea4aa095633d104699c60c4 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Mon, 24 Aug 2020 16:59:52 +0100 Subject: [PATCH 04/16] backend error --- src/alchemlyb/visualisation/mbar_martix.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/alchemlyb/visualisation/mbar_martix.py b/src/alchemlyb/visualisation/mbar_martix.py index 889902ed..e854d74f 100644 --- a/src/alchemlyb/visualisation/mbar_martix.py +++ b/src/alchemlyb/visualisation/mbar_martix.py @@ -2,6 +2,8 @@ """ from __future__ import division +import matplotlib +matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np def plot_mbar_omatrix(matrix, skip_lambda_index=[], ax=None): From c5ac34a3cf1ab1474467cf2b3bae7e27cd8e0f5c Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Mon, 24 Aug 2020 17:06:26 +0100 Subject: [PATCH 05/16] bump coverage --- src/alchemlyb/tests/test_visualisation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/alchemlyb/tests/test_visualisation.py b/src/alchemlyb/tests/test_visualisation.py index ec3771af..59031681 100644 --- a/src/alchemlyb/tests/test_visualisation.py +++ b/src/alchemlyb/tests/test_visualisation.py @@ -15,3 +15,9 @@ def test_plot_mbar_omatrix(): plot_mbar_omatrix(mbar_coul.overlap_maxtrix) plot_mbar_omatrix(mbar_coul.overlap_maxtrix, [1,]) + # Bump up coverage + overlap_maxtrix = mbar_coul.overlap_maxtrix + overlap_maxtrix[0,0] = 0.0025 + overlap_maxtrix[-1, -1] = 0.9975 + plot_mbar_omatrix(overlap_maxtrix) + From 8e554095d4283de45db15f82a1945f73da954fb3 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Mon, 24 Aug 2020 18:13:58 +0100 Subject: [PATCH 06/16] citation --- docs/visualisation.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/visualisation.rst b/docs/visualisation.rst index c84cfcae..f2afc938 100644 --- a/docs/visualisation.rst +++ b/docs/visualisation.rst @@ -11,7 +11,7 @@ The accuracy of the :class:`~alchemlyb.estimators.MBAR` estimator depends on the overlap between different lambda states. The overlap matrix from the :class:`~alchemlyb.estimators.MBAR` estimator could be plotted to check the degree of overlap. It is recommended that there should be at least -**0.05** overlap between neighboring states. :: +**0.03** [Klimovich2015]_ overlap between neighboring states. :: >>> import pandas as pd >>> from alchemtest.gmx import load_benzene @@ -26,3 +26,7 @@ the degree of overlap. It is recommended that there should be at least >>> from alchemlyb.visualisation.mbar_martix import plot_mbar_omatrix >>> ax = plot_mbar_omatrix(mbar_coul.overlap_maxtrix) >>> ax.figure.savefig('O_MBAR.pdf', bbox_inches='tight', pad_inches=0.0) + +.. [Klimovich2015] Klimovich, P.V., Shirts, M.R. & Mobley, D.L. Guidelines for + the analysis of free energy calculations. J Comput Aided Mol Des 29, 397–411 + (2015). https://doi.org/10.1007/s10822-015-9840-9 From 5f03a3e44f4a0bfb9ced121543f300b5098fa1c8 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Tue, 25 Aug 2020 20:56:35 +0100 Subject: [PATCH 07/16] apply change --- .gitignore | 2 ++ .travis.yml | 4 ++++ docs/api_principles.rst | 2 +- docs/images/O_MBAR.png | Bin 0 -> 9960 bytes docs/index.rst | 1 + docs/visualisation.rst | 11 ++++++--- ...isualisation.plot_mbar_overlap_matrix.rst} | 12 ++++++---- src/alchemlyb/estimators/mbar_.py | 9 +++++-- src/alchemlyb/tests/test_visualisation.py | 22 +++++++++++------- src/alchemlyb/visualisation/__init__.py | 2 +- .../{mbar_martix.py => mbar_matrix.py} | 8 +++---- 11 files changed, 48 insertions(+), 25 deletions(-) create mode 100644 docs/images/O_MBAR.png rename docs/visualisation/{alchemlyb.visualisation.plot_mbar_omatrix.rst => alchemlyb.visualisation.plot_mbar_overlap_matrix.rst} (52%) rename src/alchemlyb/visualisation/{mbar_martix.py => mbar_matrix.py} (95%) diff --git a/.gitignore b/.gitignore index 2a45ed72..f71e81e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.pyc .vscode +*.DS_Store +build diff --git a/.travis.yml b/.travis.yml index 3d9c07ef..d4f03437 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: python sudo: required dist: xenial +env: + global: + - MPLBACKEND=agg + python: - "2.7" - "3.5" diff --git a/docs/api_principles.rst b/docs/api_principles.rst index e644fb37..e0c6d73c 100644 --- a/docs/api_principles.rst +++ b/docs/api_principles.rst @@ -1,5 +1,5 @@ API principles -============ +============== The following is an overview over the guiding principles and ideas that underpin the API of alchemlyb. diff --git a/docs/images/O_MBAR.png b/docs/images/O_MBAR.png new file mode 100644 index 0000000000000000000000000000000000000000..65effe53df2696df1c618d0fcda6e4877756c61f GIT binary patch literal 9960 zcma)ib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OxMRP*70wPB*M-6q*O*=hq(@A0d>FVb}SK zc~IM4HH=k7btCo()0I=rE50LCcs*+K$15&$|l zVw(uv6xbRF)?d&t5drlr5i!u`pm9rAFJOMz?uBrSon`0ZYBl5*rDeWyi9Pu4&1>3X b7X>> mbar_coul = MBAR() >>> mbar_coul.fit(u_nk_coul) - >>> from alchemlyb.visualisation.mbar_martix import plot_mbar_omatrix - >>> ax = plot_mbar_omatrix(mbar_coul.overlap_maxtrix) + >>> from alchemlyb.visualisation import plot_mbar_overlap_matrix + >>> ax = plot_mbar_overlap_matrix(mbar_coul.overlap_matrix) >>> ax.figure.savefig('O_MBAR.pdf', bbox_inches='tight', pad_inches=0.0) + +Will give a plot looks like this .. image:: images/O_MBAR.png + .. [Klimovich2015] Klimovich, P.V., Shirts, M.R. & Mobley, D.L. Guidelines for the analysis of free energy calculations. J Comput Aided Mol Des 29, 397–411 (2015). https://doi.org/10.1007/s10822-015-9840-9 diff --git a/docs/visualisation/alchemlyb.visualisation.plot_mbar_omatrix.rst b/docs/visualisation/alchemlyb.visualisation.plot_mbar_overlap_matrix.rst similarity index 52% rename from docs/visualisation/alchemlyb.visualisation.plot_mbar_omatrix.rst rename to docs/visualisation/alchemlyb.visualisation.plot_mbar_overlap_matrix.rst index ccdaa6af..5323d1a9 100644 --- a/docs/visualisation/alchemlyb.visualisation.plot_mbar_omatrix.rst +++ b/docs/visualisation/alchemlyb.visualisation.plot_mbar_overlap_matrix.rst @@ -1,9 +1,11 @@ -Plot Overlap Matrix from MBar +.. _plot_overlap: + +Plot Overlap Matrix from MBAR ============================= -The function :func:`~alchemlyb.visualisation.plot_mbar_omatrix` allows the user -to plot the overlap matrix from -:attr:`~alchemlyb.estimators.MBAR.overlap_maxtrix`. The user can pass +The function :func:`~alchemlyb.visualisation.plot_mbar_overlap_matrix` allows +the user to plot the overlap matrix from +:attr:`~alchemlyb.estimators.MBAR.overlap_matrix`. The user can pass :class:`matplotlib.axes.Axes` into the function to have the overlap maxtrix drawn on a specific axes. The user could also specify a list of lambda states to be skipped when labelling the states. @@ -13,4 +15,4 @@ usage. API Reference ------------- -.. autofunction:: alchemlyb.visualisation.plot_mbar_omatrix \ No newline at end of file +.. autofunction:: alchemlyb.visualisation.plot_mbar_overlap_matrix \ No newline at end of file diff --git a/src/alchemlyb/estimators/mbar_.py b/src/alchemlyb/estimators/mbar_.py index 171429f6..9a2fb519 100644 --- a/src/alchemlyb/estimators/mbar_.py +++ b/src/alchemlyb/estimators/mbar_.py @@ -45,7 +45,7 @@ class MBAR(BaseEstimator): states_ : list Lambda states for which free energy differences were obtained. - overlap_maxtrix: DataFrame + overlap_matrix: DataFrame The overlap matrix. """ @@ -88,7 +88,6 @@ def fit(self, u_nk): verbose=self.verbose) self.states_ = u_nk.columns.values.tolist() - self.overlap_maxtrix = self._mbar.computeOverlap()['matrix'] # set attributes out = self._mbar.getFreeEnergyDifferences(return_theta=True) @@ -102,3 +101,9 @@ def fit(self, u_nk): def predict(self, u_ln): pass + + def _get_overlap_matrix(self): + return self._mbar.computeOverlap()['matrix'] + + overlap_matrix = property(_get_overlap_matrix) + diff --git a/src/alchemlyb/tests/test_visualisation.py b/src/alchemlyb/tests/test_visualisation.py index 59031681..5de33ab5 100644 --- a/src/alchemlyb/tests/test_visualisation.py +++ b/src/alchemlyb/tests/test_visualisation.py @@ -1,23 +1,27 @@ +import matplotlib +import pandas as pd + +from alchemtest.gmx import load_benzene +from alchemlyb.parsing.gmx import extract_u_nk +from alchemlyb.estimators import MBAR +from alchemlyb.visualisation.mbar_matrix import plot_mbar_overlap_matrix def test_plot_mbar_omatrix(): '''Just test if the plot runs''' - import pandas as pd - from alchemtest.gmx import load_benzene - from alchemlyb.parsing.gmx import extract_u_nk - from alchemlyb.estimators import MBAR - bz = load_benzene().data u_nk_coul = pd.concat([extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]) mbar_coul = MBAR() mbar_coul.fit(u_nk_coul) - from alchemlyb.visualisation.mbar_martix import plot_mbar_omatrix - plot_mbar_omatrix(mbar_coul.overlap_maxtrix) - plot_mbar_omatrix(mbar_coul.overlap_maxtrix, [1,]) + isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_maxtrix), + matplotlib.axes.Axes) + isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_maxtrix, [1,]), + matplotlib.axes.Axes) # Bump up coverage overlap_maxtrix = mbar_coul.overlap_maxtrix overlap_maxtrix[0,0] = 0.0025 overlap_maxtrix[-1, -1] = 0.9975 - plot_mbar_omatrix(overlap_maxtrix) + isinstance(overlap_maxtrix, + matplotlib.axes.Axes) diff --git a/src/alchemlyb/visualisation/__init__.py b/src/alchemlyb/visualisation/__init__.py index f8cc4c2a..4fc73051 100644 --- a/src/alchemlyb/visualisation/__init__.py +++ b/src/alchemlyb/visualisation/__init__.py @@ -1 +1 @@ -from .mbar_martix import plot_mbar_omatrix \ No newline at end of file +from .mbar_matrix import plot_mbar_overlap_matrix \ No newline at end of file diff --git a/src/alchemlyb/visualisation/mbar_martix.py b/src/alchemlyb/visualisation/mbar_matrix.py similarity index 95% rename from src/alchemlyb/visualisation/mbar_martix.py rename to src/alchemlyb/visualisation/mbar_matrix.py index e854d74f..14fb3210 100644 --- a/src/alchemlyb/visualisation/mbar_martix.py +++ b/src/alchemlyb/visualisation/mbar_matrix.py @@ -2,18 +2,18 @@ """ from __future__ import division -import matplotlib -matplotlib.use('Agg') + import matplotlib.pyplot as plt import numpy as np -def plot_mbar_omatrix(matrix, skip_lambda_index=[], ax=None): + +def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None): '''Plot the MBar overlap matrix. Parameters ---------- matrix : DataFrame DataFrame of the overlap matrix obtained from - :attr:`~alchemlyb.estimators.MABR.overlap_maxtrix` + :attr:`~alchemlyb.estimators.MBAR.overlap_matrix` skip_lambda_index : List list of lambda indices to be omitted from plotting process. Default: []. From c327215f9371846be7df23aa5f367350d5971079 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Tue, 25 Aug 2020 21:03:17 +0100 Subject: [PATCH 08/16] fix test --- src/alchemlyb/tests/test_visualisation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/alchemlyb/tests/test_visualisation.py b/src/alchemlyb/tests/test_visualisation.py index 5de33ab5..562609ed 100644 --- a/src/alchemlyb/tests/test_visualisation.py +++ b/src/alchemlyb/tests/test_visualisation.py @@ -13,13 +13,13 @@ def test_plot_mbar_omatrix(): mbar_coul = MBAR() mbar_coul.fit(u_nk_coul) - isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_maxtrix), + isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_matrix), matplotlib.axes.Axes) - isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_maxtrix, [1,]), + isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_matrix, [1,]), matplotlib.axes.Axes) # Bump up coverage - overlap_maxtrix = mbar_coul.overlap_maxtrix + overlap_maxtrix = mbar_coul.overlap_matrix overlap_maxtrix[0,0] = 0.0025 overlap_maxtrix[-1, -1] = 0.9975 isinstance(overlap_maxtrix, From 095868e111404fe11241d5c358660dc7e135f164 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Tue, 25 Aug 2020 21:45:59 +0100 Subject: [PATCH 09/16] fix test --- src/alchemlyb/tests/test_visualisation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/alchemlyb/tests/test_visualisation.py b/src/alchemlyb/tests/test_visualisation.py index 562609ed..ff60b6f4 100644 --- a/src/alchemlyb/tests/test_visualisation.py +++ b/src/alchemlyb/tests/test_visualisation.py @@ -22,6 +22,6 @@ def test_plot_mbar_omatrix(): overlap_maxtrix = mbar_coul.overlap_matrix overlap_maxtrix[0,0] = 0.0025 overlap_maxtrix[-1, -1] = 0.9975 - isinstance(overlap_maxtrix, + isinstance(plot_mbar_overlap_matrix(overlap_maxtrix), matplotlib.axes.Axes) From 0b998b910265335ff4ff592924d5bd02a4f5e598 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Tue, 25 Aug 2020 22:01:09 +0100 Subject: [PATCH 10/16] fix test --- src/alchemlyb/tests/test_visualisation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/alchemlyb/tests/test_visualisation.py b/src/alchemlyb/tests/test_visualisation.py index ff60b6f4..d482caad 100644 --- a/src/alchemlyb/tests/test_visualisation.py +++ b/src/alchemlyb/tests/test_visualisation.py @@ -13,15 +13,15 @@ def test_plot_mbar_omatrix(): mbar_coul = MBAR() mbar_coul.fit(u_nk_coul) - isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_matrix), + assert isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_matrix), matplotlib.axes.Axes) - isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_matrix, [1,]), + assert isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_matrix, [1,]), matplotlib.axes.Axes) # Bump up coverage overlap_maxtrix = mbar_coul.overlap_matrix overlap_maxtrix[0,0] = 0.0025 overlap_maxtrix[-1, -1] = 0.9975 - isinstance(plot_mbar_overlap_matrix(overlap_maxtrix), + assert isinstance(plot_mbar_overlap_matrix(overlap_maxtrix), matplotlib.axes.Axes) From a98027f8625e53b33621c9f37ee70688797c1607 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Wed, 26 Aug 2020 10:31:21 +0100 Subject: [PATCH 11/16] fix visulisatiuon --- AUTHORS | 4 +++- docs/conf.py | 6 ++++-- docs/visualisation.rst | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index 672262b7..c48f9fa2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -33,4 +33,6 @@ Chronological list of authors 2019 - Victoria Lim (@vlim) - Hyungro Lee (@lee212) - - Mohammad S. Barhaghi (@msoroush) \ No newline at end of file + - Mohammad S. Barhaghi (@msoroush) +2020 + - Zhiyi Wu (@xiki-tempula) \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 517695f4..28d24289 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,8 +50,10 @@ # General information about the project. project = u'alchemlyb' -author = u'David Dotson and contributors' -copyright = u'2017-2019, ' + author +author = u'''David Dotson, Ian Kenney, Oliver Beckstein, Shuai Liu, +Travis Jensen, Bryce Allen, Dominik Wille, Victoria Lim, Hyungro Lee, +Mohammad S. Barhaghi, Zhiyi Wu''' +copyright = u'2017-2020, ' + author # The version info for the project you're documenting, acts as replacement for diff --git a/docs/visualisation.rst b/docs/visualisation.rst index 2a848f14..e7a03336 100644 --- a/docs/visualisation.rst +++ b/docs/visualisation.rst @@ -30,7 +30,9 @@ the degree of overlap. It is recommended that there should be at least >>> ax.figure.savefig('O_MBAR.pdf', bbox_inches='tight', pad_inches=0.0) -Will give a plot looks like this .. image:: images/O_MBAR.png +Will give a plot looks like this + +.. image:: images/O_MBAR.png .. [Klimovich2015] Klimovich, P.V., Shirts, M.R. & Mobley, D.L. Guidelines for the analysis of free energy calculations. J Comput Aided Mol Des 29, 397–411 From 5613966b92b8cff8e02ba12c289e503ffae4797d Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Wed, 26 Aug 2020 10:33:16 +0100 Subject: [PATCH 12/16] Update CHANGES --- CHANGES | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 98638667..fcc8e133 100644 --- a/CHANGES +++ b/CHANGES @@ -15,11 +15,12 @@ The rules for this file: ------------------------------------------------------------------------------ -??/??/2020 wehs7661, dotsdl +??/??/2020 wehs7661, dotsdl, xiki-tempula * 0.?.? Enhancements + - Allow the overlap matrix of the MBAR estimated to be plotted. (PR #107) Deprecations From 505e0d66843c6c339da3710a6ecbc904c95a0450 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Wed, 26 Aug 2020 10:34:03 +0100 Subject: [PATCH 13/16] Update CHANGES --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index fcc8e133..b95aa851 100644 --- a/CHANGES +++ b/CHANGES @@ -20,7 +20,7 @@ The rules for this file: * 0.?.? Enhancements - - Allow the overlap matrix of the MBAR estimated to be plotted. (PR #107) + - Allow the overlap matrix of the MBAR estimator to be plotted. (PR #107) Deprecations From 453242cb6d688fed9e1b8a1eed25cfb29341a638 Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Wed, 26 Aug 2020 19:38:04 +0100 Subject: [PATCH 14/16] Update src/alchemlyb/estimators/mbar_.py Co-authored-by: Oliver Beckstein --- src/alchemlyb/estimators/mbar_.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/alchemlyb/estimators/mbar_.py b/src/alchemlyb/estimators/mbar_.py index 9a2fb519..6aa1821b 100644 --- a/src/alchemlyb/estimators/mbar_.py +++ b/src/alchemlyb/estimators/mbar_.py @@ -102,8 +102,18 @@ def fit(self, u_nk): def predict(self, u_ln): pass - def _get_overlap_matrix(self): + @property + def overlap_matrix(self): + r"""MBAR overlap matrix. + + The estimated state overlap matrix :math:`O_{ij}` is an estimate of the probability + of observing a sample from state :math:`i` in state :math:`j`. + + The :attr:`overlap_matrix` is computed on-the-fly. Assign it to a variable if + you plan to re-use it. + + See Also + --------- + pymbar.mbar.MBAR.computeOverlap + """ return self._mbar.computeOverlap()['matrix'] - - overlap_matrix = property(_get_overlap_matrix) - From 4492fabe8336f4f26f0e9ceb56c3fa4c15b44fdf Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Wed, 26 Aug 2020 19:47:10 +0100 Subject: [PATCH 15/16] update docs --- src/alchemlyb/visualisation/mbar_matrix.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/alchemlyb/visualisation/mbar_matrix.py b/src/alchemlyb/visualisation/mbar_matrix.py index 14fb3210..b5ee8c5d 100644 --- a/src/alchemlyb/visualisation/mbar_matrix.py +++ b/src/alchemlyb/visualisation/mbar_matrix.py @@ -1,4 +1,12 @@ -"""Functions for Plotting the overlay matrix for the Mbar estimator. +"""Functions for Plotting the overlay matrix for the MBAR estimator. + +To assess the quality of the MBAR estimator, the overlap matrix between +the lambda states can be computed and the more overlap is observed between +the states, the more reliable the estimate is. One way of accessing the +quality of the overlap matrix is by plotting it. + +The code for producing the overlap matrix plot is taken from +: `Alchemical Analysis `_. """ from __future__ import division @@ -7,7 +15,7 @@ import numpy as np def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None): - '''Plot the MBar overlap matrix. + '''Plot the MBAR overlap matrix. Parameters ---------- @@ -25,6 +33,12 @@ def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None): ------- matplotlib.axes.Axes An axes with the overlap matrix drawn. + + Notes + ----- + The code is taken and modified from + : `Alchemical Analysis `_ + ''' # Compute the size of the figure, if ax is not given. max_prob = matrix.max() From 8cfd5204468de8cbe7ae698accaff1521dcf683e Mon Sep 17 00:00:00 2001 From: Zhiyi Wu Date: Wed, 26 Aug 2020 20:26:54 +0100 Subject: [PATCH 16/16] Change data type. --- src/alchemlyb/estimators/mbar_.py | 2 +- src/alchemlyb/visualisation/mbar_matrix.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/alchemlyb/estimators/mbar_.py b/src/alchemlyb/estimators/mbar_.py index 6aa1821b..dd8127ae 100644 --- a/src/alchemlyb/estimators/mbar_.py +++ b/src/alchemlyb/estimators/mbar_.py @@ -45,7 +45,7 @@ class MBAR(BaseEstimator): states_ : list Lambda states for which free energy differences were obtained. - overlap_matrix: DataFrame + overlap_matrix: numpy.matrix The overlap matrix. """ diff --git a/src/alchemlyb/visualisation/mbar_matrix.py b/src/alchemlyb/visualisation/mbar_matrix.py index b5ee8c5d..682b8555 100644 --- a/src/alchemlyb/visualisation/mbar_matrix.py +++ b/src/alchemlyb/visualisation/mbar_matrix.py @@ -19,7 +19,7 @@ def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None): Parameters ---------- - matrix : DataFrame + matrix : numpy.matrix DataFrame of the overlap matrix obtained from :attr:`~alchemlyb.estimators.MBAR.overlap_matrix` skip_lambda_index : List @@ -38,7 +38,7 @@ def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None): ----- The code is taken and modified from : `Alchemical Analysis `_ - + ''' # Compute the size of the figure, if ax is not given. max_prob = matrix.max()