Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
BuildAtomNeighbourPDBList.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file BuildAtomNeighbourPDBList.c
5 
6  \version V1.4
7  \date 19.08.14
8  \brief Build a new PDB linked list containing atos within a given
9  distance of a specified residue
10 
11  \copyright (c) Dr. Andrew C. R. Martin, UCL, 1996-2014
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 **************************************************************************
47 
48  Revision History:
49  =================
50 - V1.0 27.08.96 Original By: ACRM
51 - V1.1 17.11.05 Fixed freed memory access
52 - V1.2 08.11.07 Moved out of mutmodel. Added check on memory allocation.
53  Uses occ rather than BVal as a flag
54 - V1.3 07.07.14 Use bl prefix for functions By: CTP
55 - V1.4 19.08.14 Renamed blBuildAtomNeighbourPDBListAsCopy to
56  blBuildAtomNeighbourPDBListAsCopy() By: CTP
57 
58 *************************************************************************/
59 /* Doxygen
60  -------
61  #GROUP Handling PDB Data
62  #SUBGROUP Manipulating the PDB linked list
63  #FUNCTION blBuildAtomNeighbourPDBListAsCopy()
64  Builds a PDB linked list of atoms neighbouring those in a specified
65  residue.
66 */
67 /************************************************************************/
68 /* Includes
69 */
70 #include <stdlib.h>
71 #include "pdb.h"
72 #include "macros.h"
73 
74 /************************************************************************/
75 /* Defines and macros
76 */
77 
78 /************************************************************************/
79 /* Globals
80 */
81 
82 /************************************************************************/
83 /* Prototypes
84 */
85 
86 /************************************************************************/
87 /*>PDB *blBuildAtomNeighbourPDBListAsCopy(PDB *pdb, PDB *pRes,
88  REAL NeighbDist)
89  -----------------------------------------------------------
90 *//**
91 
92  \param[in] *pdb PDB linked list of whole structure
93  \param[in] *pRes Pointer to start of residue of interest (may
94  be in a separate linked list providing it's
95  in the same coordinate frame)
96  \param[in] NeighbDist Cutoff neighbour distance
97  \return PDB linked list of atoms within cutoff
98  distance of the residue of interest.
99  (NULL if allocations failed)
100 
101  Builds a PDB linked list of atoms neighbouring those in a specified
102  residue. The input list is unmodified.
103 
104 - 27.08.96 Original By: ACRM
105 - 17.11.05 Fixed freed memory access
106 - 08.11.07 Moved out of mutmodel. Added check on memory allocation.
107  Uses occ rather than BVal as a flag
108  MOVED FROM MUTMODEL
109 - 07.07.14 Use bl prefix for functions By: CTP
110 - 19.08.14 Renamed function to blBuildAtomNeighbourPDBListAsCopy()
111  By: CTP
112 */
114  REAL NeighbDist)
115 {
116  PDB *pdbN = NULL,
117  *prev = NULL,
118  *p, *q,
119  *pNext = NULL;
120  REAL DCutSq = NeighbDist * NeighbDist;
121 
122  /* First, simply duplicate the PDB linked list */
123  if(!(pdbN = blDupePDB(pdb)))
124  return(NULL);
125 
126  /* We'll use the Occ column as a flag */
127  for(p=pdbN; p!=NULL; NEXT(p))
128  p->occ = 0.0;
129 
130  /* Find the atom after the residue in which we are interested */
131  pNext = blFindNextResidue(pRes);
132 
133  /* Look at each atom in our residue in turn flagging atoms in the
134  duplicate list which are in range
135  */
136  for(p=pRes; p!=pNext; NEXT(p))
137  {
138  for(q=pdbN; q!=NULL; NEXT(q))
139  {
140  if(DISTSQ(p,q) <= DCutSq)
141  q->occ = (REAL)1.0;
142  }
143  }
144 
145  /* Now run through the linked list removing any items which do not
146  have the Occ flag set
147  */
148  for(p=pdbN, prev=NULL; p!=NULL;)
149  {
150  if(p->occ < (REAL)0.5)
151  {
152  if(prev==NULL)
153  {
154  pdbN = p->next;
155  free(p);
156  p=pdbN;
157  continue;
158  }
159  else
160  {
161  prev->next = p->next;
162  free(p);
163  p=prev->next; /* 17.11.05 Fixed from p->next */
164  continue;
165  }
166  }
167  prev = p;
168  NEXT(p);
169  }
170 
171  /* Return the reduced list */
172  return(pdbN);
173 }
174 
175 
Include file for PDB routines.
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
#define NEXT(x)
Definition: macros.h:249
PDB * blDupePDB(PDB *in)
Definition: DupePDB.c:113
Useful macros.
double REAL
Definition: MathType.h:67
PDB * blFindNextResidue(PDB *pdb)
REAL occ
Definition: pdb.h:300
struct pdb_entry * next
Definition: pdb.h:307
#define DISTSQ(a, b)
Definition: macros.h:228
PDB * blBuildAtomNeighbourPDBListAsCopy(PDB *pdb, PDB *pRes, REAL NeighbDist)