Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
SetChi.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file SetChi.c
5 
6  \version V1.3
7  \date 07.07.14
8  \brief
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin, University of Reading,
11  2002-14
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.1 01.03.94
51 - V1.2 27.02.98 Removed unreachable break from switch()
52 - V1.3 07.07.14 Use bl prefix for functions By: CTP
53 
54 *************************************************************************/
55 /* Doxygen
56  -------
57  #GROUP Handling PDB Data
58  #SUBGROUP Modifying the structure
59  #FUNCTION blSetChi()
60  Sets a sidechain torsion angle in a pdb linked list. The routine
61  assumes standard atom ordering: N,CA,C,O,s/c with standard order in
62  the s/c.
63 */
64 /************************************************************************/
65 /* Includes
66 */
67 #include <stdlib.h>
68 #include <math.h>
69 
70 #include "MathType.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 /************************************************************************/
88 /*>void blSetChi(PDB *pdb, PDB *next, REAL chi, int type)
89  ------------------------------------------------------
90 *//**
91 
92  \param[in,out] *pdb PDB linked list to change
93  \param[in] *next If NULL, move all atoms in the linked list from
94  the last atom in the torsion. Otherwise move
95  atoms up to (but not including) next. Normally
96  this would be the start of the next residue.
97  \param[in] chi Sidechain chi angle to set
98  \param[in] type Torsion angle to set (as defined below)
99 
100  Sets a sidechain torsion angle in a pdb linked list. The routine
101  assumes standard atom ordering: N,CA,C,O,s/c with standard order in
102  the s/c.
103 
104  The type input parameter is defined as follows:
105 
106 
107  type Atom names Sequential atom numbers
108  --------------------------------------------------
109  0 N, CA, CB, XG (0 - 1 - 4 - 5)
110  1 CA, CB, XG, XD (1 - 4 - 5 - 6)
111  2 CB, XG, XD, XE (4 - 5 - 6 - 7)
112  3 XG, XD, XE, XZ (5 - 6 - 7 - 8)
113 
114 - 13.05.92 Original
115 - 27.02.98 Removed unreachable break from switch()
116 - 07.07.14 Use bl prefix for functions By: CTP
117 - 26.08.14 Removed unused 'one' variable
118 */
119 void blSetChi(PDB *pdb,
120  PDB *next,
121  REAL chi,
122  int type)
123 {
124  int natoms,
125  nmove,
126  j;
127  REAL *x = NULL,
128  *y = NULL,
129  *z = NULL,
130  s,
131  n1, n2, n3,
132  sinrot,
133  cosrot,
134  matrix[3][3],
135  CurrentChi;
136  PDB /* *one, */
137  *two,
138  *three,
139  *four,
140  *p;
141  VEC3F base;
142 
143  /* First count number of atoms */
144  for(p=pdb, natoms = 0; p!=next; NEXT(p), natoms++) ;
145 
146  /* Allocate memory for the coordinate lists */
147  x = (REAL *)malloc(natoms * sizeof(REAL));
148  y = (REAL *)malloc(natoms * sizeof(REAL));
149  z = (REAL *)malloc(natoms * sizeof(REAL));
150  if(x==NULL || y==NULL || z==NULL) goto Cleanup;
151 
152  /* Find the current value of the torsion angle */
153  CurrentChi = blCalcChi(pdb, type);
154 
155  /* Calc rotation required. */
156  chi -= CurrentChi;
157 
158  /* Get pointers to the appropriate atoms */
159  switch(type)
160  {
161  case 0: /* N, CA, CB, XG (0 - 1 - 4 - 5) */
162 /* one = blGetPDBByN(pdb, 0); */
163  two = blGetPDBByN(pdb, 1);
164  three = blGetPDBByN(pdb, 4);
165  four = blGetPDBByN(pdb, 5);
166  break;
167  case 1: /* CA, CB, XG, XD (1 - 4 - 5 - 6) */
168 /* one = blGetPDBByN(pdb, 1); */
169  two = blGetPDBByN(pdb, 4);
170  three = blGetPDBByN(pdb, 5);
171  four = blGetPDBByN(pdb, 6);
172  break;
173  case 2: /* CB, XG, XD, XE (4 - 5 - 6 - 7) */
174 /* one = blGetPDBByN(pdb, 4); */
175  two = blGetPDBByN(pdb, 5);
176  three = blGetPDBByN(pdb, 6);
177  four = blGetPDBByN(pdb, 7);
178  break;
179  case 3: /* XG, XD, XE, XZ (5 - 6 - 7 - 8) */
180 /* one = blGetPDBByN(pdb, 5); */
181  two = blGetPDBByN(pdb, 6);
182  three = blGetPDBByN(pdb, 7);
183  four = blGetPDBByN(pdb, 8);
184  break;
185  default:
186  return;
187  }
188 
189  /* Copy the mobile atoms into the arrays */
190  x[0] = two->x;
191  y[0] = two->y;
192  z[0] = two->z;
193  x[1] = three->x;
194  y[1] = three->y;
195  z[1] = three->z;
196  for(p=four, nmove=2; p!=next && nmove<natoms; NEXT(p), nmove++)
197  {
198  x[nmove] = p->x;
199  y[nmove] = p->y;
200  z[nmove] = p->z;
201  }
202 
203  base.x = x[0];
204  base.y = y[0];
205  base.z = z[0];
206 
207  /* Move the atoms from atom two on to the origin */
208  for(j=0; j<nmove; j++)
209  {
210  x[j] -= base.x;
211  y[j] -= base.y;
212  z[j] -= base.z;
213  }
214 
215  /* RotatePDB about an arbitrary axis using routine C-11 from Rogers &
216  Adams, `Mathematical Elements for Computer Graphics'
217  */
218  s = (REAL)sqrt((double)(x[1] * x[1] + y[1] * y[1] + z[1] * z[1]));
219 
220  n1 = x[1]/s;
221  n2 = y[1]/s;
222  n3 = z[1]/s;
223 
224  cosrot = (REAL)cos((double)chi);
225  sinrot = (REAL)sin((double)chi);
226 
227  /* Set up the transformation matrix */
228  matrix[0][0] = n1*n1+(1-n1*n1)*cosrot;
229  matrix[0][1] = n1*n2*(1-cosrot)+n3*sinrot;
230  matrix[0][2] = n1*n3*(1-cosrot)-n2*sinrot;
231  matrix[1][0] = n1*n2*(1-cosrot)-n3*sinrot;
232  matrix[1][1] = n2*n2+(1-n2*n2)*cosrot;
233  matrix[1][2] = n2*n3*(1-cosrot)+n1*sinrot;
234  matrix[2][0] = n1*n3*(1-cosrot)+n2*sinrot;
235  matrix[2][1] = n2*n3*(1-cosrot)-n1*sinrot;
236  matrix[2][2] = n3*n3+(1-n3*n3)*cosrot;
237 
238  /* Do the matrix multiplication */
239  for(j=0; j<nmove; j++)
240  {
241  REAL tempx,
242  tempy,
243  tempz;
244 
245  tempx = x[j] * matrix[0][0] +
246  y[j] * matrix[1][0] +
247  z[j] * matrix[2][0];
248  tempy = x[j] * matrix[0][1] +
249  y[j] * matrix[1][1] +
250  z[j] * matrix[2][1];
251  tempz = x[j] * matrix[0][2] +
252  y[j] * matrix[1][2] +
253  z[j] * matrix[2][2];
254 
255  x[j] = tempx;
256  y[j] = tempy;
257  z[j] = tempz;
258  }
259 
260  /* TranslatePDB back from the origin */
261  for(j=0; j<nmove; j++)
262  {
263  x[j] += base.x;
264  y[j] += base.y;
265  z[j] += base.z;
266  }
267 
268  /* Copy the new coordinates back */
269  two->x = x[0];
270  two->y = y[0];
271  two->z = z[0];
272  three->x = x[1];
273  three->y = y[1];
274  three->z = z[1];
275  for(p=four, nmove=2; p!=next && nmove<natoms; NEXT(p), nmove++)
276  {
277  p->x = x[nmove];
278  p->y = y[nmove];
279  p->z = z[nmove];
280  }
281 
282 Cleanup:
283  if(x) free(x);
284  if(y) free(y);
285  if(z) free(z);
286 }
287 
288 
struct _memlist * next
Definition: safemem.c:115
void blSetChi(PDB *pdb, PDB *next, REAL chi, int type)
Definition: SetChi.c:119
Include file for PDB routines.
REAL x
Definition: MathType.h:70
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
#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
REAL blCalcChi(PDB *pdb, int type)
Definition: CalcChiPDB.c:111
PDB * blGetPDBByN(PDB *pdb, int n)
Definition: GetPDBByN.c:106
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