LOOS  v2.3.2
gro.hpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2009, 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 #if !defined(LOOS_GRO_HPP)
24 #define LOOS_GRO_HPP
25 
26 
27 #include <iostream>
28 #include <string>
29 #include <sstream>
30 #include <fstream>
31 #include <stdexcept>
32 
33 #include <loos_defs.hpp>
34 #include <AtomicGroup.hpp>
35 
36 namespace loos {
37 
39  class Gromacs : public AtomicGroup {
40  public:
41 
42  Gromacs() { }
43 
44  explicit Gromacs(const std::string& fname) : _filename(fname), _max_index(0) {
45  std::ifstream ifs(fname.c_str());
46  if (!ifs)
47  throw(FileOpenError(fname));
48  read(ifs);
49  }
50 
51  explicit Gromacs(std::istream& ifs) : _filename("stream"), _max_index(0) { read(ifs); }
52 
53  static pAtomicGroup create(const std::string& fname) {
54  return(pAtomicGroup(new Gromacs(fname)));
55  }
56 
57 
58 #if !defined(SWIG)
59  friend std::ostream& operator<<(std::ostream&, const Gromacs&);
61 #endif
62 
63  std::string title(void) const { return(title_); }
64 
65 
66 
68  static Gromacs fromAtomicGroup(const AtomicGroup&);
69 
70  private:
71  std::string _filename;
72  std::string title_;
73  uint _max_index;
74 
75  private:
76 
77  void read(std::istream& ifs);
78 
79  // Convert an Atom to a string representation in PDB format...
80  std::string atomAsString(const pAtom p) const;
81 
83  Gromacs(const AtomicGroup& grp) : AtomicGroup(grp) { }
84 
85  };
86 
87 
88 
89 }
90 
91 
92 #endif
Error while opening a file.
Definition: exceptions.hpp:170
Implements a GROMACS model file (.gro)
Definition: gro.hpp:39
friend std::ostream & operator<<(std::ostream &, const Gromacs &)
Output as a GRO.
Definition: gro.cpp:131
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.
static Gromacs fromAtomicGroup(const AtomicGroup &)
Class method for creating a GRO from an AtomicGroup.
Definition: gro.cpp:119