Esempio n. 1
0
def replace_tail(sasmol, basis_to_python):
    # mv_A_to_E()

    mono_file = '../../1KX5_tailfold/1KX5tailfold_167bp.pdb'
    ncp = sasmol.SasMol(0)
    ncp.read_pdb(mono_file)
    replace_basis = basis_to_python.parse_basis('chain E and resid < 40')
    error, replace_mask = ncp.get_subset_mask(replace_basis)
    print sum(replace_mask)

    histone_file = '1KX5tailfold_A2E_2.pdb'
    new_histone = sasmol.SasMol(0)
    new_histone.read_pdb(histone_file)
    print new_histone.coor().shape
    part_histone = sasmol.SasMol(0)

    part_basis = basis_to_python.parse_basis('resid < 40')
    error, part_mask = new_histone.get_subset_mask(part_basis)
    new_histone.copy_molecule_using_mask(part_histone, part_mask, 0)

    ncp.set_coor_using_mask(part_histone, 0, replace_mask)
    ncp.write_pdb('1KX5tailfold_fxd2.pdb', 0, 'w')
def replace_tail(sasmol, basis_to_python):
    # mv_A_to_E()

    mono_file = '../../1KX5_tailfold/1KX5tailfold_167bp.pdb'
    ncp = sasmol.SasMol(0)
    ncp.read_pdb(mono_file)
    replace_basis = basis_to_python.parse_basis('chain E and resid < 40')
    error, replace_mask = ncp.get_subset_mask(replace_basis)
    print sum(replace_mask)

    histone_file = '1KX5tailfold_A2E_2.pdb'
    new_histone = sasmol.SasMol(0)
    new_histone.read_pdb(histone_file)
    print new_histone.coor().shape
    part_histone = sasmol.SasMol(0)

    part_basis = basis_to_python.parse_basis('resid < 40')
    error, part_mask = new_histone.get_subset_mask(part_basis)
    new_histone.copy_molecule_using_mask(part_histone, part_mask, 0)

    ncp.set_coor_using_mask(part_histone, 0, replace_mask)
    ncp.write_pdb('1KX5tailfold_fxd2.pdb', 0, 'w')
Esempio n. 3
0
def get_tetramer_axes(pdb, ncp_dna_resids, dna_ids, ncp_dyad_resids,
                      ncp_ref_atom_resids, array=None):
    pkl_file = pdb[:-3] + 'pkl'
    try:
        pkl_in = open(pkl_file, 'rb')
        load_masks = True
        all_ncp_bases = pickle.load(pkl_in)
        all_ncp_masks = pickle.load(pkl_in)
        all_dyad_bases = pickle.load(pkl_in)
        all_dyad_masks = pickle.load(pkl_in)
        all_ref_atom_masks = pickle.load(pkl_in)
        all_ncp_origins = pickle.load(pkl_in)
        all_ncp_axes = pickle.load(pkl_in)
        all_ncp_opt_params = pickle.load(pkl_in)
        all_ncp_dyad_mol = pickle.load(pkl_in)
        all_ncp_plot_vars = pickle.load(pkl_in)
        pkl_in.close()
        print 'using masks from: %s' % pkl_file
    except:
        if 'load_masks' in locals():
            pkl_in.close()
        load_masks = False
        n_ncps = len(ncp_dna_resids)
        all_ncp_bases = [None] * n_ncps
        all_ncp_masks = [None] * n_ncps
        all_dyad_bases = [None] * n_ncps
        all_dyad_masks = [None] * n_ncps
        all_ref_atom_masks = [None] * n_ncps
        all_ncp_origins = [None] * n_ncps
        all_ncp_axes = [None] * n_ncps
        all_ncp_opt_params = [None] * n_ncps
        all_ncp_dyad_mol = [None] * n_ncps
        all_ncp_plot_vars = [None] * n_ncps
        print 'creating masks from input variables'

    # check if pdb is a filename or a sasmol object
    if not array:
        array = sasmol.SasMol(0)
        array.read_pdb(pdb)

    # # re-orient the array
    # coor = array.coor()
    # coor[0] = geometry.transform_coor(coor[0], np.array([1, 0, 0]),
        # np.array([0, 0, 0]))
    # array.setCoor(coor)
    # array.write_pdb('gH5c11_r.pdb', 0, 'w')

    for (i, resids) in enumerate(ncp_dna_resids):
        print 'fitting NCP %d' % (i + 1)
        if load_masks:
            ncp_mask = all_ncp_masks[i]
            dyad_mask = all_dyad_masks[i]
            ncp_opt_params = all_ncp_opt_params[i]
            ref_atom_mask = all_ref_atom_masks[i]
        else:
            ncp_basis_vmd = ("((segname %s and resid >= %d and resid <=  %d) or"
                             " (segname %s and resid <= %d and resid >= %d) ) "
                             "and name C1' "
                             % (dna_ids[i][0], resids[0, 0], resids[1, 0],
                                dna_ids[i][1], resids[0, 1], resids[1, 1]))
            ncp_basis = basis_to_python.parse_basis(ncp_basis_vmd)
            error, ncp_mask = array.get_subset_mask(ncp_basis)
            assert not error, error

            dyad_basis = ('( segname[i] == "%s" and resid[i] == %d ) or'
                          '( segname[i] == "%s" and resid[i] == %d )'
                          % (dna_ids[i][0], ncp_dyad_resids[i][0],
                             dna_ids[i][1], ncp_dyad_resids[i][1]))
            error, dyad_mask = array.get_subset_mask(dyad_basis)
            assert not error, error

            ref_atom_basis_vmd = ("(segname %s and resid %d and name C1\')" %
                                  (dna_ids[i][0], ncp_ref_atom_resids[i]))
            ref_atom_basis = basis_to_python.parse_basis(ref_atom_basis_vmd)
            error, ref_atom_mask = array.get_subset_mask(ref_atom_basis)
            assert not error, error

            ncp_opt_params = None
            all_ncp_bases[i] = ncp_basis
            all_ncp_masks[i] = ncp_mask
            all_dyad_bases[i] = dyad_basis
            all_dyad_masks[i] = dyad_mask
            all_ref_atom_masks[i] = ref_atom_mask

        debug = not load_masks
        (ncp_origin, ncp_axes, ncp_opt_params, ncp_dyad_mol, ncp_plot_vars
         ) = geometry.get_ncp_origin_and_axes(ncp_mask, dyad_mask, dna_ids[i],
                                              array, ref_atom_mask, debug=debug,
                                              prev_opt_params=ncp_opt_params)

        # store all the variables for debug purposes
        all_ncp_origins[i] = ncp_origin
        all_ncp_axes[i] = ncp_axes
        all_ncp_opt_params[i] = ncp_opt_params
        all_ncp_dyad_mol[i] = ncp_dyad_mol
        all_ncp_plot_vars[i] = ncp_plot_vars

    if not load_masks:
        print 'saving masks and other results to: %s' % pkl_file
        pkl_out = open(pkl_file, 'wb')
        pickle.dump(all_ncp_bases, pkl_out, -1)
        pickle.dump(all_ncp_masks, pkl_out, -1)
        pickle.dump(all_dyad_bases, pkl_out, -1)
        pickle.dump(all_dyad_masks, pkl_out, -1)
        pickle.dump(all_ref_atom_masks, pkl_out, -1)
        pickle.dump(all_ncp_origins, pkl_out, -1)
        pickle.dump(all_ncp_axes, pkl_out, -1)
        pickle.dump(all_ncp_opt_params, pkl_out, -1)
        pickle.dump(all_ncp_dyad_mol, pkl_out, -1)
        pickle.dump(all_ncp_plot_vars, pkl_out, -1)
        pkl_out.close()
    return all_ncp_plot_vars, all_ncp_axes, all_ncp_origins
Esempio n. 4
0
def main(inputs):

    run_name = inputs.run_name
    dcd_name = inputs.dcd_name
    dcd_path = inputs.dcd_path
    pdb_name = inputs.pdb_name
    pdb_path = inputs.pdb_path

    foxs_exe = inputs.foxs_exe
    try:
        max_q = inputs.max_q
    except:
        max_q = 0.2
    try:
        num_points = inputs.num_points
    except:
        num_points = 50
    try:
        basis = inputs.basis
    except:
        basis = 'all'
    # n_cpus     = inputs.n_cpus # not fully implemented for parallel
    n_cpus = 1

    pdb_full_name = inputs.pdb_full_name = op.join(pdb_path, pdb_name)
    dcd_full_name = inputs.dcd_full_name = op.join(dcd_path, dcd_name)

    # check the input
    assert op.exists(dcd_full_name), 'ERROR: no such file "%s"' % dcd_full_name
    assert op.exists(pdb_full_name), 'ERROR: no such file "%s"' % pdb_full_name
    assert op.exists(foxs_exe), 'ERROR: no such file "%s"' % foxs_exe

    foxs_path = inputs.foxs_path = op.join(run_name, 'foxs')
    if op.exists(foxs_path):
        print 'WARNING: run folder exists (%s), moving it\n' % foxs_path
        append_bk(foxs_path)
    else:
        print 'created foxs output folder: %s' % foxs_path
    mkdir_p(foxs_path)

    # run foxs instance on each folder
    py_basis = b2p.parse_basis(basis)
    # split the dcd into subfolders
    sub_dirs, sub_dcd_names, first_last = split_dcd(pdb_full_name,
                                                    dcd_full_name, n_cpus,
                                                    foxs_path)
    processes = []

    if n_cpus > 1:
        for cpu in xrange(n_cpus):  # setup the processes
            foxs_args = (sub_dirs[cpu], sub_dcd_names[cpu], first_last[cpu],
                         pdb_full_name, foxs_exe, py_basis, max_q, num_points)
            processes.append(mp.Process(target=foxs, args=foxs_args))

        for p in processes:  # start the processes
            p.start()

        for p in processes:  # exit the completed processes
            p.join()
    else:
        foxs(sub_dirs[0], sub_dcd_names[0], first_last[0], pdb_full_name,
             foxs_exe, py_basis, max_q, num_points)

    print 'finished %d foxs calculations\n' % first_last[-1][1]
Esempio n. 5
0
def main(inputs):

    run_name = inputs.run_name
    dcd_name = inputs.dcd_name
    dcd_path = inputs.dcd_path
    pdb_name = inputs.pdb_name
    pdb_path = inputs.pdb_path

    foxs_exe = inputs.foxs_exe
    try:
        max_q = inputs.max_q
    except:
        max_q = 0.2
    try:
        num_points = inputs.num_points
    except:
        num_points = 50
    try:
        basis = inputs.basis
    except:
        basis = 'all'
    # n_cpus     = inputs.n_cpus # not fully implemented for parallel
    n_cpus = 1

    pdb_full_name = inputs.pdb_full_name = op.join(pdb_path, pdb_name)
    dcd_full_name = inputs.dcd_full_name = op.join(dcd_path, dcd_name)

    # check the input
    assert op.exists(dcd_full_name), 'ERROR: no such file "%s"' % dcd_full_name
    assert op.exists(pdb_full_name), 'ERROR: no such file "%s"' % pdb_full_name
    assert op.exists(foxs_exe), 'ERROR: no such file "%s"' % foxs_exe

    foxs_path = inputs.foxs_path = op.join(run_name, 'foxs')
    if op.exists(foxs_path):
        print 'WARNING: run folder exists (%s), moving it\n' % foxs_path
        append_bk(foxs_path)
    else:
        print 'created foxs output folder: %s' % foxs_path
    mkdir_p(foxs_path)

    # run foxs instance on each folder
    py_basis = b2p.parse_basis(basis)
    # split the dcd into subfolders
    sub_dirs, sub_dcd_names, first_last = split_dcd(
        pdb_full_name, dcd_full_name, n_cpus, foxs_path)
    processes = []

    if n_cpus > 1:
        for cpu in xrange(n_cpus):  # setup the processes
            foxs_args = (sub_dirs[cpu], sub_dcd_names[cpu], first_last[cpu],
                         pdb_full_name, foxs_exe, py_basis, max_q, num_points)
            processes.append(mp.Process(target=foxs, args=foxs_args))

        for p in processes:  # start the processes
            p.start()

        for p in processes:  # exit the completed processes
            p.join()
    else:
        foxs(sub_dirs[0], sub_dcd_names[0], first_last[0], pdb_full_name,
             foxs_exe, py_basis, max_q, num_points)

    print 'finished %d foxs calculations\n' % first_last[-1][1]