Ejemplo n.º 1
0
class TestMinMover():
    pose = get_pose('PYTEST')
    mmap = MoveMap()
    mmap.set_bb(True)
    sfxn = get_score_function()

    min_mv = MinMover(movemap=mmap, sfxn=sfxn)

    def test_attributes(self):
        assert self.min_mv.score_function() == self.min_mv.sfxn
        assert self.min_mv.movemap(self.pose).get_bb(1)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def main():
    pyrosetta.init('-beta')

    # making xforms
    for iter in range(10):
        x = rosetta.numeric.random.gaussian_random_xform(10.0, 0.5)
        print("should be 10-ish", x.rotation_angle_degrees())
        print('should be 0.5-ish', x.t.length())

    # customizing a score function
    sf = pyrosetta.get_score_function()
    # do print(sf) and look for weights to see what you can modify
    sf.set_weight(core.scoring.fa_dun, 0.0)

    # use xform to move pose around
    chem_manager = rosetta.core.chemical.ChemicalManager
    rts = chem_manager.get_instance().residue_type_set("fa_standard")

    gly = core.pose.Pose()
    asn = core.pose.Pose()
    core.pose.make_pose_from_sequence(gly, 'G', rts)
    core.pose.make_pose_from_sequence(asn, 'N', rts)
    gn = gly
    # anchor to 1st residue, rot round CG of res 2
    gn.append_pose_by_jump(asn, 1, 'CA', 'CG')
    j = gn.jump(1)  # only one jump in this system
    j.set_translation(j.get_translation() +
                      numeric.xyzVector_double_t(5, 0, 0))
    gn.set_jump(1, j)  # move apart a bit

    for i in range(10):
        j = gn.jump(1)
        # this is better than below, probably
        print(j.gaussian_move(1, 0.0, 5.0))
        # x = rosetta.numeric.random.gaussian_random_xform(5.0, 0.25)
        # j.set_rotation(j.get_rotation()x.R)
        # j.set_translation(j.get_translation() + x.t)
        gn.set_jump(1, j)
        gn.dump_pdb('test_%i.pdb' % i)
Ejemplo n.º 4
0
        if roll >= P:
            p.assign(last_pose)  # reject pose and reassign previous
            continue

    # if new pose is accepted, store lowest score and associated pose
    if new_score < low_score:
        low_score = new_score
        low_pose.assign(p)

# output files
p.dump_pdb("poly-A_final.pdb")
low_pose.dump_pdb("poly-A_low.pdb")

# Low-Resolution (Centroid) Scoring
ras = pose_from_file("../test/data/workshops/6Q21.clean.pdb")
score2 = get_score_function()
print(score2(ras))
print(ras.residue(5))

switch = SwitchResidueTypeSetMover("centroid")
switch.apply(ras)
print(ras.residue(5))

score3 = create_score_function("score3")
print(score3(ras))

switch2 = SwitchResidueTypeSetMover("fa_standard")
switch2.apply(ras)
print(ras.residue(5))

# Protein Fragments
Ejemplo n.º 5
0
def main(argv):
    parser = argparse.ArgumentParser(description='Program')
    parser.add_argument('-i', '--in_file', action='store', type=str,
                        help='input PDB scaffold file')
    parser.add_argument('-d', '--loop_dir', action='store', type=str,
                        required=True, nargs='+',
                        help='directories containing loops to graft. Provide'
                        ' directories with C-terminal-most loops first.')
    parser.add_argument('-o', '--out_dir', action='store', type=str,
                        help='directory to write output')
    args = parser.parse_args()
    list_of_loop_files = [[path.join(ld, l) for l in
                          listdir(ld)] for ld in args.loop_dir]
#    print(list_of_loop_files[0])

    if not path.exists(args.out_dir):
        makedirs(args.out_dir)

    # user-specified scorefxn
    pyrosetta.init()  # extra_options='-beta_nov15')

    # figure out the pdb-numbered residue ranges for the loops from the
    # directory name. This is hacky, but whateva
    def _get_loop_ranges(dir_name, split_char='_'):
        components = dir_name.split(split_char)
        res_range = list()
        for c in components:
            try:
                res_range.append(int(c))
            except ValueError:
                pass
        return res_range

    loop = list()
    start_pose = pyrosetta.pose_from_file(args.in_file)
    to_centroid = pyrosetta.rosetta.protocols.simple_moves.SwitchResidueTypeSetMover('centroid')
    to_centroid.apply(start_pose)

    for directory in args.loop_dir:
        loop_range = _get_loop_ranges(directory)
        loop.append((start_pose.pdb_info().pdb2pose('A', loop_range[0]),
                     start_pose.pdb_info().pdb2pose('A', loop_range[1])))
        assert(loop[-1][0] < loop[-1][1] and loop[-1][0] > 0)

    # temporary -- I'd rather have some recursive type of thing that doesn't
    # need to know how many loops we're talking about here
    assert(len(list_of_loop_files) ==  len(loop) )
    print(len(list_of_loop_files))
    sf = pyrosetta.get_score_function(False)  # centroid score function
    score_manager = pyrosetta.rosetta.core.scoring.ScoreTypeManager()
    score_term = score_manager.score_type_from_name("atom_pair_constraint")
    sf.set_weight(score_term, 1.0)
    print(sf)
    # to avoid bookkeeping crap, we're going to smash in the downstream loop
    # first.
    if len(list_of_loop_files) == 1:
        print("One loop!")
        for i, loop_fname in enumerate(list_of_loop_files[0]):
            p = insert_loop_into_scaffold(start_pose, loop_fname, loop[0], to_centroid)
            if sf(p) < 0.:
                scaffold_base, _ = path.splitext(path.basename(args.in_file))
                l1_basename, _ = path.splitext(path.basename(loop_fname))
                fname = path.join(args.out_dir,
                                  '{}_{}.pdb'.format(scaffold_base, l1_basename))
                p.dump_pdb(fname)

    elif len(list_of_loop_files) == 2:
        for i, loop_fname in enumerate(list_of_loop_files[0]):
            p = insert_loop_into_scaffold(start_pose, loop_fname, loop[0],
                                      to_centroid)
            for i, loop2_fname in enumerate(list_of_loop_files[1]):
                p = insert_loop_into_scaffold(p, loop2_fname, loop[1], to_centroid)
                if sf(p) < 0.:
                    scaffold_base, _ = path.splitext(path.basename(args.in_file))
                    l1_basename, _ = path.splitext(path.basename(loop_fname))
                    l2_basename, _ = path.splitext(path.basename(loop2_fname))
                    fname = path.join(args.out_dir,
                                  '{}_{}_{}.pdb'.format(scaffold_base,
                                                        l1_basename,
                                                        l2_basename))
                    p.dump_pdb(fname)
    # Write the results to an outfile
    if not os.path.isdir(os.path.dirname(results_file)):
        os.makedirs(os.path.dirname(results_file))
    print("Writing the results to the file: {0}".format(results_file))
    scores_all_pdbs.to_csv(results_file)


#---------------------------------------------------------------
# Initialize relevant Movers and Filters in PyRosetta
#---------------------------------------------------------------
# Initialize a specific score function
pyrosetta.init(
    extra_options=
    '-beta_nov16 -holes:dalphaball /home/sheffler/bin/DAlphaBall.gcc')
scorefxn = pyrosetta.get_score_function()


# Tweak the score function so that it includes energies from
# backbone hydrogen bonds when computing per-residue energies
def fix_scorefxn(sfxn, allow_double_bb=False):
    opts = sfxn.energy_method_options()
    opts.hbond_options().decompose_bb_hb_into_pair_energies(True)
    opts.hbond_options().bb_donor_acceptor_check(not allow_double_bb)
    sfxn.set_energy_method_options(opts)


fix_scorefxn(scorefxn)

# Import the content of the input XML files, and store them in a dictionary
# of the form {metric name : script contents}
Ejemplo n.º 7
0
add_single_cutpoint_variant(pose, loop1)
ccd = protocols.loops.loop_closure.ccd.CCDLoopClosureMover(loop1, movemap)

ccd.apply(pose)
set_single_loop_fold_tree(pose, loop1)

# Multiple Loops
loop2 = protocols.loops.Loop(78, 83, 80)

loops = protocols.loops.Loops()
loops.add_loop(loop1)
loops.add_loop(loop2)

# Loop Building
reference_pose = pose_from_file("../test/data/test_in.pdb")
score = get_score_function()

import tempfile

output = tempfile.mkstemp()[1]

jd = PyJobDistributor(output, 1, score)

lrms = loop_rmsd(pose, reference_pose, loops, True)
jd.additional_decoy_info = " LRMSD: " + str(lrms)

# High-Resolution Loop Protocol
loop_refine = LoopMover_Refine_CCD(loops)
# loop_refine.apply(pose)  # takes too long

# KIC
def main(argv):
    parser = argparse.ArgumentParser(description='Program')
    parser.add_argument('-i',
                        '--in_file',
                        action='store',
                        type=str,
                        help='input PDB scaffold file')
    parser.add_argument('-d',
                        '--loop_dir',
                        action='store',
                        type=str,
                        required=True,
                        nargs='+',
                        help='directories containing loops to graft. Provide'
                        ' directories with C-terminal-most loops first.')
    parser.add_argument('-o',
                        '--out_dir',
                        action='store',
                        type=str,
                        help='directory to write output')
    #added by gabi
    parser.add_argument('-a1',
                        '--anchor_res_pair1',
                        nargs='+',
                        type=int,
                        help='first pair of anchor residues')
    parser.add_argument('-a2',
                        '--anchor_res_pair2',
                        nargs='+',
                        type=int,
                        help='second pair of anchor residues',
                        default=0)
    args = parser.parse_args()

    #    print(list_of_loop_files[0])

    #added by gabi
    anchor_list = [args.anchor_res_pair1, args.anchor_res_pair2]
    if not path.exists(args.out_dir):
        makedirs(args.out_dir)

    # user-specified scorefxn
    pyrosetta.init()  # extra_options='-beta_nov15')

    # figure out the pdb-numbered residue ranges for the loops from the
    # directory name. This is hacky, but whateva
    def _get_loop_ranges(dir_name, split_char='_'):
        components = dir_name.split(split_char)
        res_range = list()
        for c in components:
            try:
                res_range.append(int(c))
            except ValueError:
                pass
        return res_range

    def _get_loop_size(dir_name):
        dir_path = path.join(dir_name)
        loop_file = next(
            path.join(dir_path, f) for f in listdir(dir_path)
            if path.isfile(path.join(dir_path, f)))
        loop_pose = pyrosetta.pose_from_file(loop_file)
        loop_size = loop_pose.total_residue()
        return loop_size

    loop = list()
    start_pose = pyrosetta.pose_from_file(args.in_file)
    #added by gabi
    loops_length = list()
    for directory in args.loop_dir:
        loop_res = _get_loop_size(directory)
        loops_length.append(loop_res)
    edited_pose = renum_pose_and_loop(args, anchor_list, loops_length)

    #pose_anchor_res = get_anchor_for_renum(args,len(list_of_loop_files))
    #moved down here by gabi
    list_of_loop_files = [[path.join(ld, l) for l in listdir(ld)]
                          for ld in args.loop_dir]
    to_centroid = pyrosetta.rosetta.protocols.simple_moves.SwitchResidueTypeSetMover(
        'centroid')
    to_centroid.apply(edited_pose)

    for size in loops_length:

        loop_range = _get_loop_ranges(directory)
        loop.append((edited_pose.pdb_info().pdb2pose('A', loop_range[0]),
                     edited_pose.pdb_info().pdb2pose('A', loop_range[1])))

        assert (loop[-1][0] < loop[-1][1] and loop[-1][0] > 0)

    # temporary -- I'd rather have some recursive type of thing that doesn't
    # need to know how many loops we're talking about here
    assert (len(list_of_loop_files) == len(loop))
    print(len(list_of_loop_files))
    sf = pyrosetta.get_score_function(False)  # centroid score function
    score_manager = pyrosetta.rosetta.core.scoring.ScoreTypeManager()
    score_term = score_manager.score_type_from_name("atom_pair_constraint")
    sf.set_weight(score_term, 1.0)

    #added by gabi
    score_term = score_manager.score_type_from_name("vdw")
    sf.set_weight(score_term, 1.0)
    score_term = score_manager.score_type_from_name("hbond_sr_bb")
    sf.set_weight(score_term, 1.0)
    score_term = score_manager.score_type_from_name("hbond_lr_bb")
    sf.set_weight(score_term, 0.5)
    score_term = score_manager.score_type_from_name("dihedral_constraint")
    sf.set_weight(score_term, 10.0)
    score_term = score_manager.score_type_from_name("rama")
    sf.set_weight(score_term, 0.1)
    score_term = score_manager.score_type_from_name("omega")
    sf.set_weight(score_term, 1.0)
    score_term = score_manager.score_type_from_name("rg")
    sf.set_weight(score_term, 1.0)
    score_term = score_manager.score_type_from_name("linear_chainbreak")
    sf.set_weight(score_term, 2.778)
    score_term = score_manager.score_type_from_name("cart_bonded")
    sf.set_weight(score_term, 0.5)

    print(sf)
    # to avoid bookkeeping crap, we're going to smash in the downstream loop
    # first.
    if len(list_of_loop_files) == 1:
        print("One loop!")
        for i, loop_fname in enumerate(list_of_loop_files[0]):
            p = insert_loop_into_scaffold(edited_pose, loop_fname, loop[0],
                                          to_centroid)

            #try to filter based on the cartbonded score, misses one or two usually
            if sf.score_by_scoretype(p, score_term, True) < 180.:
                scaffold_base, _ = path.splitext(path.basename(args.in_file))
                l1_basename, _ = path.splitext(path.basename(loop_fname))
                fname = path.join(
                    args.out_dir, '{}_{}.pdb'.format(scaffold_base,
                                                     l1_basename))
                p.dump_pdb(fname)

    elif len(list_of_loop_files) == 2:
        for i, loop_fname in enumerate(list_of_loop_files[0]):
            p = insert_loop_into_scaffold(edited_pose, loop_fname, loop[0],
                                          to_centroid)
            for i, loop2_fname in enumerate(list_of_loop_files[1]):
                p2 = insert_loop_into_scaffold(p, loop2_fname, loop[1],
                                               to_centroid)

                #may need to work on the best filter score
                if sf.score_by_scoretype(p, score_term, True) < 180.:
                    scaffold_base, _ = path.splitext(
                        path.basename(args.in_file))
                    l1_basename, _ = path.splitext(path.basename(loop_fname))
                    l2_basename, _ = path.splitext(path.basename(loop2_fname))
                    fname = path.join(
                        args.out_dir,
                        '{}_{}_{}.pdb'.format(scaffold_base, l1_basename,
                                              l2_basename))
                    p2.dump_pdb(fname)
Ejemplo n.º 9
0
def main(argv):
    parser = ArgumentParser()
    parser.add_argument('-s',type=str) # Allow for input file to be specified at initialization
    args=parser.parse_args()
    input_pdb=args.s
    pdbfile=str(input_pdb) #duplicated string?
    pdb = os.path.split(str( pdbfile ))[-1]
    pdbname=str((pdb).split('.',)[0])
    print (str(pdbname))

    #initialize pyrosetta. output virtual atoms as they are the hack to centre the ligand params files specific to situation
    pyrosetta.init('-extra_res_fa DRD.params DRE.params -out:file:output_virtual true')

    
    pose = pyrosetta.pose_from_file(input_pdb)
    sf = pyrosetta.get_score_function()
    
    surface_selector = pyrosetta.rosetta.core.select.residue_selector.LayerSelector()
    surface_selector.set_layers(False, False, True)
    surface_residue_indexes = pyrosetta.rosetta.core.select.get_residues_from_subset(surface_selector.apply(pose))
    print(surface_residue_indexes)

    #For both modified amino acids
        #For each surface residue
            #For each rotamer
                
    for h in 'DRD', 'DRE':
        ncaa = h

        print "Residue ", h

        # Iterating all residue position indexes
        for i in surface_residue_indexes:
            pose_clone = pose.clone()
            
            # Mutate to target residue
            pyrosetta.rosetta.protocols.simple_moves.MutateResidue(i, ncaa).apply(pose_clone)
            # Set native rotamers - needed?
            # if ncaa == 'DRD':
            # 	pose_clone.set_chi(1, i, 170.459) # Update for Asp
            # 	pose_clone.set_chi(2, i, -89.397)
            # elif ncaa == 'DRE':
            # 	pose_clone.set_chi(1, i, 170.459) # Update for Glu
            # 	pose_clone.set_chi(2, i, -89.397)
            # 	pose_clone.set_chi(3, i, 180.000)
            
            trm = pyrosetta.rosetta.protocols.protein_interface_design.movers.TryRotamers(resnum=i, scorefxn=sf, explosion=0, jump_num=0, clash_check=True, solo_res=False, include_current=True)
            trm.setup_rotamer_set(pose_clone)
            rotamer_set = trm.rotamer_set()
        	
            #print trm
            #print rotamer_set
            #print(rotamer_set.num_rotamers())
            
            #For every rotamer that doesn't clash
            for j in pyrosetta.rrange(int(rotamer_set.num_rotamers())):
                pose_clone2 = pose_clone.clone()
                pose_clone2.replace_residue(i, rotamer_set.rotamer(j), True)
                
                angle_error, distance_error1, distance_error2 = check_alignment(pose_clone2, i) # ,dihedral1,angle1,chi2
                if (angle_error < 4 or angle_error > 176) and distance_error1 < 0.5 and distance_error2 < 0.5: #and abs(dihedral1)>30 and abs(dihedral1)<120 and angle1>90 and angle1<125 and abs(chi2)>45:
                    #print "Hit found!"
                    hitlist = open("output/hitlist.txt", "a")
                    print >>hitlist, str(pdbname) + " residue " + str(i) + " rotamer " + str(j) + " of " + str(h)
                    hitlist.close()

                    #print "pdb " + str(pdbname) + " residue " + str(i) + " rotamer " + str(j) + " supports residue " + str(h) + " in the appropriate position"

                    pose_clone3 = pose_clone2.clone()
                    sfsm_c4 = pyrosetta.rosetta.protocols.simple_moves.symmetry.SetupForSymmetryMover('./C4_Z.sym')
                    sfsm_c4.apply(pose_clone3)
               
               # export a pdb file of the symmetric molecule
                    pose_clone3.dump_pdb('output/' + str(pdbname) + '_' + str(h) + '_' + str(i) + '_' + str(j) + '.pdb')
Ejemplo n.º 10
0
movemap.set_bb(True)
movemap.set_bb(10, False)
print('outputting movemap')
movemap.show(pose.total_residue())

fragset3mer = core.fragment.ConstantLengthFragSet(
    3, "../test/data/test3_fragments")  # "aatestA03_05.200_v1_3")
fragset9mer = core.fragment.ConstantLengthFragSet(
    9, "../test/data/test9_fragments")  # "aatestA09_05.200_v1_3")
print('mover: ClassicFragmentMover, 3mer')
movemap.set_bb(True)
mover_3mer = protocols.simple_moves.ClassicFragmentMover(fragset3mer, movemap)
mover_3mer.apply(pose_frag)

print('Creating standard score function with patch and scoring')
scorefxn = get_score_function()
scorefxn(pose)

print('mover: SmallMover')
movemap.set_bb(True)
smallmover = protocols.simple_moves.SmallMover(movemap, kT, n_moves)
smallmover = protocols.simple_moves.SmallMover()
smallmover.angle_max('L', 50)
smallmover.apply(pose_frag)
print(smallmover)
# TODO: fix printout.  show mover params (temp, nmoves, anglemax) and last output status

# TODO: mover base class printout with name, last output status, brief description(?)

print('mover: ShearMover')
shearmover = protocols.simple_moves.ShearMover(movemap, kT, n_moves)