Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
H3PerturbCCD.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
6 // (c) under license. The Rosetta software is developed by the contributing
7 // (c) members of the Rosetta Commons. For more information, see
8 // (c) http://www.rosettacommons.org. Questions about this can be addressed to
9 // (c) University of Washington UW TechTransfer, email:license@u.washington.edu
10 
11 /// @file protocols/antibody2/H3PerturbCCD.cc
12 /// @brief Build a homology model of an antibody2
13 /// @detailed
14 ///
15 ///
16 /// @author Jianqing Xu (xubest@gmail.com)
17 
18 
19 
21 
22 #include <basic/Tracer.hh>
23 #include <basic/options/option.hh>
24 #include <basic/options/keys/in.OptionKeys.gen.hh>
25 
26 #include <numeric/numeric.functions.hh>
27 #include <numeric/random/random.hh>
28 #include <numeric/xyz.functions.hh>
29 
31 #include <core/io/pdb/pose_io.hh>
33 #include <core/kinematics/Jump.hh>
36 #include <core/fragment/Frame.hh>
41 #include <core/fragment/FragSet.hh>
42 #include <core/pose/Pose.hh>
43 #include <core/pose/PDBInfo.hh>
44 #include <core/pose/util.hh>
46 
49 #include <protocols/loops/Loop.hh>
50 #include <protocols/loops/Loops.hh>
52 
57 
60 
61 
62 
63 static numeric::random::RandomGenerator RG(21141980);
64 
65 
66 
67 
68 using basic::T;
69 using basic::Error;
70 using basic::Warning;
71 
72 static basic::Tracer TR("protocols.antibody2.H3PerturbCCD");
73 
74 
75 
76 
77 using namespace core;
78 namespace protocols {
79 namespace antibody2 {
80 
81 
82 
83 
84 // default constructor
85 H3PerturbCCD::H3PerturbCCD() : Mover() {
86  user_defined_ = false;
87 }
88 
89 // default destructor
91 
92 
93 H3PerturbCCD::H3PerturbCCD( AntibodyInfoOP antibody_in ) : Mover()
94 {
95  user_defined_ = false;
96  ab_info_ = antibody_in;
97 
98  init();
99 }
100 
101 
103  core::scoring::ScoreFunctionCOP lowres_scorefxn ) : Mover()
104 {
105  user_defined_ = true;
106  ab_info_=antibody_in;
107  lowres_scorefxn_ = new core::scoring::ScoreFunction(*lowres_scorefxn);
108 
109  init();
110 }
111 
112 
113 
115 {
116  set_default();
117 
118 }
119 
120 
121 
122 
124  cutoff_9_ = 16; // size of loop above which 9mer frags are used
125  cutoff_3_ = 6; // size of loop above which 3mer frags are used
126  cen_cst_ = 10.0;
127  num_cycles1_ = 10; //max cycles to be spent building loops
128  h3_fraction_ = 0.75; // 75% of loops are required to be H3's
129  max_ccd_cycles_ = 500;
130  ccd_threshold_ = 0.1;
131  Temperature_ = 2.0;
132 
133  is_camelid_ = false;
134  current_loop_is_H3_ = true;
135  H3_filter_ = true;
136 
137 
138 
139  if(!user_defined_){
141  lowres_scorefxn_->set_weight( scoring::chainbreak, 10./3. );
143  }
144 }
145 
146 
147 
148 
149 
150 //clone
152  return( new H3PerturbCCD() );
153 }
154 
155 
156 
157 
158 
159 
160 
162 
164 
167 
168 }
169 
170 
171 
172 
173 void H3PerturbCCD::apply( pose::Pose & pose_in ) {
174 
175 
176  finalize_setup( pose_in );
177 
178 
179  loops::Loop trimmed_cdr_h3 = input_loop_;
180 
181  using namespace fragment;
182  using namespace protocols;
183  using namespace protocols::simple_moves;
184  using namespace protocols::loops;
189 
190  TR << "Fragments based centroid CDR H3 loop building" << std::endl;
191 
192  if( trimmed_cdr_h3.size() <= 2){
193  utility_exit_with_message("Loop too small for modeling");
194  }
195 
196 
197 
198 
199 
200  // params
201  Size h3_attempts(0);
202  Real current_h3_prob = RG.uniform();
203  TR<<"current_h3_prob="<<current_h3_prob<<std::endl;
204 
205 
206 
207  Size frag_size(0);
208  FragSetOP frags_to_use;
209  {
210  if( trimmed_cdr_h3.size() > cutoff_9_ ) {
211  frags_to_use = cdr_h3_frags_[1]->empty_clone();
212  frags_to_use = cdr_h3_frags_[1];
213  frag_size = 9;
214  }
215  else {
216  frags_to_use = cdr_h3_frags_[2]->empty_clone();
217  frags_to_use = cdr_h3_frags_[2];
218  frag_size = 3;
219  }
220  }
221  TR<<"frag_size="<<frag_size<<std::endl;
222 
223  // Storing Fold Tree
224  kinematics::FoldTree old_fold_tree = pose_in.fold_tree();
225 
226  // New Fold Tree
227  simple_one_loop_fold_tree( pose_in, trimmed_cdr_h3 );// is the cutpoint important or not???
228  TR<<trimmed_cdr_h3<<std::endl;
229  TR<<pose_in<<std::endl;
230 
231 
232  // set cutpoint variants for correct chainbreak scoring
233  loops::remove_cutpoint_variants( pose_in, true );
234  if( !pose_in.residue( trimmed_cdr_h3.cut() ).is_upper_terminus() ) {
235  if( !pose_in.residue( trimmed_cdr_h3.cut() ).has_variant_type(chemical::CUTPOINT_LOWER))
237  if( !pose_in.residue( trimmed_cdr_h3.cut() + 1 ).has_variant_type(chemical::CUTPOINT_UPPER ) )
239  }
240 
241 
242  //setting MoveMap
243  //JQX: all the chi angles of all the side chains are flexible
244  // only the backbone of the trimmed_cdr_h3 is flexible
245  kinematics::MoveMapOP cdrh3_map;
246  cdrh3_map = new kinematics::MoveMap();
247  cdrh3_map->clear();
248  cdrh3_map->set_chi(true );
249  cdrh3_map->set_bb (false);
250  for( Size ii=trimmed_cdr_h3.start(); ii<=trimmed_cdr_h3.stop(); ii++ ){
251  cdrh3_map->set_bb( ii, true );
252  }
253  cdrh3_map->set_jump( 1, false );
254 
255 
256  // aroop_temp default 25 * loop size
257  Size num_cycles2(25 * trimmed_cdr_h3.size() );
258  bool H3_found_ever(false);
259  Size total_cycles(0);
260  Size buffer( (is_camelid_ && (ab_info_->get_Predicted_H3BaseType()==Extended) ) ? 2 : 0 );
261  bool loop_found(false);
262 
263  while( !loop_found && ( total_cycles++ < num_cycles1_) ) {
264  // JQX: insert random fragments over the whole loop
265  // fragment has a size frag_size
266  //TR<<"trimmed_cdr_h3.start() = "<<trimmed_cdr_h3.start()<<std::endl;
267  //TR<<"trimmed_cdr_h3.stop() - ( buffer + (frag_size - 1 ) ) = "<<trimmed_cdr_h3.stop() - ( buffer + (frag_size - 1 ) )<<std::endl;
268  for(Size ii = trimmed_cdr_h3.start(); ii<=trimmed_cdr_h3.stop() - ( buffer + (frag_size - 1 ) ); ii++ ) {
269  ClassicFragmentMoverOP cfm = new ClassicFragmentMover( frags_to_use, cdrh3_map);
270  cfm->set_check_ss( false );
271  cfm->enable_end_bias_check( false );
272  cfm->define_start_window( ii );
273  cfm->apply( pose_in );
274  }
275 
276 
277  if( total_cycles == 1 ) {
278  mc_->reset( pose_in );
279  }
280  Size local_h3_attempts(0);
281 
282 
283 
284  for ( Size c2 = 1; c2 <= num_cycles2; ++c2 ) {
285  TR<<"c1="<<total_cycles<<" "<<"c2="<<c2<<std::endl;
286  // apply a random fragment
287  ClassicFragmentMoverOP cfm = new ClassicFragmentMover( frags_to_use, cdrh3_map);
288  cfm->set_check_ss( false );
289  cfm->enable_end_bias_check( false );
290  cfm->apply( pose_in );
291 
292 
293 
294  bool H3_found_current(false);
295  if( current_loop_is_H3_ && H3_filter_ && ( local_h3_attempts++ < (50 * num_cycles2) ) ) {
296  H3_found_current = CDR_H3_cter_filter(pose_in, ab_info_);
297  if( !H3_found_ever && !H3_found_current) {
298  --c2;
299  mc_->boltzmann( pose_in );
300  // JQX: 1. this try failed, and never succeeded before, --c2
301  // 2. accept or reject this pose, then retry this cycle
302  }
303  else if( !H3_found_ever && H3_found_current ) {
304  H3_found_ever = true;
305  mc_->reset( pose_in );
306  // JQX: 1. this try succeeded, and it is the 1st time success
307  // 2. reset the pose
308  }
309  else if( H3_found_ever && !H3_found_current ) {
310  --c2;
311  continue;
312  // JQX: this try failed, but you get success before, --c2, retry this cycle
313  }
314  else if( H3_found_ever && H3_found_current ){
315  mc_->boltzmann( pose_in );
316  // JQX: this try succeeded, and you also succeeded before
317  }
318  }
319  else{
320  mc_->boltzmann( pose_in );
321  }
322 
323  // TODO:
324  // JQX: this "RG.uniform() * num_cycles2 < c2" is so weird, not sure what Aroop really wants to do
325  if ( (c2 > num_cycles2/2 && RG.uniform() * num_cycles2 < c2) || ( trimmed_cdr_h3.size() <= 5) ) {
326  // in 2nd half of simulation, start trying to close the loop:
327  CcdMoverOP ccd_moves = new CcdMover( trimmed_cdr_h3, cdrh3_map );
329  if( trimmed_cdr_h3.size() <= 5 ) {
330  ccd_cycle = new protocols::moves::RepeatMover(ccd_moves,500*trimmed_cdr_h3.size());
331  ccd_cycle->apply( pose_in );
332  }
333  else {
334  ccd_cycle = new protocols::moves::RepeatMover(ccd_moves, 10*trimmed_cdr_h3.size());
335  ccd_cycle->apply( pose_in );
336  }
337  mc_->boltzmann( pose_in );
338  }
339  }// finish cycles2
340 
341 
342 
343  mc_->recover_low( pose_in );
344 
345 
346 
347  CcdLoopClosureMoverOP ccd_closure = new CcdLoopClosureMover(trimmed_cdr_h3, cdrh3_map );
348  ccd_closure->set_tolerance( ccd_threshold_ );
349  ccd_closure->set_ccd_cycles( max_ccd_cycles_ );
350  ccd_closure->apply( pose_in );
351 
352 
353 
354  if( total_cycles == 1 ){
355  outer_mc_->reset( pose_in );
356  }
357 
358  if ( ccd_closure->forward_deviation() <= ccd_threshold_ && ccd_closure->backward_deviation()<= ccd_threshold_ )
359  {
360  // CDR-H3 filter for antibody mode
361  // introduce enough diversity
362  outer_mc_->boltzmann( pose_in );
363  if( current_loop_is_H3_ && H3_filter_ && (current_h3_prob < h3_fraction_) && (h3_attempts++<50) ){
364  if( !CDR_H3_cter_filter(pose_in, ab_info_) )
365  {
366  continue;
367  }
368  }
369  loop_found = true;
370  }
371  else if( H3_filter_ ){h3_attempts++;}
372 
373  }// finish cycles1
374 
375  outer_mc_->recover_low( pose_in );
376 
377  // Restoring Fold Tree
378  pose_in.fold_tree( old_fold_tree );
379 
380  TR << "Finished Fragments based centroid CDR H3 loop building" << std::endl;
381 
382  return;
383 }
384 
385 
386 
387 
388 
389 
391  using namespace chemical;
392  using namespace id;
393  using namespace fragment;
394  using namespace core::scoring;
395 
396 
397 
398  // fragment initialization
400 
402 
403  Size frag_size = (ab_info_->get_CDR_loop(h3).stop() - ab_info_->get_CDR_loop(h3).start()) + 3; //JQX: why +3??
404  TR<<frag_size<<std::endl;
405 
406 
407 
408  FragSetOP offset_3mer_frags;
409 
410  // a fragset of same type should be able to handle everything
411  offset_3mer_frags = frag_libs[2]->empty_clone();
412  FrameList loop_3mer_frames;
413  Size offset = 0;
414  frag_libs[2]->region_simple( 1, frag_size, loop_3mer_frames );
415  for ( FrameList::const_iterator it = loop_3mer_frames.begin(),
416  eit = loop_3mer_frames.end(); it!=eit; ++it ) {
417  FrameOP short_frame = (*it)->clone_with_frags();
418  offset++;
419  short_frame->shift_to( ( ab_info_->get_CDR_loop(h3).start() - 2 ) + offset );
420  offset_3mer_frags->add( short_frame );
421  }
422 
423  FragSetOP offset_9mer_frags;
424  // a fragset of same type should be able to handle everything
425  offset_9mer_frags = frag_libs[1]->empty_clone();
426  FrameList loop_9mer_frames;
427  offset = 0;
428  frag_libs[1]->region_simple( 1, frag_size, loop_9mer_frames );
429  for ( FrameList::const_iterator it = loop_9mer_frames.begin(),
430  eit = loop_9mer_frames.end(); it!=eit; ++it ) {
431  FrameOP short_frame = (*it)->clone_with_frags();
432  offset++;
433  short_frame->shift_to( ( ab_info_->get_CDR_loop(h3).start() - 2 ) + offset );
434  offset_9mer_frags->add( short_frame );
435  }
436 
437 
438 
439  cdr_h3_frags_.push_back( offset_9mer_frags );
440  cdr_h3_frags_.push_back( offset_3mer_frags );
441 
442  TR<<"Finished reading fragments files!!!"<<std::endl;
443 
444  return;
445 
446 }
447 
448 
449 
450 
451 
452 
453 
454 
455 
456 
457 }// namespace antibody2
458 }// namespace protocols
459 
460 
461