Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VallResidue.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 and 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 and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file protocols/frag_picker/VallResidue.cc
10 /// @brief class for managing a line of the Vall fragment library
11 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
12 
13 // unit headers
15 
16 // project headers
17 #include <core/chemical/AA.hh>
20 
21 // boost headers
22 #include <boost/type_traits.hpp>
23 
24 // utility headers
25 #include <utility/pointer/owning_ptr.hh>
26 #include <utility/exit.hh>
27 
28 // C++ headers
29 #include <cstdio>
30 #include <iostream>
31 #include <sstream>
32 
33 // Tracer
34 #include <basic/Tracer.hh>
35 
36 namespace protocols {
37 namespace frag_picker {
38 
39 static basic::Tracer TR("protocols.frag_picker.VallResidue");
40 
41 // static initialization
43 
44 /// @brief default constructor
46  utility::pointer::ReferenceCount(), key_(0),id_(""),profile_(20),profile_struct_(20),sec_shift_data_(0),
47  position_index_(0), section_index_(0) {
48 }
49 
50 /// @brief string constructor
52  if (line.length() > 300)
54  else if (line.length() > 240)
55  fill_from_string_cs(line);
56  else if (line.length() > 110)
57  fill_from_string(line);
58  else
60 }
61 
62 /// @brief copy constructor
64  utility::pointer::ReferenceCount(),
65  key_(rval.key_),
66  id_(rval.id_),
67  aa_(rval.aa_),
68  ss_(rval.ss_),
69  ss_str_(rval.ss_str_),
70  resi_(rval.resi_),
71  bF_(rval.bF_),
72  x_(rval.x_),
73  y_(rval.y_),
74  z_(rval.z_),
75  cbx_(rval.cbx_),
76  cby_(rval.cby_),
77  cbz_(rval.cbz_),
78  cenx_(rval.cenx_),
79  ceny_(rval.ceny_),
80  cenz_(rval.cenz_),
81  phi_(rval.phi_),
82  psi_(rval.psi_),
83  omega_(rval.omega_),
84  sa_(rval.sa_),
85  sa_norm_(rval.sa_norm_),
86  dssp_phi_(rval.dssp_phi_),
87  dssp_psi_(rval.dssp_psi_),
88  nali_(rval.nali_),
89  profile_(rval.profile_),
90  profile_struct_(rval.profile_struct_),
91  sec_shift_data_(rval.sec_shift_data_),
92  position_index_(rval.position_index_),
93  section_index_(rval.section_index_),
94  all_atom_residue_depth_(rval.all_atom_residue_depth_){
95 }
96 
97 /// @brief default destructor
99 }
100 
101 /// @brief copy assignment
103  if (this != &rval) {
104  id_ = rval.id_;
105  aa_ = rval.aa_;
106  ss_ = rval.ss_;
107  ss_str_ = rval.ss_str_;
108  resi_ = rval.resi_;
109  bF_ = rval.bF_;
110  x_ = rval.x_;
111  y_ = rval.y_;
112  z_ = rval.z_;
113  cbx_ = rval.cbx_;
114  cby_ = rval.cby_;
115  cbz_ = rval.cbz_;
116  cenx_ = rval.cenx_;
117  ceny_ = rval.ceny_;
118  cenz_ = rval.cenz_;
119  dssp_phi_ = rval.dssp_phi_;
120  dssp_psi_ = rval.dssp_psi_;
121  sa_ = rval.sa_;
122  sa_norm_ = rval.sa_norm_;
123  nali_ = rval.nali_;
124  phi_ = rval.phi_;
125  psi_ = rval.psi_;
126  omega_ = rval.omega_;
127  profile_ = rval.profile_;
132  }
133  return *this;
134 }
135 
136 /// @brief build a BBTorsionSRFD from this page
138  BBTorsionSRFD * srfd = new BBTorsionSRFD();
139 
140  srfd->set_sequence(aa_);
141  srfd->set_secstruct(ss_);
142 
143  // currently, phi = 1, psi = 2, omega = 3
144  // see BBTorsionSRFD and Pose implemenations for details
145  srfd->set_torsion(1, phi_);
146  srfd->set_torsion(2, psi_);
147  srfd->set_torsion(3, omega_);
148  srfd->set_coordinates( x_, y_, z_ );
149 
150  return srfd;
151 }
152 
153 /// @brief fill internal data from string
154 /// @details Values are delimited by whitespace. Ordering is:
155 /// <tt> id aa ss resi dummy dummy x y z phi psi omega dummy dummy dummy dummy (aa profile_info, 20 columns) BFactor </tt>
157 
158  char id[] = { '\0', '\0', '\0', '\0', '\0', '\0' }; // 5 char + 1 null termination
159 
160  static String format_here = format_string();
161 
162  // Use sscanf here; Vall is huge and istringstream is way too slow.
163  // *One* sscanf call per line, multiple calls decreases performance!
164  std::sscanf(line.c_str(), format_here.c_str(), &id, &aa_, &ss_, &resi_, &x_,
165  &y_, &z_, &phi_, &psi_, &omega_, &profile_[order_[1]],
166  &profile_[order_[2]], &profile_[order_[3]], &profile_[order_[4]],
167  &profile_[order_[5]], &profile_[order_[6]], &profile_[order_[7]],
168  &profile_[order_[8]], &profile_[order_[9]], &profile_[order_[10]],
169  &profile_[order_[11]], &profile_[order_[12]],
170  &profile_[order_[13]], &profile_[order_[14]],
171  &profile_[order_[15]], &profile_[order_[16]],
172  &profile_[order_[17]], &profile_[order_[18]],
173  &profile_[order_[19]], &profile_[order_[20]]);
174  ss_str_ = ss_; // this vall format does not use an STR alphabet so just set as ss_
175  id_ = id;
176 }
177 
178 /// @brief fill internal data from string
179 /// @details Values are delimited by whitespace. Ordering is:
180 /// <tt> id aa ss resi dummy dummy x y z phi psi omega dummy dummy dummy dummy (aa profile_info, 20 columns) (CS data, 12 columns)</tt>
182 
183  char id[] = { '\0', '\0', '\0', '\0', '\0', '\0' }; // 5 char + 1 null termination
184  //std::cerr<<line<<std::endl;
185  sec_shift_data_.resize(12);
186 
187  // Use sscanf here; Vall is huge and istringstream is way too slow.
188  // *One* sscanf call per line, multiple calls decreases performance!
189 
190  static String format_here = format_string_cs();
191 
192  std::sscanf(line.c_str(), format_here.c_str(), &id, &aa_, &ss_, &resi_, &bF_,
193  &x_, &y_, &z_, &phi_, &psi_, &omega_, &profile_[order_[1]],
194  &profile_[order_[2]], &profile_[order_[3]], &profile_[order_[4]],
195  &profile_[order_[5]], &profile_[order_[6]], &profile_[order_[7]],
196  &profile_[order_[8]], &profile_[order_[9]], &profile_[order_[10]],
197  &profile_[order_[11]], &profile_[order_[12]],
198  &profile_[order_[13]], &profile_[order_[14]],
199  &profile_[order_[15]], &profile_[order_[16]],
200  &profile_[order_[17]], &profile_[order_[18]],
201  &profile_[order_[19]], &profile_[order_[20]],
202  &sec_shift_data_[1], &sec_shift_data_[2], &sec_shift_data_[3],
203  &sec_shift_data_[4], &sec_shift_data_[5], &sec_shift_data_[6],
204  &sec_shift_data_[7], &sec_shift_data_[8], &sec_shift_data_[9],
205  &sec_shift_data_[10], &sec_shift_data_[11], &sec_shift_data_[12]);
206  ss_str_ = ss_; // this vall format does not use an STR alphabet so just set as ss_
207  id_ = id;
208 }
209 
210 /// @brief fill internal data from string
211 /// @details Values are delimited by whitespace. Ordering is:
212 /// <tt> id aa ss resi dummy dummy x y z cbz cby cbz cenx ceny cenz phi psi omega dssp_phi dssp_psi sa nali (aa profile_info, 20 columns) BFactor </tt>
214 
215  char id[] = { '\0', '\0', '\0', '\0', '\0', '\0' }; // 5 char + 1 null termination
216 
217  static String format_here = format_string_version1();
218 
219  // Use sscanf here; Vall is huge and istringstream is way too slow.
220  // *One* sscanf call per line, multiple calls decreases performance!
221  std::sscanf(line.c_str(), format_here.c_str(), &id, &aa_, &ss_str_, &resi_, &bF_, &x_,
222  &y_, &z_, &cbx_, &cby_, &cbz_, &cenx_, &ceny_, &cenz_, &phi_, &psi_, &omega_, &dssp_phi_, &dssp_psi_, &sa_, &nali_, &profile_[order_[1]],
223  &profile_[order_[2]], &profile_[order_[3]], &profile_[order_[4]],
224  &profile_[order_[5]], &profile_[order_[6]], &profile_[order_[7]],
225  &profile_[order_[8]], &profile_[order_[9]], &profile_[order_[10]],
226  &profile_[order_[11]], &profile_[order_[12]],
227  &profile_[order_[13]], &profile_[order_[14]],
228  &profile_[order_[15]], &profile_[order_[16]],
229  &profile_[order_[17]], &profile_[order_[18]],
230  &profile_[order_[19]], &profile_[order_[20]],
231  &profile_struct_[order_[1]],&profile_struct_[order_[2]],
232  &profile_struct_[order_[3]], &profile_struct_[order_[4]],
233  &profile_struct_[order_[5]], &profile_struct_[order_[6]],
234  &profile_struct_[order_[7]], &profile_struct_[order_[8]],
235  &profile_struct_[order_[9]], &profile_struct_[order_[10]],
236  &profile_struct_[order_[11]], &profile_struct_[order_[12]],
237  &profile_struct_[order_[13]], &profile_struct_[order_[14]],
238  &profile_struct_[order_[15]], &profile_struct_[order_[16]],
239  &profile_struct_[order_[17]], &profile_struct_[order_[18]],
240  &profile_struct_[order_[19]], &profile_struct_[order_[20]]);
241 
243  set_ss_from_str();
244  id_ = id;
245 }
246 
248 
249  char id[] = { '\0', '\0', '\0', '\0', '\0', '\0' }; // 5 char + 1 null termination
250 
251  static String format_here = format_string_residue_depth_version1();
252 
253  std::sscanf(line.c_str(), format_here.c_str(), &id, &aa_, &resi_, &x_,
255  id_ = id;
256  ss_ = 'L'; // placeholder
257  ss_str_ = 'C'; // placeholder
258 }
259 
260 
261 /// @brief return a vector specifying the order of profile data in Vall
264 
285 
286  return order;
287 }
288 
289 /// @brief return a formatting string for fill_from_string() dependent
290 /// upon actual type of core::Real and core::Size
291 /// @remarks This is necessary for sscanf; wrong type can give wrong
292 /// input.
294  using boost::is_same;
295 
296  // resolve types
297  bool const is_ulong = is_same<Size, unsigned long>::value;
298  bool const is_double = is_same<Real, double>::value;
299 
300  // format w/ the following order:
301  std::ostringstream s;
302  s << "%s" << " "; // (string) id
303  s << "%c" << " "; // (char) aa
304  s << "%c" << " "; // (char) ss
305  s << (is_ulong ? "%lu" : "%u") << " "; // (int) resi
306  s << "%*s" << " "; // (string) dummy
307  s << "%*s" << " ";// (string) dummy
308  s << (is_double ? "%lf" : "%f") << " "; // (real) x
309  s << (is_double ? "%lf" : "%f") << " "; // (real) y
310  s << (is_double ? "%lf" : "%f") << " "; // (real) z
311  s << (is_double ? "%lf" : "%f") << " "; // (real) phi
312  s << (is_double ? "%lf" : "%f") << " "; // (real) psi
313  s << (is_double ? "%lf" : "%f") << " "; // (real) omega
314  s << "%*s" << " "; // (string) dummy
315  s << "%*s" << " "; // (string) dummy
316  s << "%*s" << " "; // (string) dummy
317  s << "%*s"; // (string) dummy
318 
319  // (real) (aa profile_info, 20 columns)
320  for (Size i = 0; i < 20; ++i) {
321  s << " " << (is_double ? "%lf" : "%f");
322  }
323 
324  TR.Debug << "vall line format (no CS) is:\n"<<s.str()<<std::endl;
325 
326  return s.str();
327 }
328 
330  using boost::is_same;
331 
332  // resolve types
333  bool const is_ulong = is_same<Size, unsigned long>::value;
334  bool const is_double = is_same<Real, double>::value;
335 
336  // format w/ the following order:
337  std::ostringstream s;
338  s << "%s" << " "; // (string) id
339  s << "%c" << " "; // (char) aa
340  s << "%c" << " "; // (char) ss
341  s << (is_ulong ? "%lu" : "%u") << " "; // (int) resi
342  s << "%*s" << " "; // (string) dummy
343  s << "%*s" << " ";// (string) dummy
344  s << (is_double ? "%lf" : "%f") << " "; // (real) b factor
345  s << (is_double ? "%lf" : "%f") << " "; // (real) x
346  s << (is_double ? "%lf" : "%f") << " "; // (real) y
347  s << (is_double ? "%lf" : "%f") << " "; // (real) z
348  s << (is_double ? "%lf" : "%f") << " "; // (real) phi
349  s << (is_double ? "%lf" : "%f") << " "; // (real) psi
350  s << (is_double ? "%lf" : "%f") << " "; // (real) omega
351 
352  // (real) (aa profile_info, 20 columns)
353  for (Size i = 0; i < 20; ++i) {
354  s << " " << (is_double ? "%lf" : "%f");
355  }
356 
357  // (real) (CS data, 12 columns)
358  for (Size i = 0; i < 12; ++i) {
359  s << " " << (is_double ? "%lf" : "%f");
360  }
361 
362 
363  TR.Debug << "vall line format (WITH CS) is:\n"<<s.str()<<std::endl;
364  return s.str();
365 }
366 
367 /// @brief return a formatting string for fill_from_string_version1() dependent
368 /// upon actual type of core::Real and core::Size
369 /// @remarks This is necessary for sscanf; wrong type can give wrong
370 /// input.
372  using boost::is_same;
373 
374  // resolve types
375  bool const is_ulong = is_same<Size, unsigned long>::value;
376  bool const is_double = is_same<Real, double>::value;
377 
378  // format w/ the following order:
379  std::ostringstream s;
380  s << "%s" << " "; // (string) id
381  s << "%c" << " "; // (char) aa
382  s << "%c" << " "; // (char) ss
383  s << (is_ulong ? "%lu" : "%u") << " "; // (int) resi
384  s << (is_double ? "%lf" : "%f") << " "; // (real) avg bfactor
385  s << (is_double ? "%lf" : "%f") << " "; // (real) x
386  s << (is_double ? "%lf" : "%f") << " "; // (real) y
387  s << (is_double ? "%lf" : "%f") << " "; // (real) z
388  s << (is_double ? "%lf" : "%f") << " "; // (real) cbx
389  s << (is_double ? "%lf" : "%f") << " "; // (real) cby
390  s << (is_double ? "%lf" : "%f") << " "; // (real) cbz
391  s << (is_double ? "%lf" : "%f") << " "; // (real) cenx
392  s << (is_double ? "%lf" : "%f") << " "; // (real) ceny
393  s << (is_double ? "%lf" : "%f") << " "; // (real) cenz
394  s << (is_double ? "%lf" : "%f") << " "; // (real) phi
395  s << (is_double ? "%lf" : "%f") << " "; // (real) psi
396  s << (is_double ? "%lf" : "%f") << " "; // (real) omega
397  s << (is_double ? "%lf" : "%f") << " "; // (real) dssp_phi
398  s << (is_double ? "%lf" : "%f") << " "; // (real) dssp_psi
399  s << (is_double ? "%lf" : "%f") << " "; // (real) sa
400  s << (is_ulong ? "%ld" : "%d") << " "; // (size) nali
401 
402  // (real) (aa profile_info, 20 columns)
403  for (Size i = 0; i < 20; ++i) {
404  s << " " << (is_double ? "%lf" : "%f");
405  }
406 
407  // (real) (aa structure profile_info, 20 columns)
408  for (Size i = 0; i < 20; ++i) {
409  s << " " << (is_double ? "%lf" : "%f");
410  }
411 
412  TR.Debug << "vall line format version1 is:\n"<<s.str()<<std::endl;
413 
414  return s.str();
415 }
416 
418  using boost::is_same;
419 
420  // resolve types
421  bool const is_ulong = is_same<Size, unsigned long>::value;
422  bool const is_double = is_same<Real, double>::value;
423 
424  // format w/ the following order:
425  std::ostringstream s;
426  s << "%s" << " "; // (string) id
427  s << "%c" << " "; // (char) aa
428  s << (is_ulong ? "%lu" : "%u") << " "; // (int) resi
429  s << "%*s" << " "; // (string) dummy actual pdb resi
430  s << (is_double ? "%lf" : "%f") << " "; // (real) x
431  s << (is_double ? "%lf" : "%f") << " "; // (real) y
432  s << (is_double ? "%lf" : "%f") << " "; // (real) z
433  s << (is_double ? "%lf" : "%f") << " "; // (real) all-atom residue depth
434 
435  TR.Debug << "vall line format residue depth version1 is:\n"<<s.str()<<std::endl;
436 
437  return s.str();
438 }
439 
441  core::Real x = x_-r->x();
442  core::Real y = y_-r->y();
443  core::Real z = z_-r->z();
444  return x*x+y*y+z*z;
445 }
446 
448  // use CA for Gly
449  if (aa_ == 'G') {
450  if (r->aa() == 'G') {
451  return distance_squared( r );
452  } else {
453  core::Real x = x_-r->cbx();
454  core::Real y = y_-r->cby();
455  core::Real z = z_-r->cbz();
456  return x*x+y*y+z*z;
457  }
458  } else if (r->aa() == 'G') {
459  core::Real x = cbx_-r->x();
460  core::Real y = cby_-r->y();
461  core::Real z = cbz_-r->z();
462  return x*x+y*y+z*z;
463  } else {
464  core::Real x = cbx_-r->cbx();
465  core::Real y = cby_-r->cby();
466  core::Real z = cbz_-r->cbz();
467  return x*x+y*y+z*z;
468  }
469 }
470 
472  core::Real x = cenx_-r->cenx();
473  core::Real y = ceny_-r->ceny();
474  core::Real z = cenz_-r->cenz();
475  return x*x+y*y+z*z;
476 }
477 
479  switch (type) {
480  case CA:
481  return distance_squared(r);
482  case CB:
483  return distance_squared_cb(r);
484  case CEN:
485  return distance_squared_cen(r);
486  default:
487  utility_exit_with_message("unkown contacts type for distance");
488  }
489 }
490 
491 } // frag_picker
492 } // protocols