The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
SelAtPDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file SelAtPDB.c
5 
6  \version V1.11
7  \date 19.04.15
8  \brief Select a subset of atom types from a PDB linked list
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1990-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 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45 \code
46  pdbout = blSelectAtomsPDBAsCopy(pdbin,nsel,sel,natom)
47 \endcode
48 
49  This routine takes a linked list of type PDB and returns a list
50  containing only those atom types specfied in the sel array.
51 
52  \param[in] pdbin Input list
53  \param[in] nsel Number of atom types to keep
54  \param[in] sel List of atom types to keep
55  \param[out] natom Number of atoms kept
56  \return PDB output list
57 
58  To set up the list of atoms to keep, define an array of pointers
59  to char:
60  e.g. char *sel[10]
61 
62  Then define the atoms in the list thus:
63 
64  SELECT(sel[0],"N ");
65  SELECT(sel[1],"CA ");
66  SELECT(sel[2],"C ");
67  SELECT(sel[3],"O ");
68 
69  The SELECT macro returns a character pointer which will be NULL if
70  the allocation it performs fails.
71 
72  N.B. The routines are non-destructive; i.e. the original PDB linked
73  list is intact after the selection process
74 
75 **************************************************************************
76 
77  Revision History:
78  =================
79 - V1.0 01.03.90 Original By: ACRM
80 - V1.1 28.03.90 Modified to match new version of pdb.h
81 - V1.2 24.05.90 Fixed so the variables passed in as sel[] don't
82  *have* to be 4 chars.
83 - V1.3 17.05.93 Modified for book. Returns BOOL.
84 - V1.4 09.07.93 Modified to return PDB pointer. Changed allocation
85  scheme. Changed back to sel[] variables *must* be 4
86  chars.
87 - V1.5 01.11.94 Added HStripPDB()
88 - V1.6 26.07.95 Removed unused variables
89 - V1.7 16.10.96 Added SelectCaPDB()
90 - V1.8 04.02.09 SelectAtomsPDB(): Initialize q for fussy compliers
91 - V1.9 07.07.14 Use bl prefix for functions By: CTP
92 - V1.10 19.08.14 Renamed function to blSelectAtomsPDBAsCopy(). By: CTP
93 - V1.11 19.04.15 Added call to blCopyConect() By: ACRM
94 
95 *************************************************************************/
96 /* Doxygen
97  -------
98  #GROUP Handling PDB Data
99  #SUBGROUP Manipulating the PDB linked list
100  #FUNCTION blSelectAtomsPDBAsCopy()
101  Take a PDB linked list and returns a list containing only those atom
102  types specified in the sel array.
103 */
104 /************************************************************************/
105 /* Includes
106 */
107 #include <string.h>
108 #include <math.h>
109 #include <stdio.h>
110 #include <stdlib.h>
111 
112 #include "SysDefs.h"
113 #include "MathType.h"
114 
115 #include "pdb.h"
116 #include "macros.h"
117 
118 /************************************************************************/
119 /* Defines and macros
120 */
121 
122 /************************************************************************/
123 /* Globals
124 */
125 
126 /************************************************************************/
127 /* Prototypes
128 */
129 
130 /************************************************************************/
131 /*>PDB *blSelectAtomsPDBAsCopy(PDB *pdbin, int nsel, char **sel,
132  int *natom)
133  -------------------------------------------------------------
134 *//**
135 
136  \param[in] *pdbin Input list
137  \param[in] nsel Number of atom types to keep
138  \param[in] **sel List of atom types to keep
139  \param[out] *natom Number of atoms kept
140  \return Output list
141 
142  Take a PDB linked list and returns a list containing only those atom
143  types specified in the sel array.
144 
145  To set up the list of atoms to keep, define an array of pointers
146  to char:
147  e.g. char *sel[10]
148  Then define the atoms in the list thus:
149 
150 
151  SELECT(sel[0],"N ");
152  SELECT(sel[1],"CA ");
153  SELECT(sel[2],"C ");
154  SELECT(sel[3],"O ");
155 
156  Ensure the spaces are used!!
157 
158  N.B. The routine is non-destructive; i.e. the original PDB linked
159  list is intact after the selection process
160 
161 - 01.03.90 Original By: ACRM
162 - 28.03.90 Modified to match new version of pdb.h
163 - 24.05.90 Fixed so the variables passed in as sel[] don't
164  *have* to be 4 chars.
165 - 17.05.93 Modified for book. Returns BOOL.
166 - 09.07.93 Modified to return PDB pointer. Changed allocation
167  scheme. Changed back to sel[] variables *must* be 4
168  chars.
169 - 04.02.09 Initialize q for fussy compliers
170 - 07.07.14 Use bl prefix for functions By: CTP
171 - 19.08.14 Renamed function to blSelectAtomsPDBAsCopy(). By: CTP
172 */
173 PDB *blSelectAtomsPDBAsCopy(PDB *pdbin, int nsel, char **sel, int *natom)
174 {
175  PDB *pdbout = NULL,
176  *p,
177  *q = NULL;
178  int i;
179 
180  *natom = 0;
181 
182  /* Step through the input PDB linked list */
183  for(p=pdbin; p!= NULL; NEXT(p))
184  {
185  /* Step through the selection list */
186  for(i=0; i<nsel; i++)
187  {
188  /* See if there is a match */
189  if(!strncmp(p->atnam,sel[i],4))
190  {
191  /* Alloacte a new entry */
192  if(pdbout==NULL)
193  {
194  INIT(pdbout, PDB);
195  q = pdbout;
196  }
197  else
198  {
199  ALLOCNEXT(q, PDB);
200  }
201 
202  /* If failed, free anything allocated and return */
203  if(q==NULL)
204  {
205  if(pdbout != NULL) FREELIST(pdbout,PDB);
206  *natom = 0;
207  return(NULL);
208  }
209 
210  /* Increment atom count */
211  (*natom)++;
212 
213  /* Copy the record to the output list (sets ->next to NULL) */
214  blCopyPDB(q, p);
215 
216  break;
217  }
218  }
219  }
220 
221  /* Copy CONECT data */
222  if(!blCopyConects(pdbout, pdbin))
223  {
224  FREELIST(pdbout, PDB);
225  *natom = 0;
226  return(NULL);
227  }
228 
229  /* Return pointer to start of output list */
230  return(pdbout);
231 }
232 
#define ALLOCNEXT(x, y)
Definition: macros.h:251
Include file for PDB routines.
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
PDB * blSelectAtomsPDBAsCopy(PDB *pdbin, int nsel, char **sel, int *natom)
Definition: SelAtPDB.c:173
#define NEXT(x)
Definition: macros.h:249
Useful macros.
void blCopyPDB(PDB *out, PDB *in)
Definition: CopyPDB.c:108
BOOL blCopyConects(PDB *out, PDB *in)
Definition: BuildConect.c:574
#define FREELIST(y, z)
Definition: macros.h:264
#define INIT(x, y)
Definition: macros.h:244
System-type variable type definitions.
Type definitions for maths.