def homologousonePointcrossover(eaObj, inParent): similarpoints = [] # Creating a list to store points with similar angles found randParent = Pose() # Searching for similar angles while (len(similarpoints) == 0): randParent.assign(randomParent(eaObj, inParent)) for i in range(1, inParent.pose.size()): if((inParent.pose.phi(i) == randParent.phi(i)) and (inParent.pose.psi(i) == randParent.psi(i)) and (inParent.pose.omega(i) == randParent.omega(i))): similarpoints.append(i) child = Pose() child.assign(inParent.pose) # Now we select a random point from the list of points that had similar angles as our crossOverPoint crossOverPoint = random.choice(similarpoints) # We should switch the values from the parents for residue in range(1, crossOverPoint): Pose.replace_residue( child, residue, Pose.residue(randParent, residue), True) inParent.pose.assign(child)
def GeneratePopulation(eaObj, initcfg): eaObj.population = [] # Truncation starting point delStart = min(eaObj.seqLen, eaObj.knownNativeLen) delEnd = max(eaObj.seqLen, eaObj.knownNativeLen) # Truncation ending point if (((delEnd - delStart) >= 1) and (eaObj.knownNativeLen == delEnd)): delete_region(eaObj.knownNative, delStart + 1, delEnd) # Create the initial population specified in the ini file size = 0 maxPopulation = int(initcfg['population']) while (size < maxPopulation): # new protein to be added to population that is subject to a randomized conformation newPose = Pose() newPose.assign(eaObj.initialPose) # Will convert the protein into a centroid. eaObj.fa2cen.apply(newPose) eaObj.varMover.apply(newPose) # Molecular fragment replacement if (((delEnd - delStart) >= 1) and (eaObj.seqLen == delEnd)): delete_region(newPose, delStart + 1, delEnd) # Add the newly modified protein to the total population eaObj.population.append( ProteinData(newPose, eaObj.impScoreFxn(newPose))) eaObj.evalnum += 1 size += 1
def Fc_glycan_rmsd( working, working_Fc_glycan_chains, native, native_Fc_glycan_chains, decoy_num, dump_dir ): """ :param working: decoy Pose() :param working_Fc_glycan_chains: list( the chain id's for the working Fc glycan ). Ex = [ 'H', 'I' ] :param native: native Pose() :param native_Fc_glycan_chains: list( the chain id's for the native Fc glycan ). Ex = [ 'D', 'E' ] :param decoy_num: int( the number of the decoy for use when dumping its Fc glycan ) :param dump_dir: str( /path/to/dump_dir for the temp pdb files made. Files will be deleted ) return: float( Fc glycan rmsd ) """ # imports import os from pyrosetta import Pose from rosetta.core.scoring import non_peptide_heavy_atom_RMSD from antibody_functions import load_pose from util import dump_pdb_by_chain, id_generator # get temporary files to work with id = id_generator() if dump_dir.endswith( '/' ): working_filename = "%s%s_temp_working_just_glyc%s.pdb" %( dump_dir, id, str( decoy_num ) ) native_filename = "%s%s_temp_native_just_glyc%s.pdb" %( dump_dir, id, str( decoy_num ) ) else: working_filename = "%s/%s_temp_working_just_glyc%s.pdb" %( dump_dir, id, str( decoy_num ) ) native_filename = "%s/%s_temp_native_just_glyc%s.pdb" %( dump_dir, id, str( decoy_num ) ) # dump out the Fc glycans by their chain id's dump_pdb_by_chain( working_filename, working, working_Fc_glycan_chains, decoy_num, dump_dir = dump_dir ) dump_pdb_by_chain( native_filename, native, native_Fc_glycan_chains, decoy_num, dump_dir = dump_dir ) # load in the Fc glycans just_Fc_glycan = Pose() try: just_Fc_glycan.assign( load_pose( working_filename ) ) except: pass native_just_Fc_glycan = Pose() try: native_just_Fc_glycan.assign( load_pose( native_filename ) ) except: pass # calculate the glycan rmsd try: glycan_rmsd = non_peptide_heavy_atom_RMSD( just_Fc_glycan, native_just_Fc_glycan ) except: glycan_rmsd = "nan" pass # delete the files try: os.popen( "rm %s" %working_filename ) os.popen( "rm %s" %native_filename ) except: pass return glycan_rmsd
def __init__(self, temp_path,results_path,pdb_path,input_path,\ close_cycles = 20, refine_cycles = 1,relax_cycles=3, DEBUG=True,watch = True,ligand=False,ligand_params=[],partners='A_X'): self.DEBUG = DEBUG super(InDelMut, self).__init__() if temp_path.strip()[-1]=='/': temp_path = temp_path.strip()[:-1] if results_path.strip()[-1]=='/': results_path = results_path.strip()[:-1] self.temp_path = temp_path self.results_path = results_path if DEBUG: print('temp_path:',self.temp_path) if DEBUG: print('results_path:',self.results_path) self.pdb_path = pdb_path self.input_path = input_path self.refine_cycles = refine_cycles self.close_cycles = close_cycles self.relax_cycles = relax_cycles self.ligand = ligand self.partners = partners self._load_files() # constant pose - initial pose if ligand: self.POSE = get_pose_with_ligand(self.pdb_path,ligand_params) else: self.POSE = get_pose(self.pdb_path) pose = Pose() # keeps current pose self.pose = pose.assign(self.POSE) movemap = MoveMap() movemap.set_bb(True) movemap.set_chi(True) minmover = pyrosetta.rosetta.protocols.minimization_packing.MinMover() minmover.movemap(movemap) minmover.score_function(get_fa_scorefxn()) minmover.apply(self.pose) self._load_movers() self.scores[0] = pose.scores['total_score'] self._load_numbering() # pymol = PyMOLMover() # pymol.keep_history(True) # self.pymol = pymol # if watch: self._apply_pymol() self.mover_index = 0
def twoPointcrossover(eaObj, inParent): randParent = Pose() randParent.assign(randomParent(eaObj, inParent)) crossOverPoint1 = randint(1, inParent.pose.size()) crossOverPoint2 = randint(1, inParent.pose.size()) # the first crossover point should be smaller than the second one. while(crossOverPoint1 >= crossOverPoint2): crossOverPoint1 = randint(1, inParent.pose.size()) crossOverPoint2 = randint(1, inParent.pose.size()) # The crossover'd child child = Pose() child.assign(inParent.pose) # We switch the values between the two crossover points with values from the random parent for residue in range(crossOverPoint1, crossOverPoint2): Pose.replace_residue( child, residue, Pose.residue(randParent, residue), True) inParent.pose.assign(child)
def onePointcrossover(eaObj, inParent): # Get random parent from population, ensure that we didn't get the same one. randParent = Pose() randParent.assign(randomParent(eaObj, inParent)) # Pick a random point in the sequence of the strand of amino acids to crossover crossOverPoint = randint(1, inParent.pose.size()) # Create a new pose to be crossover'd by the two parents child = Pose() child.assign(inParent.pose) """ We iterate through the size of the crossover point (since we already have one of the parents copied) one by one until the offspring has reached it's crossoverpoint and we should have a fully newborn offspring by the end of the loop. """ for residue in range(1, crossOverPoint): Pose.replace_residue( child, residue, Pose.residue(randParent, residue), True) inParent.pose.assign(child)
def sample_folding(sequence, long_frag_filename, long_frag_length, short_frag_filename, short_frag_length, kT=3.0, long_inserts=1, short_inserts=3, cycles=40, jobs=1, job_output='fold_output'): """ Performs exporting structures to a PyMOL instance Output structures are named <job_output>_(job#).pdb """ # 1. create a pose from the desired sequence (fullatom) # the method pose_from_sequence produces a complete IDEALIZED # protein conformation of the input sequence, the ResidueTypeSet (second # argument below) may be varied, and this method supports non-proteogenic # chemistry (though it is still a Rosetta Residue). however this syntax # is more involved and not robust to user errors, and not presented here # small differences in bond lengths and bond angles WILL change the results, #### if you desire an alternate starting conformation, alter steps #### 1. and 2. as you please pose = pose_from_sequence(sequence, 'fa_standard') # 2. linearize the pose by setting backbone torsions to large values # the method make_pose_from_sequence does not create the new pose's # PDBInfo object, so its done here, without it an error occurs later pose.pdb_info(rosetta.core.pose.PDBInfo(pose.total_residue())) for i in range(1, pose.total_residue() + 1): pose.set_omega(i, 180) pose.set_phi(i, -150) # reasonably straight pose.set_psi(i, 150) #### if you want to see the decoy scores, the PDBInfo needs these lines #pose.pdb_info().chain(i, 'A') # necessary to color by score #pose.pdb_info().number(i, i) # for PDB numbering #### # 3. create a (fullatom) reference copy of the pose test_pose = Pose() test_pose.assign(pose) test_pose.pdb_info().name('linearized pose') # 4. create centroid <--> fullatom conversion Movers to_centroid = SwitchResidueTypeSetMover('centroid') # centroid Residue objects, of amino acids, have all their sidechain atoms # replaced by a single representative "atom" to speed up calculations to_fullatom = SwitchResidueTypeSetMover('fa_standard') # 5. convert the poses to centroid to_centroid.apply(pose) to_centroid.apply(test_pose) # 6. create the MoveMap, all backbone torsions free movemap = MoveMap() movemap.set_bb(True) # minimizing the centroid chi angles (the sidechain centroid atoms) is # almost always USELESS since this compression is performed for speed, # not accuracy and clashes usually occur when converting to fullatom # 7. setup the ClassicFragmentMovers # for the long fragments file # this "try--except" is used to catch improper fragment files try: fragset_long = core.fragment.ConstantLengthFragSet( long_frag_length, long_frag_filename) #### the ConstantLengthFragSet is overloaded, this same #### ConstantLengthFragSet can be obtained with different syntax # to obtain custom fragments, see Generating Fragment Files below except: raise IOError('Make sure long_frag_length matches the fragments in\n\ long_frag_file and that long_frag_file is valid') long_frag_mover = protocols.simple_moves.ClassicFragmentMover( fragset_long, movemap) # and for the short fragments file # this "try--except" is used to catch improper fragment files try: fragset_short = core.fragment.ConstantLengthFragSet( short_frag_length, short_frag_filename) except: raise IOError('Make sure short_frag_length matches the fragments in\n\ short_frag_file and that short_frag_file is valid') short_frag_mover = protocols.simple_moves.ClassicFragmentMover( fragset_short, movemap) # 8. setup RepeatMovers for the ClassicFragmentMovers insert_long_frag = protocols.moves.RepeatMover(long_frag_mover, long_inserts) insert_short_frag = protocols.moves.RepeatMover(short_frag_mover, short_inserts) # 9. create a PyMOL_Observer for exporting structures to PyMOL (optional) # the PyMOL_Observer object owns a PyMOLMover and monitors pose objects for # structural changes, when changes are detected the new structure is # sent to PyMOL # fortunately, this allows investigation of full protocols since # intermediate changes are displayed, it also eliminates the need to # manually apply the PyMOLMover during a custom protocol # unfortunately, this can make the output difficult to interpret (since you # aren't explicitly telling it when to export) and can significantly slow # down protocols since many structures are output (PyMOL can also slow # down if too many structures are provided and a fast machine may # generate structures too quickly for PyMOL to read, the # "Buffer clean up" message # uncomment the line below to use PyMOL_Observer ## AddPyMOLObserver(test_pose, True) # 10. create ScoreFunctions # for low-resolution, centroid, poses necessary for the TrialMover's # MonteCarlo object (see below) scorefxn_low = create_score_function('score3') # for high-resolution, fullatom, poses necessary for scoring final output # from the PyJobDistributor (see below) scorefxn_high = get_fa_scorefxn( ) # create_score_function('standard', 'score12') # 11. setup a RepeatMover on a TrialMover of a SequenceMover # -setup a TrialMover # a. create a SequenceMover of the fragment insertions #### add any other moves you desire folding_mover = protocols.moves.SequenceMover() folding_mover.add_mover(insert_long_frag) folding_mover.add_mover(insert_short_frag) # b. create a MonteCarlo object to define success/failure # must reset the MonteCarlo object for each trajectory! mc = MonteCarlo(test_pose, scorefxn_low, kT) # c. create the TrialMover trial = TrialMover(folding_mover, mc) #### for each trajectory, try cycles number of applications # -create the RepeatMover folding = protocols.moves.RepeatMover(trial, cycles) # 12. create a (Py)JobDistributor jd = PyJobDistributor(job_output, jobs, scorefxn_high) # 13. store the score evaluations for output # printing the scores as they are produced would be difficult to read, # Rosetta produces a lot of verbose output when running scores = [0] * (jobs + 1) scores[0] = scorefxn_low(pose) # 14. perform folding by counter = 0 # for exporting to PyMOL while not jd.job_complete: # a. set necessary variables for the new trajectory # -reload the starting pose test_pose.assign(pose) # -change the pose's PDBInfo.name, for the PyMOL_Observer counter += 1 test_pose.pdb_info().name(job_output + '_' + str(counter)) # -reset the MonteCarlo object (sets lowest_score to that of test_pose) mc.reset(test_pose) #### if you create a custom protocol, you may have additional #### variables to reset, such as kT #### if you create a custom protocol, this section will most likely #### change, many protocols exist as single Movers or can be #### chained together in a sequence (see above) so you need #### only apply the final Mover # b. apply the refinement protocol folding.apply(test_pose) #### # c. export the lowest scoring decoy structure for this trajectory # -recover the lowest scoring decoy structure mc.recover_low(test_pose) # -store the final score for this trajectory scores[counter] = scorefxn_low(test_pose) # -convert the decoy to fullatom # the sidechain conformations will all be default, # normally, the decoys would NOT be converted to fullatom before # writing them to PDB (since a large number of trajectories would # be considered and their fullatom score are unnecessary) # here the fullatom mode is reproduced to make the output easier to # understand and manipulate, PyRosetta can load in PDB files of # centroid structures, however you must convert to fullatom for # nearly any other application to_fullatom.apply(test_pose) # -guess what cysteines are involved in disulfide bridges guess_disulfides(test_pose) # -output the fullatom decoy structure into a PDB file jd.output_decoy(test_pose) # -export the final structure to PyMOL test_pose.pdb_info().name(job_output + '_' + str(counter) + '_fa') #### if you want to see the decoy scores, uncomment the line below #scorefxn_high( test_pose ) # 15. output the score evaluations print('===== Centroid Scores =====') print('Original Score\t:\t', scores[0]) for i in range(1, len(scores)): # print out the job scores # the "[:14].ljust(14)" is to force the text alignment print( (job_output + '_' + str( i ))[:14].ljust(14) +\ '\t:\t', scores[i] ) return scores # for other protocols
def sample_dna_interface(pdb_filename, partners, jobs=1, job_output='dna_output'): """ Performs DNA-protein docking using Rosetta fullatom docking (DockingHighRes) on the DNA-protein complex in <pdb_filename> using the relative chain <partners> . <jobs> trajectories are performed with output structures named <job_output>_(job#).pdb. """ # 1. creates a pose from the desired PDB file pose = Pose() pose_from_file(pose, pdb_filename) # 2. setup the docking FoldTree # using this method, the jump number 1 is automatically set to be the # inter-body jump dock_jump = 1 # the exposed method setup_foldtree takes an input pose and sets its # FoldTree to have jump 1 represent the relation between the two docking # partners, the jump points are the residues closest to the centers of # geometry for each partner with a cutpoint at the end of the chain, # the second argument is a string specifying the relative chain orientation # such as "A_B" of "LH_A", ONLY TWO BODY DOCKING is supported and the # partners MUST have different chain IDs and be in the same pose (the # same PDB), additional chains can be grouped with one of the partners, # the "_" character specifies which bodies are separated # the third argument...is currently unsupported but must be set (it is # supposed to specify which jumps are movable, to support multibody # docking...but Rosetta doesn't currently) # the FoldTrees setup by this method are for TWO BODY docking ONLY! protocols.docking.setup_foldtree(pose, partners, Vector1([dock_jump])) # 3. create a copy of the pose for testing test_pose = Pose() test_pose.assign(pose) # 4. create ScoreFunctions for centroid and fullatom docking scorefxn = create_score_function('dna') scorefxn.set_weight(core.scoring.fa_elec, 1) # an "electrostatic" term #### global docking, a problem solved by the Rosetta DockingProtocol, #### requires interface detection and refinement #### as with other protocols, these tasks are split into centroid (interface #### detection) and high-resolution (interface refinement) methods #### without a centroid representation, low-resolution DNA-protein #### prediction is not possible and as such, only the high-resolution #### DNA-protein interface refinement is available #### WARNING: if you add a perturbation or randomization step, the #### high-resolution stages may fail (see Changing DNA Docking #### Sampling below) #### a perturbation step CAN make this a global docking algorithm however #### the rigid-body sampling preceding refinement will require EXTENSIVE #### sampling to produce accurate results and this algorithm spends most #### of its effort in refinement (which may be useless for the predicted #### interface) # 5. setup the high resolution (fullatom) docking protocol (DockMCMProtocol) # ...as should be obvious by now, Rosetta applications have no central # standardization, the DockingProtocol object can be created and # applied to perform Rosetta docking, many of its options and settings # can be set using the DockingProtocol setter methods # as there is currently no centroid representation of DNA in the chemical # database, the low-resolution docking stages are not useful for # DNA docking # instead, create an instance of just the high-resolution docking stages docking = protocols.docking.DockMCMProtocol() docking.set_scorefxn(scorefxn) # 6. setup the PyJobDistributor jd = PyJobDistributor(job_output, jobs, scorefxn) # 7. setup a PyMOL_Observer (optional) # the PyMOL_Observer object owns a PyMOLMover and monitors pose objects for # structural changes, when changes are detected the new structure is # sent to PyMOL # fortunately, this allows investigation of full protocols since # intermediate changes are displayed, it also eliminates the need to # manually apply the PyMOLMover during a custom protocol # unfortunately, this can make the output difficult to interpret (since you # aren't explicitly telling it when to export) and can significantly slow # down protocols since many structures are output (PyMOL can also slow # down if too many structures are provided and a fast machine may # generate structures too quickly for PyMOL to read, the # "Buffer clean up" message # uncomment the line below to use the PyMOL_Observer ## AddPyMOLObserver(test_pose, True) # 8. perform protein-protein docking counter = 0 # for pretty output to PyMOL while not jd.job_complete: # a. set necessary variables for this trajectory # -reset the test pose to original (centroid) structure test_pose.assign(pose) # -change the pose name, for pretty output to PyMOL counter += 1 test_pose.pdb_info().name(job_output + '_' + str(counter)) # b. perform docking docking.apply(test_pose) # c. output the decoy structure: # to PyMOL test_pose.pdb_info().name(job_output + '_' + str(counter) + '_fa') # to a PDB file jd.output_decoy(test_pose)
# loop rms and energy to command line terminal. MAX_KIC_BUILD_ATTEMPTS = 10000 # Kale: to reduce test time even further try options: -loops:outer_cycles 1 -loops:max_inner_cycles 1 init( extra_options='-constant_seed -run:test_cycles True' ) # -loops:test_cycles is only needed for self-test, please make sure to remove it on production run # WARNING: option '-constant_seed' is for testing only! MAKE SURE TO REMOVE IT IN PRODUCTION RUNS!!!!! import os os.chdir('.test.output') p = core.import_pose.pose_from_file("../test/data/2cpl_min.pdb") starting_p = Pose() starting_p.assign(p) scorefxn_low = protocols.loops.get_cen_scorefxn( ) # create_score_function( 'cen_std' ) scorefxn_high = protocols.loops.get_fa_scorefxn( ) # create_score_function_ws_patch( 'standard', 'score12' ) pymol = PyMOLMover() # If Pymol server is running, centroid stage will display loop_begin = 145 loop_end = 155 loop_cut = 150 my_loop = protocols.loops.Loop(loop_begin, loop_end, loop_cut) my_loops = protocols.loops.Loops() my_loops.add_loop(my_loop) print(my_loop)
def packer_task(pose, PDB_out=False): """ Demonstrates the syntax necessary for basic usage of the PackerTask object performs demonstrative sidechain packing and selected design using <pose> and writes structures to PDB files if <PDB_out> is True """ # create a copy of the pose test_pose = Pose() test_pose.assign(pose) # this object is contained in PyRosetta v2.0 and above pymover = PyMOLMover() # create a standard ScoreFunction scorefxn = get_fa_scorefxn( ) # create_score_function_ws_patch('standard', 'score12') ############ # PackerTask # a PackerTask encodes preferences and options for sidechain packing, an # effective Rosetta methodology for changing sidechain conformations, and # design (mutation) # a PackerTask stores information on a per-residue basis # each residue may be packed or designed # PackerTasks are handled slightly differently in PyRosetta ####pose_packer = PackerTask() # this line will not work properly pose_packer = standard_packer_task(test_pose) # the pose argument tells the PackerTask how large it should be # sidechain packing "optimizes" a pose's sidechain conformations by cycling # through (Dunbrack) rotamers (sets of chi angles) at a specific residue # and selecting the rotamer which achieves the lowest score, # enumerating all possibilities for all sidechains simultaneously is # impractically expensive so the residues to be packed are individually # optimized in a "random" order # packing options include: # -"freezing" the residue, preventing it from changing conformation # -including the original sidechain conformation when determining the # lowest scoring conformation pose_packer.restrict_to_repacking() # turns off design pose_packer.or_include_current(True) # considers original conformation print(pose_packer) # packing and design can be performed by a PackRotamersMover, it requires # a ScoreFunction, for optimizing the sidechains and a PackerTask, # setting the packing and design options packmover = protocols.minimization_packing.PackRotamersMover( scorefxn, pose_packer) scorefxn(pose) # to prevent verbose output on the next line print('\nPre packing score:', scorefxn(test_pose)) test_pose.pdb_info().name('original') # for PyMOLMover pymover.apply(test_pose) packmover.apply(test_pose) print('Post packing score:', scorefxn(test_pose)) test_pose.pdb_info().name('packed') # for PyMOLMover pymover.apply(test_pose) if PDB_out: test_pose.dump_pdb('packed.pdb') # since the PackerTask specifies how the sidechains change, it has been # extended to include sidechain constitutional changes allowing # protein design, this method of design is very similar to sidechain # packing; all rotamers of the possible mutants at a single residue # are considered and the lowest scoring conformation is selected # design options include: # -allow all amino acids # -allow all amino acids except cysteine # -allow specific amino acids # -prevent specific amino acids # -allow polar amino acids only # -prevent polar amino acids # -allow only the native amino acid # the myriad of packing and design options can be set manually or, more # commonly, using a specific file format known as a resfile # resfile syntax is explained at: # http://www.rosettacommons.org/manuals/archive/rosetta3.1_user_guide/file_resfiles.html # manually setting deign options is tedious, the methods below are handy # for creating resfiles # mutate the "middle" residues center = test_pose.total_residue() // 2 specific_design = {} for i in range(center - 2, center + 3): specific_design[i] = 'ALLAA' # write a resfile to perform these mutations generate_resfile_from_pose(test_pose, 'sample_resfile', False, specific=specific_design) # setup the design PackerTask, use the generated resfile pose_design = standard_packer_task(test_pose) rosetta.core.pack.task.parse_resfile(test_pose, pose_design, 'sample_resfile') print(pose_design) # prepare a new structure test_pose.assign(pose) # perform design designmover = protocols.minimization_packing.PackRotamersMover( scorefxn, pose_design) print( '\nDesign with all proteogenic amino acids at (pose numbered)\ residues', center - 2, 'to', center + 2) print('Pre-design score:', scorefxn(test_pose)) print( 'Pre-design sequence: ...' + \ test_pose.sequence()[center - 5:center + 4] + '...' ) designmover.apply(test_pose) # perform design print('\nPost-design score:', scorefxn(test_pose)) print( 'Post-design sequence: ...' + \ test_pose.sequence()[center - 5:center + 4] + '...' ) test_pose.pdb_info().name('designed') # for PyMOLMover pymover.apply(test_pose) if PDB_out: test_pose.dump_pdb('designed.pdb')
def sample_single_loop_modeling(pdb_filename, loop_begin, loop_end, loop_cutpoint, frag_filename, frag_length, outer_cycles_low=2, inner_cycles_low=5, init_temp_low=2.0, final_temp_low=0.8, outer_cycles_high=5, inner_cycles_high=10, init_temp_high=2.2, final_temp_high=0.6, jobs=1, job_output='loop_output'): """ Performs simple single loop construction on the input <pdb_filename> with loop from <loop_begin> to <loop_end> with a cutpoint at <loop_cutpoint> using fragments of length <frag_length> in the file <frag_filename>. <jobs> trajectories are performed, each using a low resolution (centroid) simulated annealing with <outer_cycles> rounds and <inner_cycles> steps per round decrementing "temperature" from <init_temp> to <final_temp> geometrically. Output structures are named <job_output>_(job#).pdb. """ # 1. create a pose from the desired PDB file p = Pose() pose_from_file(p, pdb_filename) # 2. create a reference copy of the pose in fullatom starting_p = Pose() starting_p.assign(p) #### if you are constructing multiple loops simultaneously, changes will #### occur in most of the steps below # 3. create the Loop object # (note: Loop objects merely specify residues, they contain no # conformation data) my_loop = protocols.loops.Loop(loop_begin, loop_end, loop_cutpoint) #### if using multiple loops, add additional Loop objects # 4. use the Loop to set the pose FoldTree protocols.loops.set_single_loop_fold_tree(p, my_loop) #### alternate FoldTree setup, if you uncomment the lines below, #### comment-out the set_single_loop_foldtree line above (line 189) #### -create an empty FoldTree #ft = FoldTree() #### -make it a single edge the length of pose #ft.simple_tree(p.total_residue()) #### -insert a jump corresponding to the single loop region #ft.add_jump(loop_begin - 2, loop_end + 2, loop_cutpoint) #### -give the pose this FoldTree (set it to this object), this will #### erase any previous FoldTree held by the pose #p.fold_tree(ft) #### there is also a fold_tree_from_loops method in exposed which sets up #### a FoldTree but it is different from set_single_loop_foldtree in #### that is creates jumps +/- 1 residue from their corresponding loop #### endpoints and requires a third argument, the FoldTree to setup # 5. sets the cut-point residues as cut-point variants protocols.loops.add_single_cutpoint_variant(p, my_loop) # 6. create the MoveMap, allow the loop region backbone and # all chi torsions to be free movemap = MoveMap() movemap.set_bb_true_range(loop_begin, loop_end) movemap.set_chi(True) # sets all chi torsions free # 7. setup the fragment Mover # this "try--except" is used to catch improper fragment files try: fragset = core.fragment.ConstantLengthFragSet(frag_length, frag_filename) #### the ConstantLengthFragSet is overloaded, this same #### ConstantLengthFragSet can be obtained with different syntax # to obtain custom fragments, see Generating Fragment Files below except: raise IOError('Make sure frag_length matches the fragments in\n\ frag_file and that frag_file is valid') fragment_mover = protocols.simple_moves.ClassicFragmentMover( fragset, movemap) # 8. create a Mover for loop modeling using CCD (low resolution) ccd_closure = protocols.loops.loop_closure.ccd.CCDLoopClosureMover( my_loop, movemap) # 9. create ScoreFunctions # for centroid, use the default centroid ScoreFunction with chainbreak on scorefxn_low = create_score_function('cen_std') # the chainbreak ScoreType exists to penalize broken bonds # try creating a broken pose in the interpreter and use a ScoreFunction # with a chainbreak score to investigate its impact, the score is 0.0 # except when a bond is broken # this penalizes failures caused by CCD failing to close the loop scorefxn_low.set_weight(core.scoring.chainbreak, 1) # for fullatom, used for packing and scoring final output scorefxn_high = get_fa_scorefxn( ) # create_score_function_ws_patch('standard', 'score12') # 10. setup sidechain packing Mover task_pack = core.pack.task.TaskFactory.create_packer_task(starting_p) task_pack.restrict_to_repacking() # prevents design, packing only task_pack.or_include_current(True) # considers original sidechains pack = protocols.minimization_packing.PackRotamersMover( scorefxn_high, task_pack) # 11. setup the high resolution refinement # by creating a Loops object, # (note: Loops is basically a list of Loop objects), sample_loops = protocols.loops.Loops() # giving it the loop to remodel, sample_loops.add_loop(my_loop) # and creating a fullatom CCD Mover (high resolution) # this Mover is somewhat abnormal since it handles everything itself, it: # -creates its own MoveMap for the loop regions # -creates its own ScoreFunction (default to get_fa_scorefxn()) # -creates its own FoldTree for the pose based on the loops # -creates its own MonteCarlo object for monitoring the pose # -performs "simulated annealing" with 3 outer cycles and 90 inner # cycles, very similar to the protocol outlined ere # -creates its own backbone Movers (SmallMover, ShearMover) # -creates its own PackRotamersMover, it does NOT restrict repacking # to the loop regions and can alter all sidechain conformations loop_refine = LoopMover_Refine_CCD(sample_loops) # some of these parameters or objects can be set but the protocol # executed by this Mover is effectively untouchable #loop_refine.set_score_function(scorefxn_high) # in beta v2 and above loop_refine.temp_initial(init_temp_high) loop_refine.temp_final(init_temp_high) loop_refine.outer_cycles(outer_cycles_high) loop_refine.max_inner_cycles(inner_cycles_high) # 12. create centroid <--> fullatom conversion Movers to_centroid = SwitchResidueTypeSetMover('centroid') to_fullatom = SwitchResidueTypeSetMover('fa_standard') # and a Mover to recover sidechain conformations # when a protocol samples backbone torsion space in centroid, # the sidechain conformations are neglected, when it is transferred # to fullatom, we typically set the sidechain conformations to their # "original" values and perform sidechain packing, # a ReturnSidechainMover saves a pose's sidechains (in this case # staring_pose) and when applied, inserts these conformations # into the input pose recover_sidechains = protocols.simple_moves.ReturnSidechainMover( starting_p) # 13. create a reference copy of the pose in centroid # the first stage of each trajectory is in centroid # so a centroid reference is needed and the pose must start in centroid to_centroid.apply(p) starting_p_centroid = Pose() starting_p_centroid.assign(p) # 14. create the geometric "temperature" increment for simulated annealing gamma = pow((final_temp_low / init_temp_low), (1.0 / (outer_cycles_low * inner_cycles_low))) # 15. create a PyMOLMover for exporting structures to PyMOL pymov = PyMOLMover() # uncomment the line below to load structures into successive states #pymov.keep_history(True) scorefxn_high(starting_p) # for exporting the scores pymov.apply(starting_p) pymov.send_energy(starting_p) # 16. create a (Py)JobDistributor # a PyJobDistributor uses the job_output argument to name all output files # and performs the specified number (int) of jobs # a ScoreFunction is required since the PyJobDistributor output .fasc file # contains scoring information about each output PDB jd = PyJobDistributor(job_output, jobs, scorefxn_high) jd.native_pose = starting_p # 17. perform the loop modeling protocol counter = 0 # for exporting to PyMOL while not jd.job_complete: # a. set necessary variables for the new trajectory # -reload the starting pose (centroid) p.assign(starting_p_centroid) # -change the pose's PDBInfo.name, for exporting to PyMOL counter += 1 p.pdb_info().name(job_output + '_' + str(counter) + '_cen') # -reset the starting "temperature" (to init_temp) kT = init_temp_low # -create a MonteCarlo object for this trajectory # a MonteCarlo object assesses pass/fail by the Metropolis Criteria # and also records information on the lowest scoring pose mc = MonteCarlo(p, scorefxn_low, kT) # b. "randomize" the loop #### this section may change if you intend to use multiple loops or #### alter the sampling method to "randomize" the loop # -by breaking it open, for i in range(loop_begin, loop_end + 1): p.set_phi(i, -180) p.set_psi(i, 180) pymov.apply(p) # -and then inserting fragments # the number of insertions performed is somewhat arbitrary for i in range(loop_begin, loop_end + 1): fragment_mover.apply(p) pymov.apply(p) #### # low resolution loop modeling: # c. simulated annealing incrementing kT geometrically # from init_temp to final_temp #### this section may change if you intend to use multiple loops or #### alter the sampling method for low resolution modeling for i in range(1, outer_cycles_low + 1): # -start with the lowest scoring pose mc.recover_low(p) # loads mc's lowest scoring pose into p # -take several steps of in the simulated annealing by for j in range(1, inner_cycles_low + 1): # >increasing the "temperature" kT = kT * gamma mc.set_temperature(kT) # >inserting a fragment, fragment_mover.apply(p) pymov.apply(p) # >performing CCD, ccd_closure.apply(p) pymov.apply(p) # >and assessing the Metropolis Criteria mc.boltzmann(p) #### # the LoopMover_Refine_CCD makes A LOT of moves, DO NOT expect to # see useful results if you use the PyMOLMover keep_history option, the large # number of intermediates will slow processing to a halt # d. convert the best structure (lowest scoring) into fullatom by: # -recovering the best (centroid) structure (lowest scoring), mc.recover_low(p) # loads mc's lowest scoring pose into p # -switching the ResidueTypeSet to fullatom (from centroid), to_fullatom.apply(p) # -recovering the original sidechain conformations, recover_sidechains.apply(p) # -and packing the result (since the backbone conformation has changed) pack.apply(p) pymov.apply(p) p.pdb_info().name(job_output + '_' + str(counter) + '_fa') # high-resolution refinement: #### this section may change if you intend to use multiple loops or #### alter the sampling method for high resolution refinement # e. apply the LoopMover_Refine_CCD loop_refine.apply(p) # f. output the decoy (pose result from this trajectory) # include the loop RMSD (Lrsmd) # -output a PDB file using the PyJobDistributor lrms = protocols.loops.loop_rmsd(p, starting_p, sample_loops, True) jd.additional_decoy_info = ' Lrmsd: ' + str(lrms) jd.output_decoy(p) # -export the structure to PyMOL pymov.apply(p) pymov.send_energy(p)
def test_apply_pose(self): new_pose = Pose() new_pose.assign(self.pose) self.small_mv(new_pose) assert new_pose.residue(6).xyz(4) != self.pose.residue(6).xyz(4)
p = pose_from_sequence("AAAAAAAAAA", "fa_standard") for res in range(1, p.total_residue() + 1): p.set_omega(res, 180) # use the PyMOLMover to echo this structure to PyMOL pmm = PyMOLMover() pmm.apply(p) # set score function to include Van der Wals and H-bonds only score = ScoreFunction() score.set_weight(fa_atr, 0.8) score.set_weight(fa_rep, 0.44) score.set_weight(hbond_sr_bb, 1.17) # initialize low score objects low_pose.assign(p) low_score = score(p) for i in range(100): last_score = score(p) last_pose.assign(p) random_move(p) new_score = score(p) print("Iteration:", i, "Score:", new_score, "Low Score:", low_score) deltaE = new_score - last_score # accept if new energy score is improved # reject or accept if new energy score is worse based on Metropolis criteria if deltaE > 0:
print('Docking ----------------------------------------------------') dock_p = core.import_pose.pose_from_file("../test/data/test_dock.pdb") dock_jump = 1 #protocols.docking.DockingProtocol().setup_foldtree(dock_p) to_centroid = protocols.simple_moves.SwitchResidueTypeSetMover('centroid') jmp_arr = rosetta.utility.vector1_int() #jmp_arr = utility.vector1_ulong() jmp_arr.append(1) protocols.docking.setup_foldtree(dock_p, '_', jmp_arr) starting_p = Pose() starting_p.assign(dock_p) to_centroid.apply(dock_p) dock_pert = RigidBodyPerturbMover(dock_jump, 3, 8) dock_pert.apply(dock_p) spin = RigidBodySpinMover( dock_jump ) spin.apply(dock_p) slide_into_contact = protocols.docking.DockingSlideIntoContact( dock_jump ) slide_into_contact.apply(dock_p) docking_lowres = protocols.docking.DockingLowRes() docking_lowres.apply(dock_p)
def design_with_config(**config) -> dict: start_time = time.time() # Runtime measuring print('DESIGNING') ref15 = get_fa_scorefxn() # REF15 if config is 'ref15': scfxn = ref15 else: scfxn = create_scfxn.creat_scfxn_from_config( config=config) # optimization score Function # pick random # pose = random.choice(pdbs) prot_name = random.choice(list(pdbs.keys())) pose = pdbs[prot_name] # pose = pdbs['1K9P'] # prot_name = '1K9P' # copy pose for comparison after design native_pose = Pose() native_pose.assign(pose) resfile = "./design.resfile" with open(resfile, "w") as f: f.write("ALLAAxc \n") f.write("start\n") # def run(pose): taskf = prs.rosetta.core.pack.task.TaskFactory() taskf.push_back( prs.rosetta.core.pack.task.operation.InitializeFromCommandline()) taskf.push_back(prs.rosetta.core.pack.task.operation.ReadResfile(resfile)) packer = prs.rosetta.protocols.minimization_packing.PackRotamersMover( scfxn) packer.task_factory(taskf) taskf.create_task_and_apply_taskoperations(pose) packer.apply(pose) # TODO: What defines our loss, for now use REF15 or bloss62 matrix bloss62 = substitution_matrices.load("BLOSUM62") # compute normalizes similarity similar = pairwise2.align.globaldx( pose.sequence(), native_pose.sequence(), bloss62, score_only=True) / len(pose.sequence()) # compute Rosetta SimpleMetrics PSSM pssm_score = pssms[prot_name].calculate(pose) print('scored with pssm ') # moritz says its okay to return energy normalized by length # check if pose can be pickled fast and returned took = time.time() - start_time # This has to be serializable in order to get pickled and send back to parent result = { "sequence": pose.sequence(), "pose": PackedPose(pose), "prot_len": len(pose.sequence()), "prot_name": prot_name, "bloss62": -similar, "ref15": (ref15(pose) / len(pose.sequence())), "scfxn": (scfxn(pose) / len(pose.sequence())), "pssm": -pssm_score, "runtime": took } print('DESIGN_DONE: ', result) print("Took: {} to run design on length {}".format( time.strftime("%H: %M: %S", time.gmtime(took)), len(pose.sequence()))) return result
def movemap(pose, PDB_out=False): """ Demonstrates the syntax necessary for basic usage of the MoveMap object performs these changes with a demonstrative backbone minimization using <pose> and writes structures to PDB files if <PDB_out> is True """ ######### # MoveMap # a MoveMap encodes what data is allowed to change in a Pose, referred to as # its degrees of freedom # a MoveMap is separate from a Pose and is usually required by a Mover so # that the correct degrees of freedom are manipulated, in this way, # MoveMap and Pose objects often work in parallel # several MoveMap's can correspond to the same Pose # a MoveMap stores information on a per-residue basis about the # backbone ({phi, psi, omega}) and chi ({chi_i}) torsion angle sets # the MoveMap can only set these sets of torsions to True or False, it # cannot set freedom for the individual angles (such as phi free and psi # fixed) # the MoveMap has no upper-limit on its residue information, it defaults to # all residues (up to residue 99999999) backbone and chi False # you can view the MoveMap per-residue torsion settings by using the # MoveMap.show( Pose.total_residue() ) method (the input argument is the # highest residue to output, it does not support viewing a range) pose_move_map = MoveMap() # change all backbone torsion angles pose_move_map.set_bb(True) # change all chi angle torsion angles (False by default) pose_move_map.set_chi(False) # change a single backbone torsion angles #pose_move_map.set_bb(1, True) # example syntax # change a single residue's chi torsion angles #pose_move_map.set_chi(1, True) # example syntax pose_move_map.show(pose.total_residue()) # perform gradient based minimization on the "median" residues, this # method (MinMover) determines the gradient of an input pose using a # ScoreFunction for evaluation and a MoveMap to define the degrees of # freedom # create a standard ScoreFunction scorefxn = get_fa_scorefxn( ) # create_score_function_ws_patch('standard', 'score12') # redefine the MoveMap to include the median half of the residues # turn "off" all backbone torsion angles pose_move_map.set_bb(False) # reset to backbone False # turn "on" a range of residue backbone torsion angles pose_move_map.set_bb_true_range(int(pose.total_residue() / 4), int(pose.total_residue() * 3 / 4)) # create the MinMover minmover = protocols.minimization_packing.MinMover() minmover.score_function(scorefxn) minmover.movemap(pose_move_map) # create a copy of the pose test_pose = Pose() test_pose.assign(pose) # apply minimization scorefxn(test_pose) # to prevent verbose output on the next line pymover = PyMOLMover() #### uncomment the line below and "comment-out" the two lines below to #### export the structures into different PyMOL states of the same object #pymover.keep_history = True # enables viewing across states #### comment-out the line below, changing PDBInfo names tells the #### PyMOLMover to produce new objects test_pose.pdb_info().name('original') pymover.apply(test_pose) print('\nPre minimization score:', scorefxn(test_pose)) minmover.apply(test_pose) if PDB_out: test_pose.dump_pdb('minimized.pdb') print('Post minimization score:', scorefxn(test_pose)) #### comment-out the line below test_pose.pdb_info().name('minimized') pymover.apply(test_pose)
def sample_docking(pdb_filename, partners, translation = 3.0, rotation = 8.0, jobs = 1, job_output = 'dock_output'): """ Performs protein-protein docking using the Rosetta standard DockingProtocol on the proteins in <pdb_filename> using the relative chain <partners> with an initial perturbation using <translation> Angstroms and <rotation> degrees. <jobs> trajectories are performed with output structures named <job_output>_(job#).pdb. structures are exported to a PyMOL instance. """ # 1. creates a pose from the desired PDB file pose = Pose() pose_from_file(pose, pdb_filename) # 2. setup the docking FoldTree # using this method, the jump number 1 is automatically set to be the # inter-body jump dock_jump = 1 # the exposed method setup_foldtree takes an input pose and sets its # FoldTree to have jump 1 represent the relation between the two docking # partners, the jump points are the residues closest to the centers of # geometry for each partner with a cutpoint at the end of the chain, # the second argument is a string specifying the relative chain partners # such as "A_B" of "LH_A", ONLY TWO BODY DOCKING is supported and the # partners MUST have different chain IDs and be in the same pose (the # same PDB), additional chains can be grouped with one of the partners, # the "_" character specifies which bodies are separated # the third argument...is currently unsupported but must be set (it is # supposed to specify which jumps are movable, to support multibody # docking...but Rosetta doesn't currently) # the FoldTrees setup by this method are for TWO BODY docking ONLY! protocols.docking.setup_foldtree(pose, partners, Vector1([dock_jump])) # 3. create centroid <--> fullatom conversion Movers to_centroid = SwitchResidueTypeSetMover('centroid') to_fullatom = SwitchResidueTypeSetMover('fa_standard') # and a Mover to recover sidechain conformations # when a protocol samples backbone torsion space in centroid, # the sidechain conformations are neglected, when it is transferred # to fullatom, we typically set the sidechain conformations to their # "original" values and perform sidechain packing, # a ReturnSidechainMover saves a pose's sidechains (in this case # staring_pose) and when applied, inserts these conformations # into the input pose recover_sidechains = protocols.simple_moves.ReturnSidechainMover(pose) # 4. convert to centroid to_centroid.apply(pose) # 5. create a (centroid) test pose test_pose = Pose() test_pose.assign(pose) # 6. create ScoreFunctions for centroid and fullatom docking scorefxn_low = create_score_function('interchain_cen') scorefxn_high = create_score_function('docking') # PyRosetta3: scorefxn_high_min = create_score_function_ws_patch('docking', 'docking_min') scorefxn_high_min = create_score_function('docking', 'docking_min') # 7. create Movers for producing an initial perturbation of the structure # the DockingProtocol (see below) can do this but several Movers are # used to demonstrate their syntax # these Movers randomize the orientation (rotation) of each docking partner randomize_upstream = RigidBodyRandomizeMover(pose, dock_jump, partner_upstream) randomize_downstream = RigidBodyRandomizeMover(pose, dock_jump, partner_downstream) # this Mover translates one docking partner away from the other in a random # direction a distance specified by the second argument (in Angstroms) # and rotates this partner randomly by the third argument (in degrees) dock_pert = RigidBodyPerturbMover(dock_jump, translation, rotation) # this Mover randomizes a pose's partners (rotation) spin = RigidBodySpinMover(dock_jump) # this Mover uses the axis defined by the inter-body jump (jump 1) to move # the docking partners close together slide_into_contact = protocols.docking.DockingSlideIntoContact(dock_jump) # 8. setup the MinMover # the MoveMap can set jumps (by jump number) as degrees of freedom movemap = MoveMap() movemap.set_jump(dock_jump, True) # the MinMover can minimize score based on a jump degree of freedom, this # will find the distance between the docking partners which minimizes # the score minmover = protocols.minimization_packing.MinMover() minmover.movemap(movemap) minmover.score_function(scorefxn_high_min) # 9. create a SequenceMover for the perturbation step perturb = protocols.moves.SequenceMover() perturb.add_mover(randomize_upstream) perturb.add_mover(randomize_downstream) perturb.add_mover(dock_pert) perturb.add_mover(spin) perturb.add_mover(slide_into_contact) perturb.add_mover(to_fullatom) perturb.add_mover(recover_sidechains) perturb.add_mover(minmover) # 10. setup the DockingProtocol # ...as should be obvious by now, Rosetta applications have no central # standardization, the DockingProtocol object can be created and # applied to perform Rosetta docking, many of its options and settings # can be set using the DockingProtocol setter methods # here, on instance is created with all default values and the movable jump # is manually set to jump 1 (just to be certain), the centroid docking # ScoreFunction is set and the fullatom docking ScoreFunction is set dock_prot = protocols.docking.DockingProtocol() # contains many docking functions dock_prot.set_movable_jumps(Vector1([1])) # set the jump to jump 1 dock_prot.set_lowres_scorefxn(scorefxn_low) dock_prot.set_highres_scorefxn(scorefxn_high_min) #### you can alternatively access the low and high resolution sections of #### the DockingProtocol, both are applied by the DockingProtocol but #### a novel protocol may only require centroid (DockingLowRes) or #### fullatom (DockingHighRes), uncomment the lines below and their #### application below #docking_low = DockingLowRes() #docking_low.set_movable_jumps(Vector1([1])) #docking_low.set_scorefxn(scorefxn_low) #docking_high = DockingHighRes() #docking_high.set_movable_jumps(Vector1([1])) #docking_high.set_scorefxn(scorefxn_high) # 11. setup the PyJobDistributor jd = PyJobDistributor(job_output, jobs, scorefxn_high) temp_pose = Pose() # a temporary pose to export to PyMOL temp_pose.assign(pose) to_fullatom.apply(temp_pose) # the original pose was fullatom recover_sidechains.apply(temp_pose) # with these sidechains jd.native_pose = temp_pose # for RMSD comparison # 12. setup a PyMOL_Observer (optional) # the PyMOL_Observer object owns a PyMOLMover and monitors pose objects for # structural changes, when changes are detected the new structure is # sent to PyMOL # fortunately, this allows investigation of full protocols since # intermediate changes are displayed, it also eliminates the need to # manually apply the PyMOLMover during a custom protocol # unfortunately, this can make the output difficult to interpret (since you # aren't explicitly telling it when to export) and can significantly slow # down protocols since many structures are output (PyMOL can also slow # down if too many structures are provided and a fast machine may # generate structures too quickly for PyMOL to read, the # "Buffer clean up" message # uncomment the line below to use the PyMOL_Observer ## AddPyMOLObserver(test_pose, True) # 13. perform protein-protein docking counter = 0 # for pretty output to PyMOL while not jd.job_complete: # a. set necessary variables for this trajectory # -reset the test pose to original (centroid) structure test_pose.assign(pose) # -change the pose name, for pretty output to PyMOL counter += 1 test_pose.pdb_info().name(job_output + '_' + str(counter)) # b. perturb the structure for this trajectory perturb.apply(test_pose) # c. perform docking dock_prot.apply(test_pose) #### alternate application of the DockingProtocol pieces #docking_low.apply(test_pose) #docking_high.apply(test_pose) # d. output the decoy structure to_fullatom.apply(test_pose) # ensure the output is fullatom # to PyMOL test_pose.pdb_info().name(job_output + '_' + str( counter ) + '_fa') # to a PDB file jd.output_decoy(test_pose)
def calc_binding_energy(pose, scorefxn, center, cutoff=8.0): # create a copy of the pose for manipulation test_pose = Pose() test_pose.assign(pose) # setup packer options # the sidechain conformations of residues "near the interface", defined as # within <cutoff> Angstroms of an interface residue, may change and # must be repacked, if all residues are repacked, aberrant sidechain # conformations near the interface, but independent of complex # interactions, will be repacked for the mutant and wild-type structures # preventing them from adding noise to the score difference # this method of setting up a PackerTask is different from packer_task.py tf = standard_task_factory() # create a TaskFactory tf.push_back(core.pack.task.operation.RestrictToRepacking() ) # restrict it to repacking # this object contains repacking options, instead of turning the residues # "On" or "Off" directly, this will create an object for these options # and assign it to the TaskFactory prevent_repacking = core.pack.task.operation.PreventRepacking() # the "center" (nbr_atom) of the mutant residue, for distance calculation center = test_pose.residue(center).nbr_atom_xyz() for i in range(1, test_pose.total_residue() + 1): # the .distance_squared method is (a little) lighter than .norm # if the residue is further than <cutoff> Angstroms away, do not repack if center.distance_squared( test_pose.residue(i).nbr_atom_xyz()) > cutoff**2: prevent_repacking.include_residue(i) # apply these settings to the TaskFactory tf.push_back(prevent_repacking) # setup a PackRotamersMover packer = protocols.minimization_packing.PackRotamersMover(scorefxn) packer.task_factory(tf) #### create a Mover for performing translation #### RigidBodyTransMover is SUPPOSED to translate docking partners of a #### pose based on an axis and magnitude #### test it using the PyMOLMover, it does not perform a simple translation #### I also observed a "Hbond Tripped" error when packing after applying #### the Mover, it appears to store inf and NaN values into hbonds #transmover = RigidBodyTransMover() # calc_interaction_energy separates the chains by 500.0 Angstroms, # so does this Mover # if using this Mover, the step_size MUST be a float # if this setting is left to default, it will move the proteins # VERY far apart #transmover.step_size( 5.0 ) # repack the test_pose packer.apply(test_pose) # score this structure before = scorefxn(test_pose) # separate the docking partners #### since RigidBodyTransMover DOES NOT WORK, it is not used #transmover.apply(test_pose) # here are two methods for applying a translation onto a pose structure # both require an xyzVector xyz = rosetta.numeric.xyzVector_double_t() # a Vector for coordinates xyz.x = 500.0 # arbitrary separation magnitude, in the x direction xyz.y = 0.0 #...I didn't have this and it defaulted to 1e251...? xyz.z = 0.0 #...btw thats like 1e225 light years, # over 5e245 yrs at Warp Factor 9.999 (thanks M. Pacella) #### here is a hacky method for translating the downstream partner of a # pose protein-protein complex (must by two-body!) chain2starts = len(pose.chain_sequence(1)) + 1 for r in range(chain2starts, test_pose.total_residue() + 1): for a in range(1, test_pose.residue(r).natoms() + 1): test_pose.residue(r).set_xyz(a, test_pose.residue(r).xyz(a) + xyz) # here is an elegant way to do it, it assumes that jump number 1 # defines the docking partners "connectivity" # the pose.jump method returns a jump object CREATED from the pose jump # data, the pose itself does not own a Jump object, thus you can use # Jump methods, such as pose.jump(1).set_translation, however the object # has not been properly constructed for manipulation, thus performing # a change does not cause any problems, but is not permanently applied #translate = test_pose.jump( 1 ) # copy this information explicitly # adjust its translation via vector addition #translate.set_translation( translate.get_translation() + xyz ) #test_pose.set_jump( 1 , translate ) # as explained above, this call will NOT work #test_pose.jump(1).set_translation( test_pose.get_translation() + xyz ) # repack the test_pose after separation packer.apply(test_pose) # return the change in score return before - scorefxn(test_pose)
def mutate_residue(pose, mutant_position, mutant_aa, pack_radius=0.0, pack_scorefxn=''): """ Replaces the residue at <mutant_position> in <pose> with <mutant_aa> and repack any residues within <pack_radius> Angstroms of the mutating residue's center (nbr_atom) using <pack_scorefxn> note: <mutant_aa> is the single letter name for the desired ResidueType example: mutate_residue(pose, 30, A) See also: Pose PackRotamersMover MutateResidue pose_from_sequence """ #### a MutateResidue Mover exists similar to this except it does not pack #### the area around the mutant residue (no pack_radius feature) #mutator = MutateResidue(mutant_position, mutant_aa) #mutator.apply(test_pose) if pose.is_fullatom() == False: IOError('mutate_residue only works with fullatom poses') test_pose = Pose() test_pose.assign(pose) # create a standard scorefxn by default if not pack_scorefxn: pack_scorefxn = get_fa_scorefxn() # create_score_function('standard') task = standard_packer_task(test_pose) # the Vector1 of booleans (a specific object) is needed for specifying the # mutation, this demonstrates another more direct method of setting # PackerTask options for design aa_bool = rosetta.utility.vector1_bool() # PyRosetta uses several ways of tracking amino acids (ResidueTypes) # the numbers 1-20 correspond individually to the 20 proteogenic amino acids # aa_from_oneletter returns the integer representation of an amino acid # from its one letter code # convert mutant_aa to its integer representation mutant_aa = core.chemical.aa_from_oneletter_code(mutant_aa) # mutation is performed by using a PackerTask with only the mutant # amino acid available during design # to do this, construct a Vector1 of booleans indicating which amino acid # (by its numerical designation, see above) to allow for i in range(1, 21): # in Python, logical expression are evaluated with priority, thus the # line below appends to aa_bool the truth (True or False) of the # statement i == mutant_aa aa_bool.append(i == int(mutant_aa)) # modify the mutating residue's assignment in the PackerTask using the # Vector1 of booleans across the proteogenic amino acids task.nonconst_residue_task(mutant_position).restrict_absent_canonical_aas( aa_bool) # prevent residues from packing by setting the per-residue "options" of # the PackerTask center = pose.residue(mutant_position).nbr_atom_xyz() for i in range(1, pose.total_residue() + 1): # only pack the mutating residue and any within the pack_radius if not i == mutant_position or center.distance_squared( test_pose.residue(i).nbr_atom_xyz()) > pack_radius**2: task.nonconst_residue_task(i).prevent_repacking() # apply the mutation and pack nearby residues packer = protocols.minimization_packing.PackRotamersMover( pack_scorefxn, task) packer.apply(test_pose) return test_pose
def interface_ddG(pose, mutant_position, mutant_aa, movable_jumps, scorefxn='', cutoff=8.0, out_filename=''): # 1. create a reference copy of the pose wt = Pose() # the "wild-type" wt.assign(pose) # 2. setup a specific default ScoreFunction if not scorefxn: # this is a modified version of the scoring function discussed in # PNAS 2002 (22)14116-21, without environment dependent hbonding scorefxn = ScoreFunction() scorefxn.set_weight(fa_atr, 0.44) scorefxn.set_weight(fa_rep, 0.07) scorefxn.set_weight(fa_sol, 1.0) scorefxn.set_weight(hbond_bb_sc, 0.5) scorefxn.set_weight(hbond_sc, 1.0) # 3. create a copy of the pose for mutation mutant = Pose() mutant.assign(pose) # 4. mutate the desired residue # the pack_radius argument of mutate_residue (see below) is redundant # for this application since the area around the mutation is already # repacked mutant = mutate_residue(mutant, mutant_position, mutant_aa, 0.0, scorefxn) # 5. calculate the "interaction energy" # the method calc_interaction_energy is exposed in PyRosetta however it # does not alter the protein conformation after translation and may miss # significant interactions # an alternate method for manually separating and scoring is provided called # calc_binding_energy (see Interaction Energy vs. Binding Energy below) wt_score = calc_binding_energy(wt, scorefxn, mutant_position, cutoff) mut_score = calc_binding_energy(mutant, scorefxn, mutant_position, cutoff) #### the method calc_interaction_energy separates an input pose by #### 500 Angstroms along the jump defined in a Vector1 of jump numbers #### for movable jumps, a ScoreFunction must also be provided #### if setup_foldtree has not been applied, calc_interaction_energy may be #### wrong (since the jumps may be wrong) #wt_score = calc_interaction_energy(wt, scorefxn, movable_jumps) #mut_score = calc_interaction_energy(mutant, scorefxn, movable_jumps) ddg = mut_score - wt_score # 6. output data (optional) # -export the mutant structure to PyMOL (optional) mutant.pdb_info().name(pose.sequence()[mutant_position - 1] + str(pose.pdb_info().number(mutant_position)) + mutant.sequence()[mutant_position - 1]) pymover = PyMOLMover() scorefxn(mutant) pymover.apply(mutant) pymover.send_energy(mutant) # -write the mutant structure to a PDB file if out_filename: mutant.dump_pdb(out_filename) return ddg
from __future__ import print_function import pyrosetta import pyrosetta.rosetta as rosetta from pyrosetta import init, pose_from_file, create_score_function, Pose, MoveMap, PyMOLMover from pyrosetta.rosetta import core, protocols from pyrosetta.teaching import MinMover, SmallMover, ShearMover, TrialMover, MonteCarlo, RepeatMover init(extra_options = "-constant_seed") # WARNING: option '-constant_seed' is for testing only! MAKE SURE TO REMOVE IT IN PRODUCTION RUNS!!!!! import os; os.chdir('.test.output') start = pose_from_file("../test/data/workshops/1YY8.clean.pdb") test = Pose() test.assign(start) start.pdb_info().name("start") test.pdb_info().name("test") pmm = PyMOLMover() pmm.apply(start) pmm.apply(test) pmm.keep_history(True) print( pmm ) # Small and Shear Moves kT = 1.0 n_moves = 1 movemap = MoveMap() movemap.set_bb(True)
def sample_refinement(pdb_filename, kT=1.0, smallmoves=3, shearmoves=5, backbone_angle_max=7, cycles=9, jobs=1, job_output='refine_output'): """ Performs fullatom structural refinement on the input <pdb_filename> by perturbing backbone torsion angles with a maximum perturbation of <backbone_angle_max> for <cycles> trials of <smallmoves> perturbations of a random residue's phi or psi and <shearmoves> perturbations of a random residue's phi and the preceding residue's psi followed by gradient based backbone torsion angle minimization and sidechain packing with an acceptance criteria scaled by <kT>. <jobs> trajectories are performed, continually exporting structures to a PyMOL instance. Output structures are named <job_output>_(job#).pdb. """ # 1. create a pose from the desired PDB file pose = Pose() pose_from_file(pose, pdb_filename) # 2. create a reference copy of the pose in fullatom starting_pose = Pose() starting_pose.assign(pose) # 3. create a standard ScoreFunction #### implement the desired ScoreFunction here scorefxn = get_fa_scorefxn() # create_score_function('standard') #### If you wish to use the ClassRelax protocol, uncomment the following #### line and comment-out the protocol setup below #refinement = protocols.relax.ClassicRelax( scorefxn ) #### Setup custom high-resolution refinement protocol #### backbone refinement protocol # 4. create a MoveMap, all backbone torsions free movemap = MoveMap() movemap.set_bb(True) # 5. create a SmallMover # a SmallMover perturbs a random (free in the MoveMap) residue's phi or psi # torsion angle for an input number of times and accepts of rejects this # change based on the Metropolis Criteria using the "rama" ScoreType and # the parameter kT # set the maximum angle to backbone_angle_max, apply it smallmoves times smallmover = protocols.simple_moves.SmallMover(movemap, kT, smallmoves) # angle_max is secondary structure dependent, however secondary structure # has not been evaulated in this protocol, thus they are all set # to the same value0 smallmover.angle_max(backbone_angle_max) # sets all at once #### use the overloaded version of the SmallMover.angle_max method if you #### want to use secondary structure biased moves #smallmover.angle_max('H', backbone_angle_max) #smallmover.angle_max('E', backbone_angle_max) #smallmover.angle_max('L', backbone_angle_max) # 6. create a ShearMover # a ShearMover is identical to a SmallMover except that the angles perturbed # are instead a random (free in the MoveMap) residue's phi and the # preceding residue's psi, this reduces the downstream structural change # set the maximum angle to backbone_angle_max, apply it shearmoves times shearmover = protocols.simple_moves.ShearMover(movemap, kT, shearmoves) # same angle_max restictions as SmallMover shearmover.angle_max(backbone_angle_max) #### use the overloaded version of the SmallMover.angle_max method if you #### want to use secondary structure biased moves #shearmover.angle_max('H', backbone_angle_max) #shearmover.angle_max('E', backbone_angle_max) #shearmover.angle_max('L', backbone_angle_max) # 7. create a MinMover, for backbone torsion minimization minmover = protocols.minimization_packing.MinMover() minmover.movemap(movemap) minmover.score_function(scorefxn) #### sidechain refinement protocol, simple packing # 8. setup a PackRotamersMover to_pack = standard_packer_task(starting_pose) to_pack.restrict_to_repacking() # prevents design, packing only to_pack.or_include_current(True) # considers the original sidechains packmover = protocols.minimization_packing.PackRotamersMover( scorefxn, to_pack) #### assess the new structure # 9. create a PyMOLMover pymover = PyMOLMover() # uncomment the line below to load structures into successive states #pymover.keep_history(True) #### the PyMOLMover slows down the protocol SIGNIFICANTLY but provides #### very informative displays #### the keep_history flag (when True) tells the PyMOLMover to store new #### structures into successive states, for a single trajectory, this #### allows you to see intermediate changes (depending on where the #### PyMOLMover is applied), when using a JobDistributor or otherwise #### displaying multiple trajectories with a single protocol, the output #### can get confusing to interpret, by changing the pose's PDBInfo.name #### the structure will load into a new PyMOL state #### try uncommenting the lines below to see different output #pymover.update_energy(True) # see the total score in color # 10. export the original structure, and scores, to PyMOL pymover.apply(pose) scorefxn(pose) pymover.send_energy(pose) # 11. setup a RepeatMover on a TrialMover of a SequenceMover (wow!) # -setup a TrialMover # a. create a SequenceMover of the previous moves #### add any other moves you desire combined_mover = SequenceMover() combined_mover.add_mover(smallmover) combined_mover.add_mover(shearmover) combined_mover.add_mover(minmover) combined_mover.add_mover(packmover) #### explore the protocol using the PyMOLMover, try viewing structures #### before they are accepted or rejected combined_mover.add_mover(pymover) # b. create a MonteCarlo object to define success/failure mc = MonteCarlo(pose, scorefxn, kT) # must reset for each trajectory! # c. create the TrialMover trial = TrialMover(combined_mover, mc) #### explore the protocol using the PyMOLMover, try viewing structures #### after acceptance/rejection, comment-out the lines below #original_trial = TrialMover(combined_mover, mc) #trial = SequenceMover() #trial.add_mover(original_trial) #trial.add_mover(pymover) #### for each trajectory, try cycles number of applications # -create the RepeatMover refinement = RepeatMover(trial, cycles) #### # 12. create a (Py)JobDistributor jd = PyJobDistributor(job_output, jobs, scorefxn) jd.native_pose = starting_pose # 13. store the score evaluations for output # printing the scores as they are produced would be difficult to read, # Rosetta produces a lot of verbose output when running scores = [0] * (jobs + 1) scores[0] = scorefxn(starting_pose) # 14. perform the refinement protocol counter = 0 # for exporting to PyMOL while not jd.job_complete: # a. set necessary variables for the new trajectory # -reload the starting pose pose.assign(starting_pose) # -change the pose's PDBInfo.name, for the PyMOLMover counter += 1 pose.pdb_info().name(job_output + '_' + str(counter)) # -reset the MonteCarlo object (sets lowest_score to that of p) mc.reset(pose) #### if you create a custom protocol, you may have additional #### variables to reset, such as kT #### if you create a custom protocol, this section will most likely #### change, many protocols exist as single Movers or can be #### chained together in a sequence (see above) so you need #### only apply the final Mover # b. apply the refinement protocol refinement.apply(pose) #### # c. output the lowest scoring decoy structure for this trajectory # -recover and output the decoy structure to a PDB file mc.recover_low(pose) jd.output_decoy(pose) # -export the final structure to PyMOL for each trajectory pose.pdb_info().name(job_output + '_' + str(counter) + '_final') pymover.apply(pose) pymover.send_energy(pose) # see the total score in color # -store the final score for this trajectory scores[counter] = scorefxn(pose) # 15. output the score evaluations print('Original Score\t:\t', scores[0]) for i in range(1, len(scores)): # print out the job scores print(job_output + '_' + str(i) + '\t:\t', scores[i]) return scores # for other protocols
def Fc_glycan_metrics( working, native, working_Fc_glycan_chains, native_Fc_glycan_chains, sf, decoy_num, dump_dir ): """ Return the glycan RMSD contribution of the two Fc glycans in 3ay4 (may work for other PDBs, but I don't know yet) Fc_glycan_buried_sasa = complex with Fc glycan - ( complex without Fc glycan + just Fc glycan ) hbonds contributed by Fc glycans = total hbonds in Pose - total hbonds in Pose without Fc glycans - just Fc glycan hbonds :param working: decoy Pose() :param native: native Pose() :param working_Fc_glycan_chains: list( the chain id's for the working Fc glycan ). Ex = [ 'H', 'I' ] :param native_Fc_glycan_chains: list( the chain id's for the native Fc glycan ). Ex = [ 'D', 'E' ] :param sf: ScoreFunction :param decoy_num: int( the number of the decoy for use when dumping its Fc glycan ) :param dump_dir: str( /path/to/dump_dir for the temp pdb files made. Files will be deleted ) :return: obj( DataHolder that contains Fc_glycan_rmsd, Fc_glycan_tot_score, Fc_glycan_buried_sasa, and Fc_glycan_internal_hbonds, Fc_glycan_hbonds_contributed ) """ ################# #### IMPORTS #### ################# # Rosetta functions from pyrosetta import Pose from rosetta.core.scoring import non_peptide_heavy_atom_RMSD, \ calc_total_sasa # Rosetta functions I wrote out from antibody_functions import load_pose, DataHolder # utility functions import os from util import dump_pdb_by_chain, id_generator from pyrosetta.toolbox import get_hbonds # for use in SASA calculations probe_size = 1.4 # get glycan rmsd (not using above function because I want to use the glycan poses for something else # get temporary files to work with id = id_generator() if dump_dir.endswith( '/' ): working_filename = "%s%s_temp_working_just_glyc%s.pdb" %( dump_dir, id, str( decoy_num ) ) native_filename = "%s%s_temp_native_just_glyc%s.pdb" %( dump_dir, id, str( decoy_num ) ) else: working_filename = "%s/%s_temp_working_just_glyc%s.pdb" %( dump_dir, id, str( decoy_num ) ) native_filename = "%s/%s_temp_native_just_glyc%s.pdb" %( dump_dir, id, str( decoy_num ) ) # dump out the Fc glycans by their chain id's dump_pdb_by_chain( working_filename, working, working_Fc_glycan_chains, decoy_num, dump_dir = dump_dir ) dump_pdb_by_chain( native_filename, native, native_Fc_glycan_chains, decoy_num, dump_dir = dump_dir ) # load in the Fc glycans working_just_Fc_glycan = Pose() try: working_just_Fc_glycan.assign( load_pose( working_filename ) ) except: pass native_just_Fc_glycan = Pose() try: native_just_Fc_glycan.assign( load_pose( native_filename ) ) except: pass # calculate the glycan rmsd try: glycan_rmsd = non_peptide_heavy_atom_RMSD( working_just_Fc_glycan, native_just_Fc_glycan ) except: glycan_rmsd = "nan" pass # get the metrics associated with just the Fc glycan # score first as to gain access to the hbonds data working_Fc_glycan_tot_score = sf( working_just_Fc_glycan ) native_Fc_glycan_tot_score = sf( native_just_Fc_glycan ) # SASA of just the glycan working_Fc_glycan_sasa = calc_total_sasa( working_just_Fc_glycan, probe_size ) native_Fc_glycan_sasa = calc_total_sasa( native_just_Fc_glycan, probe_size ) # num hbonds in Fc glycan working_Fc_glycan_internal_hbonds = get_hbonds( working_just_Fc_glycan ).nhbonds() native_Fc_glycan_internal_hbonds = get_hbonds( native_just_Fc_glycan ).nhbonds() # delete the files try: os.popen( "rm %s" %working_filename ) os.popen( "rm %s" %native_filename ) except: pass # now move to metrics requiring the removal of the glycan from the complex # get temporary files to work with id = id_generator() if dump_dir.endswith( '/' ): working_filename = "%s%s_working_no_glyc_%s.pdb" %( dump_dir, id, str( decoy_num ) ) native_filename = "%s%s_native_no_glyc_%s.pdb" %( dump_dir, id, str( decoy_num ) ) else: working_filename = "%s/%s_working_no_glyc_%s.pdb" %( dump_dir, id, str( decoy_num ) ) native_filename = "%s/%s_native_no_glyc_%s.pdb" %( dump_dir, id, str( decoy_num ) ) # get the chain id's of everything discluding the passed Fc glycan chain id's working_pose_chains = [] for res in working: chain_id = working.pdb_info().chain( res.seqpos() ) if ( chain_id not in working_pose_chains ) and ( chain_id not in working_Fc_glycan_chains ): working_pose_chains.append( chain_id ) native_pose_chains = [] for res in native: chain_id = native.pdb_info().chain( res.seqpos() ) if ( chain_id not in native_pose_chains ) and ( chain_id not in native_Fc_glycan_chains ): native_pose_chains.append( chain_id ) # dump out the pose without its Fc glycans by the chain id's dump_pdb_by_chain( working_filename, working, working_pose_chains, decoy_num, dump_dir = dump_dir ) dump_pdb_by_chain( native_filename, native, native_pose_chains, decoy_num, dump_dir = dump_dir ) # load in the working Pose without the Fc glycans working_complex_no_Fc_glycan = Pose() native_complex_no_Fc_glycan = Pose() try: working_complex_no_Fc_glycan.assign( load_pose( working_filename ) ) native_complex_no_Fc_glycan.assign( load_pose( working_filename ) ) except: pass # score the Poses so their hbond energies get updated sf( working ) sf( working_complex_no_Fc_glycan ) sf( native ) sf( native_complex_no_Fc_glycan ) # get the number of hbonds in the Pose without the Fc glycans # working working_with_Fc_glycan_hbonds = get_hbonds( working ) working_no_Fc_glycan_hbonds = get_hbonds( working_complex_no_Fc_glycan ) working_Fc_glycan_hbonds_contributed = working_with_Fc_glycan_hbonds.nhbonds() - working_no_Fc_glycan_hbonds.nhbonds() - working_Fc_glycan_internal_hbonds # native native_with_Fc_glycan_hbonds = get_hbonds( native ) native_no_Fc_glycan_hbonds = get_hbonds( native_complex_no_Fc_glycan ) native_Fc_glycan_hbonds_contributed = native_with_Fc_glycan_hbonds.nhbonds() - native_no_Fc_glycan_hbonds.nhbonds() - native_Fc_glycan_internal_hbonds # get the SASA contributed by the presence of the Fc glycan # working working_with_Fc_glycan_sasa = calc_total_sasa( working, probe_size ) working_no_Fc_glycan_sasa = calc_total_sasa( working_complex_no_Fc_glycan, probe_size ) working_Fc_glycan_sasa_contributed = working_with_Fc_glycan_sasa - ( working_no_Fc_glycan_sasa + working_Fc_glycan_sasa ) # native native_with_Fc_glycan_sasa = calc_total_sasa( native, probe_size ) native_no_Fc_glycan_sasa = calc_total_sasa( native_complex_no_Fc_glycan, probe_size ) native_Fc_glycan_sasa_contributed = native_with_Fc_glycan_sasa - ( native_no_Fc_glycan_sasa + native_Fc_glycan_sasa ) # delete the files try: os.popen( "rm %s" %working_filename ) os.popen( "rm %s" %native_filename ) except: pass # store data in the DataHolder and return it data = DataHolder() data.Fc_glycan_rmsd = glycan_rmsd data.Fc_glycan_tot_score = working_Fc_glycan_tot_score data.native_Fc_glycan_tot_score = native_Fc_glycan_tot_score data.Fc_glycan_internal_hbonds = working_Fc_glycan_internal_hbonds data.native_Fc_glycan_internal_hbonds = native_Fc_glycan_internal_hbonds data.Fc_glycan_hbonds_contributed = working_Fc_glycan_hbonds_contributed data.native_Fc_glycan_hbonds_contributed = native_Fc_glycan_hbonds_contributed data.Fc_glycan_sasa_contributed = working_Fc_glycan_sasa_contributed data.native_Fc_glycan_sasa_contributed = native_Fc_glycan_sasa_contributed data.probe_size = probe_size return data
def pseudo_interface_energy_3ay4( pose, in_sf, native = False, pmm = None ): """ Attempts to get pseudo-interface energy of a glycosylated 3ay4 decoy Lots of hard coding here - works on a decoy pose as Rosetta renumbers the Pose a bit Makes the two ASN connections to the Fc A and B glycans JUMPs instead of chemical EDGEs :param pose: Pose :param in_sf: ScoreFunction :param native: bool( is this the native 3ay4 or a decoy? Answer determines how FoldTree gets coded ) :param pmm: PyMOL_Mover( pass a PyMOL_Mover object if you want to watch the protocol ). Default = None :return: float( pseudo interface energy ) """ from pyrosetta import FoldTree, Pose from rosetta.numeric import xyzVector_double_t from rosetta.core.scoring import score_type_from_name # if this isn't the Fc-FcR structure of 3ay4, just return 0 if pose.size() != 618: return 0 # set atom_pair_constraint weight to 0 sf = in_sf.clone() sf.set_weight( score_type_from_name( "atom_pair_constraint" ), 0.0 ) # get the score of the whole complex start_score = sf( pose ) # hard code the new FoldTree specific to a glycosylated decoy of 3ay4 if not native: ft = FoldTree() ft.add_edge( 1, 215, -1 ) ft.add_edge( 1, 216, 1 ) # beginning of chain A to beginning of chain B ft.add_edge( 216, 431, -1 ) ft.add_edge( 1, 432, 2 ) # beginning of chain A to beginning of chain C ft.add_edge( 432, 591, -1 ) ft.add_edge( 579, 592, "ND2", "C1" ) ft.add_edge( 592, 596, -1 ) ft.add_edge( 594, 597, "O6", "C1" ) ft.add_edge( 597, 598, -1 ) ft.add_edge( 592, 599, "O6", "C1" ) ft.add_edge( 462, 600, "ND2", "C1" ) ft.add_edge( 600, 602, -1 ) ft.add_edge( 69, 603, 3 ) # ASN 297 A to core GlcNAc H ft.add_edge( 603, 607, -1 ) ft.add_edge( 605, 608, "O6", "C1" ) ft.add_edge( 608, 610, -1 ) ft.add_edge( 284, 611, 4 ) # ASN 297 B to core GlcNAc J ft.add_edge( 611, 615, -1 ) ft.add_edge( 613, 616, "O6", "C1" ) ft.add_edge( 616, 618, -1 ) # hard code the new FoldTree specific to the native 3ay4 else: ft = FoldTree() ft.add_edge( 1, 215, -1 ) ft.add_edge( 69, 216, 1 ) # ASN 297 A to core GlcNAc D ft.add_edge( 216, 220, -1 ) ft.add_edge( 218, 221, "O6", "C1" ) ft.add_edge( 221, 223, -1 ) ft.add_edge( 1, 224, 2 ) # beginning of chain A to beginning of chain B ft.add_edge( 224, 439, -1 ) ft.add_edge( 292, 440, 3 ) # ASN 297 B to core GlcNAc E ft.add_edge( 440, 444, -1 ) ft.add_edge( 442, 445, "O6", "C1" ) ft.add_edge( 445, 447, -1 ) ft.add_edge( 1, 448, 4 ) # beginning of chain A to beginning of chain C ft.add_edge( 448, 607, -1 ) ft.add_edge( 595, 608, "ND2", "C1" ) ft.add_edge( 608, 612, -1 ) ft.add_edge( 610, 613, "O6", "C1" ) ft.add_edge( 613, 614, -1 ) ft.add_edge( 608, 615, "O6", "C1" ) ft.add_edge( 478, 616, "ND2", "C1" ) ft.add_edge( 616, 618, -1 ) # make a temporary Pose and give the new FoldTree to it try: pmm.keep_history( True ) except: pass temp_pose = Pose() temp_pose.assign( pose ) temp_pose.fold_tree( ft ) try: pmm.apply( temp_pose ) except: pass # split apart the two Fc sugars one-by-one # if decoy structure -- the two glycans are now the last two new jumps if not native: jump = temp_pose.jump( 3 ) # sugar A vec = xyzVector_double_t( 1000, 1000, 1000 ) jump.set_translation( vec ) temp_pose.set_jump( 3, jump ) try: pmm.apply( temp_pose ) except: pass jump = temp_pose.jump( 4 ) # sugar B vec = xyzVector_double_t( 1000, 1000, 1000 ) jump.set_translation( vec ) temp_pose.set_jump( 4, jump ) try: pmm.apply( temp_pose ) except: pass # else native structure -- the two glycans are the first and third new jumps else: jump = temp_pose.jump( 1 ) # sugar A vec = xyzVector_double_t( 1000, 1000, 1000 ) jump.set_translation( vec ) temp_pose.set_jump( 1, jump ) try: pmm.apply( temp_pose ) except: pass jump = temp_pose.jump( 3 ) # sugar B vec = xyzVector_double_t( 1000, 1000, 1000 ) jump.set_translation( vec ) temp_pose.set_jump( 3, jump ) try: pmm.apply( temp_pose ) except: pass # score the split-apart Pose split_score = sf( temp_pose ) # get the pseudo-interface score # total - split = interface ( ie. interface + split = total ) pseudo_interface_energy = start_score - split_score return pseudo_interface_energy
print( 'Done Applying MinMover!' ) ''' #except rosetta.PyRosettaException: pass except RuntimeError: pass else: print( 'Was not able to finish min_mover in 10 tries, failing...' ) sys.exit(1) ''' # Low-Resolution Docking via RosettaDock switch_low = SwitchResidueTypeSetMover("centroid") pose_high = Pose() pose_high.assign(pose) switch_low.apply(pose) pose_low = Pose() pose_low.assign(pose) protocols.docking.setup_foldtree(pose_low, "A_B", Vector1([1])) scorefxn_low = create_score_function("interchain_cen") dock_lowres = protocols.docking.DockingLowRes(scorefxn_low, jump_num) dock_lowres.apply(pose_low) print( CA_rmsd(pose, pose_low) ) print( calc_Lrmsd(pose, pose_low, Vector1([1])) )