2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2016, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
46 #include "gromacs/listed-forces/bonded.h"
47 #include "gromacs/math/functions.h"
48 #include "gromacs/math/units.h"
49 #include "gromacs/math/vec.h"
50 #include "gromacs/topology/index.h"
51 #include "gromacs/topology/topology.h"
52 #include "gromacs/utility/arraysize.h"
53 #include "gromacs/utility/fatalerror.h"
54 #include "gromacs/utility/smalloc.h"
56 real ellipticity(int nres, t_bb bb[])
61 // Avoid warnings about narrowing conversions from double to real
63 #pragma warning(disable: 4838)
65 static const t_ppwstr ppw[] = {
72 { -70.5, -35.8, 0.15 },
80 #pragma warning(default: 4838)
82 #define NPPW asize(ppw)
85 real ell, pp2, phi, psi;
88 for (i = 0; (i < nres); i++)
92 for (j = 0; (j < NPPW); j++)
94 pp2 = gmx::square(phi-ppw[j].phi)+gmx::square(psi-ppw[j].psi);
106 real ahx_len(int gnx, int index[], rvec x[])
107 /* Assume we have a list of Calpha atoms only! */
111 rvec_sub(x[index[0]], x[index[gnx-1]], dx);
116 real radius(FILE *fp, int nca, int ca_index[], rvec x[])
117 /* Assume we have all the backbone */
123 for (i = 0; (i < nca); i++)
126 dl2 = gmx::square(x[ai][XX])+gmx::square(x[ai][YY]);
130 fprintf(fp, " %10g", dl2);
140 return std::sqrt(dlt/nca);
143 static real rot(rvec x1, rvec x2)
145 real phi1, dphi, cp, sp;
148 phi1 = std::atan2(x1[YY], x1[XX]);
151 xx = cp*x2[XX]+sp*x2[YY];
152 yy = -sp*x2[XX]+cp*x2[YY];
154 dphi = RAD2DEG*std::atan2(yy, xx);
159 real twist(int nca, int caindex[], rvec x[])
166 for (i = 1; (i < nca); i++)
170 dphi = rot(x[a0], x[a1]);
182 real ca_phi(int gnx, int index[], rvec x[])
183 /* Assume we have a list of Calpha atoms only! */
186 int i, ai, aj, ak, al, t1, t2, t3;
187 rvec r_ij, r_kj, r_kl, m, n;
196 for (i = 0; (i < gnx-4); i++)
203 dih_angle(x[ai], x[aj], x[ak], x[al], NULL,
204 r_ij, r_kj, r_kl, m, n,
205 &sign, &t1, &t2, &t3);
209 return (phitot/(gnx-4.0));
212 real dip(int nbb, int const bbind[], const rvec x[], const t_atom atom[])
219 for (i = 0; (i < nbb); i++)
223 for (m = 0; (m < DIM); m++)
225 dipje[m] += x[ai][m]*q;
231 real rise(int gnx, int index[], rvec x[])
232 /* Assume we have a list of Calpha atoms only! */
240 for (i = 1; (i < gnx); i++)
248 return (ztot/(gnx-1.0));
251 void av_hblen(FILE *fp3, FILE *fp3a,
252 FILE *fp4, FILE *fp4a,
253 FILE *fp5, FILE *fp5a,
254 real t, int nres, t_bb bb[])
256 int i, n3 = 0, n4 = 0, n5 = 0;
257 real d3 = 0, d4 = 0, d5 = 0;
259 for (i = 0; (i < nres-3); i++)
263 fprintf(fp3a, "%10g", bb[i].d3);
268 fprintf(fp4a, "%10g", bb[i].d4);
274 fprintf(fp5a, "%10g", bb[i].d5);
280 fprintf(fp3, "%10g %10g\n", t, d3/n3);
281 fprintf(fp4, "%10g %10g\n", t, d4/n4);
282 fprintf(fp5, "%10g %10g\n", t, d5/n5);
289 void av_phipsi(FILE *fphi, FILE *fpsi, FILE *fphi2, FILE *fpsi2,
290 real t, int nres, t_bb bb[])
293 real phi = 0, psi = 0;
295 fprintf(fphi2, "%10g", t);
296 fprintf(fpsi2, "%10g", t);
297 for (i = 0; (i < nres); i++)
303 fprintf(fphi2, " %10g", bb[i].phi);
304 fprintf(fpsi2, " %10g", bb[i].psi);
308 fprintf(fphi, "%10g %10g\n", t, (phi/n));
309 fprintf(fpsi, "%10g %10g\n", t, (psi/n));
310 fprintf(fphi2, "\n");
311 fprintf(fpsi2, "\n");
314 static void set_ahcity(int nbb, t_bb bb[])
319 for (n = 0; (n < nbb); n++)
321 pp2 = gmx::square(bb[n].phi-PHI_AHX)+gmx::square(bb[n].psi-PSI_AHX);
323 bb[n].bHelix = FALSE;
326 if ((bb[n].d4 < 0.36) || ((n > 0) && bb[n-1].bHelix))
334 t_bb *mkbbind(const char *fn, int *nres, int *nbb, int res0,
335 int *nall, int **index,
336 char ***atomname, t_atom atom[],
339 static const char * bb_nm[] = { "N", "H", "CA", "C", "O", "HN" };
340 #define NBB asize(bb_nm)
343 int ai, i, i0, i1, j, k, ri, rnr, gnx, r0, r1;
345 fprintf(stderr, "Please select a group containing the entire backbone\n");
346 rd_index(fn, 1, &gnx, index, &grpname);
348 fprintf(stderr, "Checking group %s\n", grpname);
349 r0 = r1 = atom[(*index)[0]].resind;
350 for (i = 1; (i < gnx); i++)
352 r0 = std::min(r0, atom[(*index)[i]].resind);
353 r1 = std::max(r1, atom[(*index)[i]].resind);
356 fprintf(stderr, "There are %d residues\n", rnr);
358 for (i = 0; (i < rnr); i++)
360 bb[i].N = bb[i].H = bb[i].CA = bb[i].C = bb[i].O = -1, bb[i].resno = res0+i;
363 for (i = j = 0; (i < gnx); i++)
366 ri = atom[ai].resind-r0;
367 if (std::strcmp(*(resinfo[ri].name), "PRO") == 0)
369 if (std::strcmp(*(atomname[ai]), "CD") == 0)
374 for (k = 0; (k < NBB); k++)
376 if (std::strcmp(bb_nm[k], *(atomname[ai])) == 0)
389 /* No attempt to address the case where some weird input has both H and HN atoms in the group */
406 for (i0 = 0; (i0 < rnr); i0++)
408 if ((bb[i0].N != -1) && (bb[i0].H != -1) &&
410 (bb[i0].C != -1) && (bb[i0].O != -1))
415 for (i1 = rnr-1; (i1 >= 0); i1--)
417 if ((bb[i1].N != -1) && (bb[i1].H != -1) &&
419 (bb[i1].C != -1) && (bb[i1].O != -1))
433 for (i = i0; (i < i1); i++)
435 bb[i].Cprev = bb[i-1].C;
436 bb[i].Nnext = bb[i+1].N;
438 rnr = std::max(0, i1-i0+1);
439 fprintf(stderr, "There are %d complete backbone residues (from %d to %d)\n",
440 rnr, bb[i0].resno, bb[i1].resno);
443 gmx_fatal(FARGS, "Zero complete backbone residues were found, cannot proceed");
445 for (i = 0; (i < rnr); i++, i0++)
451 for (i = 0; (i < rnr); i++)
453 ri = atom[bb[i].CA].resind;
454 sprintf(bb[i].label, "%s%d", *(resinfo[ri].name), ri+res0);
458 *nbb = rnr*asize(bb_nm);
463 real pprms(FILE *fp, int nbb, t_bb bb[])
466 real rms, rmst, rms2;
469 for (i = n = 0; (i < nbb); i++)
473 rms = std::sqrt(bb[i].pprms2);
475 rms2 += bb[i].pprms2;
476 fprintf(fp, "%10g ", rms);
481 rms = std::sqrt(rms2/n-gmx::square(rmst/n));
486 void calc_hxprops(int nres, t_bb bb[], const rvec x[])
488 int i, ao, an, t1, t2, t3;
489 rvec dx, r_ij, r_kj, r_kl, m, n;
492 for (i = 0; (i < nres); i++)
495 bb[i].d4 = bb[i].d3 = bb[i].d5 = 0;
499 rvec_sub(x[ao], x[an], dx);
505 rvec_sub(x[ao], x[an], dx);
511 rvec_sub(x[ao], x[an], dx);
516 dih_angle(x[bb[i].Cprev], x[bb[i].N], x[bb[i].CA], x[bb[i].C], NULL,
517 r_ij, r_kj, r_kl, m, n,
518 &sign, &t1, &t2, &t3);
520 dih_angle(x[bb[i].N], x[bb[i].CA], x[bb[i].C], x[bb[i].Nnext], NULL,
521 r_ij, r_kj, r_kl, m, n,
522 &sign, &t1, &t2, &t3);
523 bb[i].pprms2 = gmx::square(bb[i].phi-PHI_AHX)+gmx::square(bb[i].psi-PSI_AHX);
526 1.4*std::sin((bb[i].psi+138.0)*DEG2RAD) -
527 4.1*std::cos(2.0*DEG2RAD*(bb[i].psi+138.0)) +
528 2.0*std::cos(2.0*DEG2RAD*(bb[i].phi+30.0));
532 static void check_ahx(int nres, t_bb bb[],
533 int *hstart, int *hend)
535 int h0, h1, h0sav, h1sav;
537 set_ahcity(nres, bb);
538 h0 = h0sav = h1sav = 0;
541 for (; (!bb[h0].bHelix) && (h0 < nres-4); h0++)
545 for (h1 = h0; bb[h1+1].bHelix && (h1 < nres-1); h1++)
551 /*fprintf(stderr,"Helix from %d to %d\n",h0,h1);*/
552 if (h1-h0 > h1sav-h0sav)
565 void do_start_end(int nres, t_bb bb[], int *nbb, int bbindex[],
566 int *nca, int caindex[],
567 gmx_bool bRange, int rStart, int rEnd)
569 int i, j, hstart = 0, hend = 0;
573 for (i = 0; (i < nres); i++)
575 if ((bb[i].resno >= rStart) && (bb[i].resno <= rEnd))
579 if (bb[i].resno == rStart)
583 if (bb[i].resno == rEnd)
591 /* Find start and end of longest helix fragment */
592 check_ahx(nres, bb, &hstart, &hend);
594 fprintf(stderr, "helix from: %d through %d\n",
595 bb[hstart].resno, bb[hend].resno);
597 for (j = 0, i = hstart; (i <= hend); i++)
599 bbindex[j++] = bb[i].N;
600 bbindex[j++] = bb[i].H;
601 bbindex[j++] = bb[i].CA;
602 bbindex[j++] = bb[i].C;
603 bbindex[j++] = bb[i].O;
604 caindex[i-hstart] = bb[i].CA;
607 *nca = (hend-hstart+1);
610 void pr_bb(FILE *fp, int nres, t_bb bb[])
615 fprintf(fp, "%3s %3s %3s %3s %3s %7s %7s %7s %7s %7s %3s\n",
616 "AA", "N", "Ca", "C", "O", "Phi", "Psi", "D3", "D4", "D5", "Hx?");
617 for (i = 0; (i < nres); i++)
619 fprintf(fp, "%3d %3d %3d %3d %3d %7.2f %7.2f %7.3f %7.3f %7.3f %3s\n",
620 bb[i].resno, bb[i].N, bb[i].CA, bb[i].C, bb[i].O,
621 bb[i].phi, bb[i].psi, bb[i].d3, bb[i].d4, bb[i].d5,
622 bb[i].bHelix ? "Yes" : "No");