-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mbar overlap matrix plot #107
Conversation
Codecov Report
@@ Coverage Diff @@
## master #107 +/- ##
==========================================
+ Coverage 97.26% 97.30% +0.04%
==========================================
Files 12 14 +2
Lines 695 743 +48
Branches 141 150 +9
==========================================
+ Hits 676 723 +47
Misses 5 5
- Partials 14 15 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution. I have some comments inline. Could you please also fix the spelling of "matrix" throughout?
Finally, could you include an image of the plot in the docs and attach the equivalent image from alchemical-analysis.py
for the same data so that we can see in how far it reproduces the old code? Thanks!
""" | ||
from __future__ import division | ||
import matplotlib | ||
matplotlib.use('Agg') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove, this is up to the user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orbeckst Thank you for the review. I got a problem with CI for py2, where if I don't add this line in. I would get
src/alchemlyb/tests/test_visualisation.py:15:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/alchemlyb/visualisation/mbar_martix.py:31: in plot_mbar_omatrix
fig, ax = plt.subplots(figsize=(size / 2, size / 2))
../../../virtualenv/python2.7.15/lib/python2.7/site-packages/matplotlib/pyplot.py:1184: in subplots
fig = figure(**fig_kw)
../../../virtualenv/python2.7.15/lib/python2.7/site-packages/matplotlib/pyplot.py:533: in figure
**kwargs)
../../../virtualenv/python2.7.15/lib/python2.7/site-packages/matplotlib/backend_bases.py:161: in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
../../../virtualenv/python2.7.15/lib/python2.7/site-packages/matplotlib/backends/_backend_tk.py:1046: in new_figure_manager_given_figure
window = Tk.Tk(className="matplotlib")
As is seen https://travis-ci.org/github/alchemistry/alchemlyb/jobs/720700286, Google suggests that this is one way of solving the problem. I'm not familiar with CI so I'm not sure of what is the best way to process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orbeckst I'm sorry for the confusion. I originally put the line matplotlib.use('Agg')
in order to avoid the travis failing for py2. I wonder what is your suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to be brief: see https://github.com/MDAnalysis/mdanalysis/pull/2798/files#diff-354f30a63fb0907d4ad57269548329e3R39 : add the env var MPLBACKEND: "agg"
to the CI.
matplotlib.use('Agg') | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
def plot_mbar_omatrix(matrix, skip_lambda_index=[], ax=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write out omatrix => overlap_matrix: just be explicit
overlap_maxtrix = mbar_coul.overlap_maxtrix | ||
overlap_maxtrix[0,0] = 0.0025 | ||
overlap_maxtrix[-1, -1] = 0.9975 | ||
plot_mbar_omatrix(overlap_maxtrix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert that you return an axes object
|
||
from alchemlyb.visualisation.mbar_martix import plot_mbar_omatrix | ||
plot_mbar_omatrix(mbar_coul.overlap_maxtrix) | ||
plot_mbar_omatrix(mbar_coul.overlap_maxtrix, [1,]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert isinstance axes
|
||
def test_plot_mbar_omatrix(): | ||
'''Just test if the plot runs''' | ||
import pandas as pd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imports at top of test file
src/alchemlyb/estimators/mbar_.py
Outdated
@@ -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'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it a managed attribute so that it is not computed by default or make it a method compute_overlap_matrix()
-- not sure if @dotsdl has a preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxtrix => matrix
@@ -0,0 +1,16 @@ | |||
Plot Overlap Matrix from MBar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MBAR
In MDAnalysis we solved this by setting the backend environment variable to agg; it’s either already in develop and/or in the 1.0.1 backport branch,IIRC.
… Am 25.08.2020 um 04:57 schrieb Zhiyi Wu ***@***.***>:
@xiki-tempula commented on this pull request.
In src/alchemlyb/visualisation/mbar_martix.py:
> @@ -0,0 +1,81 @@
+"""Functions for Plotting the overlay matrix for the Mbar estimator.
+
+"""
+from __future__ import division
+import matplotlib
+matplotlib.use('Agg')
@orbeckst Thank you for the review. I got a problem with CI for py2, where if I don't add this line in. I would get
src/alchemlyb/tests/test_visualisation.py:15:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/alchemlyb/visualisation/mbar_martix.py:31: in plot_mbar_omatrix
fig, ax = plt.subplots(figsize=(size / 2, size / 2))
../../../virtualenv/python2.7.15/lib/python2.7/site-packages/matplotlib/pyplot.py:1184: in subplots
fig = figure(**fig_kw)
../../../virtualenv/python2.7.15/lib/python2.7/site-packages/matplotlib/pyplot.py:533: in figure
**kwargs)
../../../virtualenv/python2.7.15/lib/python2.7/site-packages/matplotlib/backend_bases.py:161: in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
../../../virtualenv/python2.7.15/lib/python2.7/site-packages/matplotlib/backends/_backend_tk.py:1046: in new_figure_manager_given_figure
window = Tk.Tk(className="matplotlib")
As is seen https://travis-ci.org/github/alchemistry/alchemlyb/jobs/720700286, Google suggests that this is one way of solving the problem. I'm not familiar with CI so I'm not sure of what is the best way to process.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Don't forget to add yourself to AUTHORS and entry to CHANGES. I think there's also an authors list in the docs conf.py so add yourself also. |
@orbeckst I have changed the author list and embedded the figure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking very good. Please see inline comments, especially about attributing code to alchemical-analysis if necessary (alchemical-analysis is MIT so that's all good)
Did you build the docs locally and do they look ok?
@@ -0,0 +1,81 @@ | |||
"""Functions for Plotting the overlay matrix for the Mbar estimator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it a title and write one short paragraph.
Use MBAR consistently (not Mbar)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also say that this code is based on alchemical-analysis.
import numpy as np | ||
|
||
def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None): | ||
'''Plot the MBar overlap matrix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MBAR
Co-authored-by: Oliver Beckstein <[email protected]>
@orbeckst Thank you for the suggestions. I have built the docs locally and it looks fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments, please see inline, almost there!!
|
||
Parameters | ||
---------- | ||
matrix : DataFrame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this a numpy array?
src/alchemlyb/estimators/mbar_.py
Outdated
@@ -45,6 +45,9 @@ class MBAR(BaseEstimator): | |||
states_ : list | |||
Lambda states for which free energy differences were obtained. | |||
|
|||
overlap_matrix: DataFrame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really a DataFrame... I thought that pymbar returns numpy arrays. please check and correct if necessary
@orbeckst Sorry for the omission. Data type corrected. |
Thank you very much @xiki-tempula , great addition! |
I have ported the MBAR overlap matrix to this library and have written some documentation.
I don't know how to write tests for the plot so I have just written a script where the plot runs.
Related to #73