The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
StripWatersPDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file StripWatersPDB.c
5 
6  \version V1.3
7  \date 19.04.15
8  \brief
9 
10  \copyright (c) Dr. Andrew C. R. Martin, UCL, 2008-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.04.08 Original based on StripHPDB() By: ACRM
50 - V1.1 07.07.14 Use bl prefix for functions By: CTP
51 - V1.2 19.08.14 Renamed function blStripWatersPDB() to
52  blStripWatersPDBAsCopy() By: CTP
53 - V1.3 19.04.15 Added call to blCopyConect() By: ACRM
54 
55 *************************************************************************/
56 /* Doxygen
57  -------
58  #GROUP Handling PDB Data
59  #SUBGROUP Modifying the structure
60  #FUNCTION blStripWatersPDBAsCopy()
61  Take a PDB linked list and returns the PDB list minus waters
62 */
63 /************************************************************************/
64 /* Includes
65 */
66 #include <stdlib.h>
67 
68 #include "pdb.h"
69 #include "macros.h"
70 
71 /************************************************************************/
72 /* Defines and macros
73 */
74 
75 /************************************************************************/
76 /* Globals
77 */
78 
79 /************************************************************************/
80 /* Prototypes
81 */
82 
83 
84 /************************************************************************/
85 /*>PDB *blStripWatersPDBAsCopy(PDB *pdbin, int *natom)
86  ---------------------------------------------------
87 *//**
88 
89  \param[in] *pdbin Input list
90  \param[out] *natom Number of atoms kept
91  \return Output list
92 
93  Take a PDB linked list and returns the PDB list minus waters
94 
95 - 30.04.08 Original based on StripHPDB() By: ACRM
96 - 19.08.14 Renamed function to blStripWatersPDBAsCopy() By: CTP
97 - 12.04.15 Added rebuild of CONECT data
98 */
99 PDB *blStripWatersPDBAsCopy(PDB *pdbin, int *natom)
100 {
101  PDB *pdbout = NULL,
102  *p,
103  *q;
104 
105  *natom = 0;
106 
107  /* Step through the input PDB linked list */
108  for(p=pdbin; p!=NULL; NEXT(p))
109  {
110  if(!ISWATER(p))
111  {
112  /* Allocate a new entry */
113  if(pdbout==NULL)
114  {
115  INIT(pdbout, PDB);
116  q = pdbout;
117  }
118  else
119  {
120  ALLOCNEXT(q, PDB);
121  }
122 
123  /* If failed, free anything allocated and return */
124  if(q==NULL)
125  {
126  if(pdbout != NULL) FREELIST(pdbout,PDB);
127  *natom = 0;
128  return(NULL);
129  }
130 
131  /* Increment atom count */
132  (*natom)++;
133 
134  /* Copy the record to the output list (sets ->next to NULL) */
135  blCopyPDB(q, p);
136  }
137  }
138 
139  /* Copy CONECT data to new linked list */
140  if(!blCopyConects(pdbout, pdbin))
141  {
142  FREELIST(pdbout, PDB);
143  *natom = 0;
144  return(NULL);
145  }
146 
147  /* Return pointer to start of output list */
148  return(pdbout);
149 }
#define ALLOCNEXT(x, y)
Definition: macros.h:251
Include file for PDB routines.
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
#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 ISWATER(z)
Definition: pdb.h:487
#define FREELIST(y, z)
Definition: macros.h:264
#define INIT(x, y)
Definition: macros.h:244
PDB * blStripWatersPDBAsCopy(PDB *pdbin, int *natom)