Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DenseEnergyContainer.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 core/scoring/LongRangeEnergyContainer.hh
11 /// @brief A container interface for storing and scoring long range energies
12 /// @author Andrew Leaver-Fay
13 
14 #ifndef INCLUDED_core_scoring_DenseEnergyContainer_hh
15 #define INCLUDED_core_scoring_DenseEnergyContainer_hh
16 
17 // Unit headers
19 
20 // Package headers
21 #include <core/types.hh>
25 
26 // Utility headers
27 
28 // ObjexxFCL headers
29 #include <ObjexxFCL/FArray2D.hh>
30 
31 #include <utility/vector1.hh>
32 
33 
34 
35 namespace core {
36 namespace scoring {
37 
38 ///////////////////////////////////////////////////////
39 
41 {
42 public:
44 
46  Size const pos1_in,
47  Size const pos2_in,
48  ScoreType const st,
49  ObjexxFCL::FArray2D< Real > * table_in,
50  ObjexxFCL::FArray2D< bool > * computed_in
51  ):
52  pos1_( pos1_in ),
53  pos2_( pos2_in ),
54  score_type_( st ),
55  table_( table_in ),
56  computed_( computed_in )
57  {}
58 
60  {
61  assert( dynamic_cast< DenseNeighborIterator const * >( &src ) );
62  DenseNeighborIterator const & my_src( static_cast< DenseNeighborIterator const & >( src ) );
63  pos1_ = my_src.pos1_;
64  pos2_ = my_src.pos2_;
65  table_ = my_src.table_;
66  computed_ = my_src.computed_;
67  return *this;
68  }
69 
71  {
72  ++pos2_;
73  if ( pos2_ == pos1_ ) ++pos2_;
74  return *this;
75  }
76 
77  virtual bool operator == ( ResidueNeighborIterator const & other ) const
78  {
79  return ( residue_iterated_on() == other.residue_iterated_on() &&
80  neighbor_id() == other.neighbor_id() );
81  }
82 
83  virtual bool operator != ( ResidueNeighborIterator const & other ) const
84  {
85  return !( *this == other );
86  }
87 
88  virtual Size upper_neighbor_id() const
89  {
90  return std::max( pos1_, pos2_ );
91  }
92 
93  virtual Size lower_neighbor_id() const
94  {
95  return std::min( pos1_, pos2_ );
96  }
97 
98  virtual Size residue_iterated_on() const
99  {
100  return pos1_;
101  }
102 
103  virtual Size neighbor_id() const
104  {
105  return pos2_;
106  }
107 
108  virtual void save_energy( EnergyMap const & emap )
109  {
110  Real const energy( emap[ score_type_ ] );
111  (*table_)( pos1_, pos2_ ) = energy;
112  (*table_)( pos2_, pos1_ ) = energy;
113  }
114 
115  virtual void retrieve_energy( EnergyMap & emap ) const
116  {
117  emap[ score_type_ ] = (*table_)(pos1_,pos2_);
118  }
119 
120  virtual void accumulate_energy( EnergyMap & emap ) const
121  {
122  emap[ score_type_ ] += (*table_)(pos1_, pos2_);
123  }
124 
125  virtual void mark_energy_computed()
126  {
127  (*computed_)( pos1_, pos2_ ) = true;
128  (*computed_)( pos2_, pos1_ ) = true;
129  }
130 
131  virtual void mark_energy_uncomputed()
132  {
133  (*computed_)( pos1_, pos2_ ) = false;
134  (*computed_)( pos2_, pos1_ ) = false;
135  }
136 
137  virtual bool energy_computed() const
138  {
139  return (*computed_)( pos1_, pos2_ );
140  }
141 
142 private:
146  ObjexxFCL::FArray2D< Real > * table_;
147  ObjexxFCL::FArray2D< bool > * computed_;
148 };
149 
150 
151 ///////////////////////////////////////////////////////
152 
154 {
155 public:
157 
159  Size const pos1_in,
160  Size const pos2_in,
161  ScoreType const st,
162  ObjexxFCL::FArray2D< Real > const * table_in,
163  ObjexxFCL::FArray2D< bool > const * computed_in
164  ):
165  pos1_( pos1_in ),
166  pos2_( pos2_in ),
167  score_type_( st ),
168  table_( table_in ),
169  computed_( computed_in )
170  {}
171 
173  {
174  assert( dynamic_cast< DenseNeighborConstIterator const * >( &src ) );
175  DenseNeighborConstIterator const & my_src( static_cast< DenseNeighborConstIterator const & >( src ) );
176  pos1_ = my_src.pos1_;
177  pos2_ = my_src.pos2_;
178  table_ = my_src.table_;
179  computed_ = my_src.computed_;
180  return *this;
181  }
182 
184  {
185  ++pos2_;
186  if ( pos2_ == pos1_ ) ++pos2_;
187  return *this;
188  }
189 
190  virtual bool operator == ( ResidueNeighborConstIterator const & other ) const
191  {
192  return ( residue_iterated_on() == other.residue_iterated_on() &&
193  neighbor_id() == other.neighbor_id() );
194  }
195 
196  virtual bool operator != ( ResidueNeighborConstIterator const & other ) const
197  {
198  return !( *this == other );
199  }
200 
201  virtual Size upper_neighbor_id() const
202  {
203  return std::max( pos1_, pos2_ );
204  }
205 
206  virtual Size lower_neighbor_id() const
207  {
208  return std::min( pos1_, pos2_ );
209  }
210 
211  virtual Size residue_iterated_on() const
212  {
213  return pos1_;
214  }
215 
216  virtual Size neighbor_id() const
217  {
218  return pos2_;
219  }
220 
221 // virtual void save_energy( EnergyMap const & emap )
222 // {
223 // Real const energy( emap[ score_type_ ] );
224 // (*table_)( pos1_, pos2_ ) = energy;
225 // (*table_)( pos2_, pos1_ ) = energy;
226 // }
227 
228  virtual void retrieve_energy( EnergyMap & emap ) const
229  {
230  emap[ score_type_ ] = (*table_)(pos1_,pos2_);
231  }
232 
233  virtual void accumulate_energy( EnergyMap & emap ) const
234  {
235  emap[ score_type_ ] += (*table_)(pos1_, pos2_);
236  }
237 
238 // virtual void mark_energy_computed()
239 // {
240 // (*computed_)( pos1_, pos2_ ) = true;
241 // (*computed_)( pos2_, pos1_ ) = true;
242 // }
243 
244 // virtual void mark_energy_uncomputed()
245 // {
246 // (*computed_)( pos1_, pos2_ ) = false;
247 // (*computed_)( pos2_, pos1_ ) = false;
248 // }
249 
250  virtual bool energy_computed() const
251  {
252  return (*computed_)( pos1_, pos2_ );
253  }
254 
255 private:
259  ObjexxFCL::FArray2D< Real > const * table_;
260  ObjexxFCL::FArray2D< bool > const * computed_;
261 };
262 
263 ///////////////////////////////////////////////////////////////////////////
264 
266 {
267 public:
268  virtual
270 
271  virtual
273  {
274  return new DenseEnergyContainer( *this );
275  }
276 
277  DenseEnergyContainer( Size const size_in, ScoreType const score_type_in ):
278  size_( size_in ),
279  score_type_( score_type_in ),
280  table_( size_, size_, 0.0 ),
281  computed_( size_, size_, false )
282  {}
283 
284  virtual
285  bool empty() const
286  {
287  return ( size_ == 0 );
288  }
289 
290  virtual
291  void
292  set_num_nodes( Size size_in ) {
293  size_ = size_in;
294  table_.dimension( size_ , size_, 0.0 );
295  computed_.dimension( size_, size_, false );
296  }
297 
298  Size
299  size() const
300  {
301  return size_;
302  }
303 
304  //////////////////// const versions
305  virtual
307  const_neighbor_iterator_begin( int resid ) const
308  {
309  return new DenseNeighborConstIterator( resid, resid==1 ? 2 : 1, score_type_, &table_, &computed_ );
310  }
311 
312  virtual
314  const_neighbor_iterator_end( int resid ) const
315  {
316  return new DenseNeighborConstIterator( resid, size_ + 1, score_type_, &table_, &computed_ );
317  }
318 
319  virtual
322  {
323  return new DenseNeighborConstIterator( resid, resid+1, score_type_, &table_, &computed_ );
324  }
325 
326  virtual
329  {
330  return const_neighbor_iterator_end( resid );
331  }
332 
333  //////////////////// non-const versions
334  virtual
337  {
338  return new DenseNeighborIterator( resid, 1, score_type_, &table_, &computed_ );
339  }
340 
341  virtual
344  {
345  return new DenseNeighborIterator( resid, size_ + 1, score_type_, &table_, &computed_ );
346  }
347 
348  virtual
351  {
352  return new DenseNeighborIterator( resid, resid+1, score_type_, &table_, &computed_ );
353  }
354 
355  virtual
358  {
359  return neighbor_iterator_end( resid );
360  }
361 
362 private:
363  Size /*const*/ size_;
365 
366  ObjexxFCL::FArray2D< Real > table_;
367  ObjexxFCL::FArray2D< bool > computed_;
368 
369 };
370 
371 } // namespace scoring
372 } // namespace core
373 
374 #endif