Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CAcstGenerator.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
11 /// @author Eva-Maria Strauch (evas01@u.washington.edu)
12 // Unit headers
16 #include <core/pose/selection.hh>
17 #include <boost/foreach.hpp>
18 #include <core/types.hh>
19 
20 #define foreach BOOST_FOREACH
21 
22 #include <basic/Tracer.hh>
23 #include <utility/vector1.hh>
24 #include <utility/string_util.hh>
25 
26 // Project headers
27 #include <core/pose/Pose.hh>
28 #include <utility/tag/Tag.hh>
29 
30 //Auto Headers
36 #include <utility/vector0.hh>
37 #include <basic/options/keys/OptionKeys.hh>
38 
39 
40 namespace protocols {
41 namespace seeded_abinitio {
42 
43 using namespace core;
44 using namespace scoring::constraints;
45 using namespace protocols::moves;
46 
47 static basic::Tracer TR( "protocols.seeded_abinitio.CAcstGenerator" );
48 
51  {
53  }
54 
57  return new CAcstGenerator;
58  }
59 
62  {
63  return "CAcstGenerator";
64  }
65 
67 
69  protocols::moves::Mover( CAcstGeneratorCreator::mover_name() )
70  {
71  stddev_ = 3.0;
72  seed_exceptions_.clear();
73  distance_cutoff_ = 6;
74  }
75 
78  return( protocols::moves::MoverOP( new CAcstGenerator( *this ) ) );
79 }
80 
84 }
85 
86 bool
88  core::Size & residue){
89  bool res_cut = false;
90  for( Size i = 1; i <= cut_points.size(); ++i ){
91  if ( cut_points[i] == residue)
92  res_cut = true;
93  }
94  return res_cut;
95 }
96 
97 ///this method will get de-convoluted soon....
99  pose::Pose & pose,
100  pose::PoseOP & pose_of_int,
101  core::Size start_relevant_chain,
103  protocols::loops::Loops & seeds,// referring to template if one is given! or just individual chain numbering
104  protocols::loops::Loops & clear_area,
106  utility::vector1< core::Size > seed_exceptions,
107  bool add_cst_seed,
108  core::Real stddev,
109  core::Size seq_separation,
110  core::Real distance_cutoff
111  ){
112 
113  using namespace scoring::constraints;
114  using namespace id;
115  //using namespace basic::options;
116  //using namespace basic::options::OptionKeys;
117 
118  TR<<"stddev for harmonic constraints: " << stddev <<std::endl;
119 
120  if( cut_points.empty() )
121  TR<<"there are no cut point registered" <<std::endl;
122 
123  TR.Debug << "start_relevant_chain: " << start_relevant_chain << std::endl;
124  TR.Debug << "seeds: " << seeds << std::endl;
125  TR.Debug << "clear_area " << clear_area << std::endl;
126 
127  for( Size i=1;i<=cut_points.size(); i++) {
128  TR <<"cutpoints: " << cut_points[i] << std::endl;
129  }
130 
131  //adjust cutpoints first to relevant numbering
132  for( Size i = 1 ; i <= cut_points.size(); ++i ){
133  TR.Debug <<"rosetta numbering: cutpoint: "<< cut_points[i] <<std::endl;
134  cut_points[i] = cut_points[i] - (start_relevant_chain -1);
135  TR.Debug <<"adjusted cutpoint: "<< cut_points[i] <<std::endl;
136  }
137 
138  for( Size i=1;i<=cut_points.size(); i++) {
139  TR <<"cutpoints: " << cut_points[i] << std::endl;
140  }
141 
142 
143  for ( Size pos = 1; pos <= pose_of_int->total_residue(); pos++ ) {
144  for (Size pos_2 = 1; pos_2 <=pose_of_int->total_residue(); pos_2++ ){
145 
146  bool res_is_loop = false;
147  bool res2_is_loop = false;
148 
149  if( !is_part( seed_exceptions, pos) ){
150  //if residues are part of the loop, set to true
151  res_is_loop = seeds.is_loop_residue( pos );
152  }
153 
154  if( !is_part( seed_exceptions, pos_2 ) ){
155  res2_is_loop = seeds.is_loop_residue( pos_2 );
156  }
157 
158  bool cut_point_pos = false;
159  bool cut_point_pos_2 = false;
160  bool res_cst_free = false;
161 
162  //add the cst of the segment that will be replaced by the seed(s)
163  if ( add_cst_seed ){
164  res_is_loop = false;
165  res2_is_loop = false;
166  }
167 
168  //user specified area that is allowed to float
169  if ( clear_area.size() > 0 ){
170  if ( clear_area.is_loop_residue(pos) || clear_area.is_loop_residue(pos_2) ){
171  res_cst_free = true;
172  }
173  }
174 
175  //mark cut points
176  if ( cut_points.size() > 1 ) {
177  cut_point_pos = is_part(cut_points, pos );
178  cut_point_pos_2 = is_part(cut_points, pos_2 );
179  }
180 
181  //avoiding doubling of constraints
182  Size seq_sep = 0;
183 
184  if (pos > pos_2)
185  seq_sep = pos - pos_2;
186  else
187  seq_sep = 0; //to avoid repetition
188  //seq_sep = pos_2 - pos;
189 
190  if ( seq_sep >= seq_separation ){
191  if ( !res_is_loop && !res2_is_loop ) {
192  if( !cut_point_pos && !cut_point_pos_2 ){
193 
194  if (!res_cst_free){
195  core::conformation::Residue res_pos = pose_of_int->residue(pos);
196  core::conformation::Residue res_pos_2 = pose_of_int->residue(pos_2);
197 
198  Real const distance_ca( res_pos.xyz( res_pos.atom_index("CA") ).distance( res_pos_2.xyz( res_pos_2.atom_index("CA") )));
199  TR.Debug <<"distance contraints for: " << pos_2 <<" "<< pos << " "<<distance_ca <<std::endl;
200  TR.Debug <<"updated: "<<pos_2 + start_relevant_chain -1 <<" " << pos + start_relevant_chain - 1<< " " <<distance_ca << std::endl;
201 
202  if( distance_ca > distance_cutoff ){
203  //adjust numbering to the current input pose!
204  core::conformation::Residue res_in_pose = pose.residue( pos + start_relevant_chain - 1 );
205  core::conformation::Residue res_in_pose2= pose.residue( pos_2 + start_relevant_chain - 1);
206 
207  cst->add_constraint( new AtomPairConstraint ( AtomID(res_in_pose.atom_index("CA"), pos + start_relevant_chain - 1), AtomID(res_in_pose2.atom_index("CA"),pos_2 + start_relevant_chain - 1), new HarmonicFunc( distance_ca, stddev ) ) );
208  }
209  }
210  }
211  }
212  }//end seq_sep
213  }
214  }
215 }
216 
217 void
219 
220  using namespace core;
221 
222  utility::vector1< Size > cutpoints = pose.fold_tree().cutpoints();
223 
224  for( Size i=1;i<=cutpoints.size(); i++) {
225  TR.Debug <<"cutpoints: " << cutpoints[i] << std::endl;
226  }
227 
228  TR.Debug << "foldtree: " << pose.fold_tree();
229 
230  pose::PoseOP donor_poseOP;
231  Size start_recipient_chain;
233 
234  //this all has to be checked during run time since parse time input will be inaccurate if the pose has been grown before
235  if( from_chain_ == 0 ){
236  TR<<"user did not specify for which chain constraints should be derrived, defaulting to all chains"<<std::endl;
237  if( template_presence_ ){
238  donor_poseOP = *template_pdb_ ;
239  TR<<"derriving CA distance constraints from the template pdb, since a template was given"<<std::endl;
240  }
241  else
242  donor_poseOP = pose;
243  }
244 
245  //statements to prevent bogus from happening
246  if( to_chain_ == 0 && template_presence_ ){
247  if (pose.total_residue() != template_pdb_->total_residue() )
248  utility_exit_with_message("chain(s) to derrive constraints form and chain(s) to apply it to, do NOT have the same residue number. NOT supported." );
249  }
250 
251  if( from_chain_ != 0 ){
252  if( template_presence_ ){
253  donor_poseOP = new pose::Pose( template_pdb_->split_by_chain( from_chain_ ) );
254  TR<<"derriving CA distance constraints from the template pdb"<<std::endl;
255  }
256  else{
257  donor_poseOP = new pose::Pose( pose.split_by_chain( from_chain_ ) );
258  }
259  }
260 
261  if( to_chain_ != 0 ){
262  start_recipient_chain = pose.conformation().chain_begin( to_chain_ );
263  TR<<"adding constraints starting from index residue: " <<start_recipient_chain <<std::endl;
264  }
265 
266  if( from_chain_ != 0 && to_chain_ != 0 ){
267  TR<<"donor chain length: " << donor_poseOP->total_residue() <<", recipient chain length: " << pose.conformation().chain_end( to_chain_ ) - pose.conformation().chain_begin( to_chain_) +1 <<std::endl;
268  if( donor_poseOP->total_residue() != (pose.conformation().chain_end( to_chain_ ) - pose.conformation().chain_begin( to_chain_) + 1) )
269  utility_exit_with_message("donor pose and recipient chain do not have the same residue numbers, check your template or input pdb");
270  }
271 
272 
273  add_dist_constraints( pose, donor_poseOP , start_recipient_chain , ca_cst_, all_seeds_ , clear_seeds_ , cutpoints, seed_exceptions_, add_cst_seed_ , stddev_, seq_separation_, distance_cutoff_);
274 
275  if( replace_ ){
276  TR<<"replacing all constraints with newly generated constraint set" <<std::endl;
277  pose.constraint_set( ca_cst_ );
278  }
279  else {
280  utility_exit_with_message("ADDing new constraints to pose, is currently not supported, try just replacing"); //<<std::endl;
281  }
282  TR.flush();
283 }
284 
288  }
289 
290 
291 void
293  DataMap & /*data*/,
294  protocols::filters::Filters_map const & /*filters*/,
295  Movers_map const &,
296  Pose const & ){
297 
298  TR<<"CAcstGenerator has been invoked"<<std::endl;
299 
300  /// the constraints can be either derrived from a chain of the input pose or from a template pose
301  /// If a template pose is provided, the constraints will be derrived from that pdb, defaulting to chain 1 of it
302  /// otherwise, the user can specify for which chain of the input pose constraints will be derrived
303  /// currently it only allows one chain at a time or all chains....
304 
305  template_presence_ = false;
306 
307  stddev_ = tag->getOption<core::Real>( "stddev", 3.0);
308 
309  TR<<"setting constraint standard deviation to "<< stddev_<< std::endl;
310 
311  if( tag->hasOption( "template_pdb" ) ){
312  std::string const template_pdb_fname( tag->getOption< std::string >( "template_pdb" ));
313  template_pdb_ = new core::pose::Pose ;
314  core::import_pose::pose_from_pdb( *template_pdb_, template_pdb_fname );
315  TR<<"read in a template pdb with " <<template_pdb_->total_residue() <<"residues"<<std::endl;
316  template_presence_ = true;
317  }
318 
319  add_cst_seed_ = tag->getOption< bool >("add_cst_seed", 0 ); ///header
320 
321  replace_ = tag->getOption< bool >("replace", 1 );
322 
323  seq_separation_ = tag->getOption< core::Size >( "seq_separation", 6 );
324 
325  distance_cutoff_ = tag->getOption< core::Real >("distance", 6.0 );
326 
327  if( tag->hasOption( "add_seed_residues" ) ){
328  std::string residues_string = tag->getOption< std::string > ("add_seed_residues" );
329  utility::vector1< std::string > const residue_keys( utility::string_split( residues_string, ',' ) );
330  foreach( std::string const key, residue_keys ){
331  Size const res( utility::string2int( key ) );
332  TR << "add constraints to residues within seed, residue: "<< key <<std::endl;
333  seed_exceptions_.push_back( res );
334  }
335  }
336 
337  //parsing branch tags
338  utility::vector0< TagPtr > const branch_tags( tag->getTags() );
339 
340  foreach( TagPtr const btag, branch_tags ){
341  //parse the pdb of interest, which is either the template or the input pdb depending on the users specificiation
342  if( template_presence_ )
343  curr_pose_ = template_pdb_;
344 
345  if( btag->getName() == "Seeds" ) { //need an assertion for the presence of these or at least for the option file
346  //needs some assertions to avoid bogus input
347  std::string const beginS( btag->getOption<std::string>( "begin" ) );
348  std::string const endS( btag->getOption<std::string>( "end" ) );
349  core::Size const begin( core::pose::parse_resnum( beginS, *curr_pose_ ) );
350  core::Size const end( core::pose::parse_resnum( endS, *curr_pose_ ) );
351 
352  TR.Debug <<"parsing seeds: \n"<< begin <<" and " << end <<std::endl;
353  TR.Debug <<"seeds: "<< all_seeds_ <<std::endl;
354 
355  all_seeds_.add_loop( begin , end , 0, 0, false );
356 
357  }//end seed tags
358 
359  if( btag->getName() == "Clear_cst_segment" ) { //need an assertion for the presence of these or at least for the option file
360 
361  std::string const begin_str( btag->getOption<std::string>( "begin" ) );
362  std::string const end_str( btag->getOption<std::string>( "end" ) );
363  core::Size const begin( core::pose::parse_resnum( begin_str, *curr_pose_ ) );
364  core::Size const end( core::pose::parse_resnum( end_str, *curr_pose_ ) );
365  clear_seeds_.add_loop( begin , end , 0, 0, false );
366 
367  }//end seed tags
368  }//end branch tags
369 
370  ///could be eventually a vector of chains if desired
371  ///but currently just the simple version...
372 
373  if( tag->hasOption( "from_chain" ) ){
374  from_chain_ = tag->getOption< core::Size >( "from_chain", 1 );
375  TR<<"chain to derrive constraints from: "<< from_chain_ <<std::endl;
376  }
377 
378  if( tag->hasOption( "to_chain" ) ){
379  to_chain_ = tag->getOption< core::Size >( "to_chain", 1 );
380  TR<<"chain to apply constraints to: "<< to_chain_ <<std::endl;
381  }
382 
383  }//end parse my tag
384 
385  }//CAcstGenerator
386 }//protocol