In [15]:
import os
import numpy as np
import rosetta as r
import random
r.init()
r.__version__
Out[15]:
'56891:56891:6efc58f8abb54611ace5a6cdd7e69e6c970a01ef'
In [16]:
pmm = r.PyMOLMover(target_host="epr-krim")
In [19]:
#Makin a mutation after the helix is created also works
#Create sequence 
seq = 'R'*5 + 'K'+'R'*5; print seq
pose = r.pose_from_sequence(seq, res_type="fa_standard") 
scorefxn = r.get_fa_scorefxn()

#Create perfect alpha helix
#phi = -57.8, Psi -47.0
for i in range(1, pose.total_residue()+1):
    pose.set_phi(i, -57.9)
    pose.set_psi(i, -47.9)

#Make mutation    
mut = r.MutateResidue(6 , 'R1A')
mut.apply(pose)    
    
#pack side chains
packer_task = r.standard_packer_task(pose)
packer_task.restrict_to_repacking() 
print packer_task
pack_mover = r.PackRotamersMover(scorefxn, packer_task) 
pack_mover.apply(pose) 

#show the resuls
print scorefxn(pose)
pmm.apply(pose)
RRRRRKRRRRR
#Packer_Task

resid	pack?	design?	allowed_aas
1	TRUE	FALSE	ARG:NtermProteinFull
2	TRUE	FALSE	ARG
3	TRUE	FALSE	ARG
4	TRUE	FALSE	ARG
5	TRUE	FALSE	ARG
6	TRUE	FALSE	R1A
7	TRUE	FALSE	ARG
8	TRUE	FALSE	ARG
9	TRUE	FALSE	ARG
10	TRUE	FALSE	ARG
11	TRUE	FALSE	ARG:CtermProteinFull

0.0280818165478
In [23]:
##geting rotamers
import rosetta.core.pack.rotamer_set as rotamer_set
rsf = rotamer_set.RotamerSetFactory()
res_pos = 6
rs = rsf.create_rotamer_set(pose.residue(res_pos))
rs.set_resid(res_pos)


packer_graph = r.core.pack.create_packer_graph( pose, scorefxn, packer_task)

rs.build_rotamers(pose, scorefxn, packer_task, packer_graph)

print (rs.rotamer(1).name(), rs.num_rotamers())
for i in range(1, rs.num_rotamers()+1):
    print rs.rotamer(i).chi()
    
('R1A', 38)
[169.695, -77.1423, -89.9724, 179.985, -77.0601, ]
[169.723, -77.0919, -90.018, 179.989, 76.9536, ]
[169.686, -77.1266, -89.9705, -75.0039, -8.06538, ]
[169.673, -77.0842, -89.9935, -74.9985, 99.9558, ]
[172.668, 72.5688, -89.9724, 179.985, -77.0601, ]
[172.701, 72.5934, 90.0176, 179.985, -77.0601, ]
[172.69, 72.6102, -90.0058, 179.975, 76.4572, ]
[172.705, 72.5627, 90.0355, 179.975, 76.4572, ]
[172.677, 72.6363, 90.0047, 74.9619, 7.95654, ]
[172.706, 72.5977, 90.0204, 74.9934, -100.071, ]
[-179.992, 179.966, -89.9724, 179.985, -77.0601, ]
[179.998, 179.989, 90.0176, 179.985, -77.0601, ]
[-179.953, -179.978, -90.018, 179.989, 76.9536, ]
[-179.969, 179.977, 90.0279, 179.989, 76.9536, ]
[-180, 179.937, -89.9705, -75.0039, -8.06538, ]
[-179.963, 179.982, 90.0047, 74.9619, 7.95654, ]
[-179.979, -179.989, -89.9983, 74.9934, -100.071, ]
[179.982, 179.965, 90.0204, 74.9934, -100.071, ]
[-179.998, -179.983, -89.9935, -74.9985, 99.9558, ]
[-72.9716, 172.981, 90.0176, 179.985, -77.0601, ]
[-73.0073, 172.95, 90.0279, 179.989, 76.9536, ]
[-72.9747, 172.999, 89.966, -75.0039, -8.06538, ]
[-72.9599, 172.973, 90.0047, 74.9619, 7.95654, ]
[-73.0438, 172.959, 90.0204, 74.9934, -100.071, ]
[-72.9832, 172.996, 90.0101, -74.9985, 99.9558, ]
[-76.4554, -55.5492, -89.9724, 179.985, -77.0601, ]
[-76.4304, -55.5066, 90.0176, 179.985, -77.0601, ]
[-76.4162, -55.5131, -90.018, 179.989, 76.9536, ]
[-76.4048, -55.5745, 90.0279, 179.989, 76.9536, ]
[-76.4134, -55.5731, -89.9705, -75.0039, -8.06538, ]
[-76.407, -55.5611, -89.9711, 74.9619, 7.95654, ]
[-76.4122, -55.4899, 90.0047, 74.9619, 7.95654, ]
[-76.4314, -55.5125, -89.9983, 74.9934, -100.071, ]
[-76.3822, -55.579, 90.0204, 74.9934, -100.071, ]
[-76.4358, -55.5228, -89.9935, -74.9985, 99.9558, ]
[-163.831, -73.4177, 109.79, 79.6052, -98.2454, ]
[-160.639, -77.2348, 109.954, 161.459, 92.3954, ]
[-164.175, -73.2275, 112.451, 81.6127, 1.32506, ]
In [24]:
import random
def range1(n):
    return range(1,n+1)

def random_id(n):
    """Returns a random integer form 1 to n inclusive"""
    return random.randint(1,n)

def Vector1_to_list(vec1):
   return [i for i in vec1]
#vec1 = r.Vector1([1., 2., 3.])
#Vector1_to_list(vec1)


def display_rotamers(pose, rotamers,  pymol_mover):
    """Displays al the rotamers (allready built) at a given rotamers.resid()
    using the given pymol_mover
    """
    #there must be a better way to create a one amino acid pose, but I can't find it
    #Problem is with R1A or Z residue. pose_from_sequence does not seem to work
    #doing r.pose_from_sequence('Z') reports that residue can not be found 
    short_pose = r.pose_from_sequence('G', auto_termini=False)
    mut = r.MutateResidue(1 , rotamers.rotamer(1).name3())
    mut.apply(short_pose)    
    short_pose.copy_segment(1, pose, 1, rotamers.resid())
    old_keep_history = pymol_mover.keep_history()
    
    #add the rotamers as pymol states. remember the old keep_history setting
    pymol_mover.keep_history(True)
    short_pose.pdb_info().name(rotamers.rotamer(1).name1()+str( rotamers.resid()))
    
    for i in range1(rotamers.num_rotamers()):
        #print rotamers.rotamer(i).chi()
        short_pose.residue(1).set_all_chi(rotamers.rotamer(i).chi())
        
        #short_pose.pdb_info().name(rotamers.rotamer(i).name1()+str(i))
        pymol_mover.apply(short_pose)

    pymol_mover.keep_history(old_keep_history)
        
display_rotamers(pose,  rs, pmm)    

Result