LOOS 4.1.0
The Lightweight Object Oriented Structural analysis library/toolkit
Loading...
Searching...
No Matches
xtcwriter.hpp
1/*
2 This file is part of LOOS.
3
4 LOOS (Lightweight Object-Oriented Structure library)
5 Copyright (c) 2014, 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#if !defined(LOOS_XTCWRITER_HPP)
24#define LOOS_XTCWRITER_HPP
25
26#include <fstream>
27#include <string>
28#include <stdexcept>
29#include <vector>
30
31#include <loos_defs.hpp>
32#include <AtomicGroup.hpp>
33#include <xdr.hpp>
34#include <trajwriter.hpp>
35
36namespace loos {
37
39
52 class XTCWriter : public TrajectoryWriter {
53 static const int magicints[];
54 static const int firstidx;
55
56 static const int lastidx;
57
58 static const int DIM;
59
60 public:
61
62
64 static pTrajectoryWriter create(const std::string& s, const bool append = false) {
65 return(pTrajectoryWriter(new XTCWriter(s, append)));
66 }
67
68
69 XTCWriter(const std::string& fname, const bool append = false) :
70 TrajectoryWriter(fname, append),
71 buf1size(0), buf2size(0),
72 buf1(0), buf2(0),
73 natoms_(0),
74 dt_(1.0),
75 step_(0),
76 steps_per_frame_(1),
77 current_(0),
78 crds_size_(0),
79 crds_(0),
80 precision_(1e3)
81 {
82 xdr.setStream(stream_);
83 if (appending_)
84 prepareToAppend();
85 }
86
87
88 XTCWriter(const std::string& fname, const double dt, const uint steps_per_frame, const bool append = false) :
89 TrajectoryWriter(fname, append),
90 buf1size(0), buf2size(0),
91 buf1(0), buf2(0),
92 natoms_(0),
93 dt_(dt),
94 step_(0),
95 steps_per_frame_(steps_per_frame),
96 current_(0),
97 crds_size_(0),
98 crds_(0),
99 precision_(1e3)
100 {
101 xdr.setStream(stream_);
102 if (appending_)
103 prepareToAppend();
104 }
105
106
107 XTCWriter(const std::string& fname, const double dt, const uint steps_per_frame, const float precision, const bool append = false) :
108 TrajectoryWriter(fname, append),
109 buf1size(0), buf2size(0),
110 buf1(0), buf2(0),
111 natoms_(0),
112 dt_(dt),
113 step_(0),
114 steps_per_frame_(steps_per_frame),
115 current_(0),
116 crds_size_(0),
117 crds_(0),
118 precision_(precision)
119 {
120 xdr.setStream(stream_);
121 if (appending_)
122 prepareToAppend();
123 }
124
125
126
127
128
129
130
131 ~XTCWriter() {
132 delete[] buf1;
133 delete[] buf2;
134 delete[] crds_;
135 }
136
137
139 double timePerStep() const { return(dt_); }
140
142 void timePerStep(const double dt) { dt_ = dt; }
143
145 uint stepsPerFrame() const { return(steps_per_frame_); }
146
148 void stepsPerFrame(const uint s) { steps_per_frame_ = s; }
149
151 uint currentStep() const { return(step_); }
152
154 void currentStep(const uint s) { step_ = s; }
155
156
158 void writeFrame(const AtomicGroup& model);
159
161 void writeFrame(const AtomicGroup& model, const uint step, const double time);
162
163 uint framesWritten() const { return(current_); }
164
165 private:
166 int sizeofint(const int size) const;
167 int sizeofints(const int num_of_bits, const unsigned int sizes[]) const;
168 void encodebits(int* buf, int num_of_bits, const int num) const;
169 void encodeints(int* buf, const int num_of_ints, const int num_of_bits,
170 const unsigned int* sizes, const unsigned int* nums) const;
171 void writeCompressedCoordsFloat(float* ptr, int size, float precision);
172
173 void allocateBuffers(const size_t size);
174
175 void writeHeader(const int natoms, const int step, const float time);
176 void writeBox(const GCoord& box);
177
178 void prepareToAppend();
179
180 private:
181 uint buf1size, buf2size;
182 int* buf1;
183 int* buf2;
184 uint natoms_;
185 double dt_;
186 uint step_;
187 uint steps_per_frame_;
188 uint current_;
189 uint crds_size_;
190 float* crds_;
191 float precision_;
192
194 };
195
196
197};
198
199
200
201#endif
Class for handling groups of Atoms (pAtoms, actually)
Definition AtomicGroup.hpp:108
Base class for writing trajectories.
Definition trajwriter.hpp:53
TrajectoryWriter(const std::string &fname, const bool append=false)
Write a trajectory to a file, optionally appending.
Definition trajwriter.hpp:57
Class for writing Gromacs XTC trajectories.
Definition xtcwriter.hpp:52
static pTrajectoryWriter create(const std::string &s, const bool append=false)
Class factory function.
Definition xtcwriter.hpp:64
uint framesWritten() const
Total frames in output file.
Definition xtcwriter.hpp:163
void stepsPerFrame(const uint s)
Set how many steps pass per frame written.
Definition xtcwriter.hpp:148
void currentStep(const uint s)
Sets the current output step.
Definition xtcwriter.hpp:154
uint stepsPerFrame() const
How many steps per frame written.
Definition xtcwriter.hpp:145
uint currentStep() const
What the current output step is.
Definition xtcwriter.hpp:151
double timePerStep() const
Get the time per step.
Definition xtcwriter.hpp:139
void timePerStep(const double dt)
Set the time per step.
Definition xtcwriter.hpp:142
void writeFrame(const AtomicGroup &model)
Write a frame to the trajectory.
Definition xtcwriter.cpp:730
Definition xdr.hpp:160
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3