LOOS  v2.3.2
ccpdb.cpp
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 #include <ccpdb.hpp>
24 
25 namespace loos {
26 
27  // Do some initial parsing to setup the Trajectory object...
28 
29  void CCPDB::init(void) {
30  char buf[512];
31 
32  // Read the first frame to get the # of atoms...
33  frame.read(*(ifs()));
34  _natoms = frame.size();
35  cached_first = true;
36  indices.push_back(0l);
37  indices.push_back(ifs()->tellg());
38 
39  // Now count the # of END statements...
40  while (ifs()->getline(buf, sizeof(buf)))
41  if (strncmp("END", buf, 3) == 0)
42  indices.push_back(ifs()->tellg());
43 
44  _nframes = indices.size() - 1;
45  ifs()->clear();
46  ifs()->seekg(indices[1]);
47  }
48 
49 
50  void CCPDB::seekFrameImpl(const uint i) {
51  if (i >= _nframes)
52  throw(FileError(_filename, "Attempting to seek to frame beyond the end of the trajectory"));
53 
54  ifs()->clear();
55  ifs()->seekg(indices[i]);
56  if (ifs()->fail())
57  throw(FileError(_filename, "Cannot seek to requested trajectory"));
58  }
59 
60 
61  bool CCPDB::parseFrame(void) {
62  if (ifs()->eof())
63  return(false);
64 
65  // We cheat here... Maybe it would be better to have a PDB::clear()
66  // or AtomicGroup::clear() member function???
67  // Note: For some reason, PDB newframe(*(ifs())) doesn't parse correctly...
68  PDB newframe;
69  newframe.read(*(ifs()));
70  frame = newframe;
71  if (frame.size() == 0)
72  return(false);
73 
74  return(true);
75  }
76 
77 
78  std::vector<GCoord> CCPDB::coords(void) {
79  std::vector<GCoord> result(_natoms);
80 
81  for (uint i=0; i<_natoms; i++)
82  result[i] = frame[i]->coords();
83 
84  return(result);
85  }
86 
87  void CCPDB::updateGroupCoordsImpl(AtomicGroup& g) {
88 
89  for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
90  int idx = (*i)->index();
91  (*i)->coords(frame[idx]->coords());
92  }
93 
94  g.periodicBox(frame.periodicBox());
95  }
96 
97 
98 }
PDB reading/writing class.
Definition: pdb.hpp:69
void read(std::istream &is)
Read in PDB from an ifstream.
Definition: pdb.cpp:332
virtual std::vector< GCoord > coords(void)
Returns the current frames coordinates as a vector of GCoords.
Definition: ccpdb.cpp:78
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.
virtual bool parseFrame(void)
Parse an actual frame.
Definition: ccpdb.cpp:61
GCoord periodicBox(void) const
Fetch the periodic boundary conditions.