Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PhiPsiRmsd.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 // This file is part of the Rosetta software suite && is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions && developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file protocols/frag_picker/scores/FragmentCrmsd.cc
10 /// @brief Object that scores a fragment by root mean square deviation of Phi && Psi dihedrals
11 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
12 
14 
18 // AUTO-REMOVED #include <protocols/frag_picker/scores/FragmentCrmsd.hh>
19 // AUTO-REMOVED #include <protocols/frag_picker/scores/FragmentScoreManager.hh>
22 
23 // option key includes
24 // AUTO-REMOVED #include <core/init.hh>
25 #include <basic/options/option.hh>
26 // AUTO-REMOVED #include <basic/options/option_macros.hh>
27 #include <basic/options/keys/OptionKeys.hh>
28 #include <basic/options/keys/in.OptionKeys.gen.hh>
29 
30 // AUTO-REMOVED #include <core/pose/util.hh>
31 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
32 #include <basic/Tracer.hh>
33 
34 // AUTO-REMOVED #include <protocols/Protocol.hh>
35 
36 // AUTO-REMOVED #include <numeric/model_quality/rms.hh>
37 
38 // utils
39 #include <ObjexxFCL/FArray1D.hh>
40 #include <basic/prof.hh>
41 
42 // C++
43 // AUTO-REMOVED #include <math.h>
44 // AUTO-REMOVED #include <stdio.h>
45 // AUTO-REMOVED #include <string.h>
46 
47 // Boost
48 // AUTO-REMOVED #include <boost/algorithm/string.hpp>
49 #include <boost/tuple/tuple.hpp>
50 
52 #include <utility/vector1.hh>
53 
54 //Auto Headers
55 #include <core/pose/Pose.hh>
56 //Auto using namespaces
57 namespace std { } using namespace std; // AUTO USING NS
58 //Auto using namespaces end
59 
60 
61 
62 namespace protocols {
63 namespace frag_picker {
64 namespace scores {
65 
66 using namespace basic::options;
67 using namespace basic::options::OptionKeys;
68 
69 static basic::Tracer trPhiPsiRmsd(
70  "protocols.frag_picker.scores.PhiPsiRmsd");
71 
72 PhiPsiRmsd::PhiPsiRmsd(Size priority, Real lowest_acceptable_value, bool use_lowest,
73  core::pose::PoseOP reference_pose) :
74  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "PhiPsiRmsd") {
75 
76  n_atoms_ = reference_pose->total_residue();
77  query_phi_.redimension(n_atoms_);
78  query_psi_.redimension(n_atoms_);
79  existing_data_.resize(n_atoms_);
80  for (Size i = 1; i <= n_atoms_; ++i) {
81  query_phi_(i) = reference_pose->phi(i);
82  query_psi_(i) = reference_pose->psi(i);
83  existing_data_[i] = true;
84  }
85 }
86 
87  PhiPsiRmsd::PhiPsiRmsd(Size priority, Real lowest_acceptable_value, bool use_lowest,
88  PhiPsiTalosIO& reader) :
89  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "PhiPsiRmsd") {
90 
91  n_atoms_ = reader.get_sequence().length();
92  query_phi_.redimension(n_atoms_);
93  query_psi_.redimension(n_atoms_);
94  existing_data_.resize(n_atoms_);
95  for (Size i = 1; i <= n_atoms_; ++i) {
96  if (!reader.has_entry(i)) {
97  existing_data_[i] = false;
98  trPhiPsiRmsd.Warning << "Lack of data for position " << i
99  << std::endl;
100  continue;
101  }
102  boost::tuple<Size, char, Real, Real, Real, Real, Real, Real, Size,
103  std::string> entry = reader.get_entry(i);
104  if ((entry.get<2> () > 181) || (entry.get<2> () < -181)
105  || (entry.get<3> () > 181) || (entry.get<3> () < -181)) {
106  existing_data_[i] = false;
107  trPhiPsiRmsd.Warning
108  << "Unphysical Phi/Psi observation at position " << i
109  << std::endl;
110  continue;
111  }
112  existing_data_[i] = true;
113  query_phi_(i) = entry.get<2> ();
114  query_psi_(i) = entry.get<3> ();
115  }
116 }
117 
118 void PhiPsiRmsd::do_caching(VallChunkOP current_chunk) {
119 
120  chunk_phi_.redimension(current_chunk->size());
121  chunk_psi_.redimension(current_chunk->size());
122  for (Size i = 1; i <= current_chunk->size(); ++i) {
123  VallResidueOP r = current_chunk->at(i);
124  chunk_phi_(i) = r->phi();
125  chunk_psi_(i) = r->psi();
126  }
127 }
128 
130  return cached_score( fragment, scores );
131 }
132 
134 
135  std::string tmp = fragment->get_chunk()->chunk_key();
136  if (tmp.compare(cached_scores_id_) != 0) {
137  do_caching(fragment->get_chunk());
138  cached_scores_id_ = tmp;
139  }
140 
141  PROF_START( basic::FRAGMENTPICKING_PHIPSI_SCORE );
142  Size offset_q = fragment->get_first_index_in_query() - 1;
143  Size offset_v = fragment->get_first_index_in_vall() - 1;
144  Real score = 0.0;
145  Real stmp = 0.0;
146  for (Size i = 1; i <= fragment->get_length(); ++i) {
147  if (!existing_data_[i + offset_q])
148  continue;
149  stmp = abs(chunk_phi_(i + offset_v) - query_phi_(i + offset_q));
150  if ( stmp > 180.0 ) stmp = abs(360.0 - stmp);
151  score += stmp * stmp;
152  stmp = abs(chunk_psi_(i + offset_v) - query_psi_(i + offset_q));
153  if ( stmp > 180.0 ) stmp = abs(360.0 - stmp);
154  score += stmp * stmp;
155  }
156 
157  score = sqrt(score) / ((Real) fragment->get_length());
158  score /= (Real) fragment->get_length();
159  scores->set_score_component(score, id_);
160  PROF_STOP( basic::FRAGMENTPICKING_PHIPSI_SCORE );
161  if ((score > lowest_acceptable_value_) && (use_lowest_ == true))
162  return false;
163 
164  return true;
165 }
166 
168  FragmentScoreMapOP empty_map, std::ostream& out) {
169 
170  Real totalScore = 0;
171 
172  out << f->get_chunk()->get_pdb_id() << " " << I(5,
173  f->get_first_index_in_vall()) << " ";
174  for (Size i = 1; i <= f->get_length(); i++)
175  out << " " << f->get_residue(i)->aa() << " ";
176  out << std::endl << " ";
177  for (Size i = 1; i <= f->get_length(); i++)
178  out << F(6, 1, chunk_phi_(f->get_first_index_in_vall() + i - 1)) << " ";
179  out << std::endl << "query " << I(5, f->get_first_index_in_query()) << " ";
180  for (Size i = 1; i <= f->get_length(); i++)
181  out << F(6, 1, query_phi_(f->get_first_index_in_query() + i - 1))
182  << " ";
183 
184  Size offset_q = f->get_first_index_in_query() - 1;
185  Size offset_v = f->get_first_index_in_vall() - 1;
186  Real score = 0.0;
187  Real stmp = 0.0;
188  for (Size i = 1; i <= f->get_length(); ++i) {
189  stmp = abs(chunk_phi_(i + offset_v) - query_phi_(i + offset_q));
190  score += stmp * stmp;
191  if ( stmp > 180.0 ) stmp = abs(360.0 - stmp);
192  stmp = abs(chunk_psi_(i + offset_v) - query_psi_(i + offset_q));
193  if ( stmp > 180.0 ) stmp = abs(360.0 - stmp);
194  score += stmp * stmp;
195  }
196 
197  score = sqrt(score) / ((Real) f->get_length());
198 
199  if ((score > lowest_acceptable_value_) && (use_lowest_ == true))
200  out << "\nTotal score " << F(5, 3, score) << " REJECTED" << std::endl;
201  else
202  out << "\nTotal score " << F(5, 3, score) << " ACCEPTED" << std::endl;
203  totalScore /= (Real) f->get_length();
204  empty_map->set_score_component(totalScore, id_);
205  if ((score > lowest_acceptable_value_) && (use_lowest_ == true))
206  return false;
207  return true;
208 }
209 
211 }
212 
213 /// @brief Creates a PhiPsiRmsd scoring method
214 /// @param priority - priority of the scoring method. The higher value the earlier the score
215 /// will be evaluated
216 /// @param lowest_acceptable_value - if a calculated score is higher than this value,
217 /// fragment will be neglected
218 /// @param FragmentPickerOP object - not used
219 /// @param line - the relevant line extracted from the scoring configuration file that defines this scoring method
220 /// It could look like: "PhiPsiRmsd 140 -5.0 100.0 additional_string"
221 /// where 140, -5.0 && 100.0 are priority, weight && treshold, respectively.
222 /// The additional string may be:
223 /// - empty: then the maker tries to create a scoring object from a TALOS file
224 /// trying in::file::talos_phi_psi flag. If fails, will try to use a pose from in::file::s
225 /// - a pdb file, pdb extension is necessary. This will create a pose && steal Phi && Psi
226 /// - a TALOS file with Phi/Psi prediction (tab extension is necessary)
228  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP //picker
229  , std::string input_file) {
230 
231  //std::istringstream line_stream(config_line);
232  //std::string score_name;
233  //Size p;
234  //Real weight;
235  //Real lowest;
236  //std::string input_file;
237  //line_stream >> score_name >> p >> weight >> lowest;
238  //if (!line_stream.eof()) {
239  if (input_file != "") {
240  //line_stream >> input_file;
241  Size pos = input_file.find(".pdb");
242  if (pos != std::string::npos) {
243  core::pose::PoseOP nativePose = new core::pose::Pose;
244  core::import_pose::pose_from_pdb(*nativePose, input_file);
246  << "Reference structure for Phi,Psi scoring loaded from a PDB file: "
247  << input_file << std::endl;
248  trPhiPsiRmsd.Debug << "its sequence is:\n"
249  << nativePose->sequence() << std::endl;
250 
251  return (FragmentScoringMethodOP) new PhiPsiRmsd(priority,
252  lowest_acceptable_value, use_lowest, nativePose);
253  }
254  pos = input_file.find(".tab");
255  if (pos != std::string::npos) {
257  << "Reference file for Phi,Psi scoring loaded from a TALOS file: "
258  << input_file << std::endl;
259  PhiPsiTalosIO in(input_file);
260  in.write(trPhiPsiRmsd.Debug);
261  return (FragmentScoringMethodOP) new PhiPsiRmsd(priority,
262  lowest_acceptable_value, use_lowest, in);
263  }
264 
265  }
266 
267  if (option[in::file::talos_phi_psi].user()) {
269  << "Reference file for Phi,Psi scoring loaded from a TALOS file: "
270  << input_file << std::endl;
271  PhiPsiTalosIO in(option[in::file::talos_phi_psi]());
272  in.write(trPhiPsiRmsd.Debug);
273  return (FragmentScoringMethodOP) new PhiPsiRmsd(priority,
274  lowest_acceptable_value, use_lowest, in);
275  }
276  if (option[in::file::native].user()) {
277  core::pose::PoseOP nativePose = new core::pose::Pose;
278  core::import_pose::pose_from_pdb(*nativePose, option[in::file::native]());
279  trPhiPsiRmsd << "Reference file for Phi,Psi scoring loaded from "
280  << option[in::file::native]() << std::endl;
281  trPhiPsiRmsd.Debug << "its sequence is:\n" << nativePose->sequence()
282  << std::endl;
283 
284  return (FragmentScoringMethodOP) new PhiPsiRmsd(priority,
285  lowest_acceptable_value, use_lowest, nativePose);
286  }
287  if (option[in::file::s].user()) {
288  core::pose::PoseOP nativePose = new core::pose::Pose;
289  core::import_pose::pose_from_pdb(*nativePose, option[in::file::s]()[1]);
290  trPhiPsiRmsd << "Reference file for Phi,Psi scoring loaded from "
291  << option[in::file::s]()[1] << std::endl;
292  trPhiPsiRmsd.Debug << "its sequence is:\n" << nativePose->sequence()
293  << std::endl;
294 
295  return (FragmentScoringMethodOP) new PhiPsiRmsd(priority,
296  lowest_acceptable_value, use_lowest, nativePose);
297  }
298 
299  utility_exit_with_message(
300  "Can't read a reference Phi,Psi data. Provide a structure with in::file::s flag\n\t or a Phi-Psi prediction in TALOS format.");
301 
302  return NULL;
303 }
304 
305 } // scores
306 } // frag_picker
307 } // protocols