コード例 #1
0
def get_calculation_values(type_dic):
    ti = copy.deepcopy(type_dic)
    #mbar=copy.deepcopy(type_dic)
    ti_function = TI()
    #mbar_function = MBAR()
    for ef_key in type_dic.keys():
        print(ef_key)
        ef_value = type_dic[ef_key]
        for ef_comp_sol_key in ef_value.keys():
            ef_comp_sol_value = ef_value[ef_comp_sol_key]
            for ef_cal_type_key in ef_comp_sol_value.keys():
                ef_cal_type_value = ef_comp_sol_value[ef_cal_type_key]
                ti_values = pd.concat(
                    [amber.extract_dHdl(ti) for ti in ef_cal_type_value])
                ti_function.fit(ti_values)
                ti[ef_key][ef_comp_sol_key][
                    ef_cal_type_key] = ti_function.delta_f_.loc[0.00, 0.50]
                #print (ef_key,ef_comp_sol_key,ef_cal_type_key,ti_function.delta_f_, ti_function.d_delta_f_)
                #mbar_values = pd.concat([amber.extract_u_nk(ti) for ti in ef_cal_type_value])
                #print (mbar_values)
                #print (ti_values)
                #mbar_function.fit(mbar_values)
                #print (mbar_values)
                #print (mbar_function.delta_f_)
                #print (ef_key,ef_comp_sol_key,ef_cal_type_key,mbar_function.delta_f_.loc[0.00, 0.50])
                #mbar[ef_key][ef_comp_sol_value][ef_cal_type_key] = mbar_function.delta_f_.loc[0.00, 0.50]
    return ti
コード例 #2
0
def test_TI_separate_dhdl_single_column():
    dHdl = gmx_benzene_coul_dHdl()
    estimator = TI().fit(dHdl)
    assert all(
        [isinstance(dhdl, pd.Series) for dhdl in estimator.separate_dhdl()])
    assert [len(dhdl) for dhdl in estimator.separate_dhdl()] == [
        5,
    ]
コード例 #3
0
def test_TI_separate_dhdl_no_pertubed():
    '''The test for the case where two lambda are there and one is not pertubed'''
    dHdl = gmx_benzene_coul_dHdl()
    dHdl.insert(1, 'bound-lambda', [1.0, ] * len(dHdl))
    dHdl.insert(1, 'bound', [1.0, ] * len(dHdl))
    dHdl.set_index('bound-lambda', append=True, inplace=True)
    estimator = TI().fit(dHdl)
    assert all([isinstance(dhdl, pd.Series) for dhdl in estimator.separate_dhdl()])
    assert [len(dhdl) for dhdl in estimator.separate_dhdl()] == [5, ]
コード例 #4
0
def free_energy_calculation(dHdl, u_nk):
    logger("Fitting TI on dHdl ...")
    ti = TI().fit(dHdl)

    logger("Fitting BAR on u_nk ...")
    bar = BAR().fit(u_nk)

    logger("Fitting MBAR on u_nk ...\n")
    try:
        mbar_stop = False
        mbar = MBAR().fit(u_nk)
    except pymbar.utils.ParameterError:
        mbar_stop = True
        logger(
            "\sum_n W_nk is not equal to 1, probably due to insufficient overlap between states."
        )
        logger("Stop using MBAR ...")

    logger("------ Results based on the whole dataset ------")
    if hasattr(dHdl, 'statineff') is True:
        logger(f'Statistical inefficiency of dHdl: {dHdl.statineff}')
    if hasattr(u_nk, 'statineff') is True:
        logger(f'Statistical inefficiency of u_nk: {u_nk.statineff}\n')
    logger(f"TI: {ti.delta_f_.iloc[0, -1]} +/- {ti.d_delta_f_.iloc[0, -1]} kT")
    logger(f"BAR: {bar.delta_f_.iloc[0, -1]} +/- unknown kT")
    if mbar_stop is False:
        logger(
            f"MBAR: {mbar.delta_f_.iloc[0, -1]} +/- {mbar.d_delta_f_.iloc[0, -1]} kT"
        )
        logger("------------------------------------------------")
        return ti, bar, mbar
    else:
        logger("------------------------------------------------")
        return ti, bar
コード例 #5
0
 def test_ti(self, dhdl):
     ti = TI().fit(dhdl)
     assert ti.delta_f_.attrs['temperature'] == 300
     assert ti.delta_f_.attrs['energy_unit'] == 'kT'
     assert ti.d_delta_f_.attrs['temperature'] == 300
     assert ti.d_delta_f_.attrs['energy_unit'] == 'kT'
     assert ti.dhdl.attrs['temperature'] == 300
     assert ti.dhdl.attrs['energy_unit'] == 'kT'
コード例 #6
0
def test_plot_dF_state():
    '''Just test if the plot runs'''
    bz = load_benzene().data
    u_nk_coul = pd.concat([extract_u_nk(xvg, T=300) for xvg in bz['Coulomb']])
    dHdl_coul = pd.concat([extract_dHdl(xvg, T=300) for xvg in bz['Coulomb']])
    u_nk_vdw = pd.concat([extract_u_nk(xvg, T=300) for xvg in bz['VDW']])
    dHdl_vdw = pd.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)
    fig = plot_dF_state(dhdl_data, orientation='landscape')
    assert isinstance(fig, matplotlib.figure.Figure)
    fig = plot_dF_state(dhdl_data, labels=['MBAR', 'TI', 'BAR'])
    assert isinstance(fig, matplotlib.figure.Figure)
    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)
    with pytest.raises(ValueError):
        fig = plot_dF_state(dhdl_data, colors=['#C45AEC', '#33CC33'])
    with pytest.raises(NameError):
        fig = plot_dF_state(dhdl_data, orientation='xxx')
    fig = plot_dF_state(ti_coul, orientation='landscape')
    assert isinstance(fig, matplotlib.figure.Figure)
    fig = plot_dF_state(ti_coul, orientation='portrait')
    assert isinstance(fig, matplotlib.figure.Figure)
    fig = plot_dF_state([ti_coul, bar_coul])
    assert isinstance(fig, matplotlib.figure.Figure)
    fig = plot_dF_state([(ti_coul, ti_vdw)])
    assert isinstance(fig, matplotlib.figure.Figure)
コード例 #7
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
コード例 #8
0
def test_plot_ti_dhdl():
    '''Just test if the plot runs'''
    bz = load_benzene().data
    dHdl_coul = pd.concat([extract_dHdl(xvg, T=300) for xvg in bz['Coulomb']])
    ti_coul = TI()
    ti_coul.fit(dHdl_coul)
    assert isinstance(plot_ti_dhdl(ti_coul), matplotlib.axes.Axes)
    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)
    dHdl_vdw = pd.concat([extract_dHdl(xvg, T=300) for xvg in bz['VDW']])
    ti_vdw = TI().fit(dHdl_vdw)
    assert isinstance(plot_ti_dhdl([ti_coul, ti_vdw]), matplotlib.axes.Axes)
    ti_coul.dhdl = pd.DataFrame.from_dict({
        'fep': range(100)
    },
                                          orient='index',
                                          columns=np.arange(100) / 100).T
    assert isinstance(plot_ti_dhdl(ti_coul), matplotlib.axes.Axes)
コード例 #9
0
    mbars = []
    bars = []
    for nr in range(NREP):
        #read the free energy files 
        data_loc = bd + "/" + com +"/TI_"+str(nr+1)+"/state_"
        files = []
        for i in range(numFile + 1):
            freeEn_file = fname + str(i) + ext
            file_path = data_loc + str(i) + "/" + freeEn_file
            print("%4s: Reading File: %s " % (com, file_path))
            files.append(file_path)

        #for TI estimator
        #print("Working on TI method ...")
        dHdl = pd.concat([extract_dHdl(f, T=temprature) for f in files])
        ti = TI().fit(dHdl)
        sum_ti, sum_ds_ti = get_delta(ti)
        tis.append(sum_ti)


        #for MBAR estimator
        #print("Working on MBAR method ...")
        u_nk = pd.concat([extract_u_nk(f, T=temprature) for f in files])
        mbar = MBAR().fit(u_nk)
        sum_mbar, sum_ds_mbar = get_delta(mbar)
        mbars.append(sum_mbar)
        
        
        #for BAR estimator
        #print("Working on BAR method ...")
        bar = BAR().fit(u_nk)
コード例 #10
0
 def test_ti_separate_dhdl(self, dhdl):
     ti = TI().fit(dhdl)
     dhdl_list = ti.separate_dhdl()
     for dhdl in dhdl_list:
         assert dhdl.attrs['temperature'] == 300
         assert dhdl.attrs['energy_unit'] == 'kT'
コード例 #11
0
def test_TI_separate_dhdl_multiple_column():
    dHdl = gomc_benzene_dHdl()
    estimator = TI().fit(dHdl)
    assert all(
        [isinstance(dhdl, pd.Series) for dhdl in estimator.separate_dhdl()])
    assert sorted([len(dhdl) for dhdl in estimator.separate_dhdl()]) == [8, 16]
コード例 #12
0
def get_TI(dHdl):
    ti = TI().fit(dHdl)
    df = pd.DataFrame({'DG': k_b * T * ti.delta_f_.values[0,-1:], 
                       'std': k_b * T * ti.d_delta_f_.values[0,-1:]},
                      columns=['DG', 'std'])
    return df
コード例 #13
0
            #Detect uncorrelated samples using VDW+Coulomb term in derivative
            # of energy time series (calculated for TI)
            srs = dHdl['VDW'] + dHdl['Coulomb']
            list_data_TI.append(
                ss.statistical_inefficiency(dHdl,
                                            series=srs,
                                            conservative=False))
            list_data_BAR.append(
                ss.statistical_inefficiency(u_nkr,
                                            series=srs,
                                            conservative=False))

        #for TI estimator
        #print("Working on TI method ...")
        dhdl = pd.concat([ld for ld in list_data_TI])
        ti = TI().fit(dhdl)
        sum_ti, sum_ds_ti = get_delta(ti)
        tis.append(sum_ti)

        #for MBAR estimator
        #print("Working on MBAR method ...")
        u_nk = pd.concat([ld for ld in list_data_BAR])
        mbar = MBAR().fit(u_nk)
        sum_mbar, sum_ds_mbar = get_delta(mbar)
        mbars.append(sum_mbar)

        #for BAR estimator
        #print("Working on BAR method ...")
        u_nk = pd.concat([ld for ld in list_data_BAR])
        bar = BAR().fit(u_nk)
        sum_bar, sum_ds_bar = get_delta2(bar)