def mutate_residue(pose, mutant_position, mutant_aa, pack_radius=0.0, pack_scorefxn=None, repack_rotamers=0): """Replace the residue at a single position in a Pose with a new amino acid and repack any residues within user-defined radius of selected residue's center using. Args: pose (pyrosetta.rosetta.core.pose.Pose): mutant_position (int): Pose-numbered position of the residue to mutate. mutant_aa (str): The single letter name for the desired amino acid. pack_radius (float): Radius used to define neighboring residues. pack_scorefxn (pyrosetta.ScoreFunction): `ScoreFunction` to use when repacking the `Pose`. Defaults to the standard `ScoreFunction`. """ wpose = pose if not wpose.is_fullatom(): raise IOError("mutate_residue only works with fullatom poses") # create a standard scorefxn by default if not pack_scorefxn: pack_scorefxn = pyrosetta.get_score_function() # forces mutation mut = MutateResidue(mutant_position, common.atoms.aa_inv[mutant_aa]) mut.apply(wpose) # the numbers 1-20 correspond individually to the 20 proteogenic amino acids mutant_aa = int(aa_from_oneletter_code(mutant_aa)) aa_bool = pyrosetta.Vector1([aa == mutant_aa for aa in range(1, 21)]) # mutation is performed by using a PackerTask with only the mutant # amino acid available during design task = pyrosetta.standard_packer_task(wpose) 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 task = restrict_non_nbrs_from_repacking(wpose, mutant_position, task, pack_radius, repack_rotamers=repack_rotamers) # apply the mutation and pack nearby residues packer = PackRotamersMover(pack_scorefxn, task) packer.apply(wpose) # return pack_or_pose return wpose
def mutate_residue(pose, mutant_position, mutant_aa, pack_radius, pack_scorefxn): if pose.is_fullatom() == False: IOError('mutate_residue only works with fullatom poses') test_pose = Pose() test_pose.assign(pose) # Create a packer task (standard) task = TaskFactory.create_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 = 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 = 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 == 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): dist = center.distance_squared(test_pose.residue(i).nbr_atom_xyz()) # only pack the mutating residue and any within the pack_radius print(i, pack_radius, dist, pow(float(pack_radius), 2)) print('##################################################') if i != mutant_position and dist > pow(float(pack_radius), 2): task.nonconst_residue_task(i).prevent_repacking() # apply the mutation and pack nearby residues packer = PackRotamersMover(pack_scorefxn, task) packer.apply(test_pose) return test_pose
def make_point_changes(pose, task_factory, score_function): """ Applies point mutations to a given pose. This is done through a PackRotamersMover, followed by minimization. Inputs are a Pose, a TaskFactory, and a ScoreFunction """ # Make PackRotamersMover pack_rotamers = PackRotamersMover() pack_rotamers.score_function(score_function) pack_rotamers.task_factory(task_factory) # Make a copy Pose and apply the PackRotamersMover mutated_pose = pr.Pose(pose) pack_rotamers.apply(mutated_pose) # Set up fixed-backbone movemap for minimization movemap = pr.MoveMap() movemap.set_bb(True) movemap.set_chi(True) movemap.set_jump(True) # Create the MinMover min_mover = MinMover() min_mover.movemap(movemap) min_mover.score_function(score_function) # Apply the MinMover to the modified Pose min_mover.apply(mutated_pose) return mutated_pose
def repack_and_minimize_mutant(pose, task_factory, move_map, score_function, rounds=3): #Copying the pose ram_pose = pr.Pose(pose) #preparing repack and applying prm = PackRotamersMover() prm.score_function(score_function) prm.task_factory(task_factory) #preparing minimize and applying min_mover = MinMover() min_mover.movemap(move_map) min_mover.score_function(score_function) print_out("Checking Packertask") packer = task_factory.create_task_and_apply_taskoperations(pose) print_out("packer task") print_out(packer) for rnd in range(rounds): print_out("round " + str(rnd + 1) + " of repack and min") prm.apply(ram_pose) min_mover.apply(ram_pose) return ram_pose
print("emd182::Building score function") sf = pr.rosetta.core.scoring.ScoreFunction() sf.add_weights_from_file('ref2015') print("emd182::Setting up and making a mutation") res_mut = 30 mutater = pr.rosetta.protocols.simple_moves.MutateResidue() mutater.set_target(res_mut) mutater.set_res_name('AZC') mutater.apply(pose) print("emd182::Making Packertask and restricting to repacking") packer_task = pr.standard_packer_task(pose) packer_task.restrict_to_repacking() packer_task.set_bump_check(False) pack_mover = PackRotamersMover(sf, packer_task) rsf = RotamerSetFactory() rs = rsf.create_rotamer_set(pose) rs.set_resid(res_mut) sf(pose) packer_graph = pr.rosetta.core.pack.create_packer_graph(pose, sf, packer_task) rs.build_rotamers(pose, sf, packer_task, packer_graph) print(rs.rotamer(1).name(), rs.num_rotamers()) short_pose = pr.rosetta.core.pose.Pose() short_pose.detached_copy(pose) for i in range(1, rs.num_rotamers() + 1): short_pose.residue(res_mut).set_all_chi(rs.rotamer(i).chi()) short_pose.dump_pdb('mutated_pos_' + str(i) + '.pdb') #, res_mut_loc)
def make_residue_changes(pose, sf, subst_seq, subst_start, cat_res, manual_muts): """ Applies substrate sequence changes and manual mutations to a given pose. This is done through repacking, so unlike SimpleThreadingMover, the side chains don't begin clashing. This means that the residue selectors will be more accurate, and that design can begin without an initial relax step. pose is a Rosetta pose sf is a Rosetta scorefunction subst_seq is a string (doesn't need to be uppercase) subst_start is an integer corresponding to the first of a contiguous block of residues to re-sequence manual_muts is a list of two-member lists, of the following form: [site, single-letter residue name] """ # Create dict of {res: AA} for changes to make res_changes = {} # Add manual mutations list if manual_muts: print("\nApplying point substitutions:") for m in manual_muts: res_changes[int(m[0])] = m[1].upper() print(m[0], m[1].upper()) # Add substrate threading to list of res changes print("\nInserting substrate sequence:\n{}".format(subst_seq)) subst_range = range(subst_start, subst_start + len(subst_seq)) for n, i in enumerate(subst_range): res_changes[i] = subst_seq[n].upper() # Make TaskFactory to input changes mobile_residues = OrResidueSelector() # Keep list of mobile residues tf = TaskFactory() # Force packing to target residue for each desired change for r, aa in res_changes.items(): res_selection = ResidueIndexSelector(str(r)) restriction = RestrictAbsentCanonicalAASRLT() restriction.aas_to_keep(aa.upper()) tf.push_back(OperateOnResidueSubset(restriction, res_selection)) mobile_residues.add_residue_selector(res_selection) # Repack nearby residues to accommodate substitutions shell = NeighborhoodResidueSelector() shell.set_focus_selector(mobile_residues) shell.set_include_focus_in_subset(False) shell.set_distance(8) # Exclude catalytic residues if cat_res: catalytic = ResidueIndexSelector(','.join([str(i) for i in cat_res])) not_catalytic = NotResidueSelector(catalytic) shell = selector_intersection(shell, not_catalytic) restrict = RestrictToRepackingRLT() tf.push_back(OperateOnResidueSubset(restrict, shell)) # Prevent repacking of all other residues unchanging = NotResidueSelector(OrResidueSelector(mobile_residues, shell)) prevent = PreventRepackingRLT() tf.push_back(OperateOnResidueSubset(prevent, unchanging)) # Apply changes with PackRotamersMover pt = tf.create_task_and_apply_taskoperations(pose) prm = PackRotamersMover(sf, pt) mutated_pose = Pose(pose) prm.apply(mutated_pose) return mutated_pose
def get_designer_mover(score_function=DEFAULT.score_function, designable=DEFAULT.designable, repackable=DEFAULT.repackable, cutoff=DEFAULT.cutoff, ligand_chain=DEFAULT.ligand_chain, blocked_region=DEFAULT.blocked_region): """ Returns a design Mover. The design mover used in this example is a SequenceMover comprised of 2 movers: a PackRotamersMover and a MinMover, in this order. For the PackRotamersMover, extra rotamers on chi1 and chi2 are enabled. During this step, residues on the 'designable' ResidueSelector will be subject to design efforts, while residues on the 'repackable' ResidueSelector will only change conformation to rotamers of the same aminoacid. During the minimization step only the sidechains are allowed to relax. By default, when no custom designable or repackable ResidueSelector's are provided, both designable and repackable regions are set to 'auto', where the repackable region is defined as all the residues of the ligand_chain (C, by default) and the designable region is defined as the residues within a cutoff (9.0 Angstrom, by default) from the ligand_chain. If a blocked region is provided, no design nor repack will be performed on those residues. A blocked region is defined with the following syntax: "start-end", where start and end are residue index numbers. For example, blocking the region from residue 1 to 56, one would use "1-56". """ # --- SCORE FUNCTION if score_function == "auto": try: score_function = get_fa_scorefxn() except: score_function = get_fa_scorefxn() else: from pyrosetta.rosetta.core.scoring import ScoreFunction assert type(score_function) == ScoreFunction, \ "Score function for relaxer mover must be of type ScoreFunction." # --- DESIGNABLE REGION designable = get_designable_region(designable, cutoff, ligand_chain, blocked_region) # --- REPACKABLE REGION if repackable == "auto": repackable = ChainSelector(ligand_chain) else: assert isinstance(repackable, ResidueSelector) or repackable == "auto",\ "Repackable selection must be a ResidueSelector or set to 'auto'" task_factory = standard_task_factory() blockable = NotResidueSelector(OrResidueSelector(designable, repackable)) task_factory.push_back(ExtraRotamers(0, 1, 1)) # ex1 task_factory.push_back(ExtraRotamers(0, 2, 1)) # ex2 block = PreventRepackingRLT() # NO design, NO repacking repack = RestrictToRepackingRLT() # NO design, ONLY repacking task_factory.push_back(OperateOnResidueSubset(block, blockable)) task_factory.push_back(OperateOnResidueSubset(repack, repackable)) pack_mover = PackRotamersMover(score_function) pack_mover.task_factory(task_factory) move_map = MoveMap() move_map.set_chi(True) min_mover = MinMover() min_mover.movemap(move_map) min_mover.score_function(score_function) min_mover.min_type('lbfgs_armijo_nonmonotone') designer = SequenceMover() designer.add_mover(pack_mover) designer.add_mover(min_mover) return designer
task_factory = standard_task_factory() # An optinal but recommended Task is to include extra rotamers (away from # the regular optimums) for both chi1 (ex1) and chi2 (ex2) task_factory.push_back(ExtraRotamers(0, 1, 1)) # ex1 task_factory.push_back(ExtraRotamers(0, 2, 1)) # ex2 # Restrict the design to the residues on the interface and ligand stop = PreventRepackingRLT() blockable = NotResidueSelector(OrResidueSelector(designable, repackable)) task_factory.push_back(OperateOnResidueSubset(stop, blockable)) # However, on the ligand, perform repacking only repack_only = RestrictToRepackingRLT() task_factory.push_back(OperateOnResidueSubset(repack_only, repackable)) # Define the PackRotamersMover (with the defined TaskFactory): # This is essentially a MonteCarlo object. pack_mover = PackRotamersMover(score_function) pack_mover.task_factory(task_factory) # Define the Minimizer: # Define the MoveMap (allowing movement in the sidechains only): move_map = MoveMap() move_map.set_chi(True) # Ex. Set a single residue (1) Chi movements to False: # Ex. move_map.set_chi(1, False) # Ex. Set a range of residues (2 to 10) Chi movements to True: # Ex. move_map.set_chi_true_range(2, 10) # Note: Using the range, there's currently no function to set to False. # Ex. Visualize the current MoveMap: # Ex. move_map.show() # Define the MinMover (with the current MoveMap, Score Function and set # the minimization type to "lbfgs_armijo_nonmonotone"):
'N446E': 'pdz_relaxed_2.pdb_designed_9.pdb' } for des, muts in res_changes.items(): pp = pose_from_pdb('pdz_designs/examples/' + start_pdb[des]) peptide = ChainSelector('B') shell = NeighborhoodResidueSelector() shell.set_focus_selector(peptide) shell.set_include_focus_in_subset(True) shell.set_distance(12) mobile_residues = OrResidueSelector() tf = TaskFactory() tf.push_back(IncludeCurrent()) tf.push_back(ExtraRotamers(0, 1, 1)) tf.push_back(ExtraRotamers(0, 2, 1)) for r, aa in muts.items(): res_selection = ResidueIndexSelector(str(r)) restriction = RestrictAbsentCanonicalAASRLT() restriction.aas_to_keep(aa.upper()) tf.push_back(OperateOnResidueSubset(restriction, res_selection)) mobile_residues.add_residue_selector(res_selection) packable = AndResidueSelector(shell, NotResidueSelector(mobile_residues)) tf.push_back(OperateOnResidueSubset(RestrictToRepackingRLT(), packable)) not_changing = NotResidueSelector(shell) tf.push_back(OperateOnResidueSubset(PreventRepackingRLT(), not_changing)) pt = tf.create_task_and_apply_taskoperations(pose) prm = PackRotamersMover(sf, pt) prm.apply(pp) pp.dump_pdb('pdz_designs/design_models/pdz_' + des + '.pdb') # Run analyze_design_decoys.fix_file() # python relax_new_pdb.py $i -od fibrils_collaboration/pdz_designs/design_models/round_2/ -cst fibrils_collaboration/htra1_pdz.cst -ccw 0 -n 10