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

Implement the workflow pipeline #114

Merged
merged 148 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
eed8ab8
load_data
xiki-tempula Feb 28, 2021
4f96b58
update
xiki-tempula Mar 7, 2021
f05c5dd
update
xiki-tempula Mar 8, 2021
36f107a
update
xiki-tempula Mar 14, 2021
70d56bd
add doc
xiki-tempula Mar 21, 2021
d415427
add test
xiki-tempula Mar 22, 2021
f814bac
Update mbar_.py
xiki-tempula Mar 22, 2021
e197f67
cleanup
xiki-tempula Mar 27, 2021
61c9de2
Merge branch 'master' into workf
xiki-tempula Mar 27, 2021
37a2503
remove dependency for scipy constant
xiki-tempula Mar 27, 2021
ba2dcc3
dump test
xiki-tempula Mar 27, 2021
94d7bb6
Update test_workflow.py
xiki-tempula Mar 27, 2021
e4f6627
bump test
xiki-tempula Mar 27, 2021
2e0aed0
cleanup
xiki-tempula Mar 27, 2021
5ab748e
Delete result.log
xiki-tempula Mar 27, 2021
ddcaa8d
cleanup
xiki-tempula Mar 27, 2021
e566131
Merge branch 'workf' of https://github.com/xiki-tempula/alchemlyb int…
xiki-tempula Mar 27, 2021
90d033a
logging is a global variable
xiki-tempula Mar 27, 2021
c5a9b44
Revert "logging is a global variable"
xiki-tempula Mar 27, 2021
26e83fb
move some part to other PR
xiki-tempula Mar 29, 2021
eff7981
clean up
xiki-tempula Mar 29, 2021
71524fc
Merge branch 'master' into workf
xiki-tempula Apr 15, 2021
ea6b834
bump coverage
xiki-tempula Apr 15, 2021
f4b736c
dump coverage
xiki-tempula Apr 15, 2021
7dcce77
typo
xiki-tempula Apr 15, 2021
a926597
update
xiki-tempula Jul 10, 2021
cf142a1
revert change
xiki-tempula Jul 10, 2021
ce1539a
update
xiki-tempula Jul 10, 2021
c5724e1
Update ti_dhdl.py
xiki-tempula Jul 10, 2021
3cc332d
Merge branch 'master' into workf
xiki-tempula Jul 10, 2021
1a97228
Update abfe.py
xiki-tempula Jul 10, 2021
4d5425b
update to pass the test
xiki-tempula Jul 10, 2021
058aa99
Merge branch 'master' into workf
xiki-tempula Jul 13, 2021
ef52952
Update mbar_.py
xiki-tempula Jul 13, 2021
9d2eb06
update
xiki-tempula Aug 2, 2021
ab1ab76
Update abfe.py
xiki-tempula Aug 2, 2021
10fbdc4
Update mbar_.py
xiki-tempula Aug 2, 2021
622125a
Merge branch 'master' into workf
xiki-tempula Aug 2, 2021
4a72c2a
Revert "Update mbar_.py"
xiki-tempula Aug 2, 2021
90495b5
Merge branch 'workf' of https://github.com/xiki-tempula/alchemlyb int…
xiki-tempula Aug 2, 2021
dd1735e
Update mbar_.py
xiki-tempula Aug 2, 2021
eaf0b6e
Merge branch 'master' into workf
xiki-tempula Sep 24, 2021
cd2ff92
Create convergence.py
xiki-tempula Sep 25, 2021
aa3054e
Update convergence.py
xiki-tempula Sep 25, 2021
ef21b2d
Update convergence.py
xiki-tempula Sep 25, 2021
7238298
update
xiki-tempula Sep 26, 2021
8ad6bb2
update
xiki-tempula Sep 26, 2021
e87867f
update doc
xiki-tempula Sep 26, 2021
7d2b936
update doc
xiki-tempula Sep 26, 2021
36f9adc
update
xiki-tempula Oct 4, 2021
f9d08bc
update
xiki-tempula Oct 4, 2021
daa9870
Merge branch 'master' into convergence
orbeckst Oct 5, 2021
305ceac
update
xiki-tempula Oct 7, 2021
212e955
change parser
xiki-tempula Jun 5, 2021
d281582
Update test_convergence.py
xiki-tempula Oct 7, 2021
f6ce666
update
xiki-tempula Oct 7, 2021
e9601fb
Update convergence.py
xiki-tempula Oct 7, 2021
a4d379a
Update convergence.py
xiki-tempula Oct 7, 2021
1340367
Update convergence.py
xiki-tempula Oct 8, 2021
8b5135e
Merge branch 'master' into workf
xiki-tempula Oct 8, 2021
6a38d27
Merge pull request #1 from xiki-tempula/convergence
xiki-tempula Oct 8, 2021
e082035
Update abfe.py
xiki-tempula Oct 8, 2021
e7ce4fb
update
xiki-tempula Oct 8, 2021
3cbd016
Update abfe.py
xiki-tempula Oct 18, 2021
b70e68c
Update abfe.py
xiki-tempula Oct 18, 2021
204d22a
Merge branch 'master' into workf
xiki-tempula Oct 22, 2021
c8b7f66
Update convergence.py
xiki-tempula Oct 22, 2021
696c36d
Merge branch 'master' into workf
xiki-tempula Oct 30, 2021
24298a4
Update abfe.py
xiki-tempula Oct 30, 2021
73b781e
Update convergence.py
xiki-tempula Oct 30, 2021
e93d3bf
update
xiki-tempula Oct 30, 2021
281a864
update
xiki-tempula Oct 30, 2021
602b98b
Update test_workflow_ABFE.py
xiki-tempula Oct 30, 2021
b8606dd
Reobust gmx (#2)
xiki-tempula Dec 30, 2021
bbd281d
update
xiki-tempula Mar 5, 2022
dd5a604
Merge branch 'master' into workf
xiki-tempula Mar 6, 2022
1c40e97
test
xiki-tempula Mar 6, 2022
aecac7e
Update test_workflow.py
xiki-tempula Mar 13, 2022
672a41a
Merge branch 'workf' into base
xiki-tempula Mar 13, 2022
afb22f5
Base (#3)
xiki-tempula Mar 13, 2022
09efd77
Revert "Merge branch 'workf' into base"
xiki-tempula Mar 13, 2022
b173d93
Update base.py
xiki-tempula Mar 13, 2022
9ddc811
Update alchemlyb.workflows.base.rst
xiki-tempula Mar 13, 2022
3dc8c2a
update
xiki-tempula Mar 13, 2022
ecd29ee
update
xiki-tempula Mar 27, 2022
0b37cf4
Update base.py
xiki-tempula Mar 27, 2022
9b73218
Merge branch 'master' into base
xiki-tempula Apr 3, 2022
dd74acf
update
xiki-tempula Apr 10, 2022
b8355bb
Update CHANGES
xiki-tempula Apr 10, 2022
3132af3
Merge branch 'base' into workf
xiki-tempula Apr 10, 2022
36ca207
update
xiki-tempula Apr 10, 2022
02e9520
update
xiki-tempula Apr 10, 2022
b58d117
update
xiki-tempula Apr 10, 2022
58f52e7
update
xiki-tempula Apr 10, 2022
a71d32f
update
xiki-tempula Apr 10, 2022
3dbc165
update
xiki-tempula May 1, 2022
36ed0d0
Merge branch 'master' into workf
xiki-tempula May 1, 2022
f045017
update
xiki-tempula May 1, 2022
7da1bda
Merge branch 'workf' of https://github.com/xiki-tempula/alchemlyb int…
xiki-tempula May 1, 2022
81c33b8
Merge branch 'master' into workf
xiki-tempula May 2, 2022
b5a27a3
update
xiki-tempula May 15, 2022
87c473e
update
xiki-tempula May 15, 2022
5ee44a8
update
xiki-tempula May 15, 2022
db5232e
Update abfe.py
xiki-tempula May 15, 2022
1d2d536
update
xiki-tempula May 15, 2022
e79d31b
Merge branch 'master' into workf
orbeckst Jun 11, 2022
1d28042
update
xiki-tempula Jun 25, 2022
456288a
Update abfe.py
xiki-tempula Jun 26, 2022
aea041a
Merge branch 'master' into workf
xiki-tempula Jul 3, 2022
d859c4e
update
xiki-tempula Jul 3, 2022
03aad47
Update docs/workflows/alchemlyb.workflows.ABFE.rst
xiki-tempula Jul 3, 2022
995bba1
Update docs/workflows/alchemlyb.workflows.ABFE.rst
xiki-tempula Jul 3, 2022
5e3d6c4
update
xiki-tempula Jul 3, 2022
1a9f155
Merge branch 'master' into workf
xiki-tempula Aug 14, 2022
2ccef0c
resolve comments
xiki-tempula Aug 14, 2022
7aa6ecb
fix name
xiki-tempula Aug 14, 2022
eca06db
fix test
xiki-tempula Aug 14, 2022
720a76b
fix test
xiki-tempula Aug 14, 2022
5c829d0
fix test
xiki-tempula Aug 14, 2022
50f7432
fix test
xiki-tempula Aug 14, 2022
2b0941d
remove no cover
xiki-tempula Aug 14, 2022
2d173a8
bump coverage
xiki-tempula Aug 14, 2022
b2ed582
bump coverage
xiki-tempula Aug 14, 2022
80b9bb3
bump coverage
xiki-tempula Aug 14, 2022
d5c9ea5
remove no cover
xiki-tempula Aug 14, 2022
bd8873b
Merge branch 'master' into workf
orbeckst Aug 17, 2022
d061fdc
update
xiki-tempula Aug 22, 2022
a778a0e
update
xiki-tempula Aug 22, 2022
ab71686
update doc.
xiki-tempula Aug 22, 2022
c246e9c
fix docs
xiki-tempula Aug 22, 2022
c35ca7a
Update docs/workflows/alchemlyb.workflows.ABFE.rst
xiki-tempula Sep 2, 2022
9f17cbc
Update src/alchemlyb/convergence/convergence.py
xiki-tempula Sep 2, 2022
cc33374
Update src/alchemlyb/convergence/convergence.py
xiki-tempula Sep 2, 2022
f840d27
Update src/alchemlyb/estimators/mbar_.py
xiki-tempula Sep 2, 2022
5070fe6
Update src/alchemlyb/estimators/mbar_.py
xiki-tempula Sep 2, 2022
f7c7c21
Update src/alchemlyb/estimators/mbar_.py
xiki-tempula Sep 2, 2022
30bccd3
Update src/alchemlyb/estimators/mbar_.py
xiki-tempula Sep 2, 2022
fa4c4bf
update changes
xiki-tempula Sep 2, 2022
6cf8895
no cover
xiki-tempula Sep 2, 2022
8a31787
Update CHANGES
xiki-tempula Sep 2, 2022
be55f59
update
xiki-tempula Sep 2, 2022
e6752c9
update
xiki-tempula Sep 3, 2022
282e98d
fix test
xiki-tempula Sep 3, 2022
594bb33
changes
xiki-tempula Sep 3, 2022
77ce671
raise OSError from original_exception in ABFE.read()
orbeckst Sep 6, 2022
ed3871d
fixed tests for OSError exceptions
orbeckst Sep 6, 2022
d6d7b9f
use upper case estimators in tests
orbeckst Sep 6, 2022
ef4a8d7
fix test for windows, too
orbeckst Sep 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.vscode
*.DS_Store
build
.idea/
docs/_build/
src/alchemlyb.egg-info/
Binary file added 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.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Contributions are very welcome. If you have bug reports or feature requests or q
:caption: User Documentation

install
workflow
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
parsing
preprocessing
estimators
Expand Down
48 changes: 48 additions & 0 deletions docs/visualisation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ visualisation tools to help user to judge the estimate.
plot_mbar_overlap_matrix
plot_ti_dhdl
plot_dF_state
plot_convergence
orbeckst marked this conversation as resolved.
Show resolved Hide resolved

.. _plot_overlap_matrix:

Expand Down Expand Up @@ -131,6 +132,53 @@ Will give a plot looks like this
A bar plot of the free energy differences evaluated between pairs of adjacent
states via several methods, with corresponding error estimates for each method.

.. _plot_convergence:
orbeckst marked this conversation as resolved.
Show resolved Hide resolved

Forward and Backward Convergence
--------------------------------
One way of determining the simulation end point is to plot the forward and
backward convergence of the estimate using
:func:`~alchemlyb.visualisation.plot_convergence`.

Note that this is just a plotting function to plot [Klimovich2015]_ style
convergence plot. The user need to provide the forward and backward data list
and the corresponding error. ::

>>> 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
>>> data_list = [extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]
>>> forward = []
>>> forward_error = []
>>> backward = []
>>> backward_error = []
>>> num_points = 10
>>> for i in range(1, num_points+1):
>>> # Do the forward
>>> slice = int(len(data)/num_points*i)
>>> u_nk_coul = pd.concat([data[:slice] for data in data_list])
>>> estimate = MBAR().fit(u_nk_coul)
>>> forward.append(estimate.delta_f_.iloc[0,-1])
>>> forward_error.append(estimate.d_delta_f_.iloc[0,-1])
>>> # Do the backward
>>> u_nk_coul = pd.concat([data[-slice:] for data in data_list])
>>> estimate = MBAR().fit(u_nk_coul)
>>> backward.append(estimate.delta_f_.iloc[0,-1])
>>> backward_error.append(estimate.d_delta_f_.iloc[0,-1])

>>> from alchemlyb.visualisation import plot_convergence
>>> ax = plot_convergence(forward, forward_error, backward, backward_error)
>>> ax.figure.savefig('dF_t.pdf')

Will give a plot looks like this

.. figure:: images/dF_t.png

A convergence plot of showing that the forward and backward has converged
fully.

.. [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
Expand Down
19 changes: 19 additions & 0 deletions docs/visualisation/alchemlyb.visualisation.plot_convergence.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. _visualisation_plot_convergence:
orbeckst marked this conversation as resolved.
Show resolved Hide resolved

Plot the Forward and Backward Convergence
=========================================

The function :func:`~alchemlyb.visualisation.plot_convergence` allows
the user to visualise the convergence by plotting the free energy change
computed using the equilibrated snapshots between the proper target time frames
in both forward (data points are stored in `forward` and `forward_error`) and
reverse (data points are stored in `backward` and `backward_error`) directions.
The unit in the y axis could be labelled to other units by setting *units*,
which by default is kBT. The user can pass :class:`matplotlib.axes.Axes` into
the function to have the convergence drawn on a specific axes.

Please check :ref:`How to plot convergence <plot_convergence>` for usage.

API Reference
-------------
.. autofunction:: alchemlyb.visualisation.plot_convergence
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The figure could be plotted in *portrait* or *landscape* mode by setting the
The user could pass a list of strings to `labels` to name the
:class:`~alchemlyb.estimators` or a list of strings to `colors` to color
the estimators differently. The unit in the y axis could be labelled to other
units by setting `units`, which by default is kcal/mol.
units by setting `units`, which by default is kBT.

Please check :ref:`How to plot dF states <plot_dF_states>` for a complete
example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ When custom labels are desirable, the user could pass a list of strings to the
*labels* for labelling each alchemical transformation differently. The color of
each alchemical transformation could also be set by passing a list of color
string to the *colors*. The unit in the y axis could be labelled to other units
by setting *units*, which by default is kcal/mol. The user can pass
by setting *units*, which by default is kBT. The user can pass
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
:class:`matplotlib.axes.Axes` into the function to have the dhdl drawn on a
specific axes.

Expand Down
109 changes: 109 additions & 0 deletions docs/workflow.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
Automatic workflow
==================
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
Though **alchemlyb** is a library offering great flexibility in deriving free
energy estimate, it also provide a easy pipeline that is similar to
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_ and a
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
step-by-step version that allows more flexibility.

Fully Automatic analysis
------------------------
A interface similar to
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_
could be excuted with a single line of command. ::

>>> import os
>>> from alchemtest.gmx import load_ABFE
>>> from alchemlyb.workflows import ABFE
>>> # Obtain the path of the data
>>> 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, skiptime=10,
>>> uncorr='dhdl', threshold=50,
>>> methods=('mbar', 'bar', 'ti'), out='./',
>>> resultfilename='result.out', overlap='O_MBAR.pdf',
>>> breakdown=True, forwrev=10, log='result.log')

This would give the free energy estimate using all of
:class:`~alchemlyb.estimators.TI`, :class:`~alchemlyb.estimators.BAR`,
:class:`~alchemlyb.estimators.MBAR` and the result will be written to the text
file `result.out`. ::

------------ --------------------- --------------------- ---------------------
States MBAR (kcal/mol) BAR (kcal/mol) TI (kcal/mol)
------------ --------------------- --------------------- ---------------------
0 -- 1 0.041 +- 0.001 0.041 +- 0.001 0.041 +- 0.001
1 -- 2 0.056 +- 0.001 0.055 +- 0.001 0.056 +- 0.001
2 -- 3 0.082 +- 0.001 0.082 +- 0.002 0.083 +- 0.002
...
26 -- 27 0.766 +- 0.007 0.768 +- 0.010 0.770 +- 0.010
27 -- 28 0.694 +- 0.008 0.691 +- 0.011 0.690 +- 0.010
28 -- 29 0.620 +- 0.010 0.616 +- 0.011 0.625 +- 0.011
------------ --------------------- --------------------- ---------------------
coul: 6.290 +- 0.021 6.168 +- 0.026 6.168 +- 0.030
vdw: 13.872 +- 0.061 13.852 +- 0.037 13.877 +- 0.066
bonded: 1.469 +- 0.009 1.447 +- 0.003 1.461 +- 0.013
TOTAL: 21.631 +- 0.064 21.467 +- 0.054 21.506 +- 0.074

The :ref:`overlay matrix for the MBAR estimator <plot_overlap_matrix>` will be
plotted and saved to `O_MBAR.pdf`.

The :ref:`dHdl for TI <plot_TI_dhdl>` will be plotted to `dhdl_TI.pdf`.

The :ref:`dF states <plot_dF_states>` will be plotted to `dF_state.pdf` in
portrait model and `dF_state_long.pdf` in landscape model.

The forward and backward convergence will be plotted to `dF_t.pdf` using
:class:`~alchemlyb.estimators.MBAR`.

.. currentmodule:: alchemlyb.workflows

.. autoclass:: ABFE
:noindex:
orbeckst marked this conversation as resolved.
Show resolved Hide resolved

Semi-automatic analysis
-----------------------
The same analysis could also performed in steps allowing access and modification
to the data generated at each stage of the analysis. ::

>>> import os
>>> from alchemtest.gmx import load_ABFE
>>> from alchemlyb.workflows import ABFE
>>> # Obtain the path of the data
>>> dir = os.path.dirname(load_ABFE()['data']['complex'][0])
>>> print(dir)
'alchemtest/gmx/ABFE/complex'
>>> # Load the data
>>> workflow = ABFE(software='Gromacs', dir=dir,
>>> prefix='dhdl', suffix='xvg', T=298, out='./',
>>> log='result.log')
>>> # Set the unit.
>>> workflow.update_units('kcal/mol')
>>> # Decorrelate the data.
>>> workflow.preprocess(skiptime=10, uncorr='dhdl', threshold=50)
>>> # Run the estimator
>>> workflow.estimate(methods=('mbar', 'bar', 'ti'))
>>> # write the result
>>> workflow.write(resultfilename='result.out')
>>> # Plot the overlap matrix
>>> workflow.plot_overlap_matrix(overlap='O_MBAR.pdf')
>>> # Plot the dHdl for TI
>>> workflow.plot_ti_dhdl(dhdl_TI='dhdl_TI.pdf')
>>> # Plot the dF states
>>> workflow.plot_dF_state(dF_state='dF_state.pdf')
>>> # Convergence analysis
>>> workflow.check_convergence(10, dF_t='dF_t.pdf')


.. currentmodule:: alchemlyb.workflows.ABFE

.. autofunction:: update_units
.. autofunction:: preprocess
.. autofunction:: estimate
.. autofunction:: write
.. autofunction:: plot_overlap_matrix
.. autofunction:: plot_ti_dhdl
.. autofunction:: plot_dF_state
.. autofunction:: check_convergence

1 change: 0 additions & 1 deletion src/alchemlyb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
5 changes: 5 additions & 0 deletions src/alchemlyb/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'''Physical and mathematical constants and units.'''
# Taken from scipy.constants since py2 doesn't support it
k = 1.380649e-23
N_A = 6.02214076e+23
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
kJ2kcal = 0.239006
4 changes: 3 additions & 1 deletion src/alchemlyb/estimators/mbar_.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class MBAR(BaseEstimator):
"""

def __init__(self, maximum_iterations=10000, relative_tolerance=1.0e-7,
initial_f_k=None, method='hybr', verbose=False):
initial_f_k=None, method='adaptive', verbose=False):
# method='adaptive' is used as it is more stable
# https://github.com/choderalab/pymbar/issues/419

self.maximum_iterations = maximum_iterations
self.relative_tolerance = relative_tolerance
Expand Down
43 changes: 43 additions & 0 deletions src/alchemlyb/estimators/ti_.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,46 @@ def fit(self, dHdl):
self.states_ = means.index.values.tolist()

return self

def separate_dhdl(self):
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
"""
For transitions with multiple lambda, this function will separate the
dhdl with multiple columns into a list of Dataframe with a single column
(single lambda).

Returns
----------
dHdl_list : list
A list of Series such that dHdl_list[k][n] is the potential
energy gradient with respect to lambda for each configuration n and
lambda k.

"""
if len(self.dhdl.index.names) == 1:
# If only one column is present convert to series
assert len(self.dhdl.columns) == 1
name = self.dhdl.columns[0]
return [self.dhdl[name], ]
else:
dhdl_list = []
# get the lambda names
l_types = self.dhdl.index.names
# obtain bool of changed lambdas between each state
lambdas = self.dhdl.reset_index()[l_types]
diff = lambdas.diff().to_numpy(dtype='bool')
# diff will give the first row as NaN so need to fix that
diff[0, :] = diff[1, :]
# Make sure that the start point is set to true as well
diff[:-1, :] = diff[:-1, :] | diff[1:, :]
for i in range(len(l_types)):
if any(diff[:,i]) == False:
# Skip if not pertubed
pass
else:
new = self.dhdl.iloc[diff[:,i], i]
# drop all other index
for l in l_types:
if l != l_types[i]:
new = new.reset_index(l, drop=True)
dhdl_list.append(new)
return dhdl_list
1 change: 0 additions & 1 deletion src/alchemlyb/preprocessing/subsampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def _check_multiple_times(df):
else:
return df.sort_index(0).reset_index('time').duplicated('time').any()


def _check_sorted(df):
return df.reset_index(0)['time'].is_monotonic_increasing

Expand Down
5 changes: 5 additions & 0 deletions src/alchemlyb/tests/test_ti_estimators.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,8 @@ class TestTI(TIestimatorMixin):
def X_delta_f(self, request):
get_dHdl, E, dE = request.param
return get_dHdl(), E, dE

def test_TI_separate_dhdl():
dHdl = gomc_benzene_dHdl()
estimator = TI().fit(dHdl)
assert all([isinstance(dhdl, pd.Series) for dhdl in estimator.separate_dhdl()])
Loading