Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MoveMap.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/kinematics/MoveMap.hh
11 /// @brief Move map
12 /// @author Phil Bradley
13 /// @author Christopher Miles (cmiles@uw.edu)
14 #ifndef INCLUDED_core_kinematics_MoveMap_hh
15 #define INCLUDED_core_kinematics_MoveMap_hh
16 
17 // Unit headers
19 
20 // Package headers
21 #include <core/kinematics/types.hh>
22 #include <core/id/AtomID.hh>
23 #include <core/id/DOF_ID.hh>
24 #include <core/id/JumpID.hh>
25 #include <core/id/TorsionID.hh>
26 
27 // Utility headers
28 #include <utility/PyAssert.hh>
29 #include <utility/pointer/owning_ptr.hh>
30 #include <utility/pointer/ReferenceCount.hh>
31 #include <utility/vector1.hh>
32 
33 // C++ headers
34 #include <map>
35 // AUTO-REMOVED #include <utility>
36 #include <vector>
37 
40 
41 namespace core {
42 namespace kinematics {
43 
44 ///@brief A class specifying DOFs to be flexible or fixed
45 ///
46 /// currently there are two groups of data, one is residue-based Torsion
47 /// definition, such as BB, CHI and JUMP; the other is atom-based DOF
48 /// definition, such as bond length D, bond angle THETA and torsion angle PHI
49 /// which are used in atom-tree. MoveMap does not automatically handle
50 /// conversion from one group to the other, i.e., setting PHI false for
51 /// DOF_type does not affect setting for BB and CHI torsion though they are
52 /// PHIs in atom-tree.
53 ///
54 /// within each group, there are multiple levels of control
55 /// (from general/high to specific/lower):
56 /// @li Torsion-based: TorsionType(BB, CHI, JUMP) -> MoveMapTorsionID
57 /// (BB, CHI of one residue) -> TorsionID ( BB torsion 2 or CHI torsion 3 of
58 /// one residue)
59 /// @li DOF-base: DOF_type( D, THETA, PHI ) -> DOF_ID (D, THETA, PHI of one atom)
60 ///
61 /// setting for each level are stored in a map structure and they are only
62 /// added to the map when setting methods are invoked. As a result, MoveMap
63 /// does not behave like a "Boolean vector" which always contains setting for
64 /// each residue or atom in a conformation. Setting for a higher level will
65 /// override setting for lower levels (remove it from map); Similarly, when
66 /// querying a lower level finds no setting, it will check setting for its
67 /// higher level. For example, setting TorisionType BB to be true will remove
68 /// any data of BB setting for a residue or a specific BB torsion ( such as
69 /// backbone psi ) in a residue. And querying setting for BB torsion 2 of
70 /// residue 4 will first check if there is any specific setting, if not,
71 /// check if there is a setting for all BB torsions for residue 4, if not
72 /// again, use setting for BB torsions for all residues.
73 ///
74 /// example:
75 /// movemap = MoveMap()
76 /// See also:
77 /// Pose
78 /// MinMover
79 /// ShearMover
80 /// SmallMover
82  public:
83  ///@brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
84  virtual ~MoveMap();
85  // ids
86  typedef id::AtomID AtomID;
89  typedef id::DOF_ID DOF_ID;
93 
94  /// @brief Our own specific torsion_id
95  /// TorsionType can BB, CHI and JUMP. Thefore it doesnt distinguish torsion,eg phi/psi/omega
96  /// in BB torsion. Useful when setting residue k backbone fixed.
97  /// should probably make this a class/struct
98  typedef std::pair< Size, TorsionType > MoveMapTorsionID;
99 
100  /// @brief flexible or fixed for this TorsionType (BB, CHI, JUMP), for all residues
101  typedef std::map< TorsionType, bool > TorsionTypeMap;
102 
103  /// @brief flexible or fixed for this TorsionType (BB, CHI, JUMP), for one residue, eg no distinction betwen phi/psi/omega
104  typedef std::map< MoveMapTorsionID, bool > MoveMapTorsionID_Map;
105 
106  /// @brief flexible or fixed for a single torsion, eg, psi (BB torsion 2) of residue 10
107  typedef std::map< TorsionID, bool > TorsionID_Map;
108 
109  /// @brief flexible or fixed for this DOF_Type (PHI, THETA, D, RB1-6), for all atoms
110  typedef std::map< DOF_Type, bool > DOF_TypeMap;
111 
112  /// @brief flexible or fixed for a single DOF, eg, D of atom 5 in residue 10
113  typedef std::map< DOF_ID, bool > DOF_ID_Map;
114 
115  /// @brief flexible or fixed jumps (fold-tree independent definition via residue pairs )
116  typedef std::map< id::JumpID, bool > JumpID_Map;
117 
118  ///@brief default constructor
120 
121  MoveMapOP clone() const {
122  return new MoveMap( *this );
123  }
124 
125  /// @brief clear -- sets all to FALSE
126  void
127  clear();
128 
129  /// @brief Set whether or not BB TorsionType is moveable
130  ///
131  /// example:
132  /// movemap.set_bb(True)
133  /// See also:
134  /// MoveMap
135  /// MoveMap.set_chi
136  /// Pose
137  /// MinMover
138  /// ShearMover
139  /// SmallMover
140  inline
141  void
142  set_bb( bool const setting )
143  {
144  set( id::BB, setting );
145  }
146 
147  /// @brief Sets whether or not the BB torsions of residue <seqpos> are movable
148  ///
149  /// example:
150  /// movemap.set_bb(49,True)
151  /// See also:
152  /// MoveMap
153  /// MoveMap.set_chi
154  /// Pose
155  /// MinMover
156  /// ShearMover
157  /// SmallMover
158  inline
159  void
160  set_bb( Size const seqpos, bool const setting )
161  {
162  PyAssert( (seqpos>0), "MoveMap::set_bb( Size const seqpos , bool const setting ): input variable seqpos has a meaningless value");
163  set( MoveMapTorsionID( seqpos, BB ), setting );
164  }
165 
166  /// @brief Sets BB torsions movable based on input array
167  inline
168  void
170  {
171  for( Size ii = 1; ii <= allow_bb.size(); ii++ )
172  set( MoveMapTorsionID( ii, BB ), allow_bb[ii] );
173  }
174 
175  /// @brief Sets the BB torsions between residues <begin> and <end>
176  /// as movable, all other residues are non-movable
177  ///
178  /// example:
179  /// movemap.set_bb_true_range(40,60)
180  /// See also:
181  /// MoveMap
182  /// MoveMap.set_bb
183  /// MoveMap.set_chi
184  /// Pose
185  /// MinMover
186  /// ShearMover
187  /// SmallMover
188  inline
189  void
190  set_bb_true_range( Size const begin, Size const end )
191  {
192  PyAssert( (begin>0), "MoveMap::set_bb_true_range( Size const begin , Size const end): input variable begin has a meaningless value");
193  PyAssert( (end>0), "MoveMap::set_bb_true_range( Size const begin , Size const end ): input variable end has a meaningless value");
194  PyAssert( (begin <= end), "MoveMap::set_bb_true_range( Size const begin, Size const end): input variable begin < input variable end");
195  set_bb(false);
196  for( Size ir=begin;ir<=end;ir++) set_bb(ir, true);
197  }
198 
199  /// @brief Prevents backbone torsion modifications to the intervals specified
200  /// by <ranges>. Each element of the vector is a pair, which specifies the
201  /// begin and end indices. Counting begins with 1.
202  void set_ranges_unmodifiable(const std::vector<std::pair<Size, Size> >& ranges);
203 
204  /// @brief Sets whether of not CHI TorsionType is movable
205  ///
206  /// example:
207  /// movemap.set_chi(True)
208  /// See also:
209  /// MoveMap
210  /// MoveMap.set_bb
211  /// Pose
212  /// MinMover
213  /// ShearMover
214  /// SmallMover
215  inline
216  void
217  set_chi( bool const setting )
218  {
219  set( id::CHI, setting );
220  }
221 
222  /// @brief Sets whether or not the CHI torsions of residue <seqpos> are movable
223  ///
224  /// example:
225  /// movemap.set_chi(49,True)
226  /// See also:
227  /// MoveMap
228  /// MoveMap.set_bb
229  /// Pose
230  /// MinMover
231  /// ShearMover
232  /// SmallMover inline
233  void
234  set_chi( Size const seqpos, bool const setting )
235  {
236  PyAssert( (seqpos>0), "MoveMap::set_chi( Size const seqpos , bool const setting ): input variable seqpos has a meaningless value");
237  set( MoveMapTorsionID( seqpos, id::CHI ), setting );
238  }
239 
240  /// @brief set CHI torsions movable based on input array
241  inline
242  void
244  {
245  for( Size ii = 1; ii <= allow_chi.size(); ii++ )
246  set( MoveMapTorsionID( ii, id::CHI ), allow_chi[ii] );
247  }
248 
249  /// @brief Sets the chi torsions between residues <begin> and <end>
250  /// as movable and all other residues are non-movable.
251  ///
252  /// Example:
253  /// movemap.set_chi_true_range(40, 60)
254  /// See also:
255  /// MoveMap
256  /// MoveMap.set_bb
257  /// MoveMap.set_bb_true_range
258  /// MoveMap.set_chi
259  /// Pose
260  /// MinMover
261  /// ShearMover
262  /// SmallMover
263  // added by Labonte
264  inline
265  void set_chi_true_range(Size const begin, Size const end)
266  {
267  PyAssert((begin > 0), "MoveMap::set_chi_true_range(Size const begin, Size const end): input variable begin has a meaningless value");
268  PyAssert((end > 0), "MoveMap::set_chi_true_range(Size const begin, Size const end): input variable end has a meaningless value");
269  PyAssert((begin <= end), "MoveMap::set_chi_true_range(Size const begin, Size const end): input variable begin must be <= input variable end");
270  set_chi(false);
271  for(Size res = begin; res <= end; ++res) {
272  set_chi(res, true);
273  }
274  }
275 
276  /// @brief Sets whether or not JUMP TorsionType is moveable
277  ///
278  /// example:
279  /// movemap.set_jump(True)
280  inline
281  void
282  set_jump( bool const setting )
283  {
284  set( id::JUMP, setting );
285  }
286 
287  /// @brief Sets the movability of JUMP <jump_number> to <setting>
288  ///
289  /// example:
290  /// movemap.set_jump(1,True)
291  inline
292  void
293  set_jump( int const jump_number, bool const setting )
294  {
295  PyAssert( (jump_number>0), "MoveMap::set_jump( int const jump_number , bool const setting ): input variable jump_number has a meaningless value");
296  set( MoveMapTorsionID( jump_number, id::JUMP ), setting );
297  }
298 
299  ///@brief set JUMP moveable or not for one specific residue pair
300  /// this mechanism does not mix with the "jump_nr" mechanism...
301  /// i.e., if you set jump_nr 3 = movable ---> movemap does not know that this refers to say residue 23-89
302  // but it does mix with the global switch set_jump( true/false ).
303  inline
304  void
305  set_jump( Size const pos1, Size const pos2, bool const setting )
306  {
307  set_jump( id::JumpID( pos1, pos2 ), setting );
308  }
309 
310  void
311  set_jump( id::JumpID const & jump, bool const setting );
312 
313  /// @brief set a specific TorsionType moveable; currently BB, CHI, or JUMP
314  void
315  set( TorsionType const & t, bool const setting );
316 
317  /// @brief set TorsionType flexible or fixed for one residue, eg BB torsions for residue 10
318  void
319  set( MoveMapTorsionID const & id, bool const setting );
320 
321  /// @brief set an individual Torsion moveable or now, eg, "BB torsion 2 of residue 4"
322  void
323  set( TorsionID const & id, bool const setting );
324 
325  /// @brief set atom tree DOF, eg D, PHI, THETA
326  void
327  set( DOF_Type const & t, bool const setting );
328 
329  /// @brief set for an individual dof, eg "PHI of Atom 3 in Residue 5"
330  void
331  set( DOF_ID const & id, bool const setting );
332 
333 public: // accessors
334  /// @brief Returns if BB torsions are movable or not for residue <seqpos>
335  ///
336  /// example:
337  /// movemap.get_bb(49)
338  inline
339  bool
340  get_bb( Size const seqpos ) const
341  {
342  PyAssert( (seqpos>0), "MoveMap::get_bb( Size const seqpos ): input variable seqpos has a meaningless value");
343  return get( MoveMapTorsionID( seqpos, BB ) );
344  }
345 
346  /// @brief Returns if SC torsions are movable or not for residue <seqpos>
347  ///
348  /// example:
349  /// movemap.get_chi(49)
350  inline
351  bool
352  get_chi( int const seqpos ) const
353  {
354  PyAssert( (seqpos>0), "MoveMap::get_chi( int const seqpos ): input variable seqpos has a meaningless value");
355  return get( MoveMapTorsionID( seqpos, CHI ) );
356  }
357 
358  /// @brief Returns if JUMP <jump_number> is movable or not
359  ///
360  /// example:
361  /// movemap.get_jump(1)
362  bool
363  get_jump( int const jump_number ) const
364  {
365  PyAssert( (jump_number>0), "MoveMap::get_jump( int const jump_number ): input variable jump_number has a meaningless value");
366  return get( MoveMapTorsionID( jump_number, id::JUMP ) );
367  }
368 
369  inline
370  bool
371  get_jump( Size const pos1, Size const pos2 ) const
372  {
373  return get_jump( id::JumpID( pos1, pos2 ) );
374  }
375 
376  bool
377  get_jump( id::JumpID const & jump ) const;
378 
379  /// @brief get setting for a specific TorsionType, such as "BB"
380  bool
381  get( TorsionType const & t ) const;
382 
383  /// @brief get TorsionType flexible or fixed for one residue, eg BB torsions for residue 10
384  bool
385  get( MoveMapTorsionID const & id ) const;
386 
387  bool
388  get( TorsionID const & id ) const;
389 
390  /// @brief get the default for this type of DOF, eg "PHI"
391  bool
392  get( DOF_Type const & t ) const;
393 
394  /// @brief get the setting for an individual dof, eg, PHI of Atom 3 in Residue 5
395  bool
396  get( DOF_ID const & id ) const;
397 
398  /// @brief find the explicit setting for the given TorsionType
399  /// @return iterator pointing to the TorsionType-bool pair, otherwise
400  /// torsion_type_end()
401  /// @warning Do not use this for general lookup, as it does not take
402  /// into account the stringency levels. Only use this when you need
403  /// to check if a setting explicitly exists.
404  TorsionTypeMap::const_iterator
405  find( TorsionType const & t ) const;
406 
407  /// @brief find the explicit setting for the given MoveMapTorsionID
408  /// @return iterator pointing to the MoveMapTorsionID-bool pair, otherwise
409  /// movemap_torsion_id_end()
410  /// @warning Do not use this for general lookup, as it does not take
411  /// into account the stringency levels. Only use this when you need
412  /// to check if a setting explicitly exists.
413  MoveMapTorsionID_Map::const_iterator
414  find( MoveMapTorsionID const & id ) const;
415 
416  /// @brief find the explicit setting for the given TorsionID
417  /// @return iterator pointing to the TorsionID-bool pair, otherwise torsion_id_end()
418  /// @warning Do not use this for general lookup, as it does not take
419  /// into account the stringency levels. Only use this when you need
420  /// to check if a setting explicitly exists.
421  TorsionID_Map::const_iterator
422  find( TorsionID const & id ) const;
423 
424  /// @brief find the explicit setting for the given JumpID
425  /// @return iterator pointing to the JumpID-bool pair, otherwise jump_id_end()
426  /// @warning Do not use this for general lookup, as it does not take
427  /// into account the stringency levels. Only use this when you need
428  /// to check if a setting explicitly exists.
429  JumpID_Map::const_iterator
430  find( id::JumpID const & jump ) const;
431 
432  /// @brief find the explicit setting for the given DOF_Type
433  /// @return iterator pointing to the DOF_Type-bool pair, otherwise dof_type_end()
434  /// @warning Do not use this for general lookup, as it does not take
435  /// into account the stringency levels. Only use this when you need
436  /// to check if a setting explicitly exists.
437  DOF_TypeMap::const_iterator
438  find( DOF_Type const & t ) const;
439 
440  /// @brief find the explicit setting for the given DOF_ID
441  /// @return iterator pointing to the DOF_ID-bool pair, otherwise dof_id_end()
442  /// @warning Do not use this for general lookup, as it does not take
443  /// into account the stringency levels. Only use this when you need
444  /// to check if a setting explicitly exists.
445  DOF_ID_Map::const_iterator
446  find( DOF_ID const & id ) const;
447 
448  public: // iterators
449  /// @brief return an iterator pointing just past the last element of the TorsionTypeMap
450  inline
451  TorsionTypeMap::const_iterator
452  torsion_type_begin() const { return torsion_type_map_.begin(); }
453 
454  /// @brief return an iterator pointing at the first element of the TorsionTypeMap
455  inline
456  TorsionTypeMap::const_iterator
457  torsion_type_end() const { return torsion_type_map_.end(); }
458 
459  /// @brief return an iterator pointing at the first element of the MoveMapTorsionID_Map
460  inline
461  MoveMapTorsionID_Map::const_iterator
463 
464  /// @brief return an iterator pointing just past the last element of the MoveMapTorsionID_Map
465  inline
466  MoveMapTorsionID_Map::const_iterator
468 
469  /// @brief return an iterator pointing at the first element of the TorsionID_Map
470  inline
471  TorsionID_Map::const_iterator
472  torsion_id_begin() const { return torsion_id_map_.begin(); }
473 
474  /// @brief return an iterator pointing just past the last element of the TorsionID_Map
475  inline
476  TorsionID_Map::const_iterator
477  torsion_id_end() const { return torsion_id_map_.end(); }
478 
479  /// @brief return an iterator pointing just past the last element of the DOF_TypeMap
480  inline
481  DOF_TypeMap::const_iterator
482  dof_type_begin() const { return dof_type_map_.begin(); }
483 
484  /// @brief return an iterator pointing at the first element of the DOF_TypeMap
485  inline
486  DOF_TypeMap::const_iterator
487  dof_type_end() const { return dof_type_map_.end(); }
488 
489  /// @brief return an iterator pointing at the first element of the DOF_ID_Map
490  inline
491  DOF_ID_Map::const_iterator
492  dof_id_begin() const { return dof_id_map_.begin(); }
493 
494  /// @brief return an iterator pointing just past the last element of the DOF_ID_Map
495  inline
496  DOF_ID_Map::const_iterator
497  dof_id_end() const { return dof_id_map_.end(); }
498 
499  /// @brief return an iterator pointing at the first element of the JumpID_Map
500  inline
501  JumpID_Map::const_iterator
502  jump_id_begin() const { return jump_id_map_.begin(); }
503 
504  /// @brief return an iterator pointing just past the last element of the JumpID_Map
505  inline
506  JumpID_Map::const_iterator
507  jump_id_end() const { return jump_id_map_.end(); }
508 
509 public: // movemap-movemap functionality
510 
511  /// @brief import settings from another MoveMap
512  /// @return The total number of settings imported.
513  /// @remarks This function calls set() for each setting that exists in the
514  /// 'rval' MoveMap in order from lowest to highest stringency.
515  inline
516  Size import( MoveMap const & rval ) {
517  return import( rval, true, true ); // bool: import_true_settings, import_false_settings
518  }
519 
520  /// @brief import only False settings from another MoveMap
521  /// @return The total number of settings imported.
522  /// @remarks This function calls set() for each setting that is marked as
523  /// False in the 'rval' MoveMap in order from lowest to highest
524  /// stringency.
525  inline
526  Size import_false( MoveMap const & rval ) {
527  return import( rval, false, true ); // bool: import_true_settings, import_false_settings
528  }
529 
530  /// @brief import only True settings from another MoveMap
531  /// @return The total number of settings imported.
532  /// @remarks This function calls set() for each setting that is marked as
533  /// True in the 'rval' MoveMap in order from lowest to highest
534  /// stringency.
535  inline
536  Size import_true( MoveMap const & rval ) {
537  return import( rval, true, false ); // bool: import_true_settings, import_false_settings
538  }
539 
540 public: // i/o
541  /// @brief Read MoveMap from file.
542  void init_from_file( std::string const & filename );
543 
544 public: // status
545  /// @brief gives the BB and CHI bool values up to a given residue number
546  void
547  show( std::ostream & out, Size i) const;
548 
549  /// @brief gives the BB and CHI bool values up to a given residue number
550  /// wrapper for PyRosetta
551  void
552  show( Size i) const { show(std::cout, i);};
553 
554  void
555  show( std::ostream & out) const;
556  void
557  show() const { show(std::cout);};
558 
559 private: // movemap-movemap functionality
560 
561  /// @brief import settings from another MoveMap
562  /// @param[in] rval The MoveMap to import settings from.
563  /// @param[in] import_true_settings Import True settings?
564  /// @param[in] import_false_settings Import False settings?
565  /// @return The total number of settings imported.
566  /// @remarks This function calls set() for each setting that exists in the
567  /// 'rval' MoveMap in order from lowest to highest stringency.
568  Size import(
569  MoveMap const & rval,
570  bool const import_true_settings,
571  bool const import_false_settings
572  );
573 
574  private:
575  // implementation of the data
576  // WARNING: if you add something here also add it to ::clear() and ::import()
577 
578  /// @brief flexible or fixed for this TorsionType (BB, CHI, JUMP), for all residues
580 
581  /// @brief flexible or fixed for this TorsionType (BB, CHI, JUMP), for one residue, eg no distinction betwen phi/psi/omega
583 
584  /// @brief flexible or fixed for a single torsion, eg, psi (BB torsion 2) of residue 10
586 
587  /// @brief flexible or fixed for this DOF_Type (PHI, THETA, D, RB1-6), for all atoms
589 
590  /// @brief flexible or fixed for a single DOF, eg, D of atom 5 in residue 10
592 
594 }; // MoveMap
595 
596 inline
597 std::ostream &
598 operator <<( std::ostream & out, MoveMap const & mm )
599 {
600  mm.show( out );
601  return out;
602 }
603 
604 } // namespace kinematics
605 } // namespace core
606 
607 #endif // INCLUDED_core_kinematics_DOF_ID_HH