38 #include <basic/basic.hh>
44 #include <numeric/HomogeneousTransform.hh>
47 #include <utility/io/izstream.hh>
48 #include <utility/string_util.hh>
54 #include <basic/Tracer.hh>
64 #include <utility/vector1.hh>
68 static basic::Tracer
tr(
"protocols.toolbox.match_enzdes_util.MatchConstraintFileIfo");
72 namespace match_enzdes_util{
80 std::set< core::chemical::ResidueTypeCOP > & restype_subset,
85 using namespace core::chemical;
87 std::set< std::string > basename_set;
89 for(
core::Size i = 1; i <= restypes.size(); ++i ){
93 if( basename_set.find( basename ) == basename_set.end() ){
95 basename_set.insert( basename );
97 restype_subset.insert( &restype_set->name_map( basename ) );
107 tag_(tag), function_tag_(
"default" ), ideal_val_(0.0), tolerance_(0.0), periodicity_(360.0),
108 force_const_(0.0), num_steps_(0), step_size_(0.0)
117 tag_(
""), function_tag_(
"default"), ideal_val_(ideal_val), tolerance_(tolerance),
118 periodicity_(periodicity), force_const_(force_k), num_steps_(0), step_size_(0.0)
132 line_stream >> buffer;
133 if ( line_stream.fail() )
break;
134 fields.push_back( buffer );
137 if( fields.size() < 4 ){
139 tr <<
"Not enough fields detected for constraint " <<
tag_ <<
"." << std::endl;
150 std::cerr <<
"Error: illegal periodicity value of " <<
periodicity_ <<
" requested for degree of freedom " <<
tag_ <<
"." << std::endl;
151 utility_exit_with_message(
"Illegal periodicity value given. Value must be between 1.0 and 360.0 degrees.");
154 if( fields.size() > 4 ){
157 std::istringstream f5;
162 if( f5.bad() ) num_steps_ = 0;
168 if( fields[ fields.size() ] ==
"PERIODIC" )
function_tag_ =
"PERIODIC";
176 if( (
tolerance_ == 0.0 ) && (num_steps_ != 0 ) ){
180 tr <<
"WARNING: tolerance for constraint " <<
tag_ <<
" specified to be 0, yet num_steps specified to be non-0. Ignoring input and setting num_steps to 0." << std::endl;
203 std::list< core::Real > ideal_values;
207 std::set< core::Real > seen_values;
209 for(
int i = (
int) -( num_ideal_val/2) ; i <= (
int) ( num_ideal_val/2); ++i ){
213 if( !distance) val = basic::unsigned_periodic_range( val, 360.0 );
215 if( seen_values.find( val ) == seen_values.end() ){
216 ideal_values.push_back( val );
217 seen_values.insert( val );
231 tr.Debug <<
"ideal values for gsi with tag " <<
tag_ <<
", ideal_val " <<
ideal_val_ <<
", and periodicity " <<
periodicity_ <<
"are :";
233 for( std::list< core::Real >::const_iterator val_it = ideal_values.begin();
234 val_it != ideal_values.end(); ++val_it ){
236 tr.Debug << *val_it <<
", ";
242 if( !distance) val = basic::unsigned_periodic_range( val, 360.0 );
244 if( seen_values.find( val ) == seen_values.end() ){
245 samples.push_back( val );
246 seen_values.insert( val );
251 tr.Debug << std::endl <<
" the generated samples are: ";
253 for(
core::Size i = 1; i <= samples.size(); ++i ){
254 tr.Debug << samples[i] <<
", ";
256 tr.Debug << std::endl;
267 : index_( index ), is_covalent_(false),
268 dis_U1D1_( NULL ), ang_U1D2_(NULL), ang_U2D1_(NULL),
269 tor_U1D3_(NULL), tor_U3D1_(NULL), tor_U2D2_(NULL),
270 restype_set_( restype_set ), native_ (false)
287 for( EnzCstTemplateRes::RestypeToTemplateAtomsMap::const_iterator restype_it = template_res->atom_inds_for_restype_begin(), restype_end = template_res->atom_inds_for_restype_end();
288 restype_it != restype_end; ++restype_it ){
290 to_return.push_back( restype_it->first );
303 std::map< core::Size, EnzCstTemplateResOP >::const_iterator map_it =
enz_template_res_.find( which_cstres );
306 utility_exit_with_message(
"template res with code blabla not found in MatchConstraintFileInfo ");
309 return map_it->second->atom_inds_for_restype( which_template_atom, &restype );
317 std::map< core::Size, EnzCstTemplateResOP >::const_iterator map_it =
enz_template_res_.find( template_res );
320 utility_exit_with_message(
"template res with code blabla not found in MatchConstraintFileInfo ");
323 return map_it->second;
337 std::istringstream line_stream;
344 while( !data.eof() ){
350 if( comment_split[1] ==
"" )
continue;
352 line_stream.str( comment_split[1] );
357 if ( key ==
"NATIVE"){
360 else if ( key ==
"TEMPLATE::" ) {
363 if( tag ==
"ATOM_MAP:") {
365 line_stream >> map_id;
367 std::map< core::Size, EnzCstTemplateResOP >::iterator map_it =
enz_template_res_.find( map_id );
376 map_it->second->set_param_index( map_id );
379 map_it->second->read_params( line_stream );
386 else if ( key ==
"CONSTRAINT::") {
391 if( !gs_info->read_data( line_stream ) )
return false;
393 if (tag ==
"distanceAB:"){
402 else if (tag ==
"angle_A:")
ang_U1D2_ = gs_info;
404 else if (tag ==
"angle_B:")
ang_U2D1_ = gs_info;
406 else if (tag ==
"torsion_A:")
tor_U1D3_ = gs_info;
408 else if (tag ==
"torsion_AB:")
tor_U2D2_ = gs_info;
410 else if (tag ==
"torsion_B:")
tor_U3D1_ = gs_info;
413 std::cerr <<
"The following line in the cst file with key " << key <<
" was not recognized and will be ignored: " << std::endl << line << std::endl;
420 else if ( key ==
"ALGORITHM_INFO::" ) {
428 else if ( key ==
"CST::END")
return true;
430 else if ( key !=
"" ){
431 std::cerr <<
"The following line in the cst file with key " << key <<
" was not recognized and will be ignored: " << std::endl << line << std::endl;
448 for( std::map< core::Size, EnzCstTemplateResOP >::iterator map_it =
enz_template_res_.begin();
452 map_it->second->allowed_res_types();
454 std::set< core::chemical::ResidueTypeCOP > restypes_this_res;
456 for(
core::Size j = 1; j <= res_name3s.size(); ++j ) {
465 for( std::set< core::chemical::ResidueTypeCOP >::iterator set_it = restypes_this_res.begin();
466 set_it != restypes_this_res.end(); ++set_it ){
468 map_it->second->determine_atom_inds_for_restype( *set_it );
476 std::list< core::conformation::ResidueCOP >
483 core::Size const invrot_template( target_template == 1 ? 2 : 1 );
487 bool flip_exgs_upstream_downstream_samples(
false );
488 if( invrot_template == this->
upstream_res() ) flip_exgs_upstream_downstream_samples =
true;
490 std::list< core::conformation::ResidueCOP > to_return;
497 bool backbone_interaction(
false);
499 backbone_interaction =
true;
500 invrot_restypes.clear();
501 invrot_restypes.push_back( &(
restype_set_->name_map(
"ALA")) );
502 tr <<
"Only Ala inverse rotamers will be built because it is a backbone interaction." << std::endl;
504 for(
core::Size ii =1; ii <= invrot_restypes.size(); ++ii ){
509 for(
core::Size atct = 1; atct <= 3; ++atct ){
510 target_template_atom_inds[atct] = this->
template_atom_inds( target_template, atct, target_conf->type() );
511 invrot_template_atom_inds[atct] = this->
template_atom_inds( invrot_template, atct, *(invrot_restypes[ii]) );
515 for(
core::Size jj = 1; jj <= target_template_atom_inds[1].size(); ++jj ){
517 targ_ats[1] = target_template_atom_inds[1][jj]; targ_ats[2] = target_template_atom_inds[2][jj]; targ_ats[3] = target_template_atom_inds[3][jj];
518 for(
core::Size kk = 1; kk <= invrot_template_atom_inds[1].size(); ++kk ){
521 invrot_ats[1] = invrot_template_atom_inds[1][kk]; invrot_ats[2] = invrot_template_atom_inds[2][kk]; invrot_ats[3] = invrot_template_atom_inds[3][kk];
524 std::list<core::conformation::ResidueCOP > inv_rots_this_combo = this->
inverse_rotamers_against_residue( *target_conf, invrot_restypes[ii], targ_ats, invrot_ats, flip_exgs_upstream_downstream_samples, backbone_interaction );
525 to_return.splice( to_return.end(), inv_rots_this_combo );
529 tr << to_return.size() - rotcount_buffer <<
" inverse rotamers were created for restype " << invrot_restypes[ii]->name() <<
"." << std::endl;
530 rotcount_buffer = to_return.size();
535 std::list< core::conformation::ResidueCOP >
541 bool const flip_exgs_upstream_downstream_samples,
542 bool const backbone_interaction
547 std::list< core::conformation::ResidueCOP > to_return;
554 runtime_assert( rotamers.size() > 0 );
555 tr << rotamers.size() <<
" bbindependent rotamers for Residue " << rotamers[1]->type().name() <<
"." << std::endl;
559 if( backbone_interaction ){
560 runtime_assert( (rotamers.size() == 1) && (rotamers[1]->name3() ==
"ALA") );
563 core::Size inv_oat1(0), inv_oat2(0), inv_oat3(0);
564 rotamers[1]->select_orient_atoms( inv_oat1, inv_oat2, inv_oat3 );
567 for(
core::Size rotcount(1); rotcount <= rotamers.size(); ++rotcount ){
569 invrot_conformers[ rotcount ].initialize_from_residue( invrot_ats[1], invrot_ats[2], invrot_ats[3], inv_oat1, inv_oat2, inv_oat3, *(rotamers[rotcount]));
576 exgs.
set_dis_D1D2( invrot_conformers[1].atom1_atom2_distance() );
577 exgs.
set_dis_D2D3( invrot_conformers[1].atom2_atom3_distance() );
578 exgs.
set_ang_D1D2D3( invrot_conformers[1].atom1_atom2_atom3_angle() );
582 HTReal ht_start( target_conf.
xyz(target_ats[3]), target_conf.
xyz(target_ats[2]), target_conf.
xyz(target_ats[1]) );
598 for(
core::Size rotcount(1); rotcount <= rotamers.size(); ++rotcount ){
600 for(
core::Size atm = 1; atm <= rot->natoms(); ++atm ){
601 rot->set_xyz( atm, invrot_conformers[rotcount].coordinate_in_D3_frame( atm, ht_nn ) );
603 to_return.push_back( rot );
634 dummy_pose.
set_phi( 1, -60.0 );
643 utility::io::izstream & data
649 if( ( tag !=
"match") && ( tag !=
"match_positions" ) && ( tag !=
"test") && ( tag !=
"invrot_tree" ) ){
650 utility_exit_with_message(
"Tag "+tag+
" not a legal option for ALGORITHM_INFO block.");
654 tr <<
"Error: tag " << tag <<
" was found twice in the same cstfile block." << std::endl;
660 while( !data.eof() ){
667 if( utility::trimmed_compare( line,
"ALGORITHM_INFO::END") ){
669 if( alg_strings.size() != 0 ){
675 else tr <<
"WARNING: ALGORITHM_INFO block for " << tag <<
" seemed to contain no information." << std::endl;
682 if( comment_split[1] !=
"" ) alg_strings.push_back( comment_split[1] );
686 tr <<
"Error, when reading algorithm info block with tag " << tag <<
", no ALGORITHM_INFO::END line was found." << std::endl;
704 else tags_undefined_gsi.push_back(
"distanceAB:" );
707 else tags_undefined_gsi.push_back(
"angle_A:" );
710 else tags_undefined_gsi.push_back(
"angle_B:" );
713 else tags_undefined_gsi.push_back(
"torsion_A:" );
716 else tags_undefined_gsi.push_back(
"torsion_AB:" );
719 else tags_undefined_gsi.push_back(
"torsion_B:" );
721 if( tags_undefined_gsi.size() != 0 ){
723 tr <<
"WARNING: could not create external geom sampler from file input because not all 6 necessary degrees of freedom are specified.\n The following DOFs are missing specifications: ";
725 for(
core::Size i = 1; i <= tags_undefined_gsi.size(); ++i ){
726 tr << tags_undefined_gsi[i] <<
", ";
728 tr <<
"." << std::endl;
742 : restype_set_( restype_set )
763 if( mcfi->read_data( data ) ){
765 mcfi->process_data();
781 std::map< core::chemical::ResidueTypeCOP, utility::vector1< MatchConstraintFileInfoCOP > >::const_iterator mcfi_it =
mcfis_for_restype_.find( restype );
784 utility_exit_with_message(
" could not find mcfi list for given restype" );
787 return mcfi_it->second;
791 std::list< core::conformation::ResidueCOP >
796 std::list< core::conformation::ResidueCOP > to_return;
798 if(
mcfis_[i]->num_enz_cst_template_res() != 2 ){
799 tr <<
"Can't create inverse rotamers for mcfi " << i <<
" because it has more or less than 2 template res." << std::endl;
803 if( std::find(
mcfis_[i]->allowed_res_name3s( target_template ).begin(),
mcfis_[i]->allowed_res_name3s( target_template ).
end(), target_conf->name3() ) ==
mcfis_[i]->allowed_res_name3s( target_template ).end() ){
804 tr <<
"Can't create inverse rotamers for mcfi " << i <<
" because it doesn't contain target template for residue " << target_conf->name3() <<
"." << std::endl;
808 to_return.splice( to_return.end(), mcfi_invrots );
823 gly_vec.push_back(
"GLY");
825 std::set< core::chemical::ResidueTypeCOP > restype_temp_set;
829 bool is_backbone(
mcfis_[i]->is_backbone(
mcfis_[i]->upstream_res() ) );
835 std::set< core::chemical::ResidueTypeCOP > restypes_this_mcfi;
837 for(
core::Size j = 1; j <= res_name3s.size(); ++j ) {
848 for( std::set< core::chemical::ResidueTypeCOP >::iterator set_it = restypes_this_mcfi.begin();
849 set_it != restypes_this_mcfi.end(); ++set_it ){
852 std::map< core::chemical::ResidueTypeCOP, utility::vector1< MatchConstraintFileInfoCOP > >::iterator res_mcfi_it =
mcfis_for_restype_.find( *set_it );
864 res_mcfi_it->second.push_back(
mcfis_[i] );
867 if( restype_temp_set.find( *set_it ) == restype_temp_set.end() ){
868 restype_temp_set.insert( *set_it );
877 for( std::set< core::chemical::ResidueTypeCOP >::iterator set_it = restype_temp_set.begin();
878 set_it != restype_temp_set.end(); ++set_it ){