00001 // -*- Mode: C++; tab-width: 2; -*- 00002 // vi: set ts=2: 00003 // 00004 // $Id: DCDFile.h,v 1.33.18.1 2007/03/25 21:23:41 oliver Exp $ 00005 // 00006 00007 #ifndef BALL_FORMAT_DCDFILE_H 00008 #define BALL_FORMAT_DCDFILE_H 00009 00010 #ifndef BALL_FORMAT_TRAJECTORYFILE_H 00011 # include <BALL/FORMAT/trajectoryFile.h> 00012 #endif 00013 00014 namespace BALL 00015 { 00035 class BALL_EXPORT DCDFile 00036 : public TrajectoryFile 00037 { 00038 00039 public: 00040 00041 BALL_CREATE(DCDFile) 00042 00043 00046 00048 DCDFile() 00049 ; 00050 00052 DCDFile(const DCDFile& file) 00053 throw(Exception::FileNotFound); 00054 00056 DCDFile(const String& name, File::OpenMode open_mode = std::ios::in) 00057 throw(Exception::FileNotFound); 00058 00060 virtual ~DCDFile() 00061 ; 00062 00064 00067 00069 const DCDFile& operator = (const DCDFile& file) 00070 ; 00071 00073 virtual void clear() 00074 ; 00075 00077 00080 00082 bool operator == (const DCDFile& file) const 00083 ; 00084 00086 bool isSwappingBytes() const 00087 ; 00088 00090 bool hasVelocities() const 00091 ; 00092 00094 00095 00096 00099 virtual bool open(const String& name, File::OpenMode open_mode = std::ios::in) 00100 throw(Exception::FileNotFound); 00101 00104 bool init() 00105 ; 00106 00110 virtual bool readHeader() 00111 ; 00112 00116 virtual bool writeHeader() 00117 ; 00118 00121 virtual bool seekAndWriteHeader() 00122 ; 00123 00124 // ?????: 00125 // should append() also write the header? what is more intuitive? 00131 virtual bool append(const SnapShot& snapshot) 00132 ; 00133 00138 virtual bool read(SnapShot& snapshot) 00139 ; 00140 00143 virtual bool flushToDisk(const std::vector<SnapShot>& buffer) 00144 throw(File::CannotWrite); 00145 00147 00150 00152 void enableVelocityStorage() 00153 ; 00154 00156 void disableVelocityStorage() 00157 ; 00158 00160 00161 protected: 00162 00163 //_ 00164 void writeSize_(const Size& data) 00165 { *this << BinaryFileAdaptor<Size>(data);} 00166 00167 //_ 00168 void writeFloat_(const float& data) 00169 { *this << BinaryFileAdaptor<float>(data);} 00170 00171 //_ 00172 void writeVector_(const vector<Vector3>& v) 00173 ; 00174 00175 //_ 00176 float readFloat_() 00177 ; 00178 00179 //_ 00180 Size readSize_() 00181 ; 00182 00183 //_ 00184 bool readSize_(Size expected_size, const String& what) 00185 ; 00186 00187 //_ 00188 bool readVector_(vector<Vector3>& v) 00189 ; 00190 00191 //_ 00192 Size verbosity_; 00193 00194 // a flag indicating that we have to swap bytes when reading data 00195 bool swap_bytes_; 00196 00197 // a floag indicating that this DCD file contains atom velocities 00198 bool has_velocities_; 00199 00200 //_ 00201 bool charmm_extra_block_A_; 00202 00203 //_ 00204 bool charmm_extra_block_B_; 00205 00206 //_ 00207 String CORD_; 00208 00209 //_ 00210 Size step_number_of_starting_time_; 00211 00212 //_ 00213 Size steps_between_saves_; 00214 00215 //_ 00216 double time_step_length_; 00217 00218 //_ 00219 Size number_of_comments_; 00220 00221 /*_ We had a problem with read(Snapshot), as it 00222 still returned true at the end of file. No idea 00223 why the stream was still good! To fix this, 00224 I added this member to count the current read snapshot. 00225 */ 00226 Position current_snapshot_; 00227 00228 BinaryFileAdaptor<Size> adapt_size_; 00229 BinaryFileAdaptor<float> adapt_float_; 00230 }; 00231 } // namespace BALL 00232 00233 #endif // BALL_FORMAT_DCDFILE_H