Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidualDipolarCoupling.hh
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 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/scoring/ResidualDipolarCoupling.hh
11 /// @brief Uses NMR RDC for scoring
12 /// @author Srivatsan Raman, Oliver Lange
13 
14 #ifndef INCLUDED_core_scoring_ResidualDipolarCoupling_hh
15 #define INCLUDED_core_scoring_ResidualDipolarCoupling_hh
16 
18 // AUTO-REMOVED #include <core/scoring/methods/ResidualDipolarCouplingEnergy.fwd.hh>
19 #include <core/types.hh>
20 #include <numeric/xyzVector.hh>
21 
22 #include <basic/datacache/CacheableData.hh>
23 #include <numeric/numeric.functions.hh>
24 // AUTO-REMOVED #include <utility/vector1.hh>
25 #include <core/pose/Pose.fwd.hh>
26 
27 #include <utility/vector1.hh>
28 
29 namespace core {
30 namespace scoring {
31 
35 
36 ///@brief ResidualDipolarCouplings are mainly handled by this class
37 ///@detail related classed: RDC --- a single line in an RDC file - representing a single dipolar coupling
38 /// ResidualDipolarCouplingEnergy -- an energy method which triggers computations handled by this class.
39 ///
40 ///
41 class ResidualDipolarCoupling: public basic::datacache::CacheableData {
42  // friend class ResidualDipolarCouplingEnergy;
43 public:
44  // typedefs
45  typedef core::Real Real;
46  typedef core::Size Size;
48  typedef core::Real Tensor[3][3];
49  typedef core::Real rvec[3];
50 
51 public:
52  /// @brief standard c'stor -- will access option -in:file:rdc to read RDC data
53 // ResidualDipolarCoupling() :
54 // nex_(0), nrows_(0) {
55 // reserve_buffers();
56 // read_RDC_file();
57 // }
58 
60  nex_(0), nrows_(0) {
62  if ( filename != "" ) {
63  read_RDC_file( 1, filename );
67  } else {
68  read_RDC_file();
69  }
70  }
71 
72  /// @brief alternative c'stor if you have a list of RDC lines
74  All_RDC_lines_(data_in) {
77  }
78 
79  //explicit copy c'stor to initialize buffers
81  //explicit assignment operator to initialize buffers
83 
84  //explicit destructor because we use raw pointers for buffers
85  virtual ~ResidualDipolarCoupling();
86 
87  //this class lives in the PoseCache.... need to provide clone()
88  basic::datacache::CacheableDataOP clone() const {
89  return new ResidualDipolarCoupling(*this);
90  }
91 
92  ///@brief compute dipolar score for given pose
93  /// will set alignment tensor and force-fields in RDC
95 
96  /// fit rdc using RDC data
101 
102  //wRDC (like wRMSD .. iter i + 1 tensor weights are ~exp( - dev^2/sigma ))
104  core::Real sigma2, core::Real tolerance, bool reset);
105 
106  void show(std::ostream&) const;
107 
108  ///@brief read RDC data from file
109  void read_RDC_file();
110 
111  ///@brief fill internal buffers... call always when RDC lines change.
112  void preprocess_data();
113 
114  ///@brief free memory of buffers
115  void release_buffers();
116 
117  ///@brief get memory for buffers
118  void reserve_buffers();
119 
120  ///@brief get the raw RDC data
121  inline RDC_lines const& get_RDC_data() const {
122  return All_RDC_lines_;
123  }
124 
125  ///@brief return the Q value ( cornilescu ) --- only valid after compute_dipscore
126  Real Q() const {
127  return R() * sqrt(2.0f);
128  }
129 
130  ///@brief return the R value ( M Clore ) --- only valid after compute_dipscore
131  Real R() const {
132  return R_;
133  }
134 
135  //@brief return the number of experiments
136  core::Size get_n_alignments() const {return nex_;}
137 
138  ///@brief return tensor of certain experiment... exp_id starts at 1
140  return S_;
141  }
142 
143 
144  /* core::Real get_fractional_anisotropy(core::Size ex) const {
145  // std::cout << "FFA " << FA_ <<std::endl;
146  return FA_[ex] != NULL ? FA_[ex] : -1;
147  }*/
148 
150  // std::cout << "FFA " << FA_ <<std::endl;
151  return trace_[ex];
152  }
153 
154 
156  // std::cout << "FFA " << FA_ <<std::endl;
157  return maxz_[ex];
158  }
159 
160  void compute_tensor_stats();
161  void show_tensor_stats( std::ostream&, core::Size ex ) const;
162  void show_tensor_matrix( std::ostream&, core::Size ex ) const;
163  void show_rdc_values( std::ostream&, core::Size ex ) const;
164 
165  void show_tensor_stats_nls( std::ostream&, core::Size ex, const double *par) const;
166  //void show_tensor_stats_nlsDa( std::ostream&, core::Size ex, const double tensorDa, const double *par) const;
167  //void show_tensor_stats_nlsR( std::ostream&, core::Size ex, const double tensorR, const double *par) const;
168  //void show_tensor_stats_nlsDaR( std::ostream&, core::Size ex, const double tensorDa, const double tensorR, const double *par) const;
169 private:
170  ///@brief read RDC data from file
171  void read_RDC_file( Size nex, std::string const& filename );
172 
173  ///@brief non-const reference to RDC data private use only.
175 
176 private:
177  /// some internal buffers in
178  typedef core::Real rvec5[5];
179  typedef core::Real Tensor5[5][5];
181  rvec* EV_; // rvec3
182  rvec5* D_; //rvec5 x nrows
183  rvec5* rhs_; //rvec5 x nrows
184  Tensor* S_; // 3 x 3 x nex
185  Tensor5* T_; // 5 x 5 x nex
186  core::Size nex_; //number of alignment media, i.e., how many tensors
188  core::Real R_; //clore R factor only valid after compute_dipscore...
190 
191  //stuff only computed for information purposes -- call compute_tensor_stats()
192  Tensor* SD_;//3 x 3 x nex
194  core::Real* FA_;//Fractional Anisotropy of the diffusion tensor - NGS
197 
198  //stuff for nls
206 };
207 
208 /////////////////////////////////////////////////
209 //@brief short class that stores the RDC data lines
210 /////////////////////////////////////////////////
211 class RDC {
212 
213 public:
214  enum RDC_TYPE {
216  };
217 
218  RDC() {
219  }
220 
222  std::string const& atom2, Real Jdipolar, Real weight = 1.0,//for alignment calculation
223  Size expid = 1
224  // core::Real Reduced_Jdipolar
225  ) :
226  type_(get_RDC_data_type(atom1, atom2)), res1_(res1), res2_(res2),
227  Jdipolar_(Jdipolar), weight_(weight), Jdipolar_computed_(-999),
228  expid_(expid), atom1_(atom1), atom2_(atom2)
229  // Reduced_Jdipolar_( Reduced_Jdipolar )
230  {
231  }
232 
233  RDC_TYPE type() const {
234  return type_;
235  }
236 
237  ///@brief which type of RDC pairing are we dealing with ?
239  std::string const & atom2);
240 
241  inline Size expid() const {
242  return expid_;
243  }
244 
245  inline Size res1() const {
246  return res1_;
247  }
248 
249  inline Size res2() const {
250  return res2_;
251  }
252 
253  inline Real Jdipolar() const {
254  return Jdipolar_;
255  }
256 
257  Real const& Jcomputed() const {
258  return Jdipolar_computed_;
259  }
260 
262  return Jdipolar_computed_;;
263  }
264 
265  Vector fij() const {
266  return fij_;
267  }
268 
269  inline Real fixed_dist() const {
270  //changed to reproduce constants from the DC server
271  //http://spin.niddk.nih.gov/bax/software/dc/#dc_di
272  runtime_assert( 0 ); ///don't use this
273  if (type() == RDC_TYPE_NH)
274  return 1.041;
275  //return 1.042;
276  else if (type() == RDC_TYPE_NC)
277  return 1.329;
278  //return 1.329;
279  else if (type() == RDC_TYPE_CH)
280  return 1.107;
281  //return 1.08;
282  else if (type() == RDC_TYPE_CC)
283  return 1.525;
284  //return 1.525;
285  //should never get here...
286  runtime_assert( 0 );
287  return 0;
288  }
289 
290  inline Real Reduced_Jdipolar() const {
291  using namespace numeric;
292  return Jdipolar_ * Dconst() * numeric::cube(fixed_dist());
293 
294  }
295 
296  Real weight() const {
297  return weight_;
298  }
299 
300  void weight(Real w_in) {
301  weight_ = w_in;
302  }
303 
304  inline Real Dconst() const {
305  core::Real Dcnst(0.0);
306  if (type() == RDC_TYPE_NH)
307  //Concepts in Magnetic Resonance Part A, 21, 10-21
308  Dcnst = 36.5089;
309  if (type() == RDC_TYPE_NC)
310  Dcnst = 9.179532;
311  if (type() == RDC_TYPE_CH)
312  Dcnst = 90.55324;
313  //Dcnst = -90.55324;
314  if (type() == RDC_TYPE_CC)
315  Dcnst = 22.76805;
316  //Dcnst = -22.76805;
317  // std::cout << Dcnst <<std::endl;
318  runtime_assert( Dcnst != 0 ); // at this position the type() should already
319  return Dcnst;
320  }
322 
323  std::string const& atom1() const {
324  return atom1_;
325  }
326 
327  std::string const& atom2() const {
328  return atom2_;
329  }
330 
331  void show(std::ostream&) const;
332 
333 
334 private:
339 
340 public :
343 
344 private:
348 };
349 
350 extern std::ostream& operator<<(std::ostream&, ResidualDipolarCoupling const&);
351 extern std::ostream& operator<<(std::ostream&, RDC const&);
352 
353 } //scoring
354 } //core
355 
356 #endif