Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NeighborList.hh
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
11 /// @brief
12 /// @author
13 
14 
15 #ifndef INCLUDED_core_scoring_NeighborList_hh
16 #define INCLUDED_core_scoring_NeighborList_hh
17 
18 // Unit Headers
20 
21 // Package headers
22 
23 // AUTO-REMOVED #include <core/scoring/EnergyGraph.fwd.hh>
25 // AUTO-REMOVED #include <core/scoring/etable/EtableEnergy.fwd.hh>
26 
27 
28 // Project Headers
29 #include <core/id/AtomID.hh>
30 // AUTO-REMOVED #include <core/kinematics/DomainMap.hh>
31 #include <core/pose/Pose.fwd.hh>
32 #include <core/types.hh>
33 
34 #include <numeric/xyzVector.hh>
35 
36 
37 // Utility Headers
38 // AUTO-REMOVED #include <utility/vector1.hh>
39 #include <utility/pointer/owning_ptr.hh>
40 #include <utility/pointer/ReferenceCount.hh>
41 
43 #include <utility/vector1.hh>
44 #include <ObjexxFCL/FArray1D.hh>
45 
46 
47 
48 namespace core {
49 namespace scoring {
50 
51  /// an atom-atom neighborlist object
52 
53  /**
54  The neighborlist is used during minimization to speed atom-atom energy
55  calculations. It stores a list of potentially interacting neighbor atoms
56  for each atom in the system.
57 
58  The logic for using the nblist is tricky.
59 
60  Tentative scheme:
61  turn on nblist scoring at start of minimization
62 
63  // at this point, want pose to be fully scored
64  // so perhaps a call to scorefxn(pose) ??
65  // Real const start_score( scorefxn( pose ) );
66 
67  pose.energies().setup_use_nblist( true );
68 
69  Real const start_func( func( vars ) ); // nblist setup inside this call
70 
71  now require that all energy evaluations have an identical set of moving
72  dofs (guaranteed if all energy calculations are inside function
73  evaluations). This is checked inside each scorecaln using the
74  nblist.
75 
76  when using the nblist, the rsd-rsd neighbor information is not
77  updated. This will probably be a good thing in that it will smooth
78  the energy landscape during minimization...
79 
80  in a nblist score calculation, we do two things: recover cached
81  energies for non-pair-moved positions, and get atom-atom energies
82  for the pairs that are on the nblist. We don't cache 2d energies
83  for moving positions, since we are not looping over rsd nbr links
84  for that score calculation so the caching would be pretty time-
85  consuming I think.
86 
87  The nblist has the count_pair weights stored, so no calls to
88  count_pair !!
89 
90  turn off nblist scoring at the end of minimization. Since we have not
91  been updating rsd-pair energies for moving pairs, and the rsd-rsd
92  nblist is potentially out of data, we reset the neighborgraph at this
93  point to ensure a complete score calculation next time.
94 
95  **/
96 
97 // move to separate file
99 {
100 public:
101  AtomNeighbor() : rsd_( 0 ), atomno_( 0 ), path_dist_( 0 ), weight_( 0.0 ), weight_func_( 0.0 ) {}
102 
104  int const rsd_in,
105  int const atomno_in,
106  Size const path_dist_in,
107  Real const weight_in,
108  Real const weight_func_in = 1
109  ):
110  rsd_(rsd_in),
111  atomno_(atomno_in),
112  path_dist_(path_dist_in),
113  weight_(weight_in),
114  weight_func_(weight_func_in)
115  {}
116 
117 
118  ///
119  int
120  rsd() const
121  {
122  return rsd_;
123  }
124 
125  ///
126  int
127  atomno() const
128  {
129  return atomno_;
130  }
131 
132  Size
133  path_dist() const
134  {
135  return path_dist_;
136  }
137 
138  ///
139  Real
140  weight() const
141  {
142  return weight_;
143  }
144 
145  ///fpd
146  Real
147  weight_func() const
148  {
149  return weight_func_;
150  }
151 
152 
153  Real & temp1() const { return temp1_; }
154  Real & temp2() const { return temp2_; }
155  Real & temp3() const { return temp3_; }
156  Real & temp4() const { return temp4_; }
157 
158 
159 private:
160  int rsd_;
161  int atomno_;
165 
166  mutable Real temp1_;
167  mutable Real temp2_;
168  mutable Real temp3_;
169  mutable Real temp4_;
170 
171 };
172 
174 
175 ///////////////////////////////////////////////////////////////////////////////
177 {
178 public:
179  NeighborList(
181  Real const XX_cutoff,
182  Real const XH_cutoff,
183  Real const HH_cutoff
184  );
185 
186  virtual
187  ~NeighborList();
188 
189  // Clone method used in copy ctors of classes that contain NeighborListOP's
190  // like, for example, Energies.
191  NeighborListOP clone() const { return new NeighborList( *this ); }
192 
193  ///
194  AtomNeighbors const &
196  int const pos,
197  int const atomno
198  ) const
199  {
200  return nblist_[ pos ][ atomno ];
201  }
202 
203  ///
204  AtomNeighbors const &
206  id::AtomID const & id
207  ) const
208  {
209  return nblist_[ id.rsd() ][ id.atomno() ];
210  }
211 
212  AtomNeighbors const &
214  int const pos,
215  int const atomno
216  ) const
217  {
218  return upper_nblist_[ pos ][ atomno ];
219  }
220 
221  ///
222  AtomNeighbors const &
224  id::AtomID const & id
225  ) const
226  {
227  return upper_nblist_[ id.rsd() ][ id.atomno() ];
228  }
229 
230  AtomNeighbors const &
232  int const pos,
233  int const atomno
234  ) const
235  {
236  return intrares_upper_nblist_[ pos ][ atomno ];
237  }
238 
239  ///
240  AtomNeighbors const &
242  id::AtomID const & id
243  ) const
244  {
245  return intrares_upper_nblist_[ id.rsd() ][ id.atomno() ];
246  }
247 
248 
249 
250  /// @brief Initialize the nblist so that it reflects the current coordinates in the pose.
251  template < class T_Etable >
252  void
253  setup(
254  pose::Pose const & pose,
255  ScoreFunction const & sfxn,
256  T_Etable const & etable_method
257  ) const;
258 
259  ///
260  void
262  kinematics::DomainMap const & domain_map_in
263  ) const;
264 
265 
266  ///
267  void
269  {
270  nblist_.clear();
271  }
272 
273  ///
274  kinematics::DomainMap const &
275  domain_map() const
276  {
277  return domain_map_;
278  }
279 
280  /// @brief If auto_update_, ensure that no atom in the pose has not moved too much
281  /// since the last time the neighborlist was updated. The neighborlist
282  /// tracks the starting coords for all atoms, and then updates
283  template < class T_Etable >
284  void
286  pose::Pose const & pose,
287  ScoreFunction const & sfxn,
288  T_Etable const & etable_method
289  ) const;
290 
291  void
292  set_auto_update( Distance move_tolerance );
293 
294  void
296 
297 private:
298 
299  void
300  update_from_wide_nblist( pose::Pose const & pose ) const;
301 
302  inline
304  atom_pair_cutoff( bool atom1_is_hydrogen, bool atom2_is_hydrogen ) const
305  {
306  return ( ( atom1_is_hydrogen && atom2_is_hydrogen ) ?
307  HH_cutoff_ : ( ( atom1_is_hydrogen || atom2_is_hydrogen ) ?
308  XH_cutoff_ : XX_cutoff_ ) );
309  }
310 
311 protected:
312 
313  void
314  declare_atoms_neighbors( id::AtomID at1, id::AtomID at2, Size path_dist, Real weight, Real weight_func = 1.0 ) const;
315 
316  void
317  declare_atom_neighbor_1sided( id::AtomID at1, id::AtomID at2, Size path_dist, Real weight, Real weight_func = 1.0 ) const;
318 
319 private:
320 
322 
323  //square of how far can any atom move before the nblist needs to be updated
325 
326  // How far out should the wide nblist reach beyond XX_cutoff_
328 
329  // square of the coordinate movement before the wide_nblist's data becomes stale
330  // == ( wide_nblist_extension - sqrt( move_tolerance_) ) ^ 2
332 
339 
344 
348 
349 
350  /// Separation square distance for atom pairs in kept in the wide neighbor list
354 
355  /// Variables for updating the nblist from the wide nblist
356  /// don't use v1< bool >: too slow
358  //mutable utility::vector1< utility::vector1< Size > > atom_has_been_updated_from_wide_;
360 
364 };
365 
367 
368 } // namespace scoring
369 } // namespace core
370 
371 
372 #endif