Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DOF_ID_Map.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/id/DOF_ID_Map.hh
11 /// @brief Map from Atom DOF identifiers to contained values class
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 ///
14 /// @note
15 /// @li Implemented as a vector< AtomID_Map > for fast lookup but this has slower
16 /// insertion/deletion than a std::map or other associative containers
17 /// @li The outer vector is indexed by the DOF_Type
18 /// @li The inner map is indexed by the AtomID (pair of residue number and atom number)
19 /// @li The DOF layer is on the outside for simple global setting for a DOF and to
20 /// reuse the AtomID_Map code
21 /// @li The map can be sized by first calling resize( n_res ) and then calling
22 /// resize( i_res, n_atom ) for each residue to set the number of atoms
23 /// @li DOF-specific and uniform default values can be set with the overloaded
24 /// default_value() functions
25 /// @li Invariant: The DOF_Map is always of size n_DOF_Type
26 /// @li When the Value type (T) is bool note that the vector< bool > specialization is
27 /// used so the values returned by the indexing lookups are not actually references
28 
29 
30 #ifndef INCLUDED_core_id_DOF_ID_Map_hh
31 #define INCLUDED_core_id_DOF_ID_Map_hh
32 
33 
34 // Unit headers
36 
37 // Package headers
38 #include <core/id/types.hh>
39 // AUTO-REMOVED #include <core/id/AtomID_Map.hh>
40 #include <core/id/DOF_ID.hh>
41 
42 // Utility headers
43 // AUTO-REMOVED #include <utility/vector1.hh>
44 
46 #include <utility/vector1.fwd.hh>
47 
48 
49 
50 namespace core {
51 namespace id {
52 
53 
54 /// @brief Map from Atom DOF identifiers to contained values class
55 template< typename T >
56 class DOF_ID_Map
57 {
58 
59 
60 public: // Types
61 
62 
65 
66  // STL/boost style
67  typedef T value_type;
68  typedef typename AtomMap::reference reference;
70  typedef typename AtomMap::size_type size_type;
71 
72  // Project style
73  typedef T Value;
74  typedef typename AtomMap::Reference Reference;
77 
78 
79 public: // Creation
80 
81 
82  /// @brief Default constructor
83  inline
84  explicit
85  DOF_ID_Map( Value const & default_value_a = Value() ) :
86  dof_map_( n_DOF_Type, AtomMap( default_value_a ) )
87  {}
88 
89 
90  /// @brief Number of residues constructor
91  inline
92  explicit
94  Size const n_res,
95  Value const & default_value_a = Value()
96  ) :
97  dof_map_( n_DOF_Type, AtomMap( n_res, default_value_a ) )
98  {}
99 
100 
101  /// @brief Destructor
102  inline
104  {}
105 
106 
107 public: // Methods
108 
109 
110  /// @brief Resize to a given number of residues
111  inline
112  void
113  resize( Size const n_res )
114  {
115  for ( Size i = 1; i <= n_DOF_Type; ++i ) {
116  dof_map_[ i ].resize( n_res );
117  }
118  }
119 
120 
121  /// @brief Resize the number of atoms of a residue and use the default fill value
122  inline
123  void
124  resize( Size const i_res, Size const n_atom )
125  {
126  for ( Size i = 1; i <= n_DOF_Type; ++i ) {
127  dof_map_[ i ].resize( i_res, n_atom );
128  }
129  }
130 
131 
132  /// @brief Resize the number of atoms of a residue and use a specified fill value
133  inline
134  void
135  resize( Size const i_res, Size const n_atom, Value const & value )
136  {
137  assert( dof_map_.size() == n_DOF_Type );
138  for ( Size i = 1; i <= n_DOF_Type; ++i ) {
139  dof_map_[ i ].resize( i_res, n_atom, value );
140  }
141  }
142 
143 
144  /// @brief Finalize after sizing all the vectors
145  inline
146  void
148  {
149  shrink();
150  }
151 
152 
153  /// @brief Shrink the vectors to remove unused capacity
154  inline
155  void
157  {
158  for ( Size i = 1; i <= n_DOF_Type; ++i ) {
159  dof_map_[ i ].shrink();
160  }
161  }
162 
163 
164  /// @brief swap( DOF_ID_Map )
165  inline
166  void
168  {
169  dof_map_.swap( s.dof_map_ );
170  }
171 
172 
173  /// @brief swap( DOF_ID_Map, DOF_ID_Map )
174  friend
175  inline
176  void
178  {
179  a.dof_map_.swap( b.dof_map_ );
180  }
181 
182 
183  /// @brief Clear the vectors
184  inline
185  void
187  {
188  for ( Size i = 1; i <= n_DOF_Type; ++i ) {
189  dof_map_[ i ].clear();
190  }
191  }
192 
193 
194  /// @brief Set a DOF for all atoms to the default value for that DOF
195  inline
196  void
197  set( DOF_Type const dof )
198  {
199  dof_map_[ dof ].fill();
200  }
201 
202 
203  /// @brief Set a DOF for all atoms to a specified value
204  inline
205  void
206  set( DOF_Type const dof, Value const & value )
207  {
208  dof_map_[ dof ].fill_with( value );
209  }
210 
211 
212 public: // Properties
213 
214 
215  /// @brief Size (Number of DOF types)
216  inline
217  Size
218  size() const
219  {
220  return dof_map_.size();
221  }
222 
223 
224  /// @brief Number of residues
225  inline
226  Size
227  n_residue() const
228  {
229  return dof_map_[ 1 ].n_residue();
230  }
231 
232 
233  /// @brief Number of atoms in a residue
234  inline
235  Size
236  n_atom( Size const i_res ) const
237  {
238  return dof_map_[ 1 ].n_atom( i_res );
239  }
240 
241 
242  /// @brief Empty?
243  inline
244  bool
245  empty() const
246  {
247  return dof_map_.empty();
248  }
249 
250 
251  /// @brief Default value for a DOF
252  inline
253  Value const &
254  default_value( DOF_Type const dof ) const
255  {
256  return dof_map_[ dof ].default_value();
257  }
258 
259 
260  /// @brief Set default value for a DOF
261  inline
262  void
263  default_value( DOF_Type const dof, Value const & default_value_a )
264  {
265  dof_map_[ dof ].default_value( default_value_a );
266  }
267 
268 
269  /// @brief Set a uniform default value
270  inline
271  void
272  default_value( Value const & default_value_a )
273  {
274  for ( Size i = 1; i <= n_DOF_Type; ++i ) {
275  dof_map_[ i ].default_value( default_value_a );
276  }
277  }
278 
279 
280 public: // Indexers
281 
282 
283  /// @brief DOF_ID_Map[ dof_id ] const
284  inline
286  operator []( DOF_ID const & id ) const
287  {
288  return dof_map_[ id.type() ][ id.atom_id() ];
289  }
290 
291 
292  /// @brief DOF_ID_Map[ dof_id ]
293  inline
294  Reference
295  operator []( DOF_ID const & id )
296  {
297  return dof_map_[ id.type() ][ id.atom_id() ];
298  }
299 
300 
301  /// @brief DOF_ID_Map( dof_id ) const
302  inline
304  operator ()( DOF_ID const & id ) const
305  {
306  return dof_map_[ id.type() ][ id.atom_id() ];
307  }
308 
309 
310  /// @brief DOF_ID_Map( dof_id )
311  inline
312  Reference
313  operator ()( DOF_ID const & id )
314  {
315  return dof_map_[ id.type() ][ id.atom_id() ];
316  }
317 
318 
319  /// @brief DOF_ID_Map( i_res, i_atom ) const
320  inline
322  operator ()( Size const i_res, Size const i_atom, DOF_Type const dof ) const
323  {
324  return dof_map_[ dof ][ i_res ][ i_atom ];
325  }
326 
327 
328  /// @brief DOF_ID_Map( i_res, i_atom )
329  inline
330  Reference
331  operator ()( Size const i_res, Size const i_atom, DOF_Type const dof )
332  {
333  return dof_map_[ dof ][ i_res ][ i_atom ];
334  }
335 
336 
337  /// @brief DOF_ID_Map[ dof ] const
338  inline
339  AtomMap const &
340  operator []( DOF_Type const dof ) const
341  {
342  return dof_map_[ dof ];
343  }
344 
345 
346  /// @brief DOF_ID_Map[ dof ]
347  inline
348  AtomMap &
349  operator []( DOF_Type const dof )
350  {
351  return dof_map_[ dof ];
352  }
353 
354 
355  /// @brief DOF_ID_Map( dof ) const
356  inline
357  AtomMap const &
358  operator ()( DOF_Type const dof ) const
359  {
360  return dof_map_[ dof ];
361  }
362 
363 
364  /// @brief DOF_ID_Map( dof )
365  inline
366  AtomMap &
367  operator ()( DOF_Type const dof )
368  {
369  return dof_map_[ dof ];
370  }
371 
372 
373 public: // Comparison
374 
375 
376  /// @brief DOF_ID_Map == DOF_ID_Map
377  friend
378  inline
379  bool
380  operator ==( DOF_ID_Map const & a, DOF_ID_Map const & b )
381  {
382  return ( a.dof_map_ == b.dof_map_ );
383  }
384 
385 
386  /// @brief DOF_ID_Map != DOF_ID_Map
387  friend
388  inline
389  bool
390  operator !=( DOF_ID_Map const & a, DOF_ID_Map const & b )
391  {
392  return ( a.dof_map_ != b.dof_map_ );
393  }
394 
395 
396 private: // Fields
397 
398 
399  /// @brief Map from Atom DOF identifiers to values
401 
402 
403 }; // DOF_ID_Map
404 
405 
406 } // namespace id
407 } // namespace core
408 
409 
410 #endif // INCLUDED_core_id_DOF_ID_Map_HH