LOOS  v2.3.2
tinker_arc.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 #include <tinker_arc.hpp>
23 #include <AtomicGroup.hpp>
24 
25 namespace loos {
26 
27  void TinkerArc::init(void) {
28  char buf[512];
29 
30  // Read the first frame to get the # of atoms...
31  frame.read(*(ifs()));
32  _natoms = frame.size();
33  indices.push_back(0l);
34  cached_first = true;
35 
36  // Now determine the # of frames...
37  while (!ifs()->eof()) {
38  indices.push_back(ifs()->tellg());
39  ifs()->getline(buf, sizeof(buf));
40  for (uint i=0; i<_natoms; ++i)
41  ifs()->getline(buf, sizeof(buf));
42  }
43 
44  _nframes = indices.size() - 1;
45 
46  ifs()->clear();
47  ifs()->seekg(indices[1]);
48  }
49 
50 
51  void TinkerArc::seekNextFrameImpl(void) {
52  if (++current_index >= _nframes)
53  at_end = true;
54  }
55 
56 
57  void TinkerArc::seekFrameImpl(const uint i) {
58  if (i >= _nframes)
59  throw(FileError(_filename, "Requested trajectory frame is out of range"));
60 
61  ifs()->clear();
62  ifs()->seekg(indices[i]);
63  if (ifs()->fail())
64  throw(FileError(_filename, "Cannot seek to the requested frame"));
65 
66  current_index = i;
67  at_end = false;
68  }
69 
70 
71  bool TinkerArc::parseFrame(void) {
72  if (ifs()->eof() || at_end)
73  return(false);
74 
75  TinkerXYZ newframe;
76  newframe.read(*(ifs()));
77  frame = newframe;
78  if (frame.size() == 0) {
79  at_end = true;
80  return(false);
81  }
82 
83  return(true);
84  }
85 
86 
87  std::vector<GCoord> TinkerArc::coords(void) {
88  std::vector<GCoord> result(_natoms);
89 
90  for (uint i=0; i<_natoms; i++)
91  result[i] = frame[i]->coords();
92 
93  return(result);
94  }
95 
96 
97  void TinkerArc::updateGroupCoordsImpl(AtomicGroup& g)
98  {
99  for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
100  uint idx = (*i)->index();
101  if (idx >= _natoms)
102  throw(LOOSError(**i, "Atom index into the trajectory frame is out of bounds"));
103  (*i)->coords(frame[idx]->coords());
104  }
105 
106  // Handle periodic boundary conditions (if present)
107  if (hasPeriodicBox()) {
109  }
110  }
111 
112 }
virtual std::vector< GCoord > coords(void)
Returns the current frames coordinates as a vector of GCoords.
Definition: tinker_arc.cpp:87
virtual bool hasPeriodicBox(void) const
Definition: tinker_arc.hpp:78
Class for reading a subset of the TinkerXYZ format.
Definition: tinkerxyz.hpp:47
virtual GCoord periodicBox(void) const
Returns the periodic box for the current frame/trajectory.
Definition: tinker_arc.hpp:79
virtual bool parseFrame(void)
Parse an actual frame.
Definition: tinker_arc.cpp:71
Generic LOOS exception.
Definition: exceptions.hpp:40
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.
GCoord periodicBox(void) const
Fetch the periodic boundary conditions.