Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
TorCoor.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file TorCoor.c
5 
6  \version V1.1
7  \date 07.07.14
8  \brief Calculate cartesian coordinates from torsion angle
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1989-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 
50 *************************************************************************/
51 /* Doxygen
52  -------
53  #GROUP Maths
54  #SUBGROUP Geometry
55  #FUNCTION blTorToCoor()
56  Calculates cartesian coordinates for an atom given the coordinates of
57  three antecedant atoms and the bond length, angle and torsion angle
58 */
59 /************************************************************************/
60 /* Includes
61 */
62 #include <math.h>
63 #include <stdio.h>
64 
65 #include "MathType.h"
66 #include "SysDefs.h"
67 
68 /************************************************************************/
69 /* Defines and macros
70 */
71 #define ETA (1.07e-7)
72 
73 /************************************************************************/
74 /* Globals
75 */
76 
77 /************************************************************************/
78 /* Prototypes
79 */
80 
81 /************************************************************************/
82 /*>BOOL blTorToCoor(VEC3F ant1, VEC3F ant2, VEC3F ant3,
83  REAL bond, REAL theta, REAL torsion,
84  VEC3F *coords)
85  -----------------------------------------------------
86 *//**
87 
88  \param[in] ant1 First antecedent atom coordinates
89  \param[in] ant2 Second antecedent atom coordinates
90  \param[in] ant3 Third antecedent atom coordinates
91  \param[in] bond Bond length from ant3 to new atom
92  \param[in] theta Bond angle ant2-ant3-new
93  \param[in] torsion Torsion angle ant1-ant2-ant3-new
94  \param[out] *coords Coordinates of new atom
95  \return TRUE if distance between atoms 2 and 3
96  is < ETA (1.07e-7)
97 
98  Calculates cartesian coordinates for an atom given the coordinates of
99  three antecedant atoms and the bond length, angle and torsion angle
100 
101 - 08.07.96 Original By: ACRM based on earlier FORTRAN code
102 - 07.07.14 Use bl prefix for functions By: CTP
103 */
104 BOOL blTorToCoor(VEC3F ant1, VEC3F ant2, VEC3F ant3,
105  REAL bond, REAL theta, REAL torsion,
106  VEC3F *coords)
107 {
108  REAL x1, y1, z1,
109  x2, y2, z2,
110  x3, y3, z3,
111  xx4, yy4, zz4,
112  x2o, y2o, z2o,
113  CosTheta, SinTheta,
114  CosTor, SinTor,
115  DistYZ1, InvDistYZ1,
116  DistXZ2, DistSqXZ2,
117  Dist2, InvDist2,
118  y1o, z1o,
119  xz2o, xx1,
120  BondSinTheta,
121  InvDistXZ2;
122  BOOL RetVal = FALSE;
123 
124  /* Generate pretend position of new atom if all other atoms were
125  easily lined up.
126  */
127  SinTheta = sin(PI-theta);
128  CosTheta = cos(PI-theta);
129  SinTor = sin(torsion);
130  CosTor = cos(torsion);
131  BondSinTheta = bond * SinTheta;
132  coords->x = bond * CosTheta;
133  coords->y = BondSinTheta * CosTor;
134  coords->z = BondSinTheta * SinTor;
135 
136  /* Translate ant1 and ant2 such that ant3 is at the origin. */
137  x3 = ant3.x;
138  y3 = ant3.y;
139  z3 = ant3.z;
140  x1 = ant1.x - x3;
141  y1 = ant1.y - y3;
142  z1 = ant1.z - z3;
143  x2 = ant2.x - x3;
144  y2 = ant2.y - y3;
145  z2 = ant2.z - z3;
146 
147  /* Rotate ant1 by rotation of ant2 to the origin. */
148  DistSqXZ2 = x2*x2 + z2*z2;
149  Dist2 = sqrt(DistSqXZ2+y2*y2);
150  DistXZ2 = sqrt(DistSqXZ2);
151 
152  if (Dist2 < ETA)
153  {
154  RetVal = TRUE;
155  InvDist2 = 1.0/ETA;
156  }
157  else
158  {
159  InvDist2 = 1.0/Dist2;
160  }
161 
162  if (DistXZ2 < ETA)
163  {
164  xx1 = x1;
165  x2o = 1.0;
166  z2o = 0.0;
167  }
168  else
169  {
170  InvDistXZ2 = 1.0/DistXZ2;
171  x2o = x2*InvDistXZ2;
172  z2o = z2*InvDistXZ2;
173  xx1 = x1*x2o + z1*z2o;
174  z1 = z1*x2o - x1*z2o;
175  }
176 
177  xz2o = DistXZ2 * InvDist2;
178  y2o = y2 * InvDist2;
179  x1 = (-xx1*xz2o) - y1*y2o;
180  y1 = xx1*y2o - y1*xz2o;
181 
182  /* Rotate new atom by inverse of rotation which takes the transformed
183  ant1 atom to the xy plane by rotation about the x axis.
184  */
185  DistYZ1 = sqrt(y1*y1 + z1*z1);
186  InvDistYZ1 = 1.0 / DistYZ1;
187  y1o = y1 * InvDistYZ1;
188  z1o = z1 * InvDistYZ1;
189  yy4 = y1o*coords->y - z1o*coords->z;
190  zz4 = y1o*coords->z + z1o*coords->y;
191 
192  /* Rotate new atom by inverse of ant2 rotation to -x axis. */
193  xx4 = y2o*yy4 - xz2o*coords->x;
194  coords->y = (-xz2o*yy4) - y2o*coords->x;
195  coords->x = x2o*xx4 - z2o*zz4;
196  coords->z = z2o*xx4 + x2o*zz4;
197 
198  /* Move back since we translated such that ant3 was at the origin */
199  coords->x += x3;
200  coords->y += y3;
201  coords->z += z3;
202 
203  return(RetVal);
204 }
205 
REAL x
Definition: MathType.h:70
BOOL blTorToCoor(VEC3F ant1, VEC3F ant2, VEC3F ant3, REAL bond, REAL theta, REAL torsion, VEC3F *coords)
Definition: TorCoor.c:104
short BOOL
Definition: SysDefs.h:64
#define PI
Definition: macros.h:215
#define FALSE
Definition: macros.h:223
Definition: MathType.h:69
double REAL
Definition: MathType.h:67
#define TRUE
Definition: macros.h:219
#define ETA
Definition: TorCoor.c:71
System-type variable type definitions.
Type definitions for maths.
REAL z
Definition: MathType.h:70
REAL y
Definition: MathType.h:70