예제 #1
0
def build_phi_psi_model(pdb_filename):
    parser = PDBParser()
    structure = parser.get_structure("sample", Path(PDBdir, pdb_filename))
    model = structure[0]
    chain = model["A"]
    seq = ""
    phi_diangle = []
    psi_diangle = []
    omega_diangle = []
    for res in chain:
        if res.get_resname() in resdict.keys():

            seq += resdict[res.get_resname()]
            if len(seq) == 1:
                N_prev = res["N"]
                CA_prev = res["CA"]
                C_prev = res["C"]
            else:
                n1 = N_prev.get_vector()
                ca1 = CA_prev.get_vector()
                c1 = C_prev.get_vector()

                C_curr = res["C"]
                N_curr = res["N"]
                CA_curr = res["CA"]

                c = C_curr.get_vector()
                n = N_curr.get_vector()
                ca = CA_curr.get_vector()

                psi = calc_dihedral(n1, ca1, c1, n)  ##goes to current res
                omega = calc_dihedral(ca1, c1, n, ca)
                phi = calc_dihedral(c1, n, ca, c)  ##goes to current res

                phi_diangle.append(phi * 180.0 / math.pi)
                psi_diangle.append(psi * 180.0 / math.pi)
                omega_diangle.append(omega * 180.0 / math.pi)

                N_prev = res["N"]
                CA_prev = res["CA"]
                C_prev = res["C"]

    model_structure_omega = PeptideBuilder.make_structure(
        seq, phi_diangle, psi_diangle, omega_diangle
    )
    model_structure_phi_psi = PeptideBuilder.make_structure(
        seq, phi_diangle, psi_diangle
    )
    return model_structure_omega, model_structure_phi_psi
예제 #2
0
def get_structure_from_angles(aa_list, phi_list, psi_list, omega_list):
    assert len(aa_list) == len(phi_list) + 1 == len(psi_list) + 1 == len(
        omega_list) + 1
    structure = PeptideBuilder.make_structure(
        aa_list, list(map(lambda x: math.degrees(x), phi_list)),
        list(map(lambda x: math.degrees(x), psi_list)),
        list(map(lambda x: math.degrees(x), omega_list)))
    return structure
예제 #3
0
def build_phi_psi_model(pdb_filename):
    parser=PDBParser()
    structure=parser.get_structure('sample', \
                                    path.join(PDBdir, pdb_filename))
    model=structure[0]
    chain=model['A']
    seq=""
    phi_diangle=[]
    psi_diangle=[]
    omega_diangle=[]
    for res in chain:
        if(res.get_resname() in resdict.keys()):
                        
            seq+=resdict[res.get_resname()]
            if(len(seq)==1):
                N_prev=res['N']
                CA_prev=res['CA']
                C_prev=res['C']
            else:   
                n1=N_prev.get_vector()
                ca1=CA_prev.get_vector()
                c1=C_prev.get_vector()
                               
                C_curr=res['C']
                N_curr=res['N']
                CA_curr=res['CA']
                                                
                c=C_curr.get_vector()
                n=N_curr.get_vector()
                ca=CA_curr.get_vector()

                psi= calc_dihedral(n1, ca1, c1, n) ##goes to current res
                omega= calc_dihedral(ca1, c1, n, ca)
                phi= calc_dihedral(c1, n, ca, c) ##goes to current res

                phi_diangle.append(phi*180.0/math.pi)
                psi_diangle.append(psi*180.0/math.pi)
                omega_diangle.append(omega*180.0/math.pi)

                N_prev=res['N']
                CA_prev=res['CA']
                C_prev=res['C']
                                
    model_structure_omega= PeptideBuilder.make_structure( seq, phi_diangle, psi_diangle, omega_diangle )
    model_structure_phi_psi= PeptideBuilder.make_structure( seq, phi_diangle, psi_diangle)
    return model_structure_omega, model_structure_phi_psi   
예제 #4
0
def torsion_to_3d(aa, phi, psi):
    phi, psi = phi[1:], psi[:-1]
    recon_struct = PeptideBuilder.make_structure(aa, phi, psi)
    atoms = recon_struct.get_atoms()
    coords = list()
    for atom in atoms:
        coords.append(atom.get_coord())
    return np.array(coords)
예제 #5
0
def get_pdb_from_torsion(aa_seq, phis, psis, save_path):
    #phis is of length n, disregard first one
    #psis is of length n, disregard the last one
    #aa_seq is a string of amino acids encoded by capital letters
    phis = phis[1:]
    psis = psis[:-1]
    my_reconstruct = PeptideBuilder.make_structure(aa_seq, phis, psis)
    out = Bio.PDB.PDBIO()
    out.set_structure(my_reconstruct)
    out.save(save_path)
def test_make_structure():
    phi_list = []
    psi_im1_list = []

    for i in range(1, 20):
        phi_list.append(-60 + i)
        psi_im1_list.append(-40 - i)
    structure = PeptideBuilder.make_structure("ACDEFGHIKLMNPQRSTVWY", phi_list,
                                              psi_im1_list)
    assert compare_to_reference(structure, "helix.pdb")
예제 #7
0
파일: util.py 프로젝트: awilson98/project
def get_structure_from_angles(aa_list_encoded, angles):
    aa_list = protein_id_to_str(aa_list_encoded)
    omega_list = angles[1:, 0]
    phi_list = angles[1:, 1]
    psi_list = angles[:-1, 2]
    assert len(aa_list) == len(phi_list) + 1 == len(psi_list) + 1 == len(omega_list) + 1
    structure = PeptideBuilder.make_structure(aa_list,
                                              list(map(lambda x: math.degrees(x), phi_list)),
                                              list(map(lambda x: math.degrees(x), psi_list)),
                                              list(map(lambda x: math.degrees(x), omega_list)))
    return structure
예제 #8
0
def find_max(length):
    global seq, file, seq_to_pdb, pdb_to_seq
    seq = 'W' * length
    out = Bio.PDB.PDBIO()
    i = pb.make_structure(seq, [180] * len(seq), [180] * len(seq))
    out.set_structure(i)
    out.save("ignore.pdb")
    cleaning.cleanATOM("ignore.pdb", out_file=d + "\\ignore", ext='.pdb')
    file = pd.parsePDB("ignore.pdb")
    seq, seq_to_pdb, pdb_to_seq = find_seq(file)
    final = main_calc(seq)
    atom_length = len(final['primary'])
    eucl_length = final['secondary'].max()
    return atom_length, eucl_length
def test_make_structure():
    """
    Build a helix containing all 20 amino acids, with slowly varying
    backbone angles, using make_structure().
    The resulting structure should be identical to `helix.pdb`
    """
    phi_list = []
    psi_im1_list = []

    for i in range(1, 20):
        phi_list.append(-60 + i)
        psi_im1_list.append(-40 - i)
    structure = PeptideBuilder.make_structure(
        "ACDEFGHIKLMNPQRSTVWY", phi_list, psi_im1_list
    )
    assert compare_to_reference(structure, "helix.pdb")
def test_make_structure2():
    phi_list = []
    psi_im1_list = []
    omega_list = []

    for i in range(1, 20):
        phi_list.append(-60 + i)
        psi_im1_list.append(-40 - i)
        omega_list.append(180)

    for i in range(9, 19):
        omega_list[i] = -178

    structure = PeptideBuilder.make_structure("ACDEFGHIKLMNPQRSTVWY", phi_list,
                                              psi_im1_list, omega_list)
    assert compare_to_reference(structure, "helix2.pdb")
예제 #11
0
def main():
    pdb_dir = 'data/pdb/'
    pdb_prefix = 'pdb'
    pdb_suffix = '.ent'

    datafile = 'testing.pkl'
    data = load_data(datafile)
    pdbs, lengths, chains, aas, q8s, dcalphas, coords, phis, psis, pssms = data

    # reconstruct from phis, psi
    for index in range(4, 5):  #len(pdbs)):
        pdb = pdbs[index]
        chain_index = chains[index]
        aa = aas[index]
        phi = phis[index][1:]  # omit first None
        psi = psis[index][:-1]  # omit last None

        coord = coords[index]
        angles = compute_dihedral_list(torch.from_numpy(np.array(coord)))
        set_trace()
        out = Bio.PDB.PDBIO()
        #pdb_path = pdb_dir + pdb_prefix + pdb + pdb_suffix
        #structure = Bio.PDB.PDBParser(QUIET=True).get_structure(pdb_path[:-4], pdb_path)
        #ppb = PPBuilder()
        #model = ppb.build_peptides(structure)

        #for chain in model

        #for chain in structure.get_chains():
        #       print(chain.get_id())
        #print(structure[0])
        out.set_structure(structure[0]['A'])
        out.save("chain_a.pdb")
        out.set_structure(structure[0]['B'])
        out.save("chain_b.pdb")

        print('pdb', pdb)
        #print('aa', aa)
        #print('phi', phi)
        #print('psi', psi)
        #print('coord',coord)

        recon_struct = PeptideBuilder.make_structure(aa, phi, psi)
        recon_pdb = Bio.PDB.PDBIO()
        recon_pdb.set_structure(recon_struct)
        recon_pdb.save('reconstruct.pdb')
예제 #12
0
def get_structure_from_angles(aa_list_encoded, angles):
    aa_list = protein_id_to_str(aa_list_encoded)
    omega_list = angles[1:, 0]
    phi_list = angles[1:, 1]
    psi_list = angles[:-1, 2]
    assert len(aa_list) == len(phi_list) + 1 == len(psi_list) + 1 == len(
        omega_list) + 1

    print("PREDICTION RESULTS")
    print("AALIST", aa_list)
    print("PHI", list(map(lambda x: math.degrees(x), phi_list)))
    print("PHI len", len(list(map(lambda x: math.degrees(x), phi_list))))
    time.sleep(100000)
    structure = PeptideBuilder.make_structure(
        aa_list, list(map(lambda x: math.degrees(x), phi_list)),
        list(map(lambda x: math.degrees(x), psi_list)),
        list(map(lambda x: math.degrees(x), omega_list)))
    return structure
예제 #13
0
def first_structure_helix(seq_query, seq_template, structure_file,
                          output_file):
    """ This function writes a linear 3D structure of a query protein sequence
        in a pdb file. All positions are first set with phi and psi angle from
        beta strand structure. Template structural information in used to set
        phi and psi angles of positions matching a position in template, with 
        an alpha helix conformation, to alpha helix psi and phi angle values.
        
        Parameters:
            - seq_query : a string representing aligned query sequence.
            - seq_template : a string representing aligned template sequence.
            - structure_file : a string representing a path to a file 
            containing structural information extracted from a dssp file of 
            template.
            - output_file : a string representing a path where to write output
            pdb. 
    """
    #Create a temprary file with template secondary structural information
    align_dict = mk_align_dict(seq_query, seq_template)
    seq = seq_query.replace("-", "")
    #angles default values
    phi_list = [-120 for i in range(len(seq))]
    psi_list = [120 for i in range(len(seq))]

    # Building the first structure with alpha helix
    # Phi/Psi angles detection from template structure
    with open(structure_file, "r") as filin:
        print("Looking for alpha helix...")
        pos = 1
        for line in filin:
            # on extrait le premier et le deuxieme champ de chaque ligne (index?)
            columns = line[:-1].split(";")
            if (pos in align_dict) and (columns[2] == "aH"
                                        or columns[2] == "aI"):
                #angles value for alpha helix
                phi_list[align_dict[pos] - 1] = -57.8
                psi_list[align_dict[pos] - 1] = -47.0
            pos = pos + 1
    #building the pdb file
    struct = PeptideBuilder.make_structure(seq, phi_list, psi_list)
    opt = Bio.PDB.PDBIO()
    opt.set_structure(struct)
    opt.save(output_file)
예제 #14
0
def write_to_pdb_strcture(atomic_coords, aaSequence, prot_id):
    _aa_dict_inverse = {v: k for k, v in AA_ID_DICT.items()}
    atomic_coords = list([Vector(v) for v in atomic_coords.numpy()])
    aa_list = []
    phi_list = []
    psi_list = []
    omega_list = []
    for i, coord in enumerate(atomic_coords):
        if int(aaSequence[int(i / 3)]) == 0:
            print("Reached end of protein, stopping")
            break

        if i % 3 == 0:
            aa_symbol = _aa_dict_inverse[int(aaSequence[int(i / 3)])]
            aa_list.append(aa_symbol)

            if i != 0:
                phi_list.append(
                    math.degrees(
                        Bio.PDB.calc_dihedral(atomic_coords[i - 1],
                                              atomic_coords[i],
                                              atomic_coords[i + 1],
                                              atomic_coords[i + 2])))
            if i + 3 < len(atomic_coords) and int(
                    aaSequence[int(i / 3) + 1]) != 0:
                psi_list.append(
                    math.degrees(
                        Bio.PDB.calc_dihedral(atomic_coords[i],
                                              atomic_coords[i + 1],
                                              atomic_coords[i + 2],
                                              atomic_coords[i + 3])))
                omega_list.append(
                    math.degrees(
                        Bio.PDB.calc_dihedral(atomic_coords[i + 1],
                                              atomic_coords[i + 2],
                                              atomic_coords[i + 3],
                                              atomic_coords[i + 4])))

    out = Bio.PDB.PDBIO()
    structure = PeptideBuilder.make_structure(aa_list, phi_list, psi_list,
                                              omega_list)
    out.set_structure(structure)
    out.save("output/protein_" + str(prot_id) + ".pdb")
def test_make_structure2():
    """
    Build a helix containing all 20 amino acids, with slowly varying
    backbone angles, using make_structure(). Now we're changing omega also.
    The first half of the resulting structure should be identical to
    `helix.pdb`, while the second half should be slightly different.
    """
    phi_list = []
    psi_im1_list = []
    omega_list = []

    for i in range(1, 20):
        phi_list.append(-60 + i)
        psi_im1_list.append(-40 - i)
        omega_list.append(180)

    for i in range(9, 19):
        omega_list[i] = -178

    structure = PeptideBuilder.make_structure(
        "ACDEFGHIKLMNPQRSTVWY", phi_list, psi_im1_list, omega_list
    )
    assert compare_to_reference(structure, "helix2.pdb")
예제 #16
0
def constructStr(seq, Phi, Psi, NumofStructGen):
    """"Construct structures based on given Phi and Psi angle ensembles."""
    SeqLen = len(Phi[:, 0])
    iCount = 0
    PhiOut = np.zeros((int(SeqLen), int(NumofStructGen)))
    PsiOut = np.zeros((int(SeqLen), int(NumofStructGen)))
    for j in range(10 * NumofStructGen):
        model_structure_phi_psi = PeptideBuilder.make_structure(
            seq, Phi[:, j], Psi[:, j])
        Clashes = disCheck(model_structure_phi_psi)
        if Clashes == False:
            PhiOut[:, iCount] = Phi[:, j]
            PsiOut[:, iCount] = Psi[:, j]

            iCount = iCount + 1
            if iCount % 100 == 0:
                print(iCount)
            out = PDBIO()
            out.set_structure(model_structure_phi_psi)
            name = 'output' + str(iCount) + '.pdb'
            out.save('./PDBOUT/' + name)
        if iCount > (NumofStructGen - 1):
            break
    return PhiOut, PsiOut
예제 #17
0
def to_pdb(aa, phi, psi, path):
    phi, psi = phi[1:], psi[:-1]
    struct = PeptideBuilder.make_structure(aa, phi, psi)
    out = Bio.PDB.PDBIO()
    out.set_structure(struct)
    out.save(path)
예제 #18
0
    geos.append(Geometry.geometry(aa))
structure = PeptideBuilder.make_structure_from_geos(geos)  
out.set_structure(structure)
out.save("test5.pdb")


# Build a helix containing all 20 amino acids, with slowly varying
# backbone angles, using make_structure().
# The resulting structure should be identical to test2.pdb
phi_list = []
psi_im1_list = []

for i in range(1,20):
    phi_list.append(-60+i)
    psi_im1_list.append(-40-i)
structure = PeptideBuilder.make_structure("ACDEFGHIKLMNPQRSTVWY",\
                                                phi_list, psi_im1_list)
out.set_structure(structure)
out.save("test6.pdb")

# Build a helix containing all 20 amino acids, with slowly varying
# backbone angles, using make_structure().
# The first half of the resulting structure should be identical to
# test6.pdb, while the second half should be slightly different.
phi_list = []
psi_im1_list = []
omega_list = []

for i in range(1,20):
    phi_list.append(-60+i)
    psi_im1_list.append(-40-i)
    omega_list.append(180)