Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
KillPDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file KillPDB.c
5 
6  \version V1.12
7  \date 30.09.17
8  \brief
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1992-2017
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 22.02.94 Original release
50 - V1.1 23.05.94 Added FindNextChainPDB()
51 - V1.2 05.10.94 KillSidechain() uses BOOL rather than int
52 - V1.3 24.07.95 Added TermPDB()
53 - V1.4 25.07.95 Added GetPDBChainLabels()
54 - V1.5 26.09.95 Fixed bug in TermPDB()
55 - V1.6 12.10.95 Added DupePDB(), CopyPDBCoords()
56 - V1.7 23.10.95 Moved FindResidueSpec() to ParseRes.c
57 - V1.8 10.01.96 Added ExtractZonePDB()
58 - V1.9 14.03.96 Added FindAtomInRes()
59 - V1.10 08.10.99 Initialised some variables
60 - V1.11 07.07.14 Use bl prefix for functions By: CTP
61 - V1.12 30.09.17 Added vlDeleteResiduePDB() By: ACRM
62 
63 *************************************************************************/
64 /* Doxygen
65  -------
66  #GROUP Handling PDB Data
67  #SUBGROUP Manipulating the PDB linked list
68  #FUNCTION blKillPDB()
69  Remove an item in the PDB linked list and re-link correctly. Generally
70  better to use blDeleteAtomPDB()
71 
72  #FUNCTION blDeleteAtomPDB()
73  Delete an atom from the linked list re-linking the list and returning
74  the new start of the list (in case the first atom has been deleted)
75 
76  #FUNCTION blDeleteAtomRangePDB()
77  Deletes a range of atoms from the linked list re-linking the list and
78  returning the new start of the list (in case the first atom has been
79  deleted)
80 
81  #FUNCTION blDeleteResiduePDB()
82  Deletes a residue from the linked list re-linking the list. Returns
83  a pointer to the next residue and updates the start of the list if
84  it's the first residue that's been deleted
85 */
86 /************************************************************************/
87 /* Includes
88 */
89 #include <stdlib.h>
90 
91 #include "SysDefs.h"
92 #include "pdb.h"
93 
94 /************************************************************************/
95 /* Defines and macros
96 */
97 
98 /************************************************************************/
99 /* Globals
100 */
101 
102 /************************************************************************/
103 /* Prototypes
104 */
105 
106 
107 /************************************************************************/
108 /*>PDB *blDeleteAtomRangePDB(PDB *pdb, PDB *start, PDB *stop)
109  ----------------------------------------------------------
110 *//**
111  \param[in] *pdb Start of PDB linked list
112  \param[in] *start First atom to delete
113  \param[in] *stop Atom after the one to be deleted
114  \return New start of linked list
115 
116  Deletes a range of atoms from the linked list re-linking the list and
117  returning the new start of the list (in case the first atom has been
118  deleted)
119 
120 - 17.03.15 Original By: ACRM
121 */
122 PDB *blDeleteAtomRangePDB(PDB *pdb, PDB *start, PDB *stop)
123 {
124  PDB *p,
125  *prev = NULL;
126  BOOL found = FALSE;
127 
128  /* Find the atom previous to start */
129  for(p=pdb; p!=NULL; NEXT(p))
130  {
131  if(p==start)
132  {
133  found = TRUE;
134  break;
135  }
136 
137  prev = p;
138  }
139  if(!found)
140  return(pdb);
141 
142  /* Now step from start to stop deleting atoms */
143  for(p=start; p!=stop;)
144  {
145  PDB *next;
146  next=blKillPDB(p, prev);
147  p=next;
148  }
149 
150  if(prev==NULL)
151  return(stop);
152  return(pdb);
153 }
154 
155 
156 /************************************************************************/
157 /*>PDB *blDeleteAtomPDB(PDB *pdb, PDB *atom)
158  -----------------------------------------
159 *//**
160  \param[in] *pdb Start of PDB linked list
161  \param[in] *atom Atom to delete
162  \return New start of PDB linked list
163 
164  Deletes an atom from the PDB linked list. Should be called as
165  pdb=blDeleteAtomPDB(pdb, atom);
166  to allow for the first atom in the linked list being deleted.
167 
168  Returns NULL of all atoms have been deleted. Returns the input
169  pdb linked list unmodified if the atom isn't found.
170 
171 - 17.03.15 Original By: ACRM
172 */
173 PDB *blDeleteAtomPDB(PDB *pdb, PDB *atom)
174 {
175  PDB *p,
176  *next,
177  *prev=NULL;
178 
179  for(p=pdb; p!=NULL; NEXT(p))
180  {
181  if(p==atom)
182  {
183  next = blKillPDB(atom, prev);
184  /* Killed atom from start of linked list */
185  if(prev==NULL)
186  return(next);
187  return(pdb);
188  }
189 
190  prev=p;
191  }
192 
193  return(pdb);
194 }
195 
196 /************************************************************************/
197 /*>PDB *blKillPDB(PDB *pdb, PDB *prev)
198  -----------------------------------
199 *//**
200 
201  \param[in] *pdb Pointer to item in PDB linked list to be removed
202  \param[in] *prev Pointer to previous item in linked list
203  \return Next item in PDB linked list
204 
205  Kill an item in the PDB linked list and re-link correctly. Returns the
206  next item in the list, so will be NULL when the last item in the list
207  is killed.
208 
209 - 12.05.92 Original
210 - 11.03.94 Now handles prev==NULL to delete first item in a list
211 - 07.07.14 Use bl prefix for functions By: CTP
212 - 16.03.15 Checks and removes any CONECT data By: ACRM
213 */
214 PDB *blKillPDB(PDB *pdb, /* Pointer to record to kill */
215  PDB *prev) /* Pointer to previous record */
216 {
217  PDB *next;
218 
219  next = pdb->next;
220 
221  blDeleteAtomConects(pdb);
222 
223  if(prev!=NULL)
224  prev->next = next; /* Relink the list */
225  free(pdb); /* Free the item */
226 
227  return(next);
228 }
229 
230 /************************************************************************/
231 /*>PDB *blDeleteResiduePDB(PDB **pPDB, PDB *res)
232  ---------------------------------------------
233 *//**
234 
235  \param[in,out] *pPDB Pointer to pointer to start of PDB linked list
236  \param[in] *res Pointer to residue to be removed
237  \return Next residue in PDB linked list
238 
239  Remove a residue from the PDB linked list and re-link correctly.
240  Returns the next item in the list, so will be NULL when the last
241  residue has been deleted.
242 
243 - 30.09.17 Original
244 */
246 {
247  PDB *prevAtom,
248  *nextRes,
249  *p;
250 
251  if(*pPDB == NULL) return(NULL);
252 
253  /* Find the previous atom */
254  if(res == *pPDB)
255  {
256  prevAtom = NULL;
257  }
258  else
259  {
260  for(prevAtom=*pPDB;
261  ((prevAtom != NULL) && (prevAtom->next != res));
262  NEXT(prevAtom));
263  }
264 
265  /* Find the next residue */
266  nextRes = blFindNextResidue(res);
267 
268  /* Link the previous atom to the next residue */
269  if(prevAtom == NULL) /* Start of linked list */
270  {
271  *pPDB = nextRes;
272  }
273  else /* Elsewhere in the linked list */
274  {
275  prevAtom->next = nextRes;
276  }
277 
278  for(p=res; p!=nextRes; NEXT(p))
279  {
281  free(p);
282  }
283 
284  return(nextRes);
285 }
286 
PDB * blKillPDB(PDB *pdb, PDB *prev)
Definition: KillPDB.c:214
Include file for PDB routines.
PDB * blDeleteAtomRangePDB(PDB *pdb, PDB *start, PDB *stop)
Definition: KillPDB.c:122
struct _hblist * next
Definition: hbond.h:80
short BOOL
Definition: SysDefs.h:64
#define NULL
Definition: array2.c:99
PDB * blDeleteResiduePDB(PDB **pPDB, PDB *res)
Definition: KillPDB.c:245
Definition: pdb.h:298
#define FALSE
Definition: macros.h:223
#define NEXT(x)
Definition: macros.h:249
PDB * blDeleteAtomPDB(PDB *pdb, PDB *atom)
Definition: KillPDB.c:173
#define TRUE
Definition: macros.h:219
void blDeleteAtomConects(PDB *pdb)
Definition: BuildConect.c:536
System-type variable type definitions.
PDB * blFindNextResidue(PDB *pdb)
struct pdb_entry * next
Definition: pdb.h:307