LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
Loading...
Searching...
No Matches
pdb.hpp
1/*
2 This file is part of LOOS.
3
4 LOOS (Lightweight Object-Oriented Structure library)
5 Copyright (c) 2008, Tod D. Romo, Alan Grossfield
6 Department of Biochemistry and Biophysics
7 School of Medicine & Dentistry, University of Rochester
8
9 This package (LOOS) is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation under version 3 of the License.
12
13 This package is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22
23
24
25#if !defined(LOOS_PDB_HPP)
26#define LOOS_PDB_HPP
27
28
29
30
31#include <iostream>
32#include <fstream>
33#include <stdexcept>
34#include <vector>
35#include <map>
36
37#include <loos_defs.hpp>
38#include <AtomicGroup.hpp>
39#include <exceptions.hpp>
40#include <pdb_remarks.hpp>
41#include <cryst.hpp>
42#include <utils.hpp>
43#include <utils_structural.hpp>
44
45
46
47namespace loos {
48
50
69 class PDB : public AtomicGroup {
70 public:
71 PDB() : _max_index(0), _show_charge(false), _auto_ter(true), _has_cryst(false),
72 strictness_policy(false), _missing_q(false), _missing_b(false),
73 _missing_segid(false), _fname("<not set>") { }
74 virtual ~PDB() {}
75
77 explicit PDB(const std::string& fname)
78 : _max_index(0), _show_charge(false), _auto_ter(true),
79 _has_cryst(false), strictness_policy(false),
80 _missing_q(false), _missing_b(false), _missing_segid(false),
81 _fname(fname)
82 {
83 std::ifstream ifs(fname.c_str());
84 if (!ifs)
85 throw(FileOpenError(fname));
86 read(ifs);
87 }
88
90 explicit PDB(std::istream& ifs)
91 : _max_index(0), _show_charge(false), _auto_ter(true),
92 _has_cryst(false), strictness_policy(false),
93 _missing_q(false), _missing_b(false), _missing_segid(false),
94 _fname("stream")
95 {
96 read(ifs);
97 }
98
99 static pAtomicGroup create(const std::string& fname) {
100 return(pAtomicGroup(new PDB(fname)));
101 }
102
104 virtual PDB* clone(void) const;
105
107 PDB copy(void) const;
108
110
114 static PDB fromAtomicGroup(const AtomicGroup&);
115
117 void showCharge(bool b);
118
119
120 bool showCharge(void) const;
121 bool strict(void) const;
122 bool autoTerminate(void) const;
123
125 void strict(const bool b);
126
128
131 void autoTerminate(bool b);
132
134 Remarks& remarks(void);
136 void remarks(const Remarks&);
137
138 const UnitCell& unitCell(void);
139 void unitCell(const UnitCell&);
140
142 friend std::ostream& operator<<(std::ostream&, const PDB&);
143
144 std::string asString() const;
145
147 void read(std::istream& is);
148
149 private:
150 class ComparePatoms {
151 bool operator()(const pAtom& a, const pAtom& b) { return(a->id() < b->id()); }
152 };
153
154
156 PDB(const AtomicGroup& grp) : AtomicGroup(grp), _show_charge(false), _auto_ter(true), _has_cryst(false) { }
157
158 bool emptyString(const std::string&);
159
160 bool isMissingOccupancies() const { return(_missing_q); }
161 bool isMissingBFactors() const { return(_missing_b); }
162 bool isMissingSegids() const { return(_missing_segid); }
163 bool isMissingFields() const { return(_missing_q || _missing_b || _missing_segid); }
164
165
166 // These will modify the PDB upon a successful parse...
167 void parseRemark(const std::string&);
168 void parseAtomRecord(const std::string&);
169 void parseConectRecord(const std::string&);
170 void parseCryst1Record(const std::string&);
171
172 // Convert an Atom to a string representation in PDB format...
173 std::string atomAsString(const pAtom p) const;
174
175#if !defined(SWIG)
176 friend std::ostream& FormatConectRecords(std::ostream&, const PDB&);
177#endif
178
179 pAtom findAtom(const int i);
180 void uniqueBonds();
181
182 private:
183 uint _max_index;
184 bool _show_charge;
185 bool _auto_ter;
186 bool _has_cryst;
187 bool strictness_policy;
188 bool _missing_q, _missing_b, _missing_segid;
189 std::string _fname;
190 Remarks _remarks;
191 UnitCell cell;
192 std::map<int, pAtom> _atomid_to_patom;
193 };
194
195}
196
197#endif
198
Class for handling groups of Atoms (pAtoms, actually)
Definition AtomicGroup.hpp:108
Error while opening a file.
Definition exceptions.hpp:175
PDB reading/writing class.
Definition pdb.hpp:69
PDB(const std::string &fname)
Read in PDB from a filename.
Definition pdb.hpp:77
friend std::ostream & operator<<(std::ostream &, const PDB &)
Output as a PDB.
Definition pdb.cpp:493
void read(std::istream &is)
Read in PDB from an ifstream.
Definition pdb.cpp:333
Remarks & remarks(void)
Accessor for the remarks object...
Definition pdb.cpp:578
PDB copy(void) const
Creates a deep copy (see AtomicGroup::copy() for more info)
Definition pdb.cpp:532
PDB(std::istream &ifs)
Read in a PDB from an ifstream.
Definition pdb.hpp:90
virtual PDB * clone(void) const
Clones an object for polymorphism (see AtomicGroup::clone() for more info)
Definition pdb.cpp:545
static PDB fromAtomicGroup(const AtomicGroup &)
Class method for creating a PDB from an AtomicGroup.
Definition pdb.cpp:549
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3