Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChemicalShiftAnisotropyEnergy.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/ChemicalShiftAnisotropyEnergy.cc
11 /// @brief CSA 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/csa.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.ChemicalShiftAnisotropy");
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 ChemicalShiftAnisotropyEnergy class,
69 /// never an instance already in use
73 ) const {
75 }
76 
79  ScoreTypes sts;
80  sts.push_back( csa );
81  return sts;
82 }
83 
84 
85 //////////////////////////////////////////////////////
86 //@brief
87 //////////////////////////////////////////////////////
90 {}
91 
92 //////////////////////////////////////////////////////
93 //@brief
94 //////////////////////////////////////////////////////
97 {
98  return new ChemicalShiftAnisotropyEnergy();
99 }
100 
102  pose::Pose & pose,
103  ScoreFunction const &
104 ) const
105 {
106  csa_score_ = eval_csa( pose );
107 }
108 
110  pose::Pose &,
111  ScoreFunction const &,
112  EnergyMap & totals
113 ) const
114 {
115  totals[ csa ] = csa_score_;
116 }
117 
119  pose::Pose & pose,
120  ScoreFunction const &,
122 ) const
123 {
124  ChemicalShiftAnisotropy const& csa_data( * retrieve_CSA_from_pose( pose ) );
125  ChemicalShiftAnisotropy::CSA_lines const& All_CSA_lines( csa_data.get_CSA_data() );
126  ChemicalShiftAnisotropy::CSA_lines::const_iterator it;
127  Size ct = 0;
128  for( it = All_CSA_lines.begin(); it != All_CSA_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  id::AtomID atom3( pose.residue(it->res3()).atom_index(it->atom3()), it->res3());
132  //tr.Trace << "method: it->res1(): " << it->res1() << " it->atom1() " << it->atom1() << std::endl;
133  //tr.Trace << "method: it->res2(): " << it->res2() << " it->atom2() " << it->atom2() << std::endl;
134  //tr.Trace << "method: it->res3(): " << it->res3() << " it->atom3() " << it->atom3() << std::endl;
135  //tr.Trace << "insert in atom-map " << atom1 << " " << atom2 << " " << atom3 << std::endl;
136  ++ct;
140  atm1_map.push_back( ct );
141  atm2_map.push_back( ct );
142  atm3_map.push_back( ct );
143  atom2csa_map_.set( atom1, atm1_map );
144  atom2csa_map_.set( atom2, atm2_map );
145  atom2csa_map_.set( atom3, atm3_map );
146  }
147 }
148 
149 //////////////////////////////////////////////////////
150 //@brief
151 //////////////////////////////////////////////////////
154  pose::Pose & pose
155 ) const
156 {
158  if ( !csa_info ) {
159  csa_info = new ChemicalShiftAnisotropy;
160  store_CSA_in_pose( csa_info, pose );
161  }
162  return *csa_info;
163 }
164 
165 //////////////////////////////////////////////////////
166 //@brief main computation routine for CSA energy... everything is happening here right now.
167 // this has to be spread out over different routines to make this energy yield derivatives
168 //////////////////////////////////////////////////////
170  pose::Pose & pose
171 ) const
172 {
173 
174  ChemicalShiftAnisotropy& csa_data( csa_from_pose( pose ) );
175  Real score = csa_data.compute_csascore( pose );
176  return score;
177 }
178 
179 void
181  id::AtomID const & aid,
182  pose::Pose const & pose,
183  kinematics::DomainMap const &,
184  ScoreFunction const &,
185  EnergyMap const & score_weights,
186  Vector & F1,
187  Vector & F2
188 ) const {
189 
190  if ( !atom2csa_map_.has( aid ) ) return; //damn this "has" isn't correct at all
191  utility::vector1< Size > const csa_nrs( atom2csa_map_[ aid ] );
192  //tr.Trace << " aid " << aid << std::endl;
193 
194  if ( csa_nrs.size() == 0 ) {
195  // tr.Trace << "no CSA entry for " << aid << " skipping.. "<< std::endl;
196  return;
197  }
198  //tr.Trace << "csa_nrs.size(): " << csa_nrs.size() << std::endl;
199 
200  Vector fij(0,0,0);
201 
202  for (Size ii=1; ii<=csa_nrs.size(); ++ii) {
203  core::Size csa_nr = csa_nrs[ ii ];
204  //tr.Trace << "csa_nr: " << csa_nr << std::endl;
205  //tr.Trace << "aid.rsd(): " << aid.rsd() << std::endl;
206  ChemicalShiftAnisotropy const& csa_cache( *retrieve_CSA_from_pose( pose ) );
207  utility::vector1< core::scoring::CSA > All_CSA_lines( csa_cache.get_CSA_data() );
208  runtime_assert( csa_nr <= All_CSA_lines.size() );
209  CSA const& csa_data( All_CSA_lines[ csa_nr ] );
210  conformation::Residue const& rsd1( pose.residue( csa_data.res1() ) );
211  conformation::Residue const& rsd2( pose.residue( csa_data.res2() ) );
212  conformation::Residue const& rsd3( pose.residue( csa_data.res3() ) );
213  //tr.Trace << "rsd1.atom_name( aid.atomno() " << rsd1.atom_name( aid.atomno()) << std::endl;
214 
215  if ( aid.rsd() == csa_data.res1() && utility::trimmed_compare( rsd1.atom_name( aid.atomno() ), csa_data.atom1() ) ) {
216  //tr.Trace << "aid.rsd(): " << aid.rsd() << " rsd1.atom_name( aid.atomno() ) "<< rsd1.atom_name( aid.atomno() ) << " csa_data.atom1() " << csa_data.atom1() << std::endl;
217  fij += csa_data.f1ij();
218  } else if ( aid.rsd() == csa_data.res2() && utility::trimmed_compare( rsd2.atom_name( aid.atomno() ), csa_data.atom2() ) ){
219  //tr.Trace << "aid.rsd(): " << aid.rsd() << " rsd2.atom_name( aid.atomno() ) "<< rsd2.atom_name( aid.atomno() ) << " csa_data.atom2() " << csa_data.atom2() << std::endl;
220  fij += csa_data.f2ij();
221  } else if ( aid.rsd() == csa_data.res3() && utility::trimmed_compare( rsd3.atom_name( aid.atomno() ), csa_data.atom3() ) ){
222  //tr.Trace << "aid.rsd(): " << aid.rsd() << " rsd3.atom_name( aid.atomno() ) "<< rsd3.atom_name( aid.atomno() ) << " csa_data.atom3() " << csa_data.atom3() << std::endl;
223  fij += csa_data.f3ij();
224  } else return;
225 
226  }
227 
228  //tr.Trace << "fij[0]: " << fij[0]<< " fij[1]: " << fij[1]<< " fij[2]: " << fij[2]<< std::endl;
229  //tr.Trace << "torsion gradient: " << aid << std::endl;
230  //tr.Trace << "score_weights[ csa ]: " << score_weights[ csa ] << std::endl;
231  //thanks to Will Sheffler:
232  numeric::xyzVector<core::Real> atom_x = pose.xyz(aid);
233  numeric::xyzVector<core::Real> const f2( fij );
234  numeric::xyzVector<core::Real> const atom_y = atom_x - f2; // a "fake" atom in the direcion of the gradient
235  numeric::xyzVector<core::Real> const f1( atom_x.cross( atom_y ) );
236 
237  F1 += score_weights[ csa ] * f1;
238  F2 += score_weights[ csa ] * f2;
239 
240 }
241 
244 {
245  return 1; // Initial versioning
246 }
247 
248 } // methods
249 } // scoring
250 } // core