コード例 #1
0
ファイル: test_units.py プロジェクト: xiki-tempula/alchemlyb
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])
コード例 #2
0
    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
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
 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
コード例 #6
0
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
コード例 #7
0
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
コード例 #8
0
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
コード例 #9
0
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
コード例 #10
0
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
コード例 #11
0
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
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
0
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)
コード例 #15
0
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)
コード例 #16
0
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)
コード例 #17
0
 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)
コード例 #18
0
ファイル: test_units.py プロジェクト: xiki-tempula/alchemlyb
def test_concat_empty():
    '''Test if empty raise the right error.'''
    with pytest.raises(ValueError):
        alchemlyb.concat([])
コード例 #19
0
 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)
コード例 #20
0
 def dhdl():
     data = load_ABFE()['data']['complex']
     dhdl = alchemlyb.concat(
         [extract_dHdl(data[i], 300) for i in range(30)])
     return dhdl
コード例 #21
0
 def dhdl():
     bz = load_benzene().data
     dHdl_coul = alchemlyb.concat(
         [extract_dHdl(xvg, T=300) for xvg in bz['Coulomb']])
     return dHdl_coul
コード例 #22
0
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']])
コード例 #23
0
 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
コード例 #24
0
 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
コード例 #25
0
 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)
コード例 #26
0
 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
コード例 #27
0
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)