32 #include <basic/Tracer.hh>
33 #include <utility/vector1.hh>
34 #include <utility/tools/make_vector1.hh>
36 #include <ObjexxFCL/string.functions.hh>
37 #include <ObjexxFCL/format.hh>
38 #include <basic/options/option.hh>
39 #include <basic/options/keys/in.OptionKeys.gen.hh>
52 static basic::Tracer
TR(
"protocols.swa.stepwise_clusterer" ) ;
53 using namespace basic::options;
54 using namespace basic::options::OptionKeys;
64 initialize_parameters_and_input();
65 input_->set_record_source(
true );
66 input_->filenames( silent_files_in );
69 StepWiseClusterer::StepWiseClusterer(
std::string const & silent_file_in )
71 initialize_parameters_and_input();
72 input_->set_record_source(
true );
75 silent_files_.push_back( silent_file_in );
76 input_->filenames( silent_files_ );
81 initialize_parameters_and_input();
82 input_->set_silent_file_data( sfd );
88 StepWiseClusterer::~StepWiseClusterer()
93 StepWiseClusterer::initialize_parameters_and_input(){
95 cluster_radius_ = 1.5;
96 cluster_by_all_atom_rmsd_ =
true;
97 score_diff_cut_ = 1000000.0;
100 force_align_ =
false;
103 score_min_defined_ =
false;
106 input_->set_order_by_energy(
true );
108 initialize_auto_tune_cluster_rmsds();
109 hit_score_cutoff_ =
false;
110 initialized_atom_id_map_for_rmsd_ =
false;
112 rsd_type_set_ = option[ in::file::residue_type_set ]();
118 StepWiseClusterer::cluster()
120 using namespace core::scoring;
121 using namespace core::import_pose::pose_stream;
122 using namespace core::chemical;
123 using namespace core::pose;
125 clock_t
const time_start( clock() );
130 initialize_cluster_list();
133 cluster_with_auto_tune();
135 do_some_clustering();
138 std::cout <<
"Total time in StepWiseClusterer: " <<
139 static_cast<Real>(clock() - time_start) / CLOCKS_PER_SEC << std::endl;
147 using namespace core::scoring;
150 if( cluster_by_all_atom_rmsd_ ) {
155 initialized_atom_id_map_for_rmsd_ =
true;
160 StepWiseClusterer::do_some_clustering() {
162 using namespace core::pose;
164 hit_score_cutoff_ =
false;
168 Pose & pose = *pose_op;
170 while ( input_->has_another_pose() ) {
173 silent_struct->fill_pose( pose );
178 if ( !score_min_defined_ ){
180 score_min_defined_ =
true;
183 if ( score > score_min_ + score_diff_cut_ ) {
184 hit_score_cutoff_ =
true;
189 TR <<
"Checking: " << tag <<
" with score " << score <<
" against list of size " << pose_output_list_.size();
192 if ( calc_rms_res_.size() > 0 )
pdbslice( pose, calc_rms_res_ );
194 Size const found_close_cluster = check_for_closeness( pose_op );
196 if ( found_close_cluster == 0 ) {
199 tag_output_list_.push_back( tag );
200 pose_output_list_.push_back( pose_save );
201 silent_struct_output_list_.push_back( silent_struct );
202 num_pose_in_cluster_.push_back( 1 );
203 TR <<
" ... added. " << std::endl;
204 if ( pose_output_list_.size() >= max_decoys_ )
break;
206 num_pose_in_cluster_[ found_close_cluster ]++;
207 TR <<
" ... not added. " << std::endl;
211 TR <<
"After clustering, number of decoys: " << pose_output_list_.size() << std::endl;
219 StepWiseClusterer::initialize_cluster_list() {
221 pose_output_list_.clear();
222 tag_output_list_.clear();
223 silent_struct_output_list_.clear();
224 num_pose_in_cluster_.clear();
227 score_min_defined_ =
false;
229 hit_score_cutoff_ =
false;
234 StepWiseClusterer::cluster_with_auto_tune() {
236 for (
Size n = 1; n <= cluster_rmsds_to_try_with_auto_tune_.size(); n++ ) {
238 cluster_radius_ = cluster_rmsds_to_try_with_auto_tune_[ n ];
241 recluster_current_pose_list();
243 do_some_clustering();
245 if ( hit_score_cutoff_ ) {
246 std::cout <<
"Hit score cutoff: " << score_diff_cut_ << std::endl;
249 if ( !input_->has_another_pose() ) {
250 std::cout <<
"Done with pose list. " << std::endl;
255 std::cout <<
"Clustering radius after auto_tune: " << cluster_radius_ << std::endl;
262 StepWiseClusterer::recluster_current_pose_list() {
269 pose_output_list_.clear();
270 tag_output_list_.clear();
271 silent_struct_output_list_.clear();
273 for (
Size i = 1; i <= old_pose_output_list.size(); i++ ) {
277 Size const found_close_cluster = check_for_closeness( pose_op );
278 if ( found_close_cluster == 0 ) {
279 tag_output_list_.push_back( old_tag_output_list[ i ] );
280 pose_output_list_.push_back( old_pose_output_list[ i ] );
281 silent_struct_output_list_.push_back( old_silent_struct_output_list[ i ] );
282 num_pose_in_cluster_.push_back( old_num_pose_in_cluster[ i ] );
284 num_pose_in_cluster_[ found_close_cluster ] += old_num_pose_in_cluster[ i ];
289 TR <<
"After reclustering with rmsd " << cluster_radius_ <<
", number of clusters reduced from " <<
290 old_pose_output_list.size() <<
" to " << pose_output_list_.size() << std::endl;
299 using namespace core::scoring;
301 if ( !initialized_atom_id_map_for_rmsd_ ) initialize_corresponding_atom_id_map( *pose_op );
305 for (
Size n = pose_output_list_.size(); n >= 1; n-- ) {
310 if ( calc_rms_res_.size() == 0 || force_align_ ) {
315 corresponding_atom_id_map_ );
318 if ( rmsd < cluster_radius_ ) {
328 StepWiseClusterer::output_silent_file(
std::string const & silent_file ){
330 using namespace core::io::silent;
334 for (
Size n = 1 ; n <= silent_struct_output_list_.size(); n++ ) {
337 s->add_string_value(
"nclust", ObjexxFCL::fmt::I(8,num_pose_in_cluster_[ n ]) );
340 s->add_comment(
"PARENT_TAG", s->decoy_tag() );
341 std::string const tag =
"S_"+ ObjexxFCL::string_of( n-1 );
342 s->set_decoy_tag( tag );
345 silent_file_data.write_silent_struct( *s, silent_file,
false );
353 StepWiseClusterer::silent_file_data(){
355 using namespace core::io::silent;
358 for (
Size n = 1 ; n <= silent_struct_output_list_.size(); n++ ) {
359 silent_file_data->
add_structure( silent_struct_output_list_[ n ] );
361 return silent_file_data;
366 StepWiseClusterer::clustered_pose_list(){
370 for (
Size n = 1 ; n <= pose_output_list_.size(); n++ ) {
371 pose_list[ tag_output_list_[n] ] = pose_output_list_[ n ];
381 calc_rms_res_ = calc_rms_res;
387 input_->set_silent_file_data( sfd );
392 StepWiseClusterer::initialize_auto_tune_cluster_rmsds(){
393 cluster_rmsds_to_try_with_auto_tune_.clear();
394 cluster_rmsds_to_try_with_auto_tune_.push_back( 0.1 );
395 cluster_rmsds_to_try_with_auto_tune_.push_back( 0.2 );
396 cluster_rmsds_to_try_with_auto_tune_.push_back( 0.25 );
397 cluster_rmsds_to_try_with_auto_tune_.push_back( 0.3 );
398 cluster_rmsds_to_try_with_auto_tune_.push_back( 0.4 );
399 cluster_rmsds_to_try_with_auto_tune_.push_back( 0.5 );
400 cluster_rmsds_to_try_with_auto_tune_.push_back( 0.6 );
401 cluster_rmsds_to_try_with_auto_tune_.push_back( 0.8 );
402 cluster_rmsds_to_try_with_auto_tune_.push_back( 1.0 );
403 cluster_rmsds_to_try_with_auto_tune_.push_back( 1.2 );
404 cluster_rmsds_to_try_with_auto_tune_.push_back( 1.5 );
405 cluster_rmsds_to_try_with_auto_tune_.push_back( 1.75 );
406 cluster_rmsds_to_try_with_auto_tune_.push_back( 2.0 );
407 cluster_rmsds_to_try_with_auto_tune_.push_back( 2.25 );
408 cluster_rmsds_to_try_with_auto_tune_.push_back( 2.5 );
409 cluster_rmsds_to_try_with_auto_tune_.push_back( 2.75 );
410 cluster_rmsds_to_try_with_auto_tune_.push_back( 3.0 );
411 cluster_rmsds_to_try_with_auto_tune_.push_back( 3.5 );
412 cluster_rmsds_to_try_with_auto_tune_.push_back( 4.0 );
413 cluster_rmsds_to_try_with_auto_tune_.push_back( 4.5 );
414 cluster_rmsds_to_try_with_auto_tune_.push_back( 5.0 );
415 cluster_rmsds_to_try_with_auto_tune_.push_back( 6.0 );
416 cluster_rmsds_to_try_with_auto_tune_.push_back( 7.0 );
417 cluster_rmsds_to_try_with_auto_tune_.push_back( 8.0 );
418 cluster_rmsds_to_try_with_auto_tune_.push_back( 9.0 );
419 cluster_rmsds_to_try_with_auto_tune_.push_back( 10 );
420 cluster_rmsds_to_try_with_auto_tune_.push_back( 12.5 );
421 cluster_rmsds_to_try_with_auto_tune_.push_back( 15.0 );
422 cluster_rmsds_to_try_with_auto_tune_.push_back( 17.5 );
423 cluster_rmsds_to_try_with_auto_tune_.push_back( 20.0 );
424 cluster_rmsds_to_try_with_auto_tune_.push_back( 25.0 );
425 cluster_rmsds_to_try_with_auto_tune_.push_back( 30.0 );
426 cluster_rmsds_to_try_with_auto_tune_.push_back( 35.0 );
427 cluster_rmsds_to_try_with_auto_tune_.push_back( 40.0 );
428 cluster_rmsds_to_try_with_auto_tune_.push_back( 45.0 );
429 cluster_rmsds_to_try_with_auto_tune_.push_back( 50.0 );