Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomAtomPairFeatures.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/AtomAtomPairFeatures.cc
11 /// @brief report atom-atom pair geometry and scores to features statistics scientific benchmark
12 /// @author Matthew O'Meara
13 
14 // Unit Headers
16 
17 // Project Headers
18 #include <basic/Tracer.hh>
19 #include <core/chemical/AA.hh>
26 #include <core/graph/Graph.hh>
27 #include <core/pose/Pose.hh>
29 #include <core/scoring/Energies.hh>
30 #include <core/types.hh>
31 #include <utility/sql_database/DatabaseSessionManager.hh>
32 #include <utility/tag/Tag.hh>
33 #include <utility/vector1.hh>
34 #include <basic/database/sql_utils.hh>
35 #include <basic/database/schema_generator/PrimaryKey.hh>
36 #include <basic/database/schema_generator/ForeignKey.hh>
37 #include <basic/database/schema_generator/Column.hh>
38 #include <basic/database/schema_generator/Schema.hh>
39 
41 
42 // ObjexxFCL Headers
43 #include <ObjexxFCL/FArray3D.hh>
44 
45 // Numeric Headers
46 #include <numeric/xyzVector.hh>
47 
48 // External Headers
49 #include <cppdb/frontend.h>
50 #include <boost/uuid/uuid_io.hpp>
51 
52 // C++ Headers
53 #include <algorithm>
54 #include <utility/excn/Exceptions.hh>
55 #include <map>
56 
57 namespace protocols{
58 namespace features{
59 
60 using std::map;
61 using std::string;
62 using std::endl;
63 using std::upper_bound;
68 using core::pose::Pose;
69 using core::Size;
70 using core::Real;
71 using core::Distance;
72 using core::Vector;
73 using core::graph::Graph;
80 using utility::sql_database::sessionOP;
81 using utility::vector1;
82 using basic::Tracer;
83 using basic::database::safely_write_to_database;
84 using basic::database::safely_prepare_statement;
85 using ObjexxFCL::FArray3D;
86 using cppdb::statement;
87 
88 static Tracer TR("protocols.features.AtomAtomPairFeatures");
89 
91  min_dist_(0.0),
92  max_dist_(10.0),
93  nbins_(15)
94 {
95  relevant_atom_names_.push_back("CAbb");
96  relevant_atom_names_.push_back("CObb");
97  relevant_atom_names_.push_back("OCbb");
98  relevant_atom_names_.push_back("CNH2");
99  relevant_atom_names_.push_back("COO" );
100  relevant_atom_names_.push_back("CH1" );
101  relevant_atom_names_.push_back("CH2" );
102  relevant_atom_names_.push_back("CH3" );
103  relevant_atom_names_.push_back("aroC");
104  relevant_atom_names_.push_back("Nbb" );
105  relevant_atom_names_.push_back("Ntrp");
106  relevant_atom_names_.push_back("Nhis");
107  relevant_atom_names_.push_back("NH2O");
108  relevant_atom_names_.push_back("Nlys");
109  relevant_atom_names_.push_back("Narg");
110  relevant_atom_names_.push_back("Npro");
111  relevant_atom_names_.push_back("OH" );
112  relevant_atom_names_.push_back("ONH2");
113  relevant_atom_names_.push_back("OOC" );
114  relevant_atom_names_.push_back("Oaro");
115  relevant_atom_names_.push_back("Hpol");
116  relevant_atom_names_.push_back("Hapo");
117  relevant_atom_names_.push_back("Haro");
118  relevant_atom_names_.push_back("HNbb");
119  relevant_atom_names_.push_back("HOH" );
120  relevant_atom_names_.push_back("S" );
121 
122  AtomTypeSetCAP atom_type_set(ChemicalManager::get_instance()->atom_type_set("fa_standard"));
123 
124  for(Size i=1; i <= relevant_atom_names_.size(); ++i){
126  atom_type_set->atom_type_index(relevant_atom_names_[i])] = i;
127  }
128 
129  relevant_elements_["C"] = 1;
130  relevant_elements_["N"] = 2;
131  relevant_elements_["O"] = 3;
132  relevant_elements_["H"] = 4;
133 
134 }
135 
137  min_dist_(src.min_dist_),
138  max_dist_(src.max_dist_),
139  nbins_(src.nbins_),
140  relevant_atom_names_(src.relevant_atom_names_),
141  atom_index_to_relevant_atom_index_(src.atom_index_to_relevant_atom_index_),
142  relevant_elements_(src.relevant_elements_)
143 {}
144 
146 
147 string
148 AtomAtomPairFeatures::type_name() const { return "AtomAtomPairFeatures"; }
149 
150 void
152  sessionOP db_session
153 ) const {
154  write_atom_pairs_table_schema(db_session);
155 }
156 
157 void
159  sessionOP db_session
160 ) const {
161  using namespace basic::database::schema_generator;
162 
163  Column struct_id("struct_id", new DbUUID());
164  Column atom_type("atom_type", new DbText());
165  Column element("element", new DbText());
166  Column lower_break("lower_break", new DbReal());
167  Column upper_break("upper_break", new DbReal());
168  Column count("count", new DbInteger());
169 
170  Columns primary_key_columns;
171  primary_key_columns.push_back(struct_id);
172  primary_key_columns.push_back(atom_type);
173  primary_key_columns.push_back(element);
174  primary_key_columns.push_back(lower_break);
175  PrimaryKey primary_key(primary_key_columns);
176 
177  Columns foreign_key_columns;
178  foreign_key_columns.push_back(struct_id);
179  vector1< std::string > reference_columns;
180  reference_columns.push_back("struct_id");
181  ForeignKey foreign_key(foreign_key_columns, "structures", reference_columns, true);
182 
183  Schema table("atom_pairs", primary_key);
184  table.add_foreign_key(foreign_key);
185  table.add_column(upper_break);
186  table.add_column(count);
187 
188  table.write(db_session);
189 }
190 
193  utility::vector1<std::string> dependencies;
194  dependencies.push_back("StructureFeatures");
195  return dependencies;
196 }
197 
198 void
200  TagPtr const tag,
201  DataMap & /*data*/,
202  Filters_map const & /*filters*/,
203  Movers_map const & /*movers*/,
204  Pose const & /*pose*/
205 ) {
206  min_dist_ = tag->getOption<Real>("min_dist", 0.0);
207  max_dist_ = tag->getOption<Real>("max_dist", 10.0);
208  nbins_ = tag->getOption<Size>("nbins", 15);
209  if(nbins_ < 1){
210  throw utility::excn::EXCN_RosettaScriptsOption("The parameter 'nbins' must be an integer greater than 0.");
211  }
212 }
213 
214 
215 Size
217  Pose const & pose,
218  vector1< bool > const & relevant_residues,
219  boost::uuids::uuid const struct_id,
220  sessionOP db_session
221 ){
222  report_atom_pairs(pose, relevant_residues, struct_id, db_session);
223  return 0;
224 }
225 
226 
227 void
229  Pose const & pose,
230  vector1< bool > const & relevant_residues,
231  boost::uuids::uuid const struct_id,
232  sessionOP db_session
233 ){
234 
235  // assert pose.update_residue_neighbors() has been called:
236  runtime_assert(
237  !pose.conformation().structure_moved() &&
239 
240  if(pose.total_residue() ==0){
241  return;
242  }
243 
244  if(pose.residue(1).type().atom_type_set().name() != "fa_standard"){
245  TR.Warning
246  << "Currently AtomAtomPairFeatures only works "
247  << "for the 'fa_standard' AtomTypeSet. This pose has AtomTypeSet '"
248  << pose.residue(1).type().atom_type_set().name() << "'.";
249  utility_exit();
250  }
251 
252 
253  vector1<Distance> bin_breaks;
254  Distance const bin_width((max_dist_-min_dist_)/nbins_);
255  for(Size i=0; i <= nbins_; ++i){
256  bin_breaks.push_back(i*bin_width + min_dist_);
257  }
258 
259  int const dim1(relevant_atom_names_.size());
260  int const dim2(relevant_elements_.size());
261  int const dim3(nbins_);
262  Size const initial_value(0);
263  FArray3D< Size > counts;
264  counts.dimension(dim1, dim2, dim3, initial_value);
265 
266  for(Size res_num1=1; res_num1 <= pose.total_residue(); ++res_num1){
267  if(!relevant_residues[res_num1]) continue;
268  Residue res1(pose.residue(res_num1));
269 
270  for(Size atom_num1=1; atom_num1 <= res1.natoms(); ++atom_num1){
271  Vector const & atom1_xyz( res1.xyz(atom_num1) );
272 
273  Size const atom_index1(res1.type().atom(atom_num1).atom_type_index());
274  map<Size, Size>::const_iterator const i_relevant_atom_index1(
275  atom_index_to_relevant_atom_index_.find(atom_index1));
276  if(i_relevant_atom_index1 == atom_index_to_relevant_atom_index_.end()){
277  continue;
278  }
279 
280  for(Size res_num2=1; res_num2 <= pose.total_residue(); ++res_num2){
281  if(!relevant_residues[res_num2]) continue;
282  Residue res2( pose.residue(res_num2) );
283 
284  for(Size atom_num2=1; atom_num2 <= res2.natoms(); ++atom_num2){
285  string const elem_name2(res2.type().atom_type(atom_num2).element());
286  map< string, Size>::const_iterator i_elem2(
287  relevant_elements_.find(elem_name2));
288  if(i_elem2 == relevant_elements_.end()) continue;
289 
290  Vector const & atom2_xyz( res2.xyz(atom_num2) );
291  Distance dist(atom1_xyz.distance(atom2_xyz));
292  if(dist <= min_dist_ || dist > max_dist_) continue;
293 
294 
295  Size const dist_bin(
296  static_cast<Size>(ceil(
297  (dist-min_dist_)*nbins_/(max_dist_-min_dist_))));
298  counts(i_relevant_atom_index1->second, i_elem2->second, dist_bin) += 1;
299  }
300  }
301  }
302  }
303 
304  string stmt_string = "INSERT INTO atom_pairs (struct_id, atom_type, element, lower_break, upper_break, count) VALUES (?,?,?,?,?,?);";
305  statement stmt(safely_prepare_statement(stmt_string,db_session));
306 
307 
308  for(Size i_atom1=1; i_atom1 <= relevant_atom_names_.size(); ++i_atom1){
309  for(map<string, Size>::const_iterator
310  i_elem2=relevant_elements_.begin(),
311  ie_elem2=relevant_elements_.end(); i_elem2 != ie_elem2; ++i_elem2){
312  for(Size dist_bin=1; dist_bin <= nbins_; ++dist_bin){
313  Real const lower_break(min_dist_ + (dist_bin - 1)*bin_width);
314  Real const upper_break(min_dist_ + dist_bin * bin_width);
315  Size const count(counts(i_atom1,i_elem2->second, dist_bin));
316  stmt.bind(1,struct_id);
317  stmt.bind(2, relevant_atom_names_[i_atom1]);
318  stmt.bind(3, i_elem2->first);
319  stmt.bind(4, lower_break);
320  stmt.bind(5, upper_break);
321  stmt.bind(6, count);
322  safely_write_to_database(stmt);
323  }
324  }
325  }
326 }
327 
328 } // namesapce
329 } // namespace