LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
Loading...
Searching...
No Matches
dcd.hpp
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
24#if !defined(LOOS_DCD_HPP)
25#define LOOS_DCD_HPP
26
27
28#include <iostream>
29#include <string>
30#include <stdexcept>
31#include <exception>
32
33#include <loos_defs.hpp>
34
35#include <Trajectory.hpp>
36
37
38namespace loos {
39
40
42
63 class DCD : public Trajectory {
64 static bool suppress_warnings;
65
66
67 // Use a union to convert data to appropriate type...
68 typedef union { unsigned int ui; int i; char c[4]; float f; } DataOverlay;
69
70 public:
71 class EndOfFile : public LOOSError {
72 public:
73 EndOfFile() : LOOSError("unexpected end of file while reading DCD") { }
74 };
75
77 explicit DCD(const std::string s) : Trajectory(s), _natoms(0), _nframes(0),
78 qcrys(std::vector<double>(6)),
79 frame_size(0), first_frame_pos(0),
80 swabbing(false) { initTrajectory(); }
81
83 explicit DCD(const char* s) : Trajectory(s), _natoms(0), _nframes(0),
84 qcrys(std::vector<double>(6)), frame_size(0),
85 first_frame_pos(0), swabbing(false) { initTrajectory(); }
86
88 explicit DCD(std::istream& fs) : Trajectory(fs), _natoms(0), _nframes(0),
89 qcrys(std::vector<double>(6)), frame_size(0), first_frame_pos(0),
90 swabbing(false) { initTrajectory(); };
91
92 std::string description() const { return("CHARMM/NAMD DCD"); }
93
94 static pTraj create(const std::string& fname, const AtomicGroup& model) {
95 return(pTraj(new DCD(fname)));
96 }
97
98
99
100 // Accessor methods...
101
102 virtual uint natoms(void) const;
103 virtual bool hasPeriodicBox(void) const;
104 virtual GCoord periodicBox(void) const;
105
106 virtual bool hasVelocities() const { return(false); }
107 virtual double velocityConversionFactor() const { return(20.45482706); }
108
109 std::vector<std::string> titles(void) const;
110
111 int icntrl(const int) const;
112 void icntrl(const int, const int);
113
114 // * legacy *
115 std::vector<double> crystalParams(void) const;
116 bool hasCrystalParams(void) const;
117
118 virtual float timestep(void) const;
119 virtual uint nframes(void) const;
120
122 std::vector<dcd_real> xcoords(void) const;
124 std::vector<dcd_real> ycoords(void) const;
126 std::vector<dcd_real> zcoords(void) const;
127
128 // The following track CHARMm names (more or less...)
129 unsigned int nsteps(void) const;
130 float delta(void) const;
131 int nsavc(void) const;
132 int nfile(void) const;
133 int nfixed(void) const;
134
136 bool nativeFormat(void) const;
137
139
140 virtual std::vector<GCoord> coords(void) const;
141
143 // This is slated to go away...
144 std::vector<GCoord> mappedCoords(const std::vector<int>& map);
145
146
147
148 static void setSuppression(const bool b) { suppress_warnings = b; }
149
151 virtual bool parseFrame(void);
152
153 private:
154
156 void readHeader(void);
157
158 void initTrajectory();
159
160 uint calculateNumberOfFrames();
161
162 // Trajectory member functions we must provide...
163 virtual void seekNextFrameImpl(void) { } // DCD frames are always contiguous, so do nothing...
165 virtual void seekFrameImpl(const uint);
166
168 virtual void rewindImpl(void);
169
171 virtual void updateGroupCoordsImpl(AtomicGroup& g);
172
173
174
175 void allocateSpace(const int n);
176 bool readCrystalParams(void);
177 bool readCoordLine(std::vector<float>& v);
178
179 void endianMatch(pStream& fsw);
180
181 // For reading F77 I/O
182 unsigned int readRecordLen(void);
183 DataOverlay* readF77Line(unsigned int *len);
184
185
186
187 private:
188 int _icntrl[20]; // DCD header data
189 uint _natoms; // # of atoms
190 uint _nframes;
191 std::vector<std::string> _titles; // Vector of title lines from DCD
192 std::vector<double> qcrys; // Crystal params
193 float _delta; // Timestep (extracted from _icntrl)
194
195 std::streamoff frame_size; // *Internal* size (in bytes) of each frame
196 std::streampos first_frame_pos; // *Internal* location in file of start of data frames
197
198 bool swabbing; // DCD being read is not in native format...
199
200 std::vector<dcd_real> xcrds, ycrds, zcrds;
201
202 };
203
204}
205
206
207
208#endif
Class for handling groups of Atoms (pAtoms, actually)
Definition AtomicGroup.hpp:108
Definition dcd.hpp:71
Class for reading DCD files.
Definition dcd.hpp:63
DCD(std::istream &fs)
Begin reading from the stream ifs.
Definition dcd.hpp:88
virtual bool hasPeriodicBox(void) const
Definition dcd.cpp:43
virtual uint nframes(void) const
Number of frames in the trajectory.
Definition dcd.cpp:60
std::vector< dcd_real > zcoords(void) const
Return the raw coords...
Definition dcd.cpp:64
virtual bool parseFrame(void)
Parse a frame of the DCD.
Definition dcd.cpp:349
virtual double velocityConversionFactor() const
Conversion applied to velocities to get to \AA/ps.
Definition dcd.hpp:107
std::vector< dcd_real > xcoords(void) const
Return the raw coords...
Definition dcd.cpp:62
DCD(const char *s)
Begin reading from the file named s.
Definition dcd.hpp:83
virtual GCoord periodicBox(void) const
Returns the periodic box for the current frame/trajectory.
Definition dcd.cpp:44
std::string description() const
Return a string describing trajectory format.
Definition dcd.hpp:92
bool nativeFormat(void) const
Returns true if the DCD file being read is in the native endian format.
Definition dcd.cpp:73
std::vector< dcd_real > ycoords(void) const
Return the raw coords...
Definition dcd.cpp:63
std::vector< GCoord > mappedCoords(const std::vector< int > &map)
Interleave coords, selecting entries indexed by map.
Definition dcd.cpp:397
virtual std::vector< GCoord > coords(void) const
Auto-interleave the coords into a vector of GCoord()'s.
Definition dcd.cpp:385
virtual uint natoms(void) const
Definition dcd.cpp:42
virtual float timestep(void) const
Timestep per frame.
Definition dcd.cpp:59
DCD(const std::string s)
Begin reading from the file named s.
Definition dcd.hpp:77
virtual bool hasVelocities() const
Whether or not the trajectory format supports velocities.
Definition dcd.hpp:106
Generic LOOS exception.
Definition exceptions.hpp:40
Base-class for polymorphic trajectories.
Definition Trajectory.hpp:65
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3