def create_PDB(seq, phi, psi, output): try: import Bio.PDB except ImportError: raise ImportError( "You need to have BioPython installed to convert peptide sequences to structures" ) try: from PeptideBuilder import Geometry import PeptideBuilder except ImportError: try: import Geometry import PeptideBuilder except ImportError: raise ImportError( "You need to have the Python module PeptideBuilder installed to convert peptide sequences to structures" ) geo = Geometry.geometry(seq[0]) struc = PeptideBuilder.initialize_res(geo) for aa in seq[1:]: struc = PeptideBuilder.add_residue(struc, aa, phi, psi) out = Bio.PDB.PDBIO() out.set_structure(struc) out.save(output)
def test_PeptideBuilder(pdb_code): # retrieve pdb file pdb_file = "%s_clean.pdb" % (pdb_code) # build backbone model from all angles and bond lengths structure_backbone= PeptideBuilder.make_structure_from_geos(build_backbone_model(pdb_file)) # build backbone model from all angles structure_all_angles= PeptideBuilder.make_structure_from_geos(build_all_angles_model(pdb_file)) # build models from dihedral angles only structure_omega, structure_phi_psi=build_phi_psi_model(pdb_file) # compare models to original structure RMS_backbone_50, RMS_backbone_150, RMS_backbone, size= compare_structure(pdb_file, make_pdb_file(structure_backbone, "Backbone_" + pdb_file)) RMS_phi_psi_50, RMS_phi_psi_150, RMS_phi_psi, size= compare_structure(pdb_file, make_pdb_file(structure_phi_psi, "PhiPsi_" + pdb_file)) RMS_omega_50, RMS_omega_150, RMS_omega, size= compare_structure(pdb_file, make_pdb_file(structure_omega, "PhiPsiOmega_" + pdb_file)) RMS_all_angles_50, RMS_all_angles_150, RMS_all_angles, size= compare_structure(pdb_file, make_pdb_file(structure_all_angles, "AllAngles_" + pdb_file)) output_line= "%s\t%i\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\n" % \ (pdb_code, \ size, \ RMS_phi_psi_50, \ RMS_phi_psi_150, \ RMS_phi_psi, \ RMS_omega_50, \ RMS_omega_150, \ RMS_omega, \ RMS_all_angles_50, \ RMS_all_angles_150, \ RMS_all_angles, \ RMS_backbone_50, \ RMS_backbone_150, \ RMS_backbone ) return output_line
def generateSeq(seq): structure = None for aa in seq: geo = Geometry.geometry(aa) if structure is None: structure = PeptideBuilder.initialize_res(geo) else: structure = PeptideBuilder.add_residue(structure, geo) return structure
def test_add_terminal_OXT(): """ Build a peptide with terminal OXT """ structure = PeptideBuilder.initialize_res("A") for aa in "CDEFGHIKLMNPQRSTVWY": PeptideBuilder.add_residue(structure, aa) PeptideBuilder.add_terminal_OXT(structure) assert compare_to_reference(structure, "extended_OXT.pdb") # check that presence of OXT is tested assert not compare_to_reference(structure, "extended.pdb")
def test_add_residue(): structure = PeptideBuilder.initialize_res("A") for aa in "CDEFGHIKLMNPQRSTVWY": structure = PeptideBuilder.add_residue(structure, aa) # extract peptide from structure and compare to expected ppb = PPBuilder() pp = next(iter(ppb.build_peptides(structure))) assert pp.get_sequence() == "ACDEFGHIKLMNPQRSTVWY" # now compare to saved reference structure assert compare_to_reference(structure, "extended.pdb")
def test_make_extended_structure(): """ Build a peptide containing all 20 amino acids in extended conformation. The structure should be identical to `extended.pdb` """ structure = PeptideBuilder.make_extended_structure("ACDEFGHIKLMNPQRSTVWY") assert compare_to_reference(structure, "extended.pdb") # test unit tests by comparing structures that don't match structure = PeptideBuilder.make_extended_structure("ACDEFGHIKLMNPQRSTVW") assert not compare_to_reference(structure, "extended.pdb") structure = PeptideBuilder.make_extended_structure("ACDEFGHIKLMNPQRSTVWW") assert not compare_to_reference(structure, "extended.pdb")
def test_PeptideBuilder(pdb_code): # retrieve pdb file pdb_file = "%s_clean.pdb" % (pdb_code) # build backbone model from all angles and bond lengths structure_backbone = PeptideBuilder.make_structure_from_geos( build_backbone_model(pdb_file) ) # build backbone model from all angles structure_all_angles = PeptideBuilder.make_structure_from_geos( build_all_angles_model(pdb_file) ) # build models from dihedral angles only structure_omega, structure_phi_psi = build_phi_psi_model(pdb_file) # compare models to original structure RMS_backbone_50, RMS_backbone_150, RMS_backbone, size = compare_structure( pdb_file, make_pdb_file(structure_backbone, "Backbone_" + pdb_file) ) RMS_phi_psi_50, RMS_phi_psi_150, RMS_phi_psi, size = compare_structure( pdb_file, make_pdb_file(structure_phi_psi, "PhiPsi_" + pdb_file) ) RMS_omega_50, RMS_omega_150, RMS_omega, size = compare_structure( pdb_file, make_pdb_file(structure_omega, "PhiPsiOmega_" + pdb_file) ) RMS_all_angles_50, RMS_all_angles_150, RMS_all_angles, size = compare_structure( pdb_file, make_pdb_file(structure_all_angles, "AllAngles_" + pdb_file) ) output_line = ( "%s\t%i\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\t%0.1f\n" % ( pdb_code, size, RMS_phi_psi_50, RMS_phi_psi_150, RMS_phi_psi, RMS_omega_50, RMS_omega_150, RMS_omega, RMS_all_angles_50, RMS_all_angles_150, RMS_all_angles, RMS_backbone_50, RMS_backbone_150, RMS_backbone, ) ) return output_line
def test_add_residue(): """ Build a peptide containing all 20 amino acids """ structure = PeptideBuilder.initialize_res("A") for aa in "CDEFGHIKLMNPQRSTVWY": PeptideBuilder.add_residue(structure, aa) # extract peptide from structure and compare to expected ppb = PPBuilder() pp = next(iter(ppb.build_peptides(structure))) assert pp.get_sequence() == "ACDEFGHIKLMNPQRSTVWY" assert compare_to_reference(structure, "extended.pdb")
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
def generateAA(aaName): geo = Geometry.geometry(aaName) geo.phi = 0 geo.psi_im1 = 0 structure = PeptideBuilder.initialize_res(geo) tx = -np.pi / 2.0 Rx = np.array([[1, 0, 0], [0, cos(tx), -sin(tx)], [0, sin(tx), cos(tx)]]) for atom in structure.get_atoms(): atom.transform(Rx, np.array([0, 0, 0])) nAtom = list(structure.get_atoms())[0] nV = nAtom.get_coord() I = np.identity(3) for atom in structure.get_atoms(): atom.transform(I, -nV) R = rotaxis(np.pi, list(structure.get_atoms())[1].get_vector()) for atom in structure.get_atoms(): atom.transform(R, np.array([0, 0, 0])) # print(list(structure.get_atoms())[1].get_coord(), list(structure.get_atoms())[1]) out = Bio.PDB.PDBIO() out.set_structure(structure) out.save("example.pdb") return structure[0]['A'][1]
def build_linear_model(pdb_filename): parser=PDBParser() structure=parser.get_structure('sample', \ path.join(PDBdir, pdb_filename) ) model=structure[0] chain=model['A'] model_structure_geo=[] for res in chain: if(res.get_resname() in resdict.keys()): tempgeo=Geometry.geometry(resdict[res.get_resname()]) model_structure_geo.append(tempgeo) model_structure=PeptideBuilder.initialize_res(model_structure_geo[0]) for i in range(1,len(model_structure_geo)): model_structure=PeptideBuilder.add_residue(model_structure, model_structure_geo[i]) return model_structure
def test_make_structure_from_geos(): """Build a helix containing all 20 amino acids from list of geometries. The structure should be identical to `extended.pdb` """ geos = [Geometry.geometry(aa) for aa in "ACDEFGHIKLMNPQRSTVWY"] structure = PeptideBuilder.make_structure_from_geos(geos) assert compare_to_reference(structure, "extended.pdb")
def build_linear_model(pdb_filename): parser = PDBParser() structure = parser.get_structure("sample", path.join(PDBdir, pdb_filename)) model = structure[0] chain = model["A"] model_structure_geo = [] for res in chain: if res.get_resname() in resdict.keys(): tempgeo = Geometry.geometry(resdict[res.get_resname()]) model_structure_geo.append(tempgeo) model_structure = PeptideBuilder.initialize_res(model_structure_geo[0]) for i in range(1, len(model_structure_geo)): model_structure = PeptideBuilder.add_residue(model_structure, model_structure_geo[i]) return model_structure
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
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
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)
def test_add_residue2(): phi = -60 psi_im1 = -40 geo = Geometry.geometry("A") geo.phi = phi geo.psi_im1 = psi_im1 structure = PeptideBuilder.initialize_res(geo) for aa in "CDEFGHIKLMNPQRSTVWY": phi += 1 psi_im1 -= 1 geo = Geometry.geometry(aa) geo.phi = phi geo.psi_im1 = psi_im1 structure = PeptideBuilder.add_residue(structure, geo) # now compare to saved reference structure assert compare_to_reference(structure, "helix.pdb")
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")
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
def test_add_residue2(): """ Build a helix containing all 20 amino acids, with slowly varying backbone angles """ phi = -60 psi_im1 = -40 geo = Geometry.geometry("A") geo.phi = phi geo.psi_im1 = psi_im1 structure = PeptideBuilder.initialize_res(geo) for aa in "CDEFGHIKLMNPQRSTVWY": phi += 1 psi_im1 -= 1 geo = Geometry.geometry(aa) geo.phi = phi geo.psi_im1 = psi_im1 PeptideBuilder.add_residue(structure, geo) assert compare_to_reference(structure, "helix.pdb")
def starting_coords(seq, conformation="extended", input_file="", device="cpu"): import PeptideBuilder coords = torch.zeros(len(seq) * len(atoms), 3, device=device) backbone_atoms = ("N", "CA", "C", "O") ss_phis = {"C": -120.0, "H": -60.0, "E": -120.0} ss_psis = {"C": 140.0, "H": -60.0, "E": 140.0} if conformation == "predss": with open(input_file) as f: ss_pred = f.readlines()[1].rstrip() for i, r in enumerate(seq): r_to_use = "A" if r == "G" else r if i == 0: structure = PeptideBuilder.initialize_res(r_to_use) elif conformation == "predss": structure = PeptideBuilder.add_residue(structure, r_to_use, ss_phis[ss_pred[i]], ss_psis[ss_pred[i]]) elif conformation == "random": # ϕ can be -180° -> -30°, ψ can be anything phi = -180 + random() * 150 psi = -180 + random() * 360 structure = PeptideBuilder.add_residue(structure, r_to_use, phi, psi) elif conformation == "helix": structure = PeptideBuilder.add_residue(structure, r_to_use, ss_phis["H"], ss_psis["H"]) elif conformation == "extended": coil_level = 30.0 phi = -120.0 + gauss(0.0, coil_level) psi = 140.0 + gauss(0.0, coil_level) structure = PeptideBuilder.add_residue(structure, r_to_use, phi, psi) else: raise(AssertionError(f"Invalid conformation {conformation}")) for ai, atom in enumerate(atoms): if atom == "cent": coords[len(atoms) * i + ai] = torch.tensor( [at.coord for at in structure[0]["A"][i + 1] if at.name not in backbone_atoms], dtype=torch.float, device=device).mean(dim=0) else: coords[len(atoms) * i + ai] = torch.tensor(structure[0]["A"][i + 1][atom].coord, dtype=torch.float, device=device) return coords
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_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")
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 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')
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
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)
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")
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
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)
#!/usr/bin/python ''' This script builds a variety of structures using all the major functionality in PeptideBuilder. Compare the generated structures to the provided reference structures to see if everything is correct. ''' from __future__ import print_function from PeptideBuilder import Geometry import PeptideBuilder import Bio.PDB # Build a peptide containing all 20 amino acids structure = PeptideBuilder.initialize_res('A') for aa in "CDEFGHIKLMNPQRSTVWY": structure = PeptideBuilder.add_residue(structure, aa) out = Bio.PDB.PDBIO() out.set_structure(structure) out.save("test1.pdb") # Build a helix containing all 20 amino acids, with slowly varying backbone angles phi = -60 psi_im1 = -40 geo = Geometry.geometry('A') geo.phi = phi geo.psi_im1 = psi_im1 structure = PeptideBuilder.initialize_res(geo) for aa in "CDEFGHIKLMNPQRSTVWY":
def build_exact_model(structure, chain_index): model=structure[0] chain=model[chain_index] model_structure_geo=[] prev="0" N_prev="0" CA_prev="0" C_prev="0" O_prev="0" prev_res="" rad=180.0/math.pi for res in chain: name=res.get_resname() if(name !="HOH"): geo=Geometry.geometry(resdict[name]) if(prev=="0"): N_prev= res['N'] CA_prev= res['CA'] C_prev= res['C'] O_prev= res['O'] prev="1" else: n1=N_prev.get_vector() ca1=CA_prev.get_vector() c1=C_prev.get_vector() o1=O_prev.get_vector() O_curr=res['O'] C_curr=res['C'] N_curr=res['N'] CA_curr=res['CA'] o=O_curr.get_vector() c=C_curr.get_vector() n=N_curr.get_vector() ca=CA_curr.get_vector() geo.CA_C_N_angle=calc_angle(ca1, c1, n)*rad geo.C_N_CA_angle=calc_angle(c1, n, ca)*rad geo.peptide= N_curr-C_prev psi= calc_dihedral(n1, ca1, c1, n) ##goes to current res omega= calc_dihedral(ca1, c1, n, ca) ##goes to current res phi= calc_dihedral(c1, n, ca, c) ##goes to current res geo.psi_im1=psi*rad geo.omega=omega*rad geo.phi=phi*rad geo.CA_N_length= CA_curr - N_curr geo.CA_C_length= CA_curr - C_curr geo.C_O_length= C_curr - O_curr geo.N_CA_C_angle= calc_angle(n, ca, c)*rad geo.CA_C_O_angle= calc_angle(ca, c, o)*rad geo.N_CA_C_O= calc_dihedral(n, ca, c, o)*rad N_prev= res['N'] CA_prev= res['CA'] C_prev= res['C'] O_prev= res['O'] if(name=='ALA'): geo.CA_CB_length=CA_curr-res['CB'] geo.C_CA_CB_angle= calc_angle(c, ca, res['CB'].get_vector())*rad geo.N_C_CA_CB_diangle= calc_dihedral(n, c, ca, res['CB'].get_vector())*rad elif(name=='GLU'): geo.CA_CB_length=CA_curr-res['CB'] geo.C_CA_CB_angle=calc_angle(c, ca, res['CB'].get_vector())*rad geo.N_C_CA_CB_diangle=calc_dihedral(n, c, ca, res['CB'].get_vector() )*rad geo.CB_CG_length=res['CB']-res['CG'] geo.CA_CB_CG_angle=calc_angle(ca, res['CB'].get_vector(), res['CG'].get_vector())*rad geo.N_CA_CB_CG_diangle=calc_dihedral(n, ca, res['CB'].get_vector(), res['CG'].get_vector())*rad geo.CG_CD_length=res['CG']-res['CD'] geo.CB_CG_CD_angle=calc_angle(res['CB'].get_vector(), res['CG'].get_vector(), res['CD'].get_vector() )*rad geo.CA_CB_CG_CD_diangle=calc_dihedral(ca, res['CB'].get_vector(), res['CG'].get_vector(), res['CD'].get_vector())*rad geo.CD_OE1_length=res['CD']-res['OE1'] geo.CG_CD_OE1_angle=calc_angle(res['CG'].get_vector(), res['CD'].get_vector(), res['OE1'].get_vector() )*rad geo.CB_CG_CD_OE1_diangle= calc_dihedral(res['CB'].get_vector(), res['CG'].get_vector(),res['CD'].get_vector(), res['OE1'].get_vector())*rad geo.CD_OE2_length=res['CD']-res['OE2'] geo.CG_CD_OE2_angle=calc_angle(res['CG'].get_vector(), res['CD'].get_vector(), res['OE2'].get_vector() )*rad geo.CB_CG_CD_OE2_diangle= calc_dihedral(res['CB'].get_vector(), res['CG'].get_vector(),res['CD'].get_vector(), res['OE2'].get_vector())*rad elif(name=='HIS'): geo.CA_CB_length=CA_curr-res['CB'] geo.CB_CG_length=(res['CB']-res['CG']) geo.CG_ND1_length=(res['CG']-res['ND1']) geo.CG_CD2_length=(res['CG']-res['CD2']) geo.ND1_CE1_length=(res['ND1']-res['CE1']) geo.CD2_NE2_length=(res['CD2']-res['NE2']) geo.C_CA_CB_angle=(calc_angle(c, ca, res['CB'].get_vector()))*rad geo.CA_CB_CG_angle=(calc_angle(ca, res['CB'].get_vector(), res['CG'].get_vector() ) )*rad geo.CB_CG_ND1_angle= (calc_angle(res['CB'].get_vector(), res['CG'].get_vector(), res['ND1'].get_vector() ) )*rad geo.CB_CG_CD2_angle=(calc_angle(res['CB'].get_vector(), res['CG'].get_vector(), res['CD2'].get_vector() ) )*rad geo.CG_ND1_CE1_angle=(calc_angle(res['CG'].get_vector(), res['ND1'].get_vector(), res['CE1'].get_vector() ) )*rad geo.CG_CD2_NE2_angle=(calc_angle(res['CG'].get_vector(), res['CD2'].get_vector(), res['NE2'].get_vector() ) )*rad geo.N_C_CA_CB_diangle=(calc_dihedral(n, c, ca, res['CB'].get_vector()))*rad geo.N_CA_CB_CG_diangle=(calc_dihedral(n, ca, res['CB'].get_vector(), res['CG'].get_vector()))*rad geo.CA_CB_CG_ND1_diangle=(calc_dihedral(ca, res['CB'].get_vector(), res['CG'].get_vector(), res['ND1'].get_vector()))*rad geo.CA_CB_CG_CD2_diangle=(calc_dihedral(ca, res['CB'].get_vector(), res['CG'].get_vector(), res['CD2'].get_vector()))*rad geo.CB_CG_ND1_CE1_diangle=(calc_dihedral(res['CB'].get_vector(), res['CG'].get_vector(), res['ND1'].get_vector(), res['CE1'].get_vector()))*rad geo.CB_CG_CD2_NE2_diangle=(calc_dihedral(res['CB'].get_vector(), res['CG'].get_vector(), res['CD2'].get_vector(), res['NE2'].get_vector()))*rad model_structure_geo.append(geo) model_structure=PeptideBuilder.make_structure_from_geos(model_structure_geo) return model_structure
#!/usr/bin/python ''' Simple example script demonstrating how to use the PeptideBuilder library. The script generates a peptide consisting of six arginines in alpha-helix conformation, and it stores the peptide under the name "example.pdb". ''' from __future__ import print_function import Geometry import PeptideBuilder geo = Geometry.geometry('G') geo.phi=-60 geo.psi_im1=-40 structure = PeptideBuilder.initialize_res(geo) for i in range(5): structure = PeptideBuilder.add_residue(structure, geo) import Bio.PDB out = Bio.PDB.PDBIO() out.set_structure(structure) out.save( "example.pdb" )
def eval_func(self, candidates, args): """ :param candidates: Current population being evaluated. """ scores_list = [] scores = [] print "Calculating scores... " for conformation in candidates: score = 0.0 surf_area = 0.0 phobic_area = 0.0 philic_area = 0.0 e_score = 0.0 # Create PeptideBuilder structure for conformation geo = Geometry.geometry(self.sequence[0]) geo.phi = conformation[0] geo.psi_im1 = conformation[1] if self.sequence[0] != "G" and self.sequence[0] != "P" and self.sequence[0] != "A": if 0 in self.mod_dict: geo.inputRotamers(self.mod_dict[0]) structure = PeptideBuilder.initialize_res(geo) i = 2 j = 1 for aa in self.sequence[1:]: geo = Geometry.geometry(aa) geo.phi = conformation[i] geo.psi_im1 = conformation[i + 1] if aa != "G" and aa != "P" and aa != "A": if j in self.mod_dict: geo.inputRotamers(self.mod_dict[j]) j += 1 structure = PeptideBuilder.add_residue(structure, geo) i += 2 out = Bio.PDB.PDBIO() out.set_structure(structure) out.save(self.path + "/msms/prot" + str(self.id) + ".pdb") # Add hydrogens with pybel mol = pybel.readfile("pdb", self.path + "/msms/prot" + str(self.id) + ".pdb").next() mol.OBMol.AddHydrogens() pybelmol = pybel.Molecule(mol) pybelmol.write("pdb", self.path + "/msms/prot" + str(self.id) + ".pdb", overwrite=True) # Convert to xyzrn with msms executable subprocess.call('cd ' + self.path + '/msms; ./pdb_to_xyzrn prot' + str(self.id) + '.pdb > prot' + str(self.id) + '.xyzrn', shell=True) # Enforce constraints (atoms can't come closer than van-der-waals radii) check = [] with open(self.path + "/msms/prot" + str(self.id) + ".xyzrn") as f: check = f.readlines() atoms_check = [] unk = False for atom in check: entries = atom.split() name = entries[5] ent = name.split("_") resid = ent[2] atname = ent[0] res = ent[1] try: r = get_radius(atname, res)[0] except KeyError: unk = True score = 1000000 break atoms_check.append([resid, entries[0], entries[1], entries[2], r, atname, res]) if not unk: clash = False for atom in atoms_check: id1 = int(atom[0]) atname1 = atom[5] x = float(atom[1]) y = float(atom[2]) z = float(atom[3]) r = float(atom[4]) for atom2 in atoms_check: id2 = int(atom2[0]) atname2 = atom2[5] if (id1 != id2) and not (((id2 == (id1 + 1)) or (id2 == (id1 - 1))) and (((atname1 == "CA") or (atname1 == "C") or (atname1 == "N")) and ((atname2 == "CA") or (atname2 == "C") or (atname2 == "N")))): x2 = float(atom2[1]) y2 = float(atom2[2]) z2 = float(atom2[3]) r2 = float(atom2[4]) distance = np.sqrt((x2 - x)**2 + (y2 - y)**2 + (z2 - z)**2) if distance < r + r2: solved = self.rebuild(id1, id2, self.rot_iter, conformation) if not solved: score = 1000000 clash = True print "CLASH" print "> " + str(atname1) + " " + str(atname2) + " " + str(distance) + " " + str(id1) + " " \ + str(id2) break else: print "Solved." if clash: break if not clash: # Compute ses for all atoms with msms executable subprocess.call('cd ' + self.path + '/msms; ' + './msms.x86_64Linux2.2.6.1 -if prot' + str(self.id) + '.xyzrn -af ses_atoms' + str(self.id) + ' > /dev/null', shell=True) with open(self.path + "/msms/ses_atoms" + str(self.id) + ".area") as f: atoms = f.readlines() ses_type = [] for i in range(len(atoms)): if i != 0: entries = atoms[i].split() ses = entries[1] atom_desc = entries[3] atmname = atom_desc.split("_") rad_hydro = get_radius(atmname[0].strip(), atmname[1].strip()) res_num = atmname[2].strip() atm_type = rad_hydro[1] ses_type.append([ses, atm_type, res_num]) for atom in ses_type: surf_area += float(atom[0]) if atom[1] == 1: phobic_area += float(atom[0]) if atom[1] == 2: philic_area -= float(atom[0]) print "SA: " + str(surf_area/2) print "SPHOBE: " + str(phobic_area) print "SPHIL: " + str(philic_area) # print "ES: " + str(e_score) # Score the new conformation score = surf_area/2 + phobic_area + philic_area scores.append([score, conformation]) # For fitness scores_list.append(score) print "Done. \n" scores = sorted(scores) # Save lowest to pdb if scores[0][0] < self.lowest: conformation = scores[0][1] geo = Geometry.geometry(self.sequence[0]) geo.phi = conformation[0] geo.psi_im1 = conformation[1] if self.sequence[0] != "G" and self.sequence[0] != "P" and self.sequence[0] != "A": if 0 in self.mod_dict: geo.inputRotamers(self.mod_dict[0]) structure = PeptideBuilder.initialize_res(geo) i = 2 j = 1 for aa in self.sequence[1:]: geo = Geometry.geometry(aa) geo.phi = conformation[i] geo.psi_im1 = conformation[i + 1] if aa != "G" and aa != "P" and aa != "A": if j in self.mod_dict: geo.inputRotamers(self.mod_dict[j]) j += 1 structure = PeptideBuilder.add_residue(structure, geo) i += 2 out = Bio.PDB.PDBIO() out.set_structure(structure) out.save("lowest" + str(self.id) + ".pdb") mol = pybel.readfile("pdb", "lowest" + str(self.id) + ".pdb").next() mol.OBMol.AddHydrogens() pybelmol = pybel.Molecule(mol) pybelmol.write("pdb", "lowest" + str(self.id) + ".pdb", overwrite=True) pybelmol.write("pdb", "lowest_backup" + str(self.id) + ".pdb", overwrite=True) if scores[0][0] < self.lowest: self.lowest = scores[0][0] print "Lowest score: " + str(self.lowest) # return novelty_scores return scores_list
def rebuild(self, id1, id2, it, conformation): """Rebuilds clashing residues. :param id1: First residue id. :param id2: Second residue id. :param it: Number of iterations. :param conformation: Current conformation. :return: :type boolean: True if successfully rebuilt, False if not. """ print "Adjusting rotamers..." new_rot1 = [] new_rot2 = [] aa1 = self.sequence[id1 - 1] aa2 = self.sequence[id2 - 1] solved = False if (aa1 != "G" and aa1 != "P" and aa1 != "A") or (aa2 != "G" and aa2 != "P" and aa2 != "A"): for n in range(it): if solved: break if n == 0: new_rot1 = self.make_rot_list(aa1) new_rot2 = self.make_rot_list(aa2) else: moves1 = [] for j in range(len(new_rot1)): rand = random.random() if rand < 0.33: moves1.append(-self.rot_mover_size) elif rand < 0.66: moves1.append(0) else: moves1.append(self.rot_mover_size) new_rot1 = [new_rot1[i] + moves1[i] for i in range(len(new_rot1))] moves2 = [] for j in range(len(new_rot2)): rand = random.random() if rand < 0.33: moves2.append(-self.rot_mover_size) elif rand < 0.66: moves2.append(0) else: moves2.append(self.rot_mover_size) new_rot2 = [new_rot2[i] + moves2[i] for i in range(len(new_rot2))] geo = Geometry.geometry(self.sequence[0]) geo.phi = conformation[0] geo.psi_im1 = conformation[1] if id1 - 1 == 0: if aa1 != "G" and aa1 != "P" and aa1 != "A": geo.inputRotamers(new_rot1) elif id2 - 1 == 0: if aa2 != "G" and aa2 != "P" and aa2 != "A": geo.inputRotamers(new_rot2) elif 0 in self.mod_dict: if self.sequence[0] != "G" and self.sequence[0] != "P" and self.sequence[0] != "A": geo.inputRotamers(self.mod_dict[0]) structure = PeptideBuilder.initialize_res(geo) i = 2 j = 1 for aa in self.sequence[1:]: geo = Geometry.geometry(aa) geo.phi = conformation[i] geo.psi_im1 = conformation[i + 1] if id1 == j + 1: if aa1 != "G" and aa1 != "P" and aa1 != "A": geo.inputRotamers(new_rot1) elif id2 == j + 1: if aa2 != "G" and aa2 != "P" and aa2 != "A": geo.inputRotamers(new_rot2) elif j in self.mod_dict: geo.inputRotamers(self.mod_dict[j]) j += 1 structure = PeptideBuilder.add_residue(structure, geo) i += 2 out = Bio.PDB.PDBIO() out.set_structure(structure) out.save(self.path + "/msms/prot" + str(self.id) + ".pdb") mol = pybel.readfile("pdb", self.path + "/msms/prot" + str(self.id) + ".pdb").next() mol.OBMol.AddHydrogens() pybelmol = pybel.Molecule(mol) pybelmol.write("pdb", self.path + "/msms/prot" + str(self.id) + ".pdb", overwrite=True) subprocess.call('cd ' + self.path + '/msms; ./pdb_to_xyzrn prot' + str(self.id) + '.pdb > prot' + str(self.id) + '.xyzrn', shell=True) check = [] with open(self.path + "/msms/prot" + str(self.id) + ".xyzrn") as f: check = f.readlines() atoms_check = [] clash = False unk = False for atom in check: entries = atom.split() name = entries[5] ent = name.split("_") resid = ent[2] atname = ent[0] res = ent[1] try: r = get_radius(atname, res)[0] except KeyError: unk = True break atoms_check.append([resid, entries[0], entries[1], entries[2], r, atname, res]) if not unk: for atom in atoms_check: aid1 = int(atom[0]) atname1 = atom[5] x = float(atom[1]) y = float(atom[2]) z = float(atom[3]) r = float(atom[4]) for atom2 in atoms_check: aid2 = int(atom2[0]) atname2 = atom2[5] if (aid1 != aid2) and not (((aid2 == (aid1 + 1)) or (aid2 == (aid1 - 1))) and (((atname1 == "CA") or (atname1 == "C") or (atname1 == "N")) and ((atname2 == "CA") or (atname2 == "C") or (atname2 == "N")))): x2 = float(atom2[1]) y2 = float(atom2[2]) z2 = float(atom2[3]) r2 = float(atom2[4]) distance = np.sqrt((x2 - x)**2 + (y2 - y)**2 + (z2 - z)**2) if distance < r + r2: clash = True break if clash: break if not clash: solved = True else: print str(aa1) + " " + str(aa2) if solved: if aa1 != "G" and aa1 != "P" and aa1 != "A": self.mod_dict[id1 - 1] = new_rot1 if aa2 != "G" and aa2 != "P" and aa2 != "A": self.mod_dict[id2 - 1] = new_rot2 return True else: return False
def local_mover(self, n): """ :param candidates: Current population being evaluated. """ conformation = self.conformation move = 0 score = 0.0 surf_area = 0.0 phobic_area = 0.0 philic_area = 0.0 e_score = 0.0 if self.steps != 0: rand = random.random() if rand < 0.33: move = -self.mover_size elif rand < 0.66: move = 0 else: move = self.mover_size conformation[n] += move geo = Geometry.geometry(self.sequence[0]) geo.phi = conformation[0] geo.psi_im1 = conformation[1] if self.sequence[0] != "G" and self.sequence[0] != "P" and self.sequence[0] != "A": if 0 in self.mod_dict: geo.inputRotamers(self.mod_dict[0]) structure = PeptideBuilder.initialize_res(geo) i = 2 j = 1 for aa in self.sequence[1:]: geo = Geometry.geometry(aa) geo.phi = conformation[i] geo.psi_im1 = conformation[i + 1] if aa != "G" and aa != "P" and aa != "A": if j in self.mod_dict: geo.inputRotamers(self.mod_dict[j]) j += 1 structure = PeptideBuilder.add_residue(structure, geo) i += 2 out = Bio.PDB.PDBIO() out.set_structure(structure) out.save(self.path + "/msms/prot" + str(self.id) + ".pdb") mol = pybel.readfile("pdb", self.path + "/msms/prot" + str(self.id) + ".pdb").next() mol.OBMol.AddHydrogens() pybelmol = pybel.Molecule(mol) pybelmol.write("pdb", self.path + "/msms/prot" + str(self.id) + ".pdb", overwrite=True) subprocess.call('cd ' + self.path + '/msms; ./pdb_to_xyzrn prot' + str(self.id) + '.pdb > prot' + str(self.id) + '.xyzrn', shell=True) check = [] with open(self.path + "/msms/prot" + str(self.id) + ".xyzrn") as f: check = f.readlines() atoms_check = [] unk = False for atom in check: entries = atom.split() name = entries[5] ent = name.split("_") resid = ent[2] atname = ent[0] res = ent[1] try: r = get_radius(atname, res)[0] except KeyError: unk = True score = 1000000 break atoms_check.append([resid, entries[0], entries[1], entries[2], r, atname, res]) if not unk: clash = False for atom in atoms_check: id1 = int(atom[0]) atname1 = atom[5] x = float(atom[1]) y = float(atom[2]) z = float(atom[3]) r = float(atom[4]) for atom2 in atoms_check: id2 = int(atom2[0]) atname2 = atom2[5] if (id1 != id2) and not (((id2 == (id1 + 1)) or (id2 == (id1 - 1))) and (((atname1 == "CA") or (atname1 == "C") or (atname1 == "N")) and ((atname2 == "CA") or (atname2 == "C") or (atname2 == "N")))): x2 = float(atom2[1]) y2 = float(atom2[2]) z2 = float(atom2[3]) r2 = float(atom2[4]) distance = np.sqrt((x2 - x)**2 + (y2 - y)**2 + (z2 - z)**2) if distance < r + r2: solved = self.rebuild(id1, id2, self.rot_iter, conformation) if not solved: score = 1000000 clash = True print "CLASH" print "> " + str(atname1) + " " + str(atname2) + " " + str(distance) + " " + str(id1) + " " \ + str(id2) break else: print "Solved." if clash: break if not clash: self.threshold = 0 subprocess.call('cd ' + self.path + '/msms; ' + './msms.x86_64Linux2.2.6.1 -if prot' + str(self.id) + '.xyzrn -af ses_atoms' + str(self.id) + ' > /dev/null', shell=True) with open(self.path + "/msms/ses_atoms" + str(self.id) + ".area") as f: atoms = f.readlines() ses_type = [] for i in range(len(atoms)): if i != 0: entries = atoms[i].split() ses = entries[1] atom_desc = entries[3] atmname = atom_desc.split("_") rad_hydro = get_radius(atmname[0].strip(), atmname[1].strip()) res_num = atmname[2].strip() atm_type = rad_hydro[1] ses_type.append([ses, atm_type, res_num]) for atom in ses_type: surf_area += float(atom[0]) if atom[1] == 1: phobic_area += float(atom[0]) if atom[1] == 2: philic_area -= float(atom[0]) print "SA: " + str(surf_area) print "SPHOBE: " + str(phobic_area) # print "SPHIL: " + str(philic_area) # print "ES: " + str(e_score) # Score the new conformation score = surf_area + phobic_area if self.steps == 0: self.current_score = score self.accepted += 1 else: if score >= self.current_score: try: p_acc = math.exp(-(score - self.current_score)/self.temperature) print "PACC " + str(p_acc) except OverflowError: p_acc = 0 print "OVERFLOW" rand = random.random() if p_acc < rand: self.rejected += 1 pass else: self.conformation = conformation self.current_score = score self.accepted += 1 else: self.conformation = conformation self.current_score = score self.accepted += 1 if score < self.lowest: self.lowest = score pybelmol.write("pdb", "lowest" + str(self.id) + ".pdb", overwrite=True) pybelmol.write("pdb", "lowest_backup" + str(self.id) + ".pdb", overwrite=True) # For messing with dynamic parameter adjustment # if self.threshold % 10 == 0: # if self.mover_size > 1: # self.mover_size -= 1 # print "MS: " + str(self.mover_size) # self.threshold = 0 # if self.steps % 20 == 0: # if self.lowest - self.score_10 < 10: # self.mover_size += 1 # self.score_10 = self.lowest print "Done. \n" print "################################" print "Step " + str(self.steps) + " | MC Ratio: " + str(self.rejected/self.accepted) + \ " | Lowest score: " + str(self.lowest) print "################################" self.steps += 1
def rotamer_mover(self, conformation, n): if n == 0: self.rot_conf_local = self.rot_conformation for i in range(len(self.rot_conf_local)): aa = self.rot_conf_local[i] moves = [] for j in range(len(aa)): rand = random.random() if rand < 0.33: moves.append(-self.rot_mover_size) elif rand < 0.66: moves.append(0) else: moves.append(self.rot_mover_size) aa = [aa[i] + moves[i] for i in range(len(aa))] self.rot_conf_local[i] = aa geo = Geometry.geometry(self.sequence[0]) geo.phi = conformation[0] geo.psi_im1 = conformation[1] geo.inputRotamers(self.rot_conf_local[0]) structure = PeptideBuilder.initialize_res(geo) i = 2 j = 1 for aa in self.sequence[1:]: geo = Geometry.geometry(aa) geo.phi = conformation[i] geo.psi_im1 = conformation[i + 1] if aa != "G" and aa != "P" and aa != "A": geo.inputRotamers(self.rot_conf_local[j]) j += 1 structure = PeptideBuilder.add_residue(structure, geo) i += 2 out = Bio.PDB.PDBIO() out.set_structure(structure) out.save(self.path + "/msms/prot" + str(self.id) + ".pdb") mol = pybel.readfile("pdb", self.path + "/msms/prot" + str(self.id) + ".pdb").next() mol.OBMol.AddHydrogens() pybelmol = pybel.Molecule(mol) pybelmol.write("pdb", self.path + "/msms/prot" + str(self.id) + ".pdb", overwrite=True) subprocess.call('cd ' + self.path + '/msms; ./pdb_to_xyzrn prot' + str(self.id) + '.pdb > prot' + str(self.id) + '.xyzrn', shell=True) check = [] with open(self.path + "/msms/prot" + str(self.id) + ".xyzrn") as f: check = f.readlines() atoms_check = [] for atom in check: entries = atom.split() name = entries[5] ent = name.split("_") resid = ent[2] atname = ent[0] res = ent[1] try: r = get_radius(atname, res)[0] except KeyError: self.threshold += 1 return False atoms_check.append([resid, entries[0], entries[1], entries[2], r, atname, res]) for atom in atoms_check: id1 = int(atom[0]) atname1 = atom[5] x = float(atom[1]) y = float(atom[2]) z = float(atom[3]) r = float(atom[4]) for atom2 in atoms_check: id2 = int(atom2[0]) atname2 = atom2[5] if (id1 != id2) and not (((id2 == (id1 + 1)) or (id2 == (id1 - 1))) and (((atname1 == "CA") or (atname1 == "C") or (atname1 == "N")) and ((atname2 == "CA") or (atname2 == "C") or (atname2 == "N")))): x2 = float(atom2[1]) y2 = float(atom2[2]) z2 = float(atom2[3]) r2 = float(atom2[4]) distance = np.sqrt((x2 - x)**2 + (y2 - y)**2 + (z2 - z)**2) if distance < r + r2: self.threshold += 1 self.rot_conformation = self.rot_conf_local self.new_conf = True print "Success." return True