import pyrosettacolabsetup; pyrosettacolabsetup.install_pyrosetta() import pyrosetta; pyrosetta.init()
import glob import logging logging.basicConfig(level=logging.INFO) import os import pyrosetta.distributed import pyrosetta.distributed.io as io import pyrosetta.distributed.viewer as viewer from pyrosetta import pose_from_pdb
input_pose = pose_from_pdb('/mnt/Data/PopOS/Data_Ana/Wu/PigAntiBodies/AB_regine/data/14-1_ImmuneCorrect_partial.pdb') input_pose_no_loop = pose_from_pdb('/mnt/Data/PopOS/Data_Ana/Wu/PigAntiBodies/AB_regine/data/14-1_ImmuneCorrect_partial_Noloop.pdb')
helix_selector = pyrosetta.rosetta.core.select.residue_selector.SecondaryStructureSelector("H") loop_selector = pyrosetta.rosetta.core.select.residue_selector.SecondaryStructureSelector("L")
modules = [ viewer.setBackgroundColor(color="black"), viewer.setStyle(residue_selector=helix_selector, cartoon_color="blue", label=False, radius=0), viewer.setStyle(residue_selector=loop_selector, cartoon_color="yellow", label=False, radius=0), viewer.setZoomTo(residue_selector=loop_selector) ]
def Chain_num(pose): n_chains = pose.num_chains() for chain_index in range(1, n_chains+1): start_res = pose.chain_begin(chain_index) end_res = pose.chain_end(chain_index) print(f"Chain {chain_index}: residues {start_res} to {end_res}")
Chain_num(input_pose) Chain_num(input_pose_no_loop)
Start = input_pose_no_loop.chain_end(1) Len = input_pose.chain_end(1) - input_pose_no_loop.chain_end(2) End = Start + Len Miss_Seq = "".join([input_pose.residue(i).name1() for i in range(Start, End)])
print(input_pose_no_loop.residue(Start).name())
print(input_pose_no_loop.residue(Start+1).name())
def mutate_position(pose,position,mutate): '''A simple function to mutate an amino acid given a pose number''' mr = pyrosetta.rosetta.protocols.simple_moves.MutateResidue() mr.set_target(position) mr.set_res_name(mutate) mr.apply(pose)
''' In tutorial, they mutated the residues into ALA. It says is make a pose that can be applied by GenKic. I am not sure it is because of the GenKic algorithem or GenKic function. I possible could be that GenKic function doesn't accept the resideus from either side do the termianl. So, we need to remove them and add them back. Because my goal is get a better conformation of the loop, I just relpace it with itself to do the lateral test. Also, I tried to use ALA at the begining, too. The folding resutls are not promissing. ''' Resi1 = input_pose_no_loop.residue(Start).name3() Resi2 = input_pose_no_loop.residue(Start+1).name3()
mutate_position(input_pose_no_loop,Start,Resi1) mutate_position(input_pose_no_loop,Start+1,Resi2) assert(input_pose_no_loop.residue(Start).name() == Resi1) assert(input_pose_no_loop.residue(Start+1).name() == Resi2)
from pyrosetta import Pose
def slice_pose(p,start,end): ''' Take a pose object and return from start, end ''' sliced = Pose() if end > p.size() or start > p.size(): return "end/start slice is longer than total lenght of pose {} {}".format(start,end) for i in range(start,end+1): sliced.append_residue_by_bond(p.residue(i)) return sliced
helix_ab_pose = slice_pose(input_pose_no_loop,1,Start)
helix_c_pose = slice_pose(input_pose_no_loop,Start+1,input_pose_no_loop.chain_end(2))
add_pdb_info_mover = pyrosetta.rosetta.protocols.simple_moves.AddPDBInfoMover() add_pdb_info_mover.apply(helix_ab_pose) add_pdb_info_mover.apply(helix_c_pose)
def crudely_connect_w_loop(n_term_pose,c_term_pose,connect_with): """ The function will take two poses and join them with a loop
Keep in mind this is just joined as far as the pose is concerned. The bond angles and lenghts will be sub-optimal """ one_to_three = { 'A': 'ALA', 'C': 'CYS', 'D': 'ASP', 'E': 'GLU', 'F': 'PHE', 'G': 'GLY', 'H': 'HIS', 'I': 'ILE', 'K': 'LYS', 'L': 'LEU', 'M': 'MET', 'N': 'ASN', 'P': 'PRO', 'Q': 'GLN', 'R': 'ARG', 'S': 'SER', 'T': 'THR', 'V': 'VAL', 'Y': 'TYR', 'W': 'TRP'}
pose_a = Pose() pose_a.assign(n_term_pose)
pose_b = Pose() pose_b.assign(c_term_pose)
chm = pyrosetta.rosetta.core.chemical.ChemicalManager.get_instance() rts = chm.residue_type_set('fa_standard') get_residue_object = lambda x: pyrosetta.rosetta.core.conformation.ResidueFactory.create_residue( rts.name_map(x))
rebuilt_loop = []
'''Iterate through string turning each letter into a residue object and then appending it to the N term pose''' for one_letter in connect_with: resi = get_residue_object(one_to_three[one_letter]) pose_a.append_residue_by_bond(resi, True) pose_a.set_omega(pose_a.total_residue(), 180.) rebuilt_loop.append(pose_a.total_residue())
for residue_index in range(1, pose_b.total_residue()+1): pose_a.append_residue_by_bond( pose_b.residue(residue_index))
print("Joined NTerm and CTerm pose with loop {} at residues {}".format(connect_with,rebuilt_loop)) return pose_a
gk_input_pose = crudely_connect_w_loop(helix_ab_pose,helix_c_pose,Miss_Seq)
print(Miss_Seq) for chain in range(3,input_pose_no_loop.num_chains()+1): print(chain) gk_input_pose.append_pose_by_jump(input_pose_no_loop.split_by_chain(chain), gk_input_pose.total_residue())
Chain_num(helix_ab_pose) Chain_num(gk_input_pose) Chain_num(input_pose)
from additional_scripts.GenKic import GenKic
loop_residues = [i for i in range(Start,End+2)] gk_object = GenKic(loop_residues)
gk_object.set_closure_attempts(500000) gk_object.set_min_solutions(10)
from pyrosetta import ScoreFunction
def get_bb_only_sfxn(): scorefxn = ScoreFunction() scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_atr, 1) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.fa_rep, 0.55) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.hbond_sr_bb, 1) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.hbond_lr_bb, 1) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.rama_prepro, 0.45) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.omega, 0.4) scorefxn.set_weight(pyrosetta.rosetta.core.scoring.p_aa_pp, 0.625) return scorefxn
bb_only_sfxn = get_bb_only_sfxn()
gk_object.set_scorefxn(bb_only_sfxn)
gk_object.set_selector_type('lowest_energy_selector')
for res_num in loop_residues[:-1]: gk_object.set_dihedral(res_num, res_num + 1, "C", "N", 180.1)
gk_object.set_omega_angles()
for res_num in loop_residues: gk_object.randomize_backbone_by_rama_prepro(res_num)
gk_object.get_instance().apply(gk_input_pose)
gk_object.close_normal_bond(End,End+1) gk_object.get_instance().apply(gk_input_pose)
gk_object.set_filter_backbone_bin(loop_residues[0],'A',bin='ABBA')
gk_object.set_filter_backbone_bin(loop_residues[-1],'A',bin='ABBA')
gk_object.set_filter_loop_bump_check()
for r in gk_object.pivot_residues: gk_object.set_filter_rama_prepro(r,cutoff=0.5)
gk_instance = gk_object.get_instance()
gk_instance.apply(gk_input_pose)
poses = [input_pose_no_loop, input_pose, gk_input_pose]
from pyrosetta.rosetta.protocols.relax import FastRelax from pyrosetta.rosetta.core.kinematics import MoveMap
from pyrosetta.rosetta.protocols.relax import FastRelax
gk_input_pose.dump_pdb("loop.pdb")
relax = FastRelax() relax.set_scorefxn(bb_only_sfxn) movemap = MoveMap()
relax.set_movemap(movemap) relax.apply(gk_input_pose)
gk_input_pose.dump_pdb("loop_relaxe.pdb")
relax = FastRelax() relax.set_scorefxn(bb_only_sfxn) relax.apply(gk_input_pose)
gk_input_pose.dump_pdb("loop_full_relaxe.pdb")
|