Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MMLJEnergyIntra.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/ScoreFunction.hh
11 /// @brief molecular mechanics lj energy
12 /// @author P. Douglas Renfrew (renfrew@unc.edu)
13 
14 // Unit headers
18 
19 // Project headers
21 
23 
24 #include <core/pose/Pose.hh>
25 
27 
29 
33 
36 
37 #include <core/scoring/Energies.hh>
38 
40 
41 
42 
43 // Numeric headers
44 #include <numeric/xyzVector.hh>
45 
46 // C++ headers
47 #include <iostream>
48 
51 #include <utility/vector1.hh>
52 
53 
54 namespace core {
55 namespace scoring {
56 namespace methods {
57 
58 /// @details This must return a fresh instance of the MMTorsionEnergy class,
59 /// never an instance already in use
63 ) const {
64  return new MMLJEnergyIntra;
65 }
66 
69  ScoreTypes sts;
70  sts.push_back( mm_lj_intra_atr );
71  sts.push_back( mm_lj_intra_rep );
72  return sts;
73 }
74 
77  potential_( scoring::ScoringManager::get_instance()->get_MMLJEnergyTable() )
78 {}
79 
80 /// clone
83 {
84  return new MMLJEnergyIntra();
85 }
86 
87 void
89  pose::Pose & pose,
90  ScoreFunction const & sfxn,
91  kinematics::MinimizerMapBase const & min_map
92 ) const
93 {
94  // taken for the most part from BaseETableEnergy.hh
95 
96  if ( pose.energies().use_nblist() ) {
97  // stash our nblist inside the pose's energies object
98  Energies & energies( pose.energies() );
99 
100  // get a reference to the MMLJLibrary we are using
102 
103  // setup the atom-atom nblist
104  NeighborListOP nblist( new NeighborList(
105  min_map.domain_map(),
106  library.nblist_dis2_cutoff_XX(),
107  library.nblist_dis2_cutoff_XH(),
108  library.nblist_dis2_cutoff_HH())
109  );
110 
111  if ( pose.energies().use_nblist_auto_update() ) {
112  // setting this to one angstrom fudge factor
113  nblist->set_auto_update( 1 ); // MAGIC NUMBER
114  }
115  // this partially becomes the MMLJEnergy classes's responsibility
116  nblist->setup( pose, sfxn, *this );
117 
118  energies.set_nblist( EnergiesCacheableDataType::MM_LJ_INTRA_NBLIST, nblist );
119  NeighborList nblist_blah( energies.nblist( EnergiesCacheableDataType::MM_LJ_INTRA_NBLIST ) );
120  //std::cout << "In MMLJEnergyIntra setup_for_minimizing()" << std::endl;
121  }
122 }
123 
124 ///
125 bool
127 {
128  return true;
129 }
130 
131 void
133  conformation::Residue const & /*rsd1*/,
134  conformation::Residue const & /*rsd2*/,
135  pose::Pose const & ,
136  ScoreFunction const & ,
137  EnergyMap & /*emap*/
138 ) const
139 {}
140 
141 
142 void
144  conformation::Residue const & rsd,
145  pose::Pose const & pose,
146  ScoreFunction const & scrfxn,
147  EnergyMap & emap
148 ) const
149 {
150  using namespace chemical;
151  using namespace conformation;
152  using namespace etable;
153  using namespace count_pair;
154 
155  Real total_rep(0.0), total_atr(0.0);
156 
157  // get residue info
158  ResidueType const & rsdtype( rsd.type() );
159  Size const & rsdnatom = rsdtype.natoms();
160 
161  // get count pair function
162  //CountPairFunctionOP cpfxn = CountPairFactory::create_intrares_count_pair_function( rsd, CP_CROSSOVER_3 );
163  CountPairFunctionOP cpfxn( (*this).get_intrares_countpair( rsd, pose, scrfxn ) );
164 
165  // iterate over all pairs of atom in the residue
166  for ( int i = 1, i_end = rsdnatom; i <= i_end; ++i ) {
167  conformation::Atom const & atom1( rsd.atom(i) );
168  for ( int j = i + 1, j_end = rsdnatom; j <= j_end; ++j ) {
169  conformation::Atom const & atom2( rsd.atom(j) );
170 
171  Real weight(1.0); // unused
172  Size path_dist(0);
173 
174  // ask count pair if we should score it
175  if ( cpfxn->count( i, j, weight, path_dist ) ) {
176  // calc dist
177  Real dist_squared( atom1.xyz().distance_squared( atom2.xyz() ) );
178  // calc energy
179  Real rep(0), atr(0);
180  potential_.score( rsdtype.atom( i ).mm_atom_type_index(), rsdtype.atom( j ).mm_atom_type_index(), path_dist, dist_squared, rep, atr );
181  total_rep += rep;
182  total_atr += atr;
183 // std::cout << "INTRA"
184 // << " RSD: " << std::setw(22) << rsdtype.name()
185 // << " ATM1: " << std::setw(4) << rsdtype.mm_atom_name(i)
186 // << " ATM2: " << std::setw(4) << rsdtype.mm_atom_name(j)
187 // << " PDST: " << std::setw(4) << path_dist
188 // << " DIST: " << std::setw(8) << atom1.xyz().distance( atom2.xyz() )
189 // << " WGHT: " << std::setw(4) << weight
190 // << " ENER: " << std::setw(8) << energy
191 // << std::endl;
192 
193  }
194  }
195  }
196 
197  // add energies to emap
198  emap[ mm_lj_intra_rep ] += total_rep;
199  emap[ mm_lj_intra_atr ] += total_atr;
200 }
201 
202 void
204  id::AtomID const & id,
205  pose::Pose const & pose,
206  kinematics::DomainMap const & /* domain_map*/,
207  ScoreFunction const & /*sfxn*/,
208  EnergyMap const & /*weights*/,
209  Vector & F1,
210  Vector & F2
211 ) const
212 {
213  // get atom1 from id
214  conformation::Atom const & atom1( pose.residue( id.rsd() ).atom( id.atomno() ) );
215 
216  // check to see if we are using the neighbor list
217  if ( pose.energies().use_nblist() ) {
218 
219  // get atom1's neighbors
220  scoring::Energies const & energies( pose.energies() );
221  scoring::NeighborList const & nblist( energies.nblist( EnergiesCacheableDataType::MM_LJ_INTRA_NBLIST ) );
222  scoring::AtomNeighbors const & nbrs( nblist.atom_neighbors( id ) );
223 
224  // iterate over all of atom1's neighbors using the neighbor list
225  for ( scoring::AtomNeighbors::const_iterator iter=nbrs.begin(), iter_end=nbrs.end(); iter != iter_end; ++iter ) {
226  scoring::AtomNeighbor const & nbr( *iter );
227  conformation::Atom const & atom2( pose.residue( nbr.rsd() ).atom( nbr.atomno() ) );
228 
229  // calculate f1 and f2
230  Vector f1( atom1.xyz().cross( atom2.xyz() ) );
231  Vector f2( atom1.xyz() - atom2.xyz() );
232 
233  // get count pair weight from neighbor list
234  // Real const cp_weight( nbr.weight() );
235 
236  // get distance
237  Real dist_squared( atom1.xyz().distance_squared( atom2.xyz() ) );
238 
239  // get path distance
240  Size path_dist( nbr.path_dist() );
241 
242  // calc deriv
243  Real drep(0), datr(0);
244  potential_.deriv_score( atom1.mm_type(), atom2.mm_type(), path_dist, dist_squared, drep, datr );
245  Real deriv( drep + datr );
246 
247  if ( deriv != 0.0 ) {
248  F1 += deriv * f1;
249  F2 += deriv * f2;
250  }
251  }
252  } else {
253  utility_exit_with_message("non-nblist minimize!");
254  }
255 }
256 
257 /// @brief MMLJEnergy does not have an atomic interation threshold
258 Distance
260 {
261  // this will probably screw up other stuff, but it might not since etable goes to zero at 5.5
262  return 7.0;
263 }
264 
265 /// @brief MMLJEnergy is context independent; indicates that no context graphs are required
266 void
268 {}
269 
270 /// @brief required for neighbor list and to be more lke the ETable
273  Size res1,
274  Size res2,
275  pose::Pose const & pose,
276  ScoreFunction const & sfxn
277 ) const
278 {
279  return get_count_pair_function( pose.residue( res1 ), pose.residue( res2 ), pose, sfxn );
280 }
281 
282 /// @brief required for neighbor list and to be more lke the ETable
285  conformation::Residue const & res1,
286  conformation::Residue const & res2,
287  pose::Pose const & /*pose*/,
288  ScoreFunction const & /*sfxn*/
289 ) const
290 {
291  using namespace etable;
292  using namespace count_pair;
293 
294  return CountPairFunctionOP( CountPairFactory::create_count_pair_function( res1, res2, CP_CROSSOVER_3 ) );
295 }
296 
297 /// @brief required for neighbor list and to be more lke the ETable
300  conformation::Residue const & res,
301  pose::Pose const & /*pose*/,
302  ScoreFunction const & /*sfxn*/
303 ) const
304 {
305  using namespace etable;
306  using namespace count_pair;
307 
308  return CountPairFunctionOP( CountPairFactory::create_intrares_count_pair_function( res, CP_CROSSOVER_3 ) );
309 }
312 {
313  return 1; // Initial versioning
314 }
315 
316 
317 } // namespace methods
318 } // namespace scoring
319 } // namespace core