LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
Loading...
Searching...
No Matches
xtc.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/*
24 NOTE: This code is based on the xdrfile library authored by:
25 David van der Spoel <spoel@gromacs.org>
26 Erik Lindahl <lindahl@gromacs.org>
27 and covered by the GLPL-v3 license
28*/
29
30
31#if !defined(LOOS_XTC_HPP)
32#define LOOS_XTC_HPP
33#include <ios>
34#include <iostream>
35#include <string>
36#include <stdexcept>
37#include <vector>
38
39#include <loos_defs.hpp>
40
41#include <Coord.hpp>
42#include <xdr.hpp>
43#include <AtomicGroup.hpp>
44#include <Trajectory.hpp>
45
46#include <boost/format.hpp>
47
48namespace loos {
49
50
52
61 class XTC : public Trajectory {
62
63 // Systems with this size or smaller will not be compressed.
64 static const uint min_compressed_system_size;
65
66
67 // The frame header
68 struct Header {
69 uint magic;
70 uint natoms, step;
71 float time, box[9];
72 };
73
74 // Globals required by the decoding routines...
75 static const int magicints[];
76 static const int firstidx, lastidx;
77
78 static const int magic;
79
80
82 typedef float xtc_t;
83
84 public:
85 explicit XTC(const std::string& s) : Trajectory(s), xdr_file(ifs.get()),natoms_(0) {
86 init();
87 }
88
89 explicit XTC(std::istream& is) : Trajectory(is), xdr_file(ifs.get()), natoms_(0) {
90 init();
91 }
92
93 std::string description() const { return("Gromacs XTC (compressed trajectory)"); }
94 static pTraj create(const std::string& fname, const AtomicGroup& model) {
95 return(pTraj(new XTC(fname)));
96 }
97
98 uint natoms(void) const { return(natoms_); }
99 float timestep(void) const { return(timestep_); }
100 uint nframes(void) const { return(frame_indices.size()); }
101 bool hasPeriodicBox(void) const { return(true); }
102 GCoord periodicBox(void) const { return(box); }
103
104 uint currentStep(void) const { return(current_header_.step); }
105 double currentTime(void) const { return(current_header_.time); }
106
107
108 std::vector<GCoord> coords(void) const { return(coords_); }
109
111 double precision(void) const { return(precision_); }
112
113 private:
114
115 void init(void) {
116 scanFrames();
117 coords_.reserve(natoms_);
118 if (!parseFrame())
119 throw(FileReadError(_filename, "Unable to read in the first frame"));
120 cached_first = true;
121 }
122
123 internal::XDRReader xdr_file;
124 std::vector<size_t> frame_indices;
125 uint natoms_;
126 GCoord box;
127 double precision_;
128 std::vector<GCoord> coords_;
129 double timestep_;
130 Header current_header_;
131
132 bool parseFrame(void);
133
134 private:
135
136 int sizeofint(int);
137 int sizeofints(uint*, const uint);
138 int decodebits(int*, uint);
139 void decodeints(int*, const int, int, uint*, int*);
140 bool readFrameHeader(Header&);
141 void scanFrames(void);
142
143 void seekNextFrameImpl(void) { }
144 void seekFrameImpl(uint);
145 void rewindImpl(void) { ifs->clear(); ifs->seekg(0); }
146 void updateGroupCoordsImpl(AtomicGroup& g);
147 bool readCompressedCoords(void);
148 bool readUncompressedCoords(void);
149 };
150
151}
152
153
154
155#endif
Class for handling groups of Atoms (pAtoms, actually)
Definition AtomicGroup.hpp:108
Errors that occur while reading a file.
Definition exceptions.hpp:185
Base-class for polymorphic trajectories.
Definition Trajectory.hpp:65
Class representing GROMACS reduced precision, compressed trajectories.
Definition xtc.hpp:61
bool hasPeriodicBox(void) const
Definition xtc.hpp:101
uint natoms(void) const
Definition xtc.hpp:98
std::vector< GCoord > coords(void) const
Returns the current frames coordinates as a vector of GCoords.
Definition xtc.hpp:108
std::string description() const
Return a string describing trajectory format.
Definition xtc.hpp:93
GCoord periodicBox(void) const
Returns the periodic box for the current frame/trajectory.
Definition xtc.hpp:102
double precision(void) const
Return the stored file's precision.
Definition xtc.hpp:111
float timestep(void) const
Timestep per frame.
Definition xtc.hpp:99
uint nframes(void) const
Number of frames in the trajectory.
Definition xtc.hpp:100
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3
Definition xtcinfo.cpp:10