00001
00002
00003
00004
00005 #ifndef BALL_FORMAT_TRRFILE_H
00006 #define BALL_FORMAT_TRRFILE_H
00007
00008 #ifndef BALL_FORMAT_TRAJECTORYFILE_H
00009 # include <BALL/FORMAT/trajectoryFile.h>
00010 #endif
00011
00012 #ifndef BALL_SYSTEM_BINARYFILEADAPTOR_H
00013 # include <BALL/SYSTEM/binaryFileAdaptor.h>
00014 #endif
00015
00016 namespace BALL
00017 {
00028 class BALL_EXPORT TRRFile
00029 : public TrajectoryFile
00030 {
00031
00032 public:
00033
00037
00044 class BALL_EXPORT TRRHeader
00045 {
00046 public:
00047
00049 Size MAGIC;
00051 Size VERSION;
00053 Size title_string_length;
00055 String title_string;
00059 Size ir_size;
00063 Size e_size;
00064
00071 Size bounding_box_data_size;
00072
00077 Size vir_size;
00078
00083 Size pres_size;
00084
00088 Size top_size;
00089
00093 Size sym_size;
00094
00098 Size position_data_size;
00099
00104 Size velocity_data_size;
00105
00110 Size force_data_size;
00111
00114 Size number_of_atoms;
00115
00118 Size timestep_index;
00119
00123 Size nre;
00124
00127 float timestep_time;
00128
00132 float lambda;
00133
00134 TRRHeader()
00135 : MAGIC(1993),
00136 VERSION(13),
00137 title_string_length(24),
00138 title_string("Created by BALL::TRRFile"),
00139 ir_size(0),
00140 e_size(0),
00141 vir_size(0),
00142 pres_size(0),
00143 top_size(0),
00144 sym_size(0),
00145 velocity_data_size(0),
00146 force_data_size(0),
00147 timestep_index(0),
00148 nre(0),
00149 timestep_time(0.002),
00150 lambda(0)
00151 {
00152 }
00153 };
00154
00156
00160
00162 TRRFile();
00163
00165 TRRFile(const String& name, File::OpenMode open_mode = std::ios::in);
00166
00168 virtual ~TRRFile();
00170
00174
00176 virtual void clear();
00178
00182
00184 bool operator == (const TRRFile& file) const;
00186
00188
00189
00191 virtual bool init();
00192
00198 virtual bool writeNextHeader(const TRRHeader& header);
00199
00204 virtual bool readNextHeader(TRRHeader& header);
00205
00210 virtual bool append(const SnapShot& snapshot);
00211
00216 virtual bool read(SnapShot& snapshot);
00217
00219 virtual TRRFile& operator >> (SnapShotManager& ssm);
00220
00224 virtual bool flushToDisk(const std::vector<SnapShot>& buffer);
00226
00227
00230
00232 bool hasVelocities() const;
00233
00235 void setVelocityStorage(bool storage);
00236
00238 bool hasForces() const;
00239
00241 void setForceStorage(bool storage);
00242
00244 Size getPrecision() const;
00245
00247 bool setPrecision(const Size precision);
00248
00250 float getTimestep() const;
00251
00253 void setTimestep(float timestep);
00254
00256 Vector3 getBoundingBoxX() const;
00257
00259 Vector3 getBoundingBoxY() const;
00260
00262 Vector3 getBoundingBoxZ() const;
00263
00265 void setBoundingBox(const Vector3& x, const Vector3& y, const Vector3& z);
00266
00268
00269 private:
00270 const TRRFile& operator = (const TRRFile& file);
00271
00272 protected:
00273
00274
00275 TRRHeader header_;
00276
00277
00278 Size precision_;
00279
00280
00281 bool has_velocities_;
00282
00283
00284 bool has_forces_;
00285
00286
00287 Size timestep_index_;
00288
00289
00290 float timestep_;
00291
00292
00293
00294 Vector3 box1_, box2_, box3_;
00295
00296 BinaryFileAdaptor<Size> adapt_size_;
00297 BinaryFileAdaptor<char> adapt_char_;
00298 BinaryFileAdaptor<float> adapt_float_;
00299 BinaryFileAdaptor<double> adapt_double_;
00300 };
00301 }
00302
00303 #endif // BALL_FORMAT_TRRFILE_H