Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DipolarCouplingEnergy.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/DipolarCouplingEnergy.cc
11 /// @brief DC energy - Orientation dependent chemical shift
12 /// @author Lei Shi
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 #include <numeric/xyzVector.hh>
32 
33 #include <core/id/NamedAtomID.hh>
34 
35 //utility headers
36 #include <utility/vector1.hh>
37 #include <utility/exit.hh>
38 #include <basic/Tracer.hh>
39 
40 //Objexx headers
41 #include <ObjexxFCL/char.functions.hh>
42 #include <ObjexxFCL/string.functions.hh>
43 // AUTO-REMOVED #include <ObjexxFCL/Fmath.hh>
44 
45 #include <utility/io/ozstream.hh> //for dump_weights
46 
47 #include <basic/options/option.hh>
48 #include <basic/options/keys/in.OptionKeys.gen.hh>
49 //#include <basic/options/keys/dc.OptionKeys.gen.hh>
50 
51 //C++ headers
52 #include <iostream>
53 
54 //Auto Headers
56 #include <utility/string_util.hh>
57 #include <ObjexxFCL/format.hh>
58 
59 
60 static basic::Tracer tr("core.scoring.DipolarCoupling");
61 
62 namespace core {
63 namespace scoring {
64 namespace methods {
65 
66 using namespace ObjexxFCL::fmt;
67 
68 /// @details This must return a fresh instance of the DipolarCouplingEnergy class,
69 /// never an instance already in use
73 ) const {
74  return new DipolarCouplingEnergy;
75 }
76 
79  ScoreTypes sts;
80  sts.push_back( dc );
81  return sts;
82 }
83 
84 
85 //////////////////////////////////////////////////////
86 //@brief
87 //////////////////////////////////////////////////////
90 {}
91 
92 //////////////////////////////////////////////////////
93 //@brief
94 //////////////////////////////////////////////////////
97 {
98  return new DipolarCouplingEnergy();
99 }
100 
102  pose::Pose & pose,
103  ScoreFunction const &
104 ) const
105 {
106  dc_score_ = eval_dc( pose );
107 }
108 
110  pose::Pose &,
111  ScoreFunction const &,
112  EnergyMap & totals
113 ) const
114 {
115  totals[ dc ] = dc_score_;
116 }
117 
119  pose::Pose & pose,
120  ScoreFunction const &,
122 ) const
123 {
124  DipolarCoupling const& dc_data( * retrieve_DC_from_pose( pose ) );
125  DipolarCoupling::DC_lines const& All_DC_lines( dc_data.get_DC_data() );
126  DipolarCoupling::DC_lines::const_iterator it;
127  Size ct = 0;
128  for( it = All_DC_lines.begin(); it != All_DC_lines.end(); ++it) {
129  id::AtomID atom1( pose.residue(it->res1()).atom_index(it->atom1()), it->res1());
130  id::AtomID atom2( pose.residue(it->res2()).atom_index(it->atom2()), it->res2());
131  //tr.Trace << "method: it->res1(): " << it->res1() << " it->atom1() " << it->atom1() << std::endl;
132  //tr.Trace << "method: it->res2(): " << it->res2() << " it->atom2() " << it->atom2() << std::endl;
133  //tr.Trace << "insert in atom-map " << atom1 << " " << atom2 << " " << atom3 << std::endl;
134  ++ct;
135  utility::vector1< core::Size > atm1_map = atom2dc_map_.get( atom1 );
136  utility::vector1< core::Size > atm2_map = atom2dc_map_.get( atom2 );
137  atm1_map.push_back( ct );
138  atm2_map.push_back( ct );
139  atom2dc_map_.set( atom1, atm1_map );
140  atom2dc_map_.set( atom2, atm2_map );
141  }
142 }
143 
144 //////////////////////////////////////////////////////
145 //@brief
146 //////////////////////////////////////////////////////
149  pose::Pose & pose
150 ) const
151 {
152  DipolarCouplingOP dc_info( retrieve_DC_from_pose( pose ) );
153  if ( !dc_info ) {
154  dc_info = new DipolarCoupling;
155  store_DC_in_pose( dc_info, pose );
156  }
157  return *dc_info;
158 }
159 
160 //////////////////////////////////////////////////////
161 //@brief main computation routine for DC energy... everything is happening here right now.
162 // this has to be spread out over different routines to make this energy yield derivatives
163 //////////////////////////////////////////////////////
165  pose::Pose & pose
166 ) const
167 {
168 
169  DipolarCoupling& dc_data( dc_from_pose( pose ) );
170  Real score = dc_data.compute_dcscore( pose );
171  return score;
172 }
173 
174 void
176  id::AtomID const & aid,
177  pose::Pose const & pose,
178  kinematics::DomainMap const &,
179  ScoreFunction const &,
180  EnergyMap const & score_weights,
181  Vector & F1,
182  Vector & F2
183 ) const {
184 
185  if ( !atom2dc_map_.has( aid ) ) return; //damn this "has" isn't correct at all
186  utility::vector1< Size > const dc_nrs( atom2dc_map_[ aid ] );
187 // tr.Trace << " aid " << aid << std::endl;
188 
189  if ( dc_nrs.size() == 0 ) {
190  // tr.Trace << "no DC entry for " << aid << " skipping.. "<< std::endl;
191  return;
192  }
193 
194  Vector fij(0,0,0);
195 
196  for (core::Size ii=1; ii<=dc_nrs.size(); ++ii) {
197  core::Size dc_nr = dc_nrs[ ii ];
198  DipolarCoupling const& dc_cache( *retrieve_DC_from_pose( pose ) );
199  utility::vector1< core::scoring::DC > All_DC_lines( dc_cache.get_DC_data() );
200  runtime_assert( dc_nr <= All_DC_lines.size() );
201  DC const& dc_data( All_DC_lines[ dc_nr ] );
202  conformation::Residue const& rsd1( pose.residue( dc_data.res1() ) );
203  conformation::Residue const& rsd2( pose.residue( dc_data.res2() ) );
204 
205  if ( aid.rsd() == dc_data.res1() && utility::trimmed_compare( rsd1.atom_name( aid.atomno() ), dc_data.atom1() ) ) {
206 // tr.Trace << "aid.rsd(): " << aid.rsd() << " rsd1.atom_name( aid.atomno() ) "<< rsd1.atom_name( aid.atomno() ) << " dc_data.atom1() " << dc_data.atom1() << std::endl;
207  fij += dc_data.f1ij();
208  } else if ( aid.rsd() == dc_data.res2() && utility::trimmed_compare( rsd2.atom_name( aid.atomno() ), dc_data.atom2() ) ){
209 // tr.Trace << "aid.rsd(): " << aid.rsd() << " rsd2.atom_name( aid.atomno() ) "<< rsd2.atom_name( aid.atomno() ) << " dc_data.atom2() " << dc_data.atom2() << std::endl;
210  fij += dc_data.f2ij();
211  } else return;
212 
213  }
214 
215 // tr.Trace << "fij[0]: " << fij[0]<< " fij[1]: " << fij[1]<< " fij[2]: " << fij[2]<< std::endl;
216 // tr.Trace << "torsion gradient: " << aid << std::endl;
217 // tr.Trace << "score_weights[ dc ]: " << score_weights[ dc ] << std::endl;
218  //thanks to Will Sheffler:
219  numeric::xyzVector<core::Real> atom_x = pose.xyz(aid);
220  numeric::xyzVector<core::Real> const f2( fij );
221  numeric::xyzVector<core::Real> const atom_y = atom_x - f2; // a "fake" atom in the direcion of the gradient
222  numeric::xyzVector<core::Real> const f1( atom_x.cross( atom_y ) );
223 
224  F1 += score_weights[ dc ] * f1;
225  F2 += score_weights[ dc ] * f2;
226 
227 }
228 
231 {
232  return 1; // Initial versioning
233 }
234 
235 } // methods
236 } // scoring
237 } // core