33 #include <basic/datacache/BasicDataCache.hh>
35 #include <basic/datacache/CacheableString.hh>
43 #include <basic/Tracer.hh>
49 #include <basic/options/keys/enzdes.OptionKeys.gen.hh>
50 #include <basic/options/keys/in.OptionKeys.gen.hh>
51 #include <basic/options/option.hh>
58 #include <basic/options/keys/docking.OptionKeys.gen.hh>
61 #include <utility/pointer/ReferenceCount.hh>
62 #include <utility/string_util.hh>
64 #include <boost/foreach.hpp>
65 #define foreach BOOST_FOREACH
69 #include <utility/vector1.hh>
78 static basic::Tracer
tr(
"protocols.enzdes.enzdes_util");
87 if( !enz_obs)
return false;
89 if( !cst_cache )
return false;
90 for(
core::Size i = 1; i <= cst_cache->ncsts(); ++i) {
91 if( cst_cache->param_cache( i )->contains_position( seqpos ) )
return true;
101 using namespace core;
107 if( cst_cache ) to_return = cst_cache->ordered_constrained_positions( pose );
110 if( to_return.size() == 0 ){
126 using namespace core::scoring;
158 runtime_assert( input_poses.size() > 0 );
159 pose = input_poses[1];
164 if( input_poses.size() > 1 ){
165 tr <<
"PDB " << filename <<
" is a multimodel pdb containing " << input_poses.size() <<
" models." << std::endl;
168 for(
core::Size i = 2; i <= input_poses.size(); ++i ){
169 for(
core::Size j = 1; j <= input_poses[i].total_residue(); ++j){
170 core::Size pdbres( input_poses[i].pdb_info()->number( j ) );
171 char pdbchain( input_poses[i].pdb_info()->chain( j ) );
172 char pdbicode( input_poses[i].pdb_info()->icode( j ) );
173 core::Size orig_seqpos( pose.pdb_info()->pdb2pose( pdbchain, pdbres, pdbicode ) );
174 if( orig_seqpos > 0 ) {
176 newres->seqpos( orig_seqpos );
177 newres->chain( pose.residue( orig_seqpos ).chain() );
178 add_residue_confs[ orig_seqpos ].push_back( newres );
182 for(
core::Size i = 1; i <= pose.total_residue(); ++i ){
183 if( add_residue_confs[i].
size() > 0 ){
184 if( pose.residue(i).is_ligand() ){
185 enz_obs->set_rigid_body_confs_for_lig( i, add_residue_confs[i] );
186 tr <<
"For ligand at seqpos " << i <<
", " << add_residue_confs[i].size() <<
" additional rigid body locations were read in." << std::endl;
193 if( basic::options::option[basic::options::OptionKeys::enzdes::additional_packing_ligand_rb_confs] > 0 ){
194 GenerateStoredRBConfs rb_generator( basic::options::option[basic::options::OptionKeys::enzdes::additional_packing_ligand_rb_confs],
false );
195 rb_generator.
apply( pose );
206 if( min_number_continuous_trues > the_vector.size() ){
207 utility_exit_with_message(
"ridiculous. continuous region is requested to be longer than the actual vector. go play in traffic.\n");
212 bool in_cont_region =
false;
215 for(
core::Size i = 1; i <= the_vector.size(); ++i){
217 if( ( ! in_cont_region ) && (the_vector[ i ]==
true) ) {
219 in_cont_region =
true;
223 if ( in_cont_region && (the_vector[ i ]==
false ) ){
224 continuous_regions.push_back( std::pair< core::Size, core::Size > ( last_cont_begin, (i - 1) ));
225 in_cont_region =
false;
230 if( in_cont_region ) continuous_regions.push_back( std::pair< core::Size, core::Size > (last_cont_begin, the_vector.size() ) );
232 if( continuous_regions.size() == 0 ){
233 utility_exit_with_message(
"The passed in vector doesn't have a single element set to true.\n");
236 for(
core::Size j = 1; j<= continuous_regions.size(); ++j){
237 std::pair< core::Size, core::Size > & cur_region = continuous_regions[j];
240 if( cur_region.second - cur_region.first + 1 < min_number_continuous_trues ){
243 core::Size to_fill = min_number_continuous_trues - ( cur_region.second - cur_region.first + 1 );
245 core::Size to_fill_each_side = (to_fill / 2) + 1;
248 core::Size prev_region_first(1), next_region_second( the_vector.size () );
250 if( j == 1 ) left_gap = cur_region.first - 1;
252 left_gap = cur_region.first - continuous_regions[ j - 1 ].second - 1;
253 prev_region_first = continuous_regions[ j - 1 ].first;
256 if( j == continuous_regions.size() ) right_gap = the_vector.size() - cur_region.second;
258 right_gap = continuous_regions[ j + 1 ].first - cur_region.second - 1;
259 next_region_second = continuous_regions[ j + 1 ].second;
263 core::Size cur_region_tmp_first = cur_region.first - to_fill_each_side;
264 core::Size cur_region_tmp_second = cur_region.second + to_fill_each_side;
266 for(
core::Size k = 1; k <= to_fill_each_side; ++k ){
268 if( k <= left_gap ) {
269 the_vector[ cur_region.first - k ] =
true;
273 if( j == 1 )cur_region_tmp_first = 1;
275 else cur_region_tmp_first = continuous_regions[ j -1 ].second + 1;
278 if( ((cur_region.second + k - 1 ) - prev_region_first + 1) >= min_number_continuous_trues){
279 cur_region_tmp_second = cur_region.second + k - 1;
285 else if ( ((cur_region.second + k - 1 ) - prev_region_first + 1) >= min_number_continuous_trues){
286 cur_region_tmp_second = cur_region.second + k - 1;
290 if( k <= right_gap ) {
291 the_vector[ cur_region.second + k ] =
true;
294 if( k == right_gap ) {
295 if( j == continuous_regions.size() ) cur_region_tmp_second = the_vector.size();
296 else cur_region_tmp_second = continuous_regions[ j + 1 ].first - 1;
298 if( (next_region_second - (cur_region.first - k ) + 1 ) >= min_number_continuous_trues){
299 cur_region_tmp_first = (cur_region.first - k );
305 else if( (next_region_second - (cur_region.first - k ) + 1 ) >= min_number_continuous_trues){
306 cur_region_tmp_first = (cur_region.first - k );
311 cur_region.first = cur_region_tmp_first;
312 cur_region.second = cur_region_tmp_second;
329 using namespace core::pack::task;
331 if( orig_task.
total_residue() != pose.
total_residue() ) utility_exit_with_message(
"old task and pose don't have same number of residues.");
333 PackerTaskOP mod_task = TaskFactory::create_packer_task( pose );
334 mod_task->initialize_from_command_line();
340 mod_task->nonconst_residue_task( i ).append_rotamer_operation( *rot_it );
343 mod_task->nonconst_residue_task( i ).append_rotamerset_operation( *rotset_it );
353 keep_aas[ (*res_it)->aa() ] =
true;
358 mod_task->nonconst_residue_task(i).restrict_absent_canonical_aas( keep_aas );
364 mod_task->set_IGEdgeReweights()->add_reweighter( *it );
375 if( !enz_obs )
return NULL;
377 if( !enzcache )
return NULL;
378 return enzcache->enzcst_io();
390 for(
core::Size i = 0; i < remarks.size(); ++i ){
392 std::string chainA(
""), chainB(
""), resA(
""), resB(
"");
394 int pdbposA(0), pdbposB(0);
396 if( cst_block == geomcst )
continue;
398 newremarks.push_back( remarks[i] );
400 pose.
pdb_info()->remarks( newremarks );
415 for(
core::Size i(1); i <= cstcache->ncsts(); ++i){
418 std::string chainA(
""), chainB(
""), resA(
""), resB(
"");
419 int pdbposA(0), pdbposB(0), seqposA(0), seqposB(0);
421 if( param_cache.
template_res_cache_size() != 2 ) utility_exit_with_message(
"Can't build a remark line from a param cache that does not have 2 template res saved.");
422 if( (param_cache.
template_res_cache(1)->seqpos_map_size() != 1 ) || (param_cache.
template_res_cache(2)->seqpos_map_size() != 1 ) ) utility_exit_with_message(
"Can't build a remark line from a templateres cahce that does not have 1 position saved.");
426 chainA = pose.
pdb_info()->chain( seqposA );
427 chainB = pose.
pdb_info()->chain( seqposB );
428 pdbposA = pose.
pdb_info()->number( seqposA );
429 pdbposB = pose.
pdb_info()->number( seqposB );
437 newremarks.push_back( ri );
442 for(
core::Size i = 0; i < remarks.size(); ++i ){
444 std::string chainA(
""), chainB(
""), resA(
""), resB(
"");
446 int pdbposA(0), pdbposB(0);
450 pose.
pdb_info()->remarks( newremarks );
458 using namespace core::pose::datacache;
460 std::string outtag = pose.
data().get_const_ptr< basic::datacache::CacheableString >( CacheableDataType::JOBDIST_OUTPUT_TAG )->
str();
470 if( it->size() != 4 )
continue;
485 pdb_matches.push_back( cand_str );
509 if( pdb_matches.size() == 0 ){
510 std::cerr <<
"protocols/enzdes/enzdes_util: WARNING: string " << outtag <<
"does not seem to contain a pdb code, returning N/A. " << std::endl;
511 pdb_matches.push_back(
"N/A" );
514 if( pdb_matches.size() > 1 ){
515 tr <<
"WARNING WARNING: in tag " << outtag <<
", more than 1 pdbcode like pattern has been identified. assuming the first one (" << pdb_matches[1] <<
") is the correct one." << std::endl;
518 return pdb_matches[1];
532 if( cha[0] ==
'0' )
return true;
533 else if (cha[0] ==
'1')
return true;
534 else if (cha[0] ==
'2')
return true;
535 else if (cha[0] ==
'3')
return true;
536 else if (cha[0] ==
'4')
return true;
537 else if (cha[0] ==
'5')
return true;
538 else if (cha[0] ==
'6')
return true;
539 else if (cha[0] ==
'7')
return true;
540 else if (cha[0] ==
'8')
return true;
541 else if (cha[0] ==
'9')
return true;
551 if( cha[0] ==
'A' )
return true;
552 else if (cha[0] ==
'B')
return true;
553 else if (cha[0] ==
'C')
return true;
554 else if (cha[0] ==
'D')
return true;
555 else if (cha[0] ==
'E')
return true;
556 else if (cha[0] ==
'F')
return true;
557 else if (cha[0] ==
'G')
return true;
558 else if (cha[0] ==
'H')
return true;
559 else if (cha[0] ==
'I')
return true;
560 else if (cha[0] ==
'J')
return true;
561 else if (cha[0] ==
'K')
return true;
562 else if (cha[0] ==
'L')
return true;
563 else if (cha[0] ==
'M')
return true;
564 else if (cha[0] ==
'N')
return true;
565 else if (cha[0] ==
'O')
return true;
566 else if (cha[0] ==
'P')
return true;
567 else if (cha[0] ==
'Q')
return true;
568 else if (cha[0] ==
'R')
return true;
569 else if (cha[0] ==
'S')
return true;
570 else if (cha[0] ==
'T')
return true;
571 else if (cha[0] ==
'U')
return true;
572 else if (cha[0] ==
'V')
return true;
573 else if (cha[0] ==
'W')
return true;
574 else if (cha[0] ==
'X')
return true;
575 else if (cha[0] ==
'Y')
return true;
576 else if (cha[0] ==
'Z')
return true;
586 if( cha[0] ==
'a' )
return true;
587 else if (cha[0] ==
'b')
return true;
588 else if (cha[0] ==
'c')
return true;
589 else if (cha[0] ==
'd')
return true;
590 else if (cha[0] ==
'e')
return true;
591 else if (cha[0] ==
'f')
return true;
592 else if (cha[0] ==
'g')
return true;
593 else if (cha[0] ==
'h')
return true;
594 else if (cha[0] ==
'i')
return true;
595 else if (cha[0] ==
'j')
return true;
596 else if (cha[0] ==
'k')
return true;
597 else if (cha[0] ==
'l')
return true;
598 else if (cha[0] ==
'm')
return true;
599 else if (cha[0] ==
'n')
return true;
600 else if (cha[0] ==
'o')
return true;
601 else if (cha[0] ==
'p')
return true;
602 else if (cha[0] ==
'q')
return true;
603 else if (cha[0] ==
'r')
return true;
604 else if (cha[0] ==
's')
return true;
605 else if (cha[0] ==
't')
return true;
606 else if (cha[0] ==
'u')
return true;
607 else if (cha[0] ==
'v')
return true;
608 else if (cha[0] ==
'w')
return true;
609 else if (cha[0] ==
'x')
return true;
610 else if (cha[0] ==
'y')
return true;
611 else if (cha[0] ==
'z')
return true;
632 if( basic::options::option[basic::options::OptionKeys::enzdes::favor_native_res].user() || basic::options::option[ basic::options::OptionKeys::in::file::pssm ].user() ){
645 if( basic::options::option[ basic::options::OptionKeys::docking::ligand::old_estat ].user() ){
648 scorefxn->set_energy_method_options( options_repack );
656 if( !cst_cache )
return;
657 cst_cache->enzcst_io()->remove_constraints_from_pose( pose,
false,
false );
667 if(cstid==
"")
continue;
670 resnums.push_back( resnum );
672 std::unique(resnums.begin(), resnums.end());
681 char const templ(cstid[ cstid.length()-1] );
682 runtime_assert(templ ==
'A' || templ ==
'B');
684 if (templ ==
'A') template_num = 1;
685 else template_num = 2;
687 std::stringstream ss( cstid.substr( 0, cstid.length() - 1) );
692 runtime_assert( cst_cache );
693 runtime_assert( cstnum <= cst_cache->ncsts());
696 if (cst_cache->param_cache(cstnum)->template_res_cache( template_num )->contains_position( seqpos )) {
702 if (!found) utility_exit_with_message(
"Could not parse " + cstid +
"to resnum");