예제 #1
0
def get_fiber_dyad_frames(fiber_params, nuc_d, nuc_type=nuc_name):
    '''
    Convert the parameters that define a stacked fiber to the
    frame coordinates of the dyad basepairs

    Parameters
    ----------
    fiber_params : ndarray of (N, 6)
        The step paremeters of the stacked fiber

    Returns
    -------
    res : ndarray of (N, 4, 3)
        The coordinates of the dyad frames
    '''
    fiber = HelixPose(fiber_params)
    res = []

    for i in range(len(fiber.frames)):
        n_f = np.transpose(fiber.frames[i])
        n_o = fiber.coord[i]

        dna_params, dna_o, dna_f0, c = GetNuc(norigin=n_o,
                                              nframe=n_f,
                                              nuc_type=nuc_type)
        n_dna = HelixPose(dna_params, frame0=dna_f0)

        dyad_coords = nuc.of2coords(n_dna.coord[nuc_d] + dna_o,
                                    np.transpose(n_dna.frames[nuc_d]))
        res.append(dyad_coords)
    return res
예제 #2
0
def GetNuc(
        norigin=np.zeros(3), nframe=np.eye(3), wrapped_bp=0,
        nuc_type=nuc_name):
    '''
    Obtain the coordinates of a nucleosome from a pdb file

    Parameters
    ----------
    norigin : ndarray of (3)
        center of mass of the nucleosome
    nframe : ndarray of (3,3)
        frame of the nucleosome (x points to dyad, z points along cylinder axis)
    wrapped_bp : int
        controls the amount of nucleosome wrapped DNA
        negative values indicate #bp unwrapped at each side
        positive values indicate total wrapped #bp distributed symetrically 
    Returns
    -------
     params2 : ndarray of (N, 6)
        The basepair step parameters of DNA
     o2 : ndarray of (3)
         start coordinate of DNA
     f2 : ndarray of (3, 3)
         start frame of DNA
     c_dyad : ndarray of (4, 3)
         coordinate frame of the dyad basepair
     
    '''
    n = nuc.NucPose()
    n.from_file(nuc_type)
    dna = HelixPose(n.params)
    i = 0
    n_bp = dna.n_bp

    o_nuc, f_nuc = nuc.get_nframe(dna.coord, n.d_index, fixed)
    P = nuc.of2coords(o_nuc, f_nuc)
    Q = nuc.of2coords(norigin, nframe)

    transform = nuc.get_transformation(P, Q)
    o_dyad = dna.coord[n.d_index]
    f_dyad = dna.frames[n.d_index]
    c_dyad = nuc.apply_transf_coords(nuc.of2coords(o_dyad, f_dyad), transform)

    c0 = nuc.of2coords(dna.coord[0], dna.frames[0])

    c1 = nuc.apply_transf_coords(c0, transform)
    o1, f1 = nuc.coords2of(c1)
    dna1 = HelixPose(n.params, frame0=np.transpose(f1))

    f2 = dna1.frames[i]
    o2 = o1 + dna1.coord[i]
    params2 = dna1.params[i:i + n_bp]

    return params2, o2, f2, c_dyad
예제 #3
0
def GetPose(filename, drc = ''):
    '''
    Load a dinucleome HelixPose object from .npz file
    
    Parameters
    ----------
    filename : string
        name of the .npz file
    drc : string
        directory in which the file can be found (if it is not in the same 
        directory as this script)
    
    Returns
    -------
    DNA : HelixPose object
        the HelixPose of a dinucleosome
    dyads : ndarray
        numpy array with dyad indices
    nucl : NucPose object
        the NucPose of the used nucleosome
    '''
    fname = drc + '\\' + filename
    
    NRL = int(filename.split('NRL')[1].split('h')[0])
    nuctype = filename.split('NRL')[0]
    #h = int(filename.split('NRL')[1].split('h')[1].split('.')[0])
    
    DNA = HelixPose(params = np.load(fname)['params'] , frame0 = np.load(fname)['frame0'])
    n_bp = len(DNA.params)
    dyads = np.asarray(NRL*(np.arange(0, 2, 1)-(2-1)/2.0))
    dyads = (dyads+n_bp/2).astype(int)
    nucl = NMC.NucPose()
    nucl.from_file(nuctype+'.3DNA')
    return DNA, dyads, nucl
예제 #4
0
def insert_nucs(dna, dyads, pdb='1KX5'):
    '''
    Fix basepair parameters for nucleosomes in DNA at dyad positions

    Parameters
    ----------
    dna: HelixMC pose
    dyads : dyad positions in DNA (bp)
    Returns
    -------
    dna : HelixMC pose
    nucl : NucleosomeMC pose
    '''
    #    # Get nucleosome
    nucl = nMC.NucPose()
    nucl.from_file(fileio.change_extension(pdb, '3DNA'))

    params = dna.params
    length = len(nucl.dna.params)
    new_dyads = []
    for dyad in dyads:
        start = dyad - nucl.dyad
        end = start + length
        if (start >= 0 and (end < len(params))):
            params[start:end] = nucl.dna.params
            new_dyads.append(dyad)
    dna = HelixPose(params)
    return dna, nucl, np.asarray(new_dyads)
예제 #5
0
def create_nuc_array(p=None):
    '''
    Create DNA configuration, including nucleosomes

    '''
    if p is None:
        p = Parameters()
        p.add('L_bp', value=500)
        p.add('n_nuc', value=2)
        p.add('NRL', value=197)
    p = p.valuesdict()

    n_bp = p['L_bp']
    n_nucs = p['n_nuc']
    NRL = p['NRL']

    dyads = np.asarray(NRL * (np.arange(0, n_nucs, 1) - (n_nucs - 1) / 2.0))
    dyads = (dyads + n_bp // 2).astype(int)

    random_step = RandomStepSimple.load_gaussian_params('DNA_gau.npy')
    params = np.tile(random_step.params_avg, (n_bp - 1, 1))

    dna = HelixPose(params)
    dna, nuc, dyads = insert_nucs(dna, dyads)

    return dna, dyads, nuc
예제 #6
0
def create_mp4_pov(directory, origin_frame=0, fps=5, reverse=True):
    filenames = sorted(glob.glob(directory + '\\*.npz'))
    r = np.append([10], (np.ones(8) * 4))
    r = np.append(r, 3)
    r = np.append(r, 2)
    c = 'kbbggryrycy'

    image_files = []
    j = 0
    report_progress(len(filenames), title='create_pov_mp4', init=True)
    for file in filenames:
        j += 1
        report_progress(j, title='create_pov_mp4')

        dna = HelixPose.from_file(file)
        origin_of = nMC.get_of(dna, origin_frame)
        tf = nMC.get_transformation(origin_of)
        coords = nMC.apply_transformation(dna.coords, tf)
        image_files.append(
            pov_dna(file, [coords],
                    range_A=[1000, 1500],
                    offset_A=[0, 0, 150],
                    show=False))
    create_mp4_images(image_files,
                      fps=fps,
                      delete=True,
                      filename=directory + '.mp4',
                      reverse=reverse)
    return
예제 #7
0
def create_pov_npz(filename):
    filename = change_extension(filename, 'npz')
    # directory = 'E:\\Users\\Noort\\data\\20180320\\data_001\\'
    # filename = 'E:\\Users\\Noort\\data\\20180320\\data_001\\data_001_0001.npz'
    # print(filename)
    dna = HelixPose.from_file(filename)
    pov_dna(filename, [dna.coords],
            range_A=[1500, 2500],
            offset_A=[0, 0, 150],
            show=True)
    return
예제 #8
0
def plot_step_params(filename, dataset, save=False, wait=0, plot_energy=True):
    filename = fileio.change_extension(filename, 'xlsx')
    sets, files, _ = contents_xlsx(filename)
    if dataset == -1:
        filename = sorted(files)[-1]
    else:
        filename = files[sets.index(dataset)]
    dna = HelixPose.from_file(fileio.change_extension(filename, 'npz'))

    p0 = np.load(default_step_file)[0]
    sigma2 = np.load(default_step_file)[1:]
    k = 1 / sigma2
    energy_kT = []
    for p in dna.params:
        energy_kT.append(0.5 * (p - p0) * np.dot(k, p - p0) / kT)
    energy_kT = np.asarray(energy_kT)
    energy_kT = np.sum(np.abs(energy_kT), axis=1)

    i = xrange(len(dna.params))

    plt.close()
    plt.figure(figsize=(12, 4))
    if plot_energy:
        plt.plot(i, energy_kT)
        plt.ylim(-1, 25)
        plt.ylabel('G (kT)')
    else:
        plt.plot(i, dna.params)
        plt.ylim(-2.5, 4.5)
        plt.ylabel('step parameters')
        plt.legend(['Shift', 'Slide', 'Rise', 'Tilt', 'Roll', 'Twist'], loc=1)
    plt.tick_params(axis='both',
                    which='both',
                    direction='in',
                    top=True,
                    right=True)
    plt.title(filename.split('\\')[-2] + '\\' +
              filename.split('\\')[-1].split('.')[0],
              loc='left',
              fontdict={'fontsize': 10})
    plt.xlabel('i (bp)')

    plt.tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
    plt.draw()
    if wait != 0:
        plt.pause(wait)
    if save:
        filename = fileio.change_extension(filename, '_step.jpg')
        plt.savefig(filename, dpi=600, format='jpg')
    return
예제 #9
0
def create_fiber(l_handle,
                 n_nuc,
                 NRL,
                 dna_file='DinucleosomePoses\\4qlcNRL167.npz',
                 CL=True):
    '''    
    Create a chromatin fiber with prespecified handle lengths from a dinucleosome
    DNA pose file
    
    Parameters
    ----------
    l_handle : int
        lenght of DNA handle in basepairs
    n_nuc : int
        number of nucleosomes in the fiber
    NRL : int
        nucleosome repeat length in basepairs
    dna_file : string
        name of the saved HelixPose file
        
    Returns
    -------
    dna : instance of HelixPose
    
    dyads : list

    nucl : instance of NucPose
    '''
    dna = HelixPose(params=np.load(dna_file)['params'],
                    frame0=np.load(dna_file)['frame0'])
    n_bp = len(dna.coord)
    dna2, dyads, nucl = create_dna(
        n_bp,
        2,
        NRL,
        unwrap=-20,
        nuc_file=(dna_file.split('\\')[1]).split('N')[0] + '.3DNA')

    if CL == True:
        n_bp_new = NRL + 147
        diff = n_bp - n_bp_new
        newpars = dna.params[diff / 2 - 1:-(diff / 2)]
        for i in range(len(dyads)):
            dyads[i] = nucl.d_index + NRL * i - 1
        dna.set_params(newpars)
    dyads = CreateFiber(dna, dyads[0], dyads[1], n_nuc)
    #    for i in range(len(dyads)):
    #        dyads[i] = dyads[i] + l_handle
    dyads = dyads + l_handle
    handles = np.tile(random_step.params_avg, (l_handle, 1))
    newpars = dna.params

    newpars = np.concatenate((handles, newpars, handles))
    dna.set_params(newpars)

    return dna, dyads, nucl
예제 #10
0
def create_dna(n_bp,
               n_nucs,
               NRL,
               unwrap=None,
               compute_tw_wr=False,
               nuc_file=nuc_name):
    '''
    Create random DNA configuration, including nucleosomes

    Parameters
    ----------
    n_bp : number of basepairs
    n_nucs : number of nucleosomes
    NRL : nucleosome repeat length
    unwrap : number of basepaires wrapped on the nucleosome. Negative numbers
        define number of unwrapped basepairs on each side
    
    Returns
    ----------
    DNA : instance of HelixMC
    dyads : bp position of dyads
    nucl : instance of NucleosomeMC
    '''
    dyads = np.asarray(NRL * (np.arange(0, n_nucs, 1) - (n_nucs - 1) / 2.0))
    dyads = (dyads + n_bp / 2).astype(int)

    random_step = RandomStepSimple.load_gaussian_params('DNA_gau.npy')
    params = np.tile(random_step.params_avg, (n_bp, 1))

    # Get nucleosome
    nucl = nuc.NucPose()
    nucl.from_file(nuc_file)

    # Insert nucleosomes in DNA
    params, free_dna = insert_nucs(params,
                                   nucl.params,
                                   dna_dyads=dyads,
                                   nuc_dyad=nucl.d_index,
                                   wrapped_bp=unwrap)
    DNA = HelixPose(params, compute_tw_wr=compute_tw_wr)

    return DNA, dyads, nucl
예제 #11
0
def replace_linker(dna, dyads, linker_params):
    '''
    Replace basepair parameters for linker DNA

    Parameters
    ----------
    dna : basepair step parameters for DNA
    dyads : dyad index in DNA (bp)
    free_bps : array of bps; 0 = nucleosomal DNA, 1 = free DNA
    linker_params : basepair step parameters for linker DNA
    Returns
    -------
    dna_params : ndarray of (N, 6)
        The basepair step parameters of DNA
    free_bps : array of bps; 0 = nucleosomal DNA, 1 = free DNA
    '''
    params = dna.params
    for d1, d2 in zip(dyads, dyads[1:]):
        linker_mid = d1 + (d2 - d1) // 2
        linker_start = linker_mid - len(linker_params) // 2 - 1
        params[linker_start:linker_start + len(linker_params)] = linker_params
    dna = HelixPose(params)
    return dna
예제 #12
0
def create_folded_fiber(par, nucl):
    dna, dyads, _ = create_nuc_array(p=par)
    params = np.zeros_like(dna.params)
    w = np.zeros(len(dna.coords))
    n_ofs = get_fiber_frames(par)
    origin_of = np.concatenate(([np.zeros(3)], np.eye(3)))
    unwrapped = int(par['Unwrapped_bp'])
    length = len(nucl.dna.params) - 2 * unwrapped
    for n_of, dyad in zip(n_ofs, dyads):
        tf = nMC.get_transformation(nucl.of, target=n_of)
        start_bp = dyad - nucl.dyad + unwrapped
        w[start_bp:start_bp + length] = np.ones(length)
        params[start_bp:start_bp +
               length] = nucl.dna.params[unwrapped:unwrapped + length]
        params[start_bp - 1] = \
            nMC.ofs2params(origin_of, nMC.apply_transformation(nMC.get_of(nucl.dna, unwrapped), tf))
        params[start_bp + length] = \
            nMC.ofs2params(nMC.apply_transformation(nMC.get_of(nucl.dna, len(nucl.dna.params) - unwrapped), tf),
                           origin_of)
    fiber_dna = HelixPose(params)

    w = np.transpose(np.asarray([w, w, w]))
    return fiber_dna, dyads, w
예제 #13
0
def plot_step_params(filename, dataset, save=False):
    filename = change_extension(filename, 'xlsx')
    sets, files, _ = contents_xlsx(filename)
    if dataset == -1:
        filename = sorted(files)[-1]
    else:
        filename = files[sets.index(dataset)]
    dna = HelixPose.from_file(change_extension(filename, 'npz'))
    # dna = HelixPose.from_file(change_extension(files[-1], 'npz'))

    i = xrange(len(dna.params))

    plt.close()
    plt.figure(figsize=(12, 4))
    plt.plot(i, dna.params)
    plt.tick_params(axis='both',
                    which='both',
                    direction='in',
                    top=True,
                    right=True)
    plt.title(filename.split('\\')[-2] + '\\' +
              filename.split('\\')[-1].split('.')[0],
              loc='left',
              fontdict={'fontsize': 10})
    plt.xlabel('i (bp)')
    plt.ylabel('step parameters')
    plt.ylim(-2.5, 4.5)
    plt.legend(['Shift', 'Slide', 'Rise', 'Tilt', 'Roll', 'Twist'], loc=1)

    plt.tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
    plt.draw()
    plt.pause(5)
    if save:
        filename = change_extension(filename, '_step.jpg')
        plt.savefig(filename, dpi=600, format='jpg')

    return
예제 #14
0
    def from_file(self, input_file):
        '''
        Load pose data from an input file.

        Parameters
        ----------
        input_file : str
        input file (.txt) obtained from w3DNA.

        '''
        self.nuc_type = input_file.split('.')[0]
        if input_file == None:
            input_file = "3LZ0.3DNA"
            print('Default file: ' + input_file)
        #   read protein coords from pdb file
        filename = pdb_source_dir + input_file
        filename = fileio.change_extension(filename, 'pdb')
        chains = read_pdb(filename)

        #   read 3DNA file
        filename = fileio.change_extension(filename, '3DNA')
        with open(filename) as f:
            lines = f.read().splitlines()

        #   Basepair step parameters
        i = find(
            lines, lambda x:
            '    step       Shift     Slide      Rise      Tilt      Roll     Twist'
            in x) + 1

        j = find(lines[i:], lambda x: '~~~~~~~~~~~' in x)

        params = np.zeros((j, 6))
        for k in range(0, j):
            if not ('----' in lines[i + k]):
                tmp = np.asarray(map(float, lines[i + k].split()[2:]))
            params[k:] = np.append(tmp[0:3], np.radians(tmp[3:6]))

        #   get fixed frames
        B_factor = chains['DNA'][3]
        fixed = []
        for i in range(14):
            j = np.argmin(B_factor)
            fixed.append(j)
            B_factor[j - 6:j + 6] = np.max(B_factor)

        fixed = np.sort(fixed)
        self.dyad = int(round(np.mean(fixed)))
        self.fixed = fixed - self.dyad

        #   Centers of basepairs
        i = find(
            lines, lambda x:
            '      bp        Ox        Oy        Oz        Nx        Ny        Nz'
            in x) + 1

        coords = np.zeros((j, 3))
        frames = np.zeros((j, 3, 3))
        for k in range(0, j):
            tmp = np.asarray(map(float, lines[i + k].split()[2:]))
            coords[k, :] = tmp[0:3]
            frames[k][0] = tmp[3:6] / np.linalg.norm(tmp[3:6])
        chains['DNA'][2] = np.asarray(coords)

        # rotate all coords, such that frame0 = origin
        self.dna = HelixPose(params)
        tm = get_transformation(chains['DNA'][2][0:100],
                                self.dna.coords[0:100])
        for chain in chains:
            chains[chain][2] = apply_transformation(chains[chain][2], tm)
        self.chains = chains

        # remove non-nucleosomal DNA
        if len(self.dna.coords) > 147:
            loose_ends = 147 - (self.fixed_i[-1] - self.fixed_i[0] + 1)
            if loose_ends % 2 == 1:
                l1 = loose_ends / 2
                l2 = l1 + 1
            else:
                l1 = loose_ends / 2
                l2 = l1
            start = self.fixed_i[0] - l1 + self.d_index
            end = self.fixed_i[-1] + l2 + self.d_index
            self.d_index = self.d_index - start
            params = params[start:end]
            self.dna = HelixPose(params)

        # get origin and frame of nucleosome
        cm = np.mean(self.dna.coords[self.fixed], axis=0)
        Nx = self.dna.coords[self.dyad] - cm
        Nx = Nx / np.linalg.norm(Nx)
        Nz = np.mean(self.dna.coords[self.fixed[:7], :], axis=0) - np.mean(
            self.dna.coords[self.fixed[7:], :], axis=0)
        Nz = Nz / np.linalg.norm(Nz)

        Ny = np.cross(Nx, Nz)
        Ny = Ny / np.linalg.norm(Nz)

        Nz = np.cross(Nx, Ny)
        Nz = Nz / np.linalg.norm(Nz)
        origin = cm
        frame = np.array([Nx, Ny, Nz])
        self.of = join_o_f(origin, np.transpose(frame))
read_from_file = True

n_nuc = 2
n_bp = 147 + NRL
dna, dyads, nucl = FMC.create_dna(n_bp, n_nuc, NRL)
# end = FMC.nuc_get_ends(dna, dyads[1], nucl)[0]
start = dyads[0] + (147 - nucl.d_index)
end = dyads[1] - nucl.d_index
# start = FMC.nuc_get_ends(dna, dyads[0], nucl)[1]

####Load or create a DNA sequence####
if read_from_file == True:

    ###Load DNA sequence from existing DNA pose###
    dna_file = 'simulations\\20180215_197_0_unwrap.npz'
    dna = HelixPose(params=np.load(dna_file)['params'],
                    frame0=np.load(dna_file)['frame0'])

else:

    ###Create DNA sequence according to input parameters###
    # 197
    a = np.array([10.234, 0.312, 0.153, 0.973,
                  0.776])  # parameters in range we can probe with GUI
    a = np.array([11.6, 0.324, 3.625, 0.976,
                  0.795])  # on their way to be optimized...
    #    a = np.array([11.617, 0.329, 3.672, 0.965, 0.800])  # 15/02/18 197 solenoid --> unwrap 0-10
    # a = np.loadtxt('simulations\\180215_197_0_unwrap.dat')

    unwrap = -5
    nld = 100
예제 #16
0
file_name = 'simulations\\NLD test\\' + date + '_' + str(NRL)

read_from_file = False

n_nuc = 2
n_bp = 147 + NRL
dna, dyads, nucl = FMC.create_dna(n_bp, n_nuc, NRL)
# end = FMC.nuc_get_ends(dna, dyads[1], nucl)[0]
start = dyads[0] + (147 - nucl.d_index)
end = dyads[1] - nucl.d_index
# start = FMC.nuc_get_ends(dna, dyads[0], nucl)[1]

if read_from_file == True:

    dna_file = 'simulations\\20180215_197_0_unwrap.npz'
    dna = HelixPose(params=np.load(dna_file)['params'],
                    frame0=np.load(dna_file)['frame0'])

else:

    # 197
    a = np.array([11.617, 0.329, 3.672, 0.965,
                  0.800])  # 15/02/18 197 solenoid --> unwrap 0-10
    # a = np.loadtxt('simulations\\180215_197_0_unwrap.dat')

    unwrap = 0

    link_len = end - start

    CurveDNA(a, unwrap, dna, nucl, start, end, n_nuc, dyads)
    print start
    print end
예제 #17
0
def main():
    # Define fiber params
    pars = Parameters()
    pars.add('F_pN', value=0)
    pars.add('z_nm', value=0)
    pars.add('L_bp', value=800)
    pars.add('n_nuc', value=4)
    pars.add('NRL', value=167)
    pars.add('P_nm', value=50)
    pars.add('dyad0_bp', value=0)
    pars.add('diameter_A', value=330)
    pars.add('rise_A', value=100)
    pars.add('nld_A', value=25)
    pars.add('chirality', value=-1)
    pars.add('Unwrapped_bp', value=30)
    pars.add('face', value=1)
    pars.add('g_wrap_kT', value=3)
    pars.add('g_stack_kT', value=25)
    pars.add('fiber_start', value=2)

    g_wrap_kT = pars['g_wrap_kT'].value
    g_stack_kT = pars['g_stack_kT'].value

    # Setup files and forces
    filename = fileio.get_filename(incr=True, root='3nucs')
    print(filename)
    n_step = 250
    n_substeps = 10
    fmax_pN = 10
    fmin_pN = 0.1
    # forces = np.linspace(fmin_pN, fmax_pN, n_step / 2)
    forces = np.logspace(np.log10(fmin_pN), np.log10(fmax_pN), n_step / 2)
    forces = np.append(forces, forces[::-1])

    get_from_file = False
    if get_from_file:
        # Get from file
        file_in = 'E:\\Users\\noort\\data\\20180321\\data_003.xlsx'
        dataset = 0
        pars, datafile = fileio.read_xlsx(file_in, dataset, pars=pars)
        dna, dyads, nucl = fMC.create_nuc_array(p=pars)
        dna = HelixPose.from_file(fileio.change_extension(datafile, 'npz'))
    else:
        # Initialize fiber pose
        dna, dyads, nucl = fMC.create_nuc_array(p=pars)

    pars['dyad0_bp'].value = dyads[0]
    fileio.plot_dna(dna,
                    title='Initial conformation\n',
                    range_nm=100,
                    save=True)
    pars.pretty_print(columns=['value'])

    # Get stack and wrap parameters
    fixed_wrap_params = nMC.get_wrap_params(nucl.dna, nucl.dyad, nucl.fixed)
    fiber_dna, dyads, w = fMC.create_folded_fiber(pars, nucl)
    fixed_stack_params = fMC.get_stack_pars(fiber_dna, dyads)[0]
    fiber_start = pars['fiber_start'].value
    # Initialize random steps
    random_step = RandomStepSimple.load_gaussian_params('DNA_gau.npy')

    basepairs = np.asarray(xrange(pars['L_bp'] - 1))
    accept = 0
    all_coord = np.empty((n_step, 3))

    current_step = 0
    fileio.report_progress(n_step, title='RunMC3', init=True)
    for force in forces:
        fileio.report_progress(current_step + 1, title='RunMC3')
        scorefxn = ScoreTweezers(force)
        previous_bp = 0
        for sub_step in xrange(n_substeps):
            for bp in basepairs:
                accept += MC_move(dna, bp, previous_bp, scorefxn,
                                  fixed_wrap_params, fixed_stack_params, dyads,
                                  nucl, random_step, g_wrap_kT, g_stack_kT,
                                  fiber_start)
                previous_bp = bp
            basepairs = basepairs[::-1]

        fileio.plot_dna(dna,
                        update=True,
                        title='F = {:.1f} pN\n'.format(force),
                        save=True)

        pars['F_pN'].value = force
        pars['z_nm'].value = dna.coord_terminal[2]
        fileio.write_xlsx(fileio.get_filename(sub=True),
                          str(current_step),
                          pars,
                          report_file=filename)
        dna.write2disk(fileio.get_filename(sub=True, ext='npz'))
        all_coord[current_step] = dna.coord_terminal
        current_step += 1

    z = all_coord[:, 2] / 10
    wlc = 1 - 0.5 * np.sqrt(0.1 * kT / (forces * pars['P_nm']))
    grid = []
    for i in xrange(1, pars['n_nuc'] + 1):
        grid.append(wlc * (pars['L_bp'] - 80 * i) / 3)
        grid.append(wlc * (pars['L_bp'] - (pars['n_nuc'] * 80 + i *
                                           (147 - 80))) / 3)
    wlc *= pars['L_bp'] / 3
    selected = np.diff(np.append([-1], forces)) > 0

    fileio.save_plot((forces, z, wlc, selected),
                     filename=filename,
                     ax_labels=['z (nm)', 'F (pN)'],
                     grid=grid,
                     transpose=True,
                     xrange=[0, 1.1 * pars['L_bp'] / 3])

    if n_step > 0:
        print('Accept rate = %.1f %%' % (100 * float(accept) /
                                         (n_step * n_substeps *
                                          (pars['L_bp'] - 1))))
    try:
        fileio.create_mp4_pov(fileio.get_filename(sub=True, folder=True),
                              origin_frame=0,
                              reverse=False)
    except Exception, e:
        print(Exception, e)
예제 #18
0
파일: z-dna.py 프로젝트: DasLab/HelixMC
# Run HelixMC #
cmdline = 'helixmc-run '
cmdline += '-params Z-DNA.npz '
cmdline += '-n_bp 100 '
cmdline += '-n_step 10 '
cmdline += '-seq GC '
cmdline += '-force 5 '
cmdline += '-compute_fuller_link '
cmdline += '-out_frame test_run'

print 'Z-DNA command line:', cmdline
subprocess.check_call(cmdline.split())

# Data Analysis #
data = np.load('MC_data.npz')
# avg. z-extension in Å
print 'Avg. Z:', np.average(data['coord_terminal'][:, 2])
# avg. link in radian
print 'Avg. Link:', np.average(data['twist'] + data['writhe'])

# Helix Plotting #
pose = HelixPose.from_file('test_run.npz')
pose.plot_centerline(show=False)  # plot the centerline
plt.title('Center line')


pose.plot_helix(show=False, rb_width=15)  # plot the entire helix
plt.title('Helix Plot')
plt.show()
file_name = 'simulations\\' + date + '_' + str(NRL)

read_from_file = False

n_nuc = 2
n_bp = 147 + NRL
dna, dyads, nucl = FMC.create_dna(n_bp, n_nuc, NRL)
# end = FMC.nuc_get_ends(dna, dyads[1], nucl)[0]
start = dyads[0] + (147 - nucl.d_index)
end = dyads[1] - nucl.d_index
# start = FMC.nuc_get_ends(dna, dyads[0], nucl)[1]

if read_from_file == True:

    dna_file = 'simulations\\180215_197_0_unwrap.npz'
    dna = HelixPose(params=np.load(dna_file)['params'], frame0=np.load(dna_file)['frame0'])

else:

    # 197
    a = np.array([11.617, 0.329, 3.672, 0.965, 0.800])  # 15/02/18 197 solenoid --> unwrap 0-10
    # a = np.loadtxt('simulations\\180215_197_0_unwrap.dat')

    unwrap = 0

    link_len = end - start

    CurveDNA(a, unwrap, dna, nucl, start, end, n_nuc, dyads)
    print start
    print end
    se = np.linalg.norm(dna.coord[start] - dna.coord[end])
예제 #20
0
def plot_energy(filename):
    params = np.load(default_step_file)
    p0 = params[0]
    cov = params[1:]
    k = np.linalg.inv(cov)

    sets, files, _ = fileio.contents_xlsx(filename)
    dna = HelixPose.from_file(fileio.change_extension(files[0], 'npz'))

    energy_kT = np.empty((len(files), len(dna.params)))
    i = 0
    fileio.report_progress(len(files),
                           title='analyze_step_parameters',
                           init=True)
    for f in files:
        dna = HelixPose.from_file(fileio.change_extension(f, 'npz'))
        fileio.report_progress(i + 1)
        j = 0
        for p in dna.params:
            energy_kT[i, j] = (np.sum(0.5 * (p - p0) * np.dot(k, p - p0)))
            j += 1
        i += 1

    F_data = fileio.read_param_xlsx(filename, 'F_pN')

    forces = np.linspace(10, 0, 4)
    energy_F = []
    for force in forces:
        selected = (np.abs(F_data - force) < 2.5)
        energy_F.append(np.mean(np.abs(energy_kT[selected]), axis=0))
    energy_F = np.asarray(energy_F)
    print(forces)

    i = xrange(len(dna.params))

    plt.close()
    plt.figure(figsize=(12, 3))
    # plt.plot(i, energy_kT)
    plt.plot(i, energy_F.T)
    energy_thermal = np.ones(len(dna.params)) * 3
    plt.plot(i, energy_thermal, color='k', linestyle=':', linewidth=0.8)

    plt.xlim(0, len(dna.params))
    plt.ylim(-1, 26)
    plt.ylabel('G (kT)')
    plt.tick_params(axis='both',
                    which='both',
                    direction='in',
                    top=True,
                    right=True)
    plt.title(filename.split('\\')[-2] + '\\' +
              filename.split('\\')[-1].split('.')[0],
              loc='left',
              fontdict={'fontsize': 10})
    plt.xlabel('i (bp)')

    plt.tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
    plt.draw()
    plt.pause(5)
    filename = fileio.change_extension(filename, '_Edna.jpg')
    plt.savefig(filename, dpi=600, format='jpg')

    return
예제 #21
0
    def from_file(self, input_file):
        '''
        Load pose data from an input file.

        Parameters
        ----------
        input_file : str
        input file (.txt) obtained from w3DNA.

        '''
        
        if input_file == None:
            input_file = "3LZ0.3DNA"
            
            print('Default file: ' + input_file)
        directory = "N:\\Chromatin\\Software\\ChromatinMC\\PDBs"
#   read protein coords from pdb file

        chains = ReadPdb(directory+ input_file.replace('3DNA','pdb'))
#   get fixed frames
        B = chains['DNA'][3]

        acids = chains['DNA'][1]
        self.step_list = []
        for i in range(len(acids)-1):
            self.step_list.append(acids[i]+acids[i+1])
      
        fixed = []
        for i in range(14):
            j = np.argmin(B)
            fixed.append(j)
            B[j-6:j+6]=np.max(B)

        fixed = np.sort(fixed)
        self.d_index = int(round(np.mean(fixed)))
        self.fixed_i = fixed - self.d_index


        
#   get link coordinates Glu61 (H2A) and Asp24 (H4)
        int_dict={'H2A':60, 'H2A*':60, 'H4':23, 'H4*':23}
        self.l_coords = []
        for locus in int_dict:
            self.l_coords.append(chains[locus][2][int_dict[locus]])
        self.l_coords = np.asarray(self.l_coords)
        
#   read 3DNA file         
        with open(directory+input_file) as f:
            lines = f.read().splitlines()
            
#   Basepair step parameters            
        i=find(lines, lambda x: 
        '    step       Shift     Slide      Rise      Tilt      Roll     Twist'
        in x)+1

        j=find(lines[i:], lambda x: '~~~~~~~~~~~' in x)

        self.params=np.zeros((j,6))
        for k in range (0,j):
            if not('----' in lines[i+k]):
                tmp = np.asarray(map(float,lines[i+k].split()[2:]))
            self.params[k:]= np.append(tmp[0:3], np.radians(tmp[3:6]))
        self.n_bp = len(self.params[:,0])+1
        
        
        
#        self.origins, self.frames = util.params2coords(self.params)
#        self.d_origin =self.origins[self.d_index]
#        self.d_frame = self.frames[self.d_index]
        
        
        

#   Centers of basepairs
        i=find(lines, lambda x: 
        '      bp        Ox        Oy        Oz        Nx        Ny        Nz'
        in x)+1

        coords = np.zeros((j,3))
        frames = np.zeros((j,3,3))
        for k in range (0,j):
            tmp = np.asarray(map(float,lines[i+k].split()[2:]))
            coords[k,:] = tmp[0:3]
            frames[k][0] = tmp[3:6]/np.linalg.norm(tmp[3:6])
            if k is self.d_index:
                self.d_origin = tmp[0:3]
                self.d_frame = tmp[3:6]/np.linalg.norm(tmp[3:6])
        chains['DNA'][2] = coords
        self.chains = chains
        
        
#   Dyad frame coords
        nucDNA = HelixPose(self.params)
        self.nucDNAcopy = HelixPose(self.params)
        Qn = coords
        P = nucDNA.coord[0:len(Qn)]
        transform = get_transformation(P, Q = Qn)
        
        
        Pn = of2coords(nucDNA.coord[self.d_index], nucDNA.frames[self.d_index])
        self.d_of = Pn

        self.d_coords = of2coords(nucDNA.coord[self.d_index], np.transpose(nucDNA.frames[self.d_index]))
        self.DNAcoords = nucDNA.coord
        self.DNApose = nucDNA
#   Nucleosome frame
        self.n_origin, self.n_frame = get_nframe(self.DNAcoords, self.d_index, self.fixed_i)
        #self.n_frame = np.transpose(self.n_frame)
        self.n_coords = of2coords(self.n_origin, self.n_frame)
        
        #com frame to dyad_frame transform
        self.com_d_transform = get_transformation(self.n_coords,self.d_coords)
        
#   origin of nucleosomal DNA
        transform = get_transformation(nucDNA.coord[0:len(coords)], Q = coords)   
        framecoords = of2coords(np.zeros(3), np.eye(3))
        framecoords = apply_transf_coords(framecoords, transform)
        self.origin0, self.frame0 = coords2of(framecoords)

#   fixed coordinates of nucleosome
        self.fixed_coord = get_fixed_coord(nucDNA, self.d_index-1, self.fixed_i)
        self.fixed_coord2 = []
        for i in range(0,14):
            self.fixed_coord2.append(get_fixed_coord2(nucDNA, self.d_index-1, \
            self.fixed_i, i))
        
#   stiffnes of fixed basepairs          
        sd_pos = 0.5 # (A)
        k_pos = kBT / sd_pos**2
        self.fixed_k = k_pos
        self.fixed_g = 10*kBT
        
        if self.n_bp > 147:
            loose_ends = self.fixed_i[-1]-self.fixed_i[0]+1
            if loose_ends%2 == 1:
                l1 = loose_ends/2
                l2 = l1 + 1
            else:
                l1 = loose_ends/2
                l2 = l1
            self.DNAcoords = self.DNAcoords[self.d_index-l1+self.fixed_i[0]:self.d_index+self.fixed_i[-1]+l2]

        #return self.params
예제 #22
0
def ribbon(r, cg, theta0, N, ld, h0):
    '''
    Creates dyad frames for nucleosomes in a ribbon    
    
    Parameters 
    ----------
    r : float 
        fiber radius
    theta0 : float
        starting angle
    N : int
        number of nucleosomes
    ld : float
        distance between two nucleosomes in the same ribbon
    h0: float
        beginning height of the spiral
    
    Returns
    -------
    coords : list
        list of nucleosome coords
    '''
    def theta(s):
        return s / r + theta0

    def znuc(s):
        return 1.0/np.sqrt(1+cg**2)*np.array([-np.sin(theta(s)),\
                np.cos(theta(s)), cg])

    def xnuc(s):
        return np.array([-np.cos(theta(s)), -np.sin(theta(s)), 0])

    def ynuc(s):
        return np.cross(znuc(s), xnuc(s))

    def fnuc(s):
        return np.array([xnuc(s), ynuc(s), znuc(s)])

    def onuc(s):
        x = r * np.cos(theta(s))
        y = r * np.sin(theta(s))
        z = s * cg + h0
        return np.array([x, y, z])

    ss = np.arange(0, N * ld, ld) + h0 / cg
    onucs = []
    fnucs = []
    cnucs = []
    for s in ss:
        o = onuc(s)
        f = fnuc(s)
        onucs.append(o)
        fnucs.append(f)
        cnucs.append(nuc.of2coords(o, f))

    dfs = []
    for i in range(len(onucs)):

        dna_params, dna_o, dna_f0, c = FMC.GetNuc(norigin=onucs[i],
                                                  nframe=fnucs[i])
        n_dna = HelixPose(dna_params, frame0=dna_f0)

        dyad_coords = nuc.of2coords(n_dna.coord[nucl.d_index] + dna_o,
                                    np.transpose(n_dna.frames[nucl.d_index]))
        dfs.append(dyad_coords)

    return dfs, cnucs
예제 #23
0
from helixmc.pose import HelixPose
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3

# Here we have the final frames of 3 independent HelixMC runs,
# named data0.npz, data1.npz and data3.npz. We will plot these
# data in this example.

# Load data #
pose_list = []
pose_list.append(HelixPose.from_file('data0.npz'))
pose_list.append(HelixPose.from_file('data1.npz'))
pose_list.append(HelixPose.from_file('data2.npz'))

coords = [pose.coord / 10 for pose in pose_list]
colors = 'kbrgycm'

# Top View #
plt.figure()
for i, coord in enumerate(coords):
    plt.plot(coord[:, 0], coord[:, 1], color=colors[i])
plt.ylabel('Y (nm)')
plt.xlabel('X (nm)')
plt.title('Top view')

# Side View #
plt.figure()
for i, coord in enumerate(coords):
    plt.plot(coord[:, 0], coord[:, 2], color=colors[i])
plt.ylabel('Z (nm)')
plt.xlabel('X (nm)')
예제 #24
0
from helixmc.pose import HelixPose

# Run HelixMC #
cmdline = 'helixmc-run '
cmdline += '-params Z-DNA.npz '
cmdline += '-n_bp 100 '
cmdline += '-n_step 10 '
cmdline += '-seq GC '
cmdline += '-force 5 '
cmdline += '-compute_fuller_link '
cmdline += '-out_frame test_run'

print 'Z-DNA command line:', cmdline
subprocess.check_call(cmdline.split())

# Data Analysis #
data = np.load('MC_data.npz')
# avg. z-extension in Å
print 'Avg. Z:', np.average(data['coord_terminal'][:, 2])
# avg. link in radian
print 'Avg. Link:', np.average(data['twist'] + data['writhe'])

# Helix Plotting #
pose = HelixPose.from_file('test_run.npz')
pose.plot_centerline(show=False)  # plot the centerline
plt.title('Center line')

pose.plot_helix(show=False, rb_width=15)  # plot the entire helix
plt.title('Helix Plot')
plt.show()
예제 #25
0
    def from_file(self, input_file):
        '''
        Load pose data from an input file.

        Parameters
        ----------
        input_file : str
        input file (.txt) obtained from w3DNA.

        '''
        self.nuc_type = input_file.split('.')[0]
        if input_file == None:
            input_file = "3LZ0.3DNA"
            print('Default file: ' + input_file)
#        directory = "C:\\Users\\lion\\Desktop\\ChromatinMC\\PDBs\\"
        directory = "PDBs\\3LZ0.3DNA"

#   read protein coords from pdb file

        chains = ReadPdb(directory+ input_file.replace('3DNA','pdb'))
#   get fixed frames
        B = chains['DNA'][3]

        acids = chains['DNA'][1]
        self.step_list = []
        for i in range(len(acids)-1):
            self.step_list.append(acids[i]+acids[i+1])
      
        fixed = []
        for i in range(14):
            j = np.argmin(B)
            fixed.append(j)
            B[j-6:j+6]=np.max(B)

        fixed = np.sort(fixed)
        self.d_index = int(round(np.mean(fixed)))
        self.fixed_i = fixed - self.d_index

        
#   get link coordinates Glu61 (H2A) and Asp24 (H4)
        int_dict={'H2A':60, 'H2A*':60, 'H4':23, 'H4*':23}
        self.l_coords = []
        for locus in int_dict:
            self.l_coords.append(chains[locus][2][int_dict[locus]])
        self.l_coords = np.asarray(self.l_coords)
        
#   read 3DNA file         
#        with open(directory+input_file) as f:
        with open(directory) as f:
            lines = f.read().splitlines()
            
#   Basepair step parameters            
        i=find(lines, lambda x:
        '    step       Shift     Slide      Rise      Tilt      Roll     Twist'
        in x)+1

        j=find(lines[i:], lambda x: '~~~~~~~~~~~' in x)

        self.params=np.zeros((j,6))
        for k in range (0,j):
            if not('----' in lines[i+k]):
                tmp = np.asarray(map(float,lines[i+k].split()[2:]))
            self.params[k:]= np.append(tmp[0:3], np.radians(tmp[3:6]))
        self.n_bp = len(self.params[:,0])+1
        

        
 
        
            
            
        
        

#   Centers of basepairs
        i=find(lines, lambda x: 
        '      bp        Ox        Oy        Oz        Nx        Ny        Nz'
        in x)+1

        coords = np.zeros((j,3))
        frames = np.zeros((j,3,3))
        for k in range (0,j):
            tmp = np.asarray(map(float,lines[i+k].split()[2:]))
            coords[k,:] = tmp[0:3]
            frames[k][0] = tmp[3:6]/np.linalg.norm(tmp[3:6])
            if k is self.d_index:
                self.d_origin = tmp[0:3]
                self.d_frame = tmp[3:6]/np.linalg.norm(tmp[3:6])
        chains['DNA'][2] = coords
        self.chains = chains
        
        
        if self.n_bp > 147:
            loose_ends = 147 - (self.fixed_i[-1]-self.fixed_i[0]+1)
            if loose_ends%2 == 1:
                l1 = loose_ends/2
                l2 = l1 + 1
            else:
                l1 = loose_ends/2
                l2 = l1
            start = self.fixed_i[0] - l1 + self.d_index
            end = self.fixed_i[-1] + l2 +self.d_index
            self.params = self.params[start:end]
            coords = coords[start:end]
            self.d_index = self.d_index-start
#   Dyad frame coords
        nucDNA = HelixPose(self.params)        
        self.d_coords = of2coords(nucDNA.coord[self.d_index], np.transpose(nucDNA.frames[self.d_index]))
        self.coords = nucDNA.coord
        self.frames = nucDNA.frames
#   Nucleosome frame
        self.n_origin, self.n_frame = get_nframe(self.coords, self.d_index, self.fixed_i)
        self.n_coords = of2coords(self.n_origin, self.n_frame)
        

        
#   origin of nucleosomal DNA
        transform = get_transformation(nucDNA.coord[0:len(coords)], Q = coords)   
        framecoords = of2coords(np.zeros(3), np.eye(3))
        framecoords = apply_transf_coords(framecoords, transform)
        self.origin0, self.frame0 = coords2of(framecoords)

#   fixed coordinates of nucleosome
        self.fixed_coord = get_fixed_coord(nucDNA, self.d_index-1, self.fixed_i)
        self.fixed_coord2 = []
        for i in range(0,14):
            self.fixed_coord2.append(get_fixed_coord2(nucDNA, self.d_index-1, \
            self.fixed_i, i))
            
#   create lists of linear transforms of fixed basepair to center of mass
        self.tvs = []
        self.mats = []
        for i in range(0,14):
            index = self.d_index + self.fixed_i[i]
            #multiply those with the frame of the fixed basepair of the dna to get the 
            #frame and position of the nucleosome center of mass
            self.tvs.append(np.dot(np.transpose(self.frames[index]), self.n_coords[0]-self.coords[index]))
            
            self.mats.append(np.dot(np.transpose(self.frames[index]),np.transpose(self.n_frame)))
        
#   stiffnes of fixed basepairs          
        sd_pos = 0.5 # (A)
        k_pos = kBT / sd_pos**2
        self.fixed_k = k_pos
        self.fixed_g = 10*kBT