Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseProteinUtil.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file StepWiseProteinUtil
11 /// @brief a few functions used by several StepWiseProteinAnsatz classes
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 //////////////////////////////////
18 
19 //////////////////////////////////
20 #include <core/fragment/Frame.hh>
22 #include <core/fragment/FragSet.hh>
25 #include <core/types.hh>
26 // AUTO-REMOVED #include <core/chemical/util.hh>
30 #include <core/id/NamedAtomID.hh>
31 #include <core/id/AtomID.hh>
32 #include <core/id/AtomID_Map.hh>
33 #include <core/pose/Pose.hh>
34 
35 #include <core/pose/util.hh>
36 #include <core/scoring/rms_util.hh>
37 // AUTO-REMOVED #include <core/scoring/rms_util.tmpl.hh>
38 
39 #include <numeric/angle.functions.hh>
40 #include <numeric/xyz.functions.hh>
41 #include <numeric/conversions.hh>
42 
43 #include <string>
44 
45 //Auto Headers
46 #include <utility/vector1.hh>
47 
48 
49 using core::Real;
50 using core::Size;
51 using core::pose::Pose;
52 
53 
54 
55 namespace protocols {
56 namespace swa {
57 namespace protein {
58 
59 /////////////////////////////////////////////////////////////
60  Real get_rotamer_angle( core::Size const & i, core::Size const & N_SAMPLE ){
61  return ( -180.0 + ( 360.0 / N_SAMPLE ) * i + 0.001 );
62  }
63 
64 
65  /////////////////////////////////////////////////////////////////////////////////////////////////
66  void
67  output_silent_struct( core::pose::Pose const & pose, core::pose::PoseCOP const & native_pose_op,
68  std::string const & silent_file, std::string const & tag,
69  core::io::silent::SilentFileDataOP sfd_in /* = 0 */ ){
70 
71  utility::vector1< core::Size > calc_rms_res; //blank vector
72  output_silent_struct( pose, native_pose_op, silent_file, tag, sfd_in, calc_rms_res );
73  }
74 
75  /////////////////////////////////////////////////////////////////////////////////////////////////
76  void
77  output_silent_struct( core::pose::Pose const & pose, core::pose::PoseCOP const & native_pose_op,
78  std::string const & silent_file, std::string const & tag,
80  utility::vector1< core::Size > const & calc_rms_res ){
81 
82  using namespace core::io::silent;
83  using namespace core::scoring;
84 
85  BinaryProteinSilentStruct s( pose, tag );
86 
87  if ( native_pose_op != 0 ){
88 
89  core::pose::Pose pose_for_superpose = pose; // is this necessary? quite a bit of overhead.
90  // core::pose::Pose const & native_pose_for_superpose( *native_pose_op ); // Unused variable causes warning.
91 
92  Real rmsd( -1.0), backbone_rmsd( -1.0), all_rmsd( -1.0 );
93 
94  std::map< core::id::AtomID, core::id::AtomID > CA_map, backbone_heavy_map, heavy_map;
95  setup_matching_CA_atoms( pose, *native_pose_op, CA_map );
96  setup_matching_protein_backbone_heavy_atoms( pose, *native_pose_op, backbone_heavy_map );
97  setup_matching_heavy_atoms( pose, *native_pose_op, heavy_map );
98 
99  if ( calc_rms_res.size() == 0 ) { // superimpose over everything
100  rmsd = rms_at_corresponding_atoms( pose, *native_pose_op, CA_map );
101  backbone_rmsd = rms_at_corresponding_atoms( pose, *native_pose_op, backbone_heavy_map );
102  all_rmsd = rms_at_corresponding_atoms( pose, *native_pose_op, heavy_map );
103 
104  //rmsd = CA_rmsd( pose_for_superpose, native_pose_for_superpose );
105  //backbone_rmsd = rmsd_with_super( pose_for_superpose, native_pose_for_superpose, is_protein_backbone_including_O);
106  //all_rmsd = rms_at_corresponding_heavy_atoms( pose_for_superpose, native_pose_for_superpose );
107  } else {
108  rmsd = rms_at_corresponding_atoms_no_super( pose, *native_pose_op, CA_map, calc_rms_res );
109  backbone_rmsd = rms_at_corresponding_atoms_no_super( pose, *native_pose_op, backbone_heavy_map, calc_rms_res );
110  all_rmsd = rms_at_corresponding_atoms_no_super( pose, *native_pose_op, heavy_map, calc_rms_res );
111  }
112 
113  s.add_energy( "rms", rmsd );
114  s.add_energy( "all_rms", all_rmsd );
115  s.add_energy( "backbone_rms", backbone_rmsd );
116  }
117 
118  static const SilentFileData silent_file_data;
119  if ( silent_file.size() > 0 ) silent_file_data.write_silent_struct( s, silent_file, false /*write score only*/ );
120  if ( sfd_in != 0 ) sfd_in->add_structure( s );
121 
122  }
123 
124  ////////////////////////////////////////////////////////////////////////////////////////////////////
125  void
127 
128  using namespace core::chemical;
129  core::pose::remove_variant_type_from_pose_residue( pose, "LOWER_TERMINUS", 1 );
130  core::pose::remove_variant_type_from_pose_residue( pose, "N_ACETYLATION", 1 );
131 
132  core::pose::remove_variant_type_from_pose_residue( pose, "UPPER_TERMINUS", pose.total_residue() );
133  core::pose::remove_variant_type_from_pose_residue( pose, "C_METHYLAMIDATION", pose.total_residue() );
134 
135  }
136 
137 
138  ///////////////////////////////////////////////////////////////////
139  // sigh. bookkeeping to keep junctions inherited properly...
140  Real get_pretend_psi_explicit( core::pose::Pose const & pose, Size const & res )
141  {
142  // Psi may not be defined in pose properly because there's no "next residue".
143  // But... we kind of know phi anyway, because the carbonyl oxygen is in the
144  // current residue. Would have been better to have phi, psi, etc. defined *internally*
145  // for each residue, using the O for psi, H for phi, etc., and/or virtual atoms for
146  // other crazy torsions.
147  using namespace core::id;
148  Real const psi = numeric::dihedral_radians(
149  pose.xyz( NamedAtomID( " O ", res ) ),
150  pose.xyz( NamedAtomID( " C ", res ) ),
151  pose.xyz( NamedAtomID( " CA ", res ) ),
152  pose.xyz( NamedAtomID( " N ", res ) ) );
153  // This is phi, up to an offset.
154  return numeric::principal_angle_degrees( 180.0 + numeric::conversions::degrees( psi ) );
155  }
156 
157  ///////////////////////////////////////////////////////////////////
158  // sigh. bookkeeping to keep junctions inherited properly...
159  Real get_pretend_phi_explicit( core::pose::Pose const & pose, Size const & res )
160  {
161  // Psi may not be defined in pose properly because there's no "next residue".
162  // But... we kind of know phi anyway, because the carbonyl oxygen is in the
163  // current residue. Would have been better to have phi, psi, etc. defined *internally*
164  // for each residue, using the O for psi, H for phi, etc., and/or virtual atoms for
165  // other crazy torsions.
166  using namespace core::id;
167  Real phi( 0.0 );
168 
169  if ( pose.residue(res).has( " H " ) ) {
170  phi = numeric::dihedral_radians(
171  pose.xyz( NamedAtomID( " C ", res ) ),
172  pose.xyz( NamedAtomID( " CA ", res ) ),
173  pose.xyz( NamedAtomID( " N ", res ) ),
174  pose.xyz( NamedAtomID( " H ", res ) ) );
175  } else if ( pose.residue(res).has( "1H " ) ) {
176  phi = numeric::dihedral_radians(
177  pose.xyz( NamedAtomID( " C ", res ) ),
178  pose.xyz( NamedAtomID( " CA ", res ) ),
179  pose.xyz( NamedAtomID( " N ", res ) ),
180  pose.xyz( NamedAtomID( "1H ", res ) ) );
181  }
182 
183  // This is phi, up to an offset.
184  return numeric::principal_angle_degrees( 180.0 + numeric::conversions::degrees( phi ) );
185  }
186 
187  //////////////////////////////////////////////////////////////////////////////////////////////////
188  void
190  core::pose::Pose const & pose_2,
191  Size const base_res,
193 
194  using namespace core::id;
195 
196  if ( !pose_1.residue_type( base_res ).is_protein() ) return;
197  if ( !pose_2.residue_type( base_res ).is_protein() ) return;
198 
199  AtomID atom1( core::pose::named_atom_id_to_atom_id( NamedAtomID( " CA ", base_res ), pose_1 ));
200  AtomID atom2( core::pose::named_atom_id_to_atom_id( NamedAtomID( " CA ", base_res ), pose_2 ));
201  atom_ID_map.set( atom1, atom2 );
202 
203  }
204 
205  //////////////////////////////////////////////////////////////////////////////////////////////////
206  void
208  core::pose::Pose const & pose_2,
209  Size const base_res,
211  setup_protein_backbone_atom_id_map( pose_1, pose_2, base_res, atom_ID_map );
212  }
213 
214  //////////////////////////////////////////////////////////////////////////////////////////////////
215  void
217  core::pose::Pose const & pose_2,
218  Size const base_res,
219  Size const base_res2,
221 
222  using namespace core::id;
223 
224  if( base_res == 0 ) return;
225  if( base_res2 == 0 ) return;
226 
227  if ( !pose_1.residue_type( base_res ).is_protein() ) return;
228  if ( !pose_2.residue_type( base_res2 ).is_protein() ) return;
229 
230  if ( pose_1.residue_type( base_res ).has_variant_type( "VIRTUAL_RESIDUE" ) ) return;
231  if ( pose_2.residue_type( base_res2 ).has_variant_type( "VIRTUAL_RESIDUE" ) ) return;
232 
233  {
234  AtomID atom1( core::pose::named_atom_id_to_atom_id( NamedAtomID( " CA ", base_res ), pose_1 ));
235  AtomID atom2( core::pose::named_atom_id_to_atom_id( NamedAtomID( " CA ", base_res2 ), pose_2 ));
236  atom_ID_map.set( atom1, atom2 );
237  }
238 
239  {
240  AtomID atom1( core::pose::named_atom_id_to_atom_id( NamedAtomID( " C ", base_res ), pose_1 ));
241  AtomID atom2( core::pose::named_atom_id_to_atom_id( NamedAtomID( " C ", base_res2 ), pose_2 ));
242  atom_ID_map.set( atom1, atom2 );
243  }
244 
245  {
246  AtomID atom1( core::pose::named_atom_id_to_atom_id( NamedAtomID( " N ", base_res ), pose_1 ));
247  AtomID atom2( core::pose::named_atom_id_to_atom_id( NamedAtomID( " N ", base_res2 ), pose_2 ));
248  atom_ID_map.set( atom1, atom2 );
249  }
250 
251  }
252 
253 
254  //////////////////////////////////////////////////////////////////////////////////////////////////////////
255  void
257  utility::vector1< core::Size > const & slice_res ){
258 
259  using namespace core::fragment;
260 
261  Size const len( fragset->max_frag_length() );
262 
264 
265  for ( Size n = 1; n <= (slice_res.size() - len + 1); n++ ) {
266 
267  Size const & pos = slice_res[ n ];
268 
269  FrameList frames;
270 
271  if ( pos > (fragset->max_pos()-len+1) ) {
272  std::cout << "WARNING: NO FRAGS FOR POSITION " << pos << std::endl;
273  continue;
274  }
275 
276  fragset->frames( pos, frames );
277 
278  // CURRENTLY ONLY WORKS FOR CONST FRAG LENGTH SETS!!!! ASSUMES ONE FRAME!!!
279  assert( frames.size() == 1 );
280 
281  FrameOP & frame( frames[1] );
282  FrameOP frame_new = new Frame( n, len );
283 
284  for ( Size n = 1; n <= frame->nr_frags(); n++ ) {
285  frame_new->add_fragment( frame->fragment_ptr( n ) );
286  }
287 
288  fragset_new->add( frame_new );
289 
290  }
291 
292  fragset = fragset_new;
293 
294  }
295 
296 
297 
298 
299 }
300 }
301 }