Skip to content

Commit

Permalink
fixed/updated visualization annotations
Browse files Browse the repository at this point in the history
- fix #133
- added missing versionadded to visualization
- regenerated figures for docs with corrected units
- minor doc fixes
  • Loading branch information
orbeckst committed Jun 2, 2021
1 parent 4f95c28 commit 5802ea4
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 31 deletions.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
??/??/2021 xiki-tempula
06/01/2021 xiki-tempula, orbeckst

* 0.4.1

Enhancements

Deprecations
- Last release that supports Python 3.5 and 2.7.

Fixes
- The plotting function assumes that the default unit is kcal/mol where it is
kT (issue #124, PR #123).
- invalid escape sequence in plotting annotations (issue #133)

Changes

Expand Down
Binary file modified docs/images/dF_states.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/dF_t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/dhdl_TI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions src/alchemlyb/visualisation/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def plot_convergence(forward, forward_error, backward, backward_error,
backward_error : List
A list of error from the last X% of data.
units : str
The label for the unit of the estimate. Default: `kT`
The label for the unit of the estimate. Default: "kT"
ax : matplotlib.axes.Axes
Matplotlib axes object where the plot will be drawn on. If ax=None,
Matplotlib axes object where the plot will be drawn on. If ``ax=None``,
a new axes will be generated.
Returns
Expand All @@ -30,11 +30,13 @@ def plot_convergence(forward, forward_error, backward, backward_error,
Note
----
The code is taken and modified from
: `Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
The units variable is for labelling only. Changing it doesn't change the
unit of the underlying variable, which is in the unit of kT. The
scaling_factor is used to change the number to the desired unit.
unit of the underlying variable, which is in the unit of :math:`kT`.
.. versionadded:: 0.4.0
"""
if ax is None: # pragma: no cover
fig, ax = plt.subplots(figsize=(8, 6))
Expand Down Expand Up @@ -64,7 +66,7 @@ def plot_convergence(forward, forward_error, backward, backward_error,
plt.xticks(r_ts[::2], fontsize=10)
plt.yticks(fontsize=10)

ax.legend((line1[0], line2[0]), (r'$Forward$', r'$Reverse$'), loc=9,
ax.legend((line1[0], line2[0]), ('Forward', 'Reverse'), loc=9,
prop=FP(size=18), frameon=False)
ax.set_xlabel(r'Fraction of the simulation time', fontsize=16,
color='#151B54')
Expand Down
17 changes: 10 additions & 7 deletions src/alchemlyb/visualisation/dF_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
lambda states can be ploted to assess the quality of the estimation.
The code for producing the dF states plot is modified based on
: `Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
"""

Expand All @@ -30,7 +30,7 @@ def plot_dF_state(estimators, labels=None, colors=None, units='kT',
colors : List
list of colors for plotting different estimators.
units : str
The unit of the estimate. Default: `kT`
The unit of the estimate. Default: "kT"
orientation : string
The orientation of the figure. Can be `portrait` or `landscape`
nb : int
Expand All @@ -44,11 +44,13 @@ def plot_dF_state(estimators, labels=None, colors=None, units='kT',
Note
----
The code is taken and modified from
: `Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
The units variable is for labelling only. Changing it doesn't change the
unit of the underlying variable, which is in the unit of kT.
unit of the underlying variable, which is in the unit of :math:`kT`.
.. versionadded:: 0.4.0
'''
try:
len(estimators)
Expand Down Expand Up @@ -176,7 +178,7 @@ def plot_dF_state(estimators, labels=None, colors=None, units='kT',
plt.yticks(fontsize=10)
ax.xaxis.set_ticks([])
for i in x + 0.5 * width * len(estimators):
ax.annotate('$\mathrm{%d-%d}$' % (i, i + 1), xy=(i, 0),
ax.annotate(r'$\mathrm{%d-%d}$' % (i, i + 1), xy=(i, 0),
xycoords=('data', 'axes fraction'), xytext=(0, -2),
size=10, textcoords='offset points', va='top',
ha='center')
Expand All @@ -193,11 +195,12 @@ def plot_dF_state(estimators, labels=None, colors=None, units='kT',
fancybox=True)
plt.title('The free energy change breakdown', fontsize=12)
plt.xlabel('States', fontsize=12, color='#151B54')
plt.ylabel('$\Delta G$ ' + units, fontsize=12, color='#151B54')
plt.ylabel(r'$\Delta G$ ({})'.format(units), fontsize=12, color='#151B54')
elif orientation == 'portrait':
leg = ax.legend(lines, labels, loc=0, ncol=2,
prop=FP(size=8),
title='$\mathrm{\Delta G\/%s\/}\mathit{vs.}\/\mathrm{lambda\/pair}$' % units,
title=r'$\Delta G$ ({})'.format(units) +
r'$\mathit{vs.}$ lambda pair',
fancybox=True)

leg.get_frame().set_alpha(0.5)
Expand Down
29 changes: 20 additions & 9 deletions src/alchemlyb/visualisation/mbar_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
quality of the overlap matrix is by plotting it.
The code for producing the overlap matrix plot is taken from
: `Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
"""
from __future__ import division
Expand All @@ -24,9 +24,9 @@ def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None):
:attr:`~alchemlyb.estimators.MBAR.overlap_matrix`
skip_lambda_index : List
list of lambda indices to be omitted from plotting process.
Default: [].
Default: ``[]``.
ax : matplotlib.axes.Axes
Matplotlib axes object where the plot will be drawn on. If ax=None,
Matplotlib axes object where the plot will be drawn on. If ``ax=None``,
a new axes will be generated.
Returns
Expand All @@ -37,7 +37,10 @@ def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None):
Note
----
The code is taken and modified from
: `Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
.. versionadded:: 0.4.0
'''
# Compute the size of the figure, if ax is not given.
Expand All @@ -60,8 +63,11 @@ def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None):
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',
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:
Expand All @@ -70,11 +76,16 @@ def plot_mbar_overlap_matrix(matrix, skip_lambda_index=[], ax=None):
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'),
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'),
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'),
ax.annotate(r'$\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')
Expand Down
19 changes: 11 additions & 8 deletions src/alchemlyb/visualisation/ti_dhdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
thoroughly.
The code for producing the dhdl plot is modified based on
: `Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
"""
from __future__ import division
Expand All @@ -29,9 +29,9 @@ def plot_ti_dhdl(dhdl_data, labels=None, colors=None, units='kT',
list of colors for plotting all the alchemical transformations.
Default: ['r', 'g', '#7F38EC', '#9F000F', 'b', 'y']
units : str
The label for the unit of the estimate. Default: `kT`
The label for the unit of the estimate. Default: "kT"
ax : matplotlib.axes.Axes
Matplotlib axes object where the plot will be drawn on. If ax=None,
Matplotlib axes object where the plot will be drawn on. If ``ax=None``,
a new axes will be generated.
Returns
Expand All @@ -42,11 +42,13 @@ def plot_ti_dhdl(dhdl_data, labels=None, colors=None, units='kT',
Note
----
The code is taken and modified from
: `Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.
The units variable is for labelling only. Changing it doesn't change the
unit of the underlying variable, which is in the unit of kT.
unit of the underlying variable, which is in the unit of :math:`kT`.
.. versionadded:: 0.4.0
'''
# Make it into a list
# separate_dhdl method is used so that the input for the actual plotting
Expand Down Expand Up @@ -94,7 +96,7 @@ def plot_ti_dhdl(dhdl_data, labels=None, colors=None, units='kT',
raise ValueError(
'Number of colors ({}) should be larger than the number of data ({})'.format(
len(labels), len(dhdl_list)))

# Get the real data out
xs, ndx, dx = [0], 0, 0.001
min_y, max_y = 0, 0
Expand Down Expand Up @@ -171,9 +173,10 @@ def getInd(r=ri, z=[0]):
ax.yaxis.set_minor_locator(AML())
ax.grid(which='both', color='w', lw=0.25, axis='y', zorder=12)
ax.set_ylabel(
r'$\mathrm{\langle{\frac{ \partial U } { \partial \lambda }}\rangle_{\lambda}\/%s}$' % units,
r'$\langle{\frac{\partial U}{\partial\lambda}}\rangle_{\lambda}$' +
'({})'.format(units),
fontsize=20, color='#151B54')
ax.annotate('$\mathit{\lambda}$', xy=(0, 0), xytext=(0.5, -0.05), size=18,
ax.annotate(r'$\mathit{\lambda}$', xy=(0, 0), xytext=(0.5, -0.05), size=18,
textcoords='axes fraction', va='top', ha='center',
color='#151B54')
lege = ax.legend(prop=FP(size=14), frameon=False, loc=1)
Expand Down

0 comments on commit 5802ea4

Please sign in to comment.