OpenStructure
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/mol/mol.hh>
29 #include <ost/mol/xcs_editor.hh>
30 #include <ost/io/module_config.hh>
31 #include <ost/io/mol/io_profile.hh>
32 namespace ost { namespace io {
33 
35  struct HSEntry {
36  mol::ResNum start;
38  String chain;
39  };
40  struct HetEntry {
41  HetEntry(char c, mol::ResNum n): chain(c), num(n) {}
42  char chain;
43  mol::ResNum num;
44  };
45  typedef std::vector<HSEntry> HSList;
46  typedef std::vector<HetEntry> HetList;
47 public:
48  PDBReader(const String& filename, const IOProfile& profile);
49  PDBReader(const boost::filesystem::path& loc, const IOProfile& profile);
50  PDBReader(std::istream& instream, const IOProfile& profile);
51 
52  bool HasNext();
53 
54  void Import(mol::EntityHandle& ent,
55  const String& restrict_chains="");
56 
57 private:
58  void ClearState();
59  void AssignSecStructure(mol::EntityHandle ent);
60  void ParseAndAddAtom(const StringRef& line, int line_num,
61  mol::EntityHandle& h, const StringRef& record_type);
62 
64  bool ParseAtomIdent(const StringRef& line, int line_num,
65  String& chain_name, StringRef& res,
66  mol::ResNum& resnum, StringRef& atom_name, char& alt_loc,
67  const StringRef& record_type);
68  void ParseAnisou(const StringRef& line, int line_num,
70  void ParseHelixEntry(const StringRef& line);
71  void ParseStrandEntry(const StringRef& line);
72  void Init(const boost::filesystem::path& loc);
73  bool EnsureLineLength(const StringRef& line, size_t size);
74  mol::ChainHandle curr_chain_;
75  mol::ResidueHandle curr_residue_;
76  int chain_count_;
77  int residue_count_;
78  int atom_count_;
79  int line_num_;
80  bool hard_end_;
81  int num_model_records_;
82  String restrict_chains_;
83  HSList helix_list_;
84  HSList strand_list_;
85  boost::filesystem::ifstream infile_;
86  std::istream& instream_;
87  boost::iostreams::filtering_stream<boost::iostreams::input> in_;
88  String curr_line_;
89  HetList hets_;
90  // this needs to be set to true for reading pqr
91  // file (i.e. pdb formatted file with charges in occupacy
92  // column, and radii in b-factor column)
93  bool is_pqr_;
94  IOProfile profile_;
95  bool charmm_style_;
96  bool warned_name_mismatch_;
97 };
98 
99 }}
100 
101 #endif