Skip to content

Commit

Permalink
Revert "Merge branch 'feat_fixture'"
Browse files Browse the repository at this point in the history
This reverts commit 807915f.
  • Loading branch information
xiki-tempula committed Dec 6, 2022
1 parent 807915f commit afb7509
Show file tree
Hide file tree
Showing 8 changed files with 673 additions and 562 deletions.
2 changes: 0 additions & 2 deletions src/alchemlyb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def concat(objs, *args, **kwargs):
.. versionadded:: 0.5.0"""
if isinstance(objs, pd.DataFrame):
return objs
# Sanity check
try:
attrs = objs[0].attrs
Expand Down
267 changes: 0 additions & 267 deletions src/alchemlyb/tests/conftest.py

This file was deleted.

74 changes: 58 additions & 16 deletions src/alchemlyb/tests/test_convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
from alchemlyb.parsing import gmx


def test_convergence_ti(gmx_benzene_Coulomb_dHdl):
convergence = forward_backward_convergence(gmx_benzene_Coulomb_dHdl, "TI")
@pytest.fixture()
def gmx_benzene():
dataset = load_benzene()
return [gmx.extract_dHdl(dhdl, T=300) for dhdl in dataset["data"]["Coulomb"]], [
gmx.extract_u_nk(dhdl, T=300) for dhdl in dataset["data"]["Coulomb"]
]


def test_convergence_ti(gmx_benzene):
dHdl, u_nk = gmx_benzene
convergence = forward_backward_convergence(dHdl, "TI")
assert convergence.shape == (10, 5)

assert convergence.loc[0, "Forward"] == pytest.approx(3.07, 0.01)
Expand All @@ -19,29 +28,31 @@ def test_convergence_ti(gmx_benzene_Coulomb_dHdl):


@pytest.mark.parametrize("estimator", ["MBAR", "BAR"])
def test_convergence_fep(gmx_benzene_Coulomb_u_nk, estimator):
convergence = forward_backward_convergence(gmx_benzene_Coulomb_u_nk, estimator)
def test_convergence_fep(gmx_benzene, estimator):
dHdl, u_nk = gmx_benzene
convergence = forward_backward_convergence(u_nk, estimator)
assert convergence.shape == (10, 5)
assert convergence.loc[0, "Forward"] == pytest.approx(3.02, 0.01)
assert convergence.loc[0, "Backward"] == pytest.approx(3.06, 0.01)
assert convergence.loc[9, "Forward"] == pytest.approx(3.05, 0.01)
assert convergence.loc[9, "Backward"] == pytest.approx(3.04, 0.01)


def test_convergence_wrong_estimator(gmx_benzene_Coulomb_dHdl):
def test_convergence_wrong_estimator(gmx_benzene):
dHdl, u_nk = gmx_benzene
with pytest.raises(ValueError, match="is not available in"):
forward_backward_convergence(gmx_benzene_Coulomb_dHdl, "WWW")
forward_backward_convergence(u_nk, "WWW")


def test_convergence_wrong_cases(gmx_benzene_Coulomb_u_nk):
def test_convergence_wrong_cases(gmx_benzene):
dHdl, u_nk = gmx_benzene
with pytest.warns(DeprecationWarning, match="Using lower-case strings for"):
forward_backward_convergence(gmx_benzene_Coulomb_u_nk, "mbar")
forward_backward_convergence(u_nk, "mbar")


def test_convergence_method(gmx_benzene_Coulomb_u_nk):
convergence = forward_backward_convergence(
gmx_benzene_Coulomb_u_nk, "MBAR", num=2, method="adaptive"
)
def test_convergence_method(gmx_benzene):
dHdl, u_nk = gmx_benzene
convergence = forward_backward_convergence(u_nk, "MBAR", num=2, method="adaptive")
assert len(convergence) == 2


Expand All @@ -64,7 +75,12 @@ def test_cummean_long_none_integter():


def test_R_c_converged():
data = pd.Series(data=[0] * 100)
data = pd.Series(
data=[
0,
]
* 100
)
data.attrs["temperature"] = 310
data.attrs["energy_unit"] = "kcal/mol"
value, running_average = fwdrev_cumavg_Rc(data)
Expand All @@ -80,16 +96,42 @@ def test_R_c_notconverged():


def test_R_c_real():
data = pd.Series(data=np.hstack((range(10), [4.5] * 10)))
data = pd.Series(
data=np.hstack(
(
range(10),
[
4.5,
]
* 10,
)
)
)
data.attrs["temperature"] = 310
data.attrs["energy_unit"] = "kcal/mol"
value, running_average = fwdrev_cumavg_Rc(data, tol=2.0)
np.testing.assert_allclose(value, 0.35)


def test_A_c_real():
data = pd.Series(data=np.hstack((range(10), [4.5] * 10)))
data = pd.Series(
data=np.hstack(
(
range(10),
[
4.5,
]
* 10,
)
)
)
data.attrs["temperature"] = 310
data.attrs["energy_unit"] = "kcal/mol"
value = A_c([data] * 2, tol=2.0)
value = A_c(
[
data,
]
* 2,
tol=2.0,
)
np.testing.assert_allclose(value, 0.65)
Loading

0 comments on commit afb7509

Please sign in to comment.