Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CustomAtomPairEnergy.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/CustomAtomPairEnergy.cc
11 /// @brief Simple EnergyMethod for calculating residue-residue constraints
12 /// under some interaction cutoff.
13 /// @author James Thompson
14 
15 
16 // Unit headers
19 // AUTO-REMOVED #include <core/scoring/methods/util.hh>
21 
22 // Package headers
23 // AUTO-REMOVED #include <core/scoring/PairEPotential.hh>
24 // AUTO-REMOVED #include <core/scoring/ScoringManager.hh>
25 // AUTO-REMOVED #include <core/scoring/Energies.hh>
26 // AUTO-REMOVED #include <core/scoring/EnergyGraph.hh>
27 // AUTO-REMOVED #include <core/scoring/ContextGraphTypes.hh>
29 
30 // Project headers
33 
34 #include <core/pose/Pose.hh>
35 #include <core/pose/util.hh>
37 
38 #include <basic/Tracer.hh>
39 
40 #include <utility/io/izstream.hh>
41 #include <istream>
42 
43 #include <core/id/AtomID.hh>
44 // AUTO-REMOVED #include <ObjexxFCL/FArray2D.hh>
45 
46 #include <basic/options/option.hh>
47 #include <basic/options/keys/score.OptionKeys.gen.hh>
48 // AUTO-REMOVED #include <basic/options/keys/run.OptionKeys.gen.hh>
49 // AUTO-REMOVED #include <basic/options/keys/james.OptionKeys.gen.hh>
50 
51 #include <numeric/deriv/distance_deriv.hh>
52 
53 #include <utility/vector1.hh>
54 
55 
56 // Utility headers
57 
58 namespace core {
59 namespace scoring {
60 namespace methods {
61 
62 static basic::Tracer tr( "core.scoring.methods.CustomAtomPairEnergy" );
63 
64 /// @details This must return a fresh instance of the CustomAtomPairEnergy class,
65 /// never an instance already in use
68  methods::EnergyMethodOptions const & opts
69 ) const {
70  return new CustomAtomPairEnergy( opts.cst_max_seq_sep() );
71 }
72 
75  ScoreTypes sts;
76  sts.push_back( custom_atom_pair );
77  return sts;
78 }
79 
82  max_cst_seq_sep_( max_cst_seq_sep )
83 {}
84 
85 /// clone
88 {
90 }
91 
92 ///
93 void
95 {
97  pose.update_actcoords();
98 }
99 
100 // make seqpos1 < seqpos2
102  core::Size & seqpos1,
103  core::Size & seqpos2
104 ) {
105  if ( seqpos1 > seqpos2 ) {
106  // Size temp = seqpos2;
107  seqpos2 = seqpos1;
108  seqpos1 = seqpos2;
109  }
110 }
111 
112 
113 ///
114 void
116 {
118  pose.update_actcoords();
119 
120  using namespace basic::options;
121  using namespace basic::options::OptionKeys;
122  using namespace core::scoring::constraints;
123  using std::string;
124  using utility::vector1;
125 
126  //string const filename( option[ score::custom_atom_pair ]() );
127  string filename;
128  bool success = get_comment( pose, "custom_atom_pair_fn", filename );
129  if ( !success ) {
130  filename = option[ score::custom_atom_pair ]();
131  }
132 
133  if ( filename == fn_ ) return; // we're up to date
134 
135  tr.Debug << "reading from " << filename << std::endl;
136  utility::io::izstream data( filename.c_str() );
137  if ( !data.good() ) {
138  utility_exit_with_message(
139  "ERROR: Unable to open input file: '" + filename + "'"
140  );
141  }
142 
143  Size const n_res( pose.total_residue() );
144  // could save some space by only doing upper triangle (resi < resj)
145  have_cst_ = vector1< vector1< bool > >( n_res, vector1< bool >( n_res, false ) );
147  n_res, vector1< SOGFunc_Impl >( n_res, SOGFunc_Impl() )
148  );
149 
150  string line;
151  while( getline(data,line) ) {
152  if ( line.substr(0,1) == "#" ) continue;
153  std::istringstream line_stream(line);
154  string atomi, atomj, cst_tag, func_tag;
155  Size resi, resj;
156  line_stream >> cst_tag >> atomi >> resi >> atomj >> resj
157  >> func_tag;
158 
159  if ( cst_tag == "AtomPair" && func_tag == "SOGFUNC" ) {
160  SOGFunc_Impl func;
161  func.read_data( line_stream );
162  //swap_seqpos(resi,resj);
163  have_cst_[resi][resj] = true;
164  have_cst_[resj][resi] = true;
165  funcs_[resj][resi] = func;
166  funcs_[resi][resj] = func;
167  //funcs_[resj][resi].show_definition( tr.Debug );
168  } else {
169  tr.Error << cst_tag << "," << func_tag << std::endl;
170  tr.Error << "Ignoring function on line " << line << std::endl;
171  }
172  }
173  tr.Debug << "finished reading." << std::endl;
174 
175  tr.flush_all_channels();
176 }
177 
178 ///
179 void
181  pose::Pose & pose, ScoreFunction const &
182 ) const {
184  pose.update_actcoords();
185 }
186 
187 void
189  pose::Pose const & /*pose*/,
191 ) const {
192  for ( Size ii = 1; ii <= set.num_rotamers(); ++ii ) {
193  set.nonconst_rotamer( ii )->update_actcoord();
194  }
195 }
196 
197 void
199  pose::Pose & pose,
200  Size resid
201 ) const {
202  pose.update_actcoord( resid );
203 }
204 
205 
206 /////////////////////////////////////////////////////////////////////////////
207 // scoring
208 /////////////////////////////////////////////////////////////////////////////
209 
210 void
212  conformation::Residue const & rsd1,
213  conformation::Residue const & rsd2,
214  pose::Pose const & /*pose*/,
215  ScoreFunction const & scorefxn,
216  EnergyMap & emap
217 ) const {
218  using namespace basic::options;
219  using namespace basic::options::OptionKeys;
220 
221  Size seqpos1( rsd1.seqpos() ), seqpos2( rsd2.seqpos() );
222  if ( rsd1.seqpos() == rsd2.seqpos() ) return;
223 
224  //swap_seqpos( seqpos1, seqpos2 );
225  //if ( std::abs( seqpos1 - seqpos2 ) > max_cst_seq_sep_ ) return;
226 
227  // return early if we don't have a weight for this ScoreType
228  if ( scorefxn.has_zero_weight(custom_atom_pair) ) return;
229 
230  // return early if we don't have constraints
231  if ( !have_cst_[seqpos1][seqpos2] ) return;
232 
233  // Enforce interaction cutoff. Currently using a 10A C-alpha distance
234  // cutoff. It would be nice to do this programatically from the
235  // input cst file. Should be faster to use EnergyGraph code for this ...
236  static std::string const atom_name( "CA" );
237  if ( !( rsd1.type().has(atom_name) && rsd2.type().has(atom_name) ) ) return;
238  Distance dist( rsd1.xyz(atom_name).distance( rsd2.xyz(atom_name) ) );
239  if ( dist > interaction_cutoff() ) {
240  emap[ custom_atom_pair ] += dist - interaction_cutoff();
241  } //else {
242  //Real const score( funcs_[seqpos1][seqpos2].func( dist ) );
243  //emap[ custom_atom_pair ] += funcs_[seqpos1][seqpos2].func( dist );
244 } // residue_pair_energy
245 
246 /////////////////////////////////////////////////////////////////////////////
247 void
249  id::AtomID const & atom_id,
250  pose::Pose const & pose,
251  kinematics::DomainMap const & /*domain_map*/,
252  ScoreFunction const & scorefxn,
253  EnergyMap const & weights,
254  Vector & F1,
255  Vector & F2
256 ) const {
257  if ( scorefxn.has_zero_weight(custom_atom_pair) ) return;
258 
259  using core::Real;
260  using core::Size;
261  Size const seqpos1( atom_id.rsd() );
262  if ( atom_id.atomno() != 2 ) return; // tex - fix this!
263 
264  for ( Size seqpos2 = 1; seqpos2 <= pose.total_residue(); ++seqpos2 ) {
265  if ( seqpos1 != seqpos2 && have_cst_[seqpos1][seqpos2] ) {
266  core::id::AtomID other_atom( atom_id.atomno(), seqpos2 );
267 
268  Real dist(0.0);
269  Vector f1(0.0), f2(0.0);
270  numeric::deriv::distance_f1_f2_deriv(
271  pose.conformation().xyz( atom_id ), pose.conformation().xyz( other_atom ),
272  dist, f1, f2
273  );
274  if ( dist <= interaction_cutoff() ) {
275  Real const wderiv(
276  weights[ custom_atom_pair ] * funcs_[seqpos1][seqpos2].dfunc(dist)
277  );
278  F1 += f1 * wderiv;
279  F2 += f2 * wderiv;
280  } //else {
281  //Real const wderiv( weights[ custom_atom_pair ] );
282  //F1 += f1 * wderiv;
283  //F2 += f2 * wderiv;
284  //}
285  }
286  }
287 } // eval_atom_derivative
288 
289 /// @brief CustomAtomPairEnergy distance cutoff set to be a constant
290 Distance
292 {
293  return interaction_cutoff();
294 }
295 
296 /// @details non-virtual accessor for speed; assumption: CustomAtomPairEnergy is
297 /// not inherited from.
298 Distance
300  return 10;
301 }
302 
303 /// @brief CustomAtomPairEnergy requires no graphs (yet)
304 void
306  utility::vector1< bool > & /* context_graphs_required */
307 ) const {}
308 
309 /// @brief CustomAtomPairEnergy does not define intraresidue interactions
310 bool
312  EnergyMap const & /*weights*/
313 ) const {
314  return false;
315 }
316 
317 void
319  conformation::Residue const & ,
320  pose::Pose const & ,
321  ScoreFunction const & ,
322  EnergyMap &
323 ) const {}
326 {
327  return 1; // Initial versioning
328 }
329 
330 } // methods
331 } // scoring
332 } // core