def test_concat(): '''Test if different attrs could will give rise to error.''' d = {'col1': [1, 2], 'col2': [3, 4]} df1 = pd.DataFrame(data=d) df1.attrs = {1: 1} df2 = pd.DataFrame(data=d) df2.attrs = {1: 2} with pytest.raises(ValueError): alchemlyb.concat([df1, df2])
def estimaters(): bz = load_benzene().data dHdl_coul = alchemlyb.concat( [extract_dHdl(xvg, T=300) for xvg in bz['Coulomb']]) ti = TI().fit(dHdl_coul) u_nk_coul = alchemlyb.concat( [extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]) mbar = MBAR().fit(u_nk_coul) return ti, mbar
def gomc_benzene_dHdl(): dataset = alchemtest.gomc.load_benzene() dHdl = alchemlyb.concat( [gomc.extract_dHdl(filename, T=298) for filename in dataset['data']]) return dHdl
def gomc_benzene_u_nk(): dataset = alchemtest.gomc.load_benzene() u_nk = alchemlyb.concat( [gomc.extract_u_nk(filename, T=298) for filename in dataset['data']]) return u_nk
def u_nk(): bz = load_benzene().data u_nk_coul = alchemlyb.concat( [extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]) u_nk_coul.attrs = extract_u_nk(load_benzene().data['Coulomb'][0], T=300).attrs return u_nk_coul
def amber_simplesolvated_vdw_dHdl(): dataset = alchemtest.amber.load_simplesolvated() dHdl = alchemlyb.concat([amber.extract_dHdl(filename, T=300) for filename in dataset['data']['vdw']]) return dHdl
def gmx_water_particle_without_energy_dHdl(): dataset = alchemtest.gmx.load_water_particle_without_energy() dHdl = alchemlyb.concat([gmx.extract_dHdl(filename, T=300) for filename in dataset['data']['AllStates']]) return dHdl
def gmx_expanded_ensemble_case_3_dHdl(): dataset = alchemtest.gmx.load_expanded_ensemble_case_3() dHdl = alchemlyb.concat([gmx.extract_dHdl(filename, T=300, filter=False) for filename in dataset['data']['AllStates']]) return dHdl
def gmx_benzene_vdw_dHdl(): dataset = alchemtest.gmx.load_benzene() dHdl = alchemlyb.concat([gmx.extract_dHdl(filename, T=300) for filename in dataset['data']['VDW']]) return dHdl
def gmx_water_particle_with_potential_energy(): dataset = alchemtest.gmx.load_water_particle_with_potential_energy() u_nk = alchemlyb.concat([gmx.extract_u_nk(filename, T=300) for filename in dataset['data']['AllStates']]) return u_nk
def gmx_benzene_coul_u_nk(): dataset = alchemtest.gmx.load_benzene() u_nk = alchemlyb.concat([gmx.extract_u_nk(filename, T=300) for filename in dataset['data']['Coulomb']]) return u_nk
def amber_bace_example_complex_vdw(): dataset = alchemtest.amber.load_bace_example() u_nk = alchemlyb.concat([ amber.extract_u_nk(filename, T=300) for filename in dataset['data']['complex']['vdw'] ]) return u_nk
def gmx_expanded_ensemble_case_3(): dataset = alchemtest.gmx.load_expanded_ensemble_case_3() u_nk = alchemlyb.concat([ gmx.extract_u_nk(filename, T=300) for filename in dataset['data']['AllStates'] ]) return u_nk
def test_plot_ti_dhdl(): '''Just test if the plot runs''' bz = load_benzene().data dHdl_coul = alchemlyb.concat( [extract_dHdl(xvg, T=300) for xvg in bz['Coulomb']]) ti_coul = TI() ti_coul.fit(dHdl_coul) ax = plot_ti_dhdl(ti_coul) assert isinstance(ax, matplotlib.axes.Axes) plt.close(ax.figure) fig, ax = plt.subplots(figsize=(8, 6)) assert isinstance(plot_ti_dhdl(ti_coul, ax=ax), matplotlib.axes.Axes) assert isinstance(plot_ti_dhdl(ti_coul, labels=['Coul']), matplotlib.axes.Axes) assert isinstance(plot_ti_dhdl(ti_coul, labels=['Coul'], colors=['r']), matplotlib.axes.Axes) plt.close(fig) dHdl_vdw = alchemlyb.concat( [extract_dHdl(xvg, T=300) for xvg in bz['VDW']]) ti_vdw = TI().fit(dHdl_vdw) ax = plot_ti_dhdl([ti_coul, ti_vdw]) assert isinstance(ax, matplotlib.axes.Axes) plt.close(ax.figure) ti_coul.dhdl = pd.DataFrame.from_dict({ 'fep': range(100) }, orient='index', columns=np.arange(100) / 100).T ti_coul.dhdl.attrs = dHdl_vdw.attrs ax = plot_ti_dhdl(ti_coul) assert isinstance(ax, matplotlib.axes.Axes) plt.close(ax.figure)
def test_plot_convergence(): 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_list[0]) / num_points * i) u_nk_coul = alchemlyb.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 = alchemlyb.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]) ax = plot_convergence(forward, forward_error, backward, backward_error) assert isinstance(ax, matplotlib.axes.Axes) plt.close(ax.figure)
def test_plot_mbar_omatrix(): '''Just test if the plot runs''' bz = load_benzene().data u_nk_coul = alchemlyb.concat( [extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]) mbar_coul = MBAR() mbar_coul.fit(u_nk_coul) assert isinstance(plot_mbar_overlap_matrix(mbar_coul.overlap_matrix), matplotlib.axes.Axes) assert isinstance( plot_mbar_overlap_matrix(mbar_coul.overlap_matrix, [ 1, ]), matplotlib.axes.Axes) # Bump up coverage overlap_maxtrix = mbar_coul.overlap_matrix overlap_maxtrix[0, 0] = 0.0025 overlap_maxtrix[-1, -1] = 0.9975 assert isinstance(plot_mbar_overlap_matrix(overlap_maxtrix), matplotlib.axes.Axes)
def test_sort_off(self, gmx_ABFE): unsorted = alchemlyb.concat([gmx_ABFE[-500:], gmx_ABFE[:500]]) with pytest.raises(KeyError): statistical_inefficiency(unsorted, unsorted.sum(axis=1), sort=False)
def test_concat_empty(): '''Test if empty raise the right error.''' with pytest.raises(ValueError): alchemlyb.concat([])
def test_failback_adaptive(self, n_uk_list): # The hybr will fail on this while adaptive will work mbar = AutoMBAR().fit( alchemlyb.concat([n_uk[:2] for n_uk in n_uk_list])) assert np.isclose(mbar.d_delta_f_.iloc[0, -1], 1.76832, 0.1)
def dhdl(): data = load_ABFE()['data']['complex'] dhdl = alchemlyb.concat( [extract_dHdl(data[i], 300) for i in range(30)]) return dhdl
def dhdl(): bz = load_benzene().data dHdl_coul = alchemlyb.concat( [extract_dHdl(xvg, T=300) for xvg in bz['Coulomb']]) return dHdl_coul
def gmx_benzene_u_nk_full(): dataset = alchemtest.gmx.load_benzene() return alchemlyb.concat([gmx.extract_u_nk(i, T=300) for i in dataset['data']['Coulomb']])
def test_duplication_on_series_noseries(self, gmx_ABFE): duplicated = alchemlyb.concat([gmx_ABFE, gmx_ABFE]) subsample = statistical_inefficiency(duplicated.sum(axis=1), None, drop_duplicates=True) assert len(subsample) == 1001
def test_duplication_on_dataframe(self, gmx_ABFE): duplicated = alchemlyb.concat([gmx_ABFE, gmx_ABFE]) subsample = statistical_inefficiency(duplicated, duplicated.sum(axis=1), drop_duplicates=True) assert len(subsample) < 1000
def test_duplication_off(self, gmx_ABFE): duplicated = alchemlyb.concat([gmx_ABFE, gmx_ABFE]) with pytest.raises(KeyError): statistical_inefficiency(duplicated, duplicated.sum(axis=1), drop_duplicates=False)
def test_sort_on_noseries(self, gmx_ABFE): unsorted = alchemlyb.concat([gmx_ABFE[-500:], gmx_ABFE[:500]]) subsample = statistical_inefficiency(unsorted, None, sort=True) assert subsample.reset_index(0)['time'].is_monotonic_increasing
def test_plot_dF_state(): '''Just test if the plot runs''' bz = load_benzene().data u_nk_coul = alchemlyb.concat( [extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']]) dHdl_coul = alchemlyb.concat( [extract_dHdl(xvg, T=300) for xvg in bz['Coulomb']]) u_nk_vdw = alchemlyb.concat( [extract_u_nk(xvg, T=300) for xvg in bz['VDW']]) dHdl_vdw = alchemlyb.concat( [extract_dHdl(xvg, T=300) for xvg in bz['VDW']]) ti_coul = TI().fit(dHdl_coul) ti_vdw = TI().fit(dHdl_vdw) bar_coul = BAR().fit(u_nk_coul) bar_vdw = BAR().fit(u_nk_vdw) mbar_coul = MBAR().fit(u_nk_coul) mbar_vdw = MBAR().fit(u_nk_vdw) dhdl_data = [ (ti_coul, ti_vdw), (bar_coul, bar_vdw), (mbar_coul, mbar_vdw), ] fig = plot_dF_state(dhdl_data, orientation='portrait') assert isinstance(fig, matplotlib.figure.Figure) plt.close(fig) fig = plot_dF_state(dhdl_data, orientation='landscape') assert isinstance(fig, matplotlib.figure.Figure) plt.close(fig) fig = plot_dF_state(dhdl_data, labels=['MBAR', 'TI', 'BAR']) assert isinstance(fig, matplotlib.figure.Figure) plt.close(fig) with pytest.raises(ValueError): fig = plot_dF_state(dhdl_data, labels=[ 'MBAR', 'TI', ]) fig = plot_dF_state(dhdl_data, colors=['#C45AEC', '#33CC33', '#F87431']) assert isinstance(fig, matplotlib.figure.Figure) plt.close(fig) with pytest.raises(ValueError): fig = plot_dF_state(dhdl_data, colors=['#C45AEC', '#33CC33']) with pytest.raises(ValueError): fig = plot_dF_state(dhdl_data, orientation='xxx') fig = plot_dF_state(ti_coul, orientation='landscape') assert isinstance(fig, matplotlib.figure.Figure) plt.close(fig) fig = plot_dF_state(ti_coul, orientation='portrait') assert isinstance(fig, matplotlib.figure.Figure) plt.close(fig) fig = plot_dF_state([ti_coul, bar_coul]) assert isinstance(fig, matplotlib.figure.Figure) plt.close(fig) fig = plot_dF_state([(ti_coul, ti_vdw)]) assert isinstance(fig, matplotlib.figure.Figure) plt.close(fig)