45 #include <basic/options/option.hh>
49 #include <utility/io/izstream.hh>
50 #include <utility/string_util.hh>
56 #include <basic/Tracer.hh>
60 #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
62 #include <utility/vector1.hh>
68 static basic::Tracer
tr(
"protocols.toolbox.match_enzdes_util.EnzConstraintIO");
72 namespace match_enzdes_util {
89 using namespace core::chemical;
94 generic_instance_->read_enzyme_cstfile( basic::options::option[basic::options::OptionKeys::enzdes::cstfile]);
98 return &(*generic_instance_);
108 utility::io::izstream data( fname.c_str() );
109 std::istringstream line_stream;
112 std::cerr <<
"ERROR:: Unable to open constraints file: "
113 << fname << std::endl;
116 tr.Info <<
"read enzyme constraints from " << fname <<
" ...";
126 bool in_variable_block(
false );
128 while( !data.eof() ) {
132 line_stream.str(line);
135 if( key ==
"VARIABLE_CST::BEGIN" ){
137 in_variable_block =
true;
141 if( key ==
"VARIABLE_CST::END" ){
143 if( !in_variable_block ){
144 utility_exit_with_message(
"Error when reading cstfile. Stray VARIABLE_CST::END tag in file.");
146 in_variable_block =
false;
153 if( key ==
"CST::BEGIN" ) {
156 if( !in_variable_block){
162 if( mcfil->read_data( data ) ){
164 if( !in_variable_block ){
173 utility_exit_with_message(
"Undefined error when reading cstfile. Something is wrong with the format (no CST::END tag maybe? ).\n");
179 if( in_variable_block ) utility_exit_with_message(
"Error when reading cstfile. VARIABLE_CST::BEGIN tag without corresponding VARIABLE_CST::END tag found.");
181 tr.Info <<
" done, " <<
cst_pairs_.size() <<
" cst blocks were read." << std::endl;
206 bool accept_missing_blocks)
213 std::set< Size > found_cst_blocks;
215 std::istringstream line_stream;
222 Size cst_block(0), counted_blocks(0);
225 for( std::vector< core::pose::RemarkInfo >::const_iterator remark_it = pose_remarks.begin(); remark_it != pose_remarks.end(); remark_it++) {
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);
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 ) ){
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.");
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.");
256 if(resA_chain[0] ==
'_' ) resA_chain[0] =
' ';
257 if(resB_chain[0] ==
'_' ) resB_chain[0] =
' ';
259 found_cst_blocks.insert( cst_block );
264 pose_resnumA = PDB_map.find(resA_chain[0], resA_num);
266 if( pose_resnumA == 0 ) utility_exit_with_message(
"residue at chain "+resA_chain+
" position "+utility::to_string( resA_num )+
" not found in pose.");
271 pose_resnumB = PDB_map.find(resB_chain[0], resB_num);
273 if( pose_resnumB == 0 ) utility_exit_with_message(
"residue at chain "+resB_chain+
" position "+utility::to_string( resB_num )+
" not found in pose.");
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__);
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__);
286 if( ( (resA_num != 0 ) && (pose.
residue(pose_resnumA).
name3() != resA_type ) ) ||
287 ( (resB_num != 0 ) && (pose.
residue(pose_resnumB).
name3() != resB_type) ) )
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__);
300 cst_cache->param_cache( cst_block )->template_res_cache( 1 )->set_position_in_pose( pose_resnumA );
303 cst_cache->param_cache( cst_block )->template_res_cache( 2 )->set_position_in_pose( pose_resnumB );
305 if( resA_num == 0 || resB_num == 0){
307 bool resA_missing(
true ), resB_missing(
true );
308 if( resA_num != 0 ) resA_missing =
false;
309 if( resB_num != 0 ) resB_missing =
false;
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;
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;
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.");
341 if( found_cst_blocks.find( i ) == found_cst_blocks.end() ){
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 );
347 if( resA_missing || resB_missing ) {
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__);
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;
392 tr.Info <<
"checking cst data consistency for block " << cst_block <<
"... ";
393 cst_pairs_[ cst_block]->generate_pose_specific_data( pose, scofx );
395 tr.Info <<
" done" << std::endl;
403 bool accept_blocks_missing_header
419 if(basic::options::option[basic::options::OptionKeys::enzdes::enz_debug] )
show_cst_definitions();
421 tr.Info <<
"Generating constraints for pose... " << std::endl;
427 tr.Info <<
"Cst Block " << block <<
"done... " << std::endl;
451 using namespace core::scoring::constraints;
453 param_cache->set_active_pose_constraints( tmp );
461 bool const keep_covalent,
462 bool const fail_on_constraints_missing
466 if( !cst_cache )
return;
470 if( !cst_cache->param_cache( block )->missing_in_pose() && (! (keep_covalent &&
cst_pairs_[ block ]->is_covalent() )) ){
481 bool const fail_on_constraints_missing
485 bool constraints_found(
false);
489 constraints_found =
true;
492 else if( fail_on_constraints_missing ){
495 std::cerr <<
"trying to remove the following " << pcst.size() <<
" constraints for cst block " << cst_block <<
"... " << std::endl;
498 cst_it != pcst.end(); ++cst_it){
499 (*cst_it)->show( std::cerr );
501 utility_exit_with_message(
"Error: an enzdes constraint that should be in the pose got lost along the way.\n");
505 if( constraints_found &&
cst_pairs_[cst_block]->is_covalent() ){
506 cst_pairs_[cst_block]->remove_covalent_connections_from_pose( pose );
526 if( !cst_cache )
return;
540 using namespace core::scoring::constraints;
544 tr <<
"Notice: trying to add pregenerated enzdes constraints even though no constraints have been generated, function will have no effect... " << std::endl;
553 if(
cst_pairs_[i]->missing_in_pose(pose) )
continue;
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.");
559 bool covalent_kept(
false);
564 cst_it != cur_active_constraints.end(); ++cst_it ){
568 if( cst_find != all_pose_constraints.end() ){
570 tr <<
"WARNING: tried to add an enzdes constraint that's already in the pose. Something's a bit unclean somewhere." << std::endl;
572 else covalent_kept =
true;
582 if( !covalent_kept &&
cst_pairs_[i]->is_covalent() ) {
597 if( !enz_obs )
return false;
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;
612 bool to_return(
false);
614 if( !enz_obs )
return false;
616 if( !cst_cache )
return false;
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;
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;
640 if( !(*it)->resA()->is_backbone() && !(*it)->resB()->is_backbone() )
continue;
641 if( (*it)->missing_in_pose(pose) )
continue;
643 if( !(*it)->update_pdb_remarks( pose ) ) utility_exit_with_message(
"Error when trying to update pdb remarks.");
656 std::set< std::string > found;
660 std::set< std::string > res_this_param = (*it)->allowed_res_name3_at_position( pose, seqpos );
661 if( res_this_param.size() == 0 )
continue;
666 if( found.size() == 0 ) found = res_this_param;
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;
672 found.erase( to_erase );
678 for( std::set< std::string >::iterator set_it = found.begin(); set_it != found.end(); ++set_it ){
679 to_return.push_back( *set_it );
689 tr.Info <<
"No constraints have been read in." << std::endl;
692 tr.Info <<
cst_pairs_.size() <<
" constraint blocks have been read in: " << std::endl;
702 (*it)->remap_resid( smap );
714 runtime_assert( cst_block <=
cst_pairs_.size() );
724 runtime_assert( cst_block <=
cst_pairs_.size() );
735 runtime_assert( cst_block <=
cst_pairs_.size() );
736 cst_pairs_[ cst_block ]->set_external_position_for_resA( respos );
745 runtime_assert( cst_block <=
cst_pairs_.size() );
746 cst_pairs_[ cst_block ]->set_external_position_for_resB( respos );
862 using namespace core;
870 return cst_cache->ordered_constrained_positions( pose );
918 std::map< std::string, utility::vector1< std::string > >
const &
919 alg_info( (*
mcfi_lists_[i]).mcfi(1)->algorithm_inputs() );
921 if ( alg_info.find(
"match" ) == alg_info.end() )
target_downstream_res_.push_back( std::pair<core::Size, core::Size >(1,1) );
924 std::pair<core::Size, core::Size > this_target(1,1);
925 for (
core::Size ll = 1; ll <= info.size(); ++ll ) {
927 std::istringstream llstream( llstr );
929 llstream >> first >> second;
930 if( first ==
"SECONDARY_MATCH:" && second ==
"UPSTREAM_CST" ){
931 this_target.second = 2;
932 llstream >> this_target.first;