NAMD
PDBData.h
Go to the documentation of this file.
1 
7 /*
8  Read and parse a line of data from a PDB record. There are many
9  different types of PDB records. This version reads only the ATOM and
10  HETATM records and makes all fields accessible via the appropriate
11  member function. In NAMD, this will be called only by the PDB class,
12  which reads PDB files, and a PDB writer class.
13 */
14 
15 #ifndef _PDBREADER_H_
16 #define _PDBREADER_H_
17 
18 // These are added to the global namespace
19 // the class PDBData
20 // the class PDBUnknown, derived from PDBData
21 // the class PDBAtom, derived from PDBData - contains ATOM and HETATM records
22 // the class PDBAtomRecord, derived from PDBAtom - contains only ATOM records
23 // the class PDBHetAtm, derived from PDBAtom - contains only HETATM records
24 // the function new_PDBData, which creates the right pdb class given a string
25 
26 #ifndef WIN32
27 #include <strings.h>
28 #endif
29 #include "common.h"
30 #include <string.h>
31 
32 
33 class PDBData { // at the basic level, a PDB record only knows its type
34  public:
35 
36  // These data types come from the Protein Data Bank format
37  // description located via anon. ftp to pdb.pdb.bnl.gov
38  // in the file /pub/format.desc.ps
39  // In addition, I define an extra type, UNKNOWN. If I can't
40  // figure out what's going on, I store the complete string
41  // and return it when asked.
47 
48  enum PDBFormatStyle { COLUMNS, FIELDS }; // used to specify if the
49 
50 
51 
52  static const char *PDBNames[UNKNOWN+1]; // string descriptors for each field
53 
54  // output should be based on columns (FORTRAN style) or
55  // fields (C/ awk style).
56  // See, there are two different types of formats that this program
57  // understands, one is the basic PDB w/ or w/o the XLPOR extension - these
58  // are the column based versions. The other is my own
59  // field based version - each data element is seperated by a blank
60  // and, if the element is empty, a pound sign ('#') is put in its place.
61  // This type of record is denoted by a '#' in the first non-blank
62  // character (hence, it is the first non-blank character of the first
63  // field. Basically, I'm a unix/ C/ awk/ yacc ... freak, I like field
64  // based data rather than column based data.
65 
66 
67  private:
68  PDBType mytype;
69 
70 #ifdef MEM_OPT_VERSION
71 //for the sake of pruning PDBData
72 public:
73 #else
74  protected:
75 #endif
76  // some parsing routines to get info from a line of text
77  static void scan( const char *data, int len, int start, int size,
78  int *ans, int defalt);
79  static void scan( const char *data, int len, int start, int size,
80  BigReal *ans, BigReal defalt);
81  static void scan( const char *data, int len, int start, int size,
82  char *ans);
83  static void field( const char *data, int fld, char *result);
84  // some routine to print to a specific column and width
85  static void sprintcol( char *s, int start, int len, const char *val);
86  static void sprintcol( char *s, int start, int len, int val);
87  static void sprintcol( char *s, int start, int len, int prec, BigReal val);
88 
89  public:
90  PDBData(PDBType newtype) {
91  mytype = newtype;
92  }
93  virtual ~PDBData( void) {
94  }
95  PDBType type( void) {
96  return mytype;
97  }
98  // I know nothing, so I'll fake it and hope it works
99  virtual void sprint( char *s, PDBFormatStyle usestyle = COLUMNS) {
100  if (usestyle == COLUMNS) // get rid of warning
101  strcpy(s, "REMARK (undefined remark - this is a bug)");
102  else
103  strcpy(s, "REMARK (undefined remark - this is a bug)");
104  }
105 };
106 
108 class PDBUnknown : public PDBData {
109  private:
110  char *mystr;
111  public:
112  PDBUnknown(const char *data): PDBData(PDBData::UNKNOWN) {
113  mystr = new char[strlen(data)+1];
114  if ( mystr == NULL )
115  {
116  NAMD_die("memory allocation failed in PDBUnknown::PDBUnknown");
117  }
118  strcpy(mystr, data);
119  }
120  virtual ~PDBUnknown( void) {
121  delete [] mystr;
122  }
123  void sprint(char *s, PDBFormatStyle usestyle) {
124  strcpy(s, mystr);
125  if (usestyle == PDBData::COLUMNS) // they are the same, but I won't
126  strcpy( s, mystr); // get the stupid warning during
127  else // compilation
128  strcpy( s, mystr);
129  }
130 };
131 
132 
134 class PDBAtom : public PDBData {
135 public:
136  //extract them out from PDBAtom for the sake of pruning PDBData
137  // starting location for each record element
138  enum Start {STYPE=1,SSERIAL=7, SNAME=13, SALT=17, SRESNAME=18, SCHAIN=22,
139  SRESSEQ=23, SINSERT=27, SX=31, SY=39, SZ=47,
140  SOCC=55, STEMPF=61, SFOOT=68, SSEGNAME=73, SELEMENT=77};
141  // length of each element, the PREC is the number of digits
142  // in the output after the decimal
143 // NOTE: The PDB says the length of the residue name is only 3 characters
144 // whereas XPLOR allows 4 character names. We choose 4 for compatability
145 // with both systems (since we never change the length, we you give us is
146 // what we use)
147  enum Length {LTYPE=6, LSERIAL=5, LNAME=4, LALT=1, LRESNAME=4, LCHAIN=1,
151 
152  public:
153  static const int default_serial; // some default values
154  static const int default_residueseq; // these are set in the .C file
155  static const BigReal default_coor;
158  static const int no_footnote;
159 
160  private:
161  int myserialnumber; // atom serial number
162  char myname[LNAME+1]; // atom name
163  char myalternatelocation[LALT+1]; // alternamte location identifier
164  char myresiduename[LNAME+1]; // residue name
165  char mychain[LCHAIN+1]; // chain indentifier
166  int myresidueseq; // residue seq. no.
167  char myinsertioncode[LINSERT+1]; // code for insertions of residues
168  BigReal mycoor[3]; // X, Y, and Z orthogonal A coordinates
169  BigReal myoccupancy; // occupancy
170  BigReal mytemperaturefactor; // temperature factor
171  int myfootnote; // footnote number
172  char mysegmentname[LSEGNAME+1]; // XPLOR-type segment name
173  char myelement[LELEMENT+1]; // element
174 
175  void parse_field_data( const char *data);
176  void parse_column_data( const char *data);
177  void sprint_columns( char *outstr);
178  void sprint_fields( char *outstr);
179 
180  protected:
182  PDBAtom( const char *data,
183  PDBPossibleAtoms whichatom);// parses a line from the PDB data file
184  //PDBAtom( void); // makes a generic atom
185 
186  public:
187  PDBAtom( void); // makes a generic atom
188  virtual ~PDBAtom( void);
189  void parse( const char *s); // reset to new input values
190  void sprint( char *s, PDBFormatStyle usestyle = COLUMNS);// write to string
191  int serialnumber( void);
192  void serialnumber( int newserialnumber);
193 
194  const char*name( void);
195  void name( const char *newname);
196 
197  const char*alternatelocation( void);
198  void alternatelocation( const char *newalternatelocation);
199 
200  const char*residuename( void);
201  void residuename( const char *newresiduename);
202 
203  const char*chain( void);
204  void chain( const char *newchain);
205 
206  int residueseq( void);
207  void residueseq( int newresidueseq);
208 
209  const char*insertioncode( void);
210  void insertioncode( const char *newinsertioncode);
211 
212  BigReal xcoor( void);
213  void xcoor( BigReal newxcoor);
214  BigReal ycoor( void);
215  void ycoor( BigReal newycoor);
216  BigReal zcoor( void);
217  void zcoor( BigReal newzcoor);
218 
219  const BigReal *coordinates( void);
220  void coordinates(const BigReal *newcoordinates);
221 
222  BigReal occupancy( void);
223  void occupancy( BigReal newoccupancy);
224 
225  BigReal temperaturefactor( void);
226  void temperaturefactor( BigReal newtemperaturefactor);
227 
228  int footnote( void);
229  void footnote( int newfootnote);
230 
231  // this is not part of the PDB format but is used by XPLOR instead of
232  // the chain identifier (see XPLOR 3.1 manual, p 104)
233  const char*segmentname( void);
234  void segmentname( const char *newsegmentname);
235 
236  const char* element( void);
237  void element( const char *newelement);
238 };
239 
240 // The two sub-classes of PDB Atom
241 class PDBAtomRecord : public PDBAtom{
242  public:
243  PDBAtomRecord( const char *data ) :
244  PDBAtom( data, PDBAtom::USE_ATOM) {
245  }
246  virtual ~PDBAtomRecord( void) {
247  }
248 };
249 
250 class PDBHetatm : public PDBAtom {
251  public:
252  PDBHetatm( const char *data) :
253  PDBAtom( data, PDBAtom::USE_HETATM) {
254  }
255  virtual ~PDBHetatm( void) {
256  }
257 };
258 
259 
260 #ifdef MEM_OPT_VERSION
261 struct PDBCoreData{
262  BigReal coor[3]; // X, Y, and Z orthogonal A coordinates
263  BigReal myoccupancy; // occupancy
264  BigReal tempfactor; // temperature factor
265 
266  //These functions are added for fewer changes in the src code when
267  //pruning the PDBData
268  BigReal occupancy() { return myoccupancy; }
269  BigReal xcoor() { return coor[0]; }
270  BigReal ycoor() { return coor[1]; }
271  BigReal zcoor() { return coor[2]; }
272  BigReal temperaturefactor() { return tempfactor; }
273 
274  void sprint( char *s, PDBData::PDBFormatStyle usestyle = PDBData::COLUMNS);// write to string
275 };
276 #endif
277 
279 // somehow I need the base class to figure out which derived class
280 // to use to parse. Since I don't know how to do that, I'll
281 // fake it with this. Give it a string and it will create the
282 // correct PDB data type.
283 PDBData *new_PDBData(const char *data); // nasty
284 
285 
286 #endif
287 
static const BigReal default_coor
Definition: PDBData.h:155
static const int no_footnote
Definition: PDBData.h:158
static const BigReal default_temperaturefactor
Definition: PDBData.h:157
static void field(const char *data, int fld, char *result)
Definition: PDBData.C:133
const char * chain(void)
Definition: PDBData.C:405
BigReal temperaturefactor(void)
Definition: PDBData.C:450
const char * insertioncode(void)
Definition: PDBData.C:417
static const char * PDBNames[UNKNOWN+1]
Definition: PDBData.h:52
virtual ~PDBAtomRecord(void)
Definition: PDBData.h:246
PDBType
Definition: PDBData.h:42
PDBAtomRecord(const char *data)
Definition: PDBData.h:243
BigReal zcoor(void)
Definition: PDBData.C:433
PDBHetatm(const char *data)
Definition: PDBData.h:252
PDBData(PDBType newtype)
Definition: PDBData.h:90
const char * residuename(void)
Definition: PDBData.C:399
PDBPossibleAtoms
Definition: PDBData.h:181
static void sprintcol(char *s, int start, int len, const char *val)
Definition: PDBData.C:183
const BigReal * coordinates(void)
Definition: PDBData.C:438
int footnote(void)
Definition: PDBData.C:456
virtual ~PDBHetatm(void)
Definition: PDBData.h:255
BigReal ycoor(void)
Definition: PDBData.C:429
int residueseq(void)
Definition: PDBData.C:411
PDBUnknown(const char *data)
Definition: PDBData.h:112
void sprint(char *s, PDBFormatStyle usestyle)
Definition: PDBData.h:123
const char * alternatelocation(void)
Definition: PDBData.C:392
void NAMD_die(const char *err_msg)
Definition: common.C:83
const char * name(void)
Definition: PDBData.C:386
static const int default_residueseq
Definition: PDBData.h:154
PDBFormatStyle
Definition: PDBData.h:48
BigReal xcoor(void)
Definition: PDBData.C:425
virtual void sprint(char *s, PDBFormatStyle usestyle=COLUMNS)
Definition: PDBData.h:99
void parse(const char *s)
Definition: PDBData.C:193
virtual ~PDBData(void)
Definition: PDBData.h:93
PDBAtom(void)
Definition: PDBData.C:210
BigReal occupancy(void)
Definition: PDBData.C:444
static void scan(const char *data, int len, int start, int size, int *ans, int defalt)
Definition: PDBData.C:53
PDBData * new_PDBData(const char *data)
Definition: PDBData.C:624
const char * element(void)
Definition: PDBData.C:470
int serialnumber(void)
Definition: PDBData.C:380
void sprint(char *s, PDBFormatStyle usestyle=COLUMNS)
Definition: PDBData.C:615
static const int default_serial
Definition: PDBData.h:153
static const BigReal default_occupancy
Definition: PDBData.h:156
double BigReal
Definition: common.h:114
PDBType type(void)
Definition: PDBData.h:95
virtual ~PDBAtom(void)
Definition: PDBData.C:230
const char * segmentname(void)
Definition: PDBData.C:464
virtual ~PDBUnknown(void)
Definition: PDBData.h:120