The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
AddNTerHs.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file AddNTerHs.c
5 
6  \version V1.11
7  \date 23.06.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-2014
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 AddNTerHs(PDB **ppdb, BOOL Charmm)
47 
48  This routine is used to generate a set of N-terminal hydrogens.
49  By default GROMOS naming is used; the Charmm flag changes this to
50  Charmm format in which case an extra NTER residue will be created.
51  Any pre-existing backbone H will be removed. Typically this
52  routine would be called after calling HAddPDB()
53 
54 **************************************************************************
55 
56  Revision History:
57  =================
58 - V1.0 24.08.94 Original By: ACRM
59 - V1.1 05.10.94 Removed unused variables
60 - V1.2 12.11.96 If any of the antecedant coordinates are undefined, set
61  the terminal oxygen to NULL coordinates
62 - V1.3 13.11.96 Also checks for missing CA,C and O1 records
63 - V1.4 30.05.02 Changed PDB field from 'junk' to 'record_type'
64 - V1.5 06.02.03 Handles atnam_raw
65 - V1.6 03.06.05 Handles altpos
66 - V1.7 04.02.14 Use CHAINMATCH By: CTP
67 - V1.8 07.07.14 Use bl prefix for functions By: CTP
68 - V1.9 17.02.15 Handles element and segid By: ACRM
69 - V1.10 05.03.15 Replaced blFindEndPDB() with blFindNextResidue()
70 - V1.11 23.06.15 Added CLEAR_PDB() calls
71 
72 *************************************************************************/
73 /* Doxygen
74  -------
75  #GROUP Handling PDB Data
76  #SUBGROUP Modifying the structure
77  #FUNCTION blAddNTerHs()
78  Adds hydrogens onto the N-termini
79 */
80 /************************************************************************/
81 /* Includes
82 */
83 #include <stdio.h>
84 #include <stdlib.h>
85 #include <math.h>
86 
87 #include "SysDefs.h"
88 #include "MathType.h"
89 #include "pdb.h"
90 #include "macros.h"
91 
92 /************************************************************************/
93 /* Defines and macros
94 */
95 
96 /************************************************************************/
97 /* Globals
98 */
99 
100 /************************************************************************/
101 /* Prototypes
102 */
103 static PDB *KillNTerH(PDB *pdb);
104 static int doAddGromosNTer(PDB **ppdb, PDB *nter);
105 static int doAddCharmmNTer(PDB **ppdb, PDB *nter);
106 
107 /************************************************************************/
108 /*>int blAddNTerHs(PDB **ppdb, BOOL Charmm)
109  ----------------------------------------
110 *//**
111 
112  \param[in,out] **ppdb Pointer to pointer to PDB linked list
113  \param[in] Charmm Do Charmm style Nter
114  \return Number of hydrogens added
115 
116  Adds hydrogens onto the N-termini
117 
118 - 23.08.94 Original By: ACRM
119 - 04.02.14 Use CHAINMATCH By: CTP
120 - 07.07.14 Use bl prefix for functions By: CTP
121 - 23.06.15 Added CLEAR_PDB() calls By: ACRM
122 */
123 int blAddNTerHs(PDB **ppdb, BOOL Charmm)
124 {
125  PDB *p;
126  char chain[8] = "-";
127  int nhyd = 0;
128 
129  for(p = *ppdb; p!=NULL; NEXT(p))
130  {
131  if(!CHAINMATCH(p->chain,chain))
132  {
133  strcpy(chain,p->chain);
134 
135  /* Kill the H if there is one. Makes the (safe...) assumption
136  that the H won't be the first atom (i.e. ignore the return)
137  */
138  KillNTerH(p);
139 
140  if(Charmm)
141  nhyd += doAddCharmmNTer(ppdb, p);
142  else
143  nhyd += doAddGromosNTer(ppdb, p);
144  }
145  }
146 
147  return(nhyd);
148 }
149 
150 /************************************************************************/
151 /*>static PDB *KillNTerH(PDB *pdb)
152  -------------------------------
153 *//**
154 
155  \param[in,out] *pdb PDB linked list
156  \return New start of linked list
157 
158  Remove the backbone hydrogen from Nter residue
159 
160 - 23.08.94 Original By: ACRM
161 - 05.03.15 Replaced blFindEndPDB() with blFindNextResidue()
162 */
163 static PDB *KillNTerH(PDB *pdb)
164 {
165  PDB *p,
166  *end,
167  *prev = NULL;
168 
169  end = blFindNextResidue(pdb);
170 
171  for(p=pdb; p!=end; NEXT(p))
172  {
173  if(!strncmp(p->atnam,"H ",4))
174  {
175  if(prev==NULL) /* Is the first item in the list */
176  {
177  prev = p->next;
179  free(p);
180  return(prev);
181  }
182  else /* Is NOT the first item in the list */
183  {
184  prev->next = p->next;
186  free(p);
187  return(pdb);
188  }
189  }
190  prev = p;
191  }
192  return(pdb);
193 }
194 
195 
196 /************************************************************************/
197 /*>static int doAddGromosNTer(PDB **ppdb, PDB *nter)
198  -------------------------------------------------
199 *//**
200 
201  \param[in,out] **ppdb Pointer to pointer to PDB linked list
202  \param[in] *nter Pointer to an N-terminus
203  \return Number of Hs added (0 if error)
204 
205  Does the actual work of adding the hydrogens onto an N terminus
206 
207 - 23.08.94 Original By: ACRM
208 - 24.08.94 Set B-values of Hs to 20.0
209 - 05.10.94 Removed unused variables
210 - 06.02.03 Handles atnam_raw
211 - 03.06.05 Handles altpos
212 - 17.02.15 Handles element and segid
213 */
214 static int doAddGromosNTer(PDB **ppdb, PDB *nter)
215 {
216  COOR coor[3];
217  PDB *prev = NULL,
218  *H1, *H2, *H3;
219 
220  /* If not start of list find pointer to previous record */
221  if(*ppdb != nter)
222  {
223  for(prev = *ppdb; prev->next != nter; NEXT(prev));
224  }
225 
226  if(blCalcTetraHCoords(nter, coor))
227  {
228  /* Initialise some space to store the 3 extra hydrogens */
229  INIT(H1, PDB);
230  INIT(H2, PDB);
231  INIT(H3, PDB);
232  if(H1==NULL || H2==NULL || H3==NULL) return(0);
233 
234  CLEAR_PDB(H1); /* 23.06.15 */
235  CLEAR_PDB(H2);
236  CLEAR_PDB(H3);
237 
238  /* Initialise the hydrogens with the res info, etc. */
239  blCopyPDB(H1, nter);
240  blCopyPDB(H2, nter);
241  blCopyPDB(H3, nter);
242  H1->bval = H2->bval = H3->bval = (REAL)20.0;
243  strcpy(H1->element," H"); /* 17.02.15 */
244  strcpy(H2->element," H"); /* 17.02.15 */
245  strcpy(H3->element," H"); /* 17.02.15 */
246  H1->formal_charge = 0; /* 17.02.15 */
247  H2->formal_charge = 0; /* 17.02.15 */
248  H3->formal_charge = 0; /* 17.02.15 */
249 
250  /* Link these extra records into the linked list */
251  H3->next = nter->next;
252  H1->next = H2;
253  H2->next = nter;
254  nter->next = H3;
255 
256  /* Set the coordinates */
257  H1->x = coor[0].x;
258  H1->y = coor[0].y;
259  H1->z = coor[0].z;
260  strcpy(H1->atnam, "H1 ");
261  strcpy(H1->atnam_raw, " H1 ");
262  H1->altpos = ' '; /* 03.06.05 */
263 
264  H2->x = coor[1].x;
265  H2->y = coor[1].y;
266  H2->z = coor[1].z;
267  strcpy(H2->atnam, "H2 ");
268  strcpy(H2->atnam_raw, " H2 ");
269  H2->altpos = ' '; /* 03.06.05 */
270 
271  H3->x = coor[2].x;
272  H3->y = coor[2].y;
273  H3->z = coor[2].z;
274  strcpy(H3->atnam, "H3 ");
275  strcpy(H3->atnam_raw, " H3 ");
276  H3->altpos = ' '; /* 03.06.05 */
277 
278  /* Correctly link the new start into the whole linked list */
279  if(prev != NULL)
280  prev->next = H1;
281  else
282  *ppdb = H1;
283 
284  return(3);
285  }
286  return(0);
287 }
288 
289 /************************************************************************/
290 /*>static int doAddCharmmNTer(PDB **ppdb, PDB *nter)
291  -------------------------------------------------
292 *//**
293 
294  \param[in,out] **ppdb Pointer to pointer to PDB linked list
295  \param[in] *nter Pointer to an N-terminus
296  \return Number of Hs added (0 if error)
297 
298  Does the actual work of adding the hydrogens onto an N terminus
299 
300 - 23.08.94 Original By: ACRM
301 - 24.08.94 Set B-values of H3 to 20.0
302 - 05.10.94 Removed unused variables
303 - 06.02.03 Handles atnam_raw
304 - 03.06.05 Handles altpos
305 - 17.02.15 Handles element, segid and formal charge
306 */
307 static int doAddCharmmNTer(PDB **ppdb, PDB *nter)
308 {
309  COOR coor[3];
310  PDB *prev = NULL,
311  *H1, *H2, *H3;
312 
313  /* If not start of list find pointer to previous record */
314  if(*ppdb != nter)
315  {
316  for(prev = *ppdb; prev->next != nter; NEXT(prev));
317  }
318 
319  if(blCalcTetraHCoords(nter, coor))
320  {
321  /* Initialise some space to store the 3 extra hydrogens */
322  INIT(H1, PDB);
323  INIT(H2, PDB);
324  INIT(H3, PDB);
325  if(H1==NULL || H2==NULL || H3==NULL) return(0);
326 
327  /* Initialise the hydrogens with the res info, etc. */
328  H1->atnum = 9998;
329  H1->resnum = 9999;
330  H1->occ = 1.0;
331  H1->bval = 20.0;
332  strcpy(H1->resnam, "NTER");
333  strcpy(H1->atnam, "HT1 ");
334  strcpy(H1->atnam_raw, " HT1");
335  strcpy(H1->record_type, "ATOM ");
336  strcpy(H1->chain, nter->chain);
337  strcpy(H1->insert, " ");
338  H1->altpos = ' '; /* 03.06.05 */
339  strcpy(H1->element, " H"); /* 17.02.15 */
340  strcpy(H1->segid, nter->segid); /* 17.02.15 */
341  H1->formal_charge = 0; /* 17.02.15 */
342 
343  H2->atnum = 9999;
344  H2->resnum = 9999;
345  H2->occ = 1.0;
346  H2->bval = 20.0;
347  strcpy(H2->resnam, "NTER");
348  strcpy(H2->atnam, "HT2 ");
349  strcpy(H2->atnam_raw, " HT2");
350  strcpy(H2->record_type, "ATOM ");
351  strcpy(H2->chain, nter->chain);
352  strcpy(H2->insert, " ");
353  H2->altpos = ' '; /* 03.06.05 */
354  strcpy(H2->element, " H"); /* 17.02.15 */
355  strcpy(H2->segid, nter->segid); /* 17.02.15 */
356  H2->formal_charge = 0; /* 17.02.15 */
357 
358  blCopyPDB(H3, nter);
359  strcpy(H3->atnam, "HT3 ");
360  strcpy(H3->atnam_raw, " HT3");
361  H3->bval = 20.0;
362  H3->altpos = ' '; /* 03.06.05 */
363  strcpy(H3->element," H"); /* 17.02.15 */
364  H3->formal_charge = 0; /* 17.02.15 */
365 
366  /* Link these extra records into the linked list */
367  H3->next = nter->next;
368  H1->next = H2;
369  H2->next = nter;
370  nter->next = H3;
371 
372  /* Set the coordinates */
373  H1->x = coor[0].x;
374  H1->y = coor[0].y;
375  H1->z = coor[0].z;
376 
377  H2->x = coor[1].x;
378  H2->y = coor[1].y;
379  H2->z = coor[1].z;
380 
381  H3->x = coor[2].x;
382  H3->y = coor[2].y;
383  H3->z = coor[2].z;
384 
385  /* Change the name of the Nter nitrogen */
386  strcpy(nter->atnam, "NT ");
387  strcpy(nter->atnam_raw, " NT ");
388 
389  /* Correctly link the new start into the whole linked list */
390  if(prev != NULL)
391  prev->next = H1;
392  else
393  *ppdb = H1;
394 
395  return(3);
396  }
397  return(0);
398 }
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
#define CLEAR_PDB(p)
Definition: pdb.h:460
#define NEXT(x)
Definition: macros.h:249
Useful macros.
char atnam[8]
Definition: pdb.h:316
Definition: MathType.h:69
double REAL
Definition: MathType.h:67
int blCalcTetraHCoords(PDB *nter, COOR *coor)
char atnam_raw[8]
Definition: pdb.h:317
char chain[8]
Definition: access.h:85
int blAddNTerHs(PDB **ppdb, BOOL Charmm)
Definition: AddNTerHs.c:123
void blCopyPDB(PDB *out, PDB *in)
Definition: CopyPDB.c:108
void blDeleteAtomConects(PDB *pdb)
Definition: BuildConect.c:536
#define CHAINMATCH(chain1, chain2)
Definition: pdb.h:495
char segid[8]
Definition: pdb.h:323
#define INIT(x, y)
Definition: macros.h:244
System-type variable type definitions.
PDB * blFindNextResidue(PDB *pdb)
Type definitions for maths.
struct pdb_entry * next
Definition: pdb.h:307
REAL z
Definition: MathType.h:70
char chain[blMAXCHAINLABEL]
Definition: pdb.h:321
REAL y
Definition: MathType.h:70
REAL x
Definition: pdb.h:300