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