Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LoopsFileIO.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 protocols/loops/LoopsFileIO.hh
11 /// @brief This class exists to handle the reading and writing of loops files.
12 /// @author Brian D. Weitzner
13 
14 #ifndef INCLUDED_protocols_loops_LoopsFileIO_HH
15 #define INCLUDED_protocols_loops_LoopsFileIO_HH
16 
17 // Unit header
19 
20 // Package headers
23 
24 // Project headers
25 #include <core/pose/Pose.fwd.hh>
26 
27 // Utility headers
28 #include <utility/json_spirit/json_spirit_reader.h>
29 #include <utility/pointer/ReferenceCount.hh>
30 #include <utility/vector1.hh>
31 
32 // C/C++ headers
33 #include <fstream>
34 #include <string>
35 
36 namespace protocols {
37 namespace loops {
38 
39 /// @brief Checks if there is a problem with the beginning and ending residues defined
40 /// in a loops file.
41 void
43  bool prohibit_single_residue_loops,
46  std::string const & filename,
47  core::Size linecount
48 );
49 
50 /// @brief a class which can represent one of many ways in which to describe a
51 /// particular residue in a pose, and can, when given a pose, find its index.
52 /// The object should be constructed with all its needed parameters, but, one
53 /// instance may be copied from another.
55 {
56 public:
60  char chain,
61  int resindex,
62  char insertion_code = ' ' // space character represents no insertion code
63  );
64 
65  core::Size resolve_index( core::pose::Pose const & p ) const;
66 
67  bool unassigned() const { return unassigned_; }
68  bool pose_numbered() const { return pose_numbered_; }
69  core::Size pose_index() const { return pose_index_; }
70  char chain() const { return chain_; }
71  int resindex() const { return resindex_; }
72  char insertion_code() const { return insertion_code_; }
73 
74 private:
78  char chain_; // chain character
79  int resindex_;
81 };
82 
84 {
85 public:
87 
92  );
93 
95  std::string fname,
96  core::Size linenum,
97  char chain,
98  int resindex,
99  char insertion_code = ' ' // space character represents no insertion code
100  );
101 
102  core::Size resolve_index( core::pose::Pose const & p ) const;
103 
104  std::string const & fname() const { return fname_; }
105  core::Size linenum() const { return linenum_; }
106 
107 private:
108  std::string fname_; // file it was
110 };
111 
112 
114 {
115 public:
117 
123  bool extended,
125  );
126 
127  /// constructed the other way around (for the the PoseNumberedLoopReader)
129  SerializedLoop const & loop,
130  std::string const & fname, // file from which this loop was created
132  );
133 
134  /// @brief loop-index resolution function: construct a SerializedLoopData object
135  /// by possibly retrieving data from a Pose. This function also performs the
136  /// loop-index checks performed by the PoseNumberedLoopFileReader.
139 
141  void start_res( ResidueIndexDescriptionFromFile const & setting ) { start_res_ = setting; }
142 
144  void cutpoint_res( ResidueIndexDescriptionFromFile const & setting ) { cutpoint_res_ = setting; }
145 
147  void end_res( ResidueIndexDescriptionFromFile const & setting ) { end_res_ = setting; }
148 
149  core::Real skip_rate() const { return skip_rate_; }
150  void skip_rate( core::Real setting ) { skip_rate_ = setting; }
151 
152  bool extended() const { return extended_; }
153  void extended( bool setting ) { extended_ = setting; }
154 
157 
158 private:
163  bool extended_;
165 };
166 
168 {
169 public:
170  ///@brief Automatically generated virtual destructor for class deriving directly from ReferenceCount
171  virtual ~LoopsFileData();
172 
173  LoopsOP resolve_loops( core::pose::Pose const & pose ) const;
175  core::Size size() const;
176  void resize( core::Size new_size );
177  void push_back( LoopFromFileData const & loop );
178  void insert_loop_at_index( LoopFromFileData const & loop, core::Size i );
179 
180  LoopFromFileData const & operator[] ( core::Size const i ) const;
181 
182 private:
184 };
185 
186 /// @brief This class ensures that the Loops object that is needed to run any of the various
187 /// forms of loop modeling is correctly initialized from a Pose. If the residues specified
188 /// from a loops file have not been resolved into the residue indices for a Pose, then
189 /// this class will die with an assertion failure.
191 {
192 public:
193  /// @brief default ctor; sets the object in an "in charge" state.
195 
196  /// @brief constructor from a loops-file-data object: sets this object in an "in charge" state.
197  GuardedLoopsFromFile( LoopsFileData const & lfd );
198 
199  /// @brief constructor from loops pointer: sets this object in a "not in charge" state.
201 
202  /// @brief constructor from a loops object: set this object in an "in charge" state.
203  GuardedLoopsFromFile( Loops const & loops );
204 
205  /// @brief copy constructor; takes it's "in charge" state from src.
207 
208  /// @brief copy constructor; takes it's "in charge" state from src. Set the copy as not-in-charge.
209  GuardedLoopsFromFile( GuardedLoopsFromFile const & src, bool );
210 
211  /// @brief virtual dstor
212  virtual ~GuardedLoopsFromFile();
213 
214  /// @brief assignment operator; takes it's "in charge" state from rhs
216 
217  /// @brief set to "in charge" state.
218  void in_charge( bool setting );
219 
220  /// @brief get "in charge" state.
221  bool in_charge() const;
222 
223  /// @brief Resolve the loop indices, and mark the state as resolved, so that calls to loops() will succeed.
224  /// This function will re-resolve loop indices with a new pose, which may be important if the same loop_file_data_
225  /// is being applied to a pose which has different PDB indices. If I am not in charge, this is a no-op.
226  void resolve_loop_indices( core::pose::Pose const & );
227 
228  //// @brief Resolve the loop indices if they have not yet been resolved. If I am not in charge, this is a no-op.
230 
231  /// @brief request the LoopsCOP pointer; asserts that the loop indices
232  /// have been resolved or that "I am not in charge".
233  LoopsCOP loops() const;
234 
235  /// @brief request the LoopsOP pointer; asserts that the loop indices
236  /// have been resolved or that "I am not in charge".
237  LoopsOP loops();
238 
239  /// @brief set the loops owning pointer object directly
240  void set_loops_pointer( LoopsOP setting );
241 
242  /// @brief set the loops to copy the contents of settings into the existing Loops object
243  void loops( Loops const & setting );
244 
245  /// @brief set the LoopsFileData object directly
246  void loops( LoopsFileData const & setting );
247 
248  /// @brief read access to the LoopsFileData
249  LoopsFileData const & loops_file_data() const;
250 
251 private:
257 };
258 
259 ///////////////////////////////////////////////////////////////////////////
260 // a class for reading a loops file where the format of that file might
261 // be one of many formats
263 
264 public:
265 
266  //constructor
267  LoopsFileIO();
268 
269  //copy constructor
270  LoopsFileIO( const LoopsFileIO & src );
271 
272  // destructor
273  virtual ~LoopsFileIO();
274 
275  friend std::ostream & operator<<( std::ostream & os, const LoopsFileIO & loops_file_io );
276 
277  /// @brief Return an "unresolved" list of loops specified in a file
278  /// which can be turned into a "resolved" list of residue indices in
279  /// a particular Pose by giving each LoopFromFileData object access
280  /// to that Pose.
281  /// Note: prohibit_single_residue_loops used to be called "strict_looprelax_checks_"
282  /// which was decidedly opaque
284  std::string const & filename,
285  bool prohibit_single_residue_loops = true
286  );
287 
289  std::istream & loopfstream,
290  std::string const & filename,
291  bool prohibit_single_residue_loops = true
292  );
293 
294 
295 }; // LoopsFileIO
296 
297 
298 /// This is the main legacy loop-reading function, which will read the pose-numbered
299 /// file. This functionality is used by a great many number of places often having
300 /// nothing to do with representing a loop, so it will persist.
302 public:
304 
307  std::istream & is,
308  std::string const & filename,
309  bool strict_looprelax_checks = true // i.e. prohibit_single_residue_loops
310  );
311 
312  /// @brief if the input stream has had some number of lines already removed from it,
313  /// indicate how many.
315 
316  /// @brief For code that relys on reading loop-file-formatted ranges if residues
317  /// but which really ought to use
319 
320 private:
323 
324 };
325 
326 /// The following enumerators are used for parsing JSON formatted loop files
328  start=1,
332 };
333 
343 };
344 
346 public:
347 
348  /// @brief if the input stream has had some number of lines already removed from it,
349  /// indicate how many.
351 
354  std::istream & is,
355  std::string const & filename,
356  bool prohibit_single_residue_loops
357  );
358 
359 private: // methods
362  utility::json_spirit::mValue & json_data,
363  bool prohibit_single_residue_loops,
364  std::string const & filename
365  );
366 
367  void
368  ensure_all_fields_are_valid( utility::json_spirit::mValue & json_data, std::string const & filename );
369 
372  utility::json_spirit::mValue & json_loop_data,
373  ResidueIdentifier residue_identifier,
374  std::string const & filename,
375  core::Size & approximate_linenumber
376  );
377 
378  void
380  utility::json_spirit::mValue & json_loop_data,
381  LoopFromFileData & loop
382  );
383 
384  void setup_residue_type_map();
387 
388 private:
390 
391  static bool initialized_;
393 
394 };
395 
396 } //namespace loops
397 } //namespace protocols
398 
399 #endif //INCLUDED_protocols_loops_LoopsFileIO_HH