Example #1
0
def get_rotamers(self):
    # Gets rotamers for a given residue
    rosrots = bb_independent_rotamers(self.type())
    if self.type().is_d_aa():
        rotamers = [
            pyrosetta.Vector1([-chi for chi in rotamer.chi()])
            for rotamer in rosrots
        ]
    else:
        rotamers = [rotamer.chi() for rotamer in rosrots]
    return rotamers
Example #2
0
 def dock(self):
     """Docks the pose the normal way and without constraints"""
     docked = self.pose.clone()
     docked.remove_constraints()
     pyrosetta.rosetta.protocols.docking.setup_foldtree(
         docked, 'A_B', pyrosetta.Vector1([1]))
     scorefxn = pyrosetta.create_score_function('ligand')
     docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol()
     docking.set_scorefxn(scorefxn)
     docking.apply(docked)
     return docked
Example #3
0
def mutate_residue(pack_or_pose,
                   mutant_position,
                   mutant_aa,
                   pack_radius=0.,
                   pack_scorefxn=None):
    """Replace the residue at a single position in a Pose with a new amino acid
        and repack any residues within user-defined radius of selected residue's
        center using.

    Args:
        pack_or_pose (pyrosetta.rosetta.core.pose.Pose OR pyrosetta.distributed.packed_pose.PackedPose):
                    the `Pose` instance to use.
        mutant_position (int): Pose-numbered position of the residue to mutate.
        mutant_aa (str): The single letter name for the desired amino acid.
        pack_radius (float): Radius used to define neighboring residues.
        pack_scorefxn (pyrosetta.ScoreFunction): `ScoreFunction` to use when repacking the `Pose`.
            Defaults to the standard `ScoreFunction`.
    """
    import pyrosetta
    import pyrosetta.distributed.packed_pose as packed_pose

    wpose = packed_pose.to_pose(pack_or_pose)

    if not wpose.is_fullatom():
        raise IOError("mutate_residue only works with fullatom poses")

    # create a standard scorefxn by default
    if not pack_scorefxn:
        pack_scorefxn = pyrosetta.get_score_function()

    # the numbers 1-20 correspond individually to the 20 proteogenic amino acids
    from pyrosetta.rosetta.core.chemical import aa_from_oneletter_code

    mutant_aa = int(aa_from_oneletter_code(mutant_aa))
    aa_bool = pyrosetta.Vector1([aa == mutant_aa for aa in range(1, 21)])

    # mutation is performed by using a PackerTask with only the mutant
    # amino acid available during design
    task = pyrosetta.standard_packer_task(wpose)
    task.nonconst_residue_task(mutant_position).restrict_absent_canonical_aas(
        aa_bool)

    # prevent residues from packing by setting the per-residue "options" of the PackerTask
    task = restrict_non_nbrs_from_repacking(wpose, mutant_position, task,
                                            pack_radius)

    # apply the mutation and pack nearby residues
    from pyrosetta.rosetta.protocols.minimization_packing import PackRotamersMover

    packer = PackRotamersMover(pack_scorefxn, task)
    packer.apply(wpose)
    def dock(self, pose: pyrosetta.Pose, cst: bool = False) -> None:
        """
        Assumes the chain B is last. Uses ``docking.setup_foldtree`` mysterious method.

        :param pose: replaced structure with ligand
        :return: Changes in place
        """
        dock_jump = 1
        pyrosetta.rosetta.protocols.docking.setup_foldtree(
            pose, 'A_X', pyrosetta.Vector1([dock_jump]))
        scorefxn = pyrosetta.create_score_function('ligand')
        if cst:
            stm = pyrosetta.rosetta.core.scoring.ScoreTypeManager()
            st = stm.score_type_from_name("atom_pair_constraint")
            scorefxn.set_weight(st, 20)
        docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol()
        docking.set_scorefxn(scorefxn)
        docking.apply(pose)
    def dock(self) -> pyrosetta.Pose:
        """
        Docks the pose the normal way and without constraints.

        :return:
        """
        docked = self.pose.clone()
        docked.pdb_info().set_resinfo(res=self.ligand_residue[0],
                                      chain_id='B',
                                      pdb_res=1)
        docked.remove_constraints()
        pyrosetta.rosetta.protocols.docking.setup_foldtree(
            docked, 'A_B', pyrosetta.Vector1([1]))
        scorefxn = pyrosetta.create_score_function('ligand')
        docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol()
        docking.set_scorefxn(scorefxn)
        docking.apply(docked)
        return docked
Example #6
0
import rosetta
from sys import argv

fmt = dict(
    zip('ANDRCQEGHILKMPFSTWYV', [
        'ALA', 'ASN', 'ASP', 'ARG', 'CYS', 'GLN', 'GLU', 'GLY', 'HIS', 'ILE',
        'LEU', 'LYS', 'MET', 'PRO', 'PHE', 'SER', 'THR', 'TRP', 'TYR', 'VAL'
    ]))

with open('input_files/flags') as fn:
    flags = fn.read().replace('\n', ' ')

# init PyRosetta
pyrosetta.init(''.join(flags))

ligand_params = pyrosetta.Vector1(['input_files/pNPG.params'])
new_res_set = pyrosetta.generate_nonstandard_residue_set(ligand_params)

p = pyrosetta.Pose()
pyrosetta.pose_from_file(p, new_res_set, 'input_files/bglb.pdb')
scorefxn = pyrosetta.create_score_function('beta_cst')

add_cst = rosetta.protocols.enzdes.AddOrRemoveMatchCsts()
add_cst.cstfile('input_files/pNPG.enzdes.cst')
add_cst.set_cst_action(rosetta.protocols.enzdes.CstAction.ADD_NEW)
add_cst.apply(p)

target = int(mutant_name[1:-1])
new_res = fmt[mutant_name[-1]]
mut = rosetta.protocols.simple_moves.MutateResidue(target, new_res)
mut.apply(p)
Example #7
0
    def dock_pose(self):
        ## constraints
        def add_weights(scorefxn):
            stm = pyrosetta.rosetta.core.scoring.ScoreTypeManager()
            scorefxn.set_weight(
                stm.score_type_from_name("atom_pair_constraint"), 20)
            scorefxn.set_weight(stm.score_type_from_name("angle_constraint"),
                                20)

        setup = pyrosetta.rosetta.protocols.constraint_movers.ConstraintSetMover(
        )
        setup.constraint_file(self.constraint_filename)
        setup.apply(self.pose)
        scorefxn = pyrosetta.get_fa_scorefxn()
        add_weights(scorefxn)
        ### First relax
        movemap = pyrosetta.MoveMap()
        v = self.get_ligand_selector().apply(self.pose)
        n = self.get_neighbour_selector().apply(self.pose)
        movemap.set_bb(allow_bb=n)
        movemap.set_chi(allow_chi=n)
        relax = pyrosetta.rosetta.protocols.relax.FastRelax(scorefxn, 10)
        relax.set_movemap_disables_packing_of_fixed_chi_positions(True)
        relax.set_movemap(movemap)
        print(f'FastRelax 2: {self.name}')  #this one is non cartesian.
        self.pose.dump_pdb(
            f'{self.work_path}/{self.name}/min2_{self.name}.pdb')
        self.notebook['post-min2'] = self.calculate_score()
        ## repack
        # operation = pyrosetta.rosetta.core.pack.task.operation
        # allow = operation.RestrictToRepackingRLT()
        # restrict_to_focus = operation.OperateOnResidueSubset(allow,self.get_ligand_selector(), True)
        # tf = pyrosetta.rosetta.core.pack.task.TaskFactory()
        # tf.push_back(operation.PreventRepacking())
        # tf.push_back(restrict_to_focus)
        # packer = pyrosetta.rosetta.protocols.minimization_packing.PackRotamersMover(scorefxn)
        # packer.task_factory(tf)
        # packer.apply(self.pose)
        # self.pose.dump_pdb(f'{self.work_path}/{self.name}/repacked_{self.name}.pdb')
        ### Docking
        pyrosetta.rosetta.protocols.docking.setup_foldtree(
            self.pose, 'A_B', pyrosetta.Vector1([1]))
        scorefxn = pyrosetta.create_score_function('ligand')
        add_weights(scorefxn)
        restrict_to_focus = pyrosetta.rosetta.core.pack.task.operation.OperateOnResidueSubset(
            pyrosetta.rosetta.core.pack.task.operation.RestrictToRepackingRLT(
            ), self.get_neighbour_selector(), True)
        tf = pyrosetta.rosetta.core.pack.task.TaskFactory()
        tf.push_back(
            pyrosetta.rosetta.core.pack.task.operation.RestrictToRepacking())
        tf.push_back(restrict_to_focus)
        docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol()
        docking.set_task_factory(tf)
        docking.set_ignore_default_task(True)
        #docking.set_move_map()
        docking.set_scorefxn(scorefxn)
        docking.apply(self.pose)
        print(f'Dock: {self.name}')
        self.notebook['docked'] = self.calculate_score()
        self.pose.dump_pdb(
            f'{self.work_path}/{self.name}/docked_{self.name}.pdb')
Example #8
0
import pyrosetta

pyrosetta.init('-ignore_waters 0 -extra_res_fa NAD.fa.params')
ligand_params = pyrosetta.Vector1(['NAD.fa.params'])
pose = pyrosetta.rosetta.core.pose.Pose()
res_set = pose.conformation().modifiable_residue_type_set_for_conf()
res_set.read_files_for_base_residue_types( ligand_params )
pose.conformation().reset_residue_type_set_for_conf( res_set )
pose = pyrosetta.pose_from_file(filename='pdbfile.pdb')

obj = pyrosetta.rosetta.protocols.rosetta_scripts.XmlObjects.create_from_string("""
<RESIDUE_SELECTORS>
    <ResiduePDBInfoHasLabel name="context" property="CONTEXT" />
    <Index name="ligand2" resnums="1" />
    <Chain name="chA" chains="A"/>
    <ResidueName name="ligand" residue_name3="NAD" />
    <And name="context_ligand" selectors="ligand,context" />
    <Neighborhood name="CN01" selector="ligand" distance="10.0" include_focus_in_subset="0" atom_names_for_distance_measure="N6" />
</RESIDUE_SELECTORS>
""")

obj2 = pyrosetta.rosetta.protocols.rosetta_scripts.XmlObjects.create_from_string(""" 
<ROSETTASCRIPTS>
    <RESIDUE_SELECTORS>
        <ResiduePDBInfoHasLabel name="context" property="CONTEXT"/>
        <Index name="ligand2" resnums="1"/>
        <Chain chains="A" name="chA"/>
        <ResidueName name="ligand" residue_name3="NAD"/>
        <And name="context_ligand" selectors="ligand,context"/>
    <Neighborhood atom_names_for_distance_measure="N6" distance="10.0" include_focus_in_subset="0" name="CN01" selector="ligand"/>
</RESIDUE_SELECTORS>
def sample_ligand_interface(pdb_filename,
                            partners,
                            ligand_params=[""],
                            jobs=1,
                            job_output="ligand_output"):
    """
    Performs ligand-protein docking using Rosetta fullatom docking
    (DockingHighRes) on the ligand-protein complex in  <pdb_filename>
    using the relative chain  <partners>. If the ligand parameters
    (a .params file) are not defaultly loaded into PyRosetta,
    <ligand_params> must supply the list of files including the ligand
    parameters. <jobs>  trajectories are performed with output
    structures named <job_output>_(job#).pdb.
    
    Note: Global docking, a problem solved by the Rosetta DockingProtocol,
    requires interface detection and refinement as with other protocols,
    these tasks are split into centroid (interface detection) and
    high-resolution (interface refinement) methods without a centroid 
    representation, low-resolution ligand-protein prediction is not
    possible and as such, only the high-resolution ligand-protein 
    interface refinement is available. If you add a perturbation or 
    randomization step, the high-resolution stages may fail. A perturbation
    step CAN make this a global docking algorithm however the rigid-body
    sampling preceding refinement requires extensive sampling to produce
    accurate results and this algorithm spends most of its effort in
    refinement (which may be useless for the predicted interface).
    
    This script performs ligand-protein interface structure prediction but does NOT
    perform global ligand-protein docking. Since there is no generic interface
    detection, the input PDB file must have the ligand placed near the interface
    that will be refined. If the DockMCMProtocol is applied to a pose
    without placement near the interface, then the refinement may:
        -waste steps sampling the wrong interface
        -fail by predicting an incorrect interface very far from the true interface
        -fail by separating the ligand from the protein (usually due to a clash)
    DockMCMProtocol does not require an independent randomization or perturbation
    step to "seed" its prediction.
    
    Additional refinement steps may increase the accuracy of the predicted
    conformation (see refinement.py). Drastic moves (large conformational changes)
    should be avoided; if they precede the protocol, the problems above may occur,
    if they succeed the protocol, the protocol results may be lost.
    """

    # Declare working directory and output directory
    working_dir = os.getcwd()
    output_dir = "outputs"
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)

    # Initialize PyRosetta
    pyrosetta.init()

    # Create an empty pose from the desired PDB file
    pose = pyrosetta.rosetta.core.pose.Pose()

    # If the params list has contents, load .params files
    # Note: this method of adding ligands to the ResidueTypeSet is unnecessary
    # if you call pyrosetta.init("-extra_res_fa {}".format(ligand_params))
    if len(ligand_params) != 0 and ligand_params[0] != "":
        ligand_params = pyrosetta.Vector1(ligand_params)
        res_set = pose.conformation().modifiable_residue_type_set_for_conf()
        res_set.read_files_for_base_residue_types(ligand_params)
        pose.conformation().reset_residue_type_set_for_conf(res_set)

    # Load pdb_filename into pose
    pyrosetta.io.pose_from_file(pose, pdb_filename)

    # Setup the docking FoldTree
    # the method setup_foldtree takes an input pose and sets its
    #    FoldTree to have jump 1 represent the relation between the two docking
    #    partners, the jump points are the residues closest to the centers of
    #    geometry for each partner with a cutpoint at the end of the chain,
    # the second argument is a string specifying the relative chain orientation
    #    such as "A_B" of "LH_A", ONLY TWO BODY DOCKING is supported and the
    #    partners MUST have different chain IDs and be in the same pose (the
    #    same PDB), additional chains can be grouped with one of the partners,
    #    the "_" character specifies which bodies are separated
    # the third argument...is currently unsupported but must be set (it is
    #    supposed to specify which jumps are movable, to support multibody
    #    docking...but Rosetta doesn't currently)
    # the FoldTrees setup by this method are for TWO BODY docking ONLY!
    dock_jump = 1  # jump number 1 is the inter-body jump
    pyrosetta.rosetta.protocols.docking.setup_foldtree(
        pose, partners, pyrosetta.Vector1([dock_jump]))

    # Create a copy of the pose for testing
    test_pose = pose.clone()

    # Create ScoreFunctions for centroid and fullatom docking
    scorefxn = pyrosetta.create_score_function("ligand")

    # Setup the high resolution (fullatom) docking protocol using DockMCMProtocol.
    docking = pyrosetta.rosetta.protocols.docking.DockMCMProtocol()
    # Many of its options and settings can be set using the setter methods.
    docking.set_scorefxn(scorefxn)

    # Change directory temporarily for output
    os.chdir(output_dir)

    # Setup the PyJobDistributor
    jd = pyrosetta.toolbox.py_jobdistributor.PyJobDistributor(job_output,
                                                              jobs,
                                                              scorefxn,
                                                              compress=False)

    # Set the native pose so that the output scorefile contains the pose rmsd metric
    jd.native_pose = pose

    # Optional: setup a PyMOLObserver
    # pyrosetta.rosetta.protocols.moves.AddPyMOLObserver(test_pose, True)

    # Perform protein-ligand docking
    # counter = 0 # for pretty output to PyMOLObserver

    while not jd.job_complete:
        test_pose = pose.clone()  # Reset test pose to original structure

        # counter += 1 # Change the pose name, for pretty output to PyMOLObserver
        # test_pose.pdb_info().name(job_output + '_' + str(counter))

        docking.apply(test_pose)  # Perform docking and output to PyMOL

        # Write the decoy structure to disc
        jd.output_decoy(test_pose)

    os.chdir(working_dir)