Пример #1
0
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 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
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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 make_task_factory(residue_selectors):
    """ 
    Makes a TaskFactory with operations that leave the mutable residues 
    designable, restricts the nearby residues to repacking, and prevents 
    repacking of other residues.
    """
    mutable_set = residue_selectors['mutable']
    repack_set = residue_selectors['packable']
    immobile_set = residue_selectors['immobile']

    prevent = PreventRepackingRLT()  # No repack, no design
    repack = RestrictToRepackingRLT()  # No design

    tf = TaskFactory()
    tf.push_back(IncludeCurrent())
    tf.push_back(ExtraRotamers(0, 1, 1))
    tf.push_back(ExtraRotamers(0, 2, 1))
    tf.push_back(OperateOnResidueSubset(prevent, immobile_set))
    tf.push_back(OperateOnResidueSubset(repack, repack_set))
    # Everything else left designable by default

    return tf
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 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
Пример #9
0
    '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
Пример #10
0
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()
fr.set_scorefxn(sf)

fd = FastDesign()
fd.set_scorefxn(sf)
fd.set_task_factory(tf)

pose = pose_from_pdb(args.model)
pose.fold_tree(make_fold_tree())
pose = apply_constraints(pose)
pose = thread_to_htra1('QDYEPEA', pose)
def main(args):
    # Destination folder for PDB files
    if args.out_dir:
        dir_name = args.out_dir
        if not isdir(dir_name):
            makedirs(dir_name)
    else:
        dir_name = ""

    # Creating coordinate constraints for the entire molecule
    cg = CoordinateConstraintGenerator()
    ac = AddConstraints()
    ac.add_generator(cg)

    # Create enzdes constraints
    if args.constraints:
        enz_cst = AddOrRemoveMatchCsts()
        enz_cst.set_cst_action(ADD_NEW)
    ''' Declare the score function. '''
    if args.symmetry:  # Declare symmetric score functions
        score_function = SymmetricScoreFunction()
        if args.repulsive_type == 'hard':
            if args.membrane:
                score_function.add_weights_from_file('franklin2019')
            else:
                score_function.add_weights_from_file('ref2015')
        elif args.repulsive_type == 'soft':
            if args.membrane:  # Set up a soft-rep version of franklin2019 manually
                score_function.add_weights_from_file('ref2015_soft')
                score_function.set_weight(ScoreType.fa_water_to_bilayer, 1.0)
            else:
                score_function.add_weights_from_file('ref2015_soft')
    else:  # Declare ordinary score functions
        if args.repulsive_type == 'hard':
            if args.membrane:
                score_function = create_score_function('franklin2019')
            else:
                score_function = create_score_function('ref2015')
        elif args.repulsive_type == 'soft':
            if args.membrane:  # Set up a soft-rep version of franklin2019 manually
                score_function = create_score_function('ref2015_soft')
                score_function.set_weight(ScoreType.fa_water_to_bilayer, 1.0)
            else:
                score_function = create_score_function('ref2015_soft')

    if args.coord_wt:
        score_function.set_weight(ScoreType.coordinate_constraint,
                                  args.coord_wt)

    if args.enzdes_wt:
        score_function.set_weight(ScoreType.atom_pair_constraint,
                                  args.enzdes_wt)
        score_function.set_weight(ScoreType.angle_constraint, args.enzdes_wt)
        score_function.set_weight(ScoreType.dihedral_constraint,
                                  args.enzdes_wt)

    # Loading PDB file
    pose = pose_from_pdb(args.pdb_file)

    if args.symmetry:  # Applying symmetry if specified
        sfsm = SetupForSymmetryMover(args.symmetry)
        sfsm.apply(pose)
        if args.membrane:  # Set up membrane for membrane protein
            add_memb = SymmetricAddMembraneMover(args.span_file)
            add_memb.apply(pose)
    else:
        if args.membrane:  # Set up membrane for membrane protein
            add_memb = AddMembraneMover(args.span_file)
            add_memb.apply(pose)

    # Creating FastRelax protocol with the given score function
    fr = FastRelax()
    fr.set_scorefxn(score_function)

    # Packer tasks
    tf = standard_task_factory()
    tf.push_back(IncludeCurrent())
    tf.push_back(ExtraRotamers(0, 1, 1))
    tf.push_back(ExtraRotamers(0, 2, 1))
    protein_selector = ResiduePropertySelector(ResidueProperty.PROTEIN)
    repack = RestrictToRepackingRLT()
    tf.push_back(OperateOnResidueSubset(repack, protein_selector))
    prevent = PreventRepackingRLT()
    tf.push_back(OperateOnResidueSubset(prevent, protein_selector, True))
    fr.set_task_factory(tf)

    move_map = MoveMap()
    if args.repulsive_type == 'hard':
        move_map.set_bb(True)
    elif args.repulsive_type == 'soft':
        ''' When using the soft-rep score function, backbone should be fixed. '''
        move_map.set_bb(False)
    protein_res_true_vector = protein_selector.apply(pose)
    move_map.set_chi(protein_res_true_vector)
    fr.set_movemap(move_map)

    # Determining file name
    if args.name:
        file_name = args.name
    else:
        file_name = basename(args.pdb_file).replace('.pdb', '_relaxed')

    out_name = join(dir_name, file_name)

    # Applying constraints

    ac.apply(pose)
    if args.constraints:
        enz_cst.apply(pose)

    # RMSD metric
    rmsdm = RMSDMetric()
    rmsdm.set_comparison_pose(pose)

    print(tf.create_task_and_apply_taskoperations(pose))

    # Running relax set
    jd = PyJobDistributor(out_name, args.n_decoys, score_function)
    while not jd.job_complete:
        pp = Pose()
        pp.assign(pose)
        fr.apply(pp)
        rmsdm.apply(pp)
        jd.output_decoy(pp)