Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FragmentCrmsdResDepth.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/FragmentCrmsdResDepth.cc
10 /// @brief Object that scores a fragment by its crmsd to the native
11 /// @author David E Kim
12 
19 
20 // option key includes
21 #include <basic/options/option.hh>
22 #include <basic/options/keys/OptionKeys.hh>
23 #include <basic/options/keys/in.OptionKeys.gen.hh>
24 
26 #include <basic/Tracer.hh>
27 
28 
29 #include <numeric/model_quality/rms.hh>
30 
31 // utils
32 #include <ObjexxFCL/FArray2D.hh>
33 #include <ObjexxFCL/FArray1D.hh>
34 #include <basic/prof.hh>
35 
36 //Auto Headers
37 #include <core/id/NamedAtomID.hh>
39 #include <core/io/pdb/pose_io.hh>
40 #include <core/pose/Pose.hh>
41 #include <utility/io/izstream.hh>
42 #include <iostream>
43 #include <string>
44 
45 
46 namespace protocols {
47 namespace frag_picker {
48 namespace scores {
49 
50 using namespace basic::options;
51 using namespace basic::options::OptionKeys;
52 
53 static basic::Tracer trRmsScore(
54  "protocols.frag_picker.scores.FragmentCrmsdResDepth");
55 
57 
58 FragmentCrmsdResDepth::FragmentCrmsdResDepth(Size priority, Real lowest_acceptable_value,
59  bool use_lowest, core::pose::PoseOP reference_pose, utility::vector1<core::Real> & query_residue_depth) :
60  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "FragmentCrmsdResDepth") {
61  reference_pose_ = reference_pose;
62  n_atoms_ = reference_pose_->total_residue();
63  reference_coordinates_.redimension(3, n_atoms_, 0.0);
65  weights_.redimension(reference_pose_->total_residue(), 1.0);
66  query_residue_depth_ = query_residue_depth;
67 }
68 
69 FragmentCrmsdResDepth::FragmentCrmsdResDepth(Size priority, Real lowest_acceptable_value, bool use_lowest,
71  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "FragmentCrmsdResDepth") {
72 
73  n_atoms_ = xyz.size();
74  reference_coordinates_.redimension(3, n_atoms_, 0.0);
75  weights_.redimension(n_atoms_, 1.0);
76  for (core::Size i = 1; i <= n_atoms_; i++) {
77  trRmsScore.Debug << i<<" ";
78  for (core::Size d = 1; d <= 3; ++d) {
79  reference_coordinates_(d, i) = xyz[i][d];
80  trRmsScore.Debug <<xyz[i][d]<<" ";
81  }
82  trRmsScore.Debug <<std::endl;
83  }
84  query_residue_depth_ = query_residue_depth;
85 }
86 
88  FArray2_double& coords, Size n_atoms) {
89 
90  trRmsScore.Debug << "Copying coordinates from ... The first residues are: "
91  << pose.residue(1).name3() << " " << pose.residue(2).name3() << " "
92  << pose.residue(3).name3() << std::endl;
93 
94  for (core::Size i = 1; i <= n_atoms; i++) {
95  id::NamedAtomID idCA("CA", i);
96  PointPosition const& xyz = pose.xyz(idCA);
97  for (core::Size d = 1; d <= 3; ++d) {
98  coords(d, i) = xyz[d - 1];
99  }
100  }
101 }
102 
104 
105  PROF_START( basic::CA_RMSD_EVALUATION );
106 
107  Real depth_score = 0;
108 
109  if ((Size) fragment_coordinates_.size2() < f->get_length()) {
110  fragment_coordinates_.redimension(3, f->get_length(), 0.0);
111  frag_pos_coordinates_.redimension(3, f->get_length(), 0.0);
112  }
113  for (Size i = 1; i <= f->get_length(); i++) {
114  Size qindex = i + f->get_first_index_in_query() - 1;
115  VallChunkOP chunk = f->get_chunk();
116  VallResidueOP r = chunk->at( f->get_first_index_in_vall() + i - 1 );
117  fragment_coordinates_(1, i) = r->x();
119  fragment_coordinates_(2, i) = r->y();
121  fragment_coordinates_(3, i) = r->z();
123  // residue depth similarity score from Zhou and Zhou, Proteins 2005
124  // (exp( - Dquery / 2.8) - exp( - Dtemplate / 2.8))**2
125  Real depthdiff = exp(-1*query_residue_depth_[qindex]/2.8) - exp(-1*r->depth()/2.8);
126  depth_score += depthdiff*depthdiff;
127  }
128  Real rms = numeric::model_quality::rms_wrapper(f->get_length(),
130 
131  // similarity score from Zhou and Zhou, Proteins 2005
132  // rmsd**2 + weight*depth_score with weight = 10
133  Real totalScore = rms*rms + 10*depth_score;
134 
135  empty_map->set_score_component(totalScore, id_);
136  PROF_STOP( basic::CA_RMSD_EVALUATION );
137  if ((rms > lowest_acceptable_value_) && (use_lowest_ == true))
138  return false;
139 
140  return true;
141 }
142 
143 
145 
146  chunk_coordinates_.redimension(3, current_chunk->size());
147  for (core::Size i = 1; i <= current_chunk->size(); i++) {
148  VallResidueOP r = current_chunk->at(i);
149  chunk_coordinates_(1, i) = r->x();
150  chunk_coordinates_(2, i) = r->y();
151  chunk_coordinates_(3, i) = r->z();
152  }
153 }
154 
156  FragmentScoreMapOP scores) {
157 
158  std::string tmp = fragment->get_chunk()->chunk_key();
159  if (tmp.compare(cached_scores_id_) != 0)
160  do_caching(fragment->get_chunk());
161 
162  Real depth_score = 0;
163 
164  PROF_START( basic::CA_RMSD_EVALUATION );
165  Size frag_len = fragment->get_length();
166  if ((Size) fragment_coordinates_.size2() < frag_len)
167  fragment_coordinates_.redimension(3, frag_len, 0.0);
168  if ((Size) frag_pos_coordinates_.size2() < frag_len)
169  frag_pos_coordinates_.redimension(3, frag_len, 0.0);
170 
171  for (core::Size i = 1; i <= frag_len; ++i) {
172  Size qindex = i + fragment->get_first_index_in_query() - 1;
173  Size vindex = i + fragment->get_first_index_in_vall() - 1;
174  for (core::Size d = 1; d <= 3; ++d) {
175  fragment_coordinates_(d, i) = chunk_coordinates_(d, vindex);
177  }
178  // residue depth similarity score from Zhou and Zhou, Proteins 2005
179  // (exp( - Dquery / 2.8) - exp( - Dtemplate / 2.8))**2
180  Real depthdiff = exp(-1*query_residue_depth_[qindex]/2.8) -
181  exp(-1*fragment->get_chunk()->at( vindex )->depth()/2.8);
182  depth_score += depthdiff*depthdiff;
183  }
184 
185  Real rms = numeric::model_quality::rms_wrapper(frag_len,
187 
188  // similarity score from Zhou and Zhou, Proteins 2005
189  // rmsd**2 + weight*depth_score with weight = 10
190  Real totalScore = rms*rms + 10*depth_score;
191 
192  scores->set_score_component(totalScore, id_);
193  PROF_STOP( basic::CA_RMSD_EVALUATION );
194  if ((rms > lowest_acceptable_value_) && (use_lowest_ == true))
195  return false;
196 
197  return true;
198 }
199 
201 }
202 
204  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP picker, std::string) {
205 
206  if (option[in::file::native].user()) {
207  trRmsScore
208  << "Reference structure to score fragments by crmsd loaded from: "
209  << option[in::file::native]() << std::endl;
210  core::pose::PoseOP nativePose = new core::pose::Pose;
211  core::import_pose::pose_from_pdb(*nativePose, option[in::file::native]());
212 
213  if (nativePose->total_residue() != picker->get_query_residue_depth().size())
214  utility_exit_with_message("MakeFragmentCrmsdResDepth native total residue != query residue depth length");
215 
216  return (FragmentScoringMethodOP) new FragmentCrmsdResDepth(priority,
217  lowest_acceptable_value, use_lowest, nativePose, picker->get_query_residue_depth());
218  }
219  if (option[in::file::s].user()) {
220  trRmsScore
221  << "Reference structure to score fragments by crmsd loaded from: "
222  << option[in::file::s]()[1] << std::endl;
223  core::pose::PoseOP nativePose = new core::pose::Pose;
224  core::import_pose::pose_from_pdb(*nativePose, option[in::file::s]()[1]);
225 
226  if (nativePose->total_residue() != picker->get_query_residue_depth().size())
227  utility_exit_with_message("MakeFragmentCrmsdResDepth native total residue != query residue depth length");
228 
229  return (FragmentScoringMethodOP) new FragmentCrmsdResDepth(priority,
230  lowest_acceptable_value, use_lowest, nativePose, picker->get_query_residue_depth());
231  }
232  if (option[in::file::xyz].user()) {
233 
234  trRmsScore
235  << "Reference structure to score fragments by crmsd loaded from: "
236  << option[in::file::xyz]().c_str() << std::endl;
237  std::string line;
239  // std::istream & input = utility::io::izstream( option[ in::file::xyz ]().c_str() );
240  std::ifstream input( option[ in::file::xyz ]().c_str() );
241 
242  while( getline( input, line ) ) {
243  trRmsScore.Warning << line<<std::endl;
244  if ( line.substr(0,1) == "#" ) continue;
245  std::istringstream line_stream( line );
247  Real x,y,z;
248  line_stream >> x >> y >> z;
249  row.push_back(x);
250  row.push_back(y);
251  row.push_back(z);
252  xyz.push_back( row );
253  }
254  trRmsScore << xyz.size() << " atoms found in the reference" << std::endl;
255 
256  if (xyz.size() != picker->get_query_residue_depth().size())
257  utility_exit_with_message("MakeFragmentCrmsdResDepth xyz size != query residue depth length");
258 
259  return (FragmentScoringMethodOP) new FragmentCrmsdResDepth(priority,
260  lowest_acceptable_value, use_lowest, xyz, picker->get_query_residue_depth());
261  }
262  utility_exit_with_message(
263  "Can't read a reference structure. Provide it with in::file::s flag");
264 
265  return NULL;
266 }
267 
268 } // scores
269 } // frag_picker
270 } // protocols