Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JointSequenceOperation.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 protocols/toolbox/task_operations/JointSequenceOperation.cc
11 /// @brief set designable residues to those observed in a set of structures
12 /// @author Rocco Moretti, rmoretti@u.washington.edu
13 
14 
15 // Unit Headers
18 
19 // Project Headers
20 #include <basic/options/option.hh>
21 #include <basic/options/keys/in.OptionKeys.gen.hh>
22 #include <basic/Tracer.hh>
23 
24 #include <core/chemical/AA.hh>
27 #include <core/pose/Pose.hh>
28 #include <core/pose/PDBInfo.hh>
31 #include <core/sequence/util.hh>
36 #include <protocols/jd2/util.hh>
37 
38 // Utility Headers
39 #include <utility/tag/Tag.hh>
40 #include <utility/vector1.hh>
41 #include <string>
42 
43 #include <utility/vector0.hh>
44 
45 
46 static basic::Tracer TR("protocols.toolbox.task_operations.JointSequenceOperation");
47 
48 namespace protocols{
49 namespace toolbox{
50 namespace task_operations{
51 
54 {
55  return new JointSequenceOperation;
56 }
57 
58 /// @brief default constructor
60  TaskOperation(),
61  use_current_pose_(true),
62  use_natro_(false),
63  use_fasta_(false),
64  ubr_(0),
65  chain_(0)
66 {
67 }
68 
69 /// @brief destructor
71 
72 /// @brief clone
75  return new JointSequenceOperation( *this );
76 }
77 
78 /// @brief all AA that have a higher probability in the seqprofile
79 /// than the native residue are allowed. probability also
80 /// needs to be higher than min_aa_probability_
81 void
82 JointSequenceOperation::apply( Pose const & pose, PackerTask & task ) const
83 {
84 
87 
90 
91  if( chain_ > 0 ){
92  //core::pose::Pose new_pose;
93  //new_pose = pose.split_by_chain( chain_ );
94  //pose = new_pose;
95  start = pose.conformation().chain_begin( chain_ );
96  end = pose.conformation().chain_end( chain_ );
97  }
98  else {
99  start = 1;
100  end = pose.total_residue();
101  }
102 
103  //TR << "CHAIN: " << chain_ << std::endl;
104  //TR << "START: " << start << std::endl;
105  //TR << "END: " << end << std::endl;
106 
107  core::Size seq_length = end - start + 1;
108 
109  // Iter through native sequence
110  for( std::vector<core::sequence::SequenceOP>::const_iterator iter(sequences_.begin()); iter != sequences_.end(); iter++ ) {
111  if( (*iter)->length() != seq_length ) {
112  std::string name("current pdb");
113  if( pose.pdb_info() ) {
114  name = pose.pdb_info()->name();
115  }
116  TR.Warning << "WARNING: considered sequence " << (*iter)->id() << " contains a different number of residues than " << name << std::endl;
117  }
118  }
119  // Inter through current pose sequence
120  for( core::Size ii = start; ii <= end; ++ii){
121  if( core::pose::symmetry::is_symmetric(pose) && !syminfo->chi_is_independent(ii) ) continue;
122  if( !pose.residue_type( ii ).is_protein() ) continue;
123 
124  int na_ii = ii - start + 1;
125 //NK120531 -- These lines commented out bc they are useless and crash for symmetric systems.
126 //NK120531 std::vector<core::sequence::SequenceOP>::const_iterator iter(sequences_.begin());
127 //NK120531 char aa( (*(*iter))[ na_ii ] ); // aa char of native pose
128 
130 
131  if(use_current_pose_) {
132  if( pose.aa(ii) <= allowed.size() ) allowed[ pose.aa(ii) ] = true;
133  }
134  for( std::vector<core::sequence::SequenceOP>::const_iterator iter(sequences_.begin()); iter != sequences_.end(); iter++ ) {
135  //if ( ii > (*iter)->length() ) continue; // ignore short references
136  char aa( (*(*iter))[ na_ii ] );
138  if(core::chemical::aa_from_oneletter_code(aa)<=allowed.size()) {
139  //TR << "JointSeq: " << pose.aa(ii) << ii << " " << core::chemical::aa_from_oneletter_code(aa) << na_ii << std::endl;
140  allowed[ core::chemical::aa_from_oneletter_code(aa) ] = true;
141  }
142  }
143  }
145  } //loop over all residues
146 
147  if( use_natro_ && ubr_) {
149  }
150 } // apply
151 
152 void
154 {
155  use_current_pose( tag->getOption< bool >( "use_current", true ) );
156  use_natro( tag->getOption< bool >( "use_natro", false ) );
157 
158  // specifiy a chain, if 0 use all
159  chain_ = tag->getOption< core::Size >("chain", 0 );
160 
161  if( tag->getOption< bool >( "use_native", false )) {
162  if( basic::options::option[ basic::options::OptionKeys::in::file::native ].user() ) {
163  add_native_pdb( basic::options::option[ basic::options::OptionKeys::in::file::native ] );
164  }
165  else {
166  utility_exit_with_message("Native PDB not specified on command line.");
167  }
168  }
169 
170  if( tag->getOption< bool >( "use_starting_as_native", false )) {
172  add_native_pose( pose );
173  }
174 
175  if( tag->hasOption("filename") ){
176  add_pdb( tag->getOption< String >( "filename" ) );
177  }
178  if( tag->hasOption("native") ){
179  add_native_pdb( tag->getOption< String >( "native" ) );
180  }
181 
182  if ( tag->getOption< bool >( "use_fasta", false )) {
183  // Use native FASTA sequence
184  if( basic::options::option[ basic::options::OptionKeys::in::file::fasta ].user() ) {
185  std::string fasta_file( core::sequence::read_fasta_file_str( basic::options::option[ basic::options::OptionKeys::in::file::fasta ]()[1] )[1] );
186  add_native_fasta( fasta_file );
187  }
188  else {
189  utility_exit_with_message("Native FASTA file not specified on command line.");
190  }
191 
192  }
193 
194 }
195 
196 void
197 JointSequenceOperation::parse_def( utility::lua::LuaObject const & def)
198 {
199  use_current_pose( def["use_current"] ? def["use_current"].to<bool>() : true );
200  use_natro( def["use_natro"] ? def["use_natro"].to<bool>() : false );
201 
202  // specifiy a chain, if 0 use all
203  chain_ = def["chain"] ? def["chain"].to<core::Size>() : 0;
204 
205  if( def["use_native"] && def["use_native"].to<bool>() == false ) {
206  if( basic::options::option[ basic::options::OptionKeys::in::file::native ].user() ) {
207  add_native_pdb( basic::options::option[ basic::options::OptionKeys::in::file::native ] );
208  }
209  else {
210  utility_exit_with_message("Native PDB not specified on command line.");
211  }
212  }
213 
214  if( def["use_starting_as_native"] && def["use_starting_as_native"].to<bool>() == false ) {
216  add_native_pose( pose );
217  }
218 
219  if( def["filename"] ) {
220  add_pdb( def["filename"].to<std::string>() );
221  }
222  if( def["native"] ) {
223  add_native_pdb( def["native"].to<std::string>() );
224  }
225 
226  if( def["use_fasta"] && def["use_fasta"].to<bool>() == false ) {
227  // Use native FASTA sequence
228  if( basic::options::option[ basic::options::OptionKeys::in::file::fasta ].user() ) {
229  std::string fasta_file( core::sequence::read_fasta_file_str( basic::options::option[ basic::options::OptionKeys::in::file::fasta ]()[1] )[1] );
230  add_native_fasta( fasta_file );
231  }
232  else {
233  utility_exit_with_message("Native FASTA file not specified on command line.");
234  }
235 
236  }
237 }
238 
239 /// @brief Add the sequence from the given filename to the set of allowed aas.
240 void
242 {
243 
244  core::pose::Pose new_pose;
245  core::pose::Pose pose;
246 
247  core::import_pose::pose_from_pdb( new_pose, filename );
248  if( chain_ > 0 ){
249  TR << "taking only chain " << chain_ << std::endl;
250  pose = new_pose.split_by_chain( chain_ ) ;
251  }
252  else
253  pose = new_pose;
254 
255  add_pose( pose );
256 }
257 
258 /// @brief Add the sequence from the given pose to the set of allowed aas.
259 void
261 {
262  std::string name("unknown");
263  if( pose.pdb_info() ) {
264  name = pose.pdb_info()->name();
265  }
266  sequences_.push_back( new core::sequence::Sequence(pose.sequence(), name) );
267 }
268 
269 /// @brief Add the sequence from the given filename to the set of allowed aas
270 /// and add the rotamers to the set of possible rotamers (if use_natro_ is set)
271 void
274  core::import_pose::pose_from_pdb( *poseop, filename );
275  add_native_pose( poseop );
276 }
277 
278 /// @brief Add the sequence from the given pose to the set of allowed aas
279 /// and add the rotamers to the set of possible rotamers
280 void
281 JointSequenceOperation::add_native_pose( core::pose::PoseCOP posecop ){ // PoseCOP needed by UnboundRot, unfortunately
282  if( use_natro_ ) { // Deliberate check now to avoid keeping native poses around if we're never going to need them.
283  ubr_->add_pose(posecop);
284  }
285  add_pose(*posecop);
286 }
287 
288 /// @brief Should the current pose (pose supplied to apply) be used in addition to the other ones?
289 void
291 {
292  use_current_pose_ = ucp;
293 }
294 
295 /// @brief Should the rotamers for the native poses be used?
296 void
298  if( !use_natro_ && unr ) {
300  }
301  if( use_natro_ && !unr ) {
302  ubr_ = 0; // Allow owning pointer to garbage collect as necessary.
303  }
304  use_natro_ = unr;
305 }
306 
307 /// @brief which chain should be considered
308 void
310  chain_ = chain;
311 }
312 
313 /// @brief Read native as a FASTA file
314 void
316 
317  //core::sequence::SequenceOPSequenceOP native_sequence = new Sequence(fasta_file,"fasta",1);
318  std::string name("unknown");
319  sequences_.push_back( new core::sequence::Sequence(fasta_file, name) );
320 
321  //string query_sequence ( read_fasta_file( option[ in::file::fasta ]()[1])[1]->sequence() );
322  //core::pose::PoseOP poseop(new core::pose::Pose);
323  //core::import_pose::pose_from_pdb( *poseop, filename );
324  //add_native_pose( poseop );
325 
326  //using core::sequence::read_fasta_file;
327  //string fasta_sequence ( read_fasta_file( option[ in::file::fasta ]()[1])[1]->sequence() );
328 }
329 
330 } // TaskOperations
331 } // toolbox
332 } // protocols
333