def fast_relax_mutant(pose, task_factory, move_map, score_function, decoys=1):
    """
    Runs Fast Relax on the mutant pose instead of just repack an minimize.
    Can modify to take varying amounts of decoys.
    """
    fast_relax = FastRelax(1)
    fast_relax.set_scorefxn(score_function)
    fast_relax.set_task_factory(task_factory)
    fast_relax.set_movemap(move_map)
    score_function(pose)
    packer = task_factory.create_task_and_apply_taskoperations(pose)
    print_out("packer task")
    print_out(packer)
    #sys.exit()
    traj_idx = 0
    lowest_energy = 1000.0
    print_out("emd182::Running Fast Relax")
    while traj_idx < decoys:
        print_out("Round Number: " + str(traj_idx))
        pose_copy = pr.Pose()
        pose_copy.assign(pose)
        print_out("emd182:: pose total residues: " + str(pose.total_residue()))
        fast_relax.apply(pose_copy)
        decoy_energy = total_energy(pose_copy, score_function)
        if traj_idx == '0':
            mutated_pose = pose_copy
            lowest_energy = decoy_energy
        elif decoy_energy < lowest_energy:
            mutated_pose = pose_copy
            lowest_energy = decoy_energy
        traj_idx += 1

    return mutated_pose
def fastrelax(pose, score_function, movemap):
	""" 
	Runs the FastRelax protocol on a pose, using given score function and 
	movemap
	"""
	relax = FastRelax()
	relax.set_scorefxn(score_function)
	relax.set_movemap(movemap)

	relax.apply(pose)
	return pose
Beispiel #3
0
def main(args):
    # Destination folder for PDB files
    od = out_directory(args.out_dir)

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

    out_name = join(od, file_name)

    # Loading pose and applying constraints, symmetry,
    pose = load_pose(args.pdb_file,
                     enzdes_cst=args.constraints,
                     coord_cst=True,
                     symmetry=args.symmetry,
                     membrane=None)

    # Setting up the scorefunction with the desired constraint weights
    sf = get_sf(rep_type='hard',
                symmetry=args.symmetry,
                membrane=0,
                constrain=args.constraint_weight)

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

    # Packer tasks
    tf = standard_task_factory()
    tf.push_back(RestrictToRepacking())
    tf.push_back(IncludeCurrent())
    tf.push_back(ExtraRotamers(0, 1, 1))
    tf.push_back(ExtraRotamers(0, 2, 1))
    fr.set_task_factory(tf)

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

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

    print("Starting relax {}".format(pdb_name))
    pose = fastrelax(pose, sf, mm, taskfactory=tf)
def fastrelax(pose, score_function, movemap, taskfactory=None):
    """ 
    Runs the FastRelax protocol on a pose, using given score function and 
    movemap, and optionally a task factory. By default, FastRelax will not do 
    design. However, given a task factory that enables design, it functions 
    like FastDesign.
    """
    relax = FastRelax()
    relax.set_scorefxn(score_function)
    relax.set_movemap(movemap)
    if taskfactory:
        relax.set_task_factory(taskfactory)

    pp = Pose(pose)
    relax.apply(pp)

    return pp
Beispiel #5
0
class Relax(Mover):
    '''Relax your pose'''
    def __init__(self):
        self.edited_movemap = False
        super().__init__()

    @property
    def mover(self):
        if hasattr(self, '_mvr'):
            return self._mvr
        else:
            return FastRelax(self.sfxn, self.rounds)

    @mover.setter
    def mover(self, mover):
        self._mvr = mover

    @property
    def rounds(self):
        if hasattr(self, '_relax_rounds'):
            return self._relax_rounds
        else:
            return 5

    @rounds.setter
    def rounds(self, relax_rounds):
        self._relax_rounds = relax_rounds

    def update_mover(self):
        self.mover = FastRelax(self.sfxn, self.rounds)
        # Only update movemap if edited (includes calling
        # self.setup_default_movemap())
        if self.edited_movemap:
            self.mover.set_movemap(self.movemap)
        init(' '.join(self.init_args))

    def apply(self):
        self.update_mover()
        self.mover.apply(self.pose)
Beispiel #6
0
def relax(pdb, native, scorefxn=scorefxn_fa):
    """
	Performs energy minimization using Rosetta FastRelax protocol, superimpose onto native structure, and calculate RMSD
	--------
	Params
		- pdb (str): path to input structure in PDB format
		- native (str): path to native structure in PDB format
		- scorefxn (ScoreFunction): energy function to use in scoring. Either centroid ('score3') or full-atom ('fa_standard'), default full-atom
	Returns
		- Protein object representing relaxed structure
		- RMSD between input and native (float)
		- Score after minimization (float)
	"""
    pose = pose_from_pdb(pdb)
    score = score_pose(pose, scorefxn)
    print('initial score', score)

    to_fullatom = SwitchResidueTypeSetMover('fa_standard')
    to_fullatom.apply(pose)

    relax = FastRelax()  #ClassicRelax()
    relax.set_scorefxn(scorefxn)

    relax.apply(pose)
    score = score_pose(pose, scorefxn)
    print('final score', score)
    pose.dump_pdb("%s_fast_relax.pdb" % (pdb[:-4]))

    native_pose = pose_from_pdb(native)
    relax.apply(native_pose)
    native_pose.dump_pdb("%s_fast_relax.pdb" % (native[:-4]))

    rmsd = superimpose_rmsd("%s_fast_relax.pdb" % (pdb[:-4]),
                            "%s.pdb" % (native[:-4]))
    print('RMSD to native', rmsd)

    return Protein(pose=pose), rmsd, score
Beispiel #7
0
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)

	# Creating symmetry setup
	if args.symmetry:
		sfsm = SetupForSymmetryMover(args.symmetry)

	# Setting up the scorefunction with the desired constraint weights
	if args.symmetry:
		sf = SymmetricScoreFunction()
		sf.add_weights_from_file(args.score_function)
	else:
		sf = create_score_function(args.score_function)

	if args.coord_wt:
		sf.set_weight(st.coordinate_constraint, args.coord_wt)

	if args.enzdes_wt:
		sf.set_weight(st.atom_pair_constraint, args.enzdes_wt)
		sf.set_weight(st.angle_constraint, args.enzdes_wt)
		sf.set_weight(st.dihedral_constraint, args.enzdes_wt)

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

	# Packer tasks
	tf = standard_task_factory()
	tf.push_back(RestrictToRepacking())
	tf.push_back(IncludeCurrent())
	tf.push_back(ExtraRotamers(0, 1, 1))
	tf.push_back(ExtraRotamers(0, 2, 1))
	fr.set_task_factory(tf)

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

	out_name = join(dir_name, file_name)

	# Loading PDB file, applying constraints
	pose = pose_from_pdb(args.pdb_file)
	ac.apply(pose)
	if args.constraints:
		enz_cst.apply(pose)
	if args.symmetry:
		sfsm.apply(pose)

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

	# Running relax set
	jd = PyJobDistributor(out_name, args.n_decoys, sf)
	while not jd.job_complete:
		pp = Pose()
		pp.assign(pose)
		fr.apply(pp)
		rmsdm.apply(pp)
		jd.output_decoy(pp)
Beispiel #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)
Beispiel #9
0
#!/usr/bin/python
from glob import glob
from os.path import basename, join
from pyrosetta import *
from pyrosetta.rosetta.protocols.relax import FastRelax

init()

sf = create_score_function('ref2015_cst')

fr = FastRelax()
fr.set_scorefxn(sf)
fr.constrain_coords(True)
fr.constrain_relax_to_start_coords(True)
fr.coord_constrain_sidechains(True)

structs = glob('pdz_nmr/*.pdb')
structs.sort()

for s in structs:
    pose = pose_from_pdb(s)

    jdname = join('pdz_relax/', basename(s).rstrip('.pdb'))

    jd = PyJobDistributor(jdname, 20, sf)
    while not jd.job_complete:
        pp = Pose()
        pp.assign(pose)
        fr.apply(pp)
        jd.output_decoy(pp)
Beispiel #10
0
    # when adding the ExtraRotamers, new 'designable' rotamers are included
    # and considered during the sampling. Therefore, the TaskFactory must
    # re-restrict the rotamers to repackaging.
    task_factory.push_back(RestrictToRepacking())
    # Altough the PyRosetta manual states that the current rotamer is included
    # by default, this does not seem to be true and therefore needs to be
    # activated.
    task_factory.push_back(IncludeCurrent())

    # Define the FastRelax object with the correct score function and extra
    # rotamers enabled
    fast_relax = FastRelax()
    fast_relax.set_scorefxn(score_function)
    fast_relax.set_task_factory(task_factory)

    fast_relax.apply(pose)
    pose.dump_pdb(args.output + ".pdb")

#             A U X I L I A R Y   F U N C T I O N S
# ______________________________________________________________________________
#
# Minimalistic version of the above script.
# Aimed to be called from other scripts.


def relax(pose,
          no_constraints=DEFAULT.no_constraints,
          c_weight=DEFAULT.c_weight):
    """
    TO DO
    """
Beispiel #11
0
#!/usr/bin/python
from pyrosetta import *
from pyrosetta.rosetta.core.scoring.symmetry import SymmetricScoreFunction
from pyrosetta.rosetta.protocols.relax import FastRelax
from pyrosetta.rosetta.protocols.symmetry import SetupForSymmetryMover

init('-relax:thorough')

sf = SymmetricScoreFunction()
sf.add_weights_from_file('ref2015_cst')

fr = FastRelax(sf, "NO CST RAMPING")
fr.set_scorefxn(sf)
fr.constrain_coords(True)
fr.constrain_relax_to_start_coords(True)
fr.ramp_down_constraints(False)
fr.coord_constrain_sidechains(True)

sfsm = SetupForSymmetryMover('tau_fibril.sym')

pose = pose_from_pdb('5o3l_INPUT.pdb')
sfsm.apply(pose)

jd = PyJobDistributor('sym_tau_relax/tau_relax', 50, sf)
while not jd.job_complete:
    p = Pose()
    p.assign(pose)
    fr.apply(p)
    jd.output_decoy(p)
Beispiel #12
0
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)

jnam = 'pdz_designs/{}_designed_{}.pdb'.format(args.model, args.job)
fr.apply(pose)
fd.apply(pose)
pose.dump_pdb(jnam)
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)