NAMD
PDBData.C
Go to the documentation of this file.
1 
7 /*
8  The code to implement the various PDBData classes. These are:
9  PDBData (base class), PDBUnknown (for unimplemented records),
10  and PDBAtom, PDBAtomRecord, and PDBHetAtm, for the various types
11  of atom records.
12 */
13 
14 // Here are the routines to manupulate a PDB ATOM record
15 // It can be created by hand or with a string in the PDB format
16 
17 #include <stdio.h> // sprintf and sscanf
18 #ifndef WIN32
19 #include <strings.h> // strncpy
20 #endif
21 #include <stdlib.h> // atoi and atof
22 #include "InfoStream.h"
23 #include "PDBData.h"
24 
25 // Define some constants for the class
26 const int PDBAtom::default_serial = -1;
27 const int PDBAtom::default_residueseq = -1;
28 const BigReal PDBAtom::default_coor = 9999.000;
31 const int PDBAtom::no_footnote = 0;
32 
33 // write down the names so I won't have to do so again
34 const char *PDBData::PDBNames[PDBData::UNKNOWN+1] = {
35  "HEADER", "OBSLTE", "COMPND",
36  "SOURCE", "EXPDTA", "AUTHOR", "REVDAT", "SPRSDE", "JRNL",
37  "REMARK", "SEQRES", "FTNOTE", "HET", "FORMUL", "HELIX",
38  "SHEET", "TURN", "SSBOND", "SITE", "CRYST1", "ORIGX",
39  "SCALE", "MTRIX", "TVECT", "MODEL", "ATOM", "HETATM",
40  "SIGATM", "ANISOU", "SIGUIJ", "TER", "ENDMDL", "CONECT",
41  "MASTER", "END", "UNKNOWN"};
42 
43 // Parse the input, a char *, for an integer.
44 // The input string is "data" and is of length 'length'.
45 // The integer starts at position "start" (ASSUMES 1st character
46 // is at location 1 !*!*!) and is at most "size" characters long.
47 // If the string is not long enough, return the default integer value.
48 //Example: scan("test 12345", 10, 5, 2, &tempint, 99);
49 // would set tempint to 12.
50 //NOTE: a blank string (" ") will return the value 0. If
51 // there is more than one integer in the string, it will return
52 // the first one seen and not complain.
53 void PDBData::scan( const char *data, int length, int start, int size,
54  int *ans, int defalt)
55 {
56  char tempbuffer[200]; // temp. string buffer
57  if (length < start) { // check if the string is long enough
58  *ans = defalt; // return the default
59  return;
60  }
61  if (size>199) // make sure I won't overflow my array
62  size=199;
63  strncpy(tempbuffer, data + start-1, size); // convert the string to an int
64  tempbuffer[size]= 0;
65  int flg=0;
66  for (int i=strlen(tempbuffer)-1; i>=0; i--) { // see if this is a blank string
67  if (tempbuffer[i]>' ') {
68  flg = 1;
69  break;
70  }
71  }
72  if (flg != 1) { // then it was a blank string
73  *ans = defalt;
74  } else {
75  *ans = atoi(tempbuffer);
76  }
77 }
78 
79 // Parse the input for a string; as above, but there is no default string.
80 // I assume that "*ans" has at least 'size+1' characters.
81 void PDBData::scan( const char *data, int length, int start, int size, char *ans)
82 {
83  if (length < start) { // check if the string is long enough
84  ans[0] = 0;
85  return;
86  }
87  strncpy(ans, data + start - 1, size);
88  ans[size]=0;
89  // fix up leading and trailing spaces
90  int i,j;
91  for (i=0,j=0; ans[i]; i++) // all this does is strip out _all_ the
92  if (ans[i]!=' ' && ans[i]!='\t') // spaces -- this is important because I
93  ans[j++]=ans[i]; // check that a string is empty by looking to see if
94  ans[j]=0; // [0] == 0 instead of checking to see if all the elements are spaces
95 }
96 // Parse the input for a BigReal
97 void PDBData::scan( const char *data, int length, int start, int size,
98  BigReal *ans, BigReal defalt)
99 {
100  char tempbuffer[200];
101  if (length < start) { // check if the string is long enough
102  *ans = defalt; // return the default
103  return;
104  }
105  if (size>199) // make sure I won't overflow my array
106  size=199;
107  strncpy(tempbuffer, data + start - 1, size);// convert the string to a BigReal
108  tempbuffer[size]= 0;
109  int flg=0;
110  for (int i=strlen(tempbuffer)-1; i>=0; i--) { // see if this is a blank string
111  if (tempbuffer[i]>' ') {
112  flg = 1;
113  break;
114  }
115  }
116  if (flg != 1) { // then it was a blank string
117  *ans = defalt;
118  } else {
119  *ans = atof(tempbuffer); // WARNING : ASSUMES BigReal <= double!!!
120  }
121 }
122 
124 // Parse the input data looking for field number 'N'
125 // where a field is defined as a collection of
126 // non-whitespace (ws == {space, tab}) characters
127 // and each field is seperated by one or more whitespace characters
128 // The result is either
129 // 1) field 'N' if it exists
130 // 2) some string starting with '#' if it does not
131 // Note: this means that you can use # to mark fields which don't exist
132 // Also note that this ASSUMES the first field is field 1 !*!*!*
133 void PDBData::field(const char *data, int fld, char *result)
134 {
135  int i;
136 
137  Bool onword = FALSE;
138  if (fld<=0) { // ask a stupid question, get a stupid answer
139  result[0]='#';
140  result[1]=0;
141  return;
142  }
143  for (i=0; data[i]; i++)
144  if (!onword && data[i] != ' ' && data[i] != '\t') { // if I found a field
145  onword = TRUE; // mark that I'm on it
146  if (--fld <= 0) // am I done?
147  break;
148  } else {
149  if (onword && (data[i] == ' ' || data[i] == '\t')) { // left a field
150  onword = FALSE; // mark that I left
151  }
152  }
153  if (fld>0) { // oh no, didn't find the field!
154  result[0] = '#';
155  result[1] = 0;
156  return;
157  }
158 
159  int cpy=0; // copy the field to the output
160  while (data[i] != ' ' && data[i] != '\t' && data[i])
161  result[cpy++] = data[i++];
162  result[cpy] = 0; // terminate and I'm done
163 }
164 
165 
167 // Note that this ASSUMES the first character is column 1 !*!*!*
168 // print an integer
169 void PDBData::sprintcol( char *s, int start, int len, int val)
170 {
171  char temps[100];
172  sprintf(temps, "%*d", len, val); // convert the int to a string
173  sprintcol( s, start, len, temps); // copy to the output string
174 }
175 // print a BigReal
176 void PDBData::sprintcol( char *s, int start, int len, int prec, BigReal val)
177 {
178  char temps[100];
179  sprintf(temps, "%*.*f", len, prec, val);
180  sprintcol( s, start, len, temps); // copy to the output string
181 }
182 // print a string
183 void PDBData::sprintcol( char *s, int start, int len, const char *val)
184 {
185  s+=start-1;
186  while (len-- >0 && *val) // copy string up to end of string or len
187  *s++ = *val++;
188 }
189 
190 /*********************************************************/
191 // base class for both PDB ATOM and HETATM //
192 /*********************************************************/
193 void PDBAtom::parse(const char *data)
194 {
195  char tempstr[100];
196  field(data, 1, tempstr); // get info about field #1 (the first one)
197  if (tempstr[0] == '#') {
198  parse_field_data(data);
199  } else {
200  parse_column_data(data);
201  }
202 }
203 PDBAtom::PDBAtom( const char *data, PDBPossibleAtoms atomclass)
204  : PDBData( atomclass==USE_HETATM ? PDBData::HETATM : PDBData::ATOM)
205 {
206  parse(data);
207 };
208 
209 // This constructor does nothing except default the record
211 {
213  name("");
214  alternatelocation("");
215  residuename("");
216  chain("");
218  insertioncode("");
225  segmentname("");
226  element("");
227 }
228 
229 
231 }
232 
233 
234 // Create an atom or hetatm record given that it is column based data
235 void PDBAtom::parse_column_data( const char *data)
236 {
237  int len = strlen(data); // to check that there is info
238  char tempstr[100];
239  int tempint;
240  BigReal tempBigReal;
241 
242  // set the serial number
243  scan(data, len, SSERIAL, LSERIAL, &tempint, default_serial);
244  serialnumber( tempint );
245 
246  // set the name
247  scan(data, len, SNAME, LNAME, tempstr);
248  name( tempstr);
249 
250  // set the alternate location
251  scan(data, len, SALT, LALT, tempstr);
252  alternatelocation( tempstr);
253 
254  // set the residue name
255  scan(data, len, SRESNAME, LRESNAME, tempstr);
256  residuename( tempstr);
257 
258  // set the chain
259  scan(data, len, SCHAIN, LCHAIN, tempstr);
260  chain( tempstr);
261 
262  // set the residue sequence
263  {
264  // If there are more than 9999 residues, X-Plor uses A000, A001,
265  // ..., A999, B000. Since we try to be X-Plor compatible,
266  // we doo the following
267  char s[10];
268  scan(data, len, SRESSEQ, LRESSEQ, s);
269  if (s[0] < '0' || s[0] > '9') {
270  static int elvis_count = 0;
271  int num = (s[0] - 'A') * 1000 + 10000;
272  num += atoi(s+1);
273  if (s[0] < 'A' || s[0] > 'Z') {
274  if (elvis_count == 0) {
275  iout << iWARN << "Man, tiny Elvis, that number is huge!\n"
276  << iWARN << "We don't know how X-Plor represents over Z999 residues\n"
277  << iWARN << "And you just tried " << s << " - so we'll fake it as " << num << "\n"
278  << iWARN << "This is reversible, but only inside this program.\n" << endi;
279  elvis_count = 1;
280  }
281  } else {
282  elvis_count = 0;
283  }
284  residueseq( num);
285  } else {
286  residueseq(atoi(s));
287  }
288  // This used to be simply
289 // scan(data, len, SRESSEQ, LRESSEQ, &tempint, default_residueseq);
290 // residueseq( tempint);
291  }
292 
293  // set the insertion code
294  scan(data, len, SINSERT, LINSERT, tempstr);
295  insertioncode( tempstr);
296 
297  // set the X, Y, and Z coordinates
298  scan(data, len, SX, LCOOR, &tempBigReal, default_coor);
299  xcoor( tempBigReal);
300  scan(data, len, SY, LCOOR, &tempBigReal, default_coor);
301  ycoor( tempBigReal);
302  scan(data, len, SZ, LCOOR, &tempBigReal, default_coor);
303  zcoor( tempBigReal);
304 
305  // set the occupancy
306  scan(data, len, SOCC, LOCC, &tempBigReal, default_occupancy);
307  occupancy( tempBigReal);
308 
309  // set the temperature factor
310  scan(data, len, STEMPF, LTEMPF, &tempBigReal, default_temperaturefactor);
311  temperaturefactor( tempBigReal);
312 
313  // set the footnote
314  scan(data, len, SFOOT, LFOOT, &tempint, no_footnote);
315  footnote( tempint);
316 
317  // this is for XPLOR style PDBs which have a segment name
318  scan(data, len, SSEGNAME, LSEGNAME, tempstr);
319  segmentname( tempstr);
320 
321  scan(data, len, SELEMENT, LELEMENT, tempstr);
322  element( tempstr);
323 }
324 
325 void PDBAtom::parse_field_data( const char *data)
326 {
327  char tempstr[100];
328  // I already know that the first field starts with a '#' and that
329  // the second is either ATOM or HETATM, so I'll start with the third
330  field(data, 3, tempstr);
331  serialnumber( tempstr[0] != '#' ? atoi(tempstr) : default_serial );
332 
333  field(data, 4, tempstr);
334  name( tempstr[0] != '#' ? tempstr : "" );
335 
336  field(data, 5, tempstr);
337  alternatelocation( tempstr[0] != '#' ? tempstr : "" );
338 
339  field(data, 6, tempstr);
340  residuename( tempstr[0] != '#' ? tempstr : "" );
341 
342  field(data, 7, tempstr);
343  chain( tempstr[0] != '#' ? tempstr : "" );
344 
345  field(data, 8, tempstr);
346  residueseq( tempstr[0] != '#' ? atoi(tempstr) : default_residueseq );
347 
348  field(data, 9, tempstr);
349  insertioncode( tempstr[0] != '#' ? tempstr : "" );
350 
351  field(data, 10, tempstr);
352  xcoor( tempstr[0] != '#' ?
353  atof( tempstr) : default_coor); // WARNING: assumes BigReal <= double
354  field(data, 11, tempstr);
355  ycoor( tempstr[0] != '#' ?
356  atof( tempstr) : default_coor); // WARNING: assumes BigReal <= double
357  field(data, 12, tempstr);
358  zcoor( tempstr[0] != '#' ?
359  atof( tempstr) : default_coor); // WARNING: assumes BigReal <= double
360 
361  field(data, 13, tempstr);
362  occupancy( tempstr[0] != '#' ?
363  atof( tempstr) : default_occupancy );// WARNING: assumes BigReal <= double
364 
365  field(data, 14, tempstr);
366  temperaturefactor( tempstr[0] != '#' ?
367  atof( tempstr) : default_temperaturefactor ); // WARNING: ditto
368 
369  field(data, 15, tempstr);
370  footnote( tempstr[0] != '#' ? atoi(tempstr) : no_footnote);
371 
372  field(data, 16, tempstr);
373  segmentname( tempstr[0] != '#' ? tempstr : "");
374 
375  field(data, 17, tempstr);
376  element( tempstr[0] != '#' ? tempstr : "");
377 }
378 
379  // get/ set the serial number
381 { return myserialnumber; }
382 void PDBAtom:: serialnumber( int newserialnumber)
383 { myserialnumber = newserialnumber; }
384 
385  // get/ set the serial number
386 const char* PDBAtom:: name( void)
387 { return myname; }
388 void PDBAtom:: name( const char *newname)
389 { strncpy(myname, newname, LNAME); myname[LNAME]=0; }
390 
391  // get/ set the alternate location
392 const char* PDBAtom:: alternatelocation( void)
393 { return myalternatelocation; }
394 void PDBAtom:: alternatelocation( const char *newalternatelocation)
395 { strncpy(myalternatelocation, newalternatelocation, LALT);
396  myalternatelocation[LALT]=0;}
397 
398  // get/ set the residue name
399 const char* PDBAtom:: residuename( void)
400 { return myresiduename; }
401 void PDBAtom:: residuename( const char *newresiduename)
402 { strncpy(myresiduename, newresiduename, LRESNAME); myresiduename[LRESNAME]=0;}
403 
404  // get/ set the chain indentifier
405 const char* PDBAtom:: chain( void)
406 { return mychain; }
407 void PDBAtom:: chain( const char *newchain)
408 { strncpy(mychain, newchain, LCHAIN); mychain[LCHAIN]=0;}
409 
410  // get/ set the residue sequence number
412 { return myresidueseq; }
413 void PDBAtom:: residueseq( int newresidueseq)
414 { myresidueseq = newresidueseq; }
415 
416  // get/ set the insertion code
417 const char* PDBAtom:: insertioncode( void)
418 { return myinsertioncode; }
419 void PDBAtom:: insertioncode( const char *newinsertioncode)
420 { strncpy(myinsertioncode, newinsertioncode, LINSERT);
421  myinsertioncode[LINSERT]=0;}
422 
423  // get/ set the different coordinates
424  // either 1 by 1 ...
426 { return mycoor[0]; }
427 void PDBAtom:: xcoor( BigReal newxcoor)
428 { mycoor[0] = newxcoor; }
430 { return mycoor[1]; }
431 void PDBAtom:: ycoor( BigReal newycoor)
432 { mycoor[1] = newycoor; }
434 { return mycoor[2]; }
435 void PDBAtom:: zcoor( BigReal newzcoor)
436 { mycoor[2] = newzcoor; }
437  // ...or all three at once
439 { return mycoor; }
440 void PDBAtom:: coordinates(const BigReal *newcoordinates)
441 { for (int i=0; i<3; i++) mycoor[i] = newcoordinates[i]; }
442 
443  // get/ set the occupancy
445 { return myoccupancy ;}
446 void PDBAtom:: occupancy( BigReal newoccupancy)
447 { myoccupancy = newoccupancy; }
448 
449  // get/ set the temperature factor
451 { return mytemperaturefactor; }
452 void PDBAtom:: temperaturefactor( BigReal newtemperaturefactor)
453 { mytemperaturefactor = newtemperaturefactor; }
454 
455  // get/ set the footnote
457 { return myfootnote; }
458 void PDBAtom:: footnote( int newfootnote)
459 { myfootnote = newfootnote; }
460 
461  // get/ set the segment name
462  // this is not part of the PDB format but is used by XPLOR instead of
463  // the chain identifier (see XPLOR 3.1 manual, p 104)
464 const char* PDBAtom:: segmentname( void)
465 { return mysegmentname; }
466 void PDBAtom:: segmentname( const char *newsegmentname)
467 { strncpy(mysegmentname, newsegmentname, LSEGNAME); mysegmentname[LSEGNAME]=0;}
468 
469  // get/ set the element name
470 const char* PDBAtom:: element( void)
471 { return myelement; }
472 void PDBAtom:: element( const char *newelement)
473 { strncpy(myelement, newelement, LELEMENT); myelement[LELEMENT]=0;}
474 
475 
476 // the function to print out an ATOM or HETATM
477 // size or outstr must be >= 80!
478 void PDBAtom::sprint_columns( char *outstr)
479 {
480  int i;
481  for (i=0; i<79; i++) // dump spaces in outstr -- must be length > 80!!
482  outstr[i] = 32;
483  outstr[i] = 0; // and terminate
484 
485  sprintcol(outstr, STYPE, LTYPE, PDBNames[type()] );
486  sprintcol(outstr, SSERIAL, LSERIAL, serialnumber());
487  {
488  // For X-Plor compatability, if the name is 1, 2, or 3
489  // characters, start it in the 2nd column of the field.
490  // 4 letter names use the first column
491  if (strlen(name()) == 4) {
492  sprintcol(outstr, SNAME, LNAME, name());
493  } else {
494  sprintcol(outstr, SNAME+1, LNAME-1, name());
495  }
496  }
497  sprintcol(outstr, SALT, LALT, alternatelocation());
498  sprintcol(outstr, SRESNAME, LRESNAME, residuename());
499  sprintcol(outstr, SCHAIN, LCHAIN, chain());
500  {
501  // Again, I may have to convert from a number > 9999 to
502  // A000 or whatever (see the comments for the residueseq input)
503  if (residueseq() <= 9999) {
504  sprintcol(outstr, SRESSEQ, LRESSEQ, residueseq());
505  } else {
506  int val = residueseq() / 1000 - 10; // integer arithmetic
507  int modulo = residueseq() % 1000;
508  char s[10];
509  sprintf(s, "%c%03d", 'A' + val, modulo);
510  sprintcol(outstr, SRESSEQ, LRESSEQ, s);
511  }
512  // This used to be just ...
513 // sprintcol(outstr, SRESSEQ, LRESSEQ, residueseq());
514  }
515  sprintcol(outstr, SINSERT, LINSERT, insertioncode());
516  sprintcol(outstr, SX, LCOOR, LCOORPREC, xcoor());
517  sprintcol(outstr, SY, LCOOR, LCOORPREC, ycoor());
518  sprintcol(outstr, SZ, LCOOR, LCOORPREC, zcoor());
519  sprintcol(outstr, SOCC, LOCC, LOCCPREC, occupancy());
521  if (footnote() == no_footnote) // special case when no footnote
522  sprintcol(outstr, SFOOT, LFOOT, "");
523  else
524  sprintcol(outstr, SFOOT, LFOOT, footnote() );
525  sprintcol(outstr, SSEGNAME, LSEGNAME, segmentname());
526  // world's lamest right-justify
527  int lelement = strlen(element());
528  lelement = ( lelement > LELEMENT ? LELEMENT : lelement );
529  sprintcol(outstr, SELEMENT+(LELEMENT-lelement), lelement, element());
530 }
531 
533 void PDBAtom::sprint_fields( char *outstr)
534 {
535  char tmpstr[50];
536  sprintf(outstr, "# %s", PDBNames[type()]);
537  if (serialnumber() == default_serial)
538  sprintf(tmpstr, " #");
539  else
540  sprintf(tmpstr, " %i", serialnumber());
541  strcat(outstr, tmpstr);
542  if (name()[0] == 0)
543  sprintf(tmpstr, " #");
544  else
545  sprintf(tmpstr, " %s", name());
546  strcat(outstr, tmpstr);
547  if (alternatelocation()[0] == 0)
548  sprintf(tmpstr, " #");
549  else
550  sprintf(tmpstr, " %s", alternatelocation());
551  strcat(outstr, tmpstr);
552  if (residuename()[0] == 0)
553  sprintf(tmpstr, " #");
554  else
555  sprintf(tmpstr, " %s", residuename());
556  strcat(outstr, tmpstr);
557  if (chain()[0] == 0)
558  sprintf(tmpstr, " #");
559  else
560  sprintf(tmpstr, " %s", chain());
561  strcat(outstr, tmpstr);
563  sprintf(tmpstr, " #");
564  else
565  sprintf(tmpstr, " %d", residueseq());
566  strcat(outstr, tmpstr);
567  if (insertioncode()[0] == 0)
568  sprintf(tmpstr, " #");
569  else
570  sprintf(tmpstr, " %s", insertioncode());
571  strcat(outstr, tmpstr);
572  if (xcoor() == default_coor)
573  sprintf(tmpstr, " #");
574  else
575  sprintf(tmpstr, " %*.*f", LCOOR, LCOORPREC, xcoor());
576  strcat(outstr, tmpstr);
577  if (ycoor() == default_coor)
578  sprintf(tmpstr, " #");
579  else
580  sprintf(tmpstr, " %*.*f", LCOOR, LCOORPREC, ycoor());
581  strcat(outstr, tmpstr);
582  if (zcoor() == default_coor)
583  sprintf(tmpstr, " #");
584  else
585  sprintf(tmpstr, " %*.*f", LCOOR, LCOORPREC, zcoor());
586  strcat(outstr, tmpstr);
587 // if (occupancy() == default_occupancy) // no way to tell if the occ. is the default
588 // sprintf(tmpstr, " #");
589 // else
590  sprintf(tmpstr, " %*.*f", LOCC, LOCCPREC, occupancy());
591  strcat(outstr, tmpstr);
592 // if (temperaturefactor() == default_temperaturefactor) // ditto previous
593 // sprintf(tmpstr, " #");
594 // else
595  sprintf(tmpstr, " %*.*f", LTEMPF, LTEMPFPREC, temperaturefactor());
596  strcat(outstr, tmpstr);
597  if (footnote() == no_footnote) // special case when no footnote
598  sprintf(tmpstr, " #");
599  else
600  sprintf(tmpstr, " %d", footnote() );
601  strcat(outstr, tmpstr);
602  if (segmentname()[0] == 0)
603  sprintf(tmpstr, " #");
604  else
605  sprintf(tmpstr, " %s", segmentname());
606  strcat(outstr, tmpstr);
607  if (element()[0] == 0)
608  sprintf(tmpstr, " #");
609  else
610  sprintf(tmpstr, " %s", element());
611  strcat(outstr, tmpstr);
612 
613 }
614 
615 void PDBAtom::sprint( char *outstr, PDBFormatStyle usestyle)
616 {
617  if (usestyle == PDBData::COLUMNS)
618  sprint_columns( outstr);
619  else
620  sprint_fields( outstr);
621 }
622 
623 //****************** The wrapper for all of the functions ************///
624 PDBData *new_PDBData(const char *data) // nasty
625 {
626  char temps1[160];
627  char temps2[160];
628  char *temps;
629  sscanf(data, "%s %s ", temps1, temps2);
630  if (temps1[0] == '#')
631  temps = temps2;
632  else
633  temps = temps1;
634 
635  // go through the list of possible PDB data types
636  //this _should_ be the same as: for(PDBTypes i=HEADER; i<UNKNOWN; i++)
637  for (int i=0; i< (int)(sizeof(PDBData::PDBNames) /
638  sizeof(PDBData::PDBNames[0])); i++)
639  if (!strcmp(temps, PDBData::PDBNames[i]))
640  switch(i) {
641  case PDBData::ATOM: return new PDBAtomRecord(data);
642  case PDBData::HETATM: return new PDBHetatm(data);
643  default: return new PDBUnknown(data);
644  }
645  // Now, if HETATM is right next to an aton number (like HETATM12345) then the above
646  // test will fail, so I have to special case it:
647  if (!strncmp(temps, PDBData::PDBNames[PDBData::HETATM], sizeof(PDBData::PDBNames[PDBData::HETATM]))) {
648  return new PDBHetatm(data);
649  }
650  // Hmm, looks like it isn't any data type, so I'll fake it
651  return new PDBUnknown(data);
652 }
653 
655 //#define TEST_PDBREADER
656 #ifdef TEST_PDBREADER
657 main()
658 {
659  char tempstr[100];
660  PDBAtomRecord atom("ATOM 6312 CB TALA 3 235I 24.681 54.463 137.827 1.00 51.30 VP3");
661  atom.sprint(tempstr, PDBData::COLUMNS);
662  std::cout << tempstr << '\n';
663  atom.sprint(tempstr, PDBData::FIELDS);
664  std::cout << tempstr << '\n';
665  std::cout << "Serial number : " << atom.serialnumber() << "\n";
666  std::cout << "name : '" << atom.name() << "'\n";
667  std::cout << "alt. location : '" << atom.alternatelocation() << "'\n";
668  std::cout << "residue name : '" << atom.residuename() << "'\n";
669  std::cout << "chain : '" << atom.chain() << "'\n";
670  std::cout << "residue seq : " << atom.residueseq() << "\n";
671  std::cout << "insertion code: '" << atom.insertioncode() << "'\n";
672  std::cout << "X coordinate : " << atom.xcoor() << "\n";
673  std::cout << "Y coordinate : " << atom.ycoor() << "\n";
674  std::cout << "Z coordinate : " << atom.zcoor() << "\n";
675  std::cout << "occupancy : " << atom.occupancy() << "\n";
676  std::cout << "temperature factor: " << atom.temperaturefactor() << "\n";
677  std::cout << "footnote : " << atom.footnote() << "\n";
678  std::cout << "segment name : '" << atom.segmentname() << "'\n";
679  std::cout << "element : '" << atom.element() << "'\n";
680  std::cout << '\n';
681 
682  PDBAtomRecord atom2("# ATOM 6312 CB T ALA 3 235 I 24.681 54.463 137.827 1.00 51.30 # VP3");
683  atom2.sprint(tempstr, PDBData::COLUMNS);
684  std::cout << tempstr << '\n';
685  atom2.sprint(tempstr, PDBData::FIELDS);
686  std::cout << tempstr << '\n';
687  std::cout << "Serial number : " << atom2.serialnumber() << "\n";
688  std::cout << "name : '" << atom2.name() << "'\n";
689  std::cout << "alt. location : '" << atom2.alternatelocation() << "'\n";
690  std::cout << "residue name : '" << atom2.residuename() << "'\n";
691  std::cout << "chain : '" << atom2.chain() << "'\n";
692  std::cout << "residue seq : " << atom2.residueseq() << "\n";
693  std::cout << "insertion code: '" << atom2.insertioncode() << "'\n";
694  std::cout << "X coordinate : " << atom2.xcoor() << "\n";
695  std::cout << "Y coordinate : " << atom2.ycoor() << "\n";
696  std::cout << "Z coordinate : " << atom2.zcoor() << "\n";
697  std::cout << "occupancy : " << atom2.occupancy() << "\n";
698  std::cout << "temperature factor: " << atom2.temperaturefactor() << "\n";
699  std::cout << "footnote : " << atom2.footnote() << "\n";
700  std::cout << "segment name : '" << atom2.segmentname() << "'\n";
701  std::cout << "element : '" << atom2.element() << "'\n";
702  std::cout << '\n';
703 
704 
705  PDBAtomRecord atom3("# ATOM # # Q WER # # # # 123.456 # # # 9 LAST anything?");
706  atom3.sprint(tempstr, PDBData::COLUMNS);
707  std::cout << tempstr << '\n';
708  atom3.sprint(tempstr, PDBData::FIELDS);
709  std::cout << tempstr << '\n';
710  std::cout << "Serial number : " << atom3.serialnumber() << "\n";
711  std::cout << "name : '" << atom3.name() << "'\n";
712  std::cout << "alt. location : '" << atom3.alternatelocation() << "'\n";
713  std::cout << "residue name : '" << atom3.residuename() << "'\n";
714  std::cout << "chain : '" << atom3.chain() << "'\n";
715  std::cout << "residue seq : " << atom3.residueseq() << "\n";
716  std::cout << "insertion code: '" << atom3.insertioncode() << "'\n";
717  std::cout << "X coordinate : " << atom3.xcoor() << "\n";
718  std::cout << "Y coordinate : " << atom3.ycoor() << "\n";
719  std::cout << "Z coordinate : " << atom3.zcoor() << "\n";
720  std::cout << "occupancy : " << atom3.occupancy() << "\n";
721  std::cout << "temperature factor: " << atom3.temperaturefactor() << "\n";
722  std::cout << "footnote : " << atom3.footnote() << "\n";
723  std::cout << "segment name : '" << atom3.segmentname() << "'\n";
724  std::cout << "element : '" << atom3.element() << "'\n";
725  std::cout << '\n';
726 
727 }
728 #endif
729 
static const BigReal default_coor
Definition: PDBData.h:155
static const int no_footnote
Definition: PDBData.h:158
#define ATOM
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
#define FALSE
Definition: common.h:118
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:108
BigReal zcoor(void)
Definition: PDBData.C:433
#define iout
Definition: InfoStream.h:87
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
BigReal ycoor(void)
Definition: PDBData.C:429
int Bool
Definition: common.h:133
int residueseq(void)
Definition: PDBData.C:411
const char * alternatelocation(void)
Definition: PDBData.C:392
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
void parse(const char *s)
Definition: PDBData.C:193
int main(int argc, char *argv[])
Definition: diffbinpdb.c:15
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
infostream & endi(infostream &s)
Definition: InfoStream.C:38
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
#define TRUE
Definition: common.h:119
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