Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResidualDipolarCouplingEnergyRigidSegments.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/ResidualDipolarCouplingEnergyRigidSegments.cc
11 /// @brief RDC energy - comparing experimental RDC values to calculated values
12 /// @author Srivatsan Raman
13 
14 
15 //Unit headers
17 #include <core/scoring/methods/ResidualDipolarCouplingEnergyRigidSegmentsCreator.hh>
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 #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/rdc.OptionKeys.gen.hh>
51 
52 //C++ headers
53 #include <iostream>
54 
55 //Auto Headers
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 ResidualDipolarCouplingEnergyRigidSegments class,
70 /// never an instance already in use
72 ResidualDipolarCouplingEnergyRigidSegmentsCreator::create_energy_method(
74 ) const {
76 }
77 
79 ResidualDipolarCouplingEnergyRigidSegmentsCreator::score_types_for_method() const {
80  ScoreTypes sts;
81  sts.push_back( rdc_segments );
82  return sts;
83 }
84 
85 
86 
87 //////////////////////////////////////////////////////
88 //@brief
89 //////////////////////////////////////////////////////
91  parent( new ResidualDipolarCouplingEnergyRigidSegmentsCreator )
92 {}
93 
94 
95 //////////////////////////////////////////////////////
96 //@brief
97 //////////////////////////////////////////////////////
100 {
101 
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_segments_from_pose( pose ) );
131  residual_dipolar_coupling::RDC_lines const& All_RDC_lines( rdc_data.get_RDC_data() );
132  residual_dipolar_coupling::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( id::NamedAtomID( it->atom1(), it->res1() ), pose );
136  id::AtomID atom2( id::NamedAtomID( it->atom2(), it->res2() ), pose );
137  tr.Trace << "insert in atom-map " << atom1 << " " << atom2 << std::endl;
138  ++ct;
139  atom2rdc_map_.set( atom1, ct );
140  atom2rdc_map_.set( atom2, ct );
141  }
142 }
143 
144 
145 
146 //////////////////////////////////////////////////////
147 //@brief
148 //////////////////////////////////////////////////////
151  pose::Pose & pose
152 ) const
153 {
154 // //using core::pose::datacache::CacheableDataType::RESIDUAL_DIPOLAR_COUPLING_DATA;
155 
156 // if( pose.data().has( RESIDUAL_DIPOLAR_COUPLING_DATA ) )
157 // return *( static_cast< ResidualDipolarCoupling const * >( pose.data().get_const_ptr( RESIDUAL_DIPOLAR_COUPLING_DATA )() ) );
158 
159 // ResidualDipolarCouplingOP rdc_info = new ResidualDipolarCoupling;
160 // pose.data().set( RESIDUAL_DIPOLAR_COUPLING_DATA, rdc_info );
162  if ( !rdc_info ) {
163  rdc_info = new ResidualDipolarCouplingRigidSegments;
164  store_RDC_segments_in_pose( rdc_info, pose );
165  }
166  return *rdc_info;
167 }
168 
169 //////////////////////////////////////////////////////
170 //@brief main computation routine for RDC energy... everything is happening here right now.
171 // this has to be spread out over different routines to make this energy yield derivatives
172 //////////////////////////////////////////////////////
174  pose::Pose & pose
175 ) const
176 {
177 
178  ResidualDipolarCoupling& rdc_data( rdc_from_pose( pose ) );
179  utility::vector1< core::scoring::RDC > const& All_RDC_lines( rdc_data.get_RDC_data() );
180  Real score;
181  //Size const nrow( All_RDC_lines.size() ); //number of experimental couplins
182  if ( basic::options::option[ basic::options::OptionKeys::rdc::iterate_weights ].user() ) {
183  Real const sigma2( basic::options::option[ basic::options::OptionKeys::rdc::iterate_weights ] );
184  Real const tol( basic::options::option[ basic::options::OptionKeys::rdc::iterate_tol ] );
185  bool const reset( basic::options::option[ basic::options::OptionKeys::rdc::iterate_reset ] );
186  score = rdc_data.iterate_tensor_weights( pose, sigma2, tol, reset );
187 
188  if ( basic::options::option[ basic::options::OptionKeys::rdc::dump_weight_trajectory ].user() ) {
189  std::string const filename( basic::options::option[ basic::options::OptionKeys::rdc::dump_weight_trajectory ]() );
190  utility::io::ozstream out( filename , std::ios_base::out | std::ios_base::app );
192  for ( it = All_RDC_lines.begin(); it != All_RDC_lines.end(); ++it) {
193  out << RJ( 4, it->weight()) << " ";
194  }
195  out << std::endl;
196  } //dump_weights
197  } else {
198  score = rdc_data.compute_dipscore( pose );
199  }
200  return score;
201 }
202 
203 
204 void
206  id::AtomID const & aid,
207  pose::Pose const & pose,
208  kinematics::DomainMap const &,
209  ScoreFunction const &,
210  EnergyMap const & score_weights,
211  Vector & F1,
212  Vector & F2
213 ) const {
214 
215  if ( !atom2rdc_map_.has( aid ) ) return; //damn this "has" isn't correct at all
216  Size const rdc_nr( atom2rdc_map_[ aid ] );
217  if ( rdc_nr == 0 ) {
218  // tr.Trace << "no RDC entry for " << aid << " skipping.. "<< std::endl;
219  return;
220  }
221  ResidualDipolarCoupling const& rdc_cache( *retrieve_RDC_segments_from_pose( pose ) );
222  utility::vector1< core::scoring::RDC > All_RDC_lines( rdc_cache.get_RDC_data() );
223  runtime_assert( rdc_nr <= All_RDC_lines.size() );
224  RDC const& rdc_data( All_RDC_lines[ rdc_nr ] );
225  conformation::Residue const& rsd1( pose.residue( rdc_data.res1() ) );
226  conformation::Residue const& rsd2( pose.residue( rdc_data.res2() ) );
227  Vector fij;
228  if ( aid.rsd() == rdc_data.res1() && utility::trimmed_compare( rsd1.atom_name( aid.atomno() ), rdc_data.atom1() ) ) {
229  fij = rdc_data.fij();
230  } else if ( aid.rsd() == rdc_data.res2() && utility::trimmed_compare( rsd2.atom_name( aid.atomno() ), rdc_data.atom2() ) ){
231  fij = -rdc_data.fij();
232  } else return;
233 
234  // Real fij;
235  //thanks to Will Sheffler:
236  numeric::xyzVector<core::Real> atom_x = pose.xyz(aid);
237  numeric::xyzVector<core::Real> const f2( -fij );
238  numeric::xyzVector<core::Real> const atom_y = atom_x - f2; // a "fake" atom in the direcion of the gradient
239  numeric::xyzVector<core::Real> const f1( atom_x.cross( atom_y ) );
240 
241  F1 += score_weights[ rdc ] * f1;
242  F2 += score_weights[ rdc ] * f2;
243 
244 }
245 
246 } // methods
247 } // scoring
248 } // core