Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EnzConstraintIO.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 IO-functionality for enzyme design constraints
11 /// @brief
12 /// @author Florian Richter, floric@u.washington.edu
13 
14 // Unit headers
17 
18 // Package headers
19 //#include <core/scoring/constraints/SequenceProfileConstraint.hh> //msa
25 
26 // Project headers
29 #include <core/pose/Pose.hh>
30 #include <core/pose/PDBInfo.hh> //reading remarks
31 #include <core/pose/PDBPoseMap.hh> //for PDB-info-to-resid functionality
32 // AUTO-REMOVED #include <core/io/pdb/file_data.hh> //reading remarks
33 //MSA
34 //#include <core/sequence/SequenceProfile.hh>
35 // AUTO-REMOVED #include <core/scoring/constraints/ConstraintIO.hh>
37 // AUTO-REMOVED #include <basic/options/keys/constraints.OptionKeys.gen.hh>
38 
39 #include <core/scoring/ScoreFunction.hh> //scoring ambiguous constraints
42 //#include <core/scoring/constraints/ResidueTypeConstraint.hh>
43 
44 // AUTO-REMOVED #include <core/pack/task/PackerTask.hh> //favor_native_res
45 #include <basic/options/option.hh> //options
46 
47 // Utility Headers
48 //#include <utility/pointer/ReferenceCount.hh>
49 #include <utility/io/izstream.hh>
50 #include <utility/string_util.hh>
51 #include <iostream>
52 #include <fstream>
53 #include <string>
54 #include <sstream>
55 
56 #include <basic/Tracer.hh>
57 
58 // option key includes
59 
60 #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
61 
62 #include <utility/vector1.hh>
63 
64 //#include <basic/options/keys/in.OptionKeys.gen.hh>
65 
66 
67 
68 static basic::Tracer tr("protocols.toolbox.match_enzdes_util.EnzConstraintIO");
69 
70 namespace protocols {
71 namespace toolbox {
72 namespace match_enzdes_util {
73 
75 
76 ///@ brief constructor for EnzConstraintIO class, builds up function types
78  restype_set_ = src_restype_set;
79  //favor_native_constraints_.clear();
80  mcfi_lists_.clear();
81  cst_pairs_.clear();
82 }
83 
85 
88 
89  using namespace core::chemical;
90 
91  if( !generic_instance_ ){
92 
94  generic_instance_->read_enzyme_cstfile( basic::options::option[basic::options::OptionKeys::enzdes::cstfile]);
95 
96  }
97 
98  return &(*generic_instance_);
99 
100 } //get_instance
101 
102 
103 /// @brief reads the enzyme cstfile and for each block of residue residue constraints, creates a new
104 /// @brief instance of EnzConstraintParameters
105 void
107 
108  utility::io::izstream data( fname.c_str() );
109  std::istringstream line_stream;
110 
111  if ( !data ) {
112  std::cerr << "ERROR:: Unable to open constraints file: "
113  << fname << std::endl;
114  std::exit( 1 );
115  }
116  tr.Info << "read enzyme constraints from " << fname << " ...";
117 
118  EnzConstraintParametersOP parameters;
120  cst_pairs_.clear();
121  mcfi_lists_.clear();
122 
123  std::string line, key("");
124  core::Size counted_blocks(0);
125 
126  bool in_variable_block( false );
127 
128  while( !data.eof() ) {
129  key = "";
130  getline(data,line);
131  line_stream.clear();
132  line_stream.str(line);
133  line_stream >> key;
134 
135  if( key == "VARIABLE_CST::BEGIN" ){
136  counted_blocks++; // APL MOD HERE
137  in_variable_block = true;
139  }
140 
141  if( key == "VARIABLE_CST::END" ){
142 
143  if( !in_variable_block ){
144  utility_exit_with_message("Error when reading cstfile. Stray VARIABLE_CST::END tag in file.");
145  }
146  in_variable_block = false;
147  parameters = new EnzConstraintParameters(counted_blocks, restype_set_, this);
148  //parameters->set_mcfi_list( mcfil );
149  cst_pairs_.push_back( parameters );
150  mcfi_lists_.push_back( mcfil );
151  }
152 
153  if( key == "CST::BEGIN" ) {
154 
155 
156  if( !in_variable_block){
158  counted_blocks++;
159  }
160 
161 
162  if( mcfil->read_data( data ) ){
163 
164  if( !in_variable_block ){
165  parameters = new EnzConstraintParameters(counted_blocks, restype_set_, this);
166  //parameters->set_mcfi_list( mcfil );
167  cst_pairs_.push_back( parameters );
168  mcfi_lists_.push_back( mcfil );
169  }
170  }
171 
172  else{
173  utility_exit_with_message("Undefined error when reading cstfile. Something is wrong with the format (no CST::END tag maybe? ).\n");
174  }
175  }
176 
177  } // file reading
178 
179  if( in_variable_block ) utility_exit_with_message("Error when reading cstfile. VARIABLE_CST::BEGIN tag without corresponding VARIABLE_CST::END tag found.");
180 
181  tr.Info << " done, " << cst_pairs_.size() << " cst blocks were read." << std::endl;
182 
183  //if we're doing matching or building inverse rotamer trees later on,
184  //this information is necessary
186 
187 } //funtion read enzyme cst
188 
189 
190 
193 {
194 
195  runtime_assert( block <= mcfi_lists_.size() );
196 
197  return mcfi_lists_[ block ];
198 }
199 
200 
201 
202 /// @brief reads the residue numbers that the constraints will be applied to.
203 void
205  core::pose::Pose & pose,
206  bool accept_missing_blocks)
207 {
208 
209 
210  core::pose::PDBPoseMap PDB_map( pose.pdb_info()->pdb2pose() );
212 
213  std::set< Size > found_cst_blocks;
214 
215  std::istringstream line_stream;
216  std::map< Size, std::pair< utility::vector1<Size >, utility::vector1< Size > > > cst_block_to_residues;
217 
218  //basic::datacache::BasicDataCache const & pose_cache = pose.data();
219  core::pose::PDBInfoCOP pose_pdbinfo = pose.pdb_info();
220  core::pose::Remarks const & pose_remarks = pose_pdbinfo->remarks();
221  std::string line, buffer(""), tag("");
222  Size cst_block(0), counted_blocks(0);
223 
224  //std::cerr << "There are " << pose_remarks->size() << " remark lines." << std::endl;
225  for( std::vector< core::pose::RemarkInfo >::const_iterator remark_it = pose_remarks.begin(); remark_it != pose_remarks.end(); remark_it++) {
226 
227  //line_stream.clear();
228  //line_stream.str( remark_it->value );
229 
230  //std::cerr << "this remark string is: " << remark_it->value << std::endl;
231  //std::cerr << "and the number is: " << remark_it->num << std::endl;
232 
233  //line_stream >> buffer >> tag;
234  std::string remark_line( remark_it->value), resA_type(""), resB_type("");
235  int resA_num(0), resB_num(0);
236  Size pose_resnumA(0), pose_resnumB(0), ex_geom_id(0);
237  std::string resA_chain(""),resB_chain("");
238  //if( tag == "TEMPLATE"){
239  if( split_up_remark_line( remark_line, resA_chain, resA_type, resA_num, resB_chain, resB_type, resB_num, cst_block, ex_geom_id ) ){
240 
241  if( cst_block > cst_pairs_.size() ) utility_exit_with_message("The cst_block given in line:\n"+remark_line+"\n is larger than the number of blocks in the constraint file.");
242 
243  if( ex_geom_id > mcfi_lists_[ cst_block ]->num_mcfis() ) utility_exit_with_message("The external geometry ID specified for cst block "+utility::to_string( cst_block)+" is larger than the number of sub-blocks for that block in the cst file.");
244 
245  counted_blocks++;
246  cst_pairs_[ cst_block ]->set_mcfi( mcfi_lists_[ cst_block ]->mcfi( ex_geom_id ) );
247 
248  //Size resA_pose_num(0), resB_pose_num(0);
249 
250  //line_stream >> resA_chain >> resA_type >> resA_num;
251  //line_stream >> buffer >> buffer >> resB_chain >> resB_type >> resB_num >> cst_block;
252  //if( resA_type.size() == 2 ) resA_type = " " + resA_type;
253  //if( resB_type.size() == 2 ) resB_type = " " + resB_type;
254  //note: if the chain is '_', this means the pose doesn't have a chain info.
255  //we'll set the chain to ' ' to prevent a crash
256  if(resA_chain[0] == '_' ) resA_chain[0] = ' ';
257  if(resB_chain[0] == '_' ) resB_chain[0] = ' ';
258 
259  found_cst_blocks.insert( cst_block );
260  //debug output
261  //tr.Info << "remark debug " << buffer << tag << resA_chain << resA_type << resA_num;
262  //tr.Info << resB_chain << resB_type << resB_num << cst_block << std::endl;
263  if(resA_num != 0) {
264  pose_resnumA = PDB_map.find(resA_chain[0], resA_num);
265 
266  if( pose_resnumA == 0 ) utility_exit_with_message( "residue at chain "+resA_chain+" position "+utility::to_string( resA_num )+" not found in pose.");
267 
268  }
269 
270  if(resB_num != 0) {
271  pose_resnumB = PDB_map.find(resB_chain[0], resB_num);
272 
273  if( pose_resnumB == 0 ) utility_exit_with_message( "residue at chain "+resB_chain+" position "+utility::to_string( resB_num )+" not found in pose.");
274 
275  }
276 
277  // first do sanity checks for format and consistency of REMARKs with actual atom data in the pdb
278  if(cst_block == 0 || cst_block > cst_pairs_.size() ) {
279  std::cerr << "Error: catalytic map in pdb file and information in cst file don't match. Either there is no correctly formatted info given in the REMARK block, or there are more constraint REMARKS than blocks in the .cst file." << std::endl;
280  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
281  }
282  if( (resA_chain.size() != 1) || (resB_chain.size() !=1) ) {
283  std::cerr << "Error: format in pdb file header is wrong, missing chains of catalytic residues. Information readfor resA_chain is " << resA_chain << ", for resB_chain is " << resB_chain << std::endl;
284  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
285  }
286  if( ( (resA_num != 0 ) && (pose.residue(pose_resnumA).name3() != resA_type ) ) ||
287  ( (resB_num != 0 ) && (pose.residue(pose_resnumB).name3() != resB_type) ) )
288  {
289  std::cerr << "Error: residue names/positions in catalytic header map in pdb file don't match actual protein residues:" << std::endl;
290  std::cerr << "Error: residue " << pose_resnumA << " ( " << resA_chain << " " << resA_num << " ) should be " << resA_type << ", is " << ( pose_resnumA?(pose.residue(pose_resnumA).name3()):"<autofind>" ) << std::endl;
291  std::cerr << "Error: residue " << pose_resnumB << " ( " << resB_chain << " " << resB_num << " ) should be " << resB_type << ", is " << ( pose_resnumB?(pose.residue(pose_resnumB).name3()):"<autofind>" ) << std::endl;
292  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
293  }
294 
295  //then get the correct residues in the pose
296  //special feature: if res(A/B)_num is 0, all residues with 3 letter name res(A/B)_type will be added
297 
298 
299  if(resA_num != 0){
300  cst_cache->param_cache( cst_block )->template_res_cache( 1 )->set_position_in_pose( pose_resnumA );
301  }
302  if(resB_num != 0){
303  cst_cache->param_cache( cst_block )->template_res_cache( 2 )->set_position_in_pose( pose_resnumB );
304  }
305  if( resA_num == 0 || resB_num == 0){
306 
307  bool resA_missing( true ), resB_missing( true );
308  if( resA_num != 0 ) resA_missing = false;
309  if( resB_num != 0 ) resB_missing = false;
310 
311  for(Size i = 1, i_end = pose.total_residue(); i <= i_end; ++i){
312  if(resA_num == 0 && pose.residue(i).name3() == resA_type){
313  cst_cache->param_cache( cst_block )->template_res_cache( 1 )->add_position_in_pose( i );
314  resA_missing = false;
315  }
316  if(resB_num == 0 && pose.residue(i).name3() == resB_type){
317  cst_cache->param_cache( cst_block )->template_res_cache( 2 )->add_position_in_pose( i );
318  resB_missing = false;
319  }
320  }
321  //make sure that even though the respos was declared 0 in the header,
322  //at least one of the demanded type was found
323  if( resA_missing ) utility_exit_with_message("Residue with name "+resA_type+" declared in header not found in pose.");
324  if( resB_missing ) utility_exit_with_message("Residue with name "+resB_type+" declared in header not found in pose.");
325 
326  } //if one of the residue positions is given as 0 in the header
327 
328  //resA_pose_num = pose.pdb_info()->pdb2pose(resA_num, resA_chain);
329  //resB_pose_num = pose.pdb_info()->pdb2pose(resB_num, resB_chain);
330 
331  }//remark line processing done
332 
333 
334  }// end file reading
335 
336  //start to process missing blocks: try to find position of residues based on information in cst file
337  if(counted_blocks != cst_pairs_.size() ){
338 
339  for( Size i = 1; i <= cst_pairs_.size(); ++i){
340 
341  if( found_cst_blocks.find( i ) == found_cst_blocks.end() ){
342  //assuming it's mcfi 1 for now
343  cst_pairs_[ i ]->set_mcfi( mcfi_lists_[ i ]->mcfi( 1 ) );
344  bool resA_missing = !cst_pairs_[i]->nonconst_resA()->find_in_pose_if_missing_from_header( pose );
345  bool resB_missing = !cst_pairs_[i]->nonconst_resB()->find_in_pose_if_missing_from_header( pose );
346 
347  if( resA_missing || resB_missing ) {
348 
349  //make sure at least one of the residues is in the pose
350  if( !accept_missing_blocks ){
351  std::cerr << "Error: catalytic map in pdb file and information in cst file don't match, unequal number of constraints. should be " << cst_pairs_.size() << ", is " << counted_blocks << std::endl;
352  utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
353  }
354  }
355  }
356  }
357  } //if counted blocks != cst pairs size
358 
359 }// end of process pdb header info function
360 
361 
362 /// @brief prepares the class for reading in data from a pose/pdb
363 //void
364 //EnzConstraintIO::clear_pose_specific_data()
365 //{
366 // favor_native_constraints_.clear();
367 //}//clear pdb specific data function
368 
369 
370 void
372  core::pose::Pose & pose,
374 {
375  for ( core::Size block = 1; block <= cst_pairs_.size(); ++block) {
376  generate_pose_specific_data_for_block( pose, scofx, block );
377  }
378 }// end check consistency function
379 
380 
381 
382 void
384  core::pose::Pose & pose,
386  core::Size cst_block) const
387 {
388 
389  if( cst_pairs_[ cst_block]->missing_in_pose(pose) ) {
390  tr.Info << "Block " << cst_block << " wasn't found in the pose, so no constraints will be generated." << std::endl;
391  } else {
392  tr.Info << "checking cst data consistency for block " << cst_block << "... ";
393  cst_pairs_[ cst_block]->generate_pose_specific_data( pose, scofx );
394 
395  tr.Info << " done" << std::endl;
396  }
397 }
398 
399 void
401  core::pose::Pose & pose,
403  bool accept_blocks_missing_header
404 )
405 {
406  //tmp hack
408  if( !cst_cache ) protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose )->set_cst_cache( new EnzdesCstCache( this, cst_pairs_.size() ) );
409  //tmp hack over
410 
411  //in case this function gets called twice, we remove constraints from the pose
412  remove_constraints_from_pose( pose, false, false );
413 
414  //new
415  protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose )->set_cst_cache( new EnzdesCstCache( this, cst_pairs_.size() ) );
416 
417  process_pdb_header( pose, accept_blocks_missing_header );
418 
419  if(basic::options::option[basic::options::OptionKeys::enzdes::enz_debug] ) show_cst_definitions();
420 
421  tr.Info << "Generating constraints for pose... " << std::endl;
422 
423  for( core::Size block = 1; block <= cst_pairs_.size(); ++block) {
424 
426 
427  tr.Info << "Cst Block " << block << "done... " << std::endl;
428  }
429 
430  //tr.Info << std::endl << "All constraints generated and added. " << std::endl;
431 } //add_constraints_to_pose functino
432 
433 
434 void
436  core::pose::Pose & pose,
438  core::Size cst_block
439 ) const
440 {
441 
442  generate_pose_specific_data_for_block( pose, scofx, cst_block);
443 
444  //debug shit
445  //utility::vector1< core::scoring::constraints::ConstraintCOP > pcst = cst_pairs_[ cst_block - 1]->active_pose_constraints();
446  //core::Size num_to_add = pcst.size();
447  //std::cerr << "about to add " << num_to_add << " constraints for block " << cst_block << " to pose." << std::endl;
448  //debug shit over
449 
450  EnzdesCstParamCacheOP param_cache = protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose )->cst_cache()->param_cache( cst_block );
451  using namespace core::scoring::constraints;
452  ConstraintCOPs tmp = pose.add_constraints( param_cache->active_pose_constraints() );
453  param_cache->set_active_pose_constraints( tmp );
454 
455 } // add_constraints_to_pose_for_block_without_clearing_and_header_processing
456 
457 
458 void
460  core::pose::Pose & pose,
461  bool const keep_covalent,
462  bool const fail_on_constraints_missing
463 ) const
464 {
466  if( !cst_cache ) return;
467  //std::cerr << "removing constraints from pose" << std::endl;
468  //need to do this in decreasing fashion in case several constraints are covalent
469  for( core::Size block = cst_pairs_.size(); block >= 1; --block){
470  if( !cst_cache->param_cache( block )->missing_in_pose() && (! (keep_covalent && cst_pairs_[ block ]->is_covalent() )) ){
471  remove_constraints_from_pose_for_block( pose, block, fail_on_constraints_missing);
472  }
473  }
474 } //remove constraints from pose function
475 
476 
477 void
479  core::pose::Pose & pose,
480  core::Size cst_block,
481  bool const fail_on_constraints_missing
482 ) const
483 {
484 
485  bool constraints_found(false);
486  EnzdesCstParamCacheOP param_cache = protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose )->cst_cache()->param_cache( cst_block );
487  if( pose.remove_constraints( param_cache->active_pose_constraints(), true ) ){
488 
489  constraints_found = true;
490  }
491 
492  else if( fail_on_constraints_missing ){
493 
494  utility::vector1< core::scoring::constraints::ConstraintCOP > pcst = param_cache->active_pose_constraints();
495  std::cerr << "trying to remove the following " << pcst.size() << " constraints for cst block " << cst_block << "... " << std::endl;
496 
498  cst_it != pcst.end(); ++cst_it){
499  (*cst_it)->show( std::cerr );
500  }
501  utility_exit_with_message("Error: an enzdes constraint that should be in the pose got lost along the way.\n");
502 
503  }
504 
505  if( constraints_found && cst_pairs_[cst_block]->is_covalent() ){
506  cst_pairs_[cst_block]->remove_covalent_connections_from_pose( pose );
507  }
508 
509 } //remove_constraints_from_pose_for_block
510 
511 void
513  core::pose::Pose & pose,
514  core::Size pos,
515  core::Size cst_block ) const
516 {
517  protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose )->cst_cache()->param_cache( cst_block )->remove_seqpos_from_template_res( pos );
518 }
519 
520 void
522  core::pose::Pose & pose,
523  core::Size pos ) const
524 {
526  if( !cst_cache ) return;
527 
528  for( core::Size i =1; i <= cst_pairs_.size(); ++i){
529  if( cst_cache->param_cache( i )->contains_position( pos ) ) remove_position_from_template_res_for_block( pose, pos, i );
530  }
531 }
532 
533 
534 void
536  core::pose::Pose & pose,
537  core::scoring::ScoreFunctionCOP scofx ) const
538 {
539 
540  using namespace core::scoring::constraints;
541  //some precautions to avoid segfaults
543  if( !cst_cache ){
544  tr << "Notice: trying to add pregenerated enzdes constraints even though no constraints have been generated, function will have no effect... " << std::endl;
545  return;
546  }
547  //std::cerr << "adding pregenerated constraints" << std::endl;
548  utility::vector1< ConstraintCOP > all_pose_constraints = pose.constraint_set()->get_all_constraints();
549 
550  for(core::Size i = 1; i<= cst_pairs_.size(); ++i){
551  EnzdesCstParamCacheOP param_cache( cst_cache->param_cache( i ) );
552 
553  if( cst_pairs_[i]->missing_in_pose(pose) ) continue;
554 
555  if( ( ! cst_pairs_[i]->is_empty() ) && ( param_cache->active_pose_constraints().size() == 0 ) ){
556  utility_exit_with_message("trying to add pregenerated constraints to the pose even though they haven't been generated yet.");
557  }
558 
559  bool covalent_kept(false);
560 
561  utility::vector1< ConstraintCOP > & cur_active_constraints = param_cache->active_pose_constraints();
562 
563  for( utility::vector1< ConstraintCOP >::iterator cst_it = cur_active_constraints.begin();
564  cst_it != cur_active_constraints.end(); ++cst_it ){
565 
566  utility::vector1< ConstraintCOP >::iterator cst_find = find(all_pose_constraints.begin(), all_pose_constraints.end(), *cst_it);
567 
568  if( cst_find != all_pose_constraints.end() ){
569  if( ! cst_pairs_[i]->is_covalent() ){
570  tr << "WARNING: tried to add an enzdes constraint that's already in the pose. Something's a bit unclean somewhere." << std::endl;
571  }
572  else covalent_kept = true;
573  }
574  else{
575  //std::cerr << "There are a total of " << cur_active_constraints.size() << " constraints in this parameter.\n" << std::endl;
576  //std::cerr << "showing definition for a constraint with " << (*cst_it)->natoms() << " atoms... ";
577  //(*cst_it)->show( std::cerr );
578  if( ! cst_pairs_[i]->is_covalent() ) *cst_it = pose.add_constraint( *cst_it );
579  }
580 
581  }
582  if( !covalent_kept && cst_pairs_[i]->is_covalent() ) {
584  }
585 
586  } //loop over cst_pairs
587 
588 } //add pregenerated constraints function
589 
590 
591 bool
593  core::pose::Pose const & pose,
594  core::Size const seqpos ) const
595 {
597  if( !enz_obs ) return false; // get_enzdes_observer() can return NULL for const pose
598  EnzdesCstCacheCOP cst_cache( enz_obs->cst_cache() );
599  if( !cst_cache ) return false;
600  for( core::Size i = 1; i <= cst_cache->ncsts(); ++i) {
601  if( cst_cache->param_cache( i )->contains_position( seqpos ) ) return true;
602  }
603  return false;
604 }
605 
606 bool
608  core::pose::Pose const & pose,
609  core::Size const seqpos ) const
610 {
611 
612  bool to_return(false);
614  if( !enz_obs ) return false; // get_enzdes_observer() can return NULL for const pose
615  EnzdesCstCacheCOP cst_cache( enz_obs->cst_cache() );
616  if( !cst_cache ) return false;
617 
618  for( core::Size i = 1; i<= cst_pairs_.size(); ++i){
619 
620  if( cst_cache->param_cache(i)->template_res_cache( 1 )->contains_position( seqpos ) ){
621  if( cst_pairs_[i]->resA()->is_backbone() ) to_return = true;
622  else return false;
623  }
624 
625  if( cst_cache->param_cache(i)->template_res_cache( 2 )->contains_position( seqpos ) ){
626  if( cst_pairs_[i]->resB()->is_backbone() ) to_return = true;
627  else return false;
628  }
629  }
630  return to_return;
631 }
632 
633 void
635  core::pose::Pose & pose ) const
636 {
637 
639 
640  if( !(*it)->resA()->is_backbone() && !(*it)->resB()->is_backbone() ) continue;
641  if( (*it)->missing_in_pose(pose) ) continue;
642 
643  if( !(*it)->update_pdb_remarks( pose ) ) utility_exit_with_message("Error when trying to update pdb remarks.");
644  }
645 }
646 
649  core::pose::Pose const & pose,
650  core::Size const seqpos ) const
651 {
652 
654  if( !protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose )->cst_cache() ) return to_return;
655 
656  std::set< std::string > found;
657 
659 
660  std::set< std::string > res_this_param = (*it)->allowed_res_name3_at_position( pose, seqpos );
661  if( res_this_param.size() == 0 ) continue;
662  //we need to make two checks:
663  //1. are there already residues in the found set? if so, dont include anything,
664  //but remove all that are not part of the second set
665  //2. if not, the found set will become res_this_param
666  if( found.size() == 0 ) found = res_this_param;
667  else{
668  for( std::set< std::string >::iterator set_it = found.begin(); set_it != found.end(); ){
669  if( res_this_param.find( *set_it ) == res_this_param.end() ){
670  std::set< std::string >::iterator to_erase = set_it;
671  ++set_it;
672  found.erase( to_erase );
673  }
674  else ++set_it;
675  }
676  }
677  } //iterator over all params
678  for( std::set< std::string >::iterator set_it = found.begin(); set_it != found.end(); ++set_it ){
679  to_return.push_back( *set_it );
680  }
681  return to_return;
682 }
683 
684 
685 void
687 {
688  if (cst_pairs_.size() == 0) {
689  tr.Info << "No constraints have been read in." << std::endl;
690  }
691  else{
692  tr.Info << cst_pairs_.size() << " constraint blocks have been read in: " << std::endl;
693  for (utility::vector1< EnzConstraintParametersOP >::const_iterator it = cst_pairs_.begin(); it != cst_pairs_.end(); ++it) { (*(*it)).show_definitions(); }
694  }
695 }
696 
697 void
699 {
700 
702  (*it)->remap_resid( smap );
703  }
704 }
705 
706 void
708  core::pose::Pose & pose,
709  core::Size cst_block,
710  core::Size respos
711 ) const
712 {
713 
714  runtime_assert( cst_block <= cst_pairs_.size() );
715 
716  protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose )->cst_cache()->param_cache( cst_block )->set_position_for_missing_res( respos );
717 }
718 
719 void
721  core::pose::Pose & pose,
722  core::Size cst_block
723 ) const{
724  runtime_assert( cst_block <= cst_pairs_.size() );
725  protocols::toolbox::match_enzdes_util::get_enzdes_observer( pose )->cst_cache()->param_cache( cst_block)->clear_active_pose_constraints();
726 }
727 
728 
729 void
731  core::Size cst_block,
732  core::Size respos
733 )
734 {
735  runtime_assert( cst_block <= cst_pairs_.size() );
736  cst_pairs_[ cst_block ]->set_external_position_for_resA( respos );
737 }
738 
739 void
741  core::Size cst_block,
742  core::Size respos
743 )
744 {
745  runtime_assert( cst_block <= cst_pairs_.size() );
746  cst_pairs_[ cst_block ]->set_external_position_for_resB( respos );
747 }
748 
749 // migrate in second step
750 /*
751 void
752 EnzConstraintIO::setup_favor_native_constraints(
753  core::pose::Pose & pose,
754  core::pack::task::PackerTaskCOP task,
755  core::pose::Pose const & native_pose
756 )
757 {
758  using namespace basic::options;
759 
760  if( option[OptionKeys::enzdes::favor_native_res].user() ) {
761  using namespace core::scoring::constraints;
762 
763  core::Real bonus = option[OptionKeys::enzdes::favor_native_res].value();
764 
765  tr.Info << "favor_native_res: adding a bonus of " << bonus << " for native residues to pose." << std::endl;
766 
767  //safety check first
768  if( favor_native_constraints_.size() != 0 ){
769  tr.Info << "Warning: when setting up favor native constraints, there might already be some previously generated favor_native constraints in the pose, trying to remove these first." << std::endl;
770  remove_favor_native_constraints( pose );
771 
772  }
773 
774  favor_native_constraints_.clear();
775  for( core::Size i = 1; i <= pose.total_residue(); ++i){
776 
777  if( task->design_residue(i) ){
778 
779  ConstraintOP resconstraint = new ResidueTypeConstraint( native_pose, i, bonus );
780  favor_native_constraints_.push_back( resconstraint );
781 
782  }
783  }
784  favor_native_constraints_ = pose.add_constraints( favor_native_constraints_ );
785  } else if (option[ OptionKeys::in::file::pssm ].user() ) {
786  //multiple sequence aligniment (adapted from MSA app)
787 
788  using namespace core;
789  using namespace scoring;
790  using namespace constraints;
791  using namespace sequence;
792 
793  using namespace protocols;
794  using namespace constraints_additional;
795 
796  tr << " Starting MSA design " << std::endl;
797 
798  // register SequenceProfileConstraint with the ConstraintFactory so that it can be constructed from a constraint file
799  //ConstraintIO::get_cst_factory().add_type(
800  //new core::scoring::constraints::SequenceProfileConstraint( Size(), utility::vector1< id::AtomID >(), NULL ) );
801 
802  // add constraints to bias design toward a sequence profile
803  SequenceProfileOP profile = new SequenceProfile;
804  utility::file::FileName filename( option[ OptionKeys::in::file::pssm ]().front() );
805 
806  profile->read_from_file( filename );
807  profile->convert_profile_to_probs( 1 ); // was previously implicit in read_from_file()
808 
809  tr << *profile << std::endl;
810 
811  for ( Size seqpos(1), end( pose.total_residue() ); seqpos <= end; ++seqpos ) {
812  // add individual profile constraint for each residue position
813  // because of the underlying constraint implementation, this enures that the constraint is
814  // a context-independent 1-body energy, or (intra)residue constraint
815  pose.add_constraint( new core::scoring::constraints::SequenceProfileConstraint( pose, seqpos, profile ) );
816  }
817  }// else if ( option[ OptionKeys::constraints::in::file::pssm ].user() ){
818  //}
819 
820 }//setup_favor_native_constraints
821 
822 //migrate in second step
823 void
824 EnzConstraintIO::remove_favor_native_constraints(
825  core::pose::Pose & pose
826 )
827 {
828  if( !( pose.remove_constraints( favor_native_constraints_ ) ) ){
829  tr.Info << "Warning: some of the favor native constraints that were previously added to the pose are not there anymore, something's a little unclean somewhere." << std::endl;
830  }
831  favor_native_constraints_.clear();
832 }
833 */
834 
837 {
838  return cst_pairs_[ block];
839 }
840 
841 //add pose to interface
844 {
846 
847  for( Size i = 1; i <= cst_pairs_.size(); ++i){
848  if( cst_pairs_[i]->missing_in_pose( pose ) ){
849  to_return.push_back( cst_pairs_[i] );
850 
851  //runtime_assert( cst_pairs_[i]->active_pose_constraints().size() == 0 ); //old
852  }
853  }
854 
855  return to_return;
856 
857 }
858 
861 {
862  using namespace core;
863  //utility::vector1< Size > found_protein_positions;
864  //utility::vector1< Size > found_lig_positions;
866  if( !enz_obs ) return utility::vector1< Size > (); // get_enzdes_observer() can return NULL for const pose
867  EnzdesCstCacheCOP cst_cache( enz_obs->cst_cache() );
868  if( !cst_cache ) return utility::vector1< Size > ();
869 
870  return cst_cache->ordered_constrained_positions( pose );
871 
872  /*
873  for( core::Size i = 1; i <= cst_pairs_.size(); ++i ){
874 
875  for(std::map< Size, EnzCstTemplateResAtomsOP >::const_iterator resA_it = cst_cache->param_cache(i)->template_res_cache( 1 )->seqpos_map_begin(), resA_end = cst_cache->param_cache(i)->template_res_cache( 1 )->seqpos_map_end();
876  resA_it != resA_end; ++resA_it ){
877  if( pose.residue_type( resA_it->first ).is_ligand() ) {
878  if( find( found_lig_positions.begin(), found_lig_positions.end(), resA_it->first ) == found_lig_positions.end() ) {
879  found_lig_positions.push_back( resA_it->first );
880  }
881  }
882  else found_protein_positions.push_back( resA_it->first );
883  }
884 
885  for(std::map< Size, EnzCstTemplateResAtomsOP >::const_iterator resB_it = cst_cache->param_cache(i)->template_res_cache( 2 )->seqpos_map_begin(), resB_end = cst_cache->param_cache(i)->template_res_cache( 2 )->seqpos_map_end();
886  resB_it != resB_end; ++resB_it ){
887  if( pose.residue_type( resB_it->first ).is_ligand() ) {
888  if( find( found_lig_positions.begin(), found_lig_positions.end(), resB_it->first ) == found_lig_positions.end() ) {
889  found_lig_positions.push_back( resB_it->first );
890  }
891  }
892  else found_protein_positions.push_back( resB_it->first );
893  }
894 
895  }// loop over EnzConstraintParams
896 
897  for( utility::vector1< Size >::const_iterator lig_it = found_lig_positions.begin(); lig_it != found_lig_positions.end(); ++lig_it ){
898  found_protein_positions.push_back( *lig_it );
899  }
900 
901  return found_protein_positions;
902  */
903 }//ordered catalytic positions
904 
907 {
908  return mcfi_lists_.size();
909 }
910 
911 void
913 {
914  target_downstream_res_.clear();
915 
916  for( core::Size i =1; i <= mcfi_lists_.size(); ++i ){
917 
918  std::map< std::string, utility::vector1< std::string > > const &
919  alg_info( (*mcfi_lists_[i]).mcfi(1)->algorithm_inputs() );
920 
921  if ( alg_info.find( "match" ) == alg_info.end() ) target_downstream_res_.push_back( std::pair<core::Size, core::Size >(1,1) );
922  else{
923  utility::vector1< std::string > const & info( alg_info.find( "match" )->second );
924  std::pair<core::Size, core::Size > this_target(1,1);
925  for ( core::Size ll = 1; ll <= info.size(); ++ll ) {
926  std::string llstr = info[ ll ];
927  std::istringstream llstream( llstr );
928  std::string first, second;
929  llstream >> first >> second;
930  if( first == "SECONDARY_MATCH:" && second == "UPSTREAM_CST" ){
931  this_target.second = 2;
932  llstream >> this_target.first;
933  break;
934  }
935  }
936  target_downstream_res_.push_back( this_target );
937  }
938  }
939 }
940 
941 }
942 } //enzdes
943 } //protocols
944 
945