Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
CalcTetraHCoords.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file CalcTetraHCoords.c
5 
6  \version V1.6
7  \date 05.03.15
8  \brief Routines to add N-terminal hydrogens and C-terminal
9  oxygens.
10 
11  \copyright (c) UCL / Dr. Andrew C. R. Martin 1994-2015
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  int CalcTetraHCoords(PDB *nter, COOR *coor)
47 
48  Calculate the coordinates for 3 tetrahedral hydrogens given a pointer
49  to the residue onto which they are to be added. Normally called from
50  AddNTerHs()
51 
52 **************************************************************************
53 
54  Revision History:
55  =================
56 - V1.0 24.08.94 Original By: ACRM
57 - V1.1 05.10.94 Removed unused variables
58 - V1.2 12.11.96 If any of the antecedant coordinates are undefined, set
59  the terminal oxygen to NULL coordinates
60 - V1.3 13.11.96 Also checks for missing CA,C and O1 records
61 - V1.4 20.03.14 Updated error message for CalcTetraHCoords(). By: CTP
62 - V1.5 07.07.14 Use bl prefix for functions By: CTP
63 - V1.6 05.03.15 Replaced blFindEndPDB() with blFindNextResidue()
64 
65 *************************************************************************/
66 /* Doxygen
67  -------
68  #GROUP Handling PDB Data
69  #SUBGROUP Calculations
70  #FUNCTION blCalcTetraHCoords()
71  Calculates coordinates for extra hydrogens.
72 */
73 /************************************************************************/
74 /* Includes
75 */
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <math.h>
79 
80 #include "SysDefs.h"
81 #include "MathType.h"
82 #include "pdb.h"
83 #include "macros.h"
84 
85 /************************************************************************/
86 /* Defines and macros
87 */
88 #define MAXBUFF 160
89 
90 /************************************************************************/
91 /* Globals
92 */
93 
94 /************************************************************************/
95 /* Prototypes
96 */
97 
98 /************************************************************************/
99 /*>int blCalcTetraHCoords(PDB *nter, COOR *coor)
100  ---------------------------------------------
101 *//**
102 
103  \param[in] *nter Pointer to the N-terminus
104  \param[out] *coor Array of hydrogen coordinates
105  \return Number of hydrogens calculated (3)
106  0 if antecedant atoms missing
107 
108  Calculates coordinates for the extra hydrogens.
109 
110 - 23.08.94 Original By: ACRM
111 - 20.03.14 Updated error message. By: CTP
112 - 07.07.14 Use bl prefix for functions By: CTP
113 - 26.08.14 Removed unused r21 By: ACRM
114 - 05.03.15 Replaced blFindEndPDB() with blFindNextResidue()
115 - 20.03.15 No longer prints a message on not finding atoms
116 */
117 int blCalcTetraHCoords(PDB *nter, COOR *coor)
118 {
119  PDB *N = NULL,
120  *CA = NULL,
121  *C = NULL,
122  *p,
123  *end;
124  REAL x21, y21, z21,
125  x32, y32, z32, r32,
126  xh, yh, zh, scalpr,
127  xp, yp, zp,
128  x21p, y21p, z21p, r21p,
129  xv, yv, zv,
130  xs, ys, zs,
131  cosax, cosay, cosaz,
132  cosa, sina,
133  BondLen, sFac;
134 
135  cosa = (REAL)cos((double)(70.6 * PI / 180.0));
136  sina = (REAL)sin((double)(70.6 * PI / 180.0));
137  BondLen = (REAL)1.08;
138  sFac = (REAL)(sqrt((double)3.0) * 0.5);
139 
140  end = blFindNextResidue(nter);
141 
142  /* Search for the antecedant atom pointers */
143  for(p=nter; p!= end; NEXT(p))
144  {
145  if(!strncmp(p->atnam,"N ",4) || !strncmp(p->atnam,"NT ",4))
146  N = p;
147  else if(!strncmp(p->atnam,"CA ",4))
148  CA = p;
149  else if(!strncmp(p->atnam,"C ",4))
150  C = p;
151  }
152 
153  /* Check all were found */
154  if(N==NULL || CA==NULL || C==NULL)
155  {
156 /*
157  fprintf(stderr,"Atom N,CA or C missing from residue: %s %s%d%s\n",
158  p->resnam, p->chain, p->resnum, p->insert);
159 */
160  return(0);
161  }
162 
163  /* Calculate coordinates for the 3 hydrogens */
164  x21 = CA->x - C->x;
165  y21 = CA->y - C->y;
166  z21 = CA->z - C->z;
167 
168  x32 = N->x - CA->x;
169  y32 = N->y - CA->y;
170  z32 = N->z - CA->z;
171  r32 = (REAL)sqrt((double)(x32*x32 + y32*y32 + z32*z32));
172 
173  xh = x32/r32;
174  yh = y32/r32;
175  zh = z32/r32;
176 
177  scalpr = (x21*x32 + y21*y32 + z21*z32)/r32;
178 
179  xp = scalpr*xh;
180  yp = scalpr*yh;
181  zp = scalpr*zh;
182 
183  x21p = x21-xp;
184  y21p = y21-yp;
185  z21p = z21-zp;
186  r21p = (REAL)sqrt((double)(x21p*x21p + y21p*y21p + z21p*z21p));
187 
188  xv = x21p/r21p;
189  yv = y21p/r21p;
190  zv = z21p/r21p;
191 
192  xs = yh*zv - zh*yv;
193  ys = zh*xv - xh*zv;
194  zs = xh*yv - yh*xv;
195 
196  cosax = cosa*xh;
197  cosay = cosa*yh;
198  cosaz = cosa*zh;
199 
200  coor[0].x = N->x + BondLen*(cosax + sina*xv);
201  coor[0].y = N->y + BondLen*(cosay + sina*yv);
202  coor[0].z = N->z + BondLen*(cosaz + sina*zv);
203 
204  coor[1].x = N->x + BondLen*(cosax + sina*(sFac*xs - 0.5*xv));
205  coor[1].y = N->y + BondLen*(cosay + sina*(sFac*ys - 0.5*yv));
206  coor[1].z = N->z + BondLen*(cosaz + sina*(sFac*zs - 0.5*zv));
207 
208  coor[2].x = N->x + BondLen*(cosax + sina*(-sFac*xs - 0.5*xv));
209  coor[2].y = N->y + BondLen*(cosay + sina*(-sFac*ys - 0.5*yv));
210  coor[2].z = N->z + BondLen*(cosaz + sina*(-sFac*zs - 0.5*zv));
211 
212  return(3);
213 }
214 
Include file for PDB routines.
REAL x
Definition: MathType.h:70
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
#define PI
Definition: macros.h:215
#define NEXT(x)
Definition: macros.h:249
Useful macros.
Definition: MathType.h:69
double REAL
Definition: MathType.h:67
REAL z
Definition: pdb.h:300
int blCalcTetraHCoords(PDB *nter, COOR *coor)
System-type variable type definitions.
PDB * blFindNextResidue(PDB *pdb)
Type definitions for maths.
REAL z
Definition: MathType.h:70
REAL y
Definition: MathType.h:70
REAL x
Definition: pdb.h:300
REAL y
Definition: pdb.h:300