Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InterbondAngleScore.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/InterbondAngleScore.cc
11 /// @brief
12 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
13 
15 
16 // package headers
21 
22 // mini headers
26 
27 #include <basic/Tracer.hh>
28 
29 #include <utility/vector1.hh>
30 #include <numeric/xyzVector.hh>
31 #include <utility/io/izstream.hh>
32 #include <numeric/NumericTraits.hh>
33 
34 // option key includes
35 #include <basic/options/option.hh>
36 #include <basic/options/keys/OptionKeys.hh>
37 #include <basic/options/keys/constraints.OptionKeys.gen.hh>
38 
39 #include <basic/prof.hh>
40 
42 
43 
44 namespace protocols {
45 namespace frag_picker {
46 namespace scores {
47 
48 static basic::Tracer trInterbondAngleScore(
49  "fragment.picking.scores.InterbondAngleScore");
50 
52  Real lowest_acceptable_value, bool use_lowest, std::string constraints_file_name,
53  Size query_size, utility::vector1<std::string> constrainable_atoms) :
54  AtomBasedConstraintsScore(priority, lowest_acceptable_value, use_lowest, query_size,
55  constrainable_atoms, "InterbondAngleScore") {
56 
60  x0,sd));
61 
62  data_.resize(get_query_size());
63  read_constraints(constraints_file_name);
64 }
65 
67  Real lowest_acceptable_value, bool use_lowest, std::string constraints_file_name,
68  Size query_size) :
69  AtomBasedConstraintsScore(priority, lowest_acceptable_value, use_lowest, query_size,
70  "InterbondAngleScore") {
71 
75  x0,sd));
76 
77  data_.resize(get_query_size());
78  read_constraints(constraints_file_name);
79 }
80 
82  FragmentScoreMapOP scores) {
83 
84  PROF_START( basic::FRAGMENTPICKING_DIHEDRALCONSTR_SCORE );
85  Size frag_len = fragment->get_length();
86  Size vi = fragment->get_first_index_in_vall();
87  Size qi = fragment->get_first_index_in_query();
88 
89  Real total_score = 0;
90  for (Size i = 0; i < frag_len; ++i) {
91  for (Size c = 1; c <= data_[i + qi].size(); ++c) {
92  Size firstQueryResidueIndex = qi + i;
93  Size firstVallResidueIndex = vi + i;
94  FourAtomsConstraintDataOP r = data_[firstQueryResidueIndex][c];
95  if (r->get_second_offset() >= frag_len - i)
96  continue;
97  if (r->get_third_offset() >= frag_len - i)
98  continue;
99  if (r->get_fourth_offset() >= frag_len - i)
100  continue;
101  Size secondVallResidueIndex = firstVallResidueIndex
102  + r->get_second_offset();
103  Size thirdVallResidueIndex = firstVallResidueIndex
104  + r->get_third_offset();
105  Size fourthVallResidueIndex = firstVallResidueIndex
106  + r->get_fourth_offset();
107  if (!has_atom(firstVallResidueIndex, r->get_first_atom()))
108  continue;
109  if (!has_atom(secondVallResidueIndex, r->get_second_atom()))
110  continue;
111  if (!has_atom(thirdVallResidueIndex, r->get_third_atom()))
112  continue;
113  if (!has_atom(fourthVallResidueIndex, r->get_fourth_atom()))
114  continue;
116  get_atom_coordinates(secondVallResidueIndex, r->get_second_atom()) -
117  get_atom_coordinates(firstVallResidueIndex, r->get_first_atom())
118  );
120  get_atom_coordinates(fourthVallResidueIndex, r->get_fourth_atom()) -
121  get_atom_coordinates(thirdVallResidueIndex, r->get_third_atom())
122  );
123 
124  double angle = angle_of(v1, v2)*180.0/numeric::NumericTraits<Real>::pi();
125  total_score += r->get_function()->func(angle);
126  }
127  }
128  total_score /= (Real) frag_len;
129  scores->set_score_component(total_score, id_);
130  PROF_STOP( basic::FRAGMENTPICKING_DIHEDRALCONSTR_SCORE );
131 
132  if ((total_score > lowest_acceptable_value_) && (use_lowest_ == true)) {
133  trInterbondAngleScore.Debug << "Trashing a fragment: "
134  << *fragment << " because its score is: " << total_score
135  << std::endl;
136  return false;
137  }
138 
139  return true;
140 }
141 
143  std::string constraints_file_name) {
144  utility::io::izstream data(constraints_file_name.c_str());
145  trInterbondAngleScore.Info << "read constraints from "
146  << constraints_file_name << std::endl;
147  if (!data) {
148  utility_exit_with_message("[ERROR] Unable to open constraints file: "
149  + constraints_file_name);
150  }
151 
152  std::string line;
153  getline(data, line); // header line
154  std::string tag;
155  Size n_constr = 0;
156  while (!data.fail()) {
157  char c = data.peek();
158  if (c == '#' || c == '\n') {
159  getline(data, line); //comment
160  continue;
161  }
162  data >> tag;
163  if (data.fail()) {
164  trInterbondAngleScore.Debug << constraints_file_name
165  << " end of file reached" << std::endl;
166  break;
167  }
168  if (tag == "InterbondAngleScore") {
169  Size res1, res2, res3, res4;
170  std::string name1, name2, name3, name4;
171  std::string func_type;
172  std::string type;
173 
174  data >> name1 >> res1 >> name2 >> res2 >> name3 >> res3 >> name4
175  >> res4 >> func_type;
176 
177  trInterbondAngleScore.Debug << "read: " << name1 << " "
178  << name2 << " " << name3 << " " << name4 << " " << res1
179  << " " << res2 << " " << res3 << " " << res4 << " func: "
180  << func_type << std::endl;
182  func_type);
183  func->read_data(data);
184  std::map<std::string, Size> constr_atoms =
186  std::map<std::string, Size>::iterator it = constr_atoms.find(name1);
187  if (it == constr_atoms.end()) {
188  trInterbondAngleScore.Warning << "Unknown atom: " << name1
189  << "\nThe following constraint will NOT be used:\n"
190  << line << std::endl;
191  continue;
192  }
193  Size a1 = it->second;
194  it = constr_atoms.find(name2);
195  if (it == constr_atoms.end()) {
196  trInterbondAngleScore.Warning << "Unknown atom: "
197  << name2
198  << "\nThe following constraint will NOT be used:\n"
199  << line << std::endl;
200  continue;
201  }
202  Size a2 = it->second;
203  it = constr_atoms.find(name3);
204  if (it == constr_atoms.end()) {
205  trInterbondAngleScore.Warning << "Unknown atom: " << name3
206  << "\nThe following constraint will NOT be used:\n"
207  << line << std::endl;
208  continue;
209  }
210  Size a3 = it->second;
211  it = constr_atoms.find(name4);
212  if (it == constr_atoms.end()) {
213  trInterbondAngleScore.Warning << "Unknown atom: "
214  << name4
215  << "\nThe following constraint will NOT be used:\n"
216  << line << std::endl;
217  continue;
218  }
219  Size a4 = it->second;
220  Size o2 = res2 - res1;
221  Size o3 = res3 - res1;
222  Size o4 = res4 - res1;
223  if ((res2 < res1) || (res3 < res1) || (res4 < res1)) {
224  trInterbondAngleScore.Warning
225  << "The residue of the first constrained atoms must precede all the other three.\n\t\t"
226  << "Check residue indexes && redefine the constraint if necessary.\n\t\t"
227  << "The following constraint will NOT be used:\n"
228  << line << std::endl;
229  continue;
230  }
231 
233  dat = new FourAtomsConstraintData(func, a1, o2, a2, o3, a3, o4, a4);
234  if (res1 > data_.size()) {
235  trInterbondAngleScore.Warning
236  << "Skipping a constraint that involves residue "
237  << res1 << " that does not exist in a query"
238  << std::endl;
239  continue;
240  }
241  data_[res1].push_back(dat);
242  n_constr++;
243  }
244  }
245  trInterbondAngleScore << n_constr << " constraints loaded from a file"
246  << std::endl;
247 }
248 
250  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP picker, std::string) {
251 
252  using namespace basic::options;
253  using namespace basic::options::OptionKeys;
254 
255  // Hack for VEAN experiment scoring. In the future atom names should come from command-line
256  utility::vector1<std::string> constrainable_atoms;
257  constrainable_atoms.push_back("N");
258  constrainable_atoms.push_back("CA");
259  constrainable_atoms.push_back("H");
260  constrainable_atoms.push_back("HA");
261 
262  if (option[constraints::cst_file].user()) {
263  trInterbondAngleScore << "Constraints loaded from: "
264  << option[constraints::cst_file]()[1] << std::endl;
265 
266  return (FragmentScoringMethodOP) new InterbondAngleScore(priority,
267  lowest_acceptable_value, use_lowest, option[constraints::cst_file]()[1],
268  picker->size_of_query(),constrainable_atoms);
269  }
270  utility_exit_with_message(
271  "Can't read a constraints file. Provide it with constraints::cst_file flag");
272 
273  return NULL;
274 }
275 
276 }
277 } // frag_picker
278 } // protocols