79 static const int magic;
107 explicit TRR(
const std::string& s) :
Trajectory(s), xdr_file(ifs.get()) {
111 explicit TRR(
const char* p) :
Trajectory(p), xdr_file(ifs.get()) {
114 explicit TRR(std::istream& is) :
Trajectory(is), xdr_file(ifs.get()) {
119 static pTraj create(
const std::string& fname,
const AtomicGroup& model) {
120 return(pTraj(
new TRR(fname)));
124 uint
natoms(
void)
const {
return(hdr_.natoms); }
131 uint
nframes(
void)
const {
return(frame_indices.size()); }
136 std::vector<GCoord>
coords(
void)
const {
return(coords_); }
139 std::vector<double> virial(
void)
const {
return(vir_); }
140 std::vector<double> pressure(
void)
const {
return(pres_); }
141 std::vector<GCoord> forces(
void)
const {
return(forc_); }
143 bool isDouble(
void)
const {
return(hdr_.bDouble); }
144 bool hasVirial(
void)
const {
return(hdr_.vir_size != 0); }
145 bool hasPressure(
void)
const {
return(hdr_.pres_size != 0); }
146 bool hasCoords(
void)
const {
return(hdr_.x_size != 0); }
148 bool hasForces(
void)
const {
return(hdr_.f_size != 0); }
150 double time(
void)
const {
return( hdr_.bDouble ? hdr_.td : hdr_.tf ); }
151 double lambda(
void)
const {
return( hdr_.bDouble ? hdr_.lambdad : hdr_.lambdaf); }
153 int step(
void)
const {
return(hdr_.step); }
156 if (!readHeader(hdr_))
160 return(readRawFrame<double>());
162 return(readRawFrame<float>());
169 bool readHeader(
Header& h);
176 void readBlock(std::vector<double>& v,
const uint n,
const std::string& msg) {
178 uint i = xdr_file.
read(buf, n);
190 void readBlock(std::vector<GCoord>& v,
const uint n,
const std::string& msg) {
193 throw(std::runtime_error(
"Out of memory"));
195 if (xdr_file.
read(buf, n) != n) {
197 throw(FileReadError(_filename,
"Unable to read " + msg));
199 for (uint i=0; i<n; i += DIM)
200 v.push_back(GCoord(buf[i], buf[i+1], buf[i+2]) * 10.0);
208 bool readRawFrame() {
219 readBlock<T>(box_, DIM*DIM,
"box");
220 box = GCoord(box_[0], box_[4], box_[8]) * 10.0;
225 readBlock<T>(vir_, DIM*DIM,
"virial");
227 readBlock<T>(pres_, DIM*DIM,
"pressure");
230 readBlock<T>(coords_, hdr_.natoms * DIM,
"Coordinates");
233 readBlock<T>(velo_, hdr_.natoms * DIM,
"Velocities");
236 readBlock<T>(forc_, hdr_.natoms * DIM,
"Forces");
239 return(! ((xdr_file.
get())->fail() || (xdr_file.
get())->eof()) );
242 void rewindImpl(
void) { ifs->clear(); ifs->seekg(0, std::ios_base::beg); }
243 void seekNextFrameImpl(
void) { }
244 void seekFrameImpl(uint);
245 void updateGroupCoordsImpl(AtomicGroup& g);
246 void updateGroupVelocitiesImpl(AtomicGroup& g);
247 std::vector<GCoord> velocitiesImpl()
const {
return(velo_); }
251 internal::XDRReader xdr_file;
252 std::vector<GCoord> coords_;
254 std::vector<size_t> frame_indices;
257 std::vector<double> box_;
258 std::vector<double> vir_;
259 std::vector<double> pres_;
260 std::vector<GCoord> velo_;
261 std::vector<GCoord> forc_;