30 #include <basic/options/option.hh>
36 #include <utility/string_util.hh>
42 #include <basic/Tracer.hh>
47 #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
50 #include <utility/vector1.hh>
54 static basic::Tracer
tr(
"protocols.toolbox.match_enzdes_util.EnzCstTemplateRes");
58 namespace match_enzdes_util {
78 std::vector< core::id::AtomID > & atomid_vec
81 for( std::vector< core::id::AtomID >::iterator vec_it = atomid_vec.begin();
82 vec_it != atomid_vec.end(); ++vec_it ){
85 if( newpos == 0 ) utility_exit_with_message(
"A catalytic residue is apparently missing from the pose");
95 ) : rb_minimizable_(true), is_backbone_(false),
96 identical_tag_found_(false), corresponding_res_block_(0),
97 corresponding_res_num_in_block_(0),
98 restype_set_(src_restype_set), enz_io_param_( NULL )
108 rb_minimizable_(true), is_backbone_(false),
109 identical_tag_found_(false), corresponding_res_block_(0),
110 corresponding_res_num_in_block_(0),
111 restype_set_(src_restype_set), enz_io_param_( src_enzio_param)
123 atom1_(other->atom1_),
124 atom2_(other->atom2_),
125 atom3_(other->atom3_),
126 at1_type_(other->at1_type_),
127 at2_type_(other->at2_type_),
128 at3_type_(other->at3_type_),
129 allowed_res_types_(other->allowed_res_types_),
130 atom_inds_for_restype_( other->atom_inds_for_restype_),
131 rb_minimizable_( other->rb_minimizable_ ),
132 is_backbone_( other->is_backbone_ ),
133 respos_from_external_(other->respos_from_external_),
134 identical_tag_found_(other->identical_tag_found_),
135 corresponding_res_block_(other->corresponding_res_block_),
136 corresponding_res_num_in_block_(other->corresponding_res_num_in_block_),
137 restype_set_(other->restype_set_),
138 enz_io_param_(new_ref_param),
139 param_index_(other->param_index_)
147 using namespace core::chemical;
154 std::vector< std::string > allowed_3res_raw;
161 if ( tag ==
"atom_name:") {
163 line_stream >> a1 >> a2 >> a3 ;
168 }
else if (tag ==
"atom_type:") {
170 }
else if (tag ==
"residue1:") {
171 line_stream >> allowed_1res_raw;
172 }
else if (tag ==
"residue3:") {
173 while(!line_stream.fail()) { line_stream >> buffer; allowed_3res_raw.push_back(buffer);}
174 }
else if (tag ==
"identical:") {
177 }
else if (tag ==
"seqpos:"){
178 while( !line_stream.fail() ){
179 line_stream >> size_buffer;
188 std::cerr <<
"Line in cstfile specifying template residue with tag " << tag <<
" was not recognized and will be ignored. " << std::endl;
198 for (std::vector< std::string >::iterator it = allowed_3res_raw.begin(); it != allowed_3res_raw.end(); ++it) {
199 if( it->size() == 2 ) *it =
" " + *it;
204 utility_exit_with_message(
"Error in cstfile: Residue with 3-letter code "+*it+
" is unknown.");
208 for(
Size ii = 0; ii != allowed_1res_raw.size(); ii++){
215 utility_exit_with_message(
"Unexpected error in program: Residue "+cur_res_name3+
" is unknown. ResidueTypeSet setup seems to not have worked properly.");
221 utility_exit_with_message(
"Error in cstfile: Residue with one letter code "+ fock +
" is unknown.");
237 using namespace core::chemical;
239 tr.Info <<
"Parameters read for template residue: atom ids are :";
241 tr.Info <<
", first atom name is " <<
at1_type_ <<
" and allowed residues are: ";
243 tr.Info << *res_it <<
", ";
245 tr.Info << std::endl ;
253 using namespace core::chemical;
257 if(template_cache->seqpos_map_.size() == 0){
258 std::cerr <<
"Error: no residues for this template." << std::endl;
259 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
264 if( template_cache->pose_data_uptodate_ ==
true )
return;
268 for (std::map< Size, EnzCstTemplateResAtomsOP >::iterator respos_it = template_cache->seqpos_map_.begin(); respos_it != template_cache->seqpos_map_.end(); ++respos_it){
277 std::cerr <<
"Error: residue " << pose.
residue( respos_it->first).
name3() << respos_it->first <<
"found in pdb header is not allowed by data in cstfile." << std::endl;
278 std::cerr <<
"Allowed restypes:";
280 std::cerr <<
" " << *iter;
282 std::cerr << std::endl;
283 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
287 std::map< core::chemical::ResidueTypeCOP, utility::vector1< utility::vector1< core::Size > > >::iterator res_aid_it =
atom_inds_for_restype_.find( cur_res );
294 for(
core::Size at1_ct = 1; at1_ct <= res_aid_it->second[1].size(); ++at1_ct ){
296 respos_it->second->atom1_.push_back( at1id );
300 for(
core::Size at2_ct = 1; at2_ct <= res_aid_it->second[2].size(); ++at2_ct ){
302 respos_it->second->atom2_.push_back( at2id );
307 for(
core::Size at3_ct = 1; at3_ct <= res_aid_it->second[3].size(); ++at3_ct ){
309 respos_it->second->atom3_.push_back( at3id );
315 template_cache->pose_data_uptodate_ =
true;
326 std::map< Size, EnzCstTemplateResAtomsOP >::const_iterator at_it = template_cache->seqpos_map_.find( seqpos );
328 if( at_it == template_cache->seqpos_map_.end() ){
329 utility_exit_with_message(
"Error: could not find template atoms in EnzCstTemplateRes.\n");
332 return at_it->second;;
349 if( template_cache->seqpos_map_.size() != 0 ){
350 utility_exit_with_message(
"Error: function find_in_pose_... was called even though there is stuff in the respos_map.\n");
357 template_cache->add_position_in_pose( *ex_it );
359 template_cache->not_in_pose_ =
false;
377 for( std::map< Size, EnzCstTemplateResAtomsOP >::const_iterator pos_it = corresponding_res_cache->seqpos_map_begin();
378 pos_it != corresponding_res_cache->seqpos_map_end(); ++pos_it ){
379 template_cache->add_position_in_pose( pos_it->first );
382 if( template_cache->seqpos_map_.size() == 0 )
return false;
384 template_cache->not_in_pose_ =
false;
397 if( found_positions.size() == 1){
398 template_cache->add_position_in_pose( found_positions[1] );
399 tr <<
"Found residue " << pose.
residue( found_positions[1] ).
name3() <<
" for CstBlock " <<
enz_io_param_->cst_block() <<
" without REMARK line in pose at position " << found_positions[1] <<
"." << std::endl;
400 template_cache->not_in_pose_ =
false;
436 if( newpos == 0 ) utility_exit_with_message(
"A catalytic residue is apparently missing from the pose");
438 respos_from_external_[i] = newpos;
447 Size natoms = restype->natoms();
454 at1_ids.push_back( restype->atom_index(
atom1_[i]) );
457 at2_ids.push_back( restype->atom_index(
atom2_[i]) );
461 at3_ids.push_back( restype->atom_index(
atom3_[i]) );
472 for(
Size ii = 1; ii <= natoms; ii++){
476 if(basic::options::option[basic::options::OptionKeys::enzdes::enz_debug] ) {
477 tr.Info <<
"Adding atom " << ii <<
" with name " << at1type.
name() <<
" for restype " << restype->name() <<
" to atom1 vector." << std::endl;
480 at1_ids.push_back( ii );
486 if(at1_ids.size() == 0 ) {
487 std::cerr <<
"Error: ResidueType " << restype->name() <<
" does not have an atom of type " <<
at1_type_ << std::endl;
488 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
495 Size id_firstbase = restype->atom_base( *at_it );
496 Size id_secondbase = restype->atom_base( id_firstbase );
501 if( ( *at_it == 1) && ( id_firstbase == 2 ) && (id_secondbase == 1 ) ) id_secondbase = 3;
502 else if( ( *at_it == 2) && ( id_firstbase == 1) && (id_secondbase == 2 ) ) id_secondbase = 3;
506 if( restype->name3() ==
"HIS" && restype->atom_name( *at_it ) ==
" ND1"){
507 id_secondbase = restype->atom_index(
" CD2");
510 at2_ids.push_back( id_firstbase );
511 at3_ids.push_back( id_secondbase );
520 std::cerr <<
"Error: cstfile did not specify any atoms for Residue " << restype->name3() <<
"." << std::endl;
521 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
526 at_ids.push_back( at1_ids );
527 at_ids.push_back( at2_ids );
528 at_ids.push_back( at3_ids );
548 if( template_atom == 1 ){
553 else if( template_atom == 2 ){
558 else if( template_atom == 3 ){
563 else utility_exit_with_message(
"When trying to find template_atom atom_ids for restype, illegal parameter was passed in for the template_atom. this has to be either 1,2, or 3" );
571 return template_atoms[ template_atom ];
583 if( res1_it ==
atom_inds_for_restype_.end() ) utility_exit_with_message(
"Residue of type "+res1.
type().
name()+
" is not part of EnzCstTemplateRes.");
584 if( res2_it ==
atom_inds_for_restype_.end() ) utility_exit_with_message(
"Residue of type "+res2.
type().
name()+
" is not part of EnzCstTemplateRes.");
591 if( res1_at_ids[1].
size() != res2_at_ids[1].
size() )
return false;
593 for(
core::Size i = 1; i <= res1_at_ids[1].size(); ++i){
595 core::Real smallest_large_deviation_this_set( sqdist_cutoff + 1.0 );
599 for(
core::Size j = 1; j <= res2_at_ids[1].size(); ++j ){
600 core::Real large_deviation_this_pair( res1.
atom( res1_at_ids[1][i] ).
xyz().distance_squared( res2.
atom( res2_at_ids[1][j] ).
xyz() ) );
602 core::Real atom2_deviation( res1.
atom( res1_at_ids[2][i] ).
xyz().distance_squared( res2.
atom( res2_at_ids[2][j] ).
xyz() ) );
603 if( atom2_deviation > large_deviation_this_pair ) large_deviation_this_pair = atom2_deviation;
605 core::Real atom3_deviation( res1.
atom( res1_at_ids[3][i] ).
xyz().distance_squared( res2.
atom( res2_at_ids[3][j] ).
xyz() ) );
607 if( atom3_deviation > large_deviation_this_pair ) large_deviation_this_pair = atom3_deviation;
609 if( large_deviation_this_pair < smallest_large_deviation_this_set ) smallest_large_deviation_this_set = large_deviation_this_pair;
612 if( smallest_large_deviation_this_set > sqdist_cutoff )
return false;
631 utility_exit_with_message(
"Cstfile has wrong format: 'identical' tag for Cstblock "+utility::to_string(
enz_io_param_->cst_block() ) +
" not formatted properly.\n");
635 utility_exit_with_message(
"Cstfile has wrong format: 'identical' tag for Cstblock "+utility::to_string(
enz_io_param_->cst_block() ) +
" is referring to a block of higher number. Please rewrite Cstfile such that identity tags only refer to blocks of higher numbers.\n");
643 else residue_names_to_match = corresponding_pair->resB()->allowed_res_types();
648 if( resfind == residue_names_to_match.end() ){
649 utility_exit_with_message(
"Error in cstfile 'identical' tag for Cstblock "+utility::to_string(
enz_io_param_->cst_block() ) +
" Allowed residue types for this cst block is not identical to the allowed residue types for the other cst_block.\n");