Exemplo n.º 1
0
def setup_fastrelax(sf):
	"""
	Creates FastRelax mover with appropriate score function, movemap, and 
	packer rules. List of neighbor residues was generated using a 10A 
	neighborhood residue selector around the peptide chain.
	"""
	relax = FastRelax()
	relax.set_scorefxn(sf)

	# MoveMap
	mm = MoveMap()
	mm.set_bb_true_range(212,216)
	neighbors = [28, 29, 41, 42, 43, 44, 45, 46, 59, 60, 61, 62, 91, 125, 126, 
		127, 128, 129, 145, 147, 148, 149, 150, 151, 157, 164, 165, 166, 167, 
		168, 169, 170, 171, 183, 184, 185, 186, 187, 188, 189, 192, 193, 194, 212, 
		213, 214, 215, 216, 217, 218, 219, 220] # Did 10A selection separately
	for n in neighbors:
		mm.set_chi(n, True)
	relax.set_movemap(mm)

	# 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))
	relax.set_task_factory(tf)

	return relax
Exemplo n.º 2
0
def setup_fastrelax(sf, pose):
    """
	Creates FastRelax mover with appropriate score function, movemap, and 
	packer rules. All sidechains are mobile, only substrate backbone is mobile.
	"""
    relax = FastRelax()
    relax.set_scorefxn(sf)

    # MoveMap
    mm = MoveMap()
    mm.set_chi(True)
    for i in range(1, pose.total_residue() + 1):
        if pose.residue(i).chain() == 2:
            mm.set_bb(i, True)
    relax.set_movemap(mm)

    # 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))
    relax.set_task_factory(tf)

    return relax
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def setup_fastrelax(sf):
    """
	Creates FastRelax mover with appropriate score function, movemap, and 
	packer rules. List of neighbor residues was generated using a 8A 
	PyMOL selection expansion around the peptide chain.
	"""
    relax = FastRelax()
    relax.set_scorefxn(sf)

    # MoveMap
    mm = MoveMap()
    mm.set_bb_true_range(106, 112)
    neighbors = [
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 22, 37,
        38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 53, 59, 62, 69, 70, 71, 72,
        73, 74, 75, 76, 77, 78, 79, 83, 85, 98, 100, 101, 103, 104, 105, 106,
        107, 108, 109, 110, 111, 112
    ]  # Did 8A selection separately
    for n in neighbors:
        mm.set_chi(n, True)
    relax.set_movemap(mm)

    # 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))
    relax.set_task_factory(tf)

    return relax
Exemplo n.º 5
0
def fast_relax_mover(score_function,
                     task_factory=None,
                     movemap=None,
                     repeats=5):
    """
    Creates a FastRelax mover with a given score function. If a task factory 
    and/or movemap are provided, they will also be incorporated into the mover.
    By default, FastRelax goes through five ramping cycles, but this number can 
    be adjusted with the repeats option.
    """
    from pyrosetta.rosetta.protocols.relax import FastRelax

    # Make FastRelax mover with given score function
    fr = FastRelax(repeats)
    fr.set_scorefxn(score_function)

    # Set task factory
    if task_factory:
        fr.set_task_factory(task_factory)

    # Set move map
    if movemap:
        fr.set_movemap(movemap)

    return fr
def create_fast_relax_mover(score_function, task_factory, move_map=None):
    # Make FastRelax mover
    fast_relax = FastRelax()
    fast_relax.set_scorefxn(score_function)
    fast_relax.set_task_factory(task_factory)
    if move_map:
        fast_relax.set_movemap(move_map)
    return fast_relax
Exemplo n.º 7
0
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
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
Exemplo n.º 9
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)
Exemplo n.º 10
0
  def __init__(self, net, pose, fix=None, glycinate=False, max_iter=100,
               n_moves=1, scorefxn=None, kT=0.1, k=15, dropout=0.5, relax=True):
    super(NetPackMover, self).__init__(net, pose, k=k, dropout=dropout)
    self.relax = relax
    self.n_moves = n_moves
    self.max_iter = max_iter
    self.kT = kT
    self.scorefxn = scorefxn
    self.fix = fix if fix is not None else []
    self.step = 0

    self.fastrelax = ...
    if relax or glycinate:
      fastrelax = FastRelax()
      fastrelax.set_scorefxn(self.scorefxn)
      mm = MoveMap()
      mm.set_bb(False)
      mm.set_chi(True)
      #for fixed in self.fix:
      #  mm.set_chi(fixed, False)
      fastrelax.set_movemap(mm)
      self.fastrelax = fastrelax

    if glycinate:
      self.dropout = 1.0
      mask = torch.tensor([
        1 - int(self.fixed_position(idx))
        for idx in range(len(pose.sequence()))
      ], dtype=torch.bool)
      for idx, residue in enumerate(pose.residues):
        residue_name = self.sample_residue(pose, idx, mask=mask, argmax=True)
        if not self.fixed_position(idx):
          mutate_residue(pose, idx + 1, residue_name, pack_radius=10.0, pack_scorefxn=scorefxn)
        mask[idx] = 0
      self.dropout = dropout
      self.fastrelax.apply(pose)
    self.monte_carlo = MonteCarlo(pose, scorefxn, kT)
    self.glycinate = glycinate
Exemplo n.º 11
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)
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)