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
00185
00186 public:
00187 PDBAtom( void);
00188 virtual ~PDBAtom( void);
00189 void parse( const char *s);
00190 void sprint( char *s, PDBFormatStyle usestyle = COLUMNS);
00191 int serialnumber( void);
00192 void serialnumber( int newserialnumber);
00193
00194 const char*name( void);
00195 void name( const char *newname);
00196
00197 const char*alternatelocation( void);
00198 void alternatelocation( const char *newalternatelocation);
00199
00200 const char*residuename( void);
00201 void residuename( const char *newresiduename);
00202
00203 const char*chain( void);
00204 void chain( const char *newchain);
00205
00206 int residueseq( void);
00207 void residueseq( int newresidueseq);
00208
00209 const char*insertioncode( void);
00210 void insertioncode( const char *newinsertioncode);
00211
00212 BigReal xcoor( void);
00213 void xcoor( BigReal newxcoor);
00214 BigReal ycoor( void);
00215 void ycoor( BigReal newycoor);
00216 BigReal zcoor( void);
00217 void zcoor( BigReal newzcoor);
00218
00219 const BigReal *coordinates( void);
00220 void coordinates(const BigReal *newcoordinates);
00221
00222 BigReal occupancy( void);
00223 void occupancy( BigReal newoccupancy);
00224
00225 BigReal temperaturefactor( void);
00226 void temperaturefactor( BigReal newtemperaturefactor);
00227
00228 int footnote( void);
00229 void footnote( int newfootnote);
00230
00231
00232
00233 const char*segmentname( void);
00234 void segmentname( const char *newsegmentname);
00235
00236 const char* element( void);
00237 void element( const char *newelement);
00238 };
00239
00240
00241 class PDBAtomRecord : public PDBAtom{
00242 public:
00243 PDBAtomRecord( const char *data ) :
00244 PDBAtom( data, PDBAtom::USE_ATOM) {
00245 }
00246 virtual ~PDBAtomRecord( void) {
00247 }
00248 };
00249
00250 class PDBHetatm : public PDBAtom {
00251 public:
00252 PDBHetatm( const char *data) :
00253 PDBAtom( data, PDBAtom::USE_HETATM) {
00254 }
00255 virtual ~PDBHetatm( void) {
00256 }
00257 };
00258
00259
00260 #ifdef MEM_OPT_VERSION
00261 struct PDBCoreData{
00262 BigReal coor[3];
00263 BigReal myoccupancy;
00264 BigReal tempfactor;
00265
00266
00267
00268 BigReal occupancy() { return myoccupancy; }
00269 BigReal xcoor() { return coor[0]; }
00270 BigReal ycoor() { return coor[1]; }
00271 BigReal zcoor() { return coor[2]; }
00272 BigReal temperaturefactor() { return tempfactor; }
00273
00274 void sprint( char *s, PDBData::PDBFormatStyle usestyle = PDBData::COLUMNS);
00275 };
00276 #endif
00277
00279
00280
00281
00282
00283 PDBData *new_PDBData(const char *data);
00284
00285
00286 #endif
00287