Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
RdSecPDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file RdSecPDB.c
5 
6  \version V1.5
7  \date 26.02.15
8  \brief Read secondary structure information from the HELIX, TURN
9  and SHEET records in a PDB file
10 
11  \copyright (c) UCL / Dr. Andrew C. R. Martin 1990-2015
12  \author Dr. Andrew C. R. Martin
13  \par
14  Institute of Structural & Molecular Biology,
15  University College London,
16  Gower Street,
17  London.
18  WC1E 6BT.
19  \par
20  andrew@bioinf.org.uk
21  andrew.martin@ucl.ac.uk
22 
23 **************************************************************************
24 
25  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
26  according to the conditions laid out in the accompanying file
27  COPYING.DOC.
28 
29  The code may be modified as required, but any modifications must be
30  documented so that the person responsible can be identified.
31 
32  The code may not be sold commercially or included as part of a
33  commercial product except as described in the file COPYING.DOC.
34 
35 **************************************************************************
36 
37  Description:
38  ============
39 
40 
41 **************************************************************************
42 
43  Usage:
44  ======
45 
46 \code
47  sec = blReadSecPDB(fp,&nsec)
48 \endcode
49 
50  This routine reads the secondary structure informaton from the
51  header of a .PDB file. It reads from file fp and creates a linked
52  list of type SECSTRUC. The user should include "pdb.h"
53 
54  On return, the variable nsec, or the value returned by the routine
55  should be checked to ensure some secondary structure was returned.
56  The secondary structure is stored together with ranges of residues
57  to which it applies. The form of the structure should be checked
58  in pdb.h
59 
60 
61  Input: fp *FILE Pointer to PDB file
62  Output: nsec *int Number of sec struc regions identified
63  Returns: sec *SECSTRUC Linked list of type SECSTRUC
64 
65 **************************************************************************
66 
67  Revision History:
68  =================
69 - V1.0 22.03.90 Original
70 - V1.1 20.06.90 Would crash if no secondary structure found---fixed.
71 - V1.2 09.07.93 Changed allocation scheme. Returns pointer to SECSTRUC.
72  No need to initialise this before calling
73 - V1.3 18.08.98 Changed SEC to SECSTRUC 'cos of conflict in SunOS
74 - V1.4 07.07.14 Use bl prefix for functions By: CTP
75 - V1.5 26.02.15 Added blReadSecWholePDB() By: ACRM
76 
77 *************************************************************************/
78 /* Doxygen
79  -------
80  #GROUP Handling PDB Data
81  #SUBGROUP File IO
82  #FUNCTION blReadSecPDB()
83  Reads secondary structure information from the header of a PDB file.
84 
85  #FUNCTION blReadSecWholePDB()
86  Reads secondary structure information from the header information
87  stored in a WHOLEPDB structure.
88 */
89 /************************************************************************/
90 /* Includes
91 */
92 #include <stdio.h>
93 #include <string.h>
94 #include <math.h>
95 #include <stdlib.h>
96 
97 #include "SysDefs.h"
98 #include "MathType.h"
99 
100 #include "pdb.h"
101 #include "fsscanf.h"
102 #include "macros.h"
103 
104 /************************************************************************/
105 /* Defines and macros
106 */
107 
108 /************************************************************************/
109 /* Globals
110 */
111 
112 /************************************************************************/
113 /* Prototypes
114 */
115 
116 /************************************************************************/
117 /*>SECSTRUC *blReadSecPDB(FILE *fp, int *nsec)
118  -------------------------------------------
119 *//**
120 
121  \param[in] *fp Pointer to PDB file
122  \param[out] *nsec Number of sec struc regions identified
123  \return Linked list of type SECSTRUC
124 
125  Reads secondary structure information from the header of a PDB file.
126  Returns a pointer to a linked list of type SECSTRUC.
127 
128  On return, the variable nsec, or the value returned by the routine
129  should be checked to ensure some secondary structure was returned.
130  The secondary structure is stored together with ranges of residues
131  to which it applies. The form of the structure should be checked
132  in pdb.h
133 
134 - 22.03.90 Original
135 - 20.06.90 Would crash if no secondary structure found---fixed.
136 - 09.07.93 Changed allocation scheme. Returns pointer to SECSTRUC.
137  No need to initialise this before calling. Uses fsscanf()
138 - 18.08.98 Changed SEC to SECSTRUC 'cos of conflict in SunOS
139 - 07.07.14 Use bl prefix for functions By: CTP
140 */
141 SECSTRUC *blReadSecPDB(FILE *fp, int *nsec)
142 {
143  int class,
144  res1,
145  res2;
146  char buffer[160],
147  chain1[8],
148  chain2[8],
149  insert1[8],
150  insert2[8],
151  type;
152  static char classtab[16] = "HHGGGHGGGH"; /* Class 0 shouldn't occur */
153  SECSTRUC *p,
154  *sec = NULL;
155 
156  *nsec = 0;
157 
158  while(fgets(buffer,159,fp))
159  {
160  /* Use this as a flag for having found some secondary structure */
161  type = '\0';
162 
163  /* Break out of the while loop when we find an ATOM */
164  if(!strncmp(buffer,"ATOM ",6)) break;
165 
166  /* Process SHEET records */
167  if(!strncmp(buffer,"SHEET ",6))
168  {
169  fsscanf(buffer,"%21x%1s%4d%1s%5x%1s%4d%1s",
170  chain1, &res1, insert1,
171  chain2, &res2, insert2);
172 
173  type = 'E';
174  }
175 
176  /* Process HELIX records */
177  if(!strncmp(buffer,"HELIX ",6))
178  {
179  fsscanf(buffer,"%19x%1s%1x%4d%1s%5x%1s%1x%4d%1s%2d",
180  chain1, &res1, insert1,
181  chain2, &res2, insert2,
182  &class);
183 
184  type=classtab[class];
185  }
186 
187  /* Process TURN records */
188  if(!strncmp(buffer,"TURN ",6))
189  {
190  fsscanf(buffer,"%19x%1s%4d%1s%5x%1s%4d%1s",
191  chain1, &res1, insert1,
192  chain2, &res2, insert2);
193 
194  type = 'T';
195  }
196 
197  if(type) /* We've got some secondary structure */
198  {
199  /* Allocate space */
200  if(sec == NULL)
201  {
202  INIT(sec,SECSTRUC);
203  p = sec;
204  }
205  else
206  {
207  ALLOCNEXT(p,SECSTRUC);
208  }
209 
210  /* Check allocation; free list and return if failed */
211  if(p==NULL)
212  {
213  if(sec != NULL) FREELIST(sec,SECSTRUC);
214  *nsec = 0;
215  return(NULL);
216  }
217 
218  /* Copy data into linked list */
219  strcpy(p->chain1, chain1);
220  strcpy(p->chain2, chain2);
221  strcpy(p->insert1,insert1);
222  strcpy(p->insert2,insert2);
223  p->res1 = res1;
224  p->res2 = res2;
225  p->type = type;
226 
227  (*nsec)++;
228  }
229  }
230 
231  /* Return pointer to start of linked list */
232  return(sec);
233 }
234 
235 /************************************************************************/
236 /*>SECSTRUC *blReadSecWholePDB(WHOLEPDB *wpdb, int *nsec)
237  ------------------------------------------------------
238 *//**
239 
240  \param[in] *wpdb WHOLEPDB structure
241  \param[out] *nsec Number of sec struc regions identified
242  \return Linked list of type SECSTRUC
243 
244  Reads secondary structure information from the header of a PDB file
245  stored in a WHOLEPDB structure.
246  Returns a pointer to a linked list of type SECSTRUC.
247 
248  On return, the variable nsec, or the value returned by the routine
249  should be checked to ensure some secondary structure was returned.
250  The secondary structure is stored together with ranges of residues
251  to which it applies. The form of the structure should be checked
252  in pdb.h
253 
254 - 26.02.15 Original based on blReadSecPDB()
255 */
257 {
258  int class,
259  res1,
260  res2;
261  char chain1[8],
262  chain2[8],
263  insert1[8],
264  insert2[8],
265  type;
266  static char classtab[16] = "HHGGGHGGGH"; /* Class 0 shouldn't occur */
267  SECSTRUC *p,
268  *sec = NULL;
269  STRINGLIST *s;
270 
271  *nsec = 0;
272 
273  for(s=wpdb->header; s!=NULL; NEXT(s))
274  {
275  /* Use this as a flag for having found some secondary structure */
276  type = '\0';
277 
278  /* Break out of the while loop when we find an ATOM */
279  if(!strncmp(s->string,"ATOM ",6)) break;
280 
281  /* Process SHEET records */
282  if(!strncmp(s->string,"SHEET ",6))
283  {
284  fsscanf(s->string,"%21x%1s%4d%1s%5x%1s%4d%1s",
285  chain1, &res1, insert1,
286  chain2, &res2, insert2);
287 
288  type = 'E';
289  }
290 
291  /* Process HELIX records */
292  if(!strncmp(s->string,"HELIX ",6))
293  {
294  fsscanf(s->string,"%19x%1s%1x%4d%1s%5x%1s%1x%4d%1s%2d",
295  chain1, &res1, insert1,
296  chain2, &res2, insert2,
297  &class);
298 
299  type=classtab[class];
300  }
301 
302  /* Process TURN records */
303  if(!strncmp(s->string,"TURN ",6))
304  {
305  fsscanf(s->string,"%19x%1s%4d%1s%5x%1s%4d%1s",
306  chain1, &res1, insert1,
307  chain2, &res2, insert2);
308 
309  type = 'T';
310  }
311 
312  if(type) /* We've got some secondary structure */
313  {
314  /* Allocate space */
315  if(sec == NULL)
316  {
317  INIT(sec,SECSTRUC);
318  p = sec;
319  }
320  else
321  {
322  ALLOCNEXT(p,SECSTRUC);
323  }
324 
325  /* Check allocation; free list and return if failed */
326  if(p==NULL)
327  {
328  if(sec != NULL) FREELIST(sec,SECSTRUC);
329  *nsec = 0;
330  return(NULL);
331  }
332 
333  /* Copy data into linked list */
334  strcpy(p->chain1, chain1);
335  strcpy(p->chain2, chain2);
336  strcpy(p->insert1,insert1);
337  strcpy(p->insert2,insert2);
338  p->res1 = res1;
339  p->res2 = res2;
340  p->type = type;
341 
342  (*nsec)++;
343  }
344  }
345 
346  /* Return pointer to start of linked list */
347  return(sec);
348 }
349 
SECSTRUC * blReadSecPDB(FILE *fp, int *nsec)
Definition: RdSecPDB.c:141
#define ALLOCNEXT(x, y)
Definition: macros.h:251
Include file for PDB routines.
#define NULL
Definition: array2.c:99
STRINGLIST * header
Definition: pdb.h:375
Definition: pdb.h:372
#define NEXT(x)
Definition: macros.h:249
char chain2[8]
Definition: pdb.h:365
Useful macros.
char chain1[8]
Definition: pdb.h:363
int fsscanf(char *buffer, char *format,...)
Definition: fsscanf.c:177
char insert1[8]
Definition: pdb.h:364
Include file for fsscanf()
SECSTRUC * blReadSecWholePDB(WHOLEPDB *wpdb, int *nsec)
Definition: RdSecPDB.c:256
#define FREELIST(y, z)
Definition: macros.h:264
char insert2[8]
Definition: pdb.h:366
#define INIT(x, y)
Definition: macros.h:244
System-type variable type definitions.
int res1
Definition: pdb.h:367
Type definitions for maths.
int res2
Definition: pdb.h:368
char * string
Definition: general.h:85
Definition: pdb.h:360
char type
Definition: pdb.h:369