Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
IndexPDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file IndexPDB.c
5 
6  \version V2.2
7  \date 19.04.15
8  \brief Create an array of pointers into a PDB linked list
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1993-2015
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39  IndexPDB() creates an array of pointers to each PDB record in a linked
40  list. This allows random access to atoms without having to step through
41  the PDB linked list.
42 
43 **************************************************************************
44 
45  Usage:
46  ======
47 
48  pdb.h must be included before using this routine.
49 
50 \code
51  PDB **indx,
52  *pdb;
53  int natom;
54 
55  indx = IndexPDB(pdb, &natom);
56 \endcode
57 
58 **************************************************************************
59 
60  Revision History:
61  =================
62 - V1.0 19.07.90 Original
63 - V1.0a 15.02.91 Corrected comments to match new standard.
64 - V1.1 01.06.92 ANSIed and documented, FPU condition added
65 - V2.0 24.02.94 Completely re-written. Note that the calling format
66  has changed!! NOT BACKWARDLY COMPATIBLE!
67 - V2.1 07.07.14 Use bl prefix for functions By: CTP
68 - V2.2 19.04.15 Added blIndexAtomNumbersPDB() By: ACRM
69 
70 *************************************************************************/
71 /* Doxygen
72  -------
73  #GROUP Handling PDB Data
74  #SUBGROUP Manipulating the PDB linked list
75  #FUNCTION blIndexPDB()
76  Creates an array of pointers to PDB from a linked list. This is used
77  to allow array style access to items in the linked list:
78  e.g. (indx[23])->x will give the x coordinate of the 23rd item
79 
80  # FUNCTION blIndexAtomNumbersPDB()
81  Creates an array of pointers to PDB from a linked list. This is used
82  to allow array style access to items in the linked list by atom
83  number:
84  e.g. (indx[23])->x will give the x coordinate of atom number 23
85 
86 */
87 /************************************************************************/
88 /* Includes
89 */
90 #include <math.h>
91 #include <stdlib.h>
92 
93 #include "MathType.h"
94 #include "SysDefs.h"
95 #include "pdb.h"
96 #include "macros.h"
97 
98 /************************************************************************/
99 /*>PDB **blIndexPDB(PDB *pdb, int *natom)
100  --------------------------------------
101 *//**
102 
103  \param[in] *pdb Pointer to the start of a PDB linked list.
104  \param[out] *natom Number of atoms in the PDB linked list.
105  \return An array of pointers to the PDB records.
106  NULL if unable to allocate memory.
107 
108  Creates an array of pointers to PDB from a linked list. This is used
109  to allow array style access to items in the linked list:
110  e.g. (indx[23])->x will give the x coordinate of the 23rd item
111 
112 - 19.07.90 Original
113 - 01.06.92 ANSIed and documented.
114 - 24.02.94 Re-written. Now allocates and returns the index.
115 - 07.07.14 Use bl prefix for functions By: CTP
116 */
117 PDB **blIndexPDB(PDB *pdb, int *natom)
118 {
119  PDB *p,
120  **indx;
121  int i=0;
122 
123  /* Count the number of entries */
124  for(p=pdb, i=0; p!=NULL; NEXT(p)) i++;
125  *natom = i;
126 
127  /* Allocate memory for the index array */
128  if((indx = (PDB **)malloc((i+1) * sizeof(PDB *)))==NULL)
129  return(NULL);
130 
131 
132  for(p=pdb, i=0; p!=NULL; NEXT(p))
133  indx[i++] = p;
134 
135  indx[i] = NULL;
136 
137  return(indx);
138 }
139 
140 /************************************************************************/
141 /*>PDB **blIndexAtomNumbersPDB(PDB *pdb, int *indexSize)
142  -----------------------------------------------------
143 *//**
144  \param[in] *pdb PDB linked list
145  \param[out] *indexSize Index size
146  \return malloc'd array of PDB pointers indexed
147  by atom number
148 
149  Creates an array of pointers to PDB from a linked list. This is used
150  to allow array style access to items in the linked list by atom
151  number:
152  e.g. (indx[23])->x will give the x coordinate of atom number 23
153 
154 - 19.04.15 Original By: ACRM
155 */
156 PDB **blIndexAtomNumbersPDB(PDB *pdb, int *indexSize)
157 {
158  PDB *p,
159  **index = NULL;
160  int maxAtnum = 0;
161 
162  for(p=pdb; p!=NULL; NEXT(p))
163  {
164  if(p->atnum > maxAtnum)
165  maxAtnum = p->atnum;
166  }
167 
168  *indexSize = maxAtnum + 1;
169 
170  if((index=(PDB **)calloc((*indexSize), sizeof(PDB *)))!=NULL)
171  {
172  for(p=pdb; p!=NULL; NEXT(p))
173  {
174  index[p->atnum] = p;
175  }
176  }
177 
178  return(index);
179 }
180 
181 
PDB ** blIndexPDB(PDB *pdb, int *natom)
Definition: IndexPDB.c:117
Include file for PDB routines.
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
#define NEXT(x)
Definition: macros.h:249
int atnum
Definition: pdb.h:309
Useful macros.
PDB ** blIndexAtomNumbersPDB(PDB *pdb, int *indexSize)
Definition: IndexPDB.c:156
System-type variable type definitions.
Type definitions for maths.