TRRFile.h

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // $Id: TRRFile.h,v 1.13 2005/12/23 17:01:45 amoll Exp $
00005 //
00006 
00007 #ifndef BALL_FORMAT_TRRFILE_H
00008 #define BALL_FORMAT_TRRFILE_H
00009 
00010 #ifndef BALL_FORMAT_TRAJECTORYFILE_H
00011 # include <BALL/FORMAT/trajectoryFile.h>
00012 #endif
00013 
00014 namespace BALL
00015 {
00026   class BALL_EXPORT TRRFile
00027     : public TrajectoryFile
00028   {
00029 
00030     public:
00031 
00035 
00042     class BALL_EXPORT TRRHeader
00043     {
00044 
00045       public: 
00046 
00048       Size        MAGIC;
00050       Size        VERSION;
00052       Size        title_string_length;
00054       String      title_string;
00058       Size        ir_size;
00062       Size        e_size;
00063 
00070       Size        bounding_box_data_size;
00071 
00076       Size        vir_size;
00077 
00082       Size        pres_size;
00083 
00087       Size        top_size;
00088 
00092       Size        sym_size;
00093 
00097       Size        position_data_size;
00098 
00103       Size        velocity_data_size;
00104 
00109       Size        force_data_size;
00110 
00113       Size        number_of_atoms;
00114 
00117       Size        timestep_index;
00118 
00122       Size        nre;
00123 
00126       float       timestep_time;
00127 
00131       float       lambda;
00132 
00133       TRRHeader()
00134         
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 
00157     BALL_CREATE(TRRFile)
00158 
00159     
00162 
00164     TRRFile() ;
00165 
00167     TRRFile(const TRRFile& file) throw(Exception::FileNotFound);
00168 
00170     TRRFile(const String& name, File::OpenMode open_mode = std::ios::in) ;
00171 
00173     virtual ~TRRFile() ;
00175 
00179 
00181     const TRRFile& operator = (const TRRFile& file) ;
00182 
00184     virtual void clear() ;
00186 
00190 
00192     bool operator == (const TRRFile& file) const ;
00194 
00196 
00197 
00199     virtual bool init() ;
00200 
00206     virtual bool writeNextHeader(const TRRHeader& header) ;
00207 
00212     virtual bool readNextHeader(TRRHeader& header) ;
00213     
00218     virtual bool append(const SnapShot& snapshot) ;
00219 
00224     virtual bool read(SnapShot& snapshot) ;
00225 
00227     virtual TRRFile& operator >> (SnapShotManager& ssm) ;
00228     
00231     virtual bool flushToDisk(const std::vector<SnapShot>& buffer)
00232       throw(File::CannotWrite);
00234 
00235 
00238 
00240     bool hasVelocities() const ;
00241 
00243     void setVelocityStorage(bool storage) ;
00244 
00246     bool hasForces() const ;
00247 
00249     void setForceStorage(bool storage) ;
00250 
00252     Size getPrecision() const ;
00253 
00255     bool setPrecision(const Size precision) ;
00256 
00258     float getTimestep() const ;
00259 
00261     void setTimestep(float timestep) ;
00262 
00264     Vector3 getBoundingBoxX() const ;
00265 
00267     Vector3 getBoundingBoxY() const ;
00268 
00270     Vector3 getBoundingBoxZ() const ;
00271 
00273     void setBoundingBox(const Vector3& x, const Vector3& y, const Vector3& z) ;
00274 
00276 
00277     protected:
00278 
00279     // the current step's header
00280     TRRHeader header_;
00281     
00282     // the precision of the file in bytes per value
00283     Size precision_;
00284     
00285     // a flag deciding if the file contains velocities
00286     bool has_velocities_;
00287 
00288     // a flag deciding if the file contains forces
00289     bool has_forces_;
00290 
00291     // the index of the current timestep / snapshot
00292     Size timestep_index_;
00293 
00294     // the length of the timestep
00295     float timestep_;
00296 
00297     // three vectors containing the base vectors of the box in
00298     // nanometers
00299     Vector3 box1_, box2_, box3_;
00300 
00301     BinaryFileAdaptor<Size> adapt_size_;
00302     BinaryFileAdaptor<char> adapt_char_;
00303     BinaryFileAdaptor<float> adapt_float_;
00304     BinaryFileAdaptor<double> adapt_double_;
00305   };
00306 } // namespace BALL
00307 
00308 #endif // BALL_FORMAT_TRRFILE_H