Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FragmentCrmsd.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 its crmsd to the native
11 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
12 
19 #ifdef WIN32
21 #endif
22 
23 // option key includes
24 #include <basic/options/option.hh>
25 #include <basic/options/keys/OptionKeys.hh>
26 #include <basic/options/keys/in.OptionKeys.gen.hh>
27 
29 #include <basic/Tracer.hh>
30 
31 
32 #include <numeric/model_quality/rms.hh>
33 
34 // utils
35 #include <ObjexxFCL/FArray2D.hh>
36 #include <ObjexxFCL/FArray1D.hh>
37 #include <basic/prof.hh>
38 
39 //Auto Headers
40 #include <core/id/NamedAtomID.hh>
42 #include <core/io/pdb/pose_io.hh>
43 #include <core/pose/Pose.hh>
44 #include <utility/io/izstream.hh>
45 #include <iostream>
46 #include <string>
47 
48 
49 namespace protocols {
50 namespace frag_picker {
51 namespace scores {
52 
53 using namespace basic::options;
54 using namespace basic::options::OptionKeys;
55 
56 static basic::Tracer trRmsScore(
57  "protocols.frag_picker.scores.FragmentCrmsd");
58 
60 
61 FragmentCrmsd::FragmentCrmsd(Size priority, Real lowest_acceptable_value,
62  bool use_lowest, core::pose::PoseOP reference_pose) :
63  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "FragmentCrmsd") {
64  reference_pose_ = reference_pose;
65  n_atoms_ = reference_pose_->total_residue();
66  reference_coordinates_.redimension(3, n_atoms_, 0.0);
68  weights_.redimension(reference_pose_->total_residue(), 1.0);
69 }
70 
71 FragmentCrmsd::FragmentCrmsd(Size priority, Real lowest_acceptable_value, bool use_lowest,
73  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "FragmentCrmsd") {
74 
75  n_atoms_ = xyz.size();
76  reference_coordinates_.redimension(3, n_atoms_, 0.0);
77  weights_.redimension(n_atoms_, 1.0);
78  for (core::Size i = 1; i <= n_atoms_; i++) {
79  trRmsScore.Debug << i<<" ";
80  for (core::Size d = 1; d <= 3; ++d) {
81  reference_coordinates_(d, i) = xyz[i][d];
82  trRmsScore.Debug <<xyz[i][d]<<" ";
83  }
84  trRmsScore.Debug <<std::endl;
85  }
86 }
87 
89  FArray2_double& coords, Size n_atoms) {
90 
91  trRmsScore.Debug << "Copying coordinates from ... The first residues are: "
92  << pose.residue(1).name3() << " " << pose.residue(2).name3() << " "
93  << pose.residue(3).name3() << std::endl;
94 
95  for (core::Size i = 1; i <= n_atoms; i++) {
96  id::NamedAtomID idCA("CA", i);
97  PointPosition const& xyz = pose.xyz(idCA);
98  for (core::Size d = 1; d <= 3; ++d) {
99  coords(d, i) = xyz[d - 1];
100  }
101  }
102 }
103 
105 
106  PROF_START( basic::CA_RMSD_EVALUATION );
107 
108  if ((Size) fragment_coordinates_.size2() < f->get_length()) {
109  fragment_coordinates_.redimension(3, f->get_length(), 0.0);
110  frag_pos_coordinates_.redimension(3, f->get_length(), 0.0);
111  }
112  for (Size i = 1; i <= f->get_length(); i++) {
113  VallChunkOP chunk = f->get_chunk();
114  Size qindex = i + f->get_first_index_in_query() - 1;
115  VallResidueOP r = chunk->at( f->get_first_index_in_vall() + i - 1 );
116  fragment_coordinates_(1, i) = r->x();
118  fragment_coordinates_(2, i) = r->y();
120  fragment_coordinates_(3, i) = r->z();
122  }
123  Real rms = numeric::model_quality::rms_wrapper(f->get_length(),
125 
126  empty_map->set_score_component(rms, id_);
127  PROF_STOP( basic::CA_RMSD_EVALUATION );
128  if ((rms > lowest_acceptable_value_) && (use_lowest_ == true))
129  return false;
130 
131  return true;
132 }
133 
134 
136 
137  chunk_coordinates_.redimension(3, current_chunk->size());
138  for (core::Size i = 1; i <= current_chunk->size(); i++) {
139  VallResidueOP r = current_chunk->at(i);
140  chunk_coordinates_(1, i) = r->x();
141  chunk_coordinates_(2, i) = r->y();
142  chunk_coordinates_(3, i) = r->z();
143  }
144 }
145 
147  FragmentScoreMapOP scores) {
148 
149  std::string tmp = fragment->get_chunk()->chunk_key();
150  if (tmp.compare(cached_scores_id_) != 0)
151  do_caching(fragment->get_chunk());
152 
153  PROF_START( basic::CA_RMSD_EVALUATION );
154  Size frag_len = fragment->get_length();
155  if ((Size) fragment_coordinates_.size2() < frag_len)
156  fragment_coordinates_.redimension(3, frag_len, 0.0);
157  if ((Size) frag_pos_coordinates_.size2() < frag_len)
158  frag_pos_coordinates_.redimension(3, frag_len, 0.0);
159 
160  for (core::Size i = 1; i <= frag_len; ++i)
161  for (core::Size d = 1; d <= 3; ++d) {
163  + fragment->get_first_index_in_vall() - 1);
165  + fragment->get_first_index_in_query() - 1);
166  }
167 
168  Real rms = numeric::model_quality::rms_wrapper(frag_len,
170 
171  scores->set_score_component(rms, id_);
172  PROF_STOP( basic::CA_RMSD_EVALUATION );
173  if ((rms > lowest_acceptable_value_) && (use_lowest_ == true))
174  return false;
175 
176  return true;
177 }
178 
180 }
181 
183  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP //picker
184  , std::string) {
185 
186  if (option[in::file::native].user()) {
187  trRmsScore
188  << "Reference structure to score fragments by crmsd loaded from: "
189  << option[in::file::native]() << std::endl;
190  core::pose::PoseOP nativePose = new core::pose::Pose;
191  core::import_pose::pose_from_pdb(*nativePose, option[in::file::native]());
192 
193  return (FragmentScoringMethodOP) new FragmentCrmsd(priority,
194  lowest_acceptable_value, use_lowest, nativePose);
195  }
196  if (option[in::file::s].user()) {
197  trRmsScore
198  << "Reference structure to score fragments by crmsd loaded from: "
199  << option[in::file::s]()[1] << std::endl;
200  core::pose::PoseOP nativePose = new core::pose::Pose;
201  core::import_pose::pose_from_pdb(*nativePose, option[in::file::s]()[1]);
202 
203  return (FragmentScoringMethodOP) new FragmentCrmsd(priority,
204  lowest_acceptable_value, use_lowest, nativePose);
205  }
206  if (option[in::file::xyz].user()) {
207 
208  trRmsScore
209  << "Reference structure to score fragments by crmsd loaded from: "
210  << option[in::file::xyz]().c_str() << std::endl;
211  std::string line;
213  // std::istream & input = utility::io::izstream( option[ in::file::xyz ]().c_str() );
214  std::ifstream input( option[ in::file::xyz ]().c_str() );
215 
216  while( getline( input, line ) ) {
217  trRmsScore.Warning << line<<std::endl;
218  if ( line.substr(0,1) == "#" ) continue;
219  std::istringstream line_stream( line );
221  Real x,y,z;
222  line_stream >> x >> y >> z;
223  row.push_back(x);
224  row.push_back(y);
225  row.push_back(z);
226  xyz.push_back( row );
227  }
228  trRmsScore << xyz.size() << " atoms found in the reference" << std::endl;
229 
230  return (FragmentScoringMethodOP) new FragmentCrmsd(priority,
231  lowest_acceptable_value, use_lowest, xyz);
232  }
233  utility_exit_with_message(
234  "Can't read a reference structure. Provide it with in::file::s flag");
235 
236  return NULL;
237 }
238 
239 } // scores
240 } // frag_picker
241 } // protocols