def ligand_neighbor_selection(lig, radius, pose, include_ligand=False): rad = float(radius) not_ligand = NotResidueSelector() not_ligand.set_residue_selector(lig) lig_distant_neighbors = InterGroupInterfaceByVectorSelector() lig_distant_neighbors.group1_selector(lig) lig_distant_neighbors.group2_selector(not_ligand) lig_distant_neighbors.cb_dist_cut(2.0 * rad) lig_distant_neighbors.nearby_atom_cut(rad) lig_contacts = pr.rosetta.core.select.residue_selector.CloseContactResidueSelector( ) lig_contacts.central_residue_group_selector(lig) lig_contacts.threshold(rad) lig_neighbors = OrResidueSelector() lig_neighbors.add_residue_selector(lig_distant_neighbors) lig_neighbors.add_residue_selector(lig_contacts) if include_ligand: selection = AndResidueSelector() selection.add_residue_selector(not_ligand) else: selection = OrResidueSelector() selection.add_residue_selector(lig) selection.add_residue_selector(lig_neighbors) return get_residues_from_subset(selection.apply(pose))
def packable_residues_selector(peptide_selection, mutable_selection, catalytic_selection): """ Selects the shell of neighbor residues to repack. Packable set should not include the mutable set, since the action is RestrictToRepacking. """ # Making negative selections for mutable and catalytic not_mutable = NotResidueSelector(mutable_selection) not_catalytic = NotResidueSelector(catalytic_selection) # Selecting residues near mutable shell near_mutable = InterGroupInterfaceByVectorSelector() near_mutable.group1_selector(not_mutable) near_mutable.group2_selector(mutable_selection) near_mutable.nearby_atom_cut(8) near_mutable.vector_dist_cut(10) # Selecting residues near the peptide, with wider range for BB mobility near_pep = InterGroupInterfaceByVectorSelector() near_pep.group1_selector(not_mutable) near_pep.group2_selector(peptide_selection) near_pep.nearby_atom_cut(10) near_pep.vector_dist_cut(12) # Combining selections for peptide and near peptide and near mutable inclusive_packable = selector_union( near_mutable, near_pep, peptide_selection, ChainSelector('B')) ##################Chain B hacky # Setting up exclusion of catalytic and mutable residues exclusive_packable = selector_intersection(inclusive_packable, not_mutable, not_catalytic) return exclusive_packable
def interaction_energy_addition(pose, lig_res_selector, sf, add_to_dict, cisortrans): not_lig = NotResidueSelector() not_lig.set_residue_selector(lig_res_selector) interact_metric = InteractionEnergyMetric() interact_metric.set_scorefunction(sf) interact_metric.set_residue_selectors(lig_res_selector, not_lig) add_to_dict['interE_' + cisortrans] = interact_metric.calculate(pose)
def mutable_residues_selector(protease_selection, peptide_selection, catalytic_selection, design_peptide=False): """ Selects the residues in a shell around the peptide using the InterGroupInterfaceByVectorSelector residue selector """ # Making protease shell selector (includes peptide) first_shell_select = InterGroupInterfaceByVectorSelector() first_shell_select.group1_selector(protease_selection) first_shell_select.group2_selector(peptide_selection) first_shell_select.nearby_atom_cut(8) first_shell_select.vector_dist_cut(10) # Excluding the catalytic residues, peptide (if not designed) not_cats_sel = NotResidueSelector(catalytic_selection) if design_peptide: mutable_selection = selector_intersection(not_cats_sel, first_shell_select) else: mutable_selection = selector_intersection(not_cats_sel, first_shell_select, protease_selection) return mutable_selection
def check_selection_proximity(pose, selection_1, selection_2): """ Determines whether any residues in one selector are close enough to potentially interact with residues from a second selector, using an InterGroupInterfaceByVector selector with default settings. """ # Make full-pose selection full_pose = TrueResidueSelector() # Make selection for the full pose minus the first selector not_selection_1 = NotResidueSelector(selection_1) full_minus_1 = selector_intersection(full_pose, not_selection_1) # Make selection for interacting residues between selection 1 the rest of the pose igibv = InterGroupInterfaceByVectorSelector() igibv.group1_selector(selection_1) igibv.group2_selector(full_minus_1) # Find intersection of selector_1's interaction partners and selector_2 selection_overlap = selector_intersection(igibv, selection_2) # Check if there are residues in the intersection, or if it is empty # If it is empty, the Boolean will be False. Otherwise, it will be True selections_do_overlap = bool(selector_to_list(pose, selection_overlap)) return selections_do_overlap
def task_factory_builder(repacking_residues='all', designing_residues=None, \ extra_rotamers=[1,2]): #Setting this up for now, need to implement these conditions: #Repackable set, Designable Set, prevent ligand repacking #Building a Task Factory for repacking/design around the neighbors residues #Task factory builder should accept: repackable residues, designable #residues, specifically preventing repacking residues, and prevent the rest. #tf = task_factory_builder(repack=repacking_neighbors) #distance - distance for Neighborhood residue selector - need to remov print_out("Building task factory") #Start up Task factory, starting ex1 and ex2, and include current tf = TaskFactory() tf.push_back(IncludeCurrent()) if extra_rotamers: for x in extra_rotamers: tf.push_back(ExtraRotamers(0, x, 1)) print(repacking_residues) #Set up repack and prevent repack repack = RestrictToRepackingRLT() prevent = PreventRepackingRLT() prevent_everything_else = NotResidueSelector() residues_for_repack = None residues_for_design = None changing_residues = OrResidueSelector() if repacking_residues != 'all': print_out("Repacking these residues: " + str(repacking_residues)) residues_for_repack = ResidueIndexSelector( ','.join(repacking_residues)) changing_residues.add_residue_selector(residues_for_repack) tf.push_back(OperateOnResidueSubset(repack, residues_for_repack)) if designing_residues: residues_for_design = ResidueIndexSelector(designing_residues) changing_residues.add_residue_selector(residues_for_design) prevent_everything_else.set_residue_selector(changing_residues) if repack == 'all': tf.push_back(OperateOnResidueSubset(repack, prevent_everything_else)) else: tf.push_back(OperateOnResidueSubset(prevent, prevent_everything_else)) return tf
def create_enzyme_design_task_factory(active_site_positions: list, neighborhood: float = 0, \ cystine: bool = True, noncanonical_amino_acids: list = list()): task_factory = TaskFactory() if len(noncanonical_amino_acids) > 0: ncaa_palette = CustomBaseTypePackerPalette() for ncaa in noncanonical_amino_acids: ncaa_palette.add_type(ncaa) task_factory.set_packer_palette(ncaa_palette) task_factory.push_back(IncludeCurrent()) # Mutatable enzyme_core_selector = ResidueIndexSelector(','.join( str(active_site_position) for active_site_position in active_site_positions)) interface_selector = InterGroupInterfaceByVectorSelector() interface_selector.group1_selector(enzyme_core_selector) interface_selector.group2_selector( NotResidueSelector(enzyme_core_selector)) designable_selector = AndResidueSelector( interface_selector, NotResidueSelector(enzyme_core_selector)) if not cystine: restriction = RestrictAbsentCanonicalAASRLT() restriction.aas_to_keep('AGILPVFWYDERHKSTMNQ') # AGILPVFWYDERHKSTCMNQ task_factory.push_back( OperateOnResidueSubset(restriction, designable_selector)) # Repack repack = RestrictToRepackingRLT() if neighborhood > 0: repacking_wo_enzyme_core_selector = NeighborhoodResidueSelector() repacking_wo_enzyme_core_selector.set_focus_selector( interface_selector) repacking_wo_enzyme_core_selector.set_distance(neighborhood) repacking_wo_enzyme_core_selector.set_include_focus_in_subset(False) repacking_selector = OrResidueSelector( repacking_wo_enzyme_core_selector, enzyme_core_selector) task_factory.push_back( OperateOnResidueSubset(repack, repacking_selector)) prevent = PreventRepackingRLT() task_factory.push_back( OperateOnResidueSubset( prevent, OrResidueSelector(designable_selector, repacking_selector), True)) else: task_factory.push_back( OperateOnResidueSubset(repack, designable_selector, True)) return task_factory
def packable_residues_selector(mutable_selector): """ Selects the shell of neighbor residues to repack Presently hard coded for HCV protease. """ # Selecting regions mutable = mutable_selector not_mutable = NotResidueSelector(mutable_selector) catalytic = ResidueIndexSelector('72,96,154') peptide = ChainSelector('B') pep_not_mutable = AndResidueSelector() pep_not_mutable.add_residue_selector(peptide) pep_not_mutable.add_residue_selector(not_mutable) # Selecting residues near mutable shell near_mutable = InterGroupInterfaceByVectorSelector() near_mutable.group1_selector(not_mutable) near_mutable.group2_selector(mutable) near_mutable.nearby_atom_cut(4) near_mutable.vector_dist_cut(4) # Selecting residues near the peptide near_pep = InterGroupInterfaceByVectorSelector() near_pep.group1_selector(not_mutable) # Protease near_pep.group2_selector(peptide) # Peptide recognition region near_pep.nearby_atom_cut(10) near_pep.vector_dist_cut(12) # Combining selections for near peptide and near mutable residues wide_set = OrResidueSelector() wide_set.add_residue_selector(near_mutable) wide_set.add_residue_selector(near_pep) # Setting up exclusion of catalytic and mutable residues limit_selection = AndResidueSelector() limit_selection.add_residue_selector(NotResidueSelector(catalytic)) limit_selection.add_residue_selector(wide_set) limit_selection.add_residue_selector(not_mutable) # Add back in the peptide expand_selection = OrResidueSelector() expand_selection.add_residue_selector(limit_selection) expand_selection.add_residue_selector(pep_not_mutable) return expand_selection
def shell_selection(selection_1, selection_2, base_range): shell_select = InterGroupInterfaceByVectorSelector() shell_select.group1_selector(selection_1) shell_select.group2_selector(selection_2) shell_select.nearby_atom_cut(base_range) shell_select.vector_dist_cut(base_range + 2) return AndResidueSelector(shell_select, NotResidueSelector(selection_2))
def other_residues_selector(mutable_selector, packable_selector): """ Selects the residues that are not designable or repackable """ all_mobile_res = OrResidueSelector() all_mobile_res.add_residue_selector(mutable_selector) all_mobile_res.add_residue_selector(packable_selector) other_res_selector = NotResidueSelector(all_mobile_res) return other_res_selector
def create_coord_cst(ref_pose=None, free_res_indexes=None): coord_cst_gen = CoordinateConstraintGenerator() if ref_pose: coord_cst_gen.set_reference_pose(ref_pose) if free_res_indexes: free_res_selector = ResidueIndexSelector(','.join( str(free_res_index) for free_res_index in free_res_indexes)) coord_cst_gen.set_residue_selector( NotResidueSelector(free_res_selector)) return coord_cst_gen
def make_task_factory(residue_selectors, confine_design=None): """ Makes a TaskFactory with operations that leave the mutable residues designable, restricts the nearby residues to repacking, and prevents repacking of other residues. Also includes the ability to take in a target residue mutatations text file in the form: res_number allowed_AAs for example: 138 KR All designable residues not listed in the file are restricted to repacking and the listed residues are limited in their design options to those AAs listed. """ design_set = residue_selectors['mutable'] repack_set = residue_selectors['packable'] other_set = residue_selectors['other'] prevent = PreventRepackingRLT() # No repack, no design repack = RestrictToRepackingRLT() # No design tf = TaskFactory() tf.push_back(OperateOnResidueSubset(prevent, other_set)) tf.push_back(OperateOnResidueSubset(repack, repack_set)) # Everything else left designable by default # Restricting design further if confine_design: trms = readfile(confine_design) # Converting lines to a dict limited_set = \ {int(line.split()[0]):line.split()[1] for line in trms} # Converting residues in the dict to a selector res_concatenated = str(limited_set.keys()).strip('[]').replace(' ','') small_des_set = ResidueIndexSelector(res_concatenated) now_only_repack = NotResidueSelector(small_des_set) # Making residue selection excluding residues in the file and # restricting them to repacking no_longer_designable = AndResidueSelector() no_longer_designable.add_residue_selector(design_set) no_longer_designable.add_residue_selector(now_only_repack) tf.push_back(OperateOnResidueSubset(repack, no_longer_designable)) # Limiting design on residues in the file for res, AAs in limited_set.items(): designable_res = ResidueIndexSelector(str(res)) restrict_AAs = RestrictAbsentCanonicalAASRLT() restrict_AAs.aas_to_keep(AAs) tf.push_back(OperateOnResidueSubset(restrict_AAs, designable_res)) return tf
def select_residues(cat_res, peptide_subset, design_protease=True, design_peptide=False): """ Makes residue selectors for protease sections. Requires manual input for which residues are catalytic and whether only part of the peptide should be selected. Options for whether the peptide is designable (false by default) and whether the protease is designable (true by default). Assumes that the protease is chain A and the peptide is chain B. """ residue_selectors = {} # Protease residues. Protease assumed to be chain A protease = ChainSelector("A") residue_selectors['protease'] = protease # Peptide residues. Peptide assumed to be chain B, unless range specified if peptide_subset: peptide = ResidueIndexSelector(peptide_subset) else: peptide = ChainSelector("B") residue_selectors['peptide'] = peptide # Catalytic residues. ResidueIndexSelector needs a string, not a list. if cat_res: cats_as_str = ','.join([str(i) for i in cat_res]) catalytic = ResidueIndexSelector(cats_as_str) else: # If no catalytic residues are given, return a null selector catalytic = selector_intersection(protease, peptide) # Empty set residue_selectors['catalytic'] = catalytic # Designable residues. May include protease and peptide, just one, or none if design_protease: mutable = mutable_residues_selector(protease, peptide, catalytic, design_peptide) elif design_peptide: mutable = peptide else: # Neither protease not peptide designable mutable = selector_intersection(protease, peptide) # Empty set residue_selectors['mutable'] = mutable # Packable residues. Centered around the peptide and designable set packable = packable_residues_selector(peptide, mutable, catalytic) residue_selectors['packable'] = packable # Immobile residues. Catalytic residues and everything that isn't mutable # or packable immobile = NotResidueSelector(selector_union(mutable, packable)) residue_selectors['immobile'] = immobile return residue_selectors
def make_task_factory(repackable_selection): """ Creates a task factory with residues in a selection repackable (not designable), and all other residues fixed. """ # Repack options prevent = PreventRepackingRLT() # No repack, no design repack = RestrictToRepackingRLT() # No design # Creating compliment selection fixed_selection = NotResidueSelector(repackable_selection) # Making task factory tf = TaskFactory() tf.push_back(OperateOnResidueSubset(prevent, fixed_selection)) tf.push_back(OperateOnResidueSubset(repack, repackable_selection)) return tf
def design(self, antibody=True, antigen=False, pack_only=False): self.pose = self.native_pose.clone() info = self.pose.pdb_info() tf = TaskFactory() tf.push_back(operation.InitializeFromCommandline()) epi_res = '' for res in self.epitopes_pose: epi_res += '{0},'.format(res) epi_selector = ResidueIndexSelector(epi_res) antibody_selector = ChainSelector() vec = vector1_std_string() for chain in self.antibody: vec.append(chain) vec.append(chain) antibody_selector.set_chain_strings(vec) interface_res_selector = InterGroupInterfaceByVectorSelector( epi_selector, antibody_selector) interface_antibody_selector = AndResidueSelector( interface_res_selector, antibody_selector) if pack_only: tf.push_back(operation.RestrictToRepacking()) else: if antigen: design_selector = epi_selector elif antibody: design_selector = interface_antibody_selector # FIRST select designable residues and prevent everything else from design and packing no_design_selector = NotResidueSelector(design_selector) prevent_repacking_rlt = operation.PreventRepackingRLT() #restrict_topack = operation.RestrictToRepackingRLT() prevent_design = operation.OperateOnResidueSubset( prevent_repacking_rlt, no_design_selector, False) tf.push_back(prevent_design) print(tf.create_task_and_apply_taskoperations(self.pose)) packer = pack_min.PackRotamersMover('ref2015') packer.task_factory(tf) packer.apply(self.pose)
def make_point_mutant_task_factory(site_1, change_1, site_2=None, change_2=None, fast=True): """ Given a site integer and a 1-letter residue name (or two sites and two residue names), generates a TaskFactory to repack all residues in a pose with the altered sites repacking to the new sequence. """ # Initialize selection of all altered residues modified_residues = OrResidueSelector() # Keep list of mobile residues # Make TaskFactory to input changes task_factory = TaskFactory() task_factory.push_back(IncludeCurrent()) if not fast: task_factory.push_back(ExtraRotamers(0, 1, 1)) task_factory.push_back(ExtraRotamers(0, 2, 1)) # Force packing to new residue for the mutated site res_selection_1 = ResidueIndexSelector(str(site_1)) aa_force_1 = RestrictAbsentCanonicalAASRLT() aa_force_1.aas_to_keep(change_1) task_factory.push_back(OperateOnResidueSubset(aa_force_1, res_selection_1)) modified_residues.add_residue_selector(res_selection_1) # Add second site if necessary if site_2 and change_2: res_selection_2 = ResidueIndexSelector(str(site_2)) aa_force_2 = RestrictAbsentCanonicalAASRLT() aa_force_2.aas_to_keep(change_2) task_factory.push_back( OperateOnResidueSubset(aa_force_2, res_selection_2)) modified_residues.add_residue_selector(res_selection_2) # Repack all other residues to accommodate substitutions unchanged_residues = NotResidueSelector(modified_residues) repack = RestrictToRepackingRLT() task_factory.push_back(OperateOnResidueSubset(repack, unchanged_residues)) return task_factory
def mutable_residues_selector(design_peptide=False, single_pep_res=None): """ Selects the residues in a shell around the peptide using the InterGroupInterfaceByVectorSelector residue selector Presently hard coded for HCV protease. Decided to design just around peptide, not pep + cat, and only the six mutable residues in the peptide. """ # Selecting regions protease = ChainSelector("A") catalytic = ResidueIndexSelector('72,96,154') if single_pep_res: variable_pep_res = ResidueIndexSelector(str(single_pep_res)) else: variable_pep_res = ResidueIndexSelector("198-203") # Making positive residue selector rs = InterGroupInterfaceByVectorSelector() rs.group1_selector(protease) # Protease rs.group2_selector(variable_pep_res) # Peptide recognition region rs.nearby_atom_cut(6) rs.vector_dist_cut(8) # Excluding the catalytic residues limit_selection = AndResidueSelector() limit_selection.add_residue_selector(NotResidueSelector(catalytic)) limit_selection.add_residue_selector(rs) # If the peptide sequence is mutable if design_peptide: return limit_selection # If only the protease is designable else: # Setting up exclusion of catalytic and peptide residues exclusive_selection = AndResidueSelector() exclusive_selection.add_residue_selector(limit_selection) exclusive_selection.add_residue_selector(ChainSelector("A")) return exclusive_selection
def create_relax_task_factory(point_mutations: list = list(), active_site_positions: list = list(), neighborhood: float = 0): task_factory = TaskFactory() task_factory.push_back(IncludeCurrent()) repack = RestrictToRepackingRLT() prevent = PreventRepackingRLT() if len(point_mutations) > 0: # Mutate mutated_selector = OrResidueSelector() for point_mutation in point_mutations: mutation_info = point_mutation.split(',') restriction = RestrictAbsentCanonicalAASRLT() restriction.aas_to_keep(mutation_info[1]) point_mutation_selector = ResidueIndexSelector(mutation_info[0]) task_factory.push_back( OperateOnResidueSubset(restriction, point_mutation_selector)) mutated_selector.add_residue_selector(point_mutation_selector) # Repack and static if neighborhood > 0: if len(active_site_positions) > 0: # Repack enzyme_core_selector = ResidueIndexSelector(','.join( str(active_site_position) for active_site_position in active_site_positions)) designable_repacking_selector = NeighborhoodResidueSelector() designable_repacking_selector.set_focus_selector( OrResidueSelector(mutated_selector, enzyme_core_selector)) designable_repacking_selector.set_distance(neighborhood) designable_repacking_selector.set_include_focus_in_subset(True) repacking_selector = AndResidueSelector( designable_repacking_selector, NotResidueSelector(mutated_selector)) task_factory.push_back( OperateOnResidueSubset(repack, repacking_selector)) # Static task_factory.push_back( OperateOnResidueSubset(prevent, designable_repacking_selector, True)) else: # Repack repacking_selector = NeighborhoodResidueSelector() repacking_selector.set_focus_selector(mutated_selector) repacking_selector.set_distance(args.neighborhood) repacking_selector.set_include_focus_in_subset(False) task_factory.push_back( OperateOnResidueSubset(repack, repacking_selector)) # Static mutated_and_repacking_selector = OrResidueSelector( mutated_selector, repacking_selector) task_factory.push_back( OperateOnResidueSubset(prevent, mutated_and_repacking_selector, True)) else: # Repack task_factory.push_back( OperateOnResidueSubset(repack, mutated_selector, True)) else: if neighborhood > 0: if len(active_site_positions) > 0: # Repack enzyme_core_selector = ResidueIndexSelector(','.join( str(active_site_position) for active_site_position in active_site_positions)) repacking_selector = NeighborhoodResidueSelector() repacking_selector.set_focus_selector(enzyme_core_selector) repacking_selector.set_distance(neighborhood) repacking_selector.set_include_focus_in_subset(True) task_factory.push_back( OperateOnResidueSubset(repack, repacking_selector)) # Static task_factory.push_back( OperateOnResidueSubset(prevent, repacking_selector, True)) else: # Static task_factory.push_back(PreventRepacking()) else: # Repack task_factory.push_back(RestrictToRepacking()) return task_factory
'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
def residue_pairs( self, primary_residue_selector=TrueResidueSelector(), secondary_residue_selector=TrueResidueSelector(), neighborhood_distance_maximum=None, sequence_distance_minimum=None, ): """Iterate the permutations of residue pairs from two selections which are within a cartesian and/or outside a sequence distance cutoff. The method uses the PrimarySequenceNeighborhoodSelector and NeighborhoodResidueSelector under the hood. Note that all _permutations_ of residues are yielded, not _combinations_. If you prefer combinations simply check `if residue_pair[0].sequence_position() > residue_pair[1].sequence_position():`. primary_residue_selector - ResidueSelector secondary_residue_selector - ResidueSelector neighborhood_distance - float sequence_distance - int return - iterator(tuple(Residue, Residue)) """ primary_residue_selection = primary_residue_selector.apply(self) primary_residue_indices = get_residues_from_subset(primary_residue_selection) for primary_residue_index in primary_residue_indices: temp_secondary_residue_selector = secondary_residue_selector primary_residue_index_selector = ResidueIndexSelector(primary_residue_index) temp_secondary_residue_selector = AndResidueSelector( temp_secondary_residue_selector, NotResidueSelector(primary_residue_index_selector), ) if ( neighborhood_distance_maximum ): # Select residues within cartesian neighborhood distance neighborhood_residue_selector = NeighborhoodResidueSelector( primary_residue_index_selector, neighborhood_distance_maximum, False ) temp_secondary_residue_selector = AndResidueSelector( temp_secondary_residue_selector, neighborhood_residue_selector ) if ( sequence_distance_minimum ): # Select residues outside sequence neighborhood distance sequence_residue_selector = PrimarySequenceNeighborhoodSelector( sequence_distance_minimum, sequence_distance_minimum, primary_residue_index_selector, ) temp_secondary_residue_selector = AndResidueSelector( temp_secondary_residue_selector, NotResidueSelector(sequence_residue_selector), ) secondary_residue_selection = temp_secondary_residue_selector.apply(self) secondary_residue_indices = get_residues_from_subset( secondary_residue_selection ) for secondary_residue_index in secondary_residue_indices: yield tuple( [ self.residues[primary_residue_index], self.residues[secondary_residue_index], ] )
def main(args): #Determining if the ligand should be removed or not #Need to be moved here as checking if the lig remains is #Imperative for how the CST file is dealt with. out_ligand_file = 'yeslig' if args.remove_ligand: args.rigid_ligand = False out_ligand_file = 'nolig' params = [args.unnatural] uaa = params[0].split('/')[-1].strip(".params") if args.ligand_type == 'ligand': params.append(args.ligand_name) lig_name = args.ligand_name.split('/')[-1].strip('.params') init_args = ' '.join(['-run:preserve_header', '-extra_res_fa'] + params) #Adding enzdes constraint file - and editing it - if necessary if args.enzdes_constraint_file: if out_ligand_file == 'nolig': if args.ligand_type == 'protein': lig_search = args.residue_set elif args.ligand_type == 'ligand': lig_search = args.ligand_name args.input_pdb, args.enzdes_constraint_file = enzdes_constraint_eliminator(\ args.input_pdb, args.enzdes_constraint_file, ligand=lig_search ) #init_args = init_args + " -enzdes::cstfile " + str(args.enzdes_constraint_file) #Starting up rosetta with the appropriate params files - #-- need both unnatural aa and ligand file to be added (if the ligand isn't a protein). print_out("emd182::Starting rosetta with the following parameters: " + init_args) pr.init(init_args) file_options = pr.rosetta.core.io.StructFileRepOptions() file_options.set_preserve_header(bool(True)) pose = pr.pose_from_pdb(args.input_pdb) #Residue selection if args.residue_number != '0': delta_resi = ResidueIndexSelector(args.residue_number) #Determining if the interacting ligand is a protein or small molecule #and selecting the appropriate residues if args.ligand_type == 'protein': ligand = ResidueIndexSelector(args.residue_set) elif args.ligand_type == 'ligand': ligand = ResidueNameSelector() ligand.set_residue_name3(lig_name) #Adding the unnatural at the mutation site print_out("Loading Unnatural " + uaa + \ " onto residue number " + args.residue_number ) if args.residue_number in selector_to_vector(ligand, pose): print_out( "Selected residue number IS a part of the ligand. Don't do that. \ Chosen residue number: " + str(args.residue_number)) #Setting up Mutation function on the correct residue, so long as the #residue isn't #0 if args.residue_number != '0': mutater = pr.rosetta.protocols.simple_moves.MutateResidue() mutating_residue = ResidueIndexSelector(args.residue_number) mutater.set_selector(mutating_residue) mutater.set_res_name(uaa) print_out("emd182::loading residue to mutate into: " + str(args.residue_number)) lig_vector = selector_to_vector(ligand, pose) if args.residue_number != '0': if args.ligand_type == 'protein' and delta_resi in lig_vector: print_out("Selected residue for mutation is part of input selection: " + \ delta_resi + " is selected, but is contained in " \ + str(lig_vector)) print_out("Exiting the python script") sys.exit() print_out("emd182::Start mutations and relaxation script " \ + str(args.nstruct) + " times.") if args.residue_number == '0': args.nstruct = 1 for struct in range(0, args.nstruct): print_out(struct) mutant_pose = pr.Pose(pose) #Residue selection if args.residue_number != '0': delta_resi = ResidueIndexSelector(args.residue_number) #apply mutation if args.residue_number != '0': mutater.apply(mutant_pose) if args.dihedral_constraint_atoms: dihedral_atoms = args.dihedral_constraint_atoms.split(';') dihedral_values = args.dihedral_constraint_degrees.split(';') dihedral_cst_stdev = args.dihedral_constraint_stdev.split(';') for dihedrals in range(len(dihedral_atoms)): apply_dihedral_constraint(dihedral_atoms[dihedrals].split(','), \ delta_resi, mutant_pose, dihedral_values[dihedrals],\ dihedral_cst_stdev[dihedrals]) move_map = build_move_map(True, True, True) #Scoring the pose sf = pr.rosetta.core.scoring.ScoreFunction() if args.symmdef_file: #Setting a residueindexselector to eliminate all extra aa post design pre_symm_ris = ResidueIndexSelector() all_aa = [] for i in range(1, mutant_pose.total_residue() + 1): all_aa.append(''.join( mutant_pose.pdb_info().pose2pdb(i).split())) pre_symm_ris.set_index(','.join(all_aa)) #sys.exit() #Symmetrizing sfsm = SetupForSymmetryMover(args.symmdef_file) sfsm.apply(mutant_pose) sf = pr.rosetta.core.scoring.symmetry.SymmetricScoreFunction() sf.add_weights_from_file('ref2015_cst') else: sf = pr.rosetta.core.scoring.ScoreFunction() sf.add_weights_from_file('ref2015_cst') sf(mutant_pose) #apply mutation if args.residue_number != '0': mutater.apply(mutant_pose) if args.dihedral_constraint_atoms: dihedral_atoms = args.dihedral_constraint_atoms.split(';') dihedral_values = args.dihedral_constraint_degrees.split(';') dihedral_cst_stdev = args.dihedral_constraint_stdev.split(';') for dihedrals in range(len(dihedral_atoms)): apply_dihedral_constraint(dihedral_atoms[dihedrals].split(','), \ delta_resi, mutant_pose, dihedral_values[dihedrals],\ dihedral_cst_stdev[dihedrals]) #Making appropriate residue selections base on if the ligand will be #Removed or not, as well as if the ligand is rigid or not. residues_around_ligand = ligand_neighbor_selection(ligand, args.radius, \ mutant_pose, bool(args.rigid_ligand) ) if args.residue_number != '0': residues_around_mutant = ligand_neighbor_selection(mutating_residue, \ args.radius, mutant_pose, True) design_around_mutant = None #if design is turned on, will design around the mutant. #Can add more variability later if args.design and args.residue_number != '0': designing_residues = ligand_neighbor_selection(mutating_residue, \ args.design, mutant_pose, False) #Combining the repacking neighborhoods around the ligand and mutant if args.residue_number != '0': repacking_neighbors = residue_selection(residues_around_ligand, \ residues_around_mutant) else: repacking_neighbors = ResidueIndexSelector(residues_around_ligand) #Specifically converting residue selectors to vectors, and removing the #Appropriate residue ids from the lists of repacking or designing residues repacking_resids = selector_to_vector(repacking_neighbors, mutant_pose) if args.rigid_ligand: lig_resids = selector_to_vector(ligand, mutant_pose) for res in lig_resids: if res in repacking_resids: repacking_resids.remove(res) if args.design: designing_resids = selector_to_vector(designing_residues, mutant_pose) for res in lig_resids: if res in designing_resids: repacking_resids.remove(res) #If the remove-ligand is called, will remove the ligand from the mutant pose #Change 'remove-ligand' to 'translate region - makes for if args.remove_ligand: used_xyzs = [] for chain in args.remove_ligand.split(','): x, y, z = random_direction_selector(used_xyzs) used_xyzs.append(np.array([x, y, z])) trans_vec = pr.rosetta.numeric.xyzVector_double_t(x, y, z) trans = pr.rosetta.protocols.rigid.RigidBodyTransMover( trans_vec) jump_id = pr.rosetta.core.pose.get_jump_id_from_chain( chain, mutant_pose) trans.rb_jump(jump_id) trans.step_size(500.0) trans.apply(mutant_pose) tf = task_factory_builder(repacking_residues=repacking_resids, \ designing_residues=design_around_mutant) move_map = build_move_map(True, True, True) #turn on match constraints if needed: if args.enzdes_constraint_file: if not args.remove_ligand: print_out( 'The code will break if the constraint file is attached \ to the ligand that is being removed') apply_match_constraints(mutant_pose, args.enzdes_constraint_file) print('just checking') #turn off constraints if requested - default is on if not args.no_constraints: mutant_pose = coord_constrain_pose(mutant_pose) #Repack or minimize if selected if args.fast_relax: print_out("Running With Fast Relax") new_pose = fast_relax_mutant(mutant_pose, tf, move_map, sf) else: print_out("Running repack and minimize") new_pose = repack_and_minimize_mutant(mutant_pose, tf, move_map, sf) #output the name of the file #Includes original pdb namne, residue number and uaa, nstruct number, #and if the ligand is included or not. base_pdb_filename = args.input_pdb.split('/')[-1].split( '_')[0].replace('.pdb', '') outname = '{}_{}_{}_{}_{}.pdb'.format(base_pdb_filename, \ args.residue_number, uaa, out_ligand_file, str(struct)) if args.residue_number == '0': outname = '{}_{}_min.pdb'.format(base_pdb_filename, \ out_ligand_file) if args.out_suffix: outname = outname.replace(".pdb", args.out_suffix + ".pdb") print_out("Outputting protein file as : " + outname) out_dir = out_directory(args.out_directory) outname = '/'.join([out_dir, outname]) print_out("Writing Outputting protein file as : " + outname) #Symmetry needs to be broken to load the proteins in another #script to analyze them symmetrically. if args.symmdef_file: full_out = outname.replace('.pdb', 'sym.pdb') new_pose.dump_pdb(full_out) not_symm = NotResidueSelector(pre_symm_ris) remove_symmetrized_aa = DeleteRegionMover() remove_symmetrized_aa.set_residue_selector(not_symm) remove_symmetrized_aa.apply(new_pose) new_pose.dump_pdb(outname) else: new_pose.dump_pdb(outname)
def main(args): if args.ligand_type == 'ligand': init_args = ' '.join(['-extra_res_fa', args.ligand_name]) lig_name = args.ligand_name.split('/')[-1].strip('.params') else: init_args = '' pr.init(init_args) sf = pr.get_fa_scorefxn() sf.add_weights_from_file('ref2015') pose = pr.pose_from_pdb(args.input_pdb) sf(pose) print_notice("Scaffold protein Loaded Successfully!") print_notice("Scaffold protein has" + str(pose.total_residue()) + "residues.") if args.symmetric_file: sfsm = SetupForSymmetryMover(args.symmetric_file) sfsm.apply(pose) #Importing list of residues if the ligand is a protein if args.ligand_type == 'protein': ligres = ResidueIndexSelector(args.residue_set) #Targeting the ligand if the ligand isn't protein elif args.ligand_type == 'ligand': ligres = ResidueNameSelector() ligres.set_residue_name3(lig_name) print_notice("Ligand found at resnum: " + \ str(get_residues_from_subset(ligres.apply(pose))) ) #Setting the proteins not in the ligand not_ligand = NotResidueSelector() not_ligand.set_residue_selector(ligres) #Setting the protein considered part of the ligand ligand_distant_contacts = InterGroupInterfaceByVectorSelector() ligand_distant_contacts.group1_selector(ligres) ligand_distant_contacts.group2_selector(not_ligand) ligand_distant_contacts.cb_dist_cut(2.5 * float(args.radius)) ligand_distant_contacts.nearby_atom_cut(float(args.radius)) #Test set: ClosecontactResidueSelector close_contacts = pr.rosetta.core.select.residue_selector.CloseContactResidueSelector( ) close_contacts.central_residue_group_selector(ligres) close_contacts.threshold(float(args.radius)) all_contacts = OrResidueSelector() all_contacts.add_residue_selector(close_contacts) all_contacts.add_residue_selector(ligand_distant_contacts) non_lig_residues = AndResidueSelector() non_lig_residues.add_residue_selector(all_contacts) non_lig_residues.add_residue_selector(not_ligand) #Collecting the residues from the subset neighbor_residues = get_residues_from_subset(non_lig_residues.apply(pose)) pdb_residues = [] for residue in neighbor_residues: print(pose.pdb_info().pose2pdb(residue)) resid = pose.pdb_info().pose2pdb(residue).split() pdb_residues.append(''.join(resid)) print_notice("Ligand found, neighbor residues are: " + ', '.join([x for x in pdb_residues])) print_notice("Ligand found, total neighbor residues is " + str(len(pdb_residues))) #Removing residues in the REMARKS section remove_set = [] f = open(args.input_pdb, 'r') for line in f.readlines(): if 'REMARK' in line: items = [x for x in line.split(' ') if x != ''] residue_set = [int(items[6]), int(items[11])] for resi in residue_set: if resi not in remove_set: remove_set.append(resi) residue_final_set = [] for resi in pdb_residues: idx = int(resi[0:-1]) if idx not in remove_set: residue_final_set.append(resi) #Final list for the designable residues residue_final_set.append('0') print_notice("Neighbor residues cleaned \n \n Residues are: " +\ ', '.join([x for x in residue_final_set])) if args.out_file: out_name = args.out_file else: out_name = args.input_pdb.strip('.pdb') + '_lig.pos' f = open(out_name, "w") for x in residue_final_set: f.write(x + '\n') f.close print("emd182::Wrote ligand position residues of pdb file " + args.input_pdb + " to filename: " + out_name)
parser = argparse.ArgumentParser() parser.add_argument('model', help='Select starting model.') parser.add_argument('job', help='job from SLURM') args = parser.parse_args() #opts = '-use_input_sc -ex1 -ex2 -enzdes::cstfile htra1_pdz.cst -run:preserve_header' opts = '-enzdes::cstfile htra1_pdz.cst -run:preserve_header' init(opts) pdz = ChainSelector('A') peptide = ChainSelector('B') designable = shell_selection(pdz, peptide, 6) packable = shell_selection(pdz, designable, 6) mobile = OrResidueSelector(designable, packable) mobile.add_residue_selector(peptide) static = NotResidueSelector(mobile) sf = get_fa_scorefxn() tf = TaskFactory() tf.push_back(IncludeCurrent()) tf.push_back(ExtraRotamers(0, 1, 1)) tf.push_back(ExtraRotamers(0, 2, 1)) prevent = PreventRepackingRLT() # No repack, no design repack = RestrictToRepackingRLT() # No design tf.push_back(OperateOnResidueSubset(prevent, static)) tf.push_back(OperateOnResidueSubset(repack, packable)) tf.push_back(OperateOnResidueSubset(repack, peptide)) fr = FastRelax()
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