The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
GlyCB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file GlyCB.c
5 
6  \version V1.1
7  \date 07.07.14
8  \brief Add C-beta atoms to glycines as pseudo-atoms for use
9  in orientating residues
10  \copyright (c) Dr. Andrew C. R. Martin, UCL, 2006-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  Based on the code from HAddPDB.c adds a C-beta to one or all glycine
40  residues.
41 
42 **************************************************************************
43 
44  Usage:
45  ======
46 
47 **************************************************************************
48 
49  Revision History:
50  =================
51 - 04.01.06 V1.0 Original By: ACRM
52 - 07.07.14 V1.1 Use bl prefix for functions By: CTP
53 
54 *************************************************************************/
55 /* Doxygen
56  -------
57  #GROUP Handling PDB Data
58  #SUBGROUP Modifying the structure
59  #FUNCTION blAddCBtoGly()
60  Adds a CB atom to a glycine. This is used when one needs to orientate
61  a residue in a common frame of reference which makes use of the CB.
62 
63  #FUNCTION blAddCBtoAllGly()
64  Adds a CB atom to all glycines in a PDB linked list. This is used
65  when one needs to orientate a residue in a common frame of reference
66  which makes use of the CB.
67 
68  #FUNCTION blStripGlyCB()
69  Removes all Glycine CB pseudo-atoms added by AddGlyCB()
70 */
71 /************************************************************************/
72 /* Includes
73 */
74 #include <stdio.h>
75 #include <math.h>
76 #include <string.h>
77 #include <stdlib.h>
78 
79 #include "MathType.h"
80 #include "SysDefs.h"
81 #include "pdb.h"
82 #include "macros.h"
83 
84 /************************************************************************/
85 /* Defines and macros
86 */
87 #define BONDLEN 1.524
88 #define ALPHA 54.7
89 
90 /************************************************************************/
91 /* Globals
92 */
93 
94 /************************************************************************/
95 /* Prototypes
96 */
97 
98 /************************************************************************/
99 /*>BOOL blAddCBtoGly(PDB *pdb)
100  ---------------------------
101 *//**
102 
103  \param[in,out] *pdb The PDB linked list for a Glycine
104  \return Success?
105 
106  Adds a CB atom to a glycine. This is used when one needs to orientate
107  a residue in a common frame of reference which makes use of the CB.
108 
109 - 04.01.06 Original By: ACRM
110 - 07.07.14 Use bl prefix for functions By: CTP
111 */
113 {
114  PDB *n = NULL,
115  *ca = NULL,
116  *cb = NULL,
117  *c = NULL,
118  *o = NULL;
119 
120  REAL x1,y1,z1,x2,y2,z2,x3,y3,z3,xnew1,ynew1,znew1,
121  x21,y21,z21,r21,x23,y23,z23,r23,
122  cosa,sina,
123  xa,ya,za,xb,yb,zb,xs,ys,zs,
124  xab,yab,zab,rab,
125  xmin,ymin,zmin,
126  xapb,yapb,zapb,rapb,
127  xplus,yplus,zplus,
128  BondLen = BONDLEN,
129  alpha = ALPHA * PI / 180.0;
130 /* REAL xnew2,ynew2,znew2; */
131 
132  if(strncmp(pdb->resnam, "GLY", 3))
133  return(FALSE);
134 
135  if((n = blFindAtomInRes(pdb, "N"))==NULL)
136  return(FALSE);
137 
138  if((ca = blFindAtomInRes(pdb, "CA"))==NULL)
139  return(FALSE);
140  if((c = blFindAtomInRes(pdb, "C"))==NULL)
141  return(FALSE);
142  if((o = blFindAtomInRes(pdb, "O"))==NULL)
143  return(FALSE);
144 
145  x1 = n->x;
146  y1 = n->y;
147  z1 = n->z;
148 
149  x2 = ca->x;
150  y2 = ca->y;
151  z2 = ca->z;
152 
153  x3 = c->x;
154  y3 = c->y;
155  z3 = c->z;
156 
157  x21=x2-x1;
158  y21=y2-y1;
159  z21=z2-z1;
160  r21=(REAL)sqrt((double)(x21*x21 + y21*y21 + z21*z21));
161 
162  x23=x2-x3;
163  y23=y2-y3;
164  z23=z2-z3;
165  r23=(REAL)sqrt((double)(x23*x23 + y23*y23 + z23*z23));
166 
167  cosa=(REAL)cos((double)alpha);
168  sina=(REAL)sin((double)alpha);
169 
170  xa=x21/r21;
171  ya=y21/r21;
172  za=z21/r21;
173  xb=x23/r23;
174  yb=y23/r23;
175  zb=z23/r23;
176  xab=xa-xb;
177  yab=ya-yb;
178  zab=za-zb;
179  rab=(REAL)sqrt((double)(xab*xab+yab*yab+zab*zab));
180  xmin=xab/rab;
181  ymin=yab/rab;
182  zmin=zab/rab;
183  xapb=xa+xb;
184  yapb=ya+yb;
185  zapb=za+zb;
186  rapb=(REAL)sqrt((double)(xapb*xapb+yapb*yapb+zapb*zapb));
187  xplus=xapb/rapb;
188  yplus=yapb/rapb;
189  zplus=zapb/rapb;
190  xs=yplus*zmin-zplus*ymin;
191  ys=zplus*xmin-xplus*zmin;
192  zs=xplus*ymin-yplus*xmin;
193  xnew1=x2+BondLen*(cosa*xplus-sina*xs);
194  ynew1=y2+BondLen*(cosa*yplus-sina*ys);
195  znew1=z2+BondLen*(cosa*zplus-sina*zs);
196 
197  /* Create a PDB record and initialize it to be the same as the O */
198  if((cb = (PDB *)malloc(sizeof(PDB)))==NULL)
199  {
200  return(FALSE);
201  }
202  blCopyPDB(cb,o);
203  /* Put it into the linked list after the backbone oxygen */
204  cb->next = o->next;
205  o->next = cb;
206  /* Change it to a CB */
207  strcpy(cb->atnam, "CB ");
208  strcpy(cb->atnam_raw, " CB ");
209  /* And set the coordinates */
210  cb->x = xnew1;
211  cb->y = ynew1;
212  cb->z = znew1;
213 
214 /* This is the position of the hydrogen
215  xnew2=x2+BondLen*(cosa*xplus+sina*xs);
216  ynew2=y2+BondLen*(cosa*yplus+sina*ys);
217  znew2=z2+BondLen*(cosa*zplus+sina*zs);
218 */
219 
220  return(TRUE);
221 }
222 
223 
224 /************************************************************************/
225 /*>BOOL blAddCBtoAllGly(PDB *pdb)
226  ------------------------------
227 *//**
228 
229  \param[in,out] *pdb The PDB linked list
230  \return Success?
231 
232  Adds a CB atom to all glycines in a PDB linked list. This is used
233  when one needs to orientate a residue in a common frame of reference
234  which makes use of the CB.
235 
236 - 04.01.06 Original By: ACRM
237 - 07.07.14 Use bl prefix for functions By: CTP
238 */
240 {
241  PDB *p;
242 
243  for(p=pdb; p!=NULL; p=blFindNextResidue(p))
244  {
245  if(!strncmp(p->resnam, "GLY", 3))
246  {
247  if(!blAddCBtoGly(p))
248  return(FALSE);
249  }
250  }
251  return(TRUE);
252 }
253 
254 
255 /************************************************************************/
256 /*>PDB *blStripGlyCB(PDB *pdb)
257  ---------------------------
258 *//**
259 
260  \param[in,out] *pdb The PDB linked list
261  \return The modified linked list
262 
263  Removes all Glycine CB pseudo-atoms added by AddGlyCB()
264  The linked list is modified in-place, but the return value
265  should be used in case the very first item in the linked list
266  is a Gly-CB which will be removed by the code.
267 
268 - 04.01.06 Original By: ACRM
269 - 07.07.14 Use bl prefix for functions By: CTP
270 */
272 {
273  PDB *p,
274  *prev = NULL;
275 
276  for(p=pdb; p!=NULL; )
277  {
278  if(!strncmp(p->resnam, "GLY", 3))
279  {
280  if(!strncmp(p->atnam, "CB ", 4))
281  {
282  if(prev!=NULL)
283  {
284  prev->next = p->next;
285  free(p);
286  p=prev->next;
287  }
288  else
289  {
290  PDB *q;
291  q=p;
292  NEXT(p);
293  free(q);
294  pdb = p;
295  }
296  }
297  else
298  {
299  prev = p;
300  NEXT(p);
301  }
302  }
303  else
304  {
305  prev=p;
306  NEXT(p);
307  }
308  }
309  return(pdb);
310 }
Include file for PDB routines.
short BOOL
Definition: SysDefs.h:64
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
#define PI
Definition: macros.h:215
#define FALSE
Definition: macros.h:223
#define NEXT(x)
Definition: macros.h:249
PDB * blStripGlyCB(PDB *pdb)
Definition: GlyCB.c:271
Useful macros.
char atnam[8]
Definition: pdb.h:316
char resnam[8]
Definition: pdb.h:319
REAL ymin
Definition: plotting.c:146
double REAL
Definition: MathType.h:67
REAL z
Definition: pdb.h:300
REAL xmin
Definition: plotting.c:146
BOOL blAddCBtoAllGly(PDB *pdb)
Definition: GlyCB.c:239
#define TRUE
Definition: macros.h:219
BOOL blAddCBtoGly(PDB *pdb)
Definition: GlyCB.c:112
void blCopyPDB(PDB *out, PDB *in)
Definition: CopyPDB.c:108
System-type variable type definitions.
PDB * blFindNextResidue(PDB *pdb)
PDB * blFindAtomInRes(PDB *pdb, char *atnam_in)
Type definitions for maths.
struct pdb_entry * next
Definition: pdb.h:307
#define ALPHA
Definition: GlyCB.c:88
REAL x
Definition: pdb.h:300
REAL y
Definition: pdb.h:300
#define BONDLEN
Definition: GlyCB.c:87