3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2004, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
35 /* This file is completely threadsafe - keep it that way! */
52 static int in_strings(char *key, int nstr, const char **str)
56 for (j = 0; (j < nstr); j++)
58 if (strcmp(str[j], key) == 0)
67 static gmx_bool hbond(rvec x[], int i, int j, real distance)
69 real tol = distance*distance;
72 rvec_sub(x[i], x[j], tmp);
74 return (iprod(tmp, tmp) < tol);
77 static void chk_allhb(t_atoms *pdba, rvec x[], t_blocka *hb,
78 gmx_bool donor[], gmx_bool accept[], real dist)
80 int i, j, k, ii, natom;
83 snew(hb->index, natom+1);
90 for (i = 0; (i < natom); i++)
94 for (j = i+1; (j < natom); j++)
96 if ((accept[j]) && (hbond(x, i, j, dist)))
104 for (j = i+1; (j < natom); j++)
106 if ((donor[j]) && (hbond(x, i, j, dist)))
117 static void pr_hbonds(FILE *fp, t_blocka *hb, t_atoms *pdba)
121 fprintf(fp, "Dumping all hydrogen bonds!\n");
122 for (i = 0; (i < hb->nr); i++)
126 for (j = j0; (j < j1); j++)
129 fprintf(fp, "%5s%4d%5s - %5s%4d%5s\n",
130 *pdba->resinfo[pdba->atom[i].resind].name,
131 pdba->resinfo[pdba->atom[i].resind].nr, *pdba->atomname[i],
132 *pdba->resinfo[pdba->atom[k].resind].name,
133 pdba->resinfo[pdba->atom[k].resind].nr, *pdba->atomname[k]);
138 static gmx_bool chk_hbonds(int i, t_atoms *pdba, rvec x[],
139 gmx_bool ad[], gmx_bool hbond[], rvec xh,
140 real angle, real dist)
143 int j, aj, ri, natom;
149 ri = pdba->atom[i].resind;
151 for (j = 0; (j < natom); j++)
153 /* Check whether the other atom is a donor/acceptor and not i */
154 if ((ad[j]) && (j != i))
156 /* Check whether the other atom is on the same ring as well */
157 if ((pdba->atom[j].resind != ri) ||
158 ((strcmp(*pdba->atomname[j], "ND1") != 0) &&
159 (strcmp(*pdba->atomname[j], "NE2") != 0)))
162 d2 = distance2(x[i], x[j]);
163 rvec_sub(x[i], xh, nh);
164 rvec_sub(x[aj], xh, oh);
165 a = RAD2DEG * acos(cos_angle(nh, oh));
166 if ((d2 < dist2) && (a > angle))
171 "HBOND between %s%d-%s and %s%d-%s is %g nm, %g deg\n",
172 *pdba->resinfo[pdba->atom[i].resind].name,
173 pdba->resinfo[pdba->atom[i].resind].nr, *pdba->atomname[i],
174 *pdba->resinfo[pdba->atom[aj].resind].name,
175 pdba->resinfo[pdba->atom[aj].resind].nr, *pdba->atomname[aj],
187 static void calc_ringh(rvec xattach, rvec xb, rvec xc, rvec xh)
192 /* Add a proton on a ring to atom attach at distance 0.1 nm */
193 rvec_sub(xattach, xb, tab);
194 rvec_sub(xattach, xc, tac);
195 rvec_add(tab, tac, xh);
198 rvec_inc(xh, xattach);
201 void set_histp(t_atoms *pdba, rvec *x, real angle, real dist)
203 static const char *prot_acc[] = {
204 "O", "OD1", "OD2", "OE1", "OE2", "OG", "OG1", "OH", "OW"
206 #define NPA asize(prot_acc)
207 static const char *prot_don[] = {
208 "N", "NH1", "NH2", "NE", "ND1", "ND2", "NE2", "NZ", "OG", "OG1", "OH", "NE1", "OW"
210 #define NPD asize(prot_don)
212 gmx_bool *donor, *acceptor;
213 gmx_bool *hbond, bHaveH = FALSE;
217 int i, j, nd, na, aj, hisind, his0, type = -1;
218 int nd1, ne2, cg, cd2, ce1;
227 gmx_strcasecmp(*pdba->resinfo[pdba->atom[i].resind].name, "HIS") != 0)
236 /* A histidine residue exists that requires automated assignment, so
237 * doing the analysis of donors and acceptors is worthwhile. */
239 "Analysing hydrogen-bonding network for automated assignment of histidine\n"
243 snew(acceptor, natom);
248 for (j = 0; (j < natom); j++)
250 if (in_strings(*pdba->atomname[j], NPA, prot_acc) != -1)
255 if (in_strings(*pdba->atomname[j], NPD, prot_don) != -1)
261 fprintf(stderr, " %d donors and %d acceptors were found.\n", nd, na);
262 chk_allhb(pdba, x, hb, donor, acceptor, dist);
265 pr_hbonds(debug, hb, pdba);
267 fprintf(stderr, "There are %d hydrogen bonds\n", hb->nra);
269 /* Now do the HIS stuff */
273 if (gmx_strcasecmp(*pdba->resinfo[pdba->atom[i].resind].name, "HIS") != 0)
279 if (pdba->atom[i].resind != hisind)
281 hisind = pdba->atom[i].resind;
283 /* Find the atoms in the ring */
284 nd1 = ne2 = cg = cd2 = ce1 = -1;
285 while (i < natom && pdba->atom[i].resind == hisind)
287 atomnm = *pdba->atomname[i];
288 if (strcmp(atomnm, "CD2") == 0)
292 else if (strcmp(atomnm, "CG") == 0)
296 else if (strcmp(atomnm, "CE1") == 0)
300 else if (strcmp(atomnm, "ND1") == 0)
304 else if (strcmp(atomnm, "NE2") == 0)
312 if (!((cg == -1 ) || (cd2 == -1) || (ce1 == -1) ||
313 (nd1 == -1) || (ne2 == -1)))
315 calc_ringh(x[nd1], x[cg], x[ce1], xh1);
316 calc_ringh(x[ne2], x[ce1], x[cd2], xh2);
318 bHDd = chk_hbonds(nd1, pdba, x, acceptor, hbond, xh1, angle, dist);
319 chk_hbonds(nd1, pdba, x, donor, hbond, xh1, angle, dist);
320 bHEd = chk_hbonds(ne2, pdba, x, acceptor, hbond, xh2, angle, dist);
321 chk_hbonds(ne2, pdba, x, donor, hbond, xh2, angle, dist);
338 fprintf(stderr, "Will use %s for residue %d\n",
339 hh[type], pdba->resinfo[hisind].nr);
343 gmx_fatal(FARGS, "Incomplete ring in HIS%d",
344 pdba->resinfo[hisind].nr);
347 snew(pdba->resinfo[hisind].rtp, 1);
348 *pdba->resinfo[hisind].rtp = strdup(hh[type]);