Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PCS_FragDistance.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 Scores fragments by disulfide-linke Calpha distances
11 /// @author Robert Vernon
12 
14 
19 
20 #include <basic/options/option.hh>
21 #include <basic/options/keys/OptionKeys.hh>
22 #include <basic/options/keys/in.OptionKeys.gen.hh>
23 
24 // AUTO-REMOVED #include <core/io/raw_data/DisulfideFile.hh>
25 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
26 //#include <core/util/Tracer.hh>
27 
28 #include <utility/io/izstream.hh>
29 
30 // utils
31 #include <ObjexxFCL/FArray1D.hh>
32 //#include <core/util/prof.hh>
33 
34 // AUTO-REMOVED #include <boost/tuple/tuple.hpp>
35 
36 #include <utility/vector1.hh>
37 
38 
39 namespace protocols {
40 namespace frag_picker {
41 namespace scores {
42 
43 using namespace basic::options;
44 using namespace basic::options::OptionKeys;
45 
46  PCS_FragDistance::PCS_FragDistance(Size priority, Real lowest_acceptable_value, bool use_lowest,
47  ObjexxFCL::FArray2D_double target_ca_dev,
48  ObjexxFCL::FArray2D_double target_ca_dist, Size largest_fragment,
49  Size max_length) :
50  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest, "PCS_FragDistance"),
51  target_ca_dev_(target_ca_dev),
52  target_ca_dist_(target_ca_dist),
53  largest_fragment_(largest_fragment),
54  max_length_(max_length)
55 {
56 }
57 
59 
60  n_res_ = current_chunk->size();
61 
62  chunk_ca_distances_.redimension(n_res_, n_res_, 0.0);
63  for (Size x = 1; x <= n_res_; ++x) {
64  VallResidueOP xr = current_chunk->at(x);
65 
66  for (Size y = x - largest_fragment_; (y <= x + largest_fragment_) && (y <= n_res_); ++y) {
67  //for (Size y = 1; y <= n_res_; ++y) {
68  if (y > 0) {
69  VallResidueOP yr = current_chunk->at(y);
70 
71  Real distance = sqrt( pow( xr->x() - yr->x(), 2) + pow( xr->y() - yr->y(), 2) + pow( xr->z() - yr->z(), 2) );
73  }
74  }
75  }
76 }
77 
79  return cached_score( fragment, scores );
80 }
81 
83 
84  std::string tmp = fragment->get_chunk()->chunk_key();
85  if (tmp.compare(cached_scores_id_) != 0) {
86  do_caching(fragment->get_chunk());
87  cached_scores_id_ = tmp;
88  }
89 
90  //Size offset_q = fragment->get_first_index_in_query() - 1;
91  //Size offset_v = fragment->get_first_index_in_vall() - 1;
92 
93  //Goes from first res - 2 to last res + 2
94  Size offset_q = fragment->get_first_index_in_query() - 1;
95  Size offset_v = fragment->get_first_index_in_vall() - 1;
96  Real score = 0.0;
97 
98  //for (Size ix = 1; ix < fragment->get_length(); ++ix) {
99  // for (Size iy = ix+1; iy < fragment->get_length(); ++iy) {
100 
101  for (Size ix = 1; ix <= fragment->get_length()+3; ++ix) {
102  for (Size iy = ix+1; iy <= fragment->get_length()+4; ++iy) {
103 
104  Size res1 = ix+offset_q;
105  Size res2 = iy+offset_q;
106 
107  Size v1 = ix+offset_v;
108  Size v2 = iy+offset_v;
109 
110  if ( ( res1 >= 3) && (res2 <= max_length_ + 2) &&
111  ( v1 >= 3) && (v2 <= n_res_ + 2) ) {
112 
113  res1 -= 2;
114  res2 -= 2;
115  v1 -= 2;
116  v2 -= 2;
117 
118  //std::cout << "HEYO " << res1 << " " << res2 << " " << v1 << " " << v2 << " " << max_length_ << " " << n_res_ << std::endl;
119 
120  if ( !((target_ca_dist_(res1,res2) == 0.0) && (target_ca_dev_(res1,res2) == 0.0)) ) {
121 
122  Real dev(target_ca_dev_(res1,res2));
123  Real diff(abs(target_ca_dist_(res1,res2) - chunk_ca_distances_(v1,v2)));
124 
125  Real sig_function = ( 1 / ( 1 + exp(-2*(diff/dev) + 5 )));// + (1 / ( 1 + exp(+2*(diff/dev) + 5 )));
126 
127  //std::cout << "HEYO " << res1 << " " << res2 << " " << target_ca_dev_(res1,res2) << " " << target_ca_dev_(res1,res2) << " " << chunk_ca_distances_(v1,v2) << " " << diff << " " << dev << " " << sig_function << std::endl;
128 
129  score += sig_function;
130  }
131  }
132  }
133  }
134 
135  score /= (Real) fragment->get_length();
136 
137  scores->set_score_component(score, id_);
138  //PROF_STOP( core::util::FRAGMENTPICKING_PHIPSI_SCORE );
139  if ((score > lowest_acceptable_value_) && (use_lowest_ == true))
140  return false;
141 
142  return true;
143 }
144 
146 }
147 
148 /// @brief Creates a PCS_FragDistance scoring method
149 /// @param priority - priority of the scoring method. The higher value the earlier the score
150 /// will be evaluated
151 /// @param lowest_acceptable_value - if a calculated score is higher than this value,
152 /// fragment will be neglected
153 /// @param FragmentPickerOP object - not used
154 /// @param line - the relevant line extracted from the scoring configuration file that defines this scoring method
155 /// It could look like: "PCS_FragDistance 140 -5.0 100.0 additional_string"
156 /// where 140, -5.0 && 100.0 are priority, weight && treshold, respectively.
157 /// The additional string may be:
158 /// - empty: then the maker tries to create a scoring object from a TALOS file
159 /// trying in::file::talos_phi_psi flag. If fails, will try to use a pose from in::file::s
160 /// - a pdb file, pdb extension is necessary. This will create a pose && steal Phi && Psi
161 /// - a TALOS file with Phi/Psi prediction (tab extension is necessary)
163  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP picker//picker
164  , std::string )
165 {
166 
167  std::string target( picker->get_query_seq_string());
168 
169  Size max_length = target.length();
170 
171  ObjexxFCL::FArray2D_double target_ca_dev;
172  ObjexxFCL::FArray2D_double target_ca_dist;
173 
174  target_ca_dev.redimension(max_length, max_length, 0.0);
175  target_ca_dist.redimension(max_length, max_length, 0.0);
176 
177 
178  if (option[in::file::PCS_frag_cst].user()) {
179 
180  utility::io::izstream data( option[ in::file::PCS_frag_cst ]() );
181 
182  // mjo commenting out 'max_data_res' because it is not used and casuses a warning
183  //Size max_data_res(0);
184  std::string line;
185  while (!data.eof()) {
186  getline(data, line);
187  std::istringstream line_stream(line);
188 
189  Size resX, resY;
190  Real dist, dev;
191 
192  line_stream >> resX >> resY >> dist >> dev;
193 
194  //if ( dev < 0.3 ) {
195  // dev = 0.3;
196  //This was the lowest dev I observed during training.
197  //The score has not been tested for lower values and
198  //therefore you should not expect it to work for lower values!
199  //}
200 
201  target_ca_dist(resX,resY) = dist;
202  target_ca_dev(resX,resY) = dev;
203  }
204 
205  Size largest_fragment(0);
206  for ( Size i = 1; i <= picker->frag_sizes_.size(); ++i ) {
207  if ( picker->frag_sizes_[i] > largest_fragment ) largest_fragment = picker->frag_sizes_[i];
208  }
209 
210  runtime_assert( largest_fragment > 0 );
211 
212  return (FragmentScoringMethodOP) new PCS_FragDistance(priority, lowest_acceptable_value, use_lowest,
213  target_ca_dev, target_ca_dist, largest_fragment, max_length);
214  }
215 
216  utility_exit_with_message(
217  "Can't read PCS_frag_cst file. Provide a connectivity file with -in::PCS_frag_cst <file>\n");
218 
219  return NULL;
220 
221 }
222 
223 } // scores
224 } // frag_picker
225 } // protocols
226