Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PDBPoseMap.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/pose/PDBPoseMap.hh
11 /// @brief class to allow querying for pose resid with pdb chain/seqpos
12 /// @author Steven Lewis
13 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
14 
15 
16 #ifndef INCLUDED_core_pose_PDBPoseMap_hh
17 #define INCLUDED_core_pose_PDBPoseMap_hh
18 
19 
20 // Unit headers
22 
23 // Package headers
24 #include <core/pose/PDBInfo.fwd.hh>
25 
26 // Project headers
27 // AUTO-REMOVED #include <core/pose/Pose.fwd.hh>
28 
29 // Utility headers
30 #include <core/types.hh>
31 // AUTO-REMOVED #include <utility/vector1.fwd.hh>
32 #include <utility/pointer/ReferenceCount.hh>
33 
34 // C++ Headers
35 #include <map>
36 
37 namespace core {
38 namespace pose {
39 
40 /// @brief PDBPoseMap can be queried with PDB information (chain, sequence position)
41 /// and returns a pose's resid position. Useful for handing input/output in terms
42 /// of PDB positions. Can be tucked into the pose for repeated access, or generated
43 /// just-in-time for a single use. Basically a wrapper class for std::map.
45 
46 
47 public: // typedefs
48 
49  typedef core::Size Size;
50 
51 
52 private: // forward declarations
53 
54  struct ResidueKey;
55 
56 
57 private: // typedefs
58 
60  typedef std::map< ResidueKey, Size > Pdb2Pose;
61 
62 
63 private: // structs
64 
65  /// @brief sortable residue key internal to PDBPoseMap
66  struct ResidueKey {
67  /// @brief default constructor
69  chainID( ' ' ),
70  resSeq( 0 ),
71  iCode( ' ')
72  {}
73 
74  /// @brief value constructor
75  ResidueKey( char const c, int const r, char const i ) :
76  chainID( c ),
77  resSeq( r ),
78  iCode( i )
79  {}
80 
81  /// @brief comparator, lexicographic ordering
82  bool
83  operator <( ResidueKey const & rval ) const
84  {
85  return (
86  ( chainID < rval.chainID ? true :
87  ( rval.chainID < chainID ? false :
88  ( resSeq < rval.resSeq ? true :
89  ( rval.resSeq < resSeq ? false :
90  ( iCode < rval.iCode ) ) ) ) ) );
91  }
92 
93  /// @brief chain id
94  char chainID;
95  /// @brief residue sequence number
96  int resSeq;
97  /// @brief insertion code
98  char iCode;
99 
100 #ifdef USEBOOSTSERIALIZE
101  private:
102  friend class boost::serialization::access;
103 
104  template<class Archive>
105  void serialize(Archive & ar, const unsigned int version) {
106  ar & chainID;
107  ar & resSeq;
108  ar & iCode;
109  }
110 #endif
111  };
112 
113 
114 public: // constructors
115 
116  /// @brief default constructor
117  PDBPoseMap();
118 
119  /// @brief PDBInfo constructor
120  PDBPoseMap( PDBInfo const & info );
121 
122  /// @brief copy constructor
123  PDBPoseMap( PDBPoseMap const & map );
124 
125 
126 public: // destructor
127 
128  /// @brief default destructor
129  virtual ~PDBPoseMap();
130 
131 
132 public: // assignment
133 
134  /// @brief copy assignment
135  PDBPoseMap &
136  operator =( PDBPoseMap const & m );
137 
138 
139 public: // methods
140 
141  /// @brief number of mappings
142  inline
143  Size size() const
144  {
145  return pdb2pose_.size();
146  }
147 
148  /// @brief lookup pose numbering
149  /// @param[in] chain chain id
150  /// @param[in] pdb_res pdb residue numbering
151  /// @param[in] ins_code insertion code
152  /// @return pose numbering for residue, returns 0 if not found
153  inline
154  Size
156  char const chain,
157  int const pdb_res,
158  char const ins_code = ' '
159  ) const
160  {
161  Pdb2Pose::const_iterator i = pdb2pose_.find( ResidueKey( chain, pdb_res, ins_code ) );
162 
163  if ( i == pdb2pose_.end() ) { // not found
164  return 0;
165  }
166 
167  return i->second; // return pose numbering
168  }
169 
170  /// @brief insert pdb -> pose number mapping
171  /// @param[in] chain chain id
172  /// @param[in] pdb_res pdb residue numbering
173  /// @param[in] ins_code insertion code, use ' ' if no insertion code
174  /// @param[in] pose_res pose numbering for residue
175  /// @remarks if the chain is equal to the PDBInfo's empty record character,
176  /// the insertion will be skipped
177  void
178  insert(
179  char const chain,
180  int const pdb_res,
181  char const ins_code,
182  Size const pose_res
183  );
184 
185  /// @brief remove mapping for pdb residue key only if Pose residue matches
186  /// @param[in] chain chain id
187  /// @param[in] pdb_res pdb residue numbering
188  /// @param[in] ins_code insertion code, use ' ' if no insertion code
189  /// @param[in] pose_res the mapped Pose residue
190  /// @return true if key-value pair erase, false otherwise
191  inline
192  bool
194  char const chain,
195  int const pdb_res,
196  char const ins_code,
197  Size const pose_res
198  )
199  {
200  Pdb2Pose::iterator i = pdb2pose_.find( ResidueKey( chain, pdb_res, ins_code ) );
201  if ( i != pdb2pose_.end() && i->second == pose_res ) {
202  pdb2pose_.erase( i );
203  return true;
204  }
205 
206  return false;
207  }
208 
209  /// @brief forcibly remove mapping for pdb residue key
210  /// @param[in] chain chain id
211  /// @param[in] pdb_res pdb residue numbering
212  /// @param[in] ins_code insertion code, use ' ' if no insertion code
213  inline
214  void
216  char const chain,
217  int const pdb_res,
218  char const ins_code
219  )
220  {
221  pdb2pose_.erase( ResidueKey( chain, pdb_res, ins_code ) );
222  }
223 
224  /// @brief clear the current mapping data
225  inline
226  void
228  {
229  pdb2pose_.clear();
230  }
231 
232  /// @brief fill with corresponding pdb -> pose residue mapping
233  /// @note does not clear any currently existing mapping data
234  void
235  fill( PDBInfo const & info );
236 
237 private: // methods
238 
239 #ifdef USEBOOSTSERIALIZE
240  friend class boost::serialization::access;
241 
242  template<class Archive>
243  void serialize(Archive & ar, const unsigned int version) {
244  ar & pdb2pose_;
245  }
246 #endif
247 
248 
249 private: // data
250 
251  /// @brief maps ResidueKey -> Pose internal numbering
253 
254 
255 }; //end class PDBPoseMap
256 
257 } // namespace pose
258 } // namespace core
259 
260 
261 #endif