Skip to content

Commit

Permalink
Merge branch 'master' into moving_average
Browse files Browse the repository at this point in the history
  • Loading branch information
orbeckst authored Aug 26, 2024
2 parents 509b95a + 8d3dabc commit 10ee4bc
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macOS-latest", "windows-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12"]
# Only test lowest and highest version on the expensive/slow
# macOS and windows runners (UPDATE when supported versions change):
exclude:
Expand Down
4 changes: 4 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The alchemlyb project is led by Oliver Beckstein (@orbeckst), David
Mobley (@davidlmobley), and Michal Shirts (@mrshirts). alchemlyb was
originally created by David Dotson (@dotsdl).

The project is being maintained by Zhiyi Wu (@xiki-tempula) and Oliver
Beckstein (@orbeckst).

All contributing authors are listed in this file below. Full name and
GitHub handle are preferred. The repository history at
https://github.com/alchemistry/alchemlyb and the CHANGES file show
Expand Down Expand Up @@ -47,5 +50,6 @@ Chronological list of authors
- Irfan Alibay (@IAlibay)
- Pascal Merz (@ptmerz)
- Domenico Marson (@DrDomenicoMarson)

2023
- Haoxi Li (@hl2500)
33 changes: 25 additions & 8 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,39 @@ The rules for this file:
* release numbers follow "Semantic Versioning" https://semver.org

------------------------------------------------------------------------------
??/??/2024 jaclark5

08/07/2024 orbeckst, xiki-tempula, jaclark5
* 2.4.0

Enhancements
- Addition of `moving_average` function in both `convergence` and
`visualization` (Issue #380, PR #381)


08/24/2024 xiki-tempula

* 2.3.2

Changes:
- Remove Python 3.9 support (issue #389, PR #390).

Enhancements
- Add a tutorial section in the documentation (issue #382, PR #379).


07/08/2024 orbeckst, xiki-tempula

* 2.3.1

Changes:
- alchemlyb adopts SPEC 0 (replaces NEP 29)
https://scientific-python.org/specs/spec-0000/
- Addition of `moving_average` function in both `convergence` and
`visualization` (Issue #380, PR #381)

Fixes
- Support matplotlib 3.9.0 (issue alchemistry/flamel#28, PR#319).


21/05/2024 xiki-tempula
05/21/2024 xiki-tempula

* 2.3.0

Expand All @@ -43,7 +60,7 @@ Enhancements
- `BAR` result is used as initial guess for `MBAR` estimator. (PR #357)
- `forward_backward_convergence` uses the result from the previous step as the initial guess for the next step. (PR #357)

06/04/2024 hl2500, xiki-tempula
04/06/2024 hl2500, xiki-tempula

* 2.2.0

Expand All @@ -65,7 +82,7 @@ Fixes
unit conversion (issue #350, PR#319).


22/06/2023 xiki-tempula
06/22/2023 xiki-tempula

* 2.1.0

Expand All @@ -91,7 +108,7 @@ DeprecationWarning
analytic to bootstrap=50 in 2.2.0 (issue #320, PR#322).


06/04/2023 xiki-tempula
04/06/2023 xiki-tempula

* 2.0.1

Expand Down Expand Up @@ -123,7 +140,7 @@ Removals
equivalent functionality. (issue #284)


12/09/2022 DrDomenicoMarson, xiki-tempula, orbeckst
09/12/2022 DrDomenicoMarson, xiki-tempula, orbeckst

* 1.0.1

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

3. Estimators for obtaining free energies directly from this data, using best-practices approaches for multistate Bennett acceptance ratio (MBAR) [Shirts2008](#shirts2008) and BAR (from [pymbar](http://pymbar.readthedocs.io/)) and thermodynamic integration (TI).

## Documentation

The documentation is hosted on [Read the Docs](https://alchemlyb.readthedocs.io/en/latest/).

## Installation

**Install** via `pip` from [PyPi (alchemlyb)](https://pypi.org/project/alchemlyb):
Expand Down
32 changes: 32 additions & 0 deletions docs/.templates/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends "!footer.html" %}
{% block contentinfo %}
<p>
{%- if show_copyright %}
{%- if hasdoc('copyright') %}
{%- trans path=pathto('copyright'), copyright=copyright %}&#169; <a href="{{ path }}">Copyright</a> {{ copyright }}.{% endtrans %}
{%- else %}
{%- trans copyright=copyright %}&#169; Copyright {{ copyright }}.{% endtrans %}
{%- endif %}
{%- endif %}

{%- if build_id and build_url %}
<span class="build">
{#- Translators: Build is a noun, not a verb -#}
{%- trans %}Build{% endtrans -%}
<a href="{{ build_url }}">{{ build_id }}</a>.
</span>
{%- elif commit %}
<span class="commit">
{#- Translators: the phrase "revision" comes from Git, referring to a commit #}
{%- trans %}Revision{% endtrans %} <code>{{ commit }}</code>.
</span>
{%- endif %}
{%- if last_updated %}
<span class="lastupdated">
{%- trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %}
</span>
{%- endif -%}

</p>

{% endblock %}
13 changes: 6 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import datetime

# -- General configuration ------------------------------------------------

Expand All @@ -39,7 +40,7 @@
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
templates_path = [".templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
Expand All @@ -51,12 +52,10 @@
master_doc = "index"

# General information about the project.
now = datetime.datetime.now()
project = "alchemlyb"
author = """Irfan Alibay, Bryce Allen, Mohammad S. Barhaghi, Oliver
Beckstein, David Dotson, Jérôme Hénin, Travis Jensen, Thomas
T. Joseph, Ian Kenney, Hyungro Lee, Victoria Lim, Shuai Liu, Domenico
Marson, Pascal Merz, Alexander Schlaich, Dominik Wille, Zhiyi Wu"""
copyright = "2017-2022, " + author
author = 'The alchemlyb development team (see <a href="https://raw.githubusercontent.com/alchemistry/alchemlyb/master/AUTHORS">AUTHORS</a>)'
copyright = f"2017-{now.year}, " + author


# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -176,7 +175,7 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"https://docs.python.org/": None,
"python": ("https://docs.python.org/", None),
"pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None),
"pymbar": ("https://pymbar.readthedocs.io/en/latest/", None),
"alchemtest": ("https://alchemtest.readthedocs.io/en/latest/", None),
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ We also welcome code contributions: have a look at our `Developer Guide`_. Open
:caption: User Documentation

install
tutorial
parsing
preprocessing
estimators
Expand Down
2 changes: 2 additions & 0 deletions docs/parsing.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.. module:: alchemlyb.parsing


.. _parsing:

Parsing data files
==================
**alchemlyb** features parsing submodules for getting raw data from different software packages into common data structures that can be used directly by its :ref:`subsamplers <subsampling>` and :ref:`estimators <estimators>`.
Expand Down
155 changes: 155 additions & 0 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
Tutorial
========

In this tutorial, we will demonstrate how to use **alchemlyb** with test data
from `alchemtest`_. This guide provides a general introduction to the tool with
minimal explanations. For more detailed information, please refer to the
relevant sections of the documentation.

Parsing the Free Energy Data
----------------------------

**alchemlyb** requires free energy data obtained from alchemical simulations.
In this example, we use free energy data from Gromacs. Instructions for
reading data from other MD engines are available in the
documentation on :ref:`parsing files <parsing>`. We load the free energy data into a
:mod:`pandas.DataFrame`: ::

>>> from alchemtest.gmx import load_benzene
>>> from alchemlyb.parsing.gmx import extract_u_nk

>>> bz = load_benzene().data
>>> u_nk_list = [extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]
>>> u_nk_list[0]
0.0 0.25 0.5 0.75 1.0
time fep-lambda
0.0 0.0 0.309323 3.656838 7.004353 10.351867 13.699382
10.0 0.0 0.308844 2.616688 4.924532 7.232375 9.540219
20.0 0.0 0.300940 1.626739 2.952538 4.278337 5.604135
30.0 0.0 0.309712 1.579647 2.849583 4.119518 5.389453
40.0 0.0 0.299979 2.255386 4.210794 6.166202 8.121609
... ... ... ... ... ...
39960.0 0.0 0.309339 2.999887 5.690435 8.380983 11.071532
39970.0 0.0 0.304674 2.313761 4.322848 6.331935 8.341022
39980.0 0.0 0.305687 2.047583 3.789479 5.531375 7.273271
39990.0 0.0 0.303546 3.174116 6.044686 8.915256 11.785826
40000.0 0.0 0.314376 3.021203 5.728030 8.434858 11.141684

[4001 rows x 5 columns]

Decorrelating the Data
----------------------

The :class:`~alchemlyb.estimators.MBAR` estimator requires decorrelated data.
Various options for decorrelating the data are available in the relevant
documentation on :ref:`subsampling data <subsampling>`. Here, we decorrelate the data using the
following code. ::

>>> from alchemlyb.preprocessing.subsampling import decorrelate_u_nk

>>> decorrelated_u_nk_list = [decorrelate_u_nk(u_nk) for u_nk in u_nk_list]
>>> decorrelated_u_nk_list[0]
0.0 0.25 0.5 0.75 1.0
time fep-lambda
0.0 0.0 0.309323 3.656838 7.004353 10.351867 13.699382
20.0 0.0 0.300940 1.626739 2.952538 4.278337 5.604135
40.0 0.0 0.299979 2.255386 4.210794 6.166202 8.121609
60.0 0.0 0.308315 2.284146 4.259977 6.235809 8.211640
80.0 0.0 0.301432 1.397817 2.494203 3.590589 4.686975
... ... ... ... ... ...
39920.0 0.0 0.305202 2.420299 4.535396 6.650492 8.765589
39940.0 0.0 0.307156 -0.552737 -1.412630 -2.272523 -3.132416
39960.0 0.0 0.309339 2.999887 5.690435 8.380983 11.071532
39980.0 0.0 0.305687 2.047583 3.789479 5.531375 7.273271
40000.0 0.0 0.314376 3.021203 5.728030 8.434858 11.141684

[2001 rows x 5 columns]

Estimating Free Energy
----------------------

We estimate the free energy using the :class:`~alchemlyb.estimators.MBAR`
method. More estimators are available in the section on
:ref:`free energy estimators <estimators>`. ::

>>> from alchemlyb.estimators import MBAR
>>> import pandas as pd

>>> mbar = MBAR()
>>> mbar.fit(pd.concat(decorrelated_u_nk_list))
>>> mbar.delta_f_
0.00 0.25 0.50 0.75 1.00
0.00 0.000000 1.613595 2.553407 2.983336 3.039517
0.25 -1.613595 0.000000 0.939812 1.369741 1.425922
0.50 -2.553407 -0.939812 0.000000 0.429929 0.486110
0.75 -2.983336 -1.369741 -0.429929 0.000000 0.056181
1.00 -3.039517 -1.425922 -0.486110 -0.056181 0.000000


Free energy difference between :math:`\lambda = 0` and :math:`\lambda = 1` is ::

>>> mbar.delta_f_.loc[0.00, 1.00]
3.039517

Plotting the Diagnostics
------------------------

We can plot the diagnostics of the estimator to assess the
:ref:`overlap metrics <plot_overlap_matrix>`. More information on diagnostics
is available in the relevant section on :ref:`visualisation <visualisation>`: ::

>>> from alchemlyb.visualisation import plot_mbar_overlap_matrix
>>> ax = plot_mbar_overlap_matrix(mbar.overlap_matrix)
>>> ax.figure.savefig('O_MBAR.pdf', bbox_inches='tight', pad_inches=0.0)

This will generate a plot that looks like the one below:

.. figure:: images/O_MBAR.png

Automated workflow
------------------

The above manual workflow can be automated using the :mod:`~alchemlyb.workflows.ABFE`
workflow class, which demonstrates a best practice implementation for using **alchemlyb** in a end-to-end fashion.

.. SeeAlso::
See the :ref:`ABFE workflow <abfe-workflow>` section of the documentation for
more details on how to use :mod:`~alchemlyb.workflows.ABFE`.

*Absolute binding free energy* (ABFE) calculations can be analyzed with
two lines of code in a fully automated manner.
All parameters are set when invoking :class:`~alchemlyb.workflows.abfe.ABFE`
and reasonable defaults are chosen for any parameters not set explicitly. The two steps are to

1. initialize an instance of the :class:`~alchemlyb.workflows.abfe.ABFE` class
2. invoke the :meth:`~alchemlyb.workflows.ABFE.run` method to execute the
complete workflow.

As an example, we again use data from a GROMACS ABFE simulation that is available
in alchemtest_. In this case, executing the workflow would look similar
to the following code ::

>>> from alchemtest.gmx import load_ABFE
>>> from alchemlyb.workflows import ABFE
>>> # Obtain the path of the data
>>> import os
>>> dir = os.path.dirname(load_ABFE()['data']['complex'][0])
>>> print(dir)
'alchemtest/gmx/ABFE/complex'
>>> workflow = ABFE(units='kcal/mol', software='GROMACS', dir=dir,
>>> prefix='dhdl', suffix='xvg', T=298, outdirectory='./')
>>> workflow.run(skiptime=10, uncorr='dhdl', threshold=50,
>>> estimators=('MBAR', 'BAR', 'TI'), overlap='O_MBAR.pdf',
>>> breakdown=True, forwrev=10)


The workflow uses :mod:`~alchemlyb.parsing` to parse the data from the
energy files, remove the initial un-equilibrated frames and decorrelate the data
with :mod:`~alchemlyb.preprocessing.subsampling`. The decorrelated datasets
:ref:`dHdl <dHdl>` and :ref:`u_nk <u_nk>` are then passed to
:mod:`~alchemlyb.estimators` for free energy estimation. The workflow will
also perform a set of analysis that allows the user to examine the quality of
the estimation.


.. _alchemtest: https://github.com/alchemistry/alchemtest
2 changes: 2 additions & 0 deletions docs/visualisation.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.. module:: alchemlyb.visualisation

.. _visualisation:

Visualisation of the results
============================
It is quite often that the user want to visualise the results to gain
Expand Down
2 changes: 2 additions & 0 deletions docs/workflows/alchemlyb.workflows.ABFE.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _abfe-workflow:

The ABFE workflow
==================
The *Absolute binding free energy* (ABFE) workflow provides a complete workflow
Expand Down
Loading

0 comments on commit 10ee4bc

Please sign in to comment.