Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RG_Energy_Fast.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/RG_Energy_Fast.cc
11 /// @brief Radius of gyration energy function definition.
12 /// @author James Thompson
13 
14 
15 // Unit headers
18 
19 // Package headers
23 
24 // Project headers
25 #include <core/pose/Pose.hh>
26 #include <core/id/AtomID.hh>
27 
28 // Utility headers
29 #include <basic/prof.hh>
30 #include <basic/datacache/BasicDataCache.hh>
32 
34 #include <utility/vector1.hh>
35 
36 
37 
38 // C++
39 
40 
41 namespace core {
42 namespace scoring {
43 namespace methods {
44 
45 
46 /// @details This must return a fresh instance of the RG_Energy_Fast class,
47 /// never an instance already in use
51 ) const {
52  return new RG_Energy_Fast;
53 }
54 
57  ScoreTypes sts;
58  sts.push_back( rg );
59  return sts;
60 }
61 
62 
63 /// c-tor
66 {}
67 
68 
69 /// clone
72 {
73  return new RG_Energy_Fast;
74 }
75 
76 /////////////////////////////////////////////////////////////////////////////
77 // scoring
78 /////////////////////////////////////////////////////////////////////////////
79 
80 void
82  pose::Pose & pose,
83  ScoreFunction const &,
84  EnergyMap & totals
85 ) const {
86  using namespace conformation;
87 
88  PROF_START( basic::RG );
89 
90  totals[ rg ] = calculate_rg_score( pose );
91 
92  PROF_STOP( basic::RG );
93 } // finalize_total_energy
94 
97 {
98 
99  Size const nres( pose.total_residue() );
100  Size nres_counted=0;
101 
102  ///////////////////////////////////////
103  //
104  // RG SCORE
105 
106  // calculate center of mass
107  Vector center_of_mass( 0, 0, 0 );
108  for ( Size i = 1; i <= nres; ++i ) {
109  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
110  if ( pose.residue(i).has_variant_type( core::chemical::REPLONLY ) ) continue;
111  if ( pose.residue(i).aa() == core::chemical::aa_vrt ) continue;
112 
113  Vector const v( pose.residue(i).nbr_atom_xyz() );
114  center_of_mass += v;
115  nres_counted++;
116  }
117  center_of_mass /= nres_counted;
118 
119  // calculate RG based on distance from center of mass
120  Real rg_score = 0;
121  for ( Size i = 1; i <= nres; ++i ) {
122  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
123  if ( pose.residue(i).has_variant_type( core::chemical::REPLONLY ) ) continue;
124  if ( pose.residue(i).aa() == core::chemical::aa_vrt ) continue;
125 
126  Vector const v( pose.residue(i).nbr_atom_xyz() );
127  rg_score += v.distance_squared( center_of_mass );
128  }
129 
130  // This definition of rg differs with the conventional definition which
131  // divides by nres and not by nres-1. For the sake of matching r++, it's
132  // being left at nres-1 for now, but is a candidate for change in the near
133  // future.
134  rg_score /= (nres_counted - 1);
135 
136  return sqrt( rg_score );
137 
138 }
139 
142  core::pose::Pose const & pose,
143  utility::vector1< bool > const & relevant_residues) const
144 {
145 
146  Size const nres( pose.total_residue() );
147  Size nres_counted=0;
148 
149  ///////////////////////////////////////
150  //
151  // RG SCORE
152 
153  // calculate center of mass
154  Vector center_of_mass( 0, 0, 0 );
155  for ( Size i = 1; i <= nres; ++i ) {
156  if (!relevant_residues[i]) continue;
157 
158  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
159  if ( pose.residue(i).has_variant_type( core::chemical::REPLONLY ) ) continue;
160  if ( pose.residue(i).aa() == core::chemical::aa_vrt ) continue;
161 
162  Vector const v( pose.residue(i).nbr_atom_xyz() );
163  center_of_mass += v;
164  nres_counted++;
165  }
166  center_of_mass /= nres_counted;
167 
168  // calculate RG based on distance from center of mass
169  Real rg_score = 0;
170  for ( Size i = 1; i <= nres; ++i ) {
171  if (!relevant_residues[i]) continue;
172 
173  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
174  if ( pose.residue(i).has_variant_type( core::chemical::REPLONLY ) ) continue;
175  if ( pose.residue(i).aa() == core::chemical::aa_vrt ) continue;
176 
177  Vector const v( pose.residue(i).nbr_atom_xyz() );
178  rg_score += v.distance_squared( center_of_mass );
179  }
180 
181  // This definition of rg differs with the conventional definition which
182  // divides by nres and not by nres-1. For the sake of matching r++, it's
183  // being left at nres-1 for now, but is a candidate for change in the near
184  // future.
185  rg_score /= (nres_counted - 1);
186 
187  return sqrt( rg_score );
188 
189 }
190 
191 
192 void
194  RG_MinData &mindata = nonconst_mindata_from_pose( pose );
195 
196  // calculate center of mass
197  Size const nres( pose.total_residue() );
198  mindata.nres_scored = 0;
199  mindata.com = Vector( 0, 0, 0 );
200  for ( Size i = 1; i <= nres; ++i ) {
201  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
202  if ( pose.residue(i).has_variant_type( core::chemical::REPLONLY ) ) continue;
203  if ( pose.residue(i).aa() == core::chemical::aa_vrt ) continue;
204 
205  Vector const v( pose.residue(i).nbr_atom_xyz() );
206  mindata.com += v;
207  mindata.nres_scored++;
208  }
209  mindata.com /= mindata.nres_scored;
210 
211  // calulate score
212  mindata.rg = 0;
213  for ( Size i = 1; i <= nres; ++i ) {
214  // ignore scoring residues which have been marked as "REPLONLY" residues (only the repulsive energy will be calculated)
215  if ( pose.residue(i).has_variant_type( core::chemical::REPLONLY ) ) continue;
216  if ( pose.residue(i).aa() == core::chemical::aa_vrt ) continue;
217 
218  Vector const v( pose.residue(i).nbr_atom_xyz() );
219  mindata.rg += v.distance_squared( mindata.com );
220  }
221  mindata.rg = sqrt( mindata.rg / (mindata.nres_scored - 1) );
222 }
223 
224 
225 void
227  id::AtomID const & id,
228  pose::Pose const & pose,
229  kinematics::DomainMap const &, // domain_map,
230  ScoreFunction const & ,
231  EnergyMap const & weights,
232  Vector & F1,
233  Vector & F2
234 ) const {
235  RG_MinData const &mindata = mindata_from_pose( pose );
236 
237  Size resid = id.rsd();
238  Size atmid = id.atomno();
239  core::conformation::Residue const &rsd_i = pose.residue(resid);
241 
242  if (atmid != rsd_i.nbr_atom())
243  return;
244 
245  numeric::xyzVector<core::Real> drg_dx = (X-mindata.com) / (mindata.rg*(mindata.nres_scored - 1));
246 
248  numeric::xyzVector<core::Real> const f2( drg_dx );
249  numeric::xyzVector<core::Real> atom_y = -f2 + atom_x;
250  Vector const f1( atom_x.cross( atom_y ) );
251 
252  F1 += weights[ rg ] * f1;
253  F2 += weights[ rg ] * f2;
254 }
255 
256 
257 RG_MinData const &
259  using namespace core::pose::datacache;
260  return *( static_cast< RG_MinData const * >( pose.data().get_const_ptr( CacheableDataType::RG_MINDATA )() ));
261 
262 }
263 
264 RG_MinData &
267  return *( static_cast< RG_MinData* >( pose.data().get_ptr( core::pose::datacache::CacheableDataType::RG_MINDATA )() ));
268  }
269  // else
270  RG_MinDataOP rgmindata = new RG_MinData;
272  return *rgmindata;
273 }
274 
275 
276 
279 {
280  return 1; // Initial versioning
281 }
282 
283 } // methods
284 } // scoring
285 } // core