Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PattersonCorrEnergy.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file core/scoring/methods/PattersonCorrEnergy.cc
10 /// @brief Scoring a structure's fit to electron density
11 /// @author Frank DiMaio
12 
13 
14 // Unit headers
17 #include <basic/options/option.hh>
18 
19 // Package headers
20 #include <core/chemical/AA.hh>
23 
24 #include <core/scoring/Energies.hh>
25 // AUTO-REMOVED #include <core/scoring/EnergyGraph.hh>
26 
29 #include <numeric/xyz.functions.hh>
30 #include <numeric/statistics.functions.hh>
31 #include <core/kinematics/Edge.hh>
33 
34 // AUTO-REMOVED #include <core/conformation/symmetry/SymmetryInfo.hh>
37 // AUTO-REMOVED #include <core/conformation/symmetry/util.hh>
38 
39 
40 // Project headers
41 #include <core/pose/Pose.hh>
43 
44 // AUTO-REMOVED #include <basic/options/keys/edensity.OptionKeys.gen.hh>
45 #include <basic/options/keys/patterson.OptionKeys.gen.hh>
46 
47 // Utility headers
48 
49 //
50 #include <basic/Tracer.hh>
51 
54 #include <utility/vector1.hh>
55 
56 #ifdef WIN32
57  #define _USE_MATH_DEFINES
58  #include <math.h>
59 #endif
60 
61 using basic::T;
62 using basic::Error;
63 using basic::Warning;
64 
65 // C++
66 
67 namespace core {
68 namespace scoring {
69 namespace electron_density {
70 
71 
72 /// @details This must return a fresh instance of the PattersonCorrEnergy class,
73 /// never an instance already in use
77 ) const {
78  return new PattersonCorrEnergy;
79 }
80 
83  ScoreTypes sts;
84  sts.push_back( patterson_cc );
85  return sts;
86 }
87 
88 inline core::Real SQ( core::Real N ) { return N*N; }
89 
90 using namespace core::scoring::methods;
91 static basic::Tracer TR("core.scoring.electron_density.PattersonCorrEnergy");
92 
95 
96 /// c-tor
99  scoreRepacks = basic::options::option[ basic::options::OptionKeys::patterson::use_on_repack ]();
100 }
101 
102 
103 /// clone
105  return new PattersonCorrEnergy( *this );
106 }
107 
108 /////////////////////////////////////////////////////////////////////////////
109 
111  pose::Pose const & pose,
112  Size res1,
113  Size res2
114 ) const {
115  return ( pose.residue( res1 ).aa() == core::chemical::aa_vrt || pose.residue( res2 ).aa() == core::chemical::aa_vrt );
116 }
117 
118 
119 void
121  if (!pose.is_fullatom()) return;
122 
124 }
125 
126 void
128 }
129 
130 void
132  pose::Pose & pose,
133  ScoreFunction const &
134 ) const {
135  using namespace methods;
136 
137  // after packing the pose is rescored
138  isRepacking = false;
139 
140  // Do we have a map?
141  if (!map_loaded) {
142  utility_exit_with_message("Density scoring function called but no map loaded.");
143  }
144 
145  // make sure the root of the FoldTree is a virtual atom and is followed by a jump
146  kinematics::Edge const &root_edge ( *pose.fold_tree().begin() );
147  int virt_res_idx = root_edge.start();
148  conformation::Residue const &root_res( pose.residue( virt_res_idx ) );
149 
150  // create LR energy container
151  LongRangeEnergyType const & lr_type( long_range_type() );
152  Energies & energies( pose.energies() );
153  bool create_new_lre_container( false );
154 
155  if ( energies.long_range_container( lr_type ) == 0 ) {
156  create_new_lre_container = true;
157  } else {
158  LREnergyContainerOP lrc = energies.nonconst_long_range_container( lr_type );
159  OneToAllEnergyContainerOP dec( static_cast< OneToAllEnergyContainer * > ( lrc.get() ) );
160  // make sure size or root did not change
161  if ( dec->size() != pose.total_residue() || dec->fixed() != virt_res_idx ) {
162  create_new_lre_container = true;
163  }
164  }
165 
166  if ( create_new_lre_container ) {
167  TR << "Creating new one-to-all energy container (" << pose.total_residue() << ")" << std::endl;
168  LREnergyContainerOP new_dec = new OneToAllEnergyContainer( virt_res_idx, pose.total_residue(), elec_dens_window );
169  energies.set_long_range_container( lr_type, new_dec );
170  }
171 
172  pose_is_proper = true;
173  if (root_res.aa() != core::chemical::aa_vrt || root_edge.label() < 0) {
174  pose_is_proper = false; // we may be able to recover from this some time but for now just exit
175  //utility_exit_with_message("Fold tree is not set properly for density scoring!");
176  TR.Warning << "Fold tree is not set properly for patterson function scoring." << std::endl;
177  pcc_structure = 0.0;
178  return;
179  }
180 
181  // allocate space for per-AA stats
182  int nres = pose.total_residue();
184 
185  // do the actual matching here; split scores among individual residues
187 
188  // # of NON-VRT residues
189  nreses = 0;
190  for (int i=1; i<=(int)pose.total_residue(); ++i)
191  if (pose.residue(i).aa() != core::chemical::aa_vrt)
192  nreses++;
193 
194  TR.Debug << "PattersonCorrEnergy::setup_for_scoring() returns PCC = " << pcc_structure << std::endl;
195 }
196 
197 
198 void
200  pose::Pose const & ,
201  ScoreFunction const &,
202  EnergyMap &
203 ) const {
204  return;
205 }
206 
207 
208 void
210  conformation::Residue const & rsd1,
211  conformation::Residue const & rsd2,
212  pose::Pose const & /* pose */,
213  ScoreFunction const &,
214  EnergyMap & emap
215 ) const {
216  if (!pose_is_proper) return;
217 
218  using namespace numeric::statistics;
219 
220  if (rsd1.aa() != core::chemical::aa_vrt && rsd2.aa() != core::chemical::aa_vrt) return;
221  if (rsd1.aa() == core::chemical::aa_vrt && rsd2.aa() == core::chemical::aa_vrt) return;
222 
223  conformation::Residue const & rsd = (rsd1.aa() == core::chemical::aa_vrt) ? rsd2 : rsd1;
224 
225  if ( isRepacking && scoreRepacks) {
226  // update patterson map quickly only moving sidechain of 'rsd'
228  emap[ patterson_cc ] += -cc;
229  TR.Debug << "Rescore residue " << rsd.seqpos() << " : patterson CC = " << cc << std::endl;
230  } else {
231  // just return score from setup_for_scoring
232  emap[ patterson_cc ] += -pcc_structure;
233  }
234 
235  return;
236 }
237 
238 void
240  pose::Pose &pose,
241  Size resid
242 ) const {
243  if (!pose_is_proper) return;
244 
246  //std::cout << "UPDATE residue " << resid << " " << std::endl;
247 }
248 
249 
250 void
252  id::AtomID const & id,
253  pose::Pose const & pose,
254  kinematics::DomainMap const &, // domain_map,
255  ScoreFunction const & ,
256  EnergyMap const & weights,
257  Vector & F1,
258  Vector & F2
259 ) const
260 {
261  if (!pose_is_proper) return;
262  if (!pose.is_fullatom()) return;
263 
264  using namespace numeric::statistics;
265 
266  int resid = id.rsd();
267  int atmid = id.atomno();
268 
269  // if (hydrogen) return
270  if ( pose.residue(resid).aa() != core::chemical::aa_vrt && !pose.residue(resid).atom_type(atmid).is_heavyatom() ) return;
271 
275 
277  ; // TO DO
278  } else {
279  // ASYMMETRIC CASE
280 
281  core::scoring::electron_density::getDensityMap().dCCdx_pat( atmid, resid, X, pose, dCCdx );
283 
285  numeric::xyzVector<core::Real> const f2( dEdx );
286  numeric::xyzVector<core::Real> atom_y = -f2 + atom_x;
287  Vector const f1( atom_x.cross( atom_y ) );
288 
289  F1 += weights[ patterson_cc ] * f1;
290  F2 += weights[ patterson_cc ] * f2;
291  }
292 }
295 {
296  return 1; // Initial versioning
297 }
298 
299 
300 }
301 }
302 }