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 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
Example #3
0
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 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
Example #5
0
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
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
Example #7
0
    pose = pose_from_pdb(args.input_file)
    score_function = get_fa_scorefxn()

    # 1. Total Energy
    # This needs to be the first step, as the score needs to be scored, for
    # example, for the InteractionEnergyMetric calculation.
    total_energy = score_function(pose)

    # 3. Interaction Energy Metric
    # This should only be calculated if a chain C is present on the pose.
    ligand_residues, interface_residues = [], []
    interaction_energy = None
    ligand = ChainSelector(args.chain)
    interface = NeighborhoodResidueSelector(ligand,
                                            args.cutoff,
                                            include_focus_in_subset=False)
    if len(get_residues_from_selector(ligand, pose)) > 0:
        interaction_energy_metric = InteractionEnergyMetric(ligand, interface)
        interaction_energy = interaction_energy_metric.calculate(pose)

        # 2. Individual Residues Energy per Selection
        ligand_residues = get_residue_energies_from_selector(ligand, pose)
        interface_residues = get_residue_energies_from_selector(
            interface, pose)

    # 4. Hydrogen Bonding Network Energy
    hydrogen_bonding_energy = 0.0
    score_terms = [hbond_sr_bb, hbond_lr_bb, hbond_bb_sc, hbond_sc]
    for score_term in score_terms:
        hydrogen_bonding_energy += pose.energies().total_energies()[score_term]
Example #8
0
def main(args):
    init()
    sf = create_score_function('ref2015_cst')
    sf.set_weight(ScoreType(1).atom_pair_constraint,
                  2)  # Increasing repulsion weight
    sf.set_weight(ScoreType(1).dihedral_constraint,
                  0.5)  # Reducing dihedral weight
    def_score = get_fa_scorefxn()

    if not isdir(args.outdir):
        makedirs(args.outdir)

    # Reading in PDB, determining middle chain
    pose = pose_from_pdb(args.start_struct)
    chain_count = pose.num_chains()
    chain_no = chain_count / 2

    # Determining which sites to tug
    if args.test_single:
        tug_sites = [args.test_single]
    else:
        chain_residues = selector_to_list(pose, get_mobile_range(chain_no))
        tug_sites = chain_residues[1::args.frame]  # First res will error
        # Error because dihedrals are calculated using the upstream residue

    # Making decoy set for each sliding frame on the tau middle monomer
    for site in tug_sites:
        in_res = int(pose.pdb_info().pose2pdb(site).split()[0])
        site_name = join(args.outdir, 'tau_fibril_distort_' + str(in_res))

        # Determining backbone-mobile section of pose
        if args.mobile_range:
            mobile_selection = get_mobile_range(chain_no, \
             central_res=in_res, range_from_tug=args.mobile_range)
        else:
            mobile_selection = get_mobile_range(chain_no)

        # Selecting repackable shell within 18A of the target (includes target)
        ris = ResidueIndexSelector(str(site))
        nrs = NeighborhoodResidueSelector(ris, 18)

        # Combining selections
        combined_selection = OrResidueSelector()
        combined_selection.add_residue_selector(mobile_selection)
        combined_selection.add_residue_selector(nrs)

        # Making move map and task factory for FastRelax
        mm = make_move_map(pose, mobile_selection, combined_selection)
        tf = make_task_factory(combined_selection)

        # Making FastRelax
        fr = FastRelax()
        fr.set_scorefxn(sf)
        fr.set_movemap(mm)
        fr.set_task_factory(tf)

        # Making constraints
        csts = make_constraints(pose, chain_no, site, args.tug_distance)

        # Making ten decoys
        jd = PyJobDistributor(site_name, args.num_decoys, sf)
        while not jd.job_complete:
            p = Pose()
            p.assign(pose)

            # Add constraints
            for c in csts:
                p.add_constraint(c)

            fr.apply(p)

            print("\n" * 5, jd.current_name)
            print(sf.show(p), "\n" * 5)

            jd.output_decoy(p)
Example #9
0
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],
                ]
            )
Example #10
0
}
start_pdb = {
    'Y382W': 'pdz_relaxed_1.pdb_designed_62.pdb',
    'R386V': 'pdz_relaxed_2.pdb_designed_13.pdb',
    'R386V-M388R-K394V': 'pdz_relaxed_2.pdb_designed_13.pdb',
    'I415K': 'pdz_relaxed_2.pdb_designed_13.pdb',
    'I415K-E416Y': 'pdz_relaxed_2.pdb_designed_13.pdb',
    'R386V-M388R-K394V-T415K-E416Y': 'pdz_relaxed_2.pdb_designed_13.pdb',
    'Y382W-R386V-M388R-K394V-T415K-E416Y': 'pdz_relaxed_2.pdb_designed_13.pdb',
    'S389D-S444R-N446Q': 'pdz_relaxed_3.pdb_designed_47.pdb',
    '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))