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 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 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_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_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 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_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 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
#!/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 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
def generateAA(aaName): geo = Geometry.geometry(aaName) structure = PeptideBuilder.initialize_res(geo) return structure