Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CoordinateCst.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 
11 /// @file
12 /// @brief allows to add coordinate constraints to the pose based on parsed spans or residues
13 /// residues specified are parsed at runtime not at parse time, so it can be used somewhat used with length changes
14 /// currently it only adds CA constraints, but hopefully at some time point others too
15 ///
16 /// @author Eva-Maria Strauch (evas01@u.washington.edu)
17 
18 // Unit headers
21 
27 #include <core/id/AtomID.hh>
28 #include <numeric/xyzVector.hh>
29 
31 #include <core/types.hh>
32 
34 #include <core/pose/selection.hh>
35 #include <utility/string_util.hh>
36 #include <boost/foreach.hpp>
37 #include <utility/tag/Tag.hh>
38 // C++ headers
39 #include <iostream>
40 #include <string>
41 
42 #define foreach BOOST_FOREACH
43 
44 #include <basic/Tracer.hh>
45 #include <utility/vector1.hh>
46 
47 #include <core/pose/Pose.hh>
48 
49 //pose
50 #include <core/pose/Pose.fwd.hh>
51 
52 #include <utility/vector0.hh>
53 
54 //Auto Headers
56 #include <core/kinematics/Jump.hh>
57 
58 
59 namespace protocols {
60 namespace seeded_abinitio {
61 
62 using namespace core;
63 using namespace scoring::constraints;
64 using namespace protocols::moves;
65 
66 static basic::Tracer TR( "protocols.seeded_abinitio.CoordinateCst" );
67 static basic::Tracer TR_debug( "CoordinateCst.Debug" );
68 
71 {
73 }
74 
77  return new CoordinateCst;
78 }
79 
82 {
83  return "CoordinateCst";
84 }
85 
87 
89  protocols::moves::Mover( CoordinateCstCreator::mover_name() )
90 {
91  stddev_ = 3.0;
92  use_jumps_ = true;
93  anchor_res_.clear();
94  span_vector_.clear();
95  unparsed_residue_.clear();
96  jump_ = 0;
97  anchor_atom_id_ = ""; // by default, use the same atom name as atom_id_ -- denote their sameness by setting this to the empty string
98  atom_id_ = "CA";
99 }
100 
103  return( protocols::moves::MoverOP( new CoordinateCst( *this ) ) );
104 }
105 
109 }
110 
111 ///parse residues at run time, in case there was a lenght change
113  pose::Pose & pose,
114  utility::vector1 < std::pair < std::string, std::string > > const span_vector,
115  std::set < core::Size > resi_collection
116 )
117 {
118 
119  for( Size iter = 1 ; iter <= span_vector.size() ; ++ iter ){
120  TR.Debug <<"sanity check, span_vector[iter].first " <<span_vector[iter].first <<std::endl;
121  core::Size const begin = core::pose::parse_resnum( span_vector[iter].first, pose ) ;
122  core::Size const end = core::pose::parse_resnum( span_vector[iter].second, pose );
123  //runtime_assert( end > begin );
124  //runtime_assert( begin>=1);
125  //runtime_assert( end<=pose.total_residue() );
126 
127  for (Size resi = begin; resi <= end ; resi ++ ){
128  resi_collection.insert( resi );
129  TR << "runtime parsed of span, residue: " << resi << std::endl;
130  }
131  }
132 }
133 
136  pose::Pose & pose,
137  std::string design_residues
138 ){
139 
140  utility::vector1< std::string > const design_keys( utility::string_split( design_residues, ',' ) );
142 
143  foreach( std::string const key, design_keys ){
144  core::Size const resnum( core::pose::parse_resnum( key, pose ));
145  //TR.Debug<<"design within seed, residue: "<< key <<", parsed: "<< resnum <<std::endl;
146  design_res.push_back( resnum);
147  TR.Debug<<"parsed "<<key<<std::endl;
148  }
149  //TR.Debug<<"runtime designable: " << design_res <<std::endl;
150  return design_res;
151 }//end parsing design residues
152 
153 
154 ///residue parsing at runtime
156  pose::Pose & pose,
157  std::string single_residues,
158  std::set < core::Size > resi_collection
159 ){
160 
161  utility::vector1< std::string > const single_keys( utility::string_split( single_residues, ',' ) );
162 
163  foreach( std::string const key, single_keys ){
164  core::Size const resnum( core::pose::parse_resnum( key, pose ));
165  resi_collection.insert( resnum );
166  }
167 }
168 
170  pose::Pose & pose,
171  std::set < core::Size > const constrain_residues,
172  core::Size const anchor_resnum,
173  core::Real const coord_sdev,
174  std::string anchor_atom_name, // if this is the empty string, use the same string as "atom_name"
175  std::string atom_name,
177 )
178 {
179 
180  using namespace core::scoring::constraints;
181  using namespace core::conformation;
182  //should this rather be a ConstraintSet?
183  ConstraintCOPs cst;
184 
185  if ( anchor_atom_name == "" ) {
186  anchor_atom_name = atom_name;
187  }
188 
189  if( anchor_resnum != 0 ){
190  TR<<"Anchor residue for the coordinate constraint is "<< anchor_resnum <<std::endl;
191 
192  if ( anchor_atom_name == "CB" ){
193  if( pose.residue( anchor_resnum ).aa() == core::chemical::aa_gly ) {
194  anchor_atom_name = "CA";
195  }
196  }
197  }
198  if ( ! pose.residue( anchor_resnum ).has( anchor_atom_name ) ) {
199  utility_exit_with_message( "Could not add coordinate constraint to anchor residue atom " + anchor_atom_name + " on residue "
200  + utility::to_string( anchor_resnum ) + " (" + pose.residue( anchor_resnum ).name()
201  + ") since that residue does not have an atom with that name" );
202  }
203  core::id::AtomID const anchor_atom( core::id::AtomID( pose.residue( anchor_resnum ).atom_index( anchor_atom_name ), anchor_resnum ) );
204 
205  if( !coord_cst_func ) {
206  coord_cst_func = new core::scoring::constraints::HarmonicFunc( 0.0, 0.0 );
207  }
208  coord_cst_func->sd( coord_sdev );
209 
210  foreach(core::Size res, constrain_residues) {
211  // safety check.
212  if ( ! pose.residue( res ).has( atom_name ) ) {
213  utility_exit_with_message( "Could not add coordinate constraint to " + atom_name + " on residue " + utility::to_string( res ) + " (" +
214  pose.residue( res ).name() + ") since that residue does not have an atom with that name" );
215  }
216  TR<<"Coordinate-constraining residue " << pose.residue( res ).name() << " " << res <<std::endl;
217  ///core::chemical::ResidueType rsd_type( pose.residue( res ).type() );
218  Size atomindex = pose.residue( res ).atom_index( atom_name );
219  cst.push_back( new CoordinateConstraint(
220  core::id::AtomID( atomindex, res ),
221  anchor_atom,
222  pose.residue( res ).xyz( atomindex ),
223  coord_cst_func));
224  cst = pose.add_constraints( cst );
225  }
226 }
227 
228 //option to use coordinate constraints on CA or on the functional group!(todo)
229 //for right now using CA
230 
231 void
233 {
234 
235  using namespace core;
236 
237  //collect all residues that should have coordinate constraints
238  std::set < core::Size > constrain_residues_set;
239 
240  if( unparsed_residue_ != "" ) {
241  adjust_single_residues( pose, unparsed_residue_, constrain_residues_set );
242  }
243 
244  parse_spans( pose, span_vector_ , constrain_residues_set );
245 
246  TR.Debug << "constrain residue set size : " << constrain_residues_set.size() <<" -- if this is 0, you did NOT read in any residues "<< std::endl;
247 
248  Size anchor_res;
249  TR.Debug<< "anchor " << anchor_res_ <<std::endl;
250 
251  if( !use_jumps_ && anchor_res_ != "" ){
252  //anchor needs to be parse too, could do that explicitly or as a set, incase anyone wanted at some point more than one anchor...
253  //std::set < core::Size > anchor_set;
254  //adjust_single_residues( pose, anchor_res_ , anchor_set);
255  utility::vector1 < core::Size > anchor_res_vec( adjust_residues( pose, anchor_res_ ) );
256  //for now just the first elemen
257  anchor_res = anchor_res_vec[1];
258  TR << "-- anchor residue: " << anchor_res << " --" << std::endl;
259  }
260 
261  if( use_jumps_ ) {
262  if( pose.fold_tree().jump_edge( jump_ ).start() == 0 ) {
263  TR<<"no jump detected, defaulting anchor to 1" << std::endl;
264  anchor_res = 1;
265  }
266  if( constrain_residues_set.size() == 0 ) {
267  constrain_residues_set.insert( pose.fold_tree().jump_edge( jump_ ).stop() );
268  TR<< "adding constraints to the downstream jump atom" << std::endl;
269  }
270 
271  anchor_res = (pose.fold_tree().jump_edge( jump_ ).start());
272  TR<< "setting anchor residue to upstream jump residue: " << anchor_res_ << std::endl;
273  }
274 
275 
277  add_coordinate_constraints( pose, constrain_residues_set, anchor_res, stddev_, anchor_atom_id_, atom_id_, coord_cst_func );
278 
279 }//end apply
280 
281 
285 }
286 
287 
288 void
290  TagPtr const tag,
291  DataMap & /*data*/,
292  protocols::filters::Filters_map const & /*filters*/,
293  Movers_map const &,
294  Pose const & /*pose*/)
295 {
296 
297  TR<<"CoordinateCst mover has been invoked"<<std::endl;
298  stddev_ = tag->getOption<core::Real>( "stddev", 0.5);
299 
300  TR<<"setting constraint standard deviation to "<< stddev_<< std::endl;
301  use_jumps_ = true;
302 
303  atom_id_ = tag->getOption< std::string >( "atom" , "CA" );
304 
305  // if not provided, set anchor_atom_id_ to the empty string which will signal to the
306  // add_coordinate_constraints function above that it should have the same value as the atom_id_ string.
307  anchor_atom_id_ = tag->getOption< std::string > ("anchor_atom", "" );
308 
309  if( tag->hasOption( "anchor_res" ) ){
310  anchor_res_ = tag->getOption< std::string >( "anchor_res" );
311  TR<< "user specified following residue as anchor atom for the coordinate constraints: " << anchor_res_ << std::endl;
312 
313  if( anchor_res_ != "" ){
314  TR<< "WARNING, if jump is specified, it will not be used, since the specification of an anchor residue will override it" <<std::endl;
315  use_jumps_ = false;
316  }//end excluding jump
317  }//end anchor
318 
319  if( tag->hasOption( "jump" )) {
320  jump_ = tag->getOption< core::Size >( "jump", 0 );
321  }
322 
323  if ( use_jumps_ ) {
324  TR<< "using jump atoms for anchor, that is the first one, for jump #: " << jump_ << std::endl;
325  }
326 
327  //parsing option for CA or CB to use or whether just functional groups!
328 
329  //parsing branch tags
330  utility::vector0< TagPtr > const branch_tags( tag->getTags() );
331 
332  foreach( TagPtr const btag, branch_tags ){
333 
334  if( btag->getName() == "Span" || btag->getName() == "span" || btag->getName() == "Seeds") {
335  std::string const beginS( btag->getOption<std::string>( "begin" ) );
336  std::string const endS( btag->getOption<std::string>( "end" ) );
337  std::pair <std::string,std::string> seedpair;
338  seedpair.first = beginS;
339  TR.Debug<<"parsing loop verteces: " << beginS << " " <<endS <<std::endl;
340  seedpair.second = endS;
341  span_vector_.push_back( seedpair );
342 
343  }//end seeds or chain
344 
345  if( btag->getName() == "residue" ) {
346  unparsed_residue_ = tag->getOption< std::string >("residue");
347  }//end residue tags
348 
349  }//end b-tags
350 }//end parse my tag
351 
352 }//seeded_abinitio/
353 }//protocol