LOOS  v2.3.2
pdbtraj.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 <pdbtraj.hpp>
24 #include <boost/format.hpp>
25 
26 namespace loos {
27  void PDBTraj::rewindImpl(void) { seekFrame(0); }
28  uint PDBTraj::nframes(void) const { return(_nframes); }
29  uint PDBTraj::natoms(void) const { return(_natoms); }
30 
31 
33 
34  for (AtomicGroup::iterator i = g.begin(); i != g.end(); ++i) {
35  int idx = (*i)->index();
36  (*i)->coords(frame[idx]->coords());
37  }
38  }
39 
40  bool PDBTraj::hasPeriodicBox(void) const { return(frame.isPeriodic()); }
41  GCoord PDBTraj::periodicBox(void) const { return(frame.periodicBox()); }
42  float PDBTraj::timestep(void) const { return(0.001); }
43  std::string PDBTraj::currentName(void) const { return(current_name); }
44  PDB PDBTraj::currentFrame(void) const { return(frame); }
45 
46 
47  void PDBTraj::init(void) {
48  seekFrame(0);
49  parseFrame();
50  _natoms = frame.size();
51  _nframes = (end - start) / stride + 1;
52  }
53 
54 
55  void PDBTraj::seekFrameImpl(const uint i) {
56 
57  uint idx = i * stride + start;
58  if (idx < start || i > end)
59  throw(FileError(_filename, "Attempting to seek to frame beyond the end of the trajectory"));
60 
61  std::stringstream s;
62  s << boost::format(pattern) % idx;
63  current_name = s.str();
64  ifs.setStream(current_name);
65  current_index = i;
66  at_end = false;
67  }
68 
69 
70  void PDBTraj::seekNextFrameImpl(void) {
71  if (at_end)
72  return;
73 
74  if (current_index >= _nframes)
75  at_end = true;
76  else {
77  seekFrame(current_index);
78  ++current_index;
79  }
80  }
81 
82 
83  bool PDBTraj::parseFrame(void) {
84 
85  if (at_end)
86  return(false);
87 
88  PDB newframe;
89  newframe.read(*(ifs()));
90  frame = newframe;
91  if (frame.size() == 0) {
92  at_end = true;
93  return(false);
94  }
95 
96  return(true);
97  }
98 
99 
100 
101  std::vector<GCoord> PDBTraj::coords(void) {
102  std::vector<GCoord> result(_natoms);
103 
104  for (uint i=0; i<_natoms; i++)
105  result[i] = frame[i]->coords();
106 
107  return(result);
108  }
109 
110 
111 }
virtual bool parseFrame(void)
Parse an actual frame.
Definition: pdbtraj.cpp:83
virtual std::vector< GCoord > coords(void)
Returns the current frames coordinates as a vector of GCoords.
Definition: pdbtraj.cpp:101
bool isPeriodic(void) const
Test whether or not periodic boundary conditions are set.
virtual bool hasPeriodicBox(void) const
Definition: pdbtraj.cpp:40
PDB currentFrame(void) const
See CCPDB::currentFrame() for important notes.
Definition: pdbtraj.cpp:44
void seekFrame(const uint i)
Definition: Trajectory.hpp:155
PDB reading/writing class.
Definition: pdb.hpp:69
virtual float timestep(void) const
Timestep per frame.
Definition: pdbtraj.cpp:42
virtual void updateGroupCoords(AtomicGroup &g)
Definition: pdbtraj.cpp:32
virtual uint natoms(void) const
of atoms per frame
Definition: pdbtraj.cpp:29
std::string currentName(void) const
Returns the auto-generated name for the file containing the current frame.
Definition: pdbtraj.cpp:43
void read(std::istream &is)
Read in PDB from an ifstream.
Definition: pdb.cpp:332
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.
virtual GCoord periodicBox(void) const
Returns the periodic box for the current frame/trajectory.
Definition: pdbtraj.cpp:41
virtual uint nframes(void) const
Number of frames in the trajectory.
Definition: pdbtraj.cpp:28
void setStream(const std::string &s, const std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary)
Sets the internal stream to point to a newly opened filed...
GCoord periodicBox(void) const
Fetch the periodic boundary conditions.