Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidualDipolarCouplingEnergy.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 // (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/methods/ResidualDipolarCouplingEnergy.cc
11 /// @brief RDC energy - comparing experimental RDC values to calculated values
12 /// @author Srivatsan Raman
13 
14 
15 //Unit headers
21 //Package headers
22 
24 //#include <core/scoring/ScoringManager.hh>
25 // AUTO-REMOVED #include <core/scoring/EnergyGraph.hh>
26 #include <core/pose/Pose.hh>
27 //#include <core/pose/datacache/CacheableDataType.hh>
28 
29 //numeric headers
30 #include <numeric/numeric.functions.hh>
31 // AUTO-REMOVED #include <numeric/xyzMatrix.hh>
32 #include <numeric/xyzVector.hh>
33 // AUTO-REMOVED #include <numeric/xyz.functions.hh>
34 
35 // AUTO-REMOVED #include <core/id/NamedAtomID.hh>
36 
37 //utility headers
38 #include <utility/vector1.hh>
39 #include <utility/exit.hh>
40 #include <basic/Tracer.hh>
41 
42 //Objexx headers
43 #include <ObjexxFCL/char.functions.hh>
44 #include <ObjexxFCL/string.functions.hh>
45 // AUTO-REMOVED #include <ObjexxFCL/Fmath.hh>
46 
47 #include <utility/io/ozstream.hh> //for dump_weights
48 
49 #include <basic/options/option.hh>
50 #include <basic/options/keys/in.OptionKeys.gen.hh>
51 #include <basic/options/keys/rdc.OptionKeys.gen.hh>
52 
53 //C++ headers
54 #include <iostream>
55 
57 #include <utility/string_util.hh>
58 #include <ObjexxFCL/format.hh>
59 
60 
61 static basic::Tracer tr("core.scoring.ResidualDipolarCoupling");
62 
63 namespace core {
64 namespace scoring {
65 namespace methods {
66 
67 using namespace ObjexxFCL::fmt;
68 
69 /// @details This must return a fresh instance of the ResidualDipolarCouplingEnergy class,
70 /// never an instance already in use
74 ) const {
76 }
77 
80  ScoreTypes sts;
81  sts.push_back( rdc );
82  return sts;
83 }
84 
85 
86 
87 //////////////////////////////////////////////////////
88 //@brief
89 //////////////////////////////////////////////////////
92 {}
93 
94 
95 //////////////////////////////////////////////////////
96 //@brief
97 //////////////////////////////////////////////////////
100 {
101 
102  return new ResidualDipolarCouplingEnergy();
103 
104 }
105 
107  pose::Pose & pose,
108  ScoreFunction const &
109 ) const
110 {
111  //ResidualDipolarCoupling& rdc_data( rdc_from_pose( pose ) );
112  dip_score_ = eval_dipolar( pose );
113 }
114 
116  pose::Pose &,
117  ScoreFunction const &,
118  EnergyMap & totals
119 ) const
120 {
121  totals[ rdc ] = dip_score_;
122 }
123 
125  pose::Pose & pose,
126  ScoreFunction const &,
128 ) const
129 {
130  ResidualDipolarCoupling const& rdc_data( * retrieve_RDC_from_pose( pose ) );
131  ResidualDipolarCoupling::RDC_lines const& All_RDC_lines( rdc_data.get_RDC_data() );
132  ResidualDipolarCoupling::RDC_lines::const_iterator it;
133  Size ct = 0;
134  for( it = All_RDC_lines.begin(); it != All_RDC_lines.end(); ++it) {
135  id::AtomID atom1( pose.residue(it->res1()).atom_index(it->atom1()), it->res1());
136  id::AtomID atom2( pose.residue(it->res2()).atom_index(it->atom2()), it->res2());
137  tr.Trace << "insert in atom-map " << atom1 << " " << atom2 << std::endl;
138  ++ct;
141  atm1_map.push_back( ct );
142  atm2_map.push_back( ct );
143  atom2rdc_map_.set( atom1, atm1_map );
144  atom2rdc_map_.set( atom2, atm2_map );
145  }
146 }
147 
148 
149 
150 //////////////////////////////////////////////////////
151 //@brief
152 //////////////////////////////////////////////////////
155  pose::Pose & pose
156 ) const
157 {
158 // //using core::pose::datacache::CacheableDataType::RESIDUAL_DIPOLAR_COUPLING_DATA;
159 
160 // if( pose.data().has( RESIDUAL_DIPOLAR_COUPLING_DATA ) )
161 // return *( static_cast< ResidualDipolarCoupling const * >( pose.data().get_const_ptr( RESIDUAL_DIPOLAR_COUPLING_DATA )() ) );
162 
163 // ResidualDipolarCouplingOP rdc_info = new ResidualDipolarCoupling;
164 // pose.data().set( RESIDUAL_DIPOLAR_COUPLING_DATA, rdc_info );
166  if ( !rdc_info ) {
167  rdc_info = new ResidualDipolarCoupling;
168  store_RDC_in_pose( rdc_info, pose );
169  }
170  return *rdc_info;
171 }
172 
173 //////////////////////////////////////////////////////
174 //@brief main computation routine for RDC energy... everything is happening here right now.
175 // this has to be spread out over different routines to make this energy yield derivatives
176 //////////////////////////////////////////////////////
178  pose::Pose& pose
179 ) const
180 {
181  ResidualDipolarCoupling& rdc_data( rdc_from_pose( pose ) );
182  return eval_dipolar( pose, rdc_data );
183 }
184 
186  pose::Pose const& pose,
187  ResidualDipolarCoupling& rdc_data
188 ) const
189 {
190  Real score;
191  //Size const nrow( All_RDC_lines.size() ); //number of experimental couplins
192  if ( basic::options::option[ basic::options::OptionKeys::rdc::iterate_weights ].user() ) {
193  utility::vector1< core::scoring::RDC > const& All_RDC_lines( rdc_data.get_RDC_data() );
194  Real const sigma2( basic::options::option[ basic::options::OptionKeys::rdc::iterate_weights ] );
195  Real const tol( basic::options::option[ basic::options::OptionKeys::rdc::iterate_tol ] );
196  bool const reset( basic::options::option[ basic::options::OptionKeys::rdc::iterate_reset ] );
197  score = rdc_data.iterate_tensor_weights( pose, sigma2, tol, reset );
198 
199  if ( basic::options::option[ basic::options::OptionKeys::rdc::dump_weight_trajectory ].user() ) {
200  std::string const filename( basic::options::option[ basic::options::OptionKeys::rdc::dump_weight_trajectory ]() );
201  utility::io::ozstream out( filename , std::ios_base::out | std::ios_base::app );
203  for ( it = All_RDC_lines.begin(); it != All_RDC_lines.end(); ++it) {
204  out << RJ( 4, it->weight()) << " ";
205  }
206  out << std::endl;
207  } //dump_weights
208  } else {
209  static std::string const fit_method(
210  basic::options::option[ basic::options::OptionKeys::rdc::fit_method ]()
211  );
212  if ( fit_method == "svd" ) {
213  tr.Trace << "residual-energy method chosen: 'svd' " << std::endl;
214  score = rdc_data.compute_dipscore( pose );
215  } else {
216  using namespace basic::options;
217  using namespace basic::options::OptionKeys;
218  if (option[ OptionKeys::rdc::fixDa].user()) {
219  if (option[ OptionKeys::rdc::fixR].user()) {
220  //Real const tensorDa( option[ OptionKeys::rdc::fixDa] );
221  //Real const tensorR( option[ OptionKeys::rdc::fixR] );
222  utility::vector1<Real> const tensorDa = option[ OptionKeys::rdc::fixDa]();
223  utility::vector1<Real> const tensorR = option[ OptionKeys::rdc::fixR]();
224 
225  //make sure R is between 0 and 2/3
226  for ( core::Size i = 1; i <= option[ OptionKeys::rdc::fixR ]().size(); ++i) {
227  if ( (tensorR[i] < 0) || (tensorR[i] > 2.0/3.0) ) {
228  utility_exit_with_message("0=< R <=2/3");
229  }
230  }
231 
232  //make sure user provide the same number Da and R
233  if ( ( option[ OptionKeys::rdc::fixDa ]().size() != option[ OptionKeys::in::file::rdc ]().size() )
234  || ( option[ OptionKeys::rdc::fixR ]().size() != option[ OptionKeys::in::file::rdc ]().size() ) ) {
235  utility_exit_with_message("Number of Da and R must be the same as in number of experiment");
236  }
237 
238  score = rdc_data.compute_dipscore_nlsDaR( pose, tensorDa , tensorR );
239  } else { //end of Da and R
240  //Real const tensorDa( option[ OptionKeys::rdc::fixDa] );
241  utility::vector1<Real> const tensorDa = option[ OptionKeys::rdc::fixDa]();
242  //tr.Trace << "nls and fixDa: " << tensorDa << std::endl;
243  score = rdc_data.compute_dipscore_nlsDa( pose, tensorDa);
244  } //end of Da and noR
245  } else {//end of fixDa
246  if (option[ OptionKeys::rdc::fixR].user()) {
247  //Real const tensorR( option[ OptionKeys::rdc::fixR] );
248  utility::vector1<Real> const tensorR = option[ OptionKeys::rdc::fixR]();
249  //tr.Trace << "nls and fixR: " << tensorR << std::endl;
250  for ( core::Size i = 1; i <= option[ OptionKeys::rdc::fixR ]().size(); ++i) {
251  if ( (tensorR[i] < 0) || (tensorR[i] > 2.0/3.0) ) {
252  utility_exit_with_message("0=< R <=2/3");
253  }
254  }
255  score = rdc_data.compute_dipscore_nlsR( pose, tensorR);
256  }//end of noDa and R
257  else {
258  //tr.Trace << "nls" << std::endl;
259  score = rdc_data.compute_dipscore_nls( pose );
260  }//end of noDa and noR
261  }//end of no fixDa
262  }//end of nls
263  }//end of else dump
264  return score;
265 }
266 
267 
268 void
270  id::AtomID const & aid,
271  pose::Pose const & pose,
272  kinematics::DomainMap const &,
273  ScoreFunction const &,
274  EnergyMap const & score_weights,
275  Vector & F1,
276  Vector & F2
277 ) const {
278 
279  if ( !atom2rdc_map_.has( aid ) ) return; //damn this "has" isn't correct at all
280  utility::vector1< Size > const rdc_nrs( atom2rdc_map_[ aid ] );
281  if ( rdc_nrs.size() == 0 ) {
282  // tr.Trace << "no RDC entry for " << aid << " skipping.. "<< std::endl;
283  return;
284  }
285  Vector fij(0,0,0);
286  for (core::Size ii=1; ii<=rdc_nrs.size(); ++ii) {
287  core::Size rdc_nr = rdc_nrs[ ii ];
288  ResidualDipolarCoupling const& rdc_cache( *retrieve_RDC_from_pose( pose ) );
289  utility::vector1< core::scoring::RDC > All_RDC_lines( rdc_cache.get_RDC_data() );
290  runtime_assert( rdc_nr <= All_RDC_lines.size() );
291  RDC const& rdc_data( All_RDC_lines[ rdc_nr ] );
292  conformation::Residue const& rsd1( pose.residue( rdc_data.res1() ) );
293  conformation::Residue const& rsd2( pose.residue( rdc_data.res2() ) );
294  if ( aid.rsd() == rdc_data.res1() && utility::trimmed_compare( rsd1.atom_name( aid.atomno() ), rdc_data.atom1() ) ) {
295  fij += rdc_data.fij();
296  } else if ( aid.rsd() == rdc_data.res2() && utility::trimmed_compare( rsd2.atom_name( aid.atomno() ), rdc_data.atom2() ) ){
297  fij -= rdc_data.fij();
298  } else return;
299  }
300 
301  // Real fij;
302  //thanks to Will Sheffler:
303  numeric::xyzVector<core::Real> atom_x = pose.xyz(aid);
304  numeric::xyzVector<core::Real> const f2( -fij );
305  numeric::xyzVector<core::Real> const atom_y = atom_x - f2; // a "fake" atom in the direcion of the gradient
306  numeric::xyzVector<core::Real> const f1( atom_x.cross( atom_y ) );
307 
308  F1 += score_weights[ rdc ] * f1;
309  F2 += score_weights[ rdc ] * f2;
310 
311 }
314 {
315  return 1; // Initial versioning
316 }
317 
318 } // methods
319 } // scoring
320 } // core