def namd_tyr2ala(): dataset = alchemtest.namd.load_tyr2ala() u_nk1 = namd.extract_u_nk(dataset['data']['forward'][0], T=300) u_nk2 = namd.extract_u_nk(dataset['data']['backward'][0], T=300) # combine dataframes of fwd and rev directions u_nk1[u_nk1.isna()] = u_nk2 u_nk = u_nk1.sort_index(level=u_nk1.index.names[1:]) return u_nk
def test_u_nk_restarted_last_window_truncated( restarted_dataset_last_window_truncated): """Test that when there is more than one lambda2 for a given lambda1, parsing throws an error.""" with pytest.raises(ValueError, match='Last window is truncated'): u_nk = extract_u_nk( restarted_dataset_last_window_truncated['data']['both'], T=300)
def test_u_nk_restarted_toomany_lambda2(restarted_dataset_toomany_lambda2): """Test that when there is more than one lambda2 for a given lambda1, parsing throws an error.""" with pytest.raises( ValueError, match='More than one lambda2 value for a particular lambda1'): u_nk = extract_u_nk(restarted_dataset_toomany_lambda2['data']['both'], T=300)
def test_u_nk_restarted_all_windows_truncated( restarted_dataset_all_windows_truncated): """Test that when there is more than one lambda2 for a given lambda1, parsing throws an error.""" with pytest.raises(ValueError, match='New window begun after truncated window'): u_nk = extract_u_nk( restarted_dataset_all_windows_truncated['data']['both'], T=300)
def test_u_nk(dataset, direction, shape): """Test that u_nk has the correct form when extracted from files. """ for filename in dataset['data'][direction]: u_nk = extract_u_nk(filename, T=300) assert u_nk.index.names == ['time', 'fep-lambda'] assert u_nk.shape == shape
def test_u_nk_idws(): """Test that u_nk has the correct form when extracted from files. """ filenames = load_idws()['data']['forward'] u_nk = extract_u_nk(filenames, T=300) assert u_nk.index.names == ['time', 'fep-lambda'] assert u_nk.shape == (29252, 11)
def test_u_nk_restarted(): """Test that u_nk has the correct form when extracted from an IDWS FEP run that includes terminations and restarts. """ filenames = load_restarted()['data']['both'] u_nk = extract_u_nk(filenames, T=300) assert u_nk.index.names == ['time', 'fep-lambda'] assert u_nk.shape == (30061, 11)
def test_u_nk_restarted_inconsistent(restarted_dataset_inconsistent): """Test that when lambda values are inconsistent between start and end of a single window, parsing throws an error. """ with pytest.raises( ValueError, match='Inconsistent lambda values within the same window'): u_nk = extract_u_nk(restarted_dataset_inconsistent['data']['both'], T=300)
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)
def test_u_nk_restarted_reversed_missing_window_header(tmp_path): """Test that u_nk has the correct form when a #NEW line is missing from the restarted_reversed dataset and the parser has to infer lambda_idws for that window.""" filenames = sorted(load_restarted_reversed()['data']['both']) # Remove "#NEW" line filenames[4] = _corrupt_fepout(filenames[4], [ ('#NEW', lambda l: None), ], tmp_path) u_nk = extract_u_nk(filenames, T=300) assert u_nk.index.names == ['time', 'fep-lambda'] assert u_nk.shape == (30170, 11)
def test_u_nk(): """Test that u_nk has the correct form when extracted from files. """ dataset = load_tyr2ala() 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_u_nk_restarted_idws_without_lambda_idws( restarted_dataset_idws_without_lambda_idws): """Test that when the first window has IDWS data but no lambda_idws, parsing throws an error. In this situation, the lambda_idws cannot be inferred, because there's no previous lambda value available. """ with pytest.raises( ValueError, match= 'IDWS data present in first window but lambda_idws not included'): u_nk = extract_u_nk( restarted_dataset_idws_without_lambda_idws['data']['both'], T=300)
def namd_idws_restarted_reversed(): dataset = alchemtest.namd.load_restarted_reversed() u_nk = namd.extract_u_nk(dataset['data']['both'], T=300) return u_nk
def namd_idws(): dataset = alchemtest.namd.load_idws() u_nk = namd.extract_u_nk(dataset['data']['forward'], T=300) return u_nk
def test_u_nk_restarted_direction_changed(restarted_dataset_direction_changed): """Test that when lambda values change direction within a dataset, parsing throws an error.""" with pytest.raises(ValueError, match='Lambda values change direction'): u_nk = extract_u_nk( restarted_dataset_direction_changed['data']['both'], T=300)
def test_u_nk_restarted_reversed(): filenames = load_restarted_reversed()['data']['both'] u_nk = extract_u_nk(filenames, T=300) assert u_nk.index.names == ['time', 'fep-lambda'] assert u_nk.shape == (30170, 11)