Beispiel #1
0
def gene_free_ene_2D(data_dict, num_sims, dim, Fx_old, rc_diml1, coefl1,
                     rc_diml2, coefl2, num_bins1, num_bins2, figname, xlabel1,
                     xlabel2, string_seq, colmap):

    global KbT

    data_RC1, bins_RC1, xaxis_RC1 = get_rc_data_1D(data_dict, num_sims,
                                                   rc_diml1, coefl1, num_bins1)
    data_RC2, bins_RC2, xaxis_RC2 = get_rc_data_1D(data_dict, num_sims,
                                                   rc_diml2, coefl2, num_bins2)

    # Generate the free energy for each bin
    Prob_RC12 = [[0.0 for i in xrange(num_bins2)] for j in xrange(num_bins1)]

    count = 0
    for i in xrange(0, num_sims):
        data_per_sim = len(data_dict[i + 1].data)
        for j in xrange(0, data_per_sim):
            # For the first dimension
            each_data_RC1 = data_RC1[count]
            each_count_RC1, bins_RCp1 = histogram(each_data_RC1, bins=bins_RC1)
            count_indx1 = list(each_count_RC1).index(1)
            # For the second dimension
            each_data_RC2 = data_RC2[count]
            each_count_RC2, bins_RCp2 = histogram(each_data_RC2, bins=bins_RC2)
            count_indx2 = list(each_count_RC2).index(1)

            #Unbias the free energy
            Ubias = [0.0 for zero_val in xrange(num_sims)]
            for k in xrange(num_sims):
                for ii in xrange(0, dim):
                    equ_dis = data_dict[k + 1].equ_dis[ii]
                    constr = data_dict[k + 1].constr[ii]
                    samp_dis = data_dict[i + 1].data[j, ii]
                    Ubias[k] = Ubias[k] + 0.5 * constr * (samp_dis -
                                                          equ_dis)**2

            denom = 0.0
            for l in xrange(num_sims):
                data_per_sim2 = len(data_dict[l + 1].data)
                denom = denom + data_per_sim2 * exp(
                    (Fx_old[l] - Ubias[l]) / KbT)

            Prob_RC12[count_indx1][count_indx2] = Prob_RC12[count_indx1][
                count_indx2] + 1.0 / denom
            count = count + 1

    ini_crd = get_string_2D(data_dict, string_seq[0], string_seq[1], rc_diml1,
                            coefl1, rc_diml2, coefl2, figname + '.inistr')
    fin_crd = get_string_2D(data_dict, string_seq[2], string_seq[3], rc_diml1,
                            coefl1, rc_diml2, coefl2, figname + '.laststr')
    plot_free_ene_2D(num_bins1, num_bins2, xaxis_RC1, xaxis_RC2, Prob_RC12,
                     figname, xlabel1, xlabel2, colmap, ini_crd, fin_crd)
def gene_free_ene_2D(data_dict, num_sims, dim, expFx, Ubiasl, rc_diml1, coefl1,
                     rc_diml2, coefl2, num_bins1, num_bins2, figname, xlabel1,
                     xlabel2, string_seq, colmap):

    data_RC1, bins_RC1, xaxis_RC1 = get_rc_data_1D(data_dict, num_sims,
                                                   rc_diml1, coefl1, num_bins1)
    data_RC2, bins_RC2, xaxis_RC2 = get_rc_data_1D(data_dict, num_sims,
                                                   rc_diml2, coefl2, num_bins2)

    # Generate the free energy for each bin
    Prob_RC12 = [[0.0 for i in xrange(num_bins2)] for j in xrange(num_bins1)]

    count = 0
    kk = 0
    for i in xrange(0, num_sims):
        data_per_sim = len(data_dict[i + 1].data)
        for l in xrange(0, data_per_sim):

            # For the first dimension
            each_data_RC1 = data_RC1[count]
            each_count_RC1, bins_RCp1 = histogram(each_data_RC1, bins=bins_RC1)
            count_indx1 = list(each_count_RC1).index(1)
            # For the second dimension
            each_data_RC2 = data_RC2[count]
            each_count_RC2, bins_RCp2 = histogram(each_data_RC2, bins=bins_RC2)
            count_indx2 = list(each_count_RC2).index(1)

            #Get the biased potentials
            Ubiasl_j = []
            for j in xrange(num_sims):
                Ubiasl_j.append(Ubiasl[kk])
                kk = kk + 1

            denom = 0.0
            for k in xrange(num_sims):
                data_per_sim2 = len(data_dict[k + 1].data)
                denom = denom + float(data_per_sim2) * Ubiasl_j[k] * expFx[k]

            Prob_RC12[count_indx1][count_indx2] = Prob_RC12[count_indx1][
                count_indx2] + 1.0 / denom
            count = count + 1

    ini_crd = get_string_2D(data_dict, string_seq[0], string_seq[1], rc_diml1,
                            coefl1, rc_diml2, coefl2, figname + '.inistr')
    fin_crd = get_string_2D(data_dict, string_seq[2], string_seq[3], rc_diml1,
                            coefl1, rc_diml2, coefl2, figname + '.laststr')
    plot_free_ene_2D(num_bins1, num_bins2, xaxis_RC1, xaxis_RC2, Prob_RC12,
                     figname, xlabel1, xlabel2, colmap, ini_crd, fin_crd)
Beispiel #3
0
def gene_free_ene_1D(data_dict, num_sims, dim, Fx_old, rc_diml, coefl,
                     num_bins, figname, rc_label):

    global KbT

    data_RC, bins_RC, xaxis_RC = get_rc_data_1D(data_dict, num_sims, rc_diml,
                                                coefl, num_bins)

    # Generate the free energy for each bin
    Prob_RC = [0.0 for i in xrange(num_bins)]

    count = 0
    for i in xrange(0, num_sims):
        data_per_sim = len(data_dict[i + 1].data)
        for j in xrange(0, data_per_sim):
            each_data_RC = data_RC[count]
            each_count_RC, bins_RCp = histogram(each_data_RC, bins=bins_RC)
            count_indx = list(each_count_RC).index(1)

            #Unbias the free energy
            Ubias = [0.0 for zero_val in xrange(num_sims)]
            for k in xrange(num_sims):
                for ii in xrange(0, dim):
                    equ_dis = data_dict[k + 1].equ_dis[ii]
                    constr = data_dict[k + 1].constr[ii]
                    samp_dis = data_dict[i + 1].data[j, ii]
                    Ubias[k] = Ubias[k] + 0.5 * constr * (samp_dis -
                                                          equ_dis)**2

            denom = 0.0
            for l in xrange(num_sims):
                data_per_sim2 = len(data_dict[l + 1].data)
                denom = denom + data_per_sim2 * exp(
                    (Fx_old[l] - Ubias[l]) / KbT)

            Prob_RC[count_indx] = Prob_RC[count_indx] + 1.0 / denom
            count = count + 1

    plot_free_ene_1D(num_bins, Prob_RC, xaxis_RC, figname, rc_label)
def gene_free_ene_1D(data_dict, num_sims, dim, expFx, Ubiasl, rc_diml, coefl,
                     num_bins, figname, rc_label):
    """The part is from eqs 10 and 11 in the WHAM paper"""

    data_RC, bins_RC, xaxis_RC = get_rc_data_1D(data_dict, num_sims, rc_diml,
                                                coefl, num_bins)
    # Generate the free energy for each bin
    Prob_RC = [0.0 for i in xrange(num_bins)]

    count = 0
    kk = 0
    for i in xrange(0, num_sims):  #Sum over big N for i
        data_per_sim = len(data_dict[i + 1].data)
        for l in xrange(0, data_per_sim):  #Sum over little n for l

            #Calculate the probability for each point
            each_data_RC = data_RC[count]
            each_count_RC, bins_RCp = histogram(each_data_RC, bins=bins_RC)
            count_indx = list(each_count_RC).index(1)

            #Get the biased potentials
            Ubiasl_j = []
            for j in xrange(num_sims):
                Ubiasl_j.append(Ubiasl[kk])
                kk = kk + 1

            #Obtain the denominator
            denom = 0.0
            for k in xrange(num_sims):
                data_per_sim2 = len(data_dict[k + 1].data)
                denom = denom + float(data_per_sim2) * Ubiasl_j[k] * expFx[k]

            Prob_RC[count_indx] = Prob_RC[count_indx] + 1.0 / denom
            count = count + 1

    plot_free_ene_1D(num_bins, Prob_RC, xaxis_RC, figname, rc_label)
def gene_free_ene_2D(data_dict, num_sims, dim, expFx, Ubiasl, rc_diml1, coefl1,
                     rc_diml2, coefl2, num_bins1, num_bins2, figname, xlabel1, xlabel2,
                     string_seq, colmap, avg=0, tot_ene=[], ene1=[]):

    data_RC1, bins_RC1, xaxis_RC1 = get_rc_data_1D(data_dict, num_sims, rc_diml1, coefl1, num_bins1)
    data_RC2, bins_RC2, xaxis_RC2 = get_rc_data_1D(data_dict, num_sims, rc_diml2, coefl2, num_bins2)

    if avg == 0: # No average to calculate
        pass
    elif avg == 1: # Only average to calculate
        if tot_ene == []:
            raise ValueError('No value list provided to calculate the average value!')
        elif tot_ene != []:
            data_list = tot_ene
            if ene1 != []:
                raise ValueError('Provide two list values to calculate the average '
                                 'value, only one list is needed!')
    elif avg == 2: # About the free energy partitioning
        if tot_ene != [] and ene1 != []:
            if len(tot_ene) == len(ene1):
                #Calculate the exp[beta*(U(ri)-U'(ri))]
                ene2 = [tot_ene[i]-ene1[i] for i in xrange(0, len(tot_ene))]
                ene2min = min(ene2)
                ene2 = [i-ene2min-300.0 for i in ene2]
                data_list = [exp(i/KbT) for i in ene2]
            else:
                raise ValueError('The length of total energy list and paritioning '
                                 'energy list are not the same!')
        elif tot_ene != []:
            raise ValueError('Only total energy list provided, you need to '
                             'provide paritioning energy list as well!')
        elif ene1 != []:
            raise ValueError('Only paritioning energy list provided, you need to '
                             'provide total energy list as well!')

    # Generate the free energy for each bin
    Prob_RC12_0 = [[0.0 for i in xrange(num_bins2)] for j in xrange(num_bins1)]
    Prob_RC12_1 = [[0.0 for i in xrange(num_bins2)] for j in xrange(num_bins1)]

    count = 0
    kk = 0
    for i in xrange(0, num_sims):
        data_per_sim = len(data_dict[i+1].data)
        for l in xrange(0, data_per_sim):

            # For the first dimension
            each_data_RC1 = data_RC1[count]
            each_count_RC1, bins_RCp1 = histogram(each_data_RC1, bins=bins_RC1)
            count_indx1 = list(each_count_RC1).index(1)
            # For the second dimension
            each_data_RC2 = data_RC2[count]
            each_count_RC2, bins_RCp2 = histogram(each_data_RC2, bins=bins_RC2)
            count_indx2 = list(each_count_RC2).index(1)

            #Get the biased potentials
            Ubiasl_j = []
            for j in xrange(num_sims):
                Ubiasl_j.append(Ubiasl[kk])
                kk = kk + 1

            denom = 0.0
            for k in xrange(num_sims):
                data_per_sim2 = len(data_dict[k+1].data)
                denom = denom + float(data_per_sim2) * Ubiasl_j[k] * expFx[k]

            Prob_RC12_0[count_indx1][count_indx2] = Prob_RC12_0[count_indx1][count_indx2] + 1.0/denom
            Prob_RC12_1[count_indx1][count_indx2] = Prob_RC12_1[count_indx1][count_indx2] + data_list[count]/denom         
            count = count + 1

    ini_crd = get_string_2D(data_dict, string_seq[0], string_seq[1], rc_diml1, coefl1, rc_diml2, coefl2, figname + '.inistr')
    fin_crd = get_string_2D(data_dict, string_seq[2], string_seq[3], rc_diml1, coefl1, rc_diml2, coefl2, figname + '.laststr')

    if avg==0:
       plot_free_ene_2D(num_bins1, num_bins2, xaxis_RC1, xaxis_RC2, Prob_RC12_0, figname, xlabel1, xlabel2, colmap, ini_crd, fin_crd, 0)
    else:
       Prob_RC12_2 = [[0.0 for i in xrange(num_bins2)] for j in xrange(num_bins1)]
       for i in xrange(num_bins2):
           for j in xrange(num_bins1):
               if Prob_RC12_0[j][i] != 0:
                   Prob_RC12_2[j][i] = Prob_RC12_1[j][i]/Prob_RC12_0[j][i]
       plot_free_ene_2D(num_bins1, num_bins2, xaxis_RC1, xaxis_RC2, Prob_RC12_2, figname, xlabel1, xlabel2, colmap, ini_crd, fin_crd, avg)
def gene_free_ene_1D(data_dict, num_sims, dim, expFx, Ubiasl, rc_diml, coefl, num_bins, figname, rc_label, avg=0, tot_ene=[], ene1=[]):
    """The part is from eqs 10 and 11 in the WHAM paper"""

    data_RC, bins_RC, xaxis_RC = get_rc_data_1D(data_dict, num_sims, rc_diml, coefl, num_bins)

    if avg == 0: # No average to calculate
        pass
    elif avg == 1: # Only average to calculate
        if tot_ene == []:
            raise ValueError('No value list provided to calculate the average value!')
        elif tot_ene != []:
            data_list = tot_ene
            if ene1 != []:
                raise ValueError('Provide two list values to calculate the average '
                                 'value, only one list is needed!')
    elif avg == 2: # About the free energy partitioning
        if tot_ene != [] and ene1 != []:
            if len(tot_ene) == len(ene1):
                #Calculate the exp[beta*(U(ri)-U'(ri))]
                ene2 = [tot_ene[i]-ene1[i] for i in xrange(0, len(tot_ene))]
                ene2min = min(ene2)
                ene2 = [i-ene2min-300.0 for i in ene2]
                data_list = [exp(i/KbT) for i in ene2]
            else:
                raise ValueError('The length of total energy list and paritioning '
                                 'energy list are not the same!')
        elif tot_ene != []:
            raise ValueError('Only total energy list provided, you need to '
                             'provide paritioning energy list as well!')
        elif ene1 != []:
            raise ValueError('Only paritioning energy list provided, you need to '
                             'provide total energy list as well!')

    # Generate the free energy for each bin
    Prob_RC0 = [0.0 for i in xrange(num_bins)]
    Prob_RC1 = [0.0 for i in xrange(num_bins)]

    count = 0
    kk = 0
    for i in xrange(0, num_sims): #Sum over big N for i
        data_per_sim = len(data_dict[i+1].data)
        for l in xrange(0, data_per_sim): #Sum over little n for l

            #Calculate the probability for each point
            each_data_RC = data_RC[count]
            each_count_RC, bins_RCp = histogram(each_data_RC, bins=bins_RC)
            count_indx = list(each_count_RC).index(1)

            #Get the biased potentials
            Ubiasl_j = []
            for j in xrange(num_sims):
                Ubiasl_j.append(Ubiasl[kk])
                kk = kk + 1

            #Obtain the denominator
            denom = 0.0
            for k in xrange(num_sims):
                data_per_sim2 = len(data_dict[k+1].data)
                denom = denom + float(data_per_sim2) * Ubiasl_j[k] * expFx[k]

            Prob_RC0[count_indx] = Prob_RC0[count_indx] + 1.0/denom
            Prob_RC1[count_indx] = Prob_RC1[count_indx] + data_list[count]/denom
            count = count + 1

    if avg==0:
        plot_free_ene_1D(num_bins, Prob_RC0, xaxis_RC, figname, rc_label, 0)
    else:
        Prob_RC2 = [Prob_RC1[i]/Prob_RC0[i] for i in xrange(num_bins)]
        plot_free_ene_1D(num_bins, Prob_RC2, xaxis_RC, figname, rc_label, avg)