Skip to content
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

Merged
merged 16 commits into from
Aug 26, 2020
Merged

mbar overlap matrix plot #107

merged 16 commits into from
Aug 26, 2020

Conversation

xiki-tempula
Copy link
Collaborator

@xiki-tempula xiki-tempula commented Aug 24, 2020

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

@codecov
Copy link

codecov bot commented Aug 24, 2020

Codecov Report

Merging #107 into master will increase coverage by 0.04%.
The diff coverage is 97.91%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/alchemlyb/visualisation/mbar_matrix.py 97.77% <97.77%> (ø)
src/alchemlyb/estimators/mbar_.py 96.15% <100.00%> (+0.32%) ⬆️
src/alchemlyb/visualisation/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fcdf7a...8cfd520. Read the comment docs.

Copy link
Member

@orbeckst orbeckst left a 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')
Copy link
Member

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

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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?

Copy link
Member

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):
Copy link
Member

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)
Copy link
Member

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,])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert isinstance axes

src/alchemlyb/tests/test_visualisation.py Show resolved Hide resolved

def test_plot_mbar_omatrix():
'''Just test if the plot runs'''
import pandas as pd
Copy link
Member

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

@@ -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']
Copy link
Member

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.

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MBAR

docs/visualisation.rst Show resolved Hide resolved
@orbeckst
Copy link
Member

orbeckst commented Aug 25, 2020 via email

@orbeckst
Copy link
Member

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.

@xiki-tempula
Copy link
Collaborator Author

xiki-tempula commented Aug 26, 2020

@orbeckst I have changed the author list and embedded the figure.

Copy link
Member

@orbeckst orbeckst left a 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.
Copy link
Member

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)

Copy link
Member

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.

src/alchemlyb/visualisation/mbar_matrix.py Show resolved Hide resolved
import numpy as np

def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None):
'''Plot the MBar overlap matrix.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MBAR

src/alchemlyb/estimators/mbar_.py Outdated Show resolved Hide resolved
@xiki-tempula
Copy link
Collaborator Author

@orbeckst Thank you for the suggestions. I have built the docs locally and it looks fine.

Copy link
Member

@orbeckst orbeckst left a 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
Copy link
Member

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?

@@ -45,6 +45,9 @@ class MBAR(BaseEstimator):
states_ : list
Lambda states for which free energy differences were obtained.

overlap_matrix: DataFrame
Copy link
Member

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

@xiki-tempula
Copy link
Collaborator Author

@orbeckst Sorry for the omission. Data type corrected.

@orbeckst orbeckst self-assigned this Aug 26, 2020
@orbeckst orbeckst merged commit 7be2e41 into alchemistry:master Aug 26, 2020
@orbeckst
Copy link
Member

Thank you very much @xiki-tempula , great addition!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants