def wham(dim,
         react_paths,
         first_num_imgs,
         num_cycles,
         num_bins,
         wham_conv,
         btstrap=0,
         read_Fx="",
         read_Ubiasl=""):

    global KbT

    # The initial string and final string
    first_i = 1
    first_t = first_num_imgs

    #############################READ THE DATA FILES###########################

    # All of the following list has dimension of iteration * images
    res_crdl = []
    res_forcel = []
    datal = []

    for i in range(1, num_cycles + 1):
        window_dir = './' + str(i) + '/'
        res_crdf = window_dir + 'newconstr.' + str(i) + '.dat'
        res_crd = read_dat_file(res_crdf)
        res_forcef = window_dir + 'force.' + str(i) + '.dat'
        res_force = read_dat_file(res_forcef)
        n1 = len(res_crd)
        n2 = len(res_force)
        if n1 == n2:
            res_crdl = res_crdl + res_crd
            res_forcel = res_forcel + res_force
            for j in range(1, n1 + 1):
                datf = window_dir + 'distperframe' + str(j) + '.dat'
                data = read_dat_file(datf)
                datal.append(data)
        else:
            raise ValueError(
                'The number of distances (%d) and (%d) force constants are '
                'not the same in the step %d!' % (n1, n2, i))

    # Define the final string
    last_num_imgs = n1
    final_t = len(datal)
    final_i = final_t - last_num_imgs + 1
    string_seq = [first_i, first_t, final_i, final_t]

    # Check the three lists are consistent
    if len(res_crdl) == len(res_forcel):
        if len(res_crdl) == len(datal):
            num_sims = len(res_crdl)
        else:
            raise ValueError(
                'The numbers of equlibrium distances and windows are not consistent!'
            )
    else:
        raise ValueError(
            'The number of equlibrium distances and force constants are not consistent!'
        )

    # Apply the fake bootstrapping
    if btstrap == 1:
        datal2 = datal
        seed()  # Initialize the random generator
        for i in xrange(num_sims):
            for j in xrange(len(datal[i])):
                k = randint(0, len(datal[i]) - 1)
                datal2[i][j] = datal[i][k]
        datal = datal2
        del datal2

    # Generate the data_dict, which contains all the data
    data_dict = {}
    for i in range(0, num_sims):
        window_datai = window_data(res_crdl[i], res_forcel[i], datal[i], dim)
        data_dict[i + 1] = window_datai

    #Plot the first and last string
    plot_string_1D(first_num_imgs, dim, data_dict, first_i, first_t,
                   react_paths, 'First_string.pdf')
    plot_string_1D(last_num_imgs, dim, data_dict, final_i, final_t,
                   react_paths, 'Last_string.pdf')

    #############################THE WHAM CODE#################################
    #Get the biased potentials

    if read_Ubiasl == "":
        Ubiasl = get_Ubiasl(data_dict, num_sims, dim)
    else:
        Ubiasl = read_list(read_Ubiasl, 1)

    if read_Fx == "":
        expFx = wham_iter(num_sims, wham_conv, data_dict, Ubiasl)
    else:
        Fx = read_dat_file(read_Fx)
        Fx = Fx[0]
        Fx0 = Fx[0]  #Normalize the Fx values
        Fx = [Fx[i] - Fx0 for i in xrange(num_sims)]
        expFx = [exp(i / KbT) for i in Fx]

    # RETURN THE DATA FOR FOLLOWING CALCULATIONS
    return data_dict, num_sims, string_seq, expFx, Ubiasl
def cal_kR_bspline(R, rdatf, outf, mass, kb, T, coeff, umax, vmax, npots):

    # mass is in the unit of electron mass
    Rt, dG0, V_el, lamb = coeff

    # Generate a potential plot for target R (Rt)
    Rpl = read_list(rdatf, 1)
    P1l = read_list(rdatf, 2)
    P2l = read_list(rdatf, 3)

    #datf = outf + '_shift.dat' # The file used for data
    #with open(datf, 'w') as f:
    #    for i in xrange(0, len(P1l)):
    #        print('%13.7f %13.7f %13.7f' %(Rpl[i], P1l[i], P2l[i]), file=f)

    # Shift to zero potential
    minP1l = min(P1l)
    P1l = [i - minP1l for i in P1l]
    minP2l = min(P2l)
    P2l = [i - minP2l for i in P2l]

    Rpl1 = [(Rp - (Rt - R) / 2.0) for Rp in Rpl]
    Rpl2 = [(Rp + (Rt - R) / 2.0) for Rp in Rpl]

    Rpl1_min = Rpl1[P1l.index(min(P1l))]
    Rpl2_min = Rpl2[P2l.index(min(P2l))]

    if Rpl2_min >= Rpl1_min:
        minval = Rpl1_min - 0.5
        maxval = Rpl2_min + 0.5
    else:
        minval = Rpl2_min - 0.8
        maxval = Rpl1_min + 0.8

    #minval = min(Rpl1)
    #maxval = max(Rpl2)

    lin_points = 128
    Rpl_new = linspace(minval, maxval, lin_points)

    # Cubic spline
    f1 = CubicSpline(Rpl1, P1l, extrapolate=True)
    f2 = CubicSpline(Rpl2, P2l, extrapolate=True)

    # Linear interpolation/extrapolation
    #f1 = interp1d(Rpl1, P1l, kind='linear', fill_value='extrapolate')
    #f2 = interp1d(Rpl2, P2l, kind='linear', fill_value='extrapolate')

    P1_fit = [f1(i) for i in Rpl_new]
    P2_fit = [f2(i) for i in Rpl_new]

    # Polynomial fitting
    #pcoef1 = polyfit(Rpl1, P1l, 5)
    #pcoef2 = polyfit(Rpl2, P2l, 5)

    #P1_fit = [polyval(pcoef1, i) for i in Rpl_new]
    #P2_fit = [polyval(pcoef2, i) for i in Rpl_new]

    au2kcal = 627.5095

    datf = outf + '.dat'  # The file used for data
    with open(datf, 'w') as f:
        for i in xrange(0, lin_points):
            print('%13.7f %13.7f %13.7f' %
                  (Rpl_new[i], P1_fit[i] / au2kcal, P2_fit[i] / au2kcal),
                  file=f)

    #mass = 1836.1526675 # Value from Alexander

    smax = max([umax + 1, vmax + 1])
    system(
        '/share/apps/bspline/bin/fgh_bspline.bin %s %d %13.7f %d > /dev/null '
        % (datf, npots, mass, smax))

    overlapf = outf + '_overlaps.dat'
    overlap = read_2d_free_energy(overlapf)

    print(overlap)

    reac_enef = outf + '_reactant_en.dat'
    Eu_list = read_2d_free_energy(reac_enef)
    Eu_list = Eu_list[0]

    print(Eu_list)

    prod_enef = outf + '_product_en.dat'
    Ev_list = read_2d_free_energy(prod_enef)
    Ev_list = Ev_list[0]

    print(Ev_list)

    # Clean the file
    #system("rm %s_*.dat" %outf)

    #
    # Calculate the k at certain R
    #

    # Normalize the probabilities
    Pu = norm_prob(Eu_list, kb, T)
    k_R = 0.0

    for u in xrange(0, umax + 1):
        for v in xrange(0, vmax + 1):
            Eu = Eu_list[u]
            Ev = Ev_list[v]
            Suv = overlap[u][v]
            #print(Suv)

            c = (kcal2j / avg_cons) * (1.0 / hbar)
            Prefac = c * (V_el**2 / hbar) * sqrt(pi /
                                                 (lamb * kb * T))  #*10^11 s^-1
            dGuv = (
                (dG0 + lamb + Ev - Eu)**2) / (4.0 * lamb * kb * T)  #unitless
            kuv_R = Prefac * (Suv**2) * exp(-dGuv)  #unit 10^11 s^-1
            kuv_R = kuv_R * (10.0**11)  #unit s^-1
            k_R += Pu[u] * kuv_R

    return k_R
    """"
Esempio n. 3
0
                  help="Wavefunction: ms, ho, or bs")
parser.add_option("--t1",
                  dest="tfname1",
                  type='string',
                  help="File containig 1000/T and Hrate")
parser.add_option("--t2",
                  dest="tfname2",
                  type='string',
                  help="File containig 1000/T and KIE")
(options, args) = parser.parse_args()

###############################################################################
#                                    Constants
###############################################################################

T_list1 = read_list(options.tfname1, 1)
kh_list = read_list(options.tfname1, 2)

T_list2 = read_list(options.tfname2, 1)
kd_list = read_list(options.tfname2, 2)
KIE_list = read_list(options.tfname2, 3)

#WT_HT_list = [3.5971, 3.5336, 3.4722, 3.4130, 3.3557, 3.3003, 3.2468, 3.1949, 3.1447, 3.0960]
#WT_Hrate_list = [213.35, 228.94, 269.96, 275.10, 327.19, 297.11, 329.06, 301.77, 348.08, 327.51]

#WT_HT_list = [3.5971, 3.5336, 3.4722, 3.3557, 3.3003, 3.2468, 3.1949, 3.1447]
#WT_Hrate_list = [213.35, 228.94, 269.96, 327.19, 297.11, 329.06, 301.77, 348.08]

#WT_DT_list = [3.5971, 3.5336, 3.4722, 3.3557, 3.3003, 3.2468, 3.1949, 3.1447]
#WT_Drate_list = [2.161, 2.4767, 2.9864, 4.2919, 3.6822, 5.023, 4.2442, 4.0017]
#WT_KIE_list = [WT_Hrate_list[i]/WT_Drate_list[i] for i in xrange(len(WT_Hrate_list))]
Esempio n. 4
0
SM_Hrate_list = [70.0, 58.0, 57.0, 54.0, 58.0, 63.0, 56.0, 61.0, 66.0]

SM_DT_list = [3.5317, 3.4704, 3.4112, 3.3540, 3.2987, 3.2452, 3.1934, 3.1432, 3.0945]
SM_Drate_list = [0.18, 0.20, 0.27, 0.3, 0.33, 0.36, 0.41, 0.38, 0.53]

SM_KIE_list = [SM_Hrate_list[i]/SM_Drate_list[i] for i in xrange(len(SM_Hrate_list))]

temp2fit = 4 # 1000.0 / 3.2987 = 303 K

###############################################################################
#                                  Main program
###############################################################################
#
# Read the W(R) list
#
R_list = read_list(options.r1fef, 1)
dR = R_list[1] - R_list[0]
WR_list = read_list(options.r1fef, 2)
para_list = read_para_file(options.pfile)
umax = 3
vmax = 3
Qm1 = 1.0

#
# Get the parition function parameter
#
T = 1000.0 / SM_HT_list[temp2fit]
k_h, k_d = get_ks(options.cmode, kb, T, R_list, WR_list, para_list, umax, vmax, hmass, dmass, Qm1, 1)
Qm1 = SM_Hrate_list[temp2fit] / k_h

# Get the lowest temperature
parser.add_option("-d", dest="dim", type='int',
                  help="Topology file name")
(options, args) = parser.parse_args()

name_list = []
r_inputf = open(options.inputf, 'r')
for rline in r_inputf:
    line = rline.strip('\n')
    line = line.strip(' ')
    name_list.append(line)
r_inputf.close()

if options.dim == 1:
    data_super_list = []
    for name in name_list:
        data_list = read_list(name, 1)
        data_super_list.append(data_list)

    data_super_list = array(data_super_list)
    avg_data_list = mean(data_super_list, axis=0)
    std_data_list = std(data_super_list, axis=0)

    # Print out the free energy profile and errorbars
    write_xy_lists(options.outputf, avg_data_list, std_data_list)

    # Plot the free energy profile with error bar
    x_list = xrange(1, len(data_list)+1)
    plt.errorbar(x_list, avg_data_list, yerr=std_data_list, linewidth=2.0)
    plt.axes().xaxis.get_major_locator().set_params(nbins=5)
    plt.axes().yaxis.get_major_locator().set_params(nbins=5)
    plt.axes().tick_params(axis='x', which='minor', length=2)