The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
FindZonePDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file FindZonePDB.c
5 
6  \version V1.6
7  \date 07.05.14
8  \brief Routines for handling zones in PDB linked lists
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1993-2014
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 **************************************************************************
46 
47  Revision History:
48  =================
49 - V1.0 30.09.92 Original
50 - V1.1 16.06.93 Tidied for book. Mode now a char.
51 - V1.2 18.06.96 Added InPDBZone() from QTree program
52 - V1.3 19.09.96 Added InPDBZoneSpec()
53 - V1.5 20.03.14 Added blFindZonePDB() and deprecated InPDBZone() By: CTP
54 - V1.6 07.05.14 Moved FindZonePDB() to deprecated.h By: CTP
55 
56 *************************************************************************/
57 
58 /* Doxygen
59  -------
60  #GROUP Handling PDB Data
61  #SUBGROUP Searching the PDB linked list
62 
63  Finds pointers to the start and end of a zone in a PDB linked list. The
64  end is the atom *after* the specified zone
65 */
66 /************************************************************************/
67 /* Includes
68 */
69 #include "SysDefs.h"
70 #include "MathType.h"
71 
72 #include "pdb.h"
73 #include "macros.h"
74 
75 
76 /************************************************************************/
77 /*>BOOL blFindZonePDB(PDB *pdb, int start, char *startinsert, int stop,
78  char *stopinsert, char *chain, int mode,
79  PDB **pdb_start, PDB **pdb_stop)
80  -------------------------------------------------------------
81 *//**
82 
83  \param[in] *pdb PDB linked list
84  \param[in] start Resnum of start of zone
85  \param[in] *startinsert Insert code for start of zone
86  \param[in] stop Resnum of end of zone
87  \param[in] *stopinsert Insert code for end of zone
88  \param[in] *chain Chain name
89  \param[in] mode ZONE_MODE_RESNUM: Use PDB residue
90  numbers/chain
91  ZONE_MODE_SEQUENTIAL: Use sequential
92  numbering
93  \param[out] **pdb_start Start of zone
94  \param[out] **pdb_stop End of zone
95  \return OK?
96 
97  Finds pointers to the start and end of a zone in a PDB linked list. The
98  end is the atom *after* the specified zone
99 
100 - 20.03.14 Function based on FindZonePDB() but takes string for chain
101  label and insert instead of single char.
102  Function finds end of chain properly if stop set to -999.
103  By: CTP
104 */
106  int start,
107  char *startinsert,
108  int stop,
109  char *stopinsert,
110  char *chain,
111  int mode,
112  PDB **pdb_start,
113  PDB **pdb_stop)
114 {
115  PDB *p;
116  int rescount,
117  resnum;
118  BOOL InStop = FALSE,
119  FoundChain = FALSE;
120  char insert[8];
121 
122  /* To start, we don't know where either are */
123  *pdb_start = NULL;
124  *pdb_stop = NULL;
125 
126  /* If both start and stop are -999, then the whole structure (or a
127  whole chain) is being specified
128  */
129  if((start == (-999)) && (stop == (-999)))
130  {
131  if(CHAINMATCH(chain," ")) /* Whole structure */
132  {
133  *pdb_start = pdb;
134  *pdb_stop = NULL;
135  return(TRUE);
136  }
137  else /* An individual chain */
138  {
139  for(p=pdb; p!=NULL; NEXT(p))
140  {
141  if(CHAINMATCH(p->chain,chain))
142  {
143  if(*pdb_start == NULL)
144  {
145  *pdb_start = p;
146  }
147  }
148  else if(*pdb_start != NULL) /* We've aleady got the start */
149  {
150  *pdb_stop = p;
151  return(TRUE);
152  }
153  }
154  if(*pdb_start==NULL)
155  return(FALSE); /* Chain not found */
156  else
157  return(TRUE);
158  }
159  }
160 
161  /* Handle one end of a zone being set to -999 */
162  if(start == -999) *pdb_start = pdb;
163  if(stop == -999) *pdb_stop = NULL;
164 
165  /* If either end is still undefined */
166  if(*pdb_start == NULL || *pdb_stop == NULL)
167  {
168  /* Search reference structure for start and end of zone */
169  rescount = 1;
170  resnum = pdb->resnum;
171  strcpy(insert,pdb->insert);
172  InStop = FALSE;
173  FoundChain = FALSE;
174 
175  for(p=pdb; p!=NULL; NEXT(p))
176  {
177  if(mode == ZONE_MODE_RESNUM)
178  {
179  if(CHAINMATCH(chain," ") || CHAINMATCH(chain,p->chain))
180  { /* We are in the correct chain */
181  FoundChain = TRUE;
182 
183  /* If start undefined, see if residue matches */
184  if(*pdb_start == NULL)
185  {
186  if((p->resnum == start) &&
187  !strcmp(p->insert,startinsert))
188  *pdb_start = p;
189  }
190 
191  /* If stop undefined, then find the following residue */
192  if(*pdb_stop == NULL)
193  {
194  /* See if we have just moved out of the stop residue.
195  If so, set the stop position and return
196  */
197  if(InStop &&
198  (p->resnum != stop || strcmp(p->insert,stopinsert)))
199  {
200  *pdb_stop = p;
201  return((*pdb_start==NULL)?FALSE:TRUE);
202  }
203 
204  /* Residue matches, so set flag to say we're in the
205  last residue of the zone.
206  */
207  if((p->resnum == stop) &&
208  !strcmp(p->insert,stopinsert))
209  InStop = TRUE;
210  }
211  if(*pdb_start != NULL && *pdb_stop != NULL) /*Found both*/
212  break;
213  }
214  else if(InStop)
215  {
216  /* We will get here if InStop has been set without having
217  found the start of the next residue. This will occur
218  if the last residue of a zone was also the last
219  residue of a chain, since the chain name will now have
220  changed.
221  We just set *pdb_stop to this pointer and return.
222  */
223  *pdb_stop = p;
224  return((*pdb_start==NULL)?FALSE:TRUE);
225  }
226  else if(stop == -999 && FoundChain == TRUE)
227  {
228  /* We get here if stop is set for the end of a chain and
229  a the start of new chain has been found. By: CTP */
230  *pdb_stop = p;
231  return((*pdb_start==NULL)?FALSE:TRUE);
232  }
233  } /* End of ZONE_MODE_RESNUM */
234  else if(mode == ZONE_MODE_SEQUENTIAL)
235  {
236  /* Correct the residue count */
237  if(p->resnum != resnum || strcmp(p->insert,insert))
238  {
239  rescount++;
240  resnum = p->resnum;
241  strcpy(insert,p->insert);
242  }
243 
244  if(*pdb_start == NULL) /* Identify zone start */
245  if(rescount == start) *pdb_start = p;
246  if(*pdb_stop == NULL) /* Identify zone stop */
247  {
248  if(InStop && rescount != stop) *pdb_stop = p;
249 
250  if(rescount == stop) InStop = TRUE;
251  }
252  if(*pdb_start != NULL && *pdb_stop != NULL) /* Found both */
253  break;
254  }
255  else
256  {
257  printf(" Error==> CreateFitAtoms(): Internal confusion!\n");
258  }
259  } /* End of loop through PDB linked list */
260  } /* End of if() one pointer undefined */
261 
262  /* Check start of range has been found and return */
263  return((*pdb_start==NULL)?FALSE:TRUE);
264 }
265 
Include file for PDB routines.
int resnum
Definition: pdb.h:310
short BOOL
Definition: SysDefs.h:64
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
#define FALSE
Definition: macros.h:223
#define NEXT(x)
Definition: macros.h:249
Useful macros.
#define ZONE_MODE_SEQUENTIAL
Definition: pdb.h:582
BOOL blFindZonePDB(PDB *pdb, int start, char *startinsert, int stop, char *stopinsert, char *chain, int mode, PDB **pdb_start, PDB **pdb_stop)
Definition: FindZonePDB.c:105
#define TRUE
Definition: macros.h:219
#define CHAINMATCH(chain1, chain2)
Definition: pdb.h:495
System-type variable type definitions.
Type definitions for maths.
#define ZONE_MODE_RESNUM
Definition: pdb.h:581
char chain[blMAXCHAINLABEL]
Definition: pdb.h:321
char insert[8]
Definition: pdb.h:320