32 #include <basic/options/option.hh>
42 #include <basic/Tracer.hh>
53 #include <basic/options/keys/in.OptionKeys.gen.hh>
54 #include <basic/options/keys/out.OptionKeys.gen.hh>
55 #include <basic/options/keys/lh.OptionKeys.gen.hh>
56 #include <basic/options/keys/relax.OptionKeys.gen.hh>
58 #include <numeric/random/random.hh>
59 #include <numeric/random/random_permutation.hh>
63 #include <utility/vector1.hh>
72 #if defined(WIN32) || defined(__CYGWIN__)
76 using namespace core::scoring;
78 using namespace core::pose;
79 using namespace conformation;
80 using namespace kinematics;
81 using namespace protocols::frag_picker;
89 static basic::Tracer
TR(
"LoopHashLibrary");
93 options(
"dfpmin", 0.2, true , false ),
94 options2(
"dfpmin", 0.02,true , false )
106 db_path_ = basic::options::option[basic::options::OptionKeys::lh::db_path]();
117 TR <<
"Hash: " << *it << std::endl;
118 hash_[ *it ].mem_foot_print();
128 TR.Info <<
"HASHSIZE: " << *it << std::endl;
130 hash_[ *it ] = newhashmap;
137 if(
hash_.count( size ) == 1 )
return hash_[ size ];
155 long starttime = time(NULL);
156 TR.Info <<
"Saving bbdb_ (BackboneDatabase) " <<
assigned_string_ <<
" with extras" << std::endl;
159 TR.Info <<
"Saving loopdb (LoopHashDatabase) " <<
assigned_string_ <<
" with loop size " << *it << std::endl;
162 long endtime = time(NULL);
163 TR <<
"Save LoopHash Library: " << endtime - starttime <<
" seconds " << std::endl;
169 long starttime = time(NULL);
172 if (
remove( dbstring.c_str() ) != 0 )
throw EXCN_DB_IO_Failed( dbstring ,
"delete" );
173 TR.Info <<
"bbdb deletion successful" << std::endl;
175 std::string dbstring =
db_path_ +
"loopdb." + utility::to_string( *it ) + assigned_string_ +
".db" ;
176 if(
remove( dbstring.c_str() ) != 0 )
throw EXCN_DB_IO_Failed( dbstring,
"delete" );
177 TR.Info <<
"loopdb size " << utility::to_string( *it ) <<
" deletion successful" << std::endl;
179 long endtime = time(NULL);
180 TR <<
"Deleted LoopHash Library: " << endtime - starttime <<
" seconds " << std::endl;
186 long starttime = time(NULL);
187 TR.Info <<
"Reading bbdb_ (BackboneDatabase) " <<
assigned_string_ <<
" with extras" << std::endl;
190 TR.Info <<
"Reading loopdb (LoopHashDatabase) " <<
assigned_string_ <<
" with loop size " << *it << std::endl;
193 long endtime = time(NULL);
194 TR <<
"Read LoopHash Library from disk: " << endtime - starttime <<
" seconds " << std::endl;
202 long starttime = time(NULL);
205 if(
extra_ )
TR.Info <<
" with extras";
206 TR.Info << std::endl;
208 std::map< core::Size, bool > homolog_map;
210 TR.Info <<
"Reading " << db_filename << std::endl;
213 TR.Info <<
"Reading loopdb (LoopHashDatabase) " <<
assigned_string_ <<
" with loop size " << *it << std::endl;
216 db_filename =
db_path_ +
"loopdb." + utility::to_string( *it ) +
".db";
219 long endtime = time(NULL);
220 TR <<
"Read MergedLoopHash Library from disk: " << endtime - starttime <<
" seconds " << std::endl;
229 long starttime = time(NULL);
236 if(
extra_ != second_lib->get_extra() ) {
239 if ( !
merge_bbdb( second_lib->backbone_database(), index_offset ) ) {
243 TR.Debug <<
"BBDB concated" << std::endl;
248 core::Real rms_cutoff = rms_cutoffs[ rms_cutoff_counter++ ];
251 LoopHashMap &second_hashmap = second_lib->gethash( loop_size );
252 TR.Debug <<
"Hashmaps loaded for frag size " << loop_size <<std::endl;
256 std::pair< BackboneIndexMap::iterator, BackboneIndexMap::iterator >
range;
259 std::vector < BackboneSegment > bs_vec_;
260 std::vector < LeapIndex > leap_vec_;
261 boost::uint64_t key = 0;
262 for( BackboneIndexMap::iterator it = range.first; it != range.second; it++ ) {
263 bool same_as_last =
false;
264 bool add_this_ =
true;
270 if( key == cp.
key ) same_as_last =
true;
275 second_lib->backbone_database().get_backbone_segment( cp.
index, cp.
offset, loop_size , bs_ );
277 if( rms_cutoff != 0 ) {
278 if( !same_as_last ) {
280 std::vector < core::Size > leap_index_equals;
287 for( std::vector < core::Size >::const_iterator itx = leap_index_equals.begin();
288 itx != leap_index_equals.end();
294 bs_vec_.push_back( bs_equals );
295 leap_vec_.push_back( cp_equals );
300 for(
core::Size j = 0; j < bs_vec_.size(); j++ ) {
302 if ( BBrms < rms_cutoff ) {
306 TR.Debug <<
"RMS too close, skipping this frag" << std::endl;
318 leap_index.
key = key;
319 hashmap.
add_leap( leap_index, key );
322 bs_vec_.push_back( bs_ );
323 leap_vec_.push_back( leap_index );
327 long endtime = time(NULL);
328 TR <<
"Merged LoopHash Library: " << endtime - starttime <<
" seconds " << std::endl;
352 using namespace basic::options;
353 using namespace basic::options::OptionKeys;
356 if ( option[in::file::vall].user() ){
363 core::Size vall_nlines = chunks->vallNumLines(option[in::file::vall]()[1]);
372 chunks->vallChunksFromLibrary(option[in::file::vall]()[1], startline, endline );
387 if ( option[ in::file::fullatom ]() ) {
394 while( input.has_another_pose() ) {
396 input.fill_pose( pose, *rsd_set );
407 using namespace core::scoring;
458 TR.Info <<
"Graft: Premin RMS: " << premin_rms << std::endl;
459 TR.Info <<
"Graft: Min Score3 " << std::endl;
473 using namespace basic::options;
474 using namespace basic::options::OptionKeys;
477 core::Size skim_size = option[ lh::skim_size ]();
481 static int casecount = 0;
483 std::vector< core::io::silent::SilentStructOP > lib_structs;
485 TR.Info <<
"Loophash apply function ! " << std::endl;
499 get_all( pose, lib_structs, 1, 0, 20,1400.0, 0.5, 4.0 );
501 TR.Info <<
"FOUND " << lib_structs.size() <<
" alternative states in time: " << endtime2 - starttime2 << std::endl;
504 numeric::random::random_permutation(lib_structs.begin(), lib_structs.end(),
numeric::random::RG);
506 std::vector< core::io::silent::SilentStructOP > select_lib_structs;
508 for(
core::Size k=0;k< std::min(skim_size, lib_structs.size() ) ;k++){
509 select_lib_structs.push_back( lib_structs[k] );
517 std::string silent_file_ = option[ OptionKeys::out::file::silent ]() +
".centroid.out" ;
518 for(
core::Size h = 0; h < select_lib_structs.size(); h++){
520 select_lib_structs[h]->fill_pose( rpose );
522 select_lib_structs[h]->add_energy(
"round",
round, 1.0 );
523 select_lib_structs[h]->add_energy(
"rms", rms, 1.0 );
524 select_lib_structs[h]->set_decoy_tag(
"S_" + string_of(
round ) +
"_" + string_of( h ) );
536 relax->batch_apply( select_lib_structs );
538 TR.Info <<
"Batchrelax time: " << endtime - starttime <<
" for " << select_lib_structs.size() <<
" structures " << std::endl;
541 for(
core::Size h = 0; h < select_lib_structs.size(); h++){
542 TR.Info <<
"DOING: " << h <<
" / " << select_lib_structs.size() << std::endl;
545 select_lib_structs[h]->fill_pose( rpose );
549 TR.Info <<
"score: " << h <<
" " << score << std::endl;
551 if( score < bestscore ){
561 TR.Info <<
"BESTSCORE: " << bestscore <<
"BESTRMS" << bestrms << std::endl;
566 std::string silent_file_ = option[ OptionKeys::out::file::silent ]();
567 for(
core::Size h = 0; h < select_lib_structs.size(); h++){
569 if( h == bestindex ) {
571 select_lib_structs[h]->fill_pose( rpose );
573 select_lib_structs[h]->add_energy(
"round",
round, 1.0 );
574 select_lib_structs[h]->add_energy(
"rms", rms, 1.0 );
575 select_lib_structs[h]->set_decoy_tag(
"S_" + string_of(
round ) +
"_" + string_of( h ) );
594 using namespace core;
595 using namespace core::pose;
596 using namespace conformation;
597 using namespace kinematics;
598 using namespace numeric::geometry::hashing;
615 while( runcount++ < 1000 ){
621 ir = numeric::random::random_range(2,nres - loop_size - 1);
623 if ( ir > nres )
continue;
624 if ( jr > nres )
continue;
635 std::vector < core::Size > leap_index_bucket;
636 hashmap.
lookup( t, leap_index_bucket );
638 TR.Info <<
"G: " << runcount <<
" " << ir <<
" " << jr <<
" " << leap_index_bucket.size() <<
" " << t[1] <<
" " << t[2] <<
" " << t[3] <<
" " << t[4] <<
" " << t[5] <<
" " << t[6] << std::endl;
640 if( leap_index_bucket.size() == 0)
continue;
641 TR.Info <<
"B: " << leap_index_bucket.size() << std::endl;
642 std::vector < core::Size > filter_leap_index_bucket;
643 for( std::vector < core::Size >::const_iterator it = leap_index_bucket.begin();
644 it != leap_index_bucket.end();
656 if( ( BBrms > min_rms ) && ( BBrms < max_rms ) ){
657 filter_leap_index_bucket.push_back( *it );
661 if( filter_leap_index_bucket.size() == 0)
continue;
663 core::Size loop_choice = numeric::random::random_range(0, filter_leap_index_bucket.size() - 1);
682 TR.Info <<
"Applying: " << ir <<
" " << jr <<
" " << BBrms << nres << loop_size << std::endl;;
695 std::vector< core::io::silent::SilentStructOP > &lib_structs,
705 using namespace core;
706 using namespace core::pose;
707 using namespace conformation;
708 using namespace kinematics;
709 using namespace numeric::geometry::hashing;
710 using namespace optimization;
738 if ( stop_res == 0 ) stop_res = nres;
739 start_res = std::min( start_res, (
core::Size)2 );
741 for( ir = 2; ir < nres; ir ++ ){
746 if ( ir > nres )
continue;
747 if ( jr > nres )
continue;
757 std::vector < core::Size > leap_index_bucket;
758 hashmap.
lookup( t, leap_index_bucket );
760 TR.Info <<
"G: " << runcount <<
" " << ir <<
" " << jr <<
" " << leap_index_bucket.size() <<
" " << t[1] <<
" " << t[2] <<
" " << t[3] <<
" " << t[4] <<
" " << t[5] <<
" " << t[6] << std::endl;
767 if( leap_index_bucket.size() == 0)
continue;
768 std::vector < core::Size > filter_leap_index_bucket;
769 for( std::vector < core::Size >::const_iterator it = leap_index_bucket.begin();
770 it != leap_index_bucket.end();
783 if( ( BBrms > min_bbrms ) && ( BBrms < max_bbrms ) ){
784 filter_leap_index_bucket.push_back( *it );
789 if( filter_leap_index_bucket.size() == 0)
continue;
794 numeric::random::random_permutation(filter_leap_index_bucket.begin(), filter_leap_index_bucket.end(),
numeric::random::RG);
796 for( std::vector < core::Size >::const_iterator it = filter_leap_index_bucket.begin();
797 it != filter_leap_index_bucket.end();
802 clock_t starttime = clock();
850 TR.Info <<
"Premin RMS: " << premin_rms << std::endl;
851 TR.Info <<
"Min Score3 " << std::endl;
859 TR.Info <<
"Final RMS: " << final_rms << std::endl;
860 if ( ( final_rms < max_rms ) && ( final_rms > min_rms ) ){
867 new_struct->fill_struct( mynewpose );
868 lib_structs.push_back( new_struct );
873 clock_t endtime = clock();
875 TR.Info <<
"Clocks: " << endtime - starttime << std::endl;
892 using namespace core;
893 using namespace core::pose;
894 using namespace conformation;
895 using namespace kinematics;
896 using namespace numeric::geometry::hashing;
903 static int runcount=0;
907 TR.Info <<
"Setting up hash: Size: " << *it << std::endl;
908 Size loop_size = *it;
911 if( loop_size + 2 > nres )
continue;
912 for( ir = 2; ir < ( nres - loop_size ); ir ++ ){
919 leap_index.
index = index;
920 leap_index.
offset = (ir-1)*3;
933 << leap_index.
index <<
" "
935 TR.Debug << std::endl;
948 if( f.reorder(1) == false ){
949 TR.Error <<
"ERROR During resetting reordering of fold tree - am ignoring this LOOP ! Cannot continue " << std::endl;
958 using namespace core;
959 using namespace core::pose;
960 using namespace conformation;
961 using namespace kinematics;
962 using namespace numeric::geometry::hashing;
971 leap_index.
index = index;
972 leap_index.offset = (ir-1)*3;
982 << ir <<
" " << jr <<
" "
983 <<
t[1] <<
" " <<
t[2] <<
" " <<
t[3] <<
" " <<
t[4] <<
" " <<
t[5] <<
" " <<
t[6] <<
" "
984 << leap_index.index <<
" "
987 hashmap.add_leap( leap_index,
t );
994 std::vector < core::Size > leap_index_bucket;
995 TR <<
"Radial lookup ... " << std::endl;
996 hashmap.radial_lookup( 0,
t, leap_index_bucket );
998 core::Size example_index = leap_index_bucket[0];
999 TR <<
"Get the actual strucure index (not just the bin index) << " << std::endl;
1001 LeapIndex cp = hashmap.get_peptide( example_index );
1008 bool result = new_bs.compare(pose_bs,0.1);
1010 if(result)
TR <<
"TEST OK " << std::endl;
else TR <<
"TEST FAIL" << std::endl;
1011 TR <<
"Done testing!" << std::endl;
1018 using namespace core;
1019 using namespace core::pose;
1020 using namespace conformation;
1021 using namespace kinematics;
1022 using namespace numeric::geometry::hashing;
1031 static int runcount=0;
1034 for( std::vector< core::Size >::const_iterator it =
hash_sizes_.begin(); it !=
hash_sizes_.end(); ++it ){
1035 TR.Info <<
"Setting up hash: Size: " << *it << std::endl;
1036 Size loop_size = *it;
1040 for( ir = 2; ir < ( nres - loop_size ); ir ++ ){
1046 leap_index.
index = index;
1047 leap_index.
offset = (ir-1)*3;
1060 << leap_index.
index <<
" "
1062 TR.Info << std::endl;
1076 Pose tmp_pose = original_pose;
1085 std::vector < core::Size > leap_index_bucket;
1092 for( std::vector < core::Size >::const_iterator it = leap_index_bucket.begin();
1093 it != leap_index_bucket.end();
1105 if( BBrms > 10.0 && leap_index_bucket.size() >= 2 ){
1107 TR.Info <<
"RMS: " << BBrms << std::endl;
1119 Pose tmp_pose = original_pose;
1125 TR.Info <<
"R6CHECKHERE: " << t[1] <<
" " << t[2] <<
" " <<t[3] <<
" " <<t[4] <<
" " <<t[5] <<
" " <<t[6] << std::endl;
1140 if( f.reorder(1) == false ){
1141 TR.Error <<
"ERROR During reordering of fold tree - am ignoring this LOOP ! I am done. " << std::endl;