Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AtomPairConstraintsScore.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 && 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/frag_picker/scores/AtomPairConstraintsScore.cc
11 /// @brief
12 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
13 
15 
16 // package headers
21 
22 // mini headers
25 
26 #include <utility/vector1.hh>
27 #include <numeric/xyzVector.hh>
28 #include <utility/io/izstream.hh>
29 #include <basic/prof.hh>
30 #include <basic/Tracer.hh>
31 
32 // option key includes
33 #include <basic/options/option.hh>
34 #include <basic/options/keys/OptionKeys.hh>
35 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
36 
37 namespace protocols {
38 namespace frag_picker {
39 namespace scores {
40 
41 // @brief Auto-generated virtual destructor
43 
44 static basic::Tracer trAtomPairConstraintsScore(
45  "fragment.picking.scores.AtomPairConstraintsScore");
46 
47 /// @brief Prepare an AtomPair constraint - based score that utilizes some user-defined atoms.
48 /// @param priority - the priority for this scoring method. The lower the priority, the later the score will be evaluated
49 /// Because a fragment may be discarded when a score is too low, the most accurate && meaningful scores should have the highest priority
50 /// @param lowest_acceptable_value - a fragment for which this score is below a certain threshold will be discarded
51 /// @param constraints_file_name - from this file AtomPair constraints will be obtained
52 /// @param query_size - the number of residues in the query sequence
53 /// @param constrainable_atoms - a vector of strings providing names of constrained atoms.
54 /// On every do_cahing() event these && only these atoms will be cached from a chunk's pose
56  Real lowest_acceptable_value, bool use_lowest, std::string constraints_file_name,
57  Size query_size, utility::vector1<std::string> constrainable_atoms) :
58  AtomBasedConstraintsScore(priority, lowest_acceptable_value, use_lowest, query_size,
59  constrainable_atoms, "AtomPairConstraintsScore") {
60 
61  data_.resize(get_query_size());
62  read_constraints(constraints_file_name);
63 }
64 
65 /// @brief Prepare an AtomPair constraint - based score that utilizes N, C, CA, O && CB atoms
66 /// @detailed These atoms that will be cached when a new
67 /// chunk is considered (i.e. at every do_caching() call)
68 /// @param priority - the priority for this scoring method. The lower the priority, the later the score will be evaluated
69 /// Because a fragment may be discarded when a score is too low, the most accurate && meaningful scores should have the highest priority
70 /// @param lowest_acceptable_value - a fragment for which this score is below a certain threshold will be discarded
71 /// @param constraints_file_name - from this file AtomPair constraints will be obtained
72 /// @param query_size - the number of residues in the query sequence
74  Real lowest_acceptable_value, bool use_lowest, std::string constraints_file_name,
75  Size query_size) :
76  AtomBasedConstraintsScore(priority, lowest_acceptable_value, use_lowest, query_size,
77  "AtomPairConstraintsScore") {
78 
79  data_.resize(get_query_size());
80  read_constraints(constraints_file_name);
81 }
82 
83 /// @brief Calculates a score for a given fragment.
84 /// @detailed Resulting value is written into a given score map.
85 /// @param fragment - fragment to be scored
86 /// @param scores - resulting score will be stored here
88  FragmentScoreMapOP scores) {
89 
90  PROF_START( basic::FRAGMENTPICKING_ATOMPAIR_SCORE );
91 
92  Size frag_len = fragment->get_length();
93  Size vi = fragment->get_first_index_in_vall();
94  Size qi = fragment->get_first_index_in_query();
95 
96  Real total_score = 0;
97  for (Size i = 0; i < frag_len; ++i) {
98  for (Size c = 1; c <= data_[i + qi].size(); ++c) {
99  Size firstQueryResidueIndex = qi + i;
100  AtomPairConstraintsDataOP r = data_[firstQueryResidueIndex][c];
101  if (r->get_offset() >= frag_len - i)
102  continue;
103  Size firstVallResidueIndex = vi + i;
104  Size secondVallResidueIndex = firstVallResidueIndex
105  + r->get_offset();
106  if (!has_atom(firstVallResidueIndex, r->get_first_atom()))
107  continue;
108  if (!has_atom(secondVallResidueIndex, r->get_second_atom()))
109  continue;
110 
111  assert (fragment->get_chunk()->size() >=secondVallResidueIndex);
112 
114  firstVallResidueIndex, r->get_first_atom());
116  secondVallResidueIndex, r->get_second_atom());
117  Real d = v1.distance(v2);
118  total_score += r->get_function()->func(d);
119  }
120  }
121  total_score /= (Real) frag_len;
122  scores->set_score_component(total_score, id_);
123  PROF_STOP( basic::FRAGMENTPICKING_ATOMPAIR_SCORE );
124  if ((total_score > lowest_acceptable_value_) && (use_lowest_ == true)) {
125  trAtomPairConstraintsScore.Debug << "Trashing a fragment: "
126  << *fragment << " because its score is: " << total_score
127  << std::endl;
128  return false;
129  }
130 
131  return true;
132 }
133 
135  std::string constraints_file_name) {
136  utility::io::izstream data(constraints_file_name.c_str());
137  trAtomPairConstraintsScore.Info << "reading constraints from "
138  << constraints_file_name << std::endl;
139  if (!data) {
140  utility_exit_with_message("[ERROR] Unable to open constraints file: "
141  + constraints_file_name);
142  }
143 
144  std::string line;
145  getline(data, line); // header line
146  std::string tag;
147  Size n_constr = 0;
148  while (!data.fail()) {
149  char c = data.peek();
150  if (c == '#' || c == '\n') {
151  getline(data, line); //comment
152  continue;
153  }
154  data >> tag;
155  if (data.fail()) {
156  trAtomPairConstraintsScore.Debug << constraints_file_name
157  << " end of file reached" << std::endl;
158  break;
159  }
160  if (tag == "AtomPair") {
161  std::string name1, name2, func_type;
162  Size id1, id2;
163  data >> name1 >> id1 >> name2 >> id2 >> func_type;
164  trAtomPairConstraintsScore.Debug << "read: " << name1 << " " << id1
165  << " " << name2 << " " << id2 << " func: " << func_type
166  << std::endl;
168  func_type);
169  func->read_data(data);
170  std::map<std::string, Size> constr_atoms =
172  std::map<std::string, Size>::iterator it = constr_atoms.find(name1);
173  if (it == constr_atoms.end()) {
174  trAtomPairConstraintsScore.Warning << "Unknown backbone atom: "
175  << name1
176  << "\nThe following constraint will NOT be used:\n"
177  << line << std::endl;
178  continue;
179  }
180  Size a1 = it->second;
181  it = constr_atoms.find(name2);
182  if (it == constr_atoms.end()) {
183  trAtomPairConstraintsScore.Warning << "Unknown backbone atom: "
184  << name2
185  << "\nThe following constraint will NOT be used:\n"
186  << line << std::endl;
187  continue;
188  }
189  Size a2 = it->second;
191  if (id2 > id1) {
192  if (id2 > get_query_size()) {
194  << "Constrained atom id exceeds the length of a query sequence. The following constraint will NOT be used:\n"
195  << line << std::endl;
196  continue;
197  }
198  dat = new AtomPairConstraintsData(func, id2 - id1, a1, a2);
199  data_[id1].push_back(dat);
200  n_constr++;
201  } else {
202  if (id1 > get_query_size()) {
204  << "Constrained atom id exceeds the length of a query sequence. The following constraint will NOT be used:\n"
205  << line << std::endl;
206  continue;
207  }
208  dat = new AtomPairConstraintsData(func, id1 - id2, a2, a1);
209  data_[id2].push_back(dat);
210  n_constr++;
211  }
212  }
213  }
214  trAtomPairConstraintsScore << n_constr << " constraints loaded from a file"
215  << std::endl;
216 }
217 
219  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP picker, std::string) {
220 
221  using namespace basic::options;
222  using namespace basic::options::OptionKeys;
223 
224  if (option[constraints::cst_file].user()) {
225  trAtomPairConstraintsScore << "Constraints loaded from: "
226  << option[constraints::cst_file]()[1] << std::endl;
227 
229  lowest_acceptable_value, use_lowest, option[constraints::cst_file]()[1],
230  picker->size_of_query());
231  }
232  utility_exit_with_message(
233  "Can't read a constraints file. Provide it with constraints::cst_file flag");
234 
235  return NULL;
236 }
237 
238 }
239 } // frag_picker
240 } // protocols