Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FlexPepDockingFlags.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) 199x-2008 Hebrew University, Jerusalem
5 //
6 // (c) Copyright Rosetta Commons Member Institutions.
7 // (c) This file is part of the Rosetta software suite and is made available under license.
8 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
9 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
10 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
11 /// @file FlexPepDockingFlags.cc
12 ///
13 /// @brief flags structure for FlexPepDocking protocols
14 /// @date January 1, 2009
15 /// @author Barak Raveh
16 
18 
20 #include <core/types.hh>
21 #include <basic/options/option.hh>
22 #include <basic/options/keys/OptionKeys.hh>
23 #include <basic/options/keys/flexPepDocking.OptionKeys.gen.hh>
24 #include <core/pose/Pose.hh>
25 #include <core/pose/PDBInfo.hh>
26 #include <basic/Tracer.hh>
28 #include <utility/exit.hh>
29 
30 #include <iostream>
31 #include <fstream>
32 #include <string>
33 // AUTO-REMOVED #include <stdlib.h>
34 
35 #include <utility/vector1.hh>
36 
37 
38 static basic::Tracer TR("protocols.flexPepDocking.FlexPepDockingFlags");
39 
40 using namespace protocols::flexpep_docking;
41 
42 
43 //////////////////////////////////////////////////
44 /// ctr
45 ///
46 /// @brief
47 /// initialize all flags from cmd-line options
48 //////////////////////////////////////////////////
50 ()
51 {
52  using namespace basic::options;
53 
54  // a-priori all flags are invalid
55  valid_chain_bounds_ = false;
56  valid_receptor_chain_ = false;
57  valid_peptide_chain_ = false;
58  valid_ref_start_struct_ = false;
59  receptor_anchor_pos = -1; // -1 == invalid
60 
61  pep_fold_only = option[ OptionKeys::flexPepDocking::pep_fold_only ]();
62  if (option[ OptionKeys::flexPepDocking::ref_startstruct].user() ) {
63  ref_start_struct_ =
64  option[ OptionKeys::flexPepDocking::ref_startstruct]();
65  valid_ref_start_struct_ = true;
66  }
67  min_only = option[ OptionKeys::flexPepDocking::flexPepDockingMinimizeOnly ]();
68  random_phi_psi_pert = false;
69  if (option[ OptionKeys::flexPepDocking::random_phi_psi_preturbation ]())
70  random_phi_psi_pert = true;// TODO: redundant, default value is enough
71  random_phi_psi_pert_size =
72  option[ OptionKeys::flexPepDocking::random_phi_psi_preturbation ]();
73  extend = option[ OptionKeys::flexPepDocking::extend_peptide ]();
74  randomRBstart = false; // TODO: redundant, default value is enough
75  if (option[ OptionKeys::flexPepDocking::random_trans_start ]() ||
76  option[ OptionKeys::flexPepDocking::random_rot_start ]())
77  randomRBstart = true;
78  lowres_abinitio = option[ OptionKeys::flexPepDocking::lowres_abinitio ]();
79  lowres_preoptimize = option[ OptionKeys::flexPepDocking::lowres_preoptimize ]();
80  pep_refine = option[ OptionKeys::flexPepDocking::pep_refine ]();
81  rbMCM = option[ OptionKeys::flexPepDocking::rbMCM ](); // obsolete
82  torsionsMCM = option[ OptionKeys::flexPepDocking::torsionsMCM ](); // obsolete
83  // the next section should be removed after we get rid of obsolee rmMCM and torsionsMCM completely
84  if(pep_refine || lowres_preoptimize || lowres_abinitio)
85  { // overrides old rbMCM and torsionsMCM
86  bool explicitFalseMCMs =
87  ( option[ OptionKeys::flexPepDocking::rbMCM ].user() && !rbMCM) ||
88  ( option[ OptionKeys::flexPepDocking::torsionsMCM ].user() && !torsionsMCM);
89  runtime_assert_msg(!explicitFalseMCMs,
90  "pep_refine / lowres_preoptimize / lowres_abinitio are not compatible with explicitly setting -rbMCM or -torsionsMCM to false");
91  rbMCM = true;
92  torsionsMCM = true;
93  }
94 
95  rb_trans_size = option[ OptionKeys::flexPepDocking::random_trans_start ]();
96  rb_rot_size = option[ OptionKeys::flexPepDocking::random_rot_start ]();
97  peptide_loop_model = option[ OptionKeys::flexPepDocking::peptide_loop_model ]();
98  smove_angle_range =
99  option[ OptionKeys::flexPepDocking::smove_angle_range ]();
100  design_peptide = option [ OptionKeys::flexPepDocking::design_peptide ]();
101  backrub_opt = option[ OptionKeys::flexPepDocking::backrub_peptide ]();
102  boost_fa_atr = option[ OptionKeys::flexPepDocking::boost_fa_atr ]();
103  ramp_fa_rep = option [ OptionKeys::flexPepDocking::ramp_fa_rep ]();
104  ramp_rama = option [ OptionKeys::flexPepDocking::ramp_rama ]();
105  rep_ramp_cycles =
106  option[ OptionKeys::flexPepDocking::rep_ramp_cycles ](); //10 default
107  mcm_cycles =
108  option[ OptionKeys::flexPepDocking::mcm_cycles ](); //8 default
109  score_only = option[ OptionKeys::flexPepDocking::flexpep_score_only ]();
110  use_cen_score = option[ OptionKeys::flexPepDocking::use_cen_score ]();
111  min_receptor_bb = option[ OptionKeys::flexPepDocking::min_receptor_bb ];
112  ppk_only = option[ OptionKeys::flexPepDocking::flexpep_prepack ]();
113  no_prepack1 = option[ OptionKeys::flexPepDocking::flexpep_noprepack1 ]();
114  no_prepack2 = option[ OptionKeys::flexPepDocking::flexpep_noprepack2 ]();
115  score_filter = option[ OptionKeys::flexPepDocking::score_filter ]();
116  hb_filter = option[ OptionKeys::flexPepDocking::hb_filter ]();
117  hotspot_filter = option[ OptionKeys::flexPepDocking::hotspot_filter ]();
118  frag3_weight = option[ OptionKeys::flexPepDocking::frag3_weight ]();
119  frag5_weight = option[ OptionKeys::flexPepDocking::frag5_weight ]();
120  frag9_weight = option[ OptionKeys::flexPepDocking::frag9_weight ]();
121  pSer2Asp_centroid = option[ OptionKeys::flexPepDocking::pSer2Asp_centroid ]();
122  pSer2Glu_centroid = option[ OptionKeys::flexPepDocking::pSer2Glu_centroid ]();
123  dumpPDB_abinitio = option[ OptionKeys::flexPepDocking::dumpPDB_abinitio ]();
124  dumpPDB_lowres = option[ OptionKeys::flexPepDocking::dumpPDB_lowres ]();
125  dumpPDB_hires = option[ OptionKeys::flexPepDocking::dumpPDB_hires ]();
126 
127 
128  if ( option[ OptionKeys::flexPepDocking::receptor_chain ].user() )
129  {
130  this->set_receptor_chain
131  (option[ OptionKeys::flexPepDocking::receptor_chain ]().at(0) );
132  // TODO: validate string size!
133  }
134  if ( option[ OptionKeys::flexPepDocking::peptide_chain ].user() )
135  {
136  this->set_peptide_chain
137  (option[ OptionKeys::flexPepDocking::peptide_chain ]().at(0) );
138  // TODO: validate string size!
139  }
140  // params file
141  if(option[ OptionKeys::flexPepDocking::params_file ].user() )
142  {
143  runtime_assert_msg(! (valid_peptide_chain_ || valid_receptor_chain_),
144  "Params file and cmd-line peptide or receptor chain are mutually exclusive");
145  params_file = option[ OptionKeys::flexPepDocking::params_file ]();
146  updateChainsAndAnchors_fromParamsFile(params_file);
147  }
148  valid_peptide_chain_ = valid_peptide_chain_;
149  runtime_assert_msg(! (pep_fold_only && (min_receptor_bb || valid_receptor_chain_) ),
150  "The flag -pep_fold_only is incompatible with receptor flags like -min_receptor_bb and -receptor chain");
151  int mut_ex_opts = 0;
152  if(min_only) mut_ex_opts++;
153  if(ppk_only) mut_ex_opts++;
154  if(torsionsMCM || rbMCM || lowres_preoptimize)
155  mut_ex_opts++;
156  runtime_assert_msg(mut_ex_opts <= 1,
157  "More than one mutually exclusive flags selected");
158 
159 }
160 
162  {
163  if(valid_chain_bounds_) {
165  return true;
166  else
167  return false;
168  }
169  std::cout << "ERROR: chain bounds invalid" << std::endl;
170  exit(-1);
171  }
172 
174  {
176  std::cout << "ERROR: receptor chain invalid" << std::endl;
177  exit(-1);
178  }
179 
180 
182 {
183  if(valid_chain_info()) return peptide_chain_;
184  std::cout << "ERROR: peptide chain invalid" << std::endl;
185  exit(-1);
186 }
187 
188 
190 {
192  std::cout << "ERROR: chain bounds invalid: receptor_first " << std::endl;
193  exit(-1);
194 }
195 
196 
198 {
200  return receptor_first_res_ + receptor_nres_ - 1;
201  std::cout << "ERROR: chain bounds invalid: receptor_last " << std::endl;
202  exit(-1);
203 }
204 
205 
207 {
208  if(valid_chain_info()) return receptor_nres_;
209  if(pep_fold_only) return 0;
210  std::cout << "ERROR: chain bounds invalid: receptor_nres " << std::endl;
211  exit(-1);
212 }
213 
214 
216 {
218  std::cout << "ERROR: chain bounds invalid: pep_first " << std::endl;
219  exit(-1);
220 }
221 
222 
224 {
225  if(valid_chain_info())
226  return peptide_first_res_ + peptide_nres_ - 1;
227  std::cout << "ERROR: chain bounds invalid: pep_last " << std::endl;
228  exit(-1);
229 }
230 
231 
233 {
234  if(valid_chain_info()) return peptide_nres_;
235  std::cout << "ERROR: chain bounds invalid: pep_nres " << std::endl;
236  exit(-1);
237 }
238 
239 
241 {
243  std::cout << "ERROR: ref start structure not specified" << std::endl;
244  exit(-1);
245 }
246 
247 
249 {
251 }
252 
253 
254 // if needed, set default chain ids for receptor and peptide
255 // and update parameters of chain length
256 //
257 // Default chains:
258 // if chains of receptor and peptide are invalid,
259 // use the first and second chain in the pose (respectively)
260 // if only one is invalid, take the first chain that differs from it
261 void
263 ( core::pose::Pose const& pose )
264 {
265  // TODO: extend for multichains?
266  // update chain ids if needed
267  core::pose::PDBInfoCOP pdbinfo = pose.pdb_info();
268  if(!pdbinfo){
269  TR.Warning << "Missing PDBInfo in input pose - generating default PDBInfo from pose object" << std::endl;
270  pdbinfo = new core::pose::PDBInfo(pose);
271  }
272  core::Size resi = 1;
273  // get receptor chain if needed
274  if(!valid_receptor_chain_ && ! pep_fold_only)
275  {
276  receptor_chain_ = pdbinfo->chain(resi);
277  // make sure receptor is different from peptide
278  if(valid_peptide_chain_ && (receptor_chain_ == peptide_chain_)){
279  do{ resi++; }
280  while(resi <= pose.total_residue() && pdbinfo->chain(resi) == peptide_chain_);
281  receptor_chain_ = pdbinfo->chain(resi);
282  }
283  valid_receptor_chain_ = true;
284  }
285  // get peptide chain if needed
286  if(!valid_peptide_chain_)
287  {
288  if(pep_fold_only)
289  {
290  this->set_peptide_chain(pdbinfo->chain(resi));
291  }
292  else // docking mode
293  {
294  // skip receptor chain
295  do{ resi++; }
296  while(resi <= pose.total_residue() && pdbinfo->chain(resi) == receptor_chain_);
297  this->set_peptide_chain(pdbinfo->chain(resi));
298  }
299  }
300 
301  // find receptor boundaries
302  resi = 1;
303  if(! pep_fold_only)
304  {
305  while(resi <= pose.total_residue() && pdbinfo->chain(resi) != receptor_chain_) resi++;
306  receptor_first_res_ = resi;
307  do{ resi++; }
308  while(resi <= pose.total_residue() && pdbinfo->chain(resi) == receptor_chain_);
309  receptor_nres_ = resi - receptor_first_res_;
310  }
311  else
312  {
313  receptor_first_res_ = 0;
314  receptor_nres_ = 0;
315  }
316 
317  // find peptide boundaries
318  resi = 1;
319  while(resi <= pose.total_residue() && pdbinfo->chain(resi) != peptide_chain_) resi++;
320  peptide_first_res_ = resi;
321  do{ resi++; }
322  while(resi <= pose.total_residue() && pdbinfo->chain(resi) == peptide_chain_);
323  peptide_nres_ = resi - peptide_first_res_;
324 
325  TR << "Receptor chain: " << receptor_chain_ << std::endl;
326  TR << "Receptor first res: " << receptor_first_res_ << std::endl;
327  TR << "Receptor nres: " << receptor_nres_ << std::endl;
328  TR << "Peptide chain: " << peptide_chain_ << std::endl;
329  TR << "Peptide first res: " << peptide_first_res_ << std::endl;
330  TR << "Peptide nres: " << peptide_nres_ << std::endl;
331 
332  // declare valid results
333  valid_chain_bounds_ = true;
334 }
335 
336 
337 // calc default anchors
338 void
340 ( core::pose::Pose& pose ) // TODO: pose should be const, fix RB_geometry 4 this
341 {
342  // TODO: extend for multichains?
343  using namespace basic::options;
344  using namespace protocols::geometry;
345  peptide_anchors.clear();
346  peptide_cuts.clear();
347  // peptide anchor - from cmd line, if not set - peptide c.o.m
348  if ( option[ OptionKeys::flexPepDocking::peptide_anchor ].user() )
349  {
350  this->peptide_anchors[1] = option[ OptionKeys::flexPepDocking::peptide_anchor ];
351  }
352  else {
353  this->peptide_anchors[1] = residue_center_of_mass
354  ( pose,
355  peptide_first_res(),
356  peptide_last_res() );
357  }
358  TR << "Peptide anchor: " << peptide_anchors[1] << std::endl;
359  TR << "# peptide anchors: " << peptide_anchors.size() << std::endl;
360  TR << "# peptide cuts: " << peptide_cuts.size() << std::endl;
361  runtime_assert_msg(peptide_anchors[1] >= peptide_first_res() &&
362  peptide_anchors[1] <= peptide_last_res(),
363  "Peptide anchor out of range");
364 
365  // receptor anchor - nearest residue in protein
367  pep_anchor_ca( pose.residue( peptide_anchors[1] ).atom( "CA" ).xyz() );
368  if(valid_receptor_chain_)
369  {
370  this->receptor_anchor_pos = return_nearest_residue
371  ( pose,
372  receptor_first_res(),
373  receptor_last_res() ,
374  pep_anchor_ca);
375  TR << "Receptor anchor: " << receptor_anchor_pos << std::endl;
376  runtime_assert_msg( receptor_anchor_pos >= receptor_first_res() &&
377  receptor_anchor_pos <= receptor_last_res() ,
378  "Receptor anchor out of range");
379 
380  }
381 }
382 
383 
384 // support for old params-file format
385 // TODO: also take chain-ids from params file
386 // TODO: currently ignores cuts
387 // TODO: add support for pep_fold_only
388 void
390 ( std::string const& params_file )
391 {
392  using namespace std;
393  bool local_debug = true;
394  TR << "Reading params from file [" << params_file << "]" << endl;
395 
396  // invalidate any previous info
397  peptide_anchors.clear();
398  peptide_cuts.clear();
399  valid_chain_bounds_ = false;
400  valid_receptor_chain_ = false;
401  valid_peptide_chain_ = false;
402  receptor_nres_ = -1;
403  peptide_first_res_ = -1;
404  peptide_nres_ = -1;
405  receptor_anchor_pos = -1;
406 
407 
408  // TODO: read params file somewhere else, move to XML?
409  receptor_first_res_ = 1; // this is an assumption in params file
410  std::ifstream data( params_file.c_str() );
411  std::string line;
412  while ( getline( data,line) ) {
413  std::istringstream l( line );
414  int param;
415  std::string tag;
416  l >> tag >> param;
417  if ( tag == "scaffold_anchor_pos" ) { //TODO: change format of params to "receptor_anchor_pos"?
418  receptor_anchor_pos = param;
419  TR << "# receptor_anchor_pos " << param << endl;
420  }
421  else if ( tag == "nres_scaffold" ) {
422  receptor_nres_ = param;
423  TR << "# nres_receptor " << param << endl;
424  peptide_first_res_ = receptor_nres_ + 1; // TODO: is that always so?
425  }
426  else if ( tag == "nres_peptide" ) {
427  peptide_nres_ = param;
428  TR << "# nres_peptide " << param << endl;
429  }
430  else if ( tag == "peptide_anchor" ) {
431  int njump = param;
432  int pep_anchor;
433  l >> pep_anchor;
434  TR << "# peptide_anchor " << njump << " anchor " << pep_anchor <<endl;
435  peptide_anchors[njump]=pep_anchor;
436  }
437  }
438 
439  TR << "# finished reading params" << endl;
440 
441  // offset peptide anchors / cuts residues, by peptide_first_res_
442  std::map<int,int>::iterator iter;
443  for(iter = peptide_anchors.begin(); iter != peptide_anchors.end(); iter++)
444  iter->second += (peptide_first_res_ - 1);
445  for(iter = peptide_cuts.begin(); iter != peptide_cuts.end(); iter++)
446  iter->second += (peptide_first_res_ - 1);
447 
448  // check results validity
449  if(receptor_first_res_ != -1 &&
450  receptor_nres_ != -1 &&
451  peptide_first_res_ != -1 &&
452  peptide_nres_ != -1)
453  {
454  valid_chain_bounds_ = true;
455  }
456 
457  if(local_debug){
458  TR << "nres_receptor: " << receptor_first_res_ << endl
459  << "nres_peptide: " << peptide_nres_ << endl
460  << "pep_begin_res: " << peptide_first_res_ << endl
461  << "receptor_anchor_pos: " << receptor_anchor_pos << endl
462  << "number of peptide anchors: " << peptide_anchors.size() << endl
463  << "number of peptide cuts: " << peptide_cuts.size() << endl
464  << endl;
465  }
466 
467  if(!valid_chain_bounds_ || !valid_anchors()){
468  TR << "Missing or invalid information in parameters file "
469  << params_file << std::endl;
470  exit(-1);
471  }
472 
473 }
474 
475