Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ElecDensAtomwiseEnergy.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 src/core/scoring/electron_density_atomwise/ElecDensAtomwiseEnergy.cc
11 /// @brief elec_dens_atomwise scoring method implementation
12 /// @author Fang-Chieh Chou
13 
14 // Unit headers
18 
19 // Package headers
22 
23 // Project headers
24 #include <core/pose/Pose.hh>
25 #include <core/scoring/Energies.hh>
27 
28 //
31 #include <core/chemical/AA.hh>
32 #include <core/kinematics/Edge.hh>
37 #include <core/id/AtomID.hh>
38 #include <basic/Tracer.hh>
39 
40 using basic::T;
41 using basic::Error;
42 using basic::Warning;
43 
44 
45 namespace core {
46 namespace scoring {
47 namespace electron_density_atomwise {
48 
49 using namespace core;
50 static basic::Tracer TR ( "core.scoring.electron_density_atomwise.ElecDensAtomwiseEnergy" );
51 
52 /// @details This must return a fresh instance of the ElecDensAtomwiseEnergy class,
53 /// never an instance already in use
57 ) const {
58  return new ElecDensAtomwiseEnergy;
59 }
60 
63  ScoreTypes sts;
64  sts.push_back ( elec_dens_atomwise );
65  return sts;
66 }
67 
71 }
72 
75  //Load map
77 }
78 
80 
81 /// clone
83  return new ElecDensAtomwiseEnergy ( *this );
84 }
85 
86 
87 void
89  pose::Pose & pose,
90  ScoreFunction const &
91 ) const {
92  using namespace methods;
93 
94  // Do we have a map?
95  if ( !get_density_map().isMapLoaded() ) {
96  utility_exit_with_message ( "Density scoring function called but no map loaded." );
97  }
98 
99  // make sure the root of the FoldTree is a virtual atom and is followed by a jump
100  // if not, emit warning
101  kinematics::Edge const &root_edge ( *pose.fold_tree().begin() );
102  int virt_res_idx = root_edge.start();
103  conformation::Residue const &root_res ( pose.residue ( virt_res_idx ) );
104  pose_is_proper = true;
105 
106  if ( root_res.aa() != core::chemical::aa_vrt || root_edge.label() < 0 ) {
107  pose_is_proper = false; // we may be able to recover from this some time but for now just exit
108  utility_exit_with_message ( "Fold tree is not set properly for density scoring!" );
109  }
110 
111  // create LR energy container
112  LongRangeEnergyType const & lr_type ( long_range_type() );
113  Energies & energies ( pose.energies() );
114  bool create_new_lre_container ( false );
115 
116  if ( energies.long_range_container ( lr_type ) == 0 ) {
117  create_new_lre_container = true;
118  } else {
119  LREnergyContainerOP lrc = energies.nonconst_long_range_container ( lr_type );
120  OneToAllEnergyContainerOP dec ( static_cast< OneToAllEnergyContainer * > ( lrc.get() ) );
121 
122  // make sure size or root did not change
123  if ( dec->size() != pose.total_residue() || dec->fixed() != virt_res_idx ) {
124  create_new_lre_container = true;
125  }
126  }
127 
128  if ( create_new_lre_container ) {
129  TR << "Creating new one-to-all energy container (" << pose.total_residue() << ")" << std::endl;
131  virt_res_idx, pose.total_residue(), elec_dens_atomwise );
132  energies.set_long_range_container ( lr_type, new_dec );
133  }
134 
135  //Pre-calculate the normalization factor and the correlation per
136  //atom
139 }
140 
141 ///////////////////////////////////////////////////////////////////////
142 ///
144  pose::Pose const & pose,
145  Size res1,
146  Size res2
147 ) const {
148  return ( pose.residue ( res1 ).aa() == core::chemical::aa_vrt || pose.residue ( res2 ).aa() == core::chemical::aa_vrt );
149 }
150 
151 ///Compute the residue energy
152 void
154  conformation::Residue const & rsd1,
155  conformation::Residue const & rsd2,
156  pose::Pose const &,
157  ScoreFunction const &,
158  EnergyMap & emap
159 ) const {
160  if ( rsd1.aa() != core::chemical::aa_vrt ) {
161  if ( rsd2.aa() != core::chemical::aa_vrt ) return;
162  } else {
163  if ( rsd2.aa() == core::chemical::aa_vrt ) return;
164  }
165 
166  conformation::Residue const &rsd ( rsd1.aa() == core::chemical::aa_vrt ? rsd2 : rsd1 );
168 }
169 
170 void
172  id::AtomID const & id,
173  pose::Pose const & pose,
174  kinematics::DomainMap const &, // domain_map,
175  ScoreFunction const &,
176  EnergyMap const & weights,
177  Vector & F1,
178  Vector & F2
179 ) const {
180  core::Size const &rsd_id = id.rsd();
181  core::Size const &atm_id = id.atomno();
182 
183  // derivatives only defined for (non-VRT) heavyatoms
184  if ( pose.residue ( rsd_id ).aa() == core::chemical::aa_vrt ) return;
185 
186  // if (hydrogen) return
187  if ( !pose.residue ( rsd_id ).atom_type ( atm_id ).is_heavyatom() ) return;
188 
189  numeric::xyzVector<core::Real> grad = get_density_map().atom_gradient ( pose, rsd_id, atm_id );
190  Vector atom_xyz = pose.xyz ( id );
191  Vector f2 = grad;
192  Vector f1 ( atom_xyz.cross ( atom_xyz - f2 ) );
193  F1 += weights[ elec_dens_atomwise ] * f1;
194  F2 += weights[ elec_dens_atomwise ] * f2;
195  return;
196 }
197 
200  return 1; // Initial versioning
201 }
202 
203 } // electron_density_atomwise
204 } // scoring
205 } // core
206