Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
mutants.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # :noTabs=true:
3 
4 
5 # (c) Copyright Rosetta Commons Member Institutions.
6 # (c) This file is part of the Rosetta software suite and is made available under license.
7 # (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 # (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 # (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 ## @file mutants.py
12 ## @brief
13 ## @author Evan H. Baugh, Johns Hopkins University
14 
15 # mutate_residue is adapted from an original script by Sid Chaudhury
16 
17 # UNFINISHED...below!
18 
19 import random
20 from rosetta import Pose
21 from rosetta import make_pose_from_sequence
22 from rosetta import create_score_function
23 from rosetta import TaskFactory
24 from rosetta.utility import vector1_bool
25 from rosetta import aa_from_oneletter_code
26 from rosetta import PackRotamersMover
27 from rosetta.core.pose import PDBInfo
28 
29 # a different version of mutate_residue is provided in PyRosetta v2.0 and
30 # earlier that does not optionally repack nearby residues
31 
32 # replaces the residue at <resid> in <pose> with <new_res> with repacking
33 def mutate_residue( pose , mutant_position , mutant_aa ,
34  pack_radius = 0.0 , pack_scorefxn = '' ):
35  """
36  Replaces the residue at <mutant_position> in <pose> with <mutant_aa>
37  and repack any residues within <pack_radius> Angstroms of the mutating
38  residue's center (nbr_atom) using <pack_scorefxn>
39  note: <mutant_aa> is the single letter name for the desired ResidueType
40 
41  example:
42  mutate_residue(pose,30,A)
43  See also:
44  Pose
45  PackRotamersMover
46  MutateResidue
47  pose_from_sequence
48  """
49  #### a MutateResidue Mover exists similar to this except it does not pack
50  #### the area around the mutant residue (no pack_radius feature)
51  #mutator = MutateResidue( mutant_position , mutant_aa )
52  #mutator.apply( test_pose )
53 
54  if pose.is_fullatom() == False:
55  IOError( 'mutate_residue only works with fullatom poses' )
56 
57  test_pose = Pose()
58  test_pose.assign( pose )
59 
60  # create a standard scorefxn by default
61  if not pack_scorefxn:
62  pack_scorefxn = create_score_function( 'standard' )
63 
64  task = standard_packer_task( test_pose )
65 
66  # the Vector1 of booleans (a specific object) is needed for specifying the
67  # mutation, this demonstrates another more direct method of setting
68  # PackerTask options for design
69  aa_bool = rosetta.utility.vector1_bool()
70  # PyRosetta uses several ways of tracking amino acids (ResidueTypes)
71  # the numbers 1-20 correspond individually to the 20 proteogenic amino acids
72  # aa_from_oneletter returns the integer representation of an amino acid
73  # from its one letter code
74  # convert mutant_aa to its integer representation
75  mutant_aa = aa_from_oneletter_code( mutant_aa )
76 
77  # mutation is performed by using a PackerTask with only the mutant
78  # amino acid available during design
79  # to do this, construct a Vector1 of booleans indicating which amino acid
80  # (by its numerical designation, see above) to allow
81  for i in range( 1 , 21 ):
82  # in Python, logical expression are evaluated with priority, thus the
83  # line below appends to aa_bool the truth (True or False) of the
84  # statement i == mutant_aa
85  aa_bool.append( i == mutant_aa )
86 
87  # modify the mutating residue's assignment in the PackerTask using the
88  # Vector1 of booleans across the proteogenic amino acids
89  task.nonconst_residue_task( mutant_position
90  ).restrict_absent_canonical_aas( aa_bool )
91 
92  # prevent residues from packing by setting the per-residue "options" of
93  # the PackerTask
94  center = pose.residue( mutant_position ).nbr_atom_xyz()
95  for i in range( 1 , pose.total_residue() + 1 ):
96  # only pack the mutating residue and any within the pack_radius
97  if not i == mutant_position or center.distance_squared(
98  test_pose.residue( i ).nbr_atom_xyz() ) > pack_radius**2:
99  task.nonconst_residue_task( i ).prevent_repacking()
100 
101  # apply the mutation and pack nearby residues
102  packer = PackRotamersMover( pack_scorefxn , task )
103  packer.apply( test_pose )
104 
105  return test_pose
106 
107 # returns a pose made from seq, all phi/psi/omega set to 180
108 def pose_from_sequence( seq , res_type = 'fa_standard' , name = '' , chain_id = 'A' ):
109  """
110  Returns a pose generated from amino acid single letters in <seq> using
111  the <res_type> ResidueType, the new pose's PDBInfo is named <name>
112  and all residues have chain ID <chain_id>
113 
114  example:
115  pose=pose_from_sequence('LIGAND')
116  See also:
117  Pose
118  make_pose_from_sequence
119  pose_from_pdb
120  pose_from_rcsb
121  """
122  pose=Pose()
123  make_pose_from_sequence(pose,seq,res_type)
124  #pdb_info = rosetta.core.pose.PDBInfo(pose.total_residue()) # actual, for other code
125  pdb_info = PDBInfo(pose.total_residue()) # create a PDBInfo object
126  for i in range(0,pose.total_residue()):
127  if pose.residue(i+1).is_protein():
128  # set to a more reasonable default
129  pose.set_phi(i+1,-150)
130  pose.set_psi(i+1,150)
131  pose.set_omega(i+1,180)
132  # set PDBInfo info for chain and number
133  #pdb_info.chain(i+1,chain_id)
134  #pdb_info.number(i+1,i+1)
135  #### you can alternatively use the deprecated method set_extended_torsions
136  #### which requires a Pose and a Loop object...so make a large loop
137  #set_extended_torsions( pose , Loop ( 1 , pose.total_residue() ) )
138  # set the PDBInfo
139  pose.pdb_info(pdb_info)
140  # default name to first 3 letters
141  if not name:
142  name = seq[:4]
143  pose.pdb_info().name(name)
144 # print pose
145  return pose
146 
147 # for use with random_sequence
148 protein_letters = 'ACDEFGHIKLMNPQRSTVWY'
149 nucleic_letters = ['A[ADE]','G[GUA]','C[CYT]','T[THY]']
150 
151 # returns a sequence of random protein letters
152 def random_sequence( length = 1 , letters = protein_letters ):
153  return ''.join( [letters[random.randint(0,len(letters)-1)] for i in range( length ) ] )
154 
155 # the following method may not be useulf to many...but whatever
156 
157 # display sequence differences
158 def compare_mutants__( pose1 , pose2 ):
159  seq1 = pose1.sequence()
160  seq2 = pose2.sequence()
161  for i in range(pose1.total_residue()):
162  if not seq1[i]==seq2[i]:
163  print 'mutation '+seq1[i]+str(i+1)+seq2[i]
164 
165 # use to compare sequences and sec_struct
166 def compare_sequences( seq1 , seq2 ):
167  for i in range(len(seq1)):
168  if not seq1[i]==seq2[i]:
169  print 'discrepency at '+seq1[i]+str(i+1)+seq2[i]
170 
171 # UNFINISHED BELOW HERE!
172 
173 # look for unmatched hbonds
174 def compare_hbonds( pose1 , pose2 , Ethresh = .5 , display = False ):
175  hblist1 = hbond_list(pose1)
176  hbset1 = get_hbonds(pose1)
177  hblist2 = hbond_list(pose2)
178  hbset2 = get_hbonds(pose2)
179  if display:
180  pymol = PyMOL_Mover()
181  delEn = []
182  for i in range(len(hblist1)):
183  for j in range(len(hblist2)):
184  if hblist1[i][1]==hblist2[j][1] and hblist1[i][2]==hblist2[j][2]:
185  # if the energy changes by ~25% or more...
186  if abs((hblist2[j][3]-hblist1[i][3])/hblist1[i][3])>Ethresh:
187  # compare bb sc ?
188  delEn.append(hblist1[i])
189  delEn[len(delEn)-1].append(hblist2[j][3])
190  delEn[len(delEn)-1].append(hblist2[j][3]>hblist1[i][3])
191  if display:
192  delEn[len(delEn)-1].append(hbset1.hbond(i))
193  hblist1[i] = (0,0,0)
194  hblist2[j] = (0,0,0)
195  break
196 
197  # remove all the matches now
198  for i in range(hblist1.count((0,0,0))):
199  hblist1.remove((0,0,0))
200  for j in range(hblist2.count((0,0,0))):
201  hblist2.remove((0,0,0))
202 
203  # print the explicit data
204  names = [pose1.pdb_info().name(),pose2.pdb_info().name()]
205  # is display: #set this up to avoid lots of ifs
206 
207  if len(hblist2)>0:
208  print 'hbonds not in',names[0]
209  for j in range(len(hblist2)):
210  # these hbonds are in pose2 but NOT in pose1
211  print hblist2[j][1],'\t',hblist2[j][2]
212  if display:
213  # send hbonds gained, green
214  # align them first!!!!
215  hbond = hbset2.hbond(hblist2[j][0])
216  donor = pose2.residue(hbond.don_res()).xyz(hbond.don_hatm())
217  acptr = pose2.residue(hbond.acc_res()).xyz(hbond.acc_atm())
218  pymol.send_point(names[0]+'_gains'+str(j),'green',donor[0],donor[1],donor[2],False,False,'')
219  pymol.send_point(names[0]+'_gains'+str(j),'green',acptr[0],acptr[1],acptr[2],False,False,'')
220 
221  if len(hblist1)>0:
222  print 'hbonds not in',names[1]
223  for i in range(len(hblist1)):
224  # these hbonds are in pose1 but NOT in pose2
225  print hblist1[i][1],'\t',hblist1[i][2]
226  if display:
227  # send hbonds lost, red
228  hbond = hbset1.hbond(hblist1[i][0])
229  donor = pose1.residue(hbond.don_res()).xyz(hbond.don_hatm())
230  acptr = pose1.residue(hbond.acc_res()).xyz(hbond.acc_atm())
231  pymol.send_point(names[0]+'_loses'+str(i),'red',donor[0],donor[1],donor[2],False,False,'')
232  pymol.send_point(names[0]+'_loses'+str(i),'red',acptr[0],acptr[1],acptr[2],False,False,'')
233 
234  if len(delEn)>0:
235  print 'Energy change from',names[0],'to',names[1]
236  for k in range(len(delEn)):
237  sign = '-'
238  color = 'blue'
239  group = '_decreases'
240  if delEn[k][5]:
241  sign = '+'
242  color = 'yellow'
243  group = '_increases'
244  print sign,'in',str(delEn[k][1]).ljust(20),str(delEn[k][2]).ljust(20),'from %.4f to %.4f'%(delEn[k][3],delEn[k][4])
245  if display:
246  # send energy change, if sign=='+' clr yellow, if sign=='-' clr blue
247  hbond = delEn[k][6]
248  donor = pose1.residue(hbond.don_res()).xyz(hbond.don_hatm())
249  acptr = pose1.residue(hbond.acc_res()).xyz(hbond.acc_atm())
250  pymol.send_point(names[0]+group+str(k),color,donor[0],donor[1],donor[2],False,False,'')
251  pymol.send_point(names[0]+group+str(k),color,acptr[0],acptr[1],acptr[2],False,False,'')
252 
253 
def random_sequence
Definition: mutants.py:152
core::pose::Pose Pose
Definition: supercharge.cc:101
def compare_sequences
Definition: mutants.py:166
xyzVector< Real > xyz(Real const &r1, Real const &omega1, Real const &t, Real const &dz1, Real const &delta_omega1, Real const &delta_z1)
Returns the x-, y-, and z-coordinates of a point on a helix given r1, omega1, and t...
Definition: HelixParams.cc:67
def get_hbonds
Definition: __init__.py:343
Fstring::size_type len(Fstring const &s)
Length.
Definition: Fstring.hh:2207
def compare_hbonds
Definition: mutants.py:174
def standard_packer_task
Definition: __init__.py:537
T abs(T const &x)
std::abs( x ) == | x |
Definition: Fmath.hh:295
def pose_from_sequence
Definition: mutants.py:108
Fstring ljust(Fstring const &s)
Left-Justified Copy.
Definition: Fstring.hh:2404
rule< Scanner, string_closure::context_t > name
Definition: Tag.cc:376
def compare_mutants__
Definition: mutants.py:158
def mutate_residue
Definition: mutants.py:34