LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
Loading...
Searching...
No Matches
amber.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_AMBER_HPP)
26#define LOOS_AMBER_HPP
27
28
29
30#include <fstream>
31#include <sstream>
32#include <string>
33#include <stdexcept>
34#include <vector>
35#include <boost/algorithm/string.hpp>
36#include <boost/tokenizer.hpp>
37
38#include <loos_defs.hpp>
39#include <AtomicGroup.hpp>
40#include <LineReader.hpp>
41
42
43namespace loos {
44
46
60 class Amber : public AtomicGroup {
61 private:
62
63 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
64
65
66 struct FormatSpec {
67 FormatSpec() : repeat(1), type('?'), width(0), precision(0) { }
68 int repeat;
69 char type;
70 int width;
71 int precision;
72 };
73
74 struct AmberLineReader : public LineReader {
75 AmberLineReader() : LineReader() { }
76 AmberLineReader(std::istream& is) : LineReader(is) { }
77 AmberLineReader(std::istream& is, std::string& s) : LineReader(is, s) { }
78
79 virtual void stripComment(std::string& s) const {
80 if (s.compare(0, 8, "%COMMENT") == 0)
81 s = "";
82 }
83 };
84
85 public:
86
87 Amber() : natoms(0), nres(0), nbonh(0), mbona(0) { }
88 virtual ~Amber() { }
89
91 explicit Amber(const std::string& fname)
92 : natoms(0), nres(0), nbonh(0), mbona(0) {
93 std::ifstream ifs(fname.c_str());
94 if (!ifs)
95 throw(FileOpenError(fname));
96 reader.stream(ifs);
97 reader.name(fname);
98 read(ifs);
99 }
100
101 explicit Amber(std::istream& ifs)
102 : natoms(0), nres(0), nbonh(0), mbona(0), reader(ifs) {
103 read(ifs);
104 }
105
106 static pAtomicGroup create(const std::string& fname) {
107 return(pAtomicGroup(new Amber(fname)));
108 }
109
110
112 virtual Amber* clone(void) const {
113 return(new Amber(*this));
114 }
115
117 Amber copy(void) const {
118 AtomicGroup grp = this->AtomicGroup::copy();
119 Amber p(grp);
120
121 return(p);
122 }
123
125 void read(std::istream& ifs);
126
128 std::string title() const { return(_title); }
129
130 private:
131
132 Amber(const AtomicGroup& grp) : AtomicGroup(grp), natoms(0), nres(0), nbonh(0), mbona(0) { }
133
134 FormatSpec parseFormat(const std::string& expected_types, const std::string& where);
135
136 void parseCharges();
137 void parseMasses();
138 void parseResidueLabels();
139 void parseResiduePointers();
140 void assignResidues(void);
141 void parseBonds(const uint);
142 void parsePointers();
143 void parseTitle();
144 void parseAtomNames();
145 void parseBoxDimensions();
146 void parseAmoebaRegularBondNumList();
147 void parseAmoebaRegularBondList(const uint);
148
149
150 // Reads in a "block" of data. Reading terminates on the first
151 // line that begins with a '%'.
152
153 template<typename T>
154 std::vector<T> readBlock(const int field_width) {
155 std::vector<T> data;
156 while (reader.getNext()) {
157 std::string line = reader.line();
158 if (line[0] == '%') {
159 reader.push_back(line);
160 break;
161 }
162 std::istringstream iss(line);
163 T d;
164 while (iss >> std::setw(field_width) >> d)
165 data.push_back(d);
166 }
167
168 return(data);
169 }
170
171 private:
172
173 std::string _title;
174
175 // These are internal and are used for parsing the parmtop info...
176 uint natoms, nres, nbonh, mbona, _amoeba_regular_bond_num_list;
177
178 std::vector<std::string> residue_labels;
179 std::vector<uint> residue_pointers;
180
181 AmberLineReader reader;
182
183 };
184
185
186}
187
188
189
190#endif
Class for reading in AMBER parmtop/coord files...
Definition amber.hpp:60
std::string title() const
Return the title.
Definition amber.hpp:128
virtual Amber * clone(void) const
Clones an object for polymorphism...
Definition amber.hpp:112
void read(std::istream &ifs)
Parse the parmtop file.
Definition amber.cpp:300
Amber(const std::string &fname)
Read in a parmtop file.
Definition amber.hpp:91
Amber copy(void) const
Deep copy.
Definition amber.hpp:117
Class for handling groups of Atoms (pAtoms, actually)
Definition AtomicGroup.hpp:108
AtomicGroup copy(void) const
Creates a deep copy of this group.
Definition AtomicGroup.cpp:59
Error while opening a file.
Definition exceptions.hpp:175
Class for reading line-by-line from a file while tracking line numbers and stripping comments.
Definition LineReader.hpp:39
virtual bool getNext()
Get the next line from the file, returning true if successful.
Definition LineReader.cpp:38
virtual std::string line() const
The currently read line.
Definition LineReader.cpp:62
virtual std::istream & stream() const
Access the internal stream pointer.
Definition LineReader.cpp:30
virtual std::string name() const
Access the name associated with the internal stream.
Definition LineReader.cpp:33
virtual void push_back(const std::string &s)
Put a line back onto the file (virtually)
Definition LineReader.cpp:58
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3