Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PeptideBondedEnergyContainer.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/PeptideBondedEnergyContainer.hh
11 /// @brief A container interface long range energies for n->n+1 interactions only
12 /// @author Frank DiMaio
13 
14 #ifndef INCLUDED_core_scoring_PeptideBondedEnergyContainer_hh
15 #define INCLUDED_core_scoring_PeptideBondedEnergyContainer_hh
16 
17 // Unit headers
19 
20 // Package headers
23 
24 // Utility headers
25 #include <utility/pointer/ReferenceCount.hh>
26 
27 #include <utility/vector1.hh>
28 
29 namespace core {
30 namespace scoring {
31 
32 ///////////////////////////////////////////////////////
33 
35 {
36 public:
38 
40  Size const base_in,
41  Size const pos_in,
44  utility::vector1< bool > * computed_in
45  ):
46  base_( base_in ),
47  pos_( pos_in ),
48  score_types_( st ),
49  tables_( table_in ),
50  computed_( computed_in )
51  {}
52 
54  assert( dynamic_cast< PeptideBondedNeighborIterator const * >( &src ) );
55  PeptideBondedNeighborIterator const & my_src( static_cast< PeptideBondedNeighborIterator const & >( src ) );
56  base_ = my_src.base_;
57  pos_ = my_src.pos_;
58  tables_ = my_src.tables_;
59  computed_ = my_src.computed_;
60  return *this;
61  }
62 
64  ++pos_;
65  if (pos_ == base_) ++pos_;
66  return *this;
67  }
68 
69  virtual bool operator == ( ResidueNeighborIterator const & other ) const
70  {
71  return ( residue_iterated_on() == other.residue_iterated_on() &&
72  neighbor_id() == other.neighbor_id() );
73  }
74 
75  virtual bool operator != ( ResidueNeighborIterator const & other ) const
76  {
77  return !( *this == other );
78  }
79 
80  virtual Size upper_neighbor_id() const {
81  return std::max(pos_,base_);
82  }
83 
84  virtual Size lower_neighbor_id() const {
85  return std::min(pos_,base_);
86  }
87 
88  virtual Size residue_iterated_on() const {
89  return base_;
90  }
91 
92  virtual Size neighbor_id() const {
93  return pos_;
94  }
95 
96  virtual void save_energy( EnergyMap const & emap ) {
97  for (Size i=1; i<=score_types_.size(); ++i)
98  {
99  Real const energy( emap[ score_types_[i] ] );
100  (*tables_)[ std::min(pos_,base_) ][i] = energy;
101  }
102  }
103 
104  virtual void retrieve_energy( EnergyMap & emap ) const {
105  for (Size i=1; i<=score_types_.size(); ++i)
106  emap[ score_types_[i] ] = (*tables_)[std::min(pos_,base_)][i];
107  }
108 
109  virtual void accumulate_energy( EnergyMap & emap ) const {
110  for (Size i=1; i<=score_types_.size(); ++i)
111  emap[ score_types_[i] ] += (*tables_)[std::min(pos_,base_)][i];
112  }
113 
114  virtual void mark_energy_computed() {
115  (*computed_)[ std::min(pos_,base_) ] = true;
116  }
117 
118  virtual void mark_energy_uncomputed() {
119  (*computed_)[ std::min(pos_,base_) ] = false;
120  }
121 
122  virtual bool energy_computed() const {
123  return (*computed_)[ std::min(pos_,base_) ];
124  }
125 
126 private:
132 };
133 
134 
135 ///////////////////////////////////////////////////////
136 
138 {
139 public:
141 
143  Size const base_in,
144  Size const pos_in,
146  utility::vector1< utility::vector1< Real > > const * table_in,
147  utility::vector1< bool > const * computed_in
148  ):
149  base_( base_in ),
150  pos_( pos_in ),
151  score_types_( st ),
152  tables_( table_in ),
153  computed_( computed_in )
154  {}
155 
157  assert( dynamic_cast< PeptideBondedNeighborConstIterator const * >( &src ) );
158  PeptideBondedNeighborConstIterator const & my_src( static_cast< PeptideBondedNeighborConstIterator const & >( src ) );
159  pos_ = my_src.pos_;
160  tables_ = my_src.tables_;
161  computed_ = my_src.computed_;
162  return *this;
163  }
164 
166  ++pos_;
167  if (pos_ == base_) ++pos_;
168  return *this;
169  }
170 
171  virtual bool operator == ( ResidueNeighborConstIterator const & other ) const {
172  return ( residue_iterated_on() == other.residue_iterated_on() &&
173  neighbor_id() == other.neighbor_id() );
174  }
175 
176  virtual bool operator != ( ResidueNeighborConstIterator const & other ) const {
177  return !( *this == other );
178  }
179 
180  virtual Size upper_neighbor_id() const {
181  return std::max(pos_,base_);
182  }
183 
184  virtual Size lower_neighbor_id() const {
185  return std::min(pos_,base_);
186  }
187 
188  virtual Size residue_iterated_on() const {
189  return base_;
190  }
191 
192  virtual Size neighbor_id() const {
193  return pos_;
194  }
195 
196  virtual void retrieve_energy( EnergyMap & emap ) const {
197  for (Size i=1; i<=score_types_.size(); ++i)
198  emap[ score_types_[i] ] = (*tables_)[std::min(pos_,base_)][i];
199  }
200 
201  virtual void accumulate_energy( EnergyMap & emap ) const {
202  for (Size i=1; i<=score_types_.size(); ++i)
203  emap[ score_types_[i] ] += (*tables_)[std::min(pos_,base_)][i];
204  }
205 
206  virtual bool energy_computed() const {
207  return (*computed_)[ std::min(pos_,base_) ];
208  }
209 
210 private:
216 };
217 
218 ///////////////////////////////////////////////////////////////////////////
219 
221 public:
222  virtual
224 
225  virtual
227  return new PeptideBondedEnergyContainer( *this );
228  }
229 
230  PeptideBondedEnergyContainer( Size const size_in, utility::vector1< ScoreType > const score_type_in ):
231  size_( size_in ),
232  score_types_( score_type_in ),
233  computed_( size_in, false )
234  {
235  int nscoretypes = score_type_in.size();
236  tables_.resize( size_in, utility::vector1< core::Real >(nscoretypes,0) );
237  }
238 
239  virtual
240  bool empty() const {
241  return ( size_ == 0 );
242  }
243 
244  virtual
245  void
246  set_num_nodes( Size size_in ) {
247  size_ = size_in;
248  int nscoretypes = score_types_.size();
249  tables_.clear();
250  tables_.resize( size_in, utility::vector1< core::Real >(nscoretypes,0) );
251  computed_.clear();
252  computed_.resize( size_, false );
253  }
254 
255  Size
256  size() const {
257  return size_;
258  }
259 
260  virtual
262  const_neighbor_iterator_begin( int resid ) const {
263  int beginat = std::min( resid-1, (int)size_+1 );
264  if (resid==1) beginat = 2;
265  if (resid>(int)size_) beginat = 1; // sometimes arises in symmetry
266  return new PeptideBondedNeighborConstIterator( resid, beginat, score_types_, &tables_, &computed_ );
267  }
268 
269  virtual
271  const_neighbor_iterator_end( int resid ) const {
272  int endat = std::min( resid+2, (int)size_+1 );
273  if (resid>(int)size_) endat = 1; // sometimes arises in symmetry
274  return new PeptideBondedNeighborConstIterator( resid, endat, score_types_, &tables_, &computed_ );
275  }
276 
277  virtual
280  int beginat = std::min( resid+1, (int)size_+1 );
281  if (resid>(int)size_) beginat = 1; // sometimes arises in symmetry
282  return new PeptideBondedNeighborConstIterator( resid, beginat, score_types_, &tables_, &computed_ );
283  }
284 
285  virtual
288  return const_neighbor_iterator_end( resid );
289  }
290 
291  //////////////////// non-const versions
292  virtual
294  neighbor_iterator_begin( int resid ) {
295  int beginat = std::min( resid-1, (int)size_+1 );
296  if (resid==1) beginat = 2;
297  if (resid>(int)size_) beginat = 1; // sometimes arises in symmetry
298  return new PeptideBondedNeighborIterator( resid, beginat, score_types_, &tables_, &computed_ );
299  }
300 
301  virtual
303  neighbor_iterator_end( int resid ) {
304  int endat = std::min( resid+2, (int)size_+1 );
305  if (resid>(int)size_) endat = 1; // sometimes arises in symmetry
306  return new PeptideBondedNeighborIterator( resid, endat, score_types_, &tables_, &computed_ );
307  }
308 
309  virtual
312  {
313  int beginat = std::min( resid+1, (int)size_+1 );
314  if (resid>(int)size_) beginat = 1; // sometimes arises in symmetry
315  return new PeptideBondedNeighborIterator( resid, beginat, score_types_, &tables_, &computed_ );
316  }
317 
318  virtual
321  return neighbor_iterator_end( resid );
322  }
323 
324 private:
329 
330 };
331 
332 } // namespace scoring
333 } // namespace core
334 
335 #endif