Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FragmentDME.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/FragmentDME.cc
10 /// @brief Object that scores a fragment by its Distance Matrix Error (DME) to the native
11 /// @author David E Kim
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 trDMEScore(
57  "protocols.frag_picker.scores.FragmentDME");
58 
60 
61 FragmentDME::FragmentDME(Size priority, Real lowest_acceptable_value,
62  bool use_lowest, core::pose::PoseOP reference_pose) :
63  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "FragmentDME") {
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 FragmentDME::FragmentDME(Size priority, Real lowest_acceptable_value, bool use_lowest,
73  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "FragmentDME") {
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  trDMEScore.Debug << i<<" ";
80  for (core::Size d = 1; d <= 3; ++d) {
81  reference_coordinates_(d, i) = xyz[i][d];
82  trDMEScore.Debug <<xyz[i][d]<<" ";
83  }
84  trDMEScore.Debug <<std::endl;
85  }
86 }
87 
89  FArray2_double& coords, Size n_atoms) {
90 
91  trDMEScore.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_DME_EVALUATION );
107  Real dme=0.0;
108  Real dme_native =99.0;
109  Size tot_pair=0;
110  for (Size i = 1; i<=f->get_length(); ++i)
111  tot_pair = tot_pair+i;
112  if (tot_pair > 0) {
113  VallChunkOP chunk = f->get_chunk();
114  for (Size i = 1; i<=f->get_length(); ++i) {
115  VallResidueOP ri = chunk->at( f->get_first_index_in_vall() + i - 1 );
116  Size qindexi = i + f->get_first_index_in_query() - 1;
117  for (Size j = i+1; j<=f->get_length(); ++j) {
118  VallResidueOP rj = chunk->at( f->get_first_index_in_vall() + j - 1 );
119  Real xdiff = ri->x()-rj->x();
120  Real ydiff = ri->y()-rj->y();
121  Real zdiff = ri->z()-rj->z();
122  Real dist1 = xdiff*xdiff + ydiff*ydiff + zdiff*zdiff;
123  Size qindexj = j + f->get_first_index_in_query() - 1;
124  Real xrdiff = reference_coordinates_(1, qindexi)-reference_coordinates_(1, qindexj);
125  Real yrdiff = reference_coordinates_(2, qindexi)-reference_coordinates_(2, qindexj);
126  Real zrdiff = reference_coordinates_(3, qindexi)-reference_coordinates_(3, qindexj);
127  Real dist2 = xrdiff*xrdiff + yrdiff*yrdiff + zrdiff*zrdiff;
128  dme += (sqrt(dist1)-sqrt(dist2))*(sqrt(dist1)-sqrt(dist2));
129  }
130  }
131  dme_native=sqrt(dme/tot_pair);
132  }
133  empty_map->set_score_component(dme_native, id_);
134  PROF_STOP( basic::CA_DME_EVALUATION );
135  if ((dme_native > lowest_acceptable_value_) && (use_lowest_ == true))
136  return false;
137 
138  return true;
139 }
140 
141 
143 
144  chunk_coordinates_.redimension(3, current_chunk->size());
145  for (core::Size i = 1; i <= current_chunk->size(); i++) {
146  VallResidueOP r = current_chunk->at(i);
147  chunk_coordinates_(1, i) = r->x();
148  chunk_coordinates_(2, i) = r->y();
149  chunk_coordinates_(3, i) = r->z();
150  }
151 }
152 
154  FragmentScoreMapOP scores) {
155 
156  std::string tmp = fragment->get_chunk()->chunk_key();
157  if (tmp.compare(cached_scores_id_) != 0)
158  do_caching(fragment->get_chunk());
159 
160  PROF_START( basic::CA_DME_EVALUATION );
161 
162  Real dme=0.0;
163  Real dme_native =99.0;
164  Size tot_pair=0;
165  for (Size i = 1; i<=fragment->get_length(); ++i)
166  tot_pair = tot_pair+i;
167  if (tot_pair > 0) {
168  for (Size i = 1; i<=fragment->get_length(); ++i) {
169  Size qindexi = i + fragment->get_first_index_in_query() - 1;
170  Size vindexi = i + fragment->get_first_index_in_vall() - 1;
171  for (Size j = i+1; j<=fragment->get_length(); ++j) {
172  Size qindexj = j + fragment->get_first_index_in_query() - 1;
173  Size vindexj = j + fragment->get_first_index_in_vall() - 1;
174  Real xdiff = chunk_coordinates_(1, vindexi)-chunk_coordinates_(1, vindexj);
175  Real ydiff = chunk_coordinates_(2, vindexi)-chunk_coordinates_(2, vindexj);
176  Real zdiff = chunk_coordinates_(3, vindexi)-chunk_coordinates_(3, vindexj);
177  Real dist1 = xdiff*xdiff + ydiff*ydiff + zdiff*zdiff;
178  Real xrdiff = reference_coordinates_(1, qindexi)-reference_coordinates_(1, qindexj);
179  Real yrdiff = reference_coordinates_(2, qindexi)-reference_coordinates_(2, qindexj);
180  Real zrdiff = reference_coordinates_(3, qindexi)-reference_coordinates_(3, qindexj);
181  Real dist2 = xrdiff*xrdiff + yrdiff*yrdiff + zrdiff*zrdiff;
182  dme += (sqrt(dist1)-sqrt(dist2))*(sqrt(dist1)-sqrt(dist2));
183  }
184  }
185  dme_native=sqrt(dme/tot_pair);
186  }
187 
188  scores->set_score_component(dme_native, id_);
189  PROF_STOP( basic::CA_DME_EVALUATION );
190  if ((dme_native > lowest_acceptable_value_) && (use_lowest_ == true))
191  return false;
192 
193  return true;
194 }
195 
197 }
198 
200  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP //picker
201  , std::string) {
202 
203  if (option[in::file::native].user()) {
204  trDMEScore
205  << "Reference structure to score fragments by DME loaded from: "
206  << option[in::file::native]() << std::endl;
207  core::pose::PoseOP nativePose = new core::pose::Pose;
208  core::import_pose::pose_from_pdb(*nativePose, option[in::file::native]());
209 
210  return (FragmentScoringMethodOP) new FragmentDME(priority,
211  lowest_acceptable_value, use_lowest, nativePose);
212  }
213  if (option[in::file::s].user()) {
214  trDMEScore
215  << "Reference structure to score fragments by DME loaded from: "
216  << option[in::file::s]()[1] << std::endl;
217  core::pose::PoseOP nativePose = new core::pose::Pose;
218  core::import_pose::pose_from_pdb(*nativePose, option[in::file::s]()[1]);
219 
220  return (FragmentScoringMethodOP) new FragmentDME(priority,
221  lowest_acceptable_value, use_lowest, nativePose);
222  }
223  if (option[in::file::xyz].user()) {
224 
225  trDMEScore
226  << "Reference structure to score fragments by DME loaded from: "
227  << option[in::file::xyz]().c_str() << std::endl;
228  std::string line;
230  // std::istream & input = utility::io::izstream( option[ in::file::xyz ]().c_str() );
231  std::ifstream input( option[ in::file::xyz ]().c_str() );
232 
233  while( getline( input, line ) ) {
234  trDMEScore.Warning << line<<std::endl;
235  if ( line.substr(0,1) == "#" ) continue;
236  std::istringstream line_stream( line );
238  Real x,y,z;
239  line_stream >> x >> y >> z;
240  row.push_back(x);
241  row.push_back(y);
242  row.push_back(z);
243  xyz.push_back( row );
244  }
245  trDMEScore << xyz.size() << " atoms found in the reference" << std::endl;
246 
247  return (FragmentScoringMethodOP) new FragmentDME(priority,
248  lowest_acceptable_value, use_lowest, xyz);
249  }
250  utility_exit_with_message(
251  "Can't read a reference structure. Provide it with in::file::s flag");
252 
253  return NULL;
254 }
255 
256 } // scores
257 } // frag_picker
258 } // protocols