Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Ramady.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 src/protocols/relax/Ramady.cc
11 /// @brief Header for the Rana energy repair code, Ramady
12 /// @author Mike Tyka
13 
14 
16 
18 
25 #include <core/pose/Pose.hh>
26 // AUTO-REMOVED #include <core/pose/util.hh>
28 #include <core/scoring/Energies.hh>
29 #include <core/scoring/rms_util.hh>
31 #include <basic/Tracer.hh>
32 // AUTO-REMOVED #include <protocols/simple_moves/MinMover.hh>
33 // AUTO-REMOVED #include <protocols/moves/Mover.hh>
34 #include <utility/exit.hh>
35 
36 #include <protocols/loops/Loops.hh>
38 #include <utility/vector1.hh>
39 #include <numeric/random/random.hh>
40 
41 //Auto Headers
42 #include <core/kinematics/Jump.hh>
43 
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 
46 static basic::Tracer TR("protocols.relax.Ramady");
47 
48 namespace protocols {
49 namespace relax {
50 ////////////////////////////////////////////////////////////////////////////////////////////////////
51 
52 
53 
54 
55 void add_coordinate_constraints_to_pose( core::pose::Pose & pose, const core::pose::Pose &constraint_target_pose, protocols::loops::Loops &exclude_regions ){
56  using namespace core;
57  using namespace conformation;
58  using namespace pose;
59  using namespace scoring;
60  using namespace constraints;
61  using namespace id;
62  using namespace kinematics;
63  using namespace moves;
64 
65  core::Size nnonvrt_cst_target = constraint_target_pose.total_residue();
66  core::Size nnonvrt_pose = pose.total_residue();
67 
68  while ( pose.residue( nnonvrt_pose ).aa() == core::chemical::aa_vrt ) { nnonvrt_pose--; }
69  while ( constraint_target_pose.residue( nnonvrt_cst_target ).aa() == core::chemical::aa_vrt ) { nnonvrt_cst_target--; }
70 
71  protocols::loops::Loops coordconstraint_segments;
72  coordconstraint_segments = exclude_regions.invert( nnonvrt_cst_target );
73 
74  //TR << coordconstraint_segments << std::endl;
75 
76  if ( nnonvrt_pose != nnonvrt_cst_target ) {
77  std::cerr << "ERROR coord constraint pose length mismatch with input pose: " << nnonvrt_cst_target << " vs. " << nnonvrt_pose << std::endl;
78  utility_exit();
79  }
80 
81  if ( pose.residue( pose.fold_tree().root() ).aa() != core::chemical::aa_vrt ) {
84  pose.total_residue()/2 );
85  }
86 
87 
88  Size nres = pose.total_residue();
89  Real const coord_sdev( 0.5 );
90  for ( Size i = 1; i<= (Size)nres; ++i ) {
91  if ( i==(Size)pose.fold_tree().root() ) continue;
92  if( coordconstraint_segments.is_loop_residue( i ) ) {
93  Residue const & nat_i_rsd( pose.residue(i) );
94  for ( Size ii = 1; ii<= nat_i_rsd.last_backbone_atom(); ++ii ) {
96  AtomID(ii,i), AtomID(1,nres), nat_i_rsd.xyz( ii ),
97  new HarmonicFunc( 0.0, coord_sdev ) ) );
98  }
99  }
100  }
101 
102 
103 
104 
105 
106  }
107 
108 
109 
110 bool rama_list_pred( const std::pair < core::Size, core::Real > &left, const std::pair < core::Size, core::Real > &right )
111 {
112  return left.second > right.second;
113 }
114 
115 void fix_worst_bad_ramas( core::pose::Pose & original_pose, core::Size how_many, core::Real skip_prob, core::Real limit_RMS, core::Real limit_rama ){
116 
117  using namespace core;
118  using namespace id;
119  using namespace optimization;
120  using namespace protocols::moves;
121  using namespace core::scoring;
122  using namespace core::pose;
123  using namespace conformation;
124  using namespace kinematics;
125 
126  //const core::Real limit_RMS = 0.5;
127  //const core::Real limit_rama = 2.0;
128  //const core::Real limit_rama_min = 2.0;
129  const core::Real limit_rama_min = limit_rama;
130 
131 
132  // Original RAFT set
133  //-140 153 180 0.135 B
134  // -72 145 180 0.155 B
135  //-122 117 180 0.073 B
136  // -82 -14 180 0.122 A
137  // -61 -41 180 0.497 A
138  // 57 39 180 0.018 L
139 
140  core::Real post_fix_rama_e=0;
141  core::Real change_rms=0 ;
142  core::Real ok_phi[] = { -140, -72, -122, -82, -61, 57 } ;
143  core::Real ok_psi[] = { 153, 145, 117, -14, -41, 39 } ;
144  core::pose::Pose pose = original_pose;
145  core::pose::Pose temp_pose = pose;
146  protocols::loops::Loops exclude_regions;
147  add_coordinate_constraints_to_pose( pose, original_pose, exclude_regions ) ;
148  core::scoring::ScoreFunction rama_scorefxn;
149  rama_scorefxn.set_weight( coordinate_constraint, 0.2 );
150  rama_scorefxn.set_weight( rama, 1.0 );
151  rama_scorefxn.set_weight( omega, 0.2 );
152  Energies & energies( pose.energies() );
153  rama_scorefxn(pose); //apply score
154 
155  MinimizerOptions options( "dfpmin", 0.02, true /*use_nblist*/, false /*deriv_check*/ );
156  kinematics::MoveMap final_mm;
157  final_mm.set_bb(true);
158 
159 
160  std::vector < std::pair < core::Size, core::Real > > rama_list;
161 
162  for ( Size j=1; j<= pose.total_residue(); ++j ) {
163  EnergyMap & emap( energies.onebody_energies( j ) );
164  if ( emap[ rama ] > limit_rama_min )
165  rama_list.push_back( std::make_pair( j, emap[ rama ] ) );
166  }
167 
168  if( rama_list.size() == 0 ) return;
169  // sort the rama_list
170 
171  std::sort(rama_list.begin(), rama_list.end(), rama_list_pred);
172 
173  for ( Size g=0; g< rama_list.size(); g++ ){
174  TR << "RAMALIST: " << rama_list[g].first << " " << rama_list[g].second << std::endl;
175  }
176 
177  for ( Size g=0; g< how_many; g++ ){
178 
179  if ( g >= rama_list.size() ) break;
180 
181  if ( numeric::random::uniform() < skip_prob ) continue;
182 
183  core::Size i = rama_list[g].first;
184  EnergyMap & emap( energies.onebody_energies( i ) );
185  core::Real rama_e = emap[ rama ];
186 
187  TR << "RAMALIST: " << rama_list[g].first << " " << rama_list[g].second << " RAMA: " << rama_e << " RES: " << i << std::endl;
188  // save the angles
189  for( core::Size ir = 1; ir < pose.total_residue(); ir ++ ){
190  temp_pose.set_phi( ir, pose.phi( ir ) );
191  temp_pose.set_psi( ir, pose.psi( ir ) );
192  temp_pose.set_omega( ir, pose.omega( ir ) );
193  }
194  std::vector < core::Size > used_angles;
195 
196  while ( used_angles.size() < 6 ) {
197 
198 
199  // pick a random reasonable phi/spi pair
200 
201  //pose.dump_pdb("ramarep_" + utility::to_string( i ) + "_" + "pre.pdb" );
202 
203  const core::Size ok_angles = 6;
204  core::Real curphi = pose.phi(i);
205  core::Real curpsi = pose.psi(i);
206  core::Real newphi = ok_phi[0];
207  core::Real newpsi = ok_psi[0];
208  core::Real bestdist = 1000000;
209  core::Size bestindex = 0;
210  TR << "S:" << curphi << " " << curpsi << " " << std::endl;
211  for(core::Size a = 0; a < ok_angles; a++ ){
212  core::Real diffphi = ok_phi[a] - curphi; while( diffphi > 180 ) diffphi-=360.0; while( diffphi < -180 ) diffphi += 360.0;
213  core::Real diffpsi = ok_psi[a] - curpsi; while( diffpsi > 180 ) diffpsi-=360.0; while( diffpsi < -180 ) diffpsi += 360.0;
214  core::Real dist = sqrt( diffphi*diffphi + diffpsi * diffpsi );
215  TR << "T:" << ok_phi[a] << " " << ok_psi[a] << " " << dist << std::endl;
216  if( (dist < bestdist) || (a == 0) ){
217  if( std::find(used_angles.begin(), used_angles.end(), a)!=used_angles.end() ) continue;
218  newphi = ok_phi[a];
219  newpsi = ok_psi[a];
220  bestdist = dist;
221  bestindex = a;
222  }
223  }
224  used_angles.push_back( bestindex );
225  TR << "B:" << newphi << " " << newpsi << " " << bestdist << "BEST: " << bestindex << std::endl;
226 
227  pose.set_phi( i, newphi );
228  pose.set_psi( i, newpsi );
229  //pose.dump_pdb("ramarep_" + utility::to_string( i ) + "_" + "mid.pdb" );
230 
231  kinematics::MoveMap local_mm;
232  local_mm.set_bb(true);
233  for ( int ii=-4; ii< 3; ii ++ ){
234  int res = i + ii;
235 
236  if( res < 1 ) continue;
237  if( res > (int)pose.total_residue() ) continue;
238  local_mm.set_bb( res, true );
239  local_mm.set( TorsionID( omega_torsion, BB, res), false );
240  // disallow proline PHI
241  if ( pose.residue(res).aa() == chemical::aa_pro ) local_mm.set( TorsionID( phi_torsion, BB, res), false );
242  }
243 
244  AtomTreeMinimizer().run( pose, local_mm, rama_scorefxn, options );
245  AtomTreeMinimizer().run( pose, final_mm, rama_scorefxn, options );
246 
247  // Now check score
248  rama_scorefxn(pose); //apply score
249 
250  post_fix_rama_e = emap[ rama ];
251  change_rms = core::scoring::CA_rmsd( temp_pose, pose );
252 
253  TR << "RMS:" << change_rms << std::endl;
254 
255 
256  // break out if structure is good
257  if ( ( post_fix_rama_e < limit_rama ) &&
258  ( change_rms < limit_RMS ) ){
259  break;
260  }
261 
262  // otherwise restore and continue
263  for( core::Size ir = 1; ir < pose.total_residue(); ir ++ ){
264  pose.set_phi( ir, temp_pose.phi( ir ) );
265  pose.set_psi( ir, temp_pose.psi( ir ) );
266  pose.set_omega( ir, temp_pose.omega( ir ) );
267  }
268  }
269 
270 
271  TR << "RAMADY " << rama_e << " " << post_fix_rama_e << " " << change_rms << std::endl;
272 
273 
274 
275 
276  //pose.dump_pdb("ramarep_" + utility::to_string( i ) + "_" + "post.pdb" );
277  }
278 
279 
280 
281 
282  // Final RamaCheck
283  rama_scorefxn(pose); //apply score
284  for ( Size i=1; i<= pose.total_residue(); ++i ) {
285  if ( !pose.residue_type(i).is_protein() ) continue;
286  EnergyMap & emap( energies.onebody_energies( i ) );
287  TR << "CHECK: " << i << " "
288  << pose.phi(i) << " "
289  << pose.psi(i) << " "
290  << emap[ rama ] << std::endl;
291  }
292 
293  // save the angles
294  for( core::Size ir = 1; ir < original_pose.total_residue(); ir ++ ){
295  if ( !pose.residue_type(ir).is_protein() ) continue;
296  original_pose.set_phi( ir, pose.phi( ir ) );
297  original_pose.set_psi( ir, pose.psi( ir ) );
298  original_pose.set_omega( ir, pose.omega( ir ) );
299  }
300 
301 }
302 
303 
304 
305 }
306 
307 }
308 
309 
310