def get_ave_ste(p1f,p2f,tau_b):
    """input files are those containing changes of property1,
    property2 along the trajectory""" 
    timep1, p1 = xvg2array(p1f)
    timep2, p2 = xvg2array(p2f) # timep1 & timenp2 will not be used, just for assignment
    p1_list = [np.average(p1), block_average(p1,tau_b)]
    p2_list = [np.average(p2), block_average(p2,tau_b)]
    # p1_list & p2_list are lists containing [average of p1, standard error of p2]
    return p1_list, p2_list
Beispiel #2
0
def ax_ave(xyf, ax):
    xf, yf = xyf
    xp, yp = xvg2array(xf)[1], xvg2array(yf)[1]
    (ave_xp, std_xp, ave_yp, std_yp) = (
        np.average(xp), np.std(xp), np.average(yp), np.std(yp))
    tid = q_acc.get_id(xyf)
    sid = tid[:3]
    cid = tid[3]
    ax.errorbar(ave_xp, ave_yp, xerr=std_xp, yerr=std_yp,
                c=mysys[cid].col, marker=mysys[sid].char,
                label=mysys[sid].seq, markersize=10)
    # ax.text(p1[0]*1.01,p2[0]*1.01,p1_file[5:12])
    return tid, ave_xp, std_xp, ave_yp, std_yp
Beispiel #3
0
def quantify_ave_change(xf, yf, change):      # xf -> yf could be from water to methano
    t1 = re.compile('sq[0-9]')
    t2 = re.compile('g_rg|[uv][pn][uv][pn]?')
    xk1, yk1 = t1.search(xf).group(), t1.search(yf).group()
    xk2, yk2 = t2.search(xf).group(), t2.search(yf).group()
    assert xk1 == yk1, '{xk1} & {yk1} are different keys'.format(xk1=xk1, yk1=yk1)
    assert xk2 == yk2, '{xk2} & {yk2} are different keys'.format(xk2=xk2, yk2=yk2)
    k1, k2 = xk1, xk2

    xf_data, yf_data = xvg2array(xf)[1], xvg2array(yf)[1]
    
    (ave_xp, std_xp, ave_yp, std_yp) = (
        np.average(xf_data), np.std(xf_data), np.average(yf_data), np.std(yf_data))

    ave_change = (ave_yp-ave_xp) / ave_xp
    std_change = error_change(ave_xp, std_xp, ave_yp, std_yp)
    if not k1 in change.keys():
        change[k1] = {}
    change[k1][k2] = [ave_change, std_change]
    return change
Beispiel #4
0
def write_turns(turns,outputfile,xvgfile=None):
    """ input turn is a list in the order of frame number, data will be written
    in a xvg format"""
    if xvgfile:
        from xvg2png import xvg2array
        times = xvg2array(xvgfile)[0]
    else:
        times = range(turns) + 1                 # starting from 1,2,3,4,5,6....
    assert len(times) == len(turns), "the index of frames is not right"
    with open(outputfile,'w') as opf:
        for time, turn in zip(times, turns): # xvgfile is not specified, then times == turns.keys(), is the frame index
            opf.write("%-20g%-10g\n" % (time,turn))
Beispiel #5
0
def gen_nbs(infs,bins):         # nbs: collections of n and bins
    ns = {}                     # collection of n, containing the number of bins
    bs = {}                     # collection of bins
    ids = []
    for inf in infs:
        bi = inf.find('sq'); id = inf[bi:bi+4]; ids.append(id)
        y = xvg2array(inf)[1]
        print inf
        n, b = np.histogram(y,bins,normed=False) # if Normed=True, the results will be distribution density
        ns[id] = n / float(len(y))
        # normed by the total number of data points, so the plot result is probability
        # distribution function instead of distribution density
        bs[id] = b
    return ids, ns, bs
Beispiel #6
0
def inte_ste_data(infiles):
    """
    To store standard error data as in a nested list, also obtain the minmum
    and maximum of y, which will be used as the ylim
    """
    data_dict = {}
    ymines = []                          
    ymaxes = []                          # maxes are used to determine the y_lim
    for infile in infiles:
        data = xvg2array(infile)[1]
        x, y = prepare_ste_data(data,min_tau_b,max_tau_b,stride,sflag)
        data_dict[infile] = [x,y]
        ymines.append(min(y))
        ymaxes.append(max(y))
    return data_dict, min(ymines), max(ymaxes)
Beispiel #7
0
def ax_plot(inf, ax, legend, color, marker, berrorbar=False):
    """keys in kwargs could be: legend, title, color, marker"""
    label = legend
    if berrorbar:
        x, y, e = xvg2array_eb(inf)
        x = x/1000. if options.nm else x
        ax.errorbar(x, y, yerr=e, label=label)
    else:
        x, y = block_average(xvg2array(inf), n=1000)
        # x, y = xvg2array(inf)
        print x.shape, y.shape

        x = x/1000. if options.nm else x

        if color and marker:
            ax.plot(x, y, color=color, marker=marker, label=label) 
        elif color:
            ax.plot(x, y, color=color, label=label) 
        elif marker:
            ax.plot(x, y, marker=marker, label=label) 
        else:
            ax.plot(x, y, linewidth=1, label=label) 
            # p = ax.plot(x, y, "o-", label=label) 
    return x, y
Beispiel #8
0
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
from xvg2png import xvg2array

inf = '/home/zyxue/pyfiles/trial_block_ave.dat'
N = xvg2array(inf)[1]
print type(N), len(N)
len_N = len(N)

def ave_bi(bi, lb):
    assert len(bi) == lb, 'len(bi) = %d, lb = %d' % (len(bi), lb) 
    return np.average(bi)

# lbs = range(3, len_N / 2, 10)
# nbs = [ len_N / lb for lb in lbs ]                   # floor division

nbs = range(2, 5000, 100)
lbs = [ len_N / nb for nb in nbs ]

b_stds = []

for lb, nb in zip(lbs, nbs):
    b = lb
    sliced_data = N[0:(nb * lb + 1)]
    bs = [ sliced_data[i * b + 1 : i * b + b + 1] for i in range(0, nb) ] # all the blocks of data
    b_means = [ave_bi(bi, lb) for bi in bs ]                  # means of all the blocks
    assert len(b_means) == nb
    b_std = np.std(b_means)
    b_stds.append(b_std)
Beispiel #9
0
def integrate_cis_prob(data):
    min_dg, max_dg = -90, 90
    data = [d for d in data if max_dg >= d[0] > min_dg]
    return integrate_prob(data)

def calc_dE(p_ratio, T):
    """p_ratio is the ratio of cisP to transP; T is the temperature"""
    R = 8.3144621e-3                                        # KJ/(K*mol)
    
    # deriving from the equ. p = exp-(dE/RT)
    dE = np.log(p_ratio) * R * T
    return dE

if __name__ == "__main__":
    infile, T = sys.argv[1:3]
    data = xvg2array(infile)
    # print sum(data[1])

    data = data.transpose()
    transP = integrate_trans_prob(data)
    cisP = integrate_cis_prob(data)
    print "trans probability: {0:8.3f}".format(transP)
    print "cis   probability: {0:8.3f}".format(cisP)
    print "TOTAL PROBABILITY: {0:8.3f}".format(transP + cisP)
    print

    p_ratio = cisP / transP
    print "P_cis / P_trans  : {0:8.3f}".format(p_ratio)
    dE = calc_dE(p_ratio, float(T))
    print "DeltaE (kJ/mol)  : {0:8.3f}".format(dE)
    print "DeltaE (kcal/mol): {0:8.3f}".format(dE * .239)
Beispiel #10
0
def quickplot_nolegend(infile, ax):
    x, y = xvg2array(infile)
    ax.plot(x, y)
    ax.set_title(infile)
    ax.grid()
Beispiel #11
0
def get_coordinates(p1file, p2file):
    p1 = xvg2array(p1file)[1]
    p2 = xvg2array(p2file)[1]
    return p1, p2
Beispiel #12
0
#!/usr/bin/env python

import sys
import numpy as np
from xvg2png import xvg2array 

f = sys.argv[1]
x, y = xvg2array(f)
print "{0:40s}{1}".format(f, np.average(y))