Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
FitNCaCPDB.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file FitNCaCPDB.c
5 
6  \version V1.5
7  \date 19.08.14
8  \brief Fit two PDB linked lists. Also a weighted fit and support
9  routines
10 
11  \copyright (c) UCL / Dr. Andrew C. R. Martin 1993-6
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.0 01.03.94 Original release
51 - V1.1 11.03.94 Fixed bug in calls to matfit(). Had not been changed
52  to reflect modification in MatMult3_33().
53 - V1.2 14.03.94 Fixed FitPDB(); wasn't filling in the output matrix
54 - V1.3 14.03.96 Added FitCaPDB()
55  Changed FitPDB() and FitCaCbPDB() to use
56  ApplyMatrixPDB() rather than RotatePDB() since the PDB
57  linked lists are already at the origin
58 - V1.4 07.07.14 Use bl prefix for functions By: CTP
59 - V1.5 19.08.14 Added AsCopy suffix to calls to blSelectAtomsPDB()
60  By: CTP
61 
62 *************************************************************************/
63 /* Doxygen
64  -------
65  #GROUP Handling PDB Data
66  #SUBGROUP Fitting
67  #FUNCTION blFitNCaCPDB()
68  Fits two PDB linked lists using only the N, CA, C atoms.
69 */
70 /************************************************************************/
71 /* Includes
72 */
73 #include <math.h>
74 #include <stdlib.h>
75 #include <string.h>
76 
77 #include "MathType.h"
78 #include "SysDefs.h"
79 #include "macros.h"
80 #include "fit.h"
81 #include "pdb.h"
82 
83 /************************************************************************/
84 /* Defines and macros
85 */
86 
87 /************************************************************************/
88 /* Globals
89 */
90 
91 /************************************************************************/
92 /* Prototypes
93 */
94 
95 /************************************************************************/
96 /*>BOOL blFitNCaCPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
97  ------------------------------------------------------------
98 *//**
99 
100  \param[in] *ref_pdb Reference PDB linked list
101  \param[in,out] *fit_pdb Mobile PDB linked list
102  \param[out] rm Rotation matrix (May be input as NULL).
103  \return Success
104 
105  Fits two PDB linked lists using only the N, CA, C atoms.
106 
107  Actually fits fit_pdb onto ref_pdb and also returns the rotation
108  matrix. This may be NULL if these data are not required.
109 
110 - 12.12.01 Original based on FitCaPDB() By: ACRM
111 - 07.07.14 Use bl prefix for functions By: CTP
112 - 19.08.14 Added AsCopy suffix to calls to blSelectAtomsPDB() By: CTP
113 */
114 BOOL blFitNCaCPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
115 {
116  REAL RotMat[3][3];
117  COOR *ref_coor = NULL,
118  *fit_coor = NULL;
119  VEC3F ref_bb_CofG,
120  fit_bb_CofG,
121  tvect;
122  int NCoor = 0,
123  i, j,
124  natoms;
125  BOOL RetVal;
126  PDB *ref_bb_pdb = NULL,
127  *fit_bb_pdb = NULL;
128  char *sel[4];
129 
130  /* First extract only the backbone (BB) atoms */
131  SELECT(sel[0], "N ");
132  SELECT(sel[1], "CA ");
133  SELECT(sel[2], "C ");
134  if((sel[0]==NULL)||(sel[1]==NULL)||(sel[2]==NULL)||(sel[3]==NULL))
135  return(FALSE);
136  if( (ref_bb_pdb = blSelectAtomsPDBAsCopy(ref_pdb, 3, sel, &natoms))
137  == NULL )
138  RetVal = FALSE;
139  if( (fit_bb_pdb = blSelectAtomsPDBAsCopy(fit_pdb, 3, sel, &natoms))
140  == NULL )
141  RetVal = FALSE;
142  free(sel[0]);
143  free(sel[1]);
144  free(sel[2]);
145 
146  /* If we succeeded in building our BB PDB linked lists... */
147  if(RetVal)
148  {
149  /* Get the CofG of the BB structures and the original mobile */
150  blGetCofGPDB(ref_bb_pdb, &ref_bb_CofG);
151  blGetCofGPDB(fit_bb_pdb, &fit_bb_CofG);
152 
153  /* Move them both to the origin */
154  blOriginPDB(ref_bb_pdb);
155  blOriginPDB(fit_bb_pdb);
156 
157  /* Create coordinate arrays, checking numbers match */
158  NCoor = blGetPDBCoor(ref_bb_pdb, &ref_coor);
159  if(blGetPDBCoor(fit_bb_pdb, &fit_coor) != NCoor)
160  {
161  RetVal = FALSE;
162  }
163  else
164  {
165  /* Can't fit with fewer than 3 coordinates */
166  if(NCoor < 3)
167  {
168  RetVal = FALSE;
169  }
170  else
171  {
172  /* Everything OK, go ahead with the fitting */
173  if(!blMatfit(ref_coor,fit_coor,RotMat,NCoor,NULL,FALSE))
174  {
175  RetVal = FALSE;
176  }
177  else
178  {
179  /* Apply the operations to the true coordinates */
180  tvect.x = (-fit_bb_CofG.x);
181  tvect.y = (-fit_bb_CofG.y);
182  tvect.z = (-fit_bb_CofG.z);
183  blTranslatePDB(fit_pdb, tvect);
184  blApplyMatrixPDB(fit_pdb, RotMat);
185  blTranslatePDB(fit_pdb, ref_bb_CofG);
186  }
187  }
188  }
189  }
190 
191  /* Free the coordinate arrays and BB PDB linked lists */
192  if(ref_coor) free(ref_coor);
193  if(fit_coor) free(fit_coor);
194  if(ref_bb_pdb) FREELIST(ref_bb_pdb, PDB);
195  if(fit_bb_pdb) FREELIST(fit_bb_pdb, PDB);
196 
197  /* Fill in the rotation matrix for output, if required */
198  if(RetVal && (rm!=NULL))
199  {
200  for(i=0; i<3; i++)
201  for(j=0; j<3; j++)
202  rm[i][j] = RotMat[i][j];
203  }
204 
205  return(RetVal);
206 }
207 
Include file for PDB routines.
REAL x
Definition: MathType.h:70
short BOOL
Definition: SysDefs.h:64
#define NULL
Definition: array2.c:99
Definition: pdb.h:298
PDB * blSelectAtomsPDBAsCopy(PDB *pdbin, int nsel, char **sel, int *natom)
Definition: SelAtPDB.c:173
#define FALSE
Definition: macros.h:223
Useful macros.
Definition: MathType.h:69
int blGetPDBCoor(PDB *pdb, COOR **coor)
Definition: GetPDBCoor.c:104
double REAL
Definition: MathType.h:67
BOOL blFitNCaCPDB(PDB *ref_pdb, PDB *fit_pdb, REAL rm[3][3])
Definition: FitNCaCPDB.c:114
BOOL blMatfit(COOR *x1, COOR *x2, REAL rm[3][3], int n, REAL *wt1, BOOL column)
Definition: fit.c:128
Include file for least squares fitting.
#define SELECT(x, w)
Definition: pdb.h:357
void blGetCofGPDB(PDB *pdb, VEC3F *cg)
Definition: GetCGPDB.c:98
#define FREELIST(y, z)
Definition: macros.h:264
System-type variable type definitions.
void blOriginPDB(PDB *pdb)
Definition: OriginPDB.c:96
Type definitions for maths.
REAL z
Definition: MathType.h:70
void blTranslatePDB(PDB *pdb, VEC3F tvect)
Definition: TranslatePDB.c:95
REAL y
Definition: MathType.h:70
void blApplyMatrixPDB(PDB *pdb, REAL matrix[3][3])
Definition: ApMatPDB.c:92