-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- moved test - added test for the error (regression test) - use fixture for NAMD dataset and parametrized test for forward/backward legs in order to simplify code
- Loading branch information
Showing
2 changed files
with
30 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,24 @@ | ||
"""NAMD parser tests. | ||
""" | ||
import pytest | ||
|
||
from alchemlyb.parsing.namd import extract_u_nk | ||
from alchemtest.namd import load_tyr2ala | ||
from numpy.testing import assert_almost_equal | ||
|
||
@pytest.fixture(scope="module") | ||
def dataset(): | ||
return load_tyr2ala() | ||
|
||
def test_u_nk(): | ||
@pytest.mark.parametrize("direction,shape", | ||
[('forward', (21021, 21)), | ||
('backward', (21021, 21)), | ||
]) | ||
def test_u_nk(dataset, direction, shape): | ||
"""Test that u_nk has the correct form when extracted from files. | ||
""" | ||
dataset = load_tyr2ala() | ||
for filename in dataset['data'][direction]: | ||
u_nk = extract_u_nk(filename) | ||
|
||
for direction in dataset['data']: | ||
for filename in dataset['data'][direction]: | ||
u_nk = extract_u_nk(filename) | ||
|
||
assert u_nk.index.names == ['timestep', 'fep-lambda'] | ||
if direction == 'forward': | ||
assert u_nk.shape == (21021, 21) | ||
elif direction == 'backward': | ||
assert u_nk.shape == (21021, 21) | ||
|
||
def test_bar_namd(): | ||
"""Test BAR calculation on NAMD data. | ||
""" | ||
from alchemlyb.estimators import BAR | ||
import numpy as np | ||
|
||
# load data | ||
dataset = load_tyr2ala() | ||
u_nk1 = extract_u_nk(dataset['data']['forward'][0]) | ||
u_nk2 = extract_u_nk(dataset['data']['backward'][0]) | ||
|
||
# combine dataframes of fwd and rev directions | ||
u_nk1.replace(0, np.nan, inplace=True) | ||
u_nk1[u_nk1.isnull()] = u_nk2 | ||
u_nk1.replace(np.nan, 0, inplace=True) | ||
u_nk = u_nk1.sort_index(level=u_nk1.index.names[1:]) | ||
|
||
# after loading BOTH fwd and rev data, do BAR calculation | ||
bar = BAR() | ||
bar.fit(u_nk) | ||
dg = (bar.delta_f_.iloc[0].iloc[-1]) | ||
assert_almost_equal(dg, 6.03126982925, decimal=4) | ||
assert u_nk.index.names == ['timestep', 'fep-lambda'] | ||
assert u_nk.shape == shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters