Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DatabaseFilters.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/features/DatabaseFilters.hh
11 /// @brief report atom-atom pair geometry and scores to features Statistics Scientific Benchmark
12 /// @author Matthew O'Meara
13 
14 // Unit Headers
18 
19 //External
20 #include <boost/uuid/uuid.hpp>
21 
22 // Project Headers
23 #include <core/pose/Pose.hh>
24 #include <core/scoring/Energies.hh>
27 #include <core/types.hh>
28 
29 // Basic Headers
30 #include <basic/options/option.hh>
31 #include <basic/options/keys/out.OptionKeys.gen.hh>
32 
33 #include <utility/sql_database/DatabaseSessionManager.hh>
34 #include <utility/vector1.hh>
35 #include <utility/exit.hh>
36 #include <utility/string_util.hh>
37 // AUTO-REMOVED #include <utility/excn/Exceptions.hh>
38 #include <basic/Tracer.hh>
39 
40 
41 // C++ Headers
42 #include <string>
43 
44 #include <protocols/jd2/Job.hh>
45 
46 //Auto Headers
47 #include <utility/excn/EXCN_Base.hh>
48 namespace protocols{
49 namespace features{
50 
51 basic::Tracer TR("protocols.features.DatabaseFilters");
52 
53 
55  //Set up to pull scores out of the energy map
56  core::scoring::Energies const & energies(pose.energies());
59  core::scoring::ScoreType score_type = static_cast<core::scoring::ScoreType>(score_type_id);
60  utility::vector1< bool > relevant_residues(pose.total_residue(), true);
61  score_function->get_sub_score(pose,relevant_residues,emap);
62  return energies.weights()[score_type] * emap[score_type];
63 }
64 
66  if( ! basic::options::option[basic::options::OptionKeys::out::database_filter].user()){
67  return NULL;// just leave the database_filter pointer null
68  }
69  utility::vector1<std::string> filter_option=
70  basic::options::option[basic::options::OptionKeys::out::database_filter];
71  utility::vector1<std::string>::iterator begin = filter_option.begin();
72  std::string type= *begin;
73  ++begin;
74  utility::vector1<std::string> arguments(begin, filter_option.end());
75 
76  if(type == "TopPercentOfEachInput") return new TopPercentOfEachInput(arguments);
77  if(type == "TopPercentOfAllInputs") return new TopPercentOfAllInputs(arguments);
78  if(type == "TopCountOfEachInput") return new TopCountOfEachInput(arguments);
79  if(type == "TopCountOfAllInputs") return new TopCountOfAllInputs(arguments);
80 
81  utility_exit_with_message(type+" is not a valid Database Filter name");
82  return NULL; // To keep the compiler happy
83 }
84 
86  core::pose::Pose const & pose,
87  utility::sql_database::sessionOP db_session,
88  core::Size const & protocol_id,
89  core::Size const & count,
90  std::string const & score_term,
91  std::string current_input=""
92 ){
93  core::Size n_models = get_current_structure_count(db_session,protocol_id,current_input);
94 
95  //store all the structures until you have at least percentile_count worth of models
96  if(n_models < count)
97  {
99  }
100  // else we need to delete some structure(s) from the database
101  boost::uuids::uuid struct_id;
102  core::Real cutoff_score = 0.0;
103  core::Real current_model_score = 0.0;
104  core::Size score_type_id = 0;
105  try
106  {
107  score_type_id = get_score_type_id_from_score_term(db_session,protocol_id,score_term);
108  }catch(utility::excn::EXCN_Base &)
109  {
110  TR << "no score type term, looking in the job data map" <<std::endl;
111  }
112  //Some applications (most ligand docking) store score terms in the job data.
113  //If this is the case score_type_id will return 0
114  //otherwise, we know that the score term in question is a normal scoring function term
115 
116  boost::uuids::uuid struct_id_to_remove;
117 
118  if(score_type_id != 0)
119  {
120  current_model_score = get_current_model_score(pose, score_type_id);
121 
122  //Get the structure ID and associated score from the database
123  struct_id = get_struct_id_with_nth_lowest_score_from_score_data(db_session,score_type_id,count, protocol_id, current_input);
124  cutoff_score = get_score_for_struct_id_and_score_term_from_score_data(db_session,struct_id,score_type_id);
125  struct_id_to_remove = get_struct_id_with_highest_score_from_score_data(db_session,score_type_id,protocol_id, current_input);
126 
127  }
128  else{
129  //get the current score out of the job data map
131  //The job data is stored as a list instead of a map so we have to actually iterate over the whole thing
132  //In order to pull out one particular item
133  protocols::jd2::Job::StringRealPairs::const_iterator it(job->output_string_real_pairs_begin());
134  for(;it != job->output_string_real_pairs_end();++it)
135  {
136  if(it->first == score_term)
137  {
138  current_model_score = it->second;
139  break;
140  }
141  }
142 
143  struct_id = get_struct_id_with_nth_lowest_score_from_job_data(db_session, score_term, count,protocol_id, current_input);
144  cutoff_score = get_score_for_struct_id_and_score_term_from_job_data(db_session,struct_id,score_term);
145 
146  //See if our current model is better
147  struct_id_to_remove = get_struct_id_with_highest_score_from_job_data(db_session,score_term,protocol_id,current_input);
148  }
149  //See if our current model is better
150  if(current_model_score < cutoff_score )
151  {
152  utility::vector1<boost::uuids::uuid> struct_ids_to_delete(1,struct_id_to_remove);
153  return WriteDeletePair(true, struct_ids_to_delete);
154  }else
155  {
157  }
158 
159 }
160 
163 ):
164  DatabaseFilter(),
165  top_count_of_each_input_()
166 {
167  if(arguments.size() != 2){
168  utility_exit_with_message("TopPercentOfEachInput option takes 2 arguments");
169  }
170  top_count_of_each_input_.score_term_ = arguments[1];
171 
172  core::Real percent = utility::from_string(arguments[2], core::Real());
173  core::Size n_structs = basic::options::option[basic::options::OptionKeys::out::nstruct];
174  core::Size percentile_count = static_cast<core::Size>(floor(percent*n_structs));
175  top_count_of_each_input_.count_ = percentile_count;
176 }
177 
180  core::pose::Pose const & pose,
181  utility::sql_database::sessionOP db_session,
182  core::Size const & protocol_id
183 ){
184  return top_count_of_each_input_(pose, db_session, protocol_id);
185 }
186 
189 {
190  if(arguments.size() != 2){
191  utility_exit_with_message("TopPercentOfAllInputs option takes 2 arguments");
192  }
193  top_count_of_all_inputs_.score_term_ = arguments[1];
194 
195  core::Real percent = utility::from_string(arguments[2], core::Real());
197  core::Size percentile_count = static_cast<core::Size>(floor(percent*total_nr_jobs));
198  top_count_of_all_inputs_.count_ = percentile_count;
199 }
200 
203  core::pose::Pose const & pose,
204  utility::sql_database::sessionOP db_session,
205  core::Size const & protocol_id
206 ){
207  return top_count_of_all_inputs_(pose, db_session, protocol_id);
208 }
209 
212 {}
213 
215  DatabaseFilter(),
216  count_(0)
217 {
218  if(arguments.size() != 2){
219  utility_exit_with_message("TopCountOfEachInput option takes 2 arguments");
220  }
221  score_term_ = arguments[1];
222  count_ = utility::from_string(arguments[2], core::Size());
223 }
224 
227  core::pose::Pose const & pose,
228  utility::sql_database::sessionOP db_session,
229  core::Size const & protocol_id
230 ){
232  return get_write_delete_pair(pose, db_session, protocol_id, count_, score_term_, current_input);
233 }
234 
237 {}
238 
240  DatabaseFilter(),
241  count_(0)
242 {
243  if(arguments.size() != 2){
244  utility_exit_with_message("TopCountOfAllInputs option takes 2 arguments");
245  }
246  score_term_ = arguments[1];
247  count_ = utility::from_string(arguments[2], core::Size());
248 }
249 
252  core::pose::Pose const & pose,
253  utility::sql_database::sessionOP db_session,
254  core::Size const & protocol_id
255 ){
256  return get_write_delete_pair(pose, db_session, protocol_id, count_, score_term_);
257 }
258 
259 } // features
260 } // protocols
261