예제 #1
0
    # get number of beads
    beads = headers[len(headers) - 1]
    beads = func.get_int(beads)

    # correct global drift
    time = np.array(df['Time (s)'])
    freq = 1 / np.median(np.diff(time))

    drift = []
    for i in range(beads):
        z_drift = np.array(df['Z' + str(i) + ' (um)'])
        amplitude_drift = np.array(df['Amp' + str(i) + ' (a.u.)'])

        rupt = func.rupture(time, amplitude_drift)
        if rupt == False:
            drift.append(func.drift_self(z_drift, time))

    drift = float(np.median(drift))

    print("Processing file: " + str(file) + " (drift: " + str(round(drift, 2)) + " nm/s)")
    print("Reference Frequencies: A = "+str(file[10:13])+", B = "+str(file[15:18]))

    for bead in range(beads):

        # print("Processing bead " + str(bead))

        Z_meas = "Z" + str(bead) + " (um)"
        Z = np.array(df[Z_meas])

        # corrections
        if correct_global_drift == True:
예제 #2
0
def read_analyze(measurement, pars, data_path):
    try:
        p = pars
    except:
        print('Error: no parameters')
        return

    global_drift = True

    # constants from parameters
    L_bp = p['L_bp']  # contour length (bp)
    S_pN = p['S_pN']  # stretch modulus (pN)
    P_nm = p['P_nm']  # persistence length (nm)

    # open data
    file_location = data_path
    file_name = "data_" + str(measurement[1])
    file_extension = ".dat"
    file_all = file_location + file_name + file_extension
    bead = int(measurement[2])

    # title
    title = int(func.get_num(file_location))

    # read DataFrame
    df = pd.read_csv(file_all, sep="\t")

    magnet = np.array(df['Stepper shift (mm)'])
    time = np.array(df['Time (s)'])
    force = func.calc_force(magnet)
    Z = np.array(df['Z' + str(bead) + ' (um)'])

    # number of beads
    file_log = file_location + file_name + ".log"
    f = open(file_log, 'r')
    try:
        beads = f.readlines()[9]
    except:
        headers = list(df)
        # get number of beads
        beads = headers[len(headers) - 1]
    f.close()

    try:
        beads = int(func.get_num(beads))
    except:
        beads = func.get_int(beads)

    drift = []
    for i in range(beads):
        z_drift = np.array(df['Z' + str(i) + ' (um)'])
        try:
            amplitude_drift = np.array(df['Amp' + str(i) + ' (a.u.)'])
        except:
            amplitude_drift = np.array(df['Amp a.u.'])

        # does the tether rupture?
        rupt, _ = func.rupture(time, amplitude_drift)

        if rupt == False:
            drift.append(func.drift_self(z_drift, time))

    if not drift:
        p['drift'] = 'uncorrected'
        drift_med = 0
    else:
        drift_med = float(np.median(drift))
        Z = Z - (drift_med / 1000) * time
        p['drift'] = str(round(drift_med, 3)) + " nm/s (global drift)"

    # calculating the first derivative of magnet
    dx = np.diff(time)
    dy = np.diff(magnet)
    diff_magnet = np.append([0], np.divide(dy, dx))  # add a zero as first element

    # split in pull & release
    factor = max(diff_magnet / 1000)
    time_pull = time[diff_magnet < factor]
    f_pull = force[diff_magnet < factor]
    f_release = force[diff_magnet > factor]
    z_pull = Z[diff_magnet < factor]
    z_release = Z[diff_magnet > factor]

    # select high-force data
    select_f = f_pull[np.where((f_pull > 50) & (f_pull < 55) & (time_pull > 60) & (time_pull < 140))]
    select_z = z_pull[np.where((f_pull > 50) & (f_pull < 55) & (time_pull > 60) & (time_pull < 140))]

    if select_f.size != 0:

        # fit the WLC in fashion (x,y) - only fit offset, fix everything else
        popt, pcov = curve_fit(lambda f, z0: func.WLC_fit(f, P_nm, L_bp * 0.34, S_pN, z0), select_f, select_z, p0=1)

        z_fit = popt[0]

        # subtract fitted offset from data
        z_pull -= z_fit
        z_release -= z_fit
        select_z -= z_fit

    else:
        z_fit = 0

    title = str(title) + '_' + str(measurement[1]) + '_' + str(measurement[2]) + '_' + str(measurement[3])

    return f_pull, z_pull, f_release, z_release, title, drift_med, z_fit
예제 #3
0
파일: plot_DNA2HMf.py 프로젝트: thms317/HMf
def read_analyze_DNA(measurement, pars):
    # import parameters
    try:
        p = pars
    except:
        print('Error: no parameters')
        return

    # constants from Parameters
    L_bp = p['L_bp']  # contour length (bp)
    S_pN = p['S_pN']  # stretch modulus (pN)
    P_nm = p['P_nm']  # persistence length (nm)

    #  working on laptop or work PC?
    folder = "C:\\Users\\tbrouwer\\Desktop\\Data\\"
    bool = os.path.isdir(folder)
    if bool == False:
        folder = "C:\\Users\\brouw\\Desktop\\Data\\"

    # open data
    sub = measurement
    file_location = folder + str(sub[0]) + "\\"
    file_name = "data_" + str(sub[1])
    file_extension = ".dat"
    file_all = file_location + file_name + file_extension
    bead = int(sub[2])

    # title
    title = int(func.get_num(file_location))

    # read DataFrame
    df = pd.read_csv(file_all, sep="\t")

    magnet = np.array(df['Stepper shift (mm)'])
    time = np.array(df['Time (s)'])
    force = func.calc_force(magnet)
    Z = np.array(df['Z' + str(bead) + ' (um)'])

    # number of beads
    file_log = file_location + file_name + ".log"
    f = open(file_log, 'r')
    beads = f.readlines()[9]
    f.close()

    beads = int(func.get_num(beads))

    drift = []
    for i in range(beads):
        z_drift = np.array(df['Z' + str(i) + ' (um)'])
        amplitude_drift = np.array(df['Amp' + str(i) + ' (a.u.)'])

        # does the tether rupture?
        rupt = rupture(time, amplitude_drift)

        if rupt == False:
            drift.append(func.drift_self(z_drift, time))

    drift_med = float(np.median(drift))
    Z = Z - (drift_med / 1000) * time

    # calculating the first derivative of magnet
    dx = np.diff(time)
    dy = np.diff(magnet)
    diff_magnet = np.append([0], np.divide(dy,
                                           dx))  # add a zero as first element

    # split in pull & release
    factor = max(diff_magnet / 1000)
    # f_pull = force[diff_magnet > factor]
    # f_release = force[diff_magnet < factor]
    # z_pull = Z[diff_magnet > factor]
    # z_release = Z[diff_magnet < factor]
    # 1st pull
    # f_pull = force[np.where((diff_magnet > factor) & (time < 25))]
    # f_release = force[np.where((diff_magnet < factor) & (time < 25))]
    # z_pull = Z[np.where((diff_magnet > factor) & (time < 25))]
    # z_release = Z[np.where((diff_magnet < factor) & (time < 25))]
    # 2nd pull
    f_pull = force[np.where((diff_magnet > factor) & (time > 25))]
    f_release = force[np.where((diff_magnet < factor) & (time > 25))]
    z_pull = Z[np.where((diff_magnet > factor) & (time > 25))]
    z_release = Z[np.where((diff_magnet < factor) & (time > 25))]

    # select high-force data
    select_f = f_pull[np.where((f_pull > 14) & (f_pull < 16))]
    select_z = z_pull[np.where((f_pull > 14) & (f_pull < 16))]

    # fit the WLC in fashion (x,y) - only fit offset, fix everything else
    popt, pcov = curve_fit(
        lambda f, z0: func.WLC_fit(f, P_nm, L_bp * 0.34, S_pN, z0),
        select_f,
        select_z,
        p0=1)

    z_fit = popt[0]

    # subtract fitted offset from data
    z_pull -= z_fit
    z_release -= z_fit
    select_z -= z_fit

    title = str(title) + '_' + str(sub[1]) + '_' + str(sub[2]) + '_' + str(
        sub[3])

    return f_pull, z_pull, f_release, z_release, title
예제 #4
0
def read_analyze_rot(measurement, pars, data_path):
    try:
        p = pars
    except:
        print('Error: no parameters')
        return

    # constants from parameters
    L_bp = p['L_bp']  # contour length (bp)
    S_pN = p['S_pN']  # stretch modulus (pN)
    P_nm = p['P_nm']  # persistence length (nm)

        # open data
    file_location = data_path
    file_name = "data_" + str("{0:0=3d}".format(int(measurement[1]) - 1))
    file_extension = ".dat"
    file_all = file_location + file_name + file_extension
    bead = int(measurement[2])

    # title
    title = int(func.get_num(file_location))

    # read DataFrame
    df = pd.read_csv(file_all, sep="\t")

    try:
        rotation = np.array(df['Stepper rot (turns)'])
    except:
        print("No rotation measurement")
        p['drift'] = 'uncorrected'
        return [], [], [], [], [], []

    time = np.array(df['Time (s)'])
    X = np.array(df['X' + str(bead) + ' (um)'])
    Y = np.array(df['Y' + str(bead) + ' (um)'])
    Z = np.array(df['Z' + str(bead) + ' (um)'])

    # number of beads
    file_log = file_location + file_name + ".log"
    f = open(file_log, 'r')
    beads = f.readlines()[9]
    f.close()

    beads = int(func.get_num(beads))

    drift = []
    for i in range(beads):
        z_drift = np.array(df['Z' + str(i) + ' (um)'])
        try:
            amplitude_drift = np.array(df['Amp' + str(i) + ' (a.u.)'])
        except:
            amplitude_drift = np.array(df['Amp a.u.'])

        # does the tether rupture?
        rupt, _ = func.rupture(time, amplitude_drift)

        if rupt == False:
            drift.append(func.drift_self(z_drift, time))

    if not drift:
        p['drift'] = 'uncorrected'

    else:
        drift_med = float(np.median(drift))
        Z = Z - (drift_med / 1000) * time
        p['drift'] = str(round(drift_med, 3)) + " nm/s (global drift)"

    # calculating the first derivative of magnet
    dx = np.diff(time)
    dy = np.diff(rotation)
    diff_rot = np.append([0], np.divide(dy, dx))  # add a zero as first element

    # offset the Z
    Z -= np.mean(Z)

    # calculate LND
    LND = rotation / (p['L_bp'] / 10.4)

    # split in pull & release
    factor = max(diff_rot / 1000)
    twist_pos = rotation[diff_rot < factor]
    twist_neg = rotation[diff_rot > factor]
    x_pos = X[diff_rot < factor]
    x_neg = X[diff_rot > factor]
    y_pos = Y[diff_rot < factor]
    y_neg = Y[diff_rot > factor]
    z_pos = Z[diff_rot < factor]
    z_neg = Z[diff_rot > factor]
    lnd_pos = LND[diff_rot < factor]
    lnd_neg = LND[diff_rot > factor]

    x_sel = np.concatenate((x_pos,x_neg))
    y_sel = np.concatenate((y_pos,y_neg))

    # fit circle to extract radius
    x_m, y_m, R = fit_circle(x_sel,y_sel)
    # alternative method (currently works better)
    R2 = (abs(np.percentile(x_sel,1)-np.percentile(x_sel,99))/2+abs(np.percentile(y_sel,1)-np.percentile(y_sel,99))/2)/2
    x_m_2 = np.percentile(x_sel,1)+R2
    y_m_2 = np.percentile(y_sel,1)+R2

    p['radius_um'] = R2

    # plt.close()
    # plt.scatter(x_sel,y_sel)
    # plt.scatter(x_m, y_m)
    # plt.scatter(x_m_2, y_m_2, color='r')
    # plt.plot(x_m+R,y_m)
    # plt.show()

    return twist_pos, twist_neg, z_pos, z_neg, lnd_pos, lnd_neg