00001
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef _PDBREADER_H_
00016 #define _PDBREADER_H_
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef WIN32
00027 #include <strings.h>
00028 #endif
00029 #include "common.h"
00030 #include <string.h>
00031
00032
00033 class PDBData {
00034 public:
00035
00036
00037
00038
00039
00040
00041
00042 enum PDBType {HEADER, OBSLTE, COMPND, SOURCE, EXPDTA, AUTHOR,
00043 REVDAT, SPRSDE, JRNL, REMARK, SEQRES, FTNOTE, HET, FORMUL,
00044 HELIX, SHEET, TURN, SSBOND, SITE, CRYST1, ORIGX, SCALE,
00045 MTRIX, TVECT, MODEL, ATOM, HETATM, SIGATM, ANISOU, SIGUIJ,
00046 TER, ENDMDL, CONECT, MASTER, END, UNKNOWN};
00047
00048 enum PDBFormatStyle { COLUMNS, FIELDS };
00049
00050
00051
00052 static const char *PDBNames[UNKNOWN+1];
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 private:
00068 PDBType mytype;
00069
00070 #ifdef MEM_OPT_VERSION
00071
00072 public:
00073 #else
00074 protected:
00075 #endif
00076
00077 static void scan( const char *data, int len, int start, int size,
00078 int *ans, int defalt);
00079 static void scan( const char *data, int len, int start, int size,
00080 BigReal *ans, BigReal defalt);
00081 static void scan( const char *data, int len, int start, int size,
00082 char *ans);
00083 static void field( const char *data, int fld, char *result);
00084
00085 static void sprintcol( char *s, int start, int len, const char *val);
00086 static void sprintcol( char *s, int start, int len, int val);
00087 static void sprintcol( char *s, int start, int len, int prec, BigReal val);
00088
00089 public:
00090 PDBData(PDBType newtype) {
00091 mytype = newtype;
00092 }
00093 virtual ~PDBData( void) {
00094 }
00095 PDBType type( void) {
00096 return mytype;
00097 }
00098
00099 virtual void sprint( char *s, PDBFormatStyle usestyle = COLUMNS) {
00100 if (usestyle == COLUMNS)
00101 strcpy(s, "REMARK (undefined remark - this is a bug)");
00102 else
00103 strcpy(s, "REMARK (undefined remark - this is a bug)");
00104 }
00105 };
00106
00108 class PDBUnknown : public PDBData {
00109 private:
00110 char *mystr;
00111 public:
00112 PDBUnknown(const char *data): PDBData(PDBData::UNKNOWN) {
00113 mystr = new char[strlen(data)+1];
00114 if ( mystr == NULL )
00115 {
00116 NAMD_die("memory allocation failed in PDBUnknown::PDBUnknown");
00117 }
00118 strcpy(mystr, data);
00119 }
00120 virtual ~PDBUnknown( void) {
00121 delete [] mystr;
00122 }
00123 void sprint(char *s, PDBFormatStyle usestyle) {
00124 strcpy(s, mystr);
00125 if (usestyle == PDBData::COLUMNS)
00126 strcpy( s, mystr);
00127 else
00128 strcpy( s, mystr);
00129 }
00130 };
00131
00132
00134 class PDBAtom : public PDBData {
00135 public:
00136
00137
00138 enum Start {STYPE=1,SSERIAL=7, SNAME=13, SALT=17, SRESNAME=18, SCHAIN=22,
00139 SRESSEQ=23, SINSERT=27, SX=31, SY=39, SZ=47,
00140 SOCC=55, STEMPF=61, SFOOT=68, SSEGNAME=73, SELEMENT=77};
00141
00142
00143
00144
00145
00146
00147 enum Length {LTYPE=6, LSERIAL=5, LNAME=4, LALT=1, LRESNAME=4, LCHAIN=1,
00148 LRESSEQ=4, LINSERT=1, LCOOR=8,
00149 LCOORPREC=3, LOCC=6, LOCCPREC=2, LTEMPF=6,
00150 LTEMPFPREC=2, LFOOT=3, LSEGNAME=4, LELEMENT=2};
00151
00152 public:
00153 static const int default_serial;
00154 static const int default_residueseq;
00155 static const BigReal default_coor;
00156 static const BigReal default_occupancy;
00157 static const BigReal default_temperaturefactor;
00158 static const int no_footnote;
00159
00160 private:
00161 int myserialnumber;
00162 char myname[LNAME+1];
00163 char myalternatelocation[LALT+1];
00164 char myresiduename[LNAME+1];
00165 char mychain[LCHAIN+1];
00166 int myresidueseq;
00167 char myinsertioncode[LINSERT+1];
00168 BigReal mycoor[3];
00169 BigReal myoccupancy;
00170 BigReal mytemperaturefactor;
00171 int myfootnote;
00172 char mysegmentname[LSEGNAME+1];
00173 char myelement[LELEMENT+1];
00174
00175 void parse_field_data( const char *data);
00176 void parse_column_data( const char *data);
00177 void sprint_columns( char *outstr);
00178 void sprint_fields( char *outstr);
00179
00180 protected:
00181 enum PDBPossibleAtoms {USE_ATOM = ATOM, USE_HETATM = HETATM};
00182 PDBAtom( const char *data,
00183 PDBPossibleAtoms whichatom);
00184 PDBAtom( void);
00185
00186 public:
00187 virtual ~PDBAtom( void);
00188 void parse( const char *s);
00189 void sprint( char *s, PDBFormatStyle usestyle = COLUMNS);
00190 int serialnumber( void);
00191 void serialnumber( int newserialnumber);
00192
00193 const char*name( void);
00194 void name( const char *newname);
00195
00196 const char*alternatelocation( void);
00197 void alternatelocation( const char *newalternatelocation);
00198
00199 const char*residuename( void);
00200 void residuename( const char *newresiduename);
00201
00202 const char*chain( void);
00203 void chain( const char *newchain);
00204
00205 int residueseq( void);
00206 void residueseq( int newresidueseq);
00207
00208 const char*insertioncode( void);
00209 void insertioncode( const char *newinsertioncode);
00210
00211 BigReal xcoor( void);
00212 void xcoor( BigReal newxcoor);
00213 BigReal ycoor( void);
00214 void ycoor( BigReal newycoor);
00215 BigReal zcoor( void);
00216 void zcoor( BigReal newzcoor);
00217
00218 const BigReal *coordinates( void);
00219 void coordinates(const BigReal *newcoordinates);
00220
00221 BigReal occupancy( void);
00222 void occupancy( BigReal newoccupancy);
00223
00224 BigReal temperaturefactor( void);
00225 void temperaturefactor( BigReal newtemperaturefactor);
00226
00227 int footnote( void);
00228 void footnote( int newfootnote);
00229
00230
00231
00232 const char*segmentname( void);
00233 void segmentname( const char *newsegmentname);
00234
00235 const char* element( void);
00236 void element( const char *newelement);
00237 };
00238
00239
00240 class PDBAtomRecord : public PDBAtom{
00241 public:
00242 PDBAtomRecord( const char *data ) :
00243 PDBAtom( data, PDBAtom::USE_ATOM) {
00244 }
00245 virtual ~PDBAtomRecord( void) {
00246 }
00247 };
00248
00249 class PDBHetatm : public PDBAtom {
00250 public:
00251 PDBHetatm( const char *data) :
00252 PDBAtom( data, PDBAtom::USE_HETATM) {
00253 }
00254 virtual ~PDBHetatm( void) {
00255 }
00256 };
00257
00258
00259 #ifdef MEM_OPT_VERSION
00260 struct PDBCoreData{
00261 BigReal coor[3];
00262 BigReal myoccupancy;
00263 BigReal tempfactor;
00264
00265
00266
00267 BigReal occupancy() { return myoccupancy; }
00268 BigReal xcoor() { return coor[0]; }
00269 BigReal ycoor() { return coor[1]; }
00270 BigReal zcoor() { return coor[2]; }
00271 BigReal temperaturefactor() { return tempfactor; }
00272
00273 void sprint( char *s, PDBData::PDBFormatStyle usestyle = PDBData::COLUMNS);
00274 };
00275 #endif
00276
00278
00279
00280
00281
00282 PDBData *new_PDBData(const char *data);
00283
00284
00285 #endif
00286