def check_loop_rmsd(self, query_pose, subject_pose): """ If the subject and query loops are the same size, take CA RMSD """ if self.query_loop_size == self.subject_loop_size: self.subject_loop_matches_query_length = True # Get pose-numbered residues for loop termini qn = self.N_splice_res.query_pose_number sn = self.N_splice_res.subject_pose_number qc = self.C_splice_res.query_pose_number sc = self.C_splice_res.subject_pose_number # Make residue selectors for loops stemp = '{}-{}' query_selector = ResidueIndexSelector(stemp.format(qn, qc)) subject_selector = ResidueIndexSelector(stemp.format(sn, sc)) # Calculate RMSD self.rmsd = align_protein_sections(query_pose, query_selector, subject_pose, subject_selector) else: self.subject_loop_matches_query_length = False return
def measure_affinity(pose, target_residue, interacting_residues, score_function="auto"): """ """ assert type(target_residue) == int, \ "'target_residue' should be an int with the residue ID" if score_function == "auto": score_function = get_fa_scorefxn() if type(interacting_residues) == int: interacting_residues = [interacting_residues] hbonds_number, hbonds_energy = measure_hbonds_number( pose, target_residue, interacting_residues) target = ResidueIndexSelector(str(target_residue)) interface = ResidueIndexSelector(ID2Rank(pose, interacting_residues)) try: interaction_energy_metric = InteractionEnergyMetric(target, interface) except: from pyrosetta.rosetta.core.simple_metrics.metrics import \ InteractionEnergyMetric interaction_energy_metric = InteractionEnergyMetric(target, interface) results = {} results["total_energy"] = score_function(pose) results["hbonds_number"] = hbonds_number results["hbonds_energy"] = hbonds_energy results["inter_energy"] = interaction_energy_metric.calculate(pose) return results
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 create_design_task_factory(designable_res_indexes: list, active_site_positions: list = 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 designable_selector = ResidueIndexSelector(','.join( str(designable_res_index) for designable_res_index in designable_res_indexes)) if not cystine: restriction = RestrictAbsentCanonicalAASRLT() restriction.aas_to_keep('AGILPVFWYDERHKSTMNQ') # AGILPVFWYDERHKSTCMNQ task_factory.push_back( OperateOnResidueSubset(restriction, designable_selector)) # Repack repack = RestrictToRepackingRLT() prevent = PreventRepackingRLT() if neighborhood > 0: if len(active_site_positions) > 0: enzdes_cst_selector = ResidueIndexSelector(','.join( str(enzdes_cst_index) for enzdes_cst_index in active_site_positions)) designable_repacking_selector = NeighborhoodResidueSelector() designable_repacking_selector.set_focus_selector( OrResidueSelector(designable_selector, enzdes_cst_selector)) designable_repacking_selector.set_distance(neighborhood) designable_repacking_selector.set_include_focus_in_subset(True) repacking_selector = AndResidueSelector( designable_repacking_selector, NotResidueSelector(designable_selector)) task_factory.push_back( OperateOnResidueSubset(repack, repacking_selector)) task_factory.push_back( OperateOnResidueSubset(prevent, designable_repacking_selector, True)) else: repacking_selector = NeighborhoodResidueSelector() repacking_selector.set_focus_selector(designable_selector) repacking_selector.set_distance(neighborhood) repacking_selector.set_include_focus_in_subset(False) task_factory.push_back( OperateOnResidueSubset(repack, repacking_selector)) 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 process(pr, p, args, out): selector = ResidueIndexSelector() for residue in args.residues: selector.append_index(residue) hits = pr.search(p, args.bidentates + args.networks, selector) prev = -1 buffer = [] limit = args.n_cutoff if args.reduced_output else 0 for (hash, pose) in hits: if (hash != prev): for n, (_, minimized) in enumerate(filter_clash_minimize(p, buffer, clash_cutoff=args.clash_cutoff, limit=limit)): print("Match found! Pair hash: %d, match number: %d" % (prev, n)) minimized.dump_pdb(path.join(out, "result_pair%d_num%d.pdb" % (prev, n))) prev = hash buffer = [] else: buffer.append((hash, pose)) if (buffer): for n, (_, minimized) in enumerate(filter_clash_minimize(p, buffer, clash_cutoff=args.clash_cutoff, limit=limit)): print("Match found! Pair hash: %d, match number: %d" % (prev, n)) minimized.dump_pdb(path.join(out, "result_pair%d_num%d.pdb" % (prev, n))) buffer = []
def get_mobile_range(chain_no, central_res=None, range_from_tug=None): """ Returns a selection of residues in given chain. The list can either include the full chain, or a subset within a given range from a given central residue. Still includes stom hard-coding for tau in the case of the subset. """ # Full chain if not all([central_res, range_from_tug]): chain_letter = chr(64 + chain_no) # 'A' is chr 65, 'B' is 66, etc. chain_selection = ChainSelector(chain_letter) return chain_selection # Subset of chain elif all([central_res, range_from_tug]): # Ignoring upstream residues of central res is near N-term if central_res >= 306 + range_from_tug: run_start = range_from_tug else: run_start = central_res - 306 # Ignoring downstream residues if central res is near C-term if central_res <= 378 - range_from_tug: run_end = range_from_tug else: run_end = 378 - central_res run_str = '-'.join([str(site - run_start), str(site + run_end)]) chain_run_selection = ResidueIndexSelector(run_str) return chain_run_selection # Shouldn't happen, but just in case... else: print("Bug detected: received one input, not zero or two.") exit()
def select_residues(design_peptide=False): """ Makes residue selectors for HCV protease sections """ residue_selectors = {} catalytic = ResidueIndexSelector('72,96,154') residue_selectors['catalytic'] = catalytic protease = ChainSelector("A") residue_selectors['protease'] = protease peptide = ChainSelector("B") residue_selectors['peptide'] = peptide mutable = mutable_residues_selector(design_peptide) residue_selectors['mutable'] = mutable packable = packable_residues_selector(mutable) residue_selectors['packable'] = packable other = other_residues_selector(mutable, packable) residue_selectors['other'] = other mm_pack = movemap_packable_residues_selector(peptide, mutable, packable) residue_selectors['movemap_pack'] = mm_pack return residue_selectors
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 apply_hbond_constraints(pose, first_strand, second_strand): """ Adds H-bond constraints to a pose, given lists of residues in two beta strands. Lists should be given as strings of residues, such as '215,217' and '185,187' for Htra1 with the extended peptide, or '199-203' and '170-174' for HCV. """ # Create selectors for residues in each set hb_res_1 = ResidueIndexSelector(first_strand) hb_res_2 = ResidueIndexSelector(second_strand) # Set up constraints generation hbcg = HydrogenBondConstraintGenerator() hbcg.set_residue_selector1(hb_res_1) hbcg.set_residue_selector2(hb_res_2) # Apply, return pose hbcg.apply(pose) return pose
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_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 index_interface(pose, substrate_indices, d=10): """This function takes a pose and a number of interface/substrate to consider and returns interface indices. The value k and pose are not used...""" # Selection for neighbor residues focus_res = ','.join([str(j) for j in substrate_indices]) focus_selector = ResidueIndexSelector(focus_res) interface = NeighborhoodResidueSelector() interface.set_focus_selector(focus_selector) interface.set_distance(d) interface.set_include_focus_in_subset(False) interface_indices = selector_to_list(pose, interface) interface_indices.sort() return interface_indices
def load_selections_from_json_file(filename, pose): """ Reads a selections.JSON file and transforms the selection into actual ResidueSelectors, if the residues exist. Otherwise, save that selection as None. """ with open(filename, "r") as file_in: selections = json.load(file_in) for selection in selections: sel = ResidueIndexSelector(selections[selection]) try: sel.apply(pose) selections[selection] = sel except RuntimeError: selections[selection] = None return selections
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 uncap(pose): """ Remove all termini conformations of a pose, switching the atoms to normal in-chain conformations. """ from pyrosetta.rosetta.core.select.residue_selector import \ ResidueIndexSelector # Identify all termini in the given pose cap_indexes = "" for residue in pose.residues: if residue.is_terminus(): cap_indexes += "%d," % (residue.seqpos()) caps = ResidueIndexSelector(cap_indexes[:-1]) # Remove termini conformations for the selection in the given pose uncap_selection(pose, caps)
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 calculate_sequence(self): """ Determine full sequence, and compare to WT if available """ # Get full sequence sm = SequenceMetric() self.full_sequence = sm.calculate(self.design) # If WT is available, compare #if self.wt: # Check that lengths are the same assert self.design.total_residue() == self.wt.total_residue() for i in range(1, self.design.total_residue() + 1): ris = ResidueIndexSelector(str(i)) sm.set_residue_selector(ris) final_aa = sm.calculate(self.design) orig_aa = sm.calculate(self.wt) pdb_number = int(self.wt.pdb_info().pose2pdb(i).split()[0]) if final_aa != orig_aa: self.mutated_residues[pdb_number] = [orig_aa, final_aa]
def get_pose_discrimination_scores(pdb): fix_file(pdb) nam = basename(pdb) pose = pose_from_pdb(pdb) # Enzdes constraints cstm = AddOrRemoveMatchCsts() cstm.set_cst_action(ADD_NEW) cstm.apply(pose) sf = create_score_function('ref2015_cst') sf(pose) #pep_res = selector_to_list(pose, ChainSelector('B')) pep_res = selector_to_list(pose, ResidueIndexSelector('212-218')) neigh = NeighborhoodResidueSelector() neigh.set_distance(8) neigh.set_focus_selector(ChainSelector('B')) neigh.set_include_focus_in_subset(False) prot_res = selector_to_list(pose, neigh) pep_score = 0 for i in pep_res: pep_score += pose.energies().residue_total_energies(i)[st.total_score] prot_score = 0 for i in prot_res: prot_score += pose.energies().residue_total_energies(i)[st.total_score] cst_score = 0 for i in [st.atom_pair_constraint, st.coordinate_constraint, st.angle_constraint, st.dihedral_constraint]: cst_score += pose.energies().total_energies()[i] discriminator = 1 * prot_score + 1 * pep_score + 3.5 * cst_score print(nam, prot_score, pep_score, cst_score, discriminator) return [nam, prot_score, pep_score, cst_score, discriminator]
def apply_constraints(pose): """ Applies enzdes constraints from the input CST file to a pose Also applies coordinate constraints to the original substrate peptide which is assumed correct from the PDB """ # Enzdes constraints cstm = AddOrRemoveMatchCsts() cstm.set_cst_action(ADD_NEW) cstm.apply(pose) # Coordinate constraints cg = CoordinateConstraintGenerator() cs = ResidueIndexSelector('213-216') cg.set_residue_selector(cs) ac = AddConstraints() ac.add_generator(cg) ac.apply(pose) return
def apply_constraints(pose): """ Applies enzdes constraints form the input CST file to a pose Also applies coordinate constraints to the substrate peptide, assumed to be chain B """ # Enzdes constraints cstm = AddOrRemoveMatchCsts() cstm.set_cst_action(ADD_NEW) cstm.apply(pose) # Coordinate constraints cg = CoordinateConstraintGenerator() ors = OrResidueSelector() ors.add_residue_selector(ChainSelector('A')) # Constrain main backbone ors.add_residue_selector( ResidueIndexSelector('113-115')) # Preserving original peptide cg.set_residue_selector(ors) ac = AddConstraints() ac.add_generator(cg) ac.apply(pose) return
def residue_selection(selection_one, selection_two): #For now, just an or selector to group up the residues. first = ResidueIndexSelector(selection_one) second = ResidueIndexSelector(selection_one) both = OrResidueSelector(first, second) return both
def calc_residue_interaction(pose, sf, res, int_target): ris = ResidueIndexSelector(str(res)) inte = InteractionEnergyMetric() inte.set_scorefunction(sf) inte.set_residue_selectors(ris, int_target) return inte.calculate(pose)
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 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
def get_cat_res(in_pose): """ For an input pose (presently assumed to be a serine protease), several steps are performed to determine the catalytic triad residues. Firstly, the pose is stripped down to the largest chain, which should be the main. This is to eliminate substrate chains that might falsly appear to be part of the triad. Secondly, selections of ser, his, and acid (asp and glu) residues are collected. Thirdly, a crude screen is conducted to weed out obviously false residues. The set of histidines is collected and scanned through individually. For each histidine, the set of neighboring residues within 10 A is checked for overlap with the sets of serines and acids, and if either set intersection is empty, which means that there is no nearby serine and/or acid, then that histidine cannot be part of the triad and is eliminated. Remaining histidines are collected with the lists of their potential ser and acid counterparts. Fourthly, the geometry of potential triads are examined. The atom distances are checked between the ND's of the histidine and the respective CB of serine and OD of the acid residue. The ND-CB distance should be 3.3 +/- 0.5 A, and the ND-OD distance should be 2.6 +/- 0.5 A. """ # 1. Isolate the protease main chain (no substrate) pose = isolate_main_chain(in_pose) # 2. Get selectors of serines, histidines, and acidic residues (aspartic and glutamic) target_res = ['SER', 'HIS', 'ASP,GLU'] name_selectors = {} for tr in target_res: # Need to set name3 in selectors to get terminal residues, HIS_D, etc. rns = ResidueNameSelector() rns.set_residue_name3(tr) name_selectors[tr] = rns # 3. Scan through list of histidines to weed out any that don't have nearby # serine and acid residues within 10 A potential_his = selector_to_list(pose, name_selectors['HIS']) potential_triads = {} for h in potential_his: # Make selector for all residues with CA within 10 A, excluding self nrs = NeighborhoodResidueSelector(ResidueIndexSelector(str(h)), 10) nrs.set_include_focus_in_subset(False) # Select intersection of neighbors and serines no_match, potential_ser = \ check_selector_nonzero_intersections([nrs, name_selectors['SER']], pose) if no_match: # If there are no nearby serines, this can't be catalytic hist continue # Select intersection of neighbors and acid residues no_match, potential_ac = \ check_selector_nonzero_intersections([nrs, name_selectors['ASP,GLU']], pose) if no_match: # If there are no nearby acid residues, this can't be catalytic hist continue # Histidine has both requisite neighbors. Collect that residue and the # lists of neighbors. potential_triads[h] = [potential_ser, potential_ac] # 4. Examine rotamer geometry of potential triads for h, [sers, acids] in potential_triads.items(): for s in sers: for a in acids: pass
add_csts.apply(pose) # constraint if args.constraints: add_fa_constraints_from_cmdline(pose, sfxn) # enzyme design constraint if args.enzyme_design_constraints: enzdes_cst = create_enzdes_cst() enzdes_cst.apply(pose) # declare movers movers = list() if not args.rmsd: rmsdm = RMSDMetric(pose) else: rmsdm = RMSDMetric( pose, ResidueIndexSelector(','.join(str(res) for res in args.rmsd))) movers.append(rmsdm) if args.fast_relax: tf = create_relax_task_factory(point_mutations = args.mutations, active_site_positions = active_site_positions, \ neighborhood = args.neighborhood) elif args.designable_sites or args.substrates or args.enzyme_design_constraints: if args.favor_native_residue: favor_nataa = FavorNativeResidue(pose, args.favor_native_residue) if args.designable_sites: tf = create_design_task_factory(args.designable_sites, active_site_positions = active_site_positions, \ neighborhood = args.neighborhood, cystine = args.cystine, noncanonical_amino_acids = args.noncanonical_amino_acids) else: tf = create_enzyme_design_task_factory(active_site_positions, neighborhood = args.neighborhood, \ cystine = args.cystine, noncanonical_amino_acids = args.noncanonical_amino_acids) else: tf = create_relax_task_factory(point_mutations=args.mutations,
prem.set_scorefunction(sf) tem = TotalEnergyMetric() tem.set_scorefunction(sf) results = [] for p in pdbs: pp = pose_from_pdb(p) results.append([p, tem.calculate(pp), prem.calculate(pp)]) s = prem.calculate(pose) with open('res_results.txt', 'w') as w: for r in results: res_scores = [] for i in range(1, 116): res_scores.append(r[2][i]) ol = [r[0], r[1]] + res_scores w.write(','.join([str(x) for x in ol]) + '\n') csb = ChainSelector('B') with open('res_interactions.csv', 'w') as w: for p in pdbs: pp = pose_from_pdb(p) tot_e = tem.calculate(pp) this_res = [p, tot_e] for i in range(1, 115): ris = ResidueIndexSelector(str(i)) inte = InteractionEnergyMetric() inte.set_scorefunction(sf) inte.set_residue_selectors(ris, csb) this_res.append(inte.calculate(pp)) w.write(','.join([str(x) for x in this_res]) + '\n')
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)