OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
pdb_reader.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_IO_PDB_READER_HH
20 #define OST_IO_PDB_READER_HH
21 /*
22  Author: Marco Biasini
23  */
24 
25 #include <boost/iostreams/filtering_stream.hpp>
26 #include <boost/filesystem/fstream.hpp>
27 #include <ost/string_ref.hh>
28 #include <ost/seq/sequence_list.hh>
30 #include <ost/mol/entity_handle.hh>
31 #include <ost/mol/chain_handle.hh>
32 #include <ost/mol/atom_handle.hh>
33 #include <ost/mol/xcs_editor.hh>
34 
35 #include <ost/io/module_config.hh>
36 #include <ost/io/mol/io_profile.hh>
37 namespace ost { namespace io {
38 
40  struct HSEntry {
41  mol::ResNum start;
43  String chain;
44  };
45  struct HetEntry {
46  HetEntry(char c, mol::ResNum n): chain(c), num(n) {}
47  char chain;
48  mol::ResNum num;
49  };
50  struct CompndEntry {
51  CompndEntry(std::vector<String> c, int n): chains(c), mol_id(n) {}
52  std::vector<String> chains;
53  int mol_id;
54  };
55  typedef std::vector<HSEntry> HSList;
56  typedef std::vector<HetEntry> HetList;
57  typedef std::vector<CompndEntry> CompndList;
58 public:
59  PDBReader(const String& filename, const IOProfile& profile);
60  PDBReader(const boost::filesystem::path& loc, const IOProfile& profile);
61  PDBReader(std::istream& instream, const IOProfile& profile);
62 
63  bool HasNext();
64 
65  void Import(mol::EntityHandle& ent,
66  const String& restrict_chains="");
67  void SetReadSeqRes(bool flag) { read_seqres_=flag; }
68  bool GetReadSeqRes() const { return read_seqres_; }
69 
70  seq::SequenceList GetSeqRes() const { return seqres_; }
71 private:
72  void ParseSeqRes(const StringRef& line, int line_num);
74  void ParseCompndEntry(const StringRef& line, int line_num);
75  void ClearState();
76  void AssignSecStructure(mol::EntityHandle ent);
78  void AssignMolIds(mol::EntityHandle ent);
79  void ParseAndAddAtom(const StringRef& line, int line_num,
80  mol::EntityHandle& h, const StringRef& record_type);
81  void ThrowFaultTolerant(const String& msg);
83  bool ParseAtomIdent(const StringRef& line, int line_num,
84  String& chain_name, StringRef& res,
85  mol::ResNum& resnum, StringRef& atom_name, char& alt_loc,
86  const StringRef& record_type);
87  void ParseAnisou(const StringRef& line, int line_num,
89  void ParseHelixEntry(const StringRef& line);
90  void ParseStrandEntry(const StringRef& line);
91  void Init(const boost::filesystem::path& loc);
92  bool EnsureLineLength(const StringRef& line, size_t size);
93  mol::ChainHandle curr_chain_;
94  mol::ResidueHandle curr_residue_;
95  int chain_count_;
96  int residue_count_;
97  int atom_count_;
98  int line_num_;
99  bool hard_end_;
100  int num_model_records_;
101  String restrict_chains_;
102  HSList helix_list_;
103  HSList strand_list_;
104  boost::filesystem::ifstream infile_;
105  std::istream& instream_;
106  boost::iostreams::filtering_stream<boost::iostreams::input> in_;
107  String curr_line_;
108  HetList hets_;
109  CompndList compnds_;
110  std::pair <bool, int> mol_id_;
111  bool skip_next_;
112  bool data_continues_;
113  String old_key_;
114  // this needs to be set to true for reading pqr
115  // file (i.e. pdb formatted file with charges in occupacy
116  // column, and radii in b-factor column)
117  bool is_pqr_;
118  IOProfile profile_;
119  bool charmm_style_;
120  bool warned_name_mismatch_;
121  bool read_seqres_;
122  bool warned_rule_based_;
123  seq::SequenceList seqres_;
124 };
125 
126 }}
127 
128 #endif