예제 #1
0
def get_angles(dcd_file_name, pdb_file_name, first_last_resid, flex_file, nf=0):
    from dna.ds_dna_monte_carlo import read_flex_resids

    txtOutput = []

    out_file = open(dcd_file_name[:-4] + '.ddat', 'w')

    # read flex file
    # flex_file = pdb_file_name[:-3] + 'flex'
    (segnames, flex_resids) = read_flex_resids(flex_file)

    segname = segnames[0]

    numranges = 0
    resid_old = -999.999  # any number that is not an int
    for resid_new in flex_resids[:, 0]:
        if resid_new != resid_old + 1:
            numranges += 1
        resid_old = resid_new

    res_low = [flex_resids[0, 0]]
    n_cont = [len(flex_resids[:, 0])]
    flexible_residues = dmc.get_flexible_residues(numranges, res_low, n_cont)

    molecule_type = "dna"

    mol = sasmol.SasMol(0)
    mol.read_pdb(pdb_file_name)

    residue_rotation_indices, residue_rotation_mask = dmc.get_rotation_indices(
        mol, molecule_type, flexible_residues, txtOutput)

    # print "residue_rotation_indices = ",residue_rotation_indices

    # first_last_resid = [flexible_residues[0], flexible_residues[-1]]

    alpha = []
    beta = []
    gamma = []
    delta = []     # <--- significant
    epsilon = []
    zeta = []
    chi = []       # <--- significant

    all_alpha = []
    all_beta = []
    all_gamma = []
    all_delta = []     # <--- significant
    all_epsilon = []
    all_zeta = []
    all_chi = []       # <--- significant

    dcdfile = mol.open_dcd_read(dcd_file_name)
    if nf == 0:
        nf = dcdfile[2]  # number of frames

    # reslist = range(first_last_resid[0],first_last_resid[1]+1)
    # print 'reslist = ',reslist

    st1 = "# base\talpha\tbeta\tgamma\tdelta\tepsilon\tzeta\tchi\n"
    out_file.write("%s" % (st1))

    res_mol = sasmol.SasMol(0)

    for i in xrange(nf):

        mol.read_dcd_step(dcdfile, i)
        coor = mol.coor()
        out_file.write("# frame %d\n" % (i + 1))

        for res in xrange(n_cont[0]):
            q0 = res_low[0] + res
            error, res_mask = mol.get_subset_mask(
                "(resid[i] == " + str(q0) + ")")
            mol.copy_molecule_using_mask(res_mol, res_mask, 0)
            st = '%s %d' % (res_mol.resname()[0][0], q0)

            # get the indices and mask for this residue
            indices = residue_rotation_indices[q0]
            this_mask = numpy.array(residue_rotation_mask[q0])

            # alpha
            alpha_angle = dr.measure(coor, indices, "alpha", this_mask, q0,
                                     first_last_resid, molecule_type)
            str_alpha_angle = '%.1f' % alpha_angle
            all_alpha.append(alpha_angle)
            st = st + '\t' + str_alpha_angle
            logging.debug('alpha: ' + str_alpha_angle)

            # beta
            beta_angle = dr.measure(coor, indices, "beta", this_mask, q0,
                                    first_last_resid, molecule_type)
            str_beta_angle = '%.1f' % (beta_angle)
            all_beta.append(beta_angle)
            st = st + '\t' + str_beta_angle
            logging.debug('beta: ' + str_beta_angle)

            # gamma
            gamma_angle = dr.measure(coor, indices, "gamma", this_mask, q0,
                                     first_last_resid, molecule_type)
            str_gamma_angle = '%.1f' % (gamma_angle)
            all_gamma.append(gamma_angle)
            st = st + '\t' + str_gamma_angle
            logging.debug('gamma: ' + str_gamma_angle)

            # delta
            delta_angle = dr.measure(coor, indices, "delta", this_mask, q0,
                                     first_last_resid, molecule_type)
            str_delta_angle = '%.1f' % (delta_angle)
            all_delta.append(delta_angle)
            st = st + '\t' + str_delta_angle
            logging.debug('delta: ' + str_delta_angle)

            # epsilon
            epsilon_angle = dr.measure(coor, indices, "epsilon", this_mask, q0,
                                       first_last_resid, molecule_type)
            str_epsilon_angle = '%.1f' % (epsilon_angle)
            all_epsilon.append(epsilon_angle)
            st = st + '\t' + str_epsilon_angle
            logging.debug('epsilon: ' + str_epsilon_angle)

            # zeta
            zeta_angle = dr.measure(coor, indices, "zeta", this_mask, q0,
                                    first_last_resid, molecule_type)
            str_zeta_angle = '%.1f' % (zeta_angle)
            all_zeta.append(zeta_angle)
            st = st + '\t' + str_zeta_angle
            logging.debug('zeta: ' + str_zeta_angle)

            # chi
            chi_angle = dr.measure(coor, indices, "chi", this_mask, q0,
                                   first_last_resid, molecule_type)
            str_chi_angle = '%.1f' % (chi_angle)
            all_chi.append(chi_angle)
            st = st + '\t' + str_chi_angle
            logging.debug('alpha: ' + str_alpha_angle)

            out_file.write("%s\n" % (st))

    all_angles = [all_alpha, all_beta, all_gamma, all_delta, all_epsilon,
                  all_zeta, all_chi]

    out_file.close()

    print '\nsuccessfully finished calculating dihedrals \_/'
    return all_angles
def initialize_system(m1, molecule_type, basis, numranges, reslow, numcont):

    resid = m1.resid()
    first_last_resid = [resid[0], resid[-1]]

    print 'first_last_resid = ', first_last_resid

    print 'resid = ', resid

    txtOutput = None

    if (molecule_type == 'protein'):
        basis_filter = 'name[i] == "' + basis + '"'
        error, basis_mask = m1.get_subset_mask(basis_filter)
        check_error(error)
        basis_m1 = sasmol.SasMol(1)
        error = m1.copy_molecule_using_mask(basis_m1, basis_mask, 0)
        check_error(error)
        basis_resname = basis_m1.resname()
        basis_resid = basis_m1.resid()

        print 'reslow = ', reslow
        print 'numcont = ', numcont
        print 'numranges = ', numranges
        print 'basis_resname = ', basis_resname
        print 'basis_resid = ', basis_resid

        respsi = []
        resphi = []
        dihedral_energy.protein_initialization(respsi, resphi, basis_resid,
                                               basis_resname, numranges,
                                               reslow, numcont,
                                               first_last_resid, txtOutput)
        dihedral_parameters = [respsi, resphi]
    elif (molecule_type == 'rna'):
        #rna_filter = 'name[i] == "P"'
        #rna_filter = 'name[i] == "O5\'"'
        rna_filter = 'name[i] == "' + basis + '"'
        error, basis_mask = m1.get_subset_mask(rna_filter)
        basis_m1 = sasmol.SasMol(1)
        error = m1.copy_molecule_using_mask(basis_m1, basis_mask, 0)
        basis_resname = basis_m1.resname()
        basis_resid = basis_m1.resid()

        print 'sum(basis_mask) rna = ', sum(basis_mask)
        print 'len(resid) rna = ', len(resid)
        resalpha = []
        resbeta = []
        resgamma = []
        resdelta = []
        resepsilon = []
        reseta = []
        dihedral_energy.rna_initialization(resalpha, resbeta, resgamma,
                                           resdelta, resepsilon, reseta,
                                           basis_resid, basis_resname,
                                           numranges, reslow, numcont,
                                           first_last_resid, txtOutput)
        dihedral_parameters = [
            resalpha, resbeta, resgamma, resdelta, resepsilon, reseta
        ]

    print 'dihedral parameters = ', dihedral_parameters

    flexible_residues = dihedral_monte_carlo.get_flexible_residues(
        numranges, reslow, numcont)

    print 'molecule_type = ', molecule_type

    residue_rotation_indices, residue_rotation_mask = dihedral_monte_carlo.get_rotation_indices(
        m1, molecule_type, flexible_residues, txtOutput)

    step_parameters = step.Setup()

    return dihedral_parameters, flexible_residues, residue_rotation_indices, residue_rotation_mask, step_parameters, first_last_resid
예제 #3
0
def initialize_system(m1, molecule_type, basis, numranges, reslow, numcont):

    resid = m1.resid()
    first_last_resid = [resid[0], resid[-1]]

    print 'first_last_resid = ', first_last_resid

    print 'resid = ', resid

    txtOutput = None

    if(molecule_type == 'protein'):
        basis_filter = 'name[i] == "' + basis + '"'
        error, basis_mask = m1.get_subset_mask(basis_filter)
        check_error(error)
        basis_m1 = sasmol.SasMol(1)
        error = m1.copy_molecule_using_mask(basis_m1, basis_mask, 0)
        check_error(error)
        basis_resname = basis_m1.resname()
        basis_resid = basis_m1.resid()

        print 'reslow = ', reslow
        print 'numcont = ', numcont
        print 'numranges = ', numranges
        print 'basis_resname = ', basis_resname
        print 'basis_resid = ', basis_resid

        respsi = []
        resphi = []
        dihedral_energy.protein_initialization(
            respsi, resphi, basis_resid, basis_resname, numranges, reslow, numcont, first_last_resid, txtOutput)
        dihedral_parameters = [respsi, resphi]
    elif(molecule_type == 'rna'):
        #rna_filter = 'name[i] == "P"'
        #rna_filter = 'name[i] == "O5\'"'
        rna_filter = 'name[i] == "' + basis + '"'
        error, basis_mask = m1.get_subset_mask(rna_filter)
        basis_m1 = sasmol.SasMol(1)
        error = m1.copy_molecule_using_mask(basis_m1, basis_mask, 0)
        basis_resname = basis_m1.resname()
        basis_resid = basis_m1.resid()

        print 'sum(basis_mask) rna = ', sum(basis_mask)
        print 'len(resid) rna = ', len(resid)
        resalpha = []
        resbeta = []
        resgamma = []
        resdelta = []
        resepsilon = []
        reseta = []
        dihedral_energy.rna_initialization(resalpha, resbeta, resgamma, resdelta, resepsilon,
                                           reseta, basis_resid, basis_resname, numranges, reslow, numcont, first_last_resid, txtOutput)
        dihedral_parameters = [
            resalpha, resbeta, resgamma, resdelta, resepsilon, reseta]

    print 'dihedral parameters = ', dihedral_parameters

    flexible_residues = dihedral_monte_carlo.get_flexible_residues(
        numranges, reslow, numcont)

    print 'molecule_type = ', molecule_type

    residue_rotation_indices, residue_rotation_mask = dihedral_monte_carlo.get_rotation_indices(
        m1, molecule_type, flexible_residues, txtOutput)

    step_parameters = step.Setup()

    return dihedral_parameters, flexible_residues, residue_rotation_indices, residue_rotation_mask, step_parameters, first_last_resid